Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.410
1.2 www 1: # The LearningOnline Network with CAPA
2: # a pile of common html routines
3: #
1.410 ! raeburn 4: # $Id: lonhtmlcommon.pm,v 1.409 2023/09/10 18:12:54 raeburn Exp $
1.2 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.10 matthew 28: ######################################################################
29: ######################################################################
30:
31: =pod
32:
33: =head1 NAME
34:
35: Apache::lonhtmlcommon - routines to do common html things
36:
37: =head1 SYNOPSIS
38:
39: Referenced by other mod_perl Apache modules.
40:
41: =head1 INTRODUCTION
42:
43: lonhtmlcommon is a collection of subroutines used to present information
44: in a consistent html format, or provide other functionality related to
45: html.
46:
47: =head2 General Subroutines
48:
49: =over 4
50:
51: =cut
52:
53: ######################################################################
54: ######################################################################
1.2 www 55:
1.1 stredwic 56: package Apache::lonhtmlcommon;
57:
1.104 albertel 58: use strict;
1.10 matthew 59: use Time::Local;
1.47 sakharuk 60: use Time::HiRes;
1.30 www 61: use Apache::lonlocal;
1.104 albertel 62: use Apache::lonnet;
1.286 www 63: use HTML::Entities();
1.330 raeburn 64: use LONCAPA qw(:DEFAULT :match);
1.1 stredwic 65:
1.284 www 66: sub java_not_enabled {
1.352 raeburn 67: if (($env{'browser.mobile'}) && ($env{'browser.mobile'} =~ /^ipad|ipod|iphone$/i)) {
68: return "\n".'<span class="LC_error">'.
69: &mt('The required Java applet could not be started, because Java is not supported by your mobile device.').
70: "</span>\n";
71: } else {
72: return "\n".'<span class="LC_error">'.
73: &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.').
74: "</span>\n";
75: }
1.284 www 76: }
1.247 www 77:
78: sub coursepreflink {
79: my ($text,$category)=@_;
80: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
1.392 raeburn 81: my $target =' target="_top"';
1.403 raeburn 82: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
83: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1.392 raeburn 84: $target ='';
85: }
86: return '<a'.$target.' href="'.&HTML::Entities::encode("/adm/courseprefs?phase=display&actions=$category",'<>&"').'"><span class="LC_setting">'.$text.'</span></a>';
1.247 www 87: } else {
88: return '';
89: }
90: }
91:
1.253 www 92: sub raw_href_to_link {
93: my ($message)=@_;
1.264 faziophi 94: $message=~s/(https?\:\/\/[^\s\'\"\<]+)([\s\<]|$)/<a href="$1"><tt>$1<\/tt><\/a>$2/gi;
1.253 www 95: return $message;
96: }
97:
1.286 www 98: sub entity_encode {
99: my ($text)=@_;
1.387 raeburn 100: return &HTML::Entities::encode($text, '\'<>&"');
1.286 www 101: }
102:
103: sub direct_parm_link {
104: my ($linktext,$symb,$filter,$part,$target)=@_;
105: $symb=&entity_encode($symb);
106: $filter=&entity_encode($filter);
107: $part=&entity_encode($part);
108: if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) {
1.393 raeburn 109: my $target=' target="_top"';
1.403 raeburn 110: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
111: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1.393 raeburn 112: $target='';
113: }
114: return "<a".$target." href=\"/adm/parmset?symb=$symb&filter=$filter&part=$part\"><span class=\"LC_setting\">$linktext</span></a>";
1.286 www 115: } else {
1.393 raeburn 116: return $linktext;
1.286 www 117: }
118: }
1.208 www 119: ##############################################
120: ##############################################
121:
1.309 raeburn 122: =item &confirm_success()
1.208 www 123:
124: Successful completion of an operation message
125:
126: =cut
127:
128: sub confirm_success {
1.209 www 129: my ($message,$failure)=@_;
130: if ($failure) {
1.265 wenzelju 131: return '<span class="LC_error" style="font-size: inherit;">'."\n"
1.218 bisitz 132: .'<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.&mt('Error').'" /> '."\n"
1.211 bisitz 133: .$message."\n"
134: .'</span>'."\n";
1.209 www 135: } else {
1.211 bisitz 136: return '<span class="LC_success">'."\n"
1.233 raeburn 137: .'<img src="/adm/lonIcons/navmap.correct.gif" alt="'.&mt('OK').'" /> '."\n"
1.211 bisitz 138: .$message."\n"
139: .'</span>'."\n";
1.209 www 140: }
1.208 www 141: }
1.176 foxr 142:
143: ##############################################
144: ##############################################
145:
146: =pod
147:
1.309 raeburn 148: =item &dragmath_button()
1.176 foxr 149:
1.177 raeburn 150: Creates a button that launches a dragmath popup-window, in which an
151: expression can be edited and pasted as LaTeX into a specified textarea.
152:
153: textarea - Name of the textarea to edit.
154: helpicon - If true, show a help icon to the right of the button.
1.176 foxr 155:
156: =cut
157:
1.177 raeburn 158: sub dragmath_button {
159: my ($textarea,$helpicon) = @_;
160: my $help_text;
161: if ($helpicon) {
1.282 raeburn 162: $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor',undef,undef,undef,undef,'mathhelpicon_'.$textarea);
1.177 raeburn 163: }
1.178 bisitz 164: my $buttontext=&mt('Edit Math');
1.177 raeburn 165: return <<ENDDRAGMATH;
1.246 bisitz 166: <input type="button" value="$buttontext" onclick="javascript:mathedit('$textarea',document)" />$help_text
1.177 raeburn 167: ENDDRAGMATH
168: }
169:
1.176 foxr 170: ##############################################
171:
1.177 raeburn 172: =pod
173:
1.309 raeburn 174: =item &dragmath_js()
1.177 raeburn 175:
176: Javascript used to open pop-up window containing dragmath applet which
177: can be used to paste LaTeX into a textarea.
1.309 raeburn 178:
1.177 raeburn 179: =cut
1.176 foxr 180:
1.177 raeburn 181: sub dragmath_js {
1.182 foxr 182: my ($popup) = @_;
1.177 raeburn 183: return <<ENDDRAGMATHJS;
184: <script type="text/javascript">
1.218 bisitz 185: // <![CDATA[
1.176 foxr 186: function mathedit(textarea, doc) {
187: targetEntry = textarea;
1.177 raeburn 188: targetDoc = doc;
1.354 raeburn 189: newwin = window.open("/adm/dragmath/$popup.html","","width=565,height=500,resizable");
1.176 foxr 190: }
1.218 bisitz 191: // ]]>
1.176 foxr 192: </script>
1.177 raeburn 193:
194: ENDDRAGMATHJS
1.176 foxr 195: }
196:
1.309 raeburn 197: ##############################################
198: ##############################################
199:
200: =pod
201:
202: =item &dependencies_button()
203:
204: Creates a button that launches a popup-window, in which dependencies
205: for the web page in the main window can be added to, replaced or deleted.
206:
207: =cut
208:
209: sub dependencies_button {
210: my $buttontext=&mt('Manage Dependencies');
211: return <<"END";
212: <input type="button" value="$buttontext" onclick="javascript:dependencycheck();" />
213: END
214: }
215:
216: ##############################################
217:
218: =pod
219:
220: =item &dependencycheck_js()
221:
222: Javascript used to open pop-up window containing interface to manage
223: dependencies for a web page uploaded diretcly to a course.
224:
225: =cut
226:
227: sub dependencycheck_js {
1.334 raeburn 228: my ($symb,$title,$url,$folderpath,$uri) = @_;
229: my $link;
230: if ($symb) {
231: $link = '/adm/dependencies?symb='.&HTML::Entities::encode($symb,'<>&"');
232: } elsif ($folderpath) {
233: $link = '/adm/dependencies?folderpath='.&HTML::Entities::encode($folderpath,'<>&"');
234: $url = $uri;
1.344 raeburn 235: } elsif ($uri =~ m{^/public/$match_domain/$match_courseid/syllabus$}) {
236: $link = '/adm/dependencies';
1.334 raeburn 237: }
238: $link .= (($link=~/\?/)?'&':'?').'title='.
239: &HTML::Entities::encode($title,'<>&"');
240: if ($url) {
241: $link .= '&url='.&HTML::Entities::encode($url,'<>&"');
242: }
1.309 raeburn 243: return <<ENDJS;
244: <script type="text/javascript">
245: // <![CDATA[
246: function dependencycheck() {
247: depwin = window.open("$link","","width=750,height=500,resizable,scrollbars=yes");
248: }
249: // ]]>
250: </script>
251: ENDJS
252: }
1.182 foxr 253:
1.40 www 254: ##############################################
255: ##############################################
256:
257: =pod
258:
1.309 raeburn 259: =item &authorbombs()
1.40 www 260:
261: =cut
262:
263: ##############################################
264: ##############################################
265:
266: sub authorbombs {
267: my $url=shift;
268: $url=&Apache::lonnet::declutter($url);
1.155 albertel 269: my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/});
1.40 www 270: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.232 raeburn 271: foreach my $bomb (keys(%bombs)) {
272: if ($bomb =~ /^$udom\/$uname\//) {
1.40 www 273: return '<a href="/adm/bombs/'.$url.
1.218 bisitz 274: '"><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/bomb.gif').'" alt="'.&mt('Bomb').'" border="0" /></a>'.
1.40 www 275: &Apache::loncommon::help_open_topic('About_Bombs');
276: }
277: }
278: return '';
279: }
1.26 matthew 280:
281: ##############################################
282: ##############################################
283:
1.41 www 284: sub recent_filename {
285: my $area=shift;
1.130 www 286: return 'nohist_recent_'.&escape($area);
1.41 www 287: }
288:
289: sub store_recent {
1.136 albertel 290: my ($area,$name,$value,$freeze)=@_;
1.41 www 291: my $file=&recent_filename($area);
292: my %recent=&Apache::lonnet::dump($file);
1.111 www 293: if (scalar(keys(%recent))>20) {
1.41 www 294: # remove oldest value
1.136 albertel 295: my $oldest=time();
1.41 www 296: my $delkey='';
1.136 albertel 297: foreach my $item (keys(%recent)) {
298: my $thistime=(split(/\&/,$recent{$item}))[0];
299: if (($thistime ne "always_include") && ($thistime<$oldest)) {
1.41 www 300: $oldest=$thistime;
1.136 albertel 301: $delkey=$item;
1.41 www 302: }
303: }
304: &Apache::lonnet::del($file,[$delkey]);
305: }
306: # store new value
1.136 albertel 307: my $timestamp;
308: if ($freeze) {
309: $timestamp = "always_include";
310: } else {
311: $timestamp = time();
312: }
1.41 www 313: &Apache::lonnet::put($file,{ $name =>
1.136 albertel 314: $timestamp.'&'.&escape($value) });
1.41 www 315: }
316:
1.89 banghart 317: sub remove_recent {
318: my ($area,$names)=@_;
319: my $file=&recent_filename($area);
320: return &Apache::lonnet::del($file,$names);
321: }
322:
1.41 www 323: sub select_recent {
324: my ($area,$fieldname,$event)=@_;
325: my %recent=&Apache::lonnet::dump(&recent_filename($area));
326: my $return="\n<select name='$fieldname'".
1.96 albertel 327: ($event?" onchange='$event'":'').
1.41 www 328: ">\n<option value=''>--- ".&mt('Recent')." ---</option>";
1.136 albertel 329: foreach my $value (sort(keys(%recent))) {
330: unless ($value =~/^error\:/) {
331: my $escaped = &Apache::loncommon::escape_url($value);
1.160 albertel 332: &Apache::loncommon::inhibit_menu_check(\$escaped);
1.251 raeburn 333: if ($area eq 'residx') {
334: next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value)));
335: }
1.94 foxr 336: $return.="\n<option value='$escaped'>".
1.136 albertel 337: &unescape((split(/\&/,$recent{$value}))[1]).
1.41 www 338: '</option>';
339: }
340: }
341: $return.="\n</select>\n";
342: return $return;
343: }
344:
1.97 albertel 345: sub get_recent {
346: my ($area, $n) = @_;
347: my %recent=&Apache::lonnet::dump(&recent_filename($area));
348:
349: # Create hash with key as time and recent as value
1.136 albertel 350: # Begin filling return_hash with any 'always_include' option
1.97 albertel 351: my %time_hash = ();
1.136 albertel 352: my %return_hash = ();
1.232 raeburn 353: foreach my $item (keys(%recent)) {
1.136 albertel 354: my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
355: if ($thistime eq 'always_include') {
356: $return_hash{$item} = &unescape($thisvalue);
357: $n--;
358: } else {
359: $time_hash{$thistime} = $item;
1.133 albertel 360: }
1.97 albertel 361: }
362:
363: # Sort by decreasing time and return key value pairs
364: my $idx = 1;
1.136 albertel 365: foreach my $item (reverse(sort(keys(%time_hash)))) {
366: $return_hash{$time_hash{$item}} =
367: &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]);
1.97 albertel 368: if ($n && ($idx++ >= $n)) {last;}
369: }
370:
371: return %return_hash;
372: }
373:
1.136 albertel 374: sub get_recent_frozen {
375: my ($area) = @_;
376: my %recent=&Apache::lonnet::dump(&recent_filename($area));
377:
378: # Create hash with all 'frozen' items
379: my %return_hash = ();
380: foreach my $item (keys(%recent)) {
381: my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
382: if ($thistime eq 'always_include') {
383: $return_hash{$item} = &unescape($thisvalue);
384: }
385: }
386: return %return_hash;
387: }
388:
1.97 albertel 389:
1.41 www 390:
1.26 matthew 391: =pod
392:
1.309 raeburn 393: =item &textbox()
1.26 matthew 394:
395: =cut
396:
397: ##############################################
398: ##############################################
399: sub textbox {
400: my ($name,$value,$size,$special) = @_;
401: $size = 40 if (! defined($size));
1.128 albertel 402: $value = &HTML::Entities::encode($value,'<>&"');
1.26 matthew 403: my $Str = '<input type="text" name="'.$name.'" size="'.$size.'" '.
404: 'value="'.$value.'" '.$special.' />';
405: return $Str;
406: }
407:
408: ##############################################
409: ##############################################
410:
411: =pod
412:
1.309 raeburn 413: =item &checkbox()
1.26 matthew 414:
415: =cut
416:
417: ##############################################
418: ##############################################
419: sub checkbox {
1.378 raeburn 420: my ($name,$checked,$value,$special) = @_;
1.68 matthew 421: my $Str = '<input type="checkbox" name="'.$name.'" ';
422: if (defined($value)) {
423: $Str .= 'value="'.$value.'"';
424: }
425: if ($checked) {
1.206 bisitz 426: $Str .= ' checked="checked"';
1.68 matthew 427: }
1.378 raeburn 428: $Str .= $special.' />';
1.26 matthew 429: return $Str;
430: }
431:
1.120 albertel 432:
433: =pod
434:
1.309 raeburn 435: =item &radiobutton()
1.120 albertel 436:
437: =cut
438:
439: ##############################################
440: ##############################################
441: sub radio {
442: my ($name,$checked,$value) = @_;
443: my $Str = '<input type="radio" name="'.$name.'" ';
444: if (defined($value)) {
445: $Str .= 'value="'.$value.'"';
446: }
447: if ($checked eq $value) {
1.206 bisitz 448: $Str .= ' checked="checked"';
1.120 albertel 449: }
450: $Str .= ' />';
451: return $Str;
452: }
453:
1.10 matthew 454: ##############################################
455: ##############################################
456:
457: =pod
458:
1.309 raeburn 459: =item &date_setter()
1.10 matthew 460:
1.22 matthew 461: &date_setter returns html and javascript for a compact date-setting form.
1.309 raeburn 462: To retrieve values from it, use &get_date_from_form.
1.22 matthew 463:
1.361 musolffc 464: =over 4
465:
466: =item Inputs
1.10 matthew 467:
1.361 musolffc 468: =over
1.10 matthew 469:
470: =item $dname
471:
472: The name to prepend to the form elements.
473: The form elements defined will be dname_year, dname_month, dname_day,
474: dname_hour, dname_min, and dname_sec.
475:
476: =item $currentvalue
477:
478: The current setting for this time parameter. A unix format time
479: (time in seconds since the beginning of Jan 1st, 1970, GMT.
1.257 faziophi 480: An undefined value is taken to indicate the value is the current time
481: unless it is requested to leave it empty. See $includeempty.
1.10 matthew 482: Also, to be explicit, a value of 'now' also indicates the current time.
483:
1.26 matthew 484: =item $special
485:
486: Additional html/javascript to be associated with each element in
487: the date_setter. See lonparmset for example usage.
488:
1.59 matthew 489: =item $includeempty
490:
1.257 faziophi 491: If it is set (true) and no date/time value is provided,
492: the date/time fields are left empty.
493:
1.59 matthew 494: =item $state
495:
496: Specifies the initial state of the form elements. Either 'disabled' or empty.
1.363 raeburn 497: Defaults to empty, which indicates the form elements are not disabled.
498:
499: =item $no_hh_mm_ss
500:
501: If true, text boxes for hours, minutes and seconds are omitted.
502:
503: =item $defhour
504:
505: Default value for hours (a default of 0 is used otherwise).
506:
507: =item $defmin
508:
509: Default value for minutes (a default of 0 is used otherwise).
510:
511: =item defsec
512:
513: Default value for seconds (a default of 0 is used otherwise).
514:
515: =item $nolink
516:
517: If true, a "Select calendar" link (to pop-up a calendar) is not displayed
518: to the right of the items.
519:
520: =item $no_mm_ss
521:
522: If true, text boxes for minutes and seconds are omitted.
523:
524: =item $no_ss
525:
526: If true, text boxes for seconds are omitted.
1.59 matthew 527:
1.22 matthew 528: =back
529:
1.361 musolffc 530: =item Bugs
1.22 matthew 531:
532: The method used to restrict user input will fail in the year 2400.
533:
1.361 musolffc 534: =back
535:
1.10 matthew 536: =cut
537:
538: ##############################################
539: ##############################################
540: sub date_setter {
1.67 matthew 541: my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
1.363 raeburn 542: $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink,$no_mm_ss,$no_ss) = @_;
1.175 raeburn 543: my $now = time;
1.257 faziophi 544:
545: my $tzname;
546: my ($sec,$min,$hour,$mday,$month,$year) = ('', '', undef,''.''.'');
547: #other potentially useful values: wkday,yrday,is_daylight_savings
548:
1.59 matthew 549: if (! defined($state) || $state ne 'disabled') {
550: $state = '';
1.374 raeburn 551: } else {
552: $state = 'disabled="disabled"';
1.59 matthew 553: }
1.67 matthew 554: if (! defined($no_hh_mm_ss)) {
555: $no_hh_mm_ss = 0;
556: }
1.110 www 557: if ($currentvalue eq 'now') {
1.257 faziophi 558: $currentvalue = $now;
1.110 www 559: }
1.257 faziophi 560:
561: # Default value: Set empty date field to current time
562: # unless empty inclusion is requested
563: if ((!$includeempty) && (!$currentvalue)) {
564: $currentvalue = $now;
1.10 matthew 565: }
1.257 faziophi 566: # Do we have a date? Split it!
1.39 www 567: if ($currentvalue) {
1.257 faziophi 568: ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue);
569:
570: #No values provided for hour, min, sec? Use default 0
571: if (($defhour) || ($defmin) || ($defsec)) {
572: $sec = ($defsec ? $defsec : 0);
573: $min = ($defmin ? $defmin : 0);
574: $hour = ($defhour ? $defhour : 0);
575: }
1.107 www 576: }
1.10 matthew 577: my $result = "\n<!-- $dname date setting form -->\n";
578: $result .= <<ENDJS;
1.135 albertel 579: <script type="text/javascript">
1.218 bisitz 580: // <![CDATA[
1.10 matthew 581: function $dname\_checkday() {
582: var day = document.$formname.$dname\_day.value;
583: var month = document.$formname.$dname\_month.value;
584: var year = document.$formname.$dname\_year.value;
585: var valid = true;
586: if (day < 1) {
587: document.$formname.$dname\_day.value = 1;
588: }
589: if (day > 31) {
590: document.$formname.$dname\_day.value = 31;
591: }
592: if ((month == 1) || (month == 3) || (month == 5) ||
593: (month == 7) || (month == 8) || (month == 10) ||
594: (month == 12)) {
595: if (day > 31) {
596: document.$formname.$dname\_day.value = 31;
597: day = 31;
598: }
599: } else if (month == 2 ) {
600: if ((year % 4 == 0) && (year % 100 != 0)) {
601: if (day > 29) {
602: document.$formname.$dname\_day.value = 29;
603: }
604: } else if (day > 29) {
605: document.$formname.$dname\_day.value = 28;
606: }
607: } else if (day > 30) {
608: document.$formname.$dname\_day.value = 30;
609: }
610: }
1.95 matthew 611:
1.59 matthew 612: function $dname\_disable() {
613: document.$formname.$dname\_month.disabled=true;
614: document.$formname.$dname\_day.disabled=true;
615: document.$formname.$dname\_year.disabled=true;
616: document.$formname.$dname\_hour.disabled=true;
617: document.$formname.$dname\_minute.disabled=true;
618: document.$formname.$dname\_second.disabled=true;
619: }
620:
621: function $dname\_enable() {
622: document.$formname.$dname\_month.disabled=false;
623: document.$formname.$dname\_day.disabled=false;
624: document.$formname.$dname\_year.disabled=false;
625: document.$formname.$dname\_hour.disabled=false;
626: document.$formname.$dname\_minute.disabled=false;
627: document.$formname.$dname\_second.disabled=false;
628: }
629:
1.29 www 630: function $dname\_opencalendar() {
1.59 matthew 631: if (! document.$formname.$dname\_month.disabled) {
632: var calwin=window.open(
1.29 www 633: "/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
634: document.$formname.$dname\_month.value+"&year="+
635: document.$formname.$dname\_year.value,
636: "LONCAPAcal",
637: "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
1.59 matthew 638: }
1.29 www 639:
640: }
1.218 bisitz 641: // ]]>
1.10 matthew 642: </script>
643: ENDJS
1.192 bisitz 644: $result .= ' <span class="LC_nobreak">';
1.96 albertel 645: my $monthselector = qq{<select name="$dname\_month" $special $state onchange="javascript:$dname\_checkday()" >};
1.67 matthew 646: # Month
1.10 matthew 647: my @Months = qw/January February March April May June
648: July August September October November December/;
649: # Pad @Months with a bogus value to make indexing easier
650: unshift(@Months,'If you can read this an error occurred');
1.95 matthew 651: if ($includeempty) { $monthselector.="<option value=''></option>"; }
1.10 matthew 652: for(my $m = 1;$m <=$#Months;$m++) {
1.228 bisitz 653: $monthselector .= qq{ <option value="$m"};
654: $monthselector .= ' selected="selected"' if ($m-1 eq $month);
655: $monthselector .= '> '.&mt($Months[$m]).' </option>'."\n";
1.10 matthew 656: }
1.95 matthew 657: $monthselector.= ' </select>';
1.67 matthew 658: # Day
1.96 albertel 659: my $dayselector = qq{<input type="text" name="$dname\_day" $state value="$mday" size="3" $special onchange="javascript:$dname\_checkday()" />};
1.67 matthew 660: # Year
1.226 bisitz 661: my $yearselector = qq{<input type="text" name="$dname\_year" $state value="$year" size="5" $special onchange="javascript:$dname\_checkday()" />};
1.95 matthew 662: #
663: my $hourselector = qq{<select name="$dname\_hour" $special $state >};
664: if ($includeempty) {
665: $hourselector.=qq{<option value=''></option>};
666: }
667: for (my $h = 0;$h<24;$h++) {
1.228 bisitz 668: $hourselector .= qq{<option value="$h"};
669: $hourselector .= ' selected="selected"' if (defined($hour) && $hour == $h);
1.95 matthew 670: $hourselector .= ">";
671: my $timest='';
672: if ($h == 0) {
673: $timest .= "12 am";
674: } elsif($h == 12) {
675: $timest .= "12 noon";
676: } elsif($h < 12) {
677: $timest .= "$h am";
678: } else {
679: $timest .= $h-12 ." pm";
680: }
681: $timest=&mt($timest);
682: $hourselector .= $timest." </option>\n";
683: }
684: $hourselector .= " </select>\n";
685: my $minuteselector = qq{<input type="text" name="$dname\_minute" $special $state value="$min" size="3" />};
686: my $secondselector= qq{<input type="text" name="$dname\_second" $special $state value="$sec" size="3" />};
1.134 raeburn 687: my $cal_link;
1.369 raeburn 688: unless (($nolink) || ($state eq 'disabled')) {
1.134 raeburn 689: $cal_link = qq{<a href="javascript:$dname\_opencalendar()">};
690: }
1.95 matthew 691: #
1.175 raeburn 692: my $tzone = ' '.$tzname.' ';
1.95 matthew 693: if ($no_hh_mm_ss) {
1.134 raeburn 694: $result .= &mt('[_1] [_2] [_3] ',
1.174 raeburn 695: $monthselector,$dayselector,$yearselector).
696: $tzone;
1.363 raeburn 697: } elsif ($no_mm_ss) {
698: $result .= &mt('[_1] [_2] [_3] [_4]',
699: $monthselector,$dayselector,$yearselector,
700: $hourselector).
701: $tzone;
702:
703: } elsif ($no_ss) {
704: $result .= &mt('[_1] [_2] [_3] [_4] [_5]m',
705: $monthselector,$dayselector,$yearselector,
706: $hourselector,$minuteselector).
707: $tzone;
708:
1.95 matthew 709: } else {
1.134 raeburn 710: $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ',
711: $monthselector,$dayselector,$yearselector,
1.174 raeburn 712: $hourselector,$minuteselector,$secondselector).
713: $tzone;
1.363 raeburn 714: }
1.369 raeburn 715: unless (($nolink) || ($state eq 'disabled')) {
1.363 raeburn 716: $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
1.67 matthew 717: }
1.135 albertel 718: $result .= "</span>\n<!-- end $dname date setting form -->\n";
1.10 matthew 719: return $result;
720: }
721:
1.175 raeburn 722: sub get_timedates {
723: my ($epoch) = @_;
724: my $dt = DateTime->from_epoch(epoch => $epoch)
725: ->set_time_zone(&Apache::lonlocal::gettimezone());
726: my $tzname = $dt->time_zone_short_name();
727: my $sec = $dt->second;
728: my $min = $dt->minute;
729: my $hour = $dt->hour;
730: my $mday = $dt->day;
731: my $month = $dt->month;
732: if ($month) {
733: $month --;
734: }
735: my $year = $dt->year;
736: return ($tzname,$sec,$min,$hour,$mday,$month,$year);
737: }
1.166 banghart 738:
739: sub build_url {
740: my ($base, $fields)=@_;
741: my $url;
742: $url = $base.'?';
1.168 albertel 743: foreach my $key (keys(%$fields)) {
744: $url.=&escape($key).'='.&escape($$fields{$key}).'&';
1.166 banghart 745: }
746: $url =~ s/&$//;
747: return $url;
748: }
749:
750:
1.10 matthew 751: ##############################################
752: ##############################################
753:
1.22 matthew 754: =pod
755:
1.309 raeburn 756: =item &get_date_from_form()
1.22 matthew 757:
758: get_date_from_form retrieves the date specified in an &date_setter form.
1.10 matthew 759:
1.361 musolffc 760: =over
761:
762: =item Inputs:
1.10 matthew 763:
764: =over 4
765:
766: =item $dname
767:
1.226 bisitz 768: The name passed to &date_setter, which prefixes the form elements.
1.10 matthew 769:
770: =item $defaulttime
771:
772: The unix time to use as the default in case of poor inputs.
773:
774: =back
775:
1.361 musolffc 776: =back
777:
1.10 matthew 778: Returns: Unix time represented in the form.
779:
780: =cut
781:
782: ##############################################
783: ##############################################
784: sub get_date_from_form {
785: my ($dname) = @_;
786: my ($sec,$min,$hour,$day,$month,$year);
787: #
1.104 albertel 788: if (defined($env{'form.'.$dname.'_second'})) {
789: my $tmpsec = $env{'form.'.$dname.'_second'};
1.10 matthew 790: if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
791: $sec = $tmpsec;
792: }
1.64 albertel 793: if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
1.67 matthew 794: } else {
795: $sec = 0;
1.10 matthew 796: }
1.104 albertel 797: if (defined($env{'form.'.$dname.'_minute'})) {
798: my $tmpmin = $env{'form.'.$dname.'_minute'};
1.10 matthew 799: if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
800: $min = $tmpmin;
801: }
1.64 albertel 802: if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
1.67 matthew 803: } else {
804: $min = 0;
1.10 matthew 805: }
1.104 albertel 806: if (defined($env{'form.'.$dname.'_hour'})) {
807: my $tmphour = $env{'form.'.$dname.'_hour'};
1.33 matthew 808: if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
1.10 matthew 809: $hour = $tmphour;
810: }
1.67 matthew 811: } else {
812: $hour = 0;
1.10 matthew 813: }
1.104 albertel 814: if (defined($env{'form.'.$dname.'_day'})) {
815: my $tmpday = $env{'form.'.$dname.'_day'};
1.10 matthew 816: if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
817: $day = $tmpday;
818: }
819: }
1.104 albertel 820: if (defined($env{'form.'.$dname.'_month'})) {
821: my $tmpmonth = $env{'form.'.$dname.'_month'};
1.10 matthew 822: if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
1.175 raeburn 823: $month = $tmpmonth;
1.10 matthew 824: }
825: }
1.104 albertel 826: if (defined($env{'form.'.$dname.'_year'})) {
827: my $tmpyear = $env{'form.'.$dname.'_year'};
1.175 raeburn 828: if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) {
829: $year = $tmpyear;
1.10 matthew 830: }
831: }
1.175 raeburn 832: if (($year<1970) || ($year>2037)) { return undef; }
1.33 matthew 833: if (defined($sec) && defined($min) && defined($hour) &&
1.175 raeburn 834: defined($day) && defined($month) && defined($year)) {
835: my $timezone = &Apache::lonlocal::gettimezone();
836: my $dt = DateTime->new( year => $year,
837: month => $month,
838: day => $day,
839: hour => $hour,
840: minute => $min,
841: second => $sec,
842: time_zone => $timezone,
843: );
844: my $epoch_time = $dt->epoch;
845: if ($epoch_time ne '') {
846: return $epoch_time;
847: } else {
848: return undef;
849: }
1.10 matthew 850: } else {
851: return undef;
852: }
1.20 matthew 853: }
854:
855: ##############################################
856: ##############################################
857:
858: =pod
859:
860: =item &pjump_javascript_definition()
861:
862: Returns javascript defining the 'pjump' function, which opens up a
863: parameter setting wizard.
864:
865: =cut
866:
867: ##############################################
868: ##############################################
869: sub pjump_javascript_definition {
870: my $Str = <<END;
1.397 raeburn 871: function pjump(type,dis,value,marker,ret,call,hour,min,sec,extra) {
1.295 www 872: openMyModal("/adm/rat/parameter.html?type="+escape(type)
1.20 matthew 873: +"&value="+escape(value)+"&marker="+escape(marker)
874: +"&return="+escape(ret)
1.109 www 875: +"&call="+escape(call)+"&name="+escape(dis)
876: +"&defhour="+escape(hour)+"&defmin="+escape(min)
1.397 raeburn 877: +"&defsec="+escape(sec)+"&extra="+escape(extra)
878: +"&modal=1",350,350,'no');
1.20 matthew 879: }
880: END
881: return $Str;
1.10 matthew 882: }
883:
884: ##############################################
885: ##############################################
1.17 matthew 886:
887: =pod
888:
889: =item &javascript_nothing()
890:
891: Return an appropriate null for the users browser. This is used
892: as the first arguement for window.open calls when you want a blank
893: window that you can then write to.
894:
895: =cut
896:
897: ##############################################
898: ##############################################
899: sub javascript_nothing {
900: # mozilla and other browsers work with "''", but IE on mac does not.
901: my $nothing = "''";
902: my $user_browser;
903: my $user_os;
1.104 albertel 904: $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
905: $user_os = $env{'browser.os'} if (exists($env{'browser.os'}));
1.17 matthew 906: if (! defined($user_browser) || ! defined($user_os)) {
907: (undef,$user_browser,undef,undef,undef,$user_os) =
908: &Apache::loncommon::decode_user_agent();
909: }
910: if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
911: $nothing = "'javascript:void(0);'";
912: }
913: return $nothing;
914: }
915:
1.90 www 916: ##############################################
917: ##############################################
918: sub javascript_docopen {
1.171 albertel 919: my ($mimetype) = @_;
920: $mimetype ||= 'text/html';
1.90 www 921: # safari does not understand document.open() and loads "text/html"
922: my $nothing = "''";
923: my $user_browser;
924: my $user_os;
1.104 albertel 925: $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
926: $user_os = $env{'browser.os'} if (exists($env{'browser.os'}));
1.90 www 927: if (! defined($user_browser) || ! defined($user_os)) {
928: (undef,$user_browser,undef,undef,undef,$user_os) =
929: &Apache::loncommon::decode_user_agent();
930: }
931: if ($user_browser eq 'safari' && $user_os =~ 'mac') {
932: $nothing = "document.clear()";
933: } else {
1.171 albertel 934: $nothing = "document.open('$mimetype','replace')";
1.90 www 935: }
936: return $nothing;
937: }
938:
1.21 matthew 939:
1.17 matthew 940: ##############################################
941: ##############################################
942:
1.21 matthew 943: =pod
1.17 matthew 944:
1.21 matthew 945: =item &StatusOptions()
1.10 matthew 946:
1.21 matthew 947: Returns html for a selection box which allows the user to choose the
948: enrollment status of students. The selection box name is 'Status'.
1.6 stredwic 949:
1.361 musolffc 950: =over
951:
952: =item Inputs:
1.6 stredwic 953:
1.21 matthew 954: $status: the currently selected status. If undefined the value of
1.104 albertel 955: $env{'form.Status'} is taken. If that is undefined, a value of 'Active'
1.21 matthew 956: is used.
1.6 stredwic 957:
1.21 matthew 958: $formname: The name of the form. If defined the onchange attribute of
959: the selection box is set to document.$formname.submit().
1.6 stredwic 960:
1.21 matthew 961: $size: the size (number of lines) of the selection box.
1.6 stredwic 962:
1.27 matthew 963: $onchange: javascript to use when the value is changed. Enclosed in
964: double quotes, ""s, not single quotes.
965:
1.361 musolffc 966: =back
967:
1.21 matthew 968: Returns: a perl string as described.
1.1 stredwic 969:
1.21 matthew 970: =cut
1.9 stredwic 971:
1.21 matthew 972: ##############################################
973: ##############################################
974: sub StatusOptions {
1.165 banghart 975: my ($status, $formName,$size,$onchange,$mult)=@_;
1.21 matthew 976: $size = 1 if (!defined($size));
977: if (! defined($status)) {
978: $status = 'Active';
1.104 albertel 979: $status = $env{'form.Status'} if (exists($env{'form.Status'}));
1.9 stredwic 980: }
1.1 stredwic 981:
982: my $Str = '';
983: $Str .= '<select name="Status"';
1.165 banghart 984: if (defined($mult)){
985: $Str .= ' multiple="multiple" ';
986: }
1.27 matthew 987: if(defined($formName) && $formName ne '' && ! defined($onchange)) {
1.1 stredwic 988: $Str .= ' onchange="document.'.$formName.'.submit()"';
1.27 matthew 989: }
990: if (defined($onchange)) {
991: $Str .= ' onchange="'.$onchange.'"';
1.1 stredwic 992: }
1.21 matthew 993: $Str .= ' size="'.$size.'" ';
1.1 stredwic 994: $Str .= '>'."\n";
1.153 raeburn 995: foreach my $type (['Active', &mt('Currently Has Access')],
996: ['Future', &mt('Will Have Future Access')],
997: ['Expired', &mt('Previously Had Access')],
998: ['Any', &mt('Any Access Status')]) {
1.151 albertel 999: my ($name,$label) = @$type;
1000: $Str .= '<option value="'.$name.'" ';
1001: if ($status eq $name) {
1002: $Str .= 'selected="selected" ';
1003: }
1004: $Str .= '>'.$label.'</option>'."\n";
1005: }
1006:
1.1 stredwic 1007: $Str .= '</select>'."\n";
1.7 stredwic 1008: }
1.12 matthew 1009:
1010: ########################################################
1011: ########################################################
1.7 stredwic 1012:
1.23 matthew 1013: =pod
1014:
1.361 musolffc 1015: =item Progress Window Handling Routines
1.23 matthew 1016:
1017: These routines handle the creation, update, increment, and closure of
1018: progress windows. The progress window reports to the user the number
1019: of items completed and an estimate of the time required to complete the rest.
1020:
1021: =over 4
1022:
1023:
1.309 raeburn 1024: =item &Create_PrgWin()
1.23 matthew 1025:
1026: Writes javascript to the client to open a progress window and returns a
1027: data structure used for bookkeeping.
1028:
1.361 musolffc 1029: =over
1030:
1031: =item Inputs
1.23 matthew 1032:
1.361 musolffc 1033: =over
1.23 matthew 1034:
1035: =item $r Apache request
1036:
1037: =item $number_to_do The total number of items being processed.
1.50 albertel 1038:
1.390 raeburn 1039: =item $preamble Optional HTML to display before the progress bar.
1040:
1.23 matthew 1041: =back
1042:
1.361 musolffc 1043: =back
1044:
1.23 matthew 1045: Returns a hash containing the progress state data structure.
1.390 raeburn 1046: If $number_to_do is zero or null, an indeterminate progress bar will
1047: be used.
1.23 matthew 1048:
1.309 raeburn 1049: =item &Update_PrgWin()
1.23 matthew 1050:
1051: Updates the text in the progress indicator. Does not increment the count.
1052: See &Increment_PrgWin.
1053:
1.361 musolffc 1054: =over
1055:
1056: =item Inputs:
1.23 matthew 1057:
1058: =over 4
1059:
1060: =item $r Apache request
1061:
1062: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
1063:
1064: =item $displaystring The string to write to the status indicator
1065:
1066: =back
1067:
1.361 musolffc 1068: =back
1069:
1.23 matthew 1070: Returns: none
1071:
1072:
1.361 musolffc 1073: =item &Increment_PrgWin()
1.23 matthew 1074:
1.276 bisitz 1075: Increment the count of items completed for the progress window by $step or 1 if no step is provided.
1.23 matthew 1076:
1.361 musolffc 1077: =over
1078:
1079: =item Inputs:
1.23 matthew 1080:
1081: =over 4
1082:
1.361 musolffc 1083: =item $r
1084:
1085: Apache request
1086:
1087: =item $prog_state
1088:
1089: Pointer to the data structure returned by Create_PrgWin
1090:
1091: =item $extraInfo
1092:
1093: A description of the items being iterated over. Typically 'student'.
1.23 matthew 1094:
1.361 musolffc 1095: =item $step
1.23 matthew 1096:
1.361 musolffc 1097: (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
1.23 matthew 1098:
1.361 musolffc 1099: =back
1.276 bisitz 1100:
1.23 matthew 1101: =back
1102:
1103: Returns: none
1104:
1105:
1.309 raeburn 1106: =item &Close_PrgWin()
1.23 matthew 1107:
1108: Closes the progress window.
1109:
1.361 musolffc 1110: =over
1111:
1112: =item Inputs:
1.23 matthew 1113:
1114: =over 4
1115:
1116: =item $r Apache request
1117:
1118: =item $prog_state Pointer to the data structure returned by Create_PrgWin
1119:
1120: =back
1121:
1.361 musolffc 1122: =back
1123:
1.23 matthew 1124: Returns: none
1125:
1126: =back
1127:
1128: =cut
1129:
1130: ########################################################
1131: ########################################################
1132:
1.51 albertel 1133:
1.7 stredwic 1134: # Create progress
1135: sub Create_PrgWin {
1.390 raeburn 1136: my ($r,$number_to_do,$preamble)=@_;
1.49 albertel 1137: my %prog_state;
1.16 albertel 1138: $prog_state{'done'}=0;
1.23 matthew 1139: $prog_state{'firststart'}=&Time::HiRes::time();
1140: $prog_state{'laststart'}=&Time::HiRes::time();
1.16 albertel 1141: $prog_state{'max'}=$number_to_do;
1.390 raeburn 1142: &Apache::loncommon::LCprogressbar($r,$prog_state{'max'},$preamble);
1.14 albertel 1143: return %prog_state;
1.7 stredwic 1144: }
1145:
1146: # update progress
1147: sub Update_PrgWin {
1.14 albertel 1148: my ($r,$prog_state,$displayString)=@_;
1.390 raeburn 1149: &Apache::loncommon::LCprogressbarUpdate($r,undef,$displayString,$$prog_state{'max'});
1.23 matthew 1150: $$prog_state{'laststart'}=&Time::HiRes::time();
1.14 albertel 1151: }
1152:
1153: # increment progress state
1154: sub Increment_PrgWin {
1.275 bisitz 1155: my ($r,$prog_state,$extraInfo,$step)=@_;
1.279 bisitz 1156: $step = $step > 0 ? $step : 1;
1.275 bisitz 1157: $$prog_state{'done'} += $step;
1158:
1159: # Catch (max modulo step) <> 0
1160: my $current = $$prog_state{'done'};
1161: my $last = ($$prog_state{'max'} - $current);
1162: if ($last <= 0) {
1163: $last = 1;
1164: $current = $$prog_state{'max'};
1165: }
1166:
1.23 matthew 1167: my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
1.275 bisitz 1168: $current * $last;
1.16 albertel 1169: $time_est = int($time_est);
1.80 matthew 1170: #
1171: my $min = int($time_est/60);
1172: my $sec = $time_est % 60;
1.278 bisitz 1173:
1.23 matthew 1174: my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
1175: if ($lasttime > 9) {
1176: $lasttime = int($lasttime);
1177: } elsif ($lasttime < 0.01) {
1178: $lasttime = 0;
1179: } else {
1180: $lasttime = sprintf("%3.2f",$lasttime);
1181: }
1.278 bisitz 1182:
1183: $sec = 0 if ($min >= 10); # Don't show seconds if remaining time >= 10 min.
1184: $sec = 1 if ( ($min == 0) && ($sec == 0) ); # Little cheating: pretend to have 1 second remaining instead of 0 to have something to display
1185:
1186: my $timeinfo =
1187: &mt('[_1]/[_2]:'
1188: .' [quant,_3,minute,minutes,] [quant,_4,second ,seconds ,]remaining'
1189: .' ([quant,_5,second] for '.$extraInfo.')',
1190: $current,
1191: $$prog_state{'max'},
1192: $min,
1193: $sec,
1194: $lasttime);
1.297 www 1195: my $percent=0;
1196: if ($$prog_state{'max'}) {
1197: $percent=int(100.*$current/$$prog_state{'max'});
1198: }
1.390 raeburn 1199: &Apache::loncommon::LCprogressbarUpdate($r,$percent,$timeinfo,$$prog_state{'max'});
1.23 matthew 1200: $$prog_state{'laststart'}=&Time::HiRes::time();
1.7 stredwic 1201: }
1202:
1203: # close Progress Line
1204: sub Close_PrgWin {
1.14 albertel 1205: my ($r,$prog_state)=@_;
1.297 www 1206: &Apache::loncommon::LCprogressbarClose($r);
1.48 albertel 1207: undef(%$prog_state);
1208: }
1209:
1.326 foxr 1210:
1.34 www 1211: # ------------------------------------------------------- Puts directory header
1212:
1213: sub crumbs {
1.373 raeburn 1214: my ($uri,$target,$prefix,$form,$skiplast,$onclick)=@_;
1.303 www 1215: # You cannot crumbnify uploaded or adm resources
1.377 raeburn 1216: if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Community Content)'); }
1.100 raeburn 1217: if ($target) {
1218: $target = ' target="'.
1219: &Apache::loncommon::escape_single($target).'"';
1220: }
1.252 bisitz 1221: my $output='<span class="LC_filename">';
1222: $output.=$prefix.'/';
1.249 raeburn 1223: if (($env{'user.adv'}) || ($env{'user.author'})) {
1.252 bisitz 1224: my $path=$prefix.'/';
1225: foreach my $dir (split('/',$uri)) {
1.99 matthew 1226: if (! $dir) { next; }
1227: $path .= $dir;
1.252 bisitz 1228: if ($path eq $uri) {
1229: if ($skiplast) {
1230: $output.=$dir;
1.132 www 1231: last;
1.252 bisitz 1232: }
1233: } else {
1234: $path.='/';
1235: }
1.378 raeburn 1236: if ($path eq '/res/') {
1237: unless (&Apache::lonnet::allowed('bre',$path)) {
1238: $output.="$dir/";
1239: next;
1240: }
1241: }
1.157 albertel 1242: my $href_path = &HTML::Entities::encode($path,'<>&"');
1.252 bisitz 1243: &Apache::loncommon::inhibit_menu_check(\$href_path);
1244: if ($form) {
1245: my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
1.373 raeburn 1246: $output.=qq{<a href="$href"$onclick$target>$dir</a>/};
1.252 bisitz 1247: } else {
1.373 raeburn 1248: $output.=qq{<a href="$href_path"$onclick$target>$dir</a>/};
1.252 bisitz 1249: }
1250: }
1.35 www 1251: } else {
1.252 bisitz 1252: foreach my $dir (split('/',$uri)) {
1.149 albertel 1253: if (! $dir) { next; }
1.252 bisitz 1254: $output.=$dir.'/';
1255: }
1.34 www 1256: }
1.149 albertel 1257: if ($uri !~ m|/$|) { $output=~s|/$||; }
1.252 bisitz 1258: $output.='</span>';
1259:
1.304 foxr 1260:
1.252 bisitz 1261: return $output;
1.34 www 1262: }
1263:
1.85 www 1264: # --------------------- A function that generates a window for the spellchecker
1265:
1266: sub spellheader {
1.123 albertel 1267: my $start_page=
1268: &Apache::loncommon::start_page('Speller Suggestions',undef,
1.140 albertel 1269: {'only_body' => 1,
1270: 'js_ready' => 1,
1271: 'bgcolor' => '#DDDDDD',
1272: 'add_entries' => {
1273: 'onload' =>
1274: 'document.forms.spellcheckform.submit()',
1275: }
1276: });
1.123 albertel 1277: my $end_page=
1278: &Apache::loncommon::end_page({'js_ready' => 1});
1279:
1.105 www 1280: my $nothing=&javascript_nothing();
1.85 www 1281: return (<<ENDCHECK);
1282: <script type="text/javascript">
1.218 bisitz 1283: // <![CDATA[
1.92 albertel 1284: //<!-- BEGIN LON-CAPA Internal
1.85 www 1285: var checkwin;
1286:
1.140 albertel 1287: function spellcheckerwindow(string) {
1288: var esc_string = string.replace(/\"/g,'"');
1.105 www 1289: checkwin=window.open($nothing,'spellcheckwin','height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.154 albertel 1290: checkwin.document.writeln('$start_page<form name="spellcheckform" action="/adm/spellcheck" method="post"><input type="hidden" name="text" value="'+esc_string+'" /><\\/form>$end_page');
1.85 www 1291: checkwin.document.close();
1292: }
1.92 albertel 1293: // END LON-CAPA Internal -->
1.218 bisitz 1294: // ]]>
1.85 www 1295: </script>
1296: ENDCHECK
1297: }
1298:
1299: # ---------------------------------- Generate link to spell checker for a field
1300:
1301: sub spelllink {
1302: my ($form,$field)=@_;
1303: my $linktext=&mt('Check Spelling');
1304: return (<<ENDLINK);
1.140 albertel 1305: <a href="javascript:if (typeof(document.$form.onsubmit)!='undefined') { if (document.$form.onsubmit!=null) { document.$form.onsubmit();}};spellcheckerwindow(this.document.forms.$form.$field.value);">$linktext</a>
1.85 www 1306: ENDLINK
1307: }
1308:
1.281 raeburn 1309: # ------------------------------------------------- Output headers for CKEditor
1.124 albertel 1310:
1.52 www 1311: sub htmlareaheaders {
1.255 faziophi 1312: my $s="";
1.260 faziophi 1313: if (&htmlareabrowser()) {
1.255 faziophi 1314: $s.=(<<ENDEDITOR);
1315: <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
1316: ENDEDITOR
1317: }
1318: $s.=(<<ENDJQUERY);
1.389 raeburn 1319: <script type="text/javascript" src="/adm/jQuery/js/jquery-3.2.1.min.js"></script>
1320: <script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.12.1.custom.min.js"></script>
1321: <link rel="stylesheet" type="text/css" href="/adm/jQuery/css/smoothness/jquery-ui-1.12.1.custom.min.css" />
1.301 foxr 1322: <script type="text/javascript" src="/adm/jpicker/js/jpicker-1.1.6.min.js" >
1323: </script>
1324: <link rel="stylesheet" type="text/css" href="/adm/jpicker/css/jPicker-1.1.6.min.css" />
1.356 raeburn 1325: <script type="text/javascript" src="/adm/countdown/js/jquery.countdown.min.js"></script>
1.310 raeburn 1326: <link rel="stylesheet" type="text/css" href="/adm/countdown/css/jquery.countdown.css" />
1.320 foxr 1327:
1.323 foxr 1328: <script type="text/javascript" src="/adm/spellchecker/js/jquery.spellchecker.min.js"></script>
1.320 foxr 1329: <link rel="stylesheet" type="text/css" href="/adm/spellchecker/css/spellchecker.css" />
1.349 raeburn 1330: <script type="text/javascript" src="/adm/nicescroll/jquery.nicescroll.min.js"></script>
1.320 foxr 1331:
1.255 faziophi 1332: ENDJQUERY
1333: return $s;
1.52 www 1334: }
1335:
1.76 www 1336: # ----------------------------------------------------------------- Preferences
1337:
1.167 albertel 1338: # ------------------------------------------------- lang to use in html editor
1339: sub htmlarea_lang {
1340: my $lang='en';
1341: if (&mt('htmlarea_lang') ne 'htmlarea_lang') {
1342: $lang=&mt('htmlarea_lang');
1343: }
1344: return $lang;
1345: }
1346:
1.326 foxr 1347: # return javacsript to activate elements of .colorchooser with jpicker:
1348: # Caller is responsible for enclosing this in <script> tags:
1349: #
1350: sub color_picker {
1351: return '
1352: $(document).ready(function(){
1353: $.fn.jPicker.defaults.images.clientPath="/adm/jpicker/images/";
1354: $(".colorchooser").jPicker({window: { position: {x: "screenCenter", y: "bottom"}}});
1355: });';
1356: }
1357:
1.391 raeburn 1358: sub countdown {
1359:
1360: # Code to put a due date countdown in 'duedatecountdown' span.
1361: # This is currently located in the breadcrumb headers.
1362: # note that the dueDateLayout is internatinoalized below.
1363: # Here document is used to support the substitution into the javascript below.
1364: # ..which unforunately necessitates escaping the $'s in the javascript.
1365: # There are several times of importance
1366: #
1367: # serverDueDate - The absolute time at which the problem expires.
1368: # serverTime - The server's time when the problem finished computing.
1369: # clientTime - The client's time...as close to serverTime as possible.
1370: # The clientTime will be slightly later due to
1371: # 1. The latency between problem computation and
1372: # the first network action.
1373: # 2. The time required between the page load-start and the actual
1374: # initial javascript execution that got clientTime.
1375: # These are used as follows:
1376: # The difference between clientTime and serverTime are used to
1377: # correct for differences in clock settings between the browser's system and the
1378: # server's.
1379: #
1380: # The difference between clientTime and the time at which the ready() method
1381: # starts executing is used to estimate latencies for page load and submission.
1382: # Since this is an estimate, it is doubled. The latency estimate + one minute
1383: # is used to determine when the countdown timer turns red to warn the user
1384: # to think about submitting.
1385:
1386:
1387: my $dueDateLayout = &mt('Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn} [_1]',
1388: "<span id='submitearly'></span>");
1389: my $early = '- <b>'.&mt('Submit Early').'</b>';
1390: my $pastdue = '- <b>'.&mt('Past Due').'</b>';
1391: return <<"JAVASCRIPT";
1392:
1393: var documentReadyTime;
1394:
1395: \$(document).ready(function() {
1396: if (typeof(dueDate) != "undefined") {
1397: documentReadyTime = (new Date()).getTime();
1398: \$("#duedatecountdown").countdown({until: dueDate, compact: true,
1399: layout: "$dueDateLayout",
1400: onTick: function (periods) {
1401: var latencyEstimate = (documentReadyTime - clientTime) * 2;
1402: if(\$.countdown.periodsToSeconds(periods) < (300 + latencyEstimate)) {
1403: \$("#submitearly").html("$early");
1404: if (\$.countdown.periodsToSeconds(periods) < 1) {
1405: \$("#submitearly").html("$pastdue");
1406: }
1407: }
1408: if(\$.countdown.periodsToSeconds(periods) < (60 + latencyEstimate)) {
1409: \$(this).css("color", "red"); //Highlight last minute.
1410: }
1411: }
1412: });
1413: }
1414: });
1415:
1416: JAVASCRIPT
1417:
1418: }
1419:
1.72 www 1420: # ----------------------------------------- Script to activate only some fields
1421:
1422: sub htmlareaselectactive {
1.281 raeburn 1423: my ($args) = @_;
1.76 www 1424: unless (&htmlareabrowser()) { return ''; }
1.262 raeburn 1425: my $output='<script type="text/javascript" defer="defer">'."\n"
1.347 raeburn 1426: .'// <![CDATA['."\n"
1427: .'//<!-- BEGIN LON-CAPA Internal'."\n";
1.167 albertel 1428: my $lang = &htmlarea_lang();
1.281 raeburn 1429: my $fullpage = 'false';
1.282 raeburn 1430: my ($dragmath_prefix,$dragmath_helpicon,$dragmath_whitespace);
1.281 raeburn 1431: if (ref($args) eq 'HASH') {
1432: if (exists($args->{'lang'})) {
1433: if ($args->{'lang'} ne '') {
1434: $lang = $args->{'lang'};
1435: }
1436: }
1437: if (exists($args->{'fullpage'})) {
1438: if ($args->{'fullpage'} eq 'true') {
1439: $fullpage = $args->{'fullpage'};
1440: }
1441: }
1442: if (exists($args->{'dragmath'})) {
1443: if ($args->{'dragmath'} ne '') {
1444: $dragmath_prefix = $args->{'dragmath'};
1.282 raeburn 1445: $dragmath_helpicon=&Apache::loncommon::lonhttpdurl("/adm/help/help.png");
1446: $dragmath_whitespace=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/transparent1x1.gif");
1.281 raeburn 1447: }
1448: }
1449: }
1.343 bisitz 1450:
1451: my %lt = &Apache::lonlocal::texthash(
1452: 'plain' => 'Plain text',
1453: 'rich' => 'Rich formatting',
1454: 'plain_title' => 'Disable rich text formatting and edit in plain text',
1455: 'rich_title' => 'Enable rich text formatting (bold, italic, etc.)',
1456: );
1457:
1.255 faziophi 1458: $output.='
1459:
1460: function containsBlockHtml(id) {
1.281 raeburn 1461: var re = $("#"+id).html().search(/(?:\<\;|\<)(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)[\s]*((?:[\/]*[\s]*(?:\>\;|\>)|(?:\>\;|\>)[\s\S]*(?:\<\;|\<)\/[\s]*\1[\s]*\(?:\>\;|\>))/im);
1.255 faziophi 1462: return (re >= 0);
1463: }
1464:
1465: function startRichEditor(id) {
1.359 damieng 1466: // fix character entities inside <m>
1467: // NOTE: this is not fixing characters inside <parse>
1.360 damieng 1468: // NOTE: < and > inside <chem> should fix automatically because there should not be a letter after <.
1.359 damieng 1469: var ta = document.getElementById(id);
1470: var value = ta.value;
1471: var in_m = false; // in the m element
1472: var in_text = false; // in the text inside the m element
1473: var im = -1; // position of <m>
1474: var it = -1; // position of the text inside
1475: for (var i=0; i<value.length; i++) {
1476: if (value.substr(i, 2) == "<m") {
1477: // ignore previous <m> if found twice
1478: in_m = true;
1479: in_text = false;
1480: im = i;
1481: it = -1;
1482: } else if (in_m) {
1483: if (!in_text) {
1484: if (value.charAt(i) == ">") {
1485: in_text = true;
1486: it = i+1;
1487: }
1488: } else if (value.substr(i, 4) == "</m>") {
1489: in_m = false;
1490: var text = value.substr(it, i-it);
1491: var l1 = text.length;
1492: text = text.replace(/</g, "<");
1493: text = text.replace(/>/g, ">");
1494: var l2 = text.length;
1495: value = value.substr(0, it) + text + "</m>" + value.substr(i+4);
1496: i = i + (l2-l1);
1497: }
1498: }
1499: }
1500: ta.value = value;
1.255 faziophi 1501: CKEDITOR.replace(id,
1502: {
1.281 raeburn 1503: customConfig: "/ckeditor/loncapaconfig.js",
1504: language : "'.$lang.'",
1505: fullPage : '.$fullpage.',
1.255 faziophi 1506: }
1507: );
1508: }
1509:
1510: function destroyRichEditor(id) {
1511: CKEDITOR.instances[id].destroy();
1.360 damieng 1512: // replace character entities < and > in <m> and <chem>
1.359 damieng 1513: // and "&fctname(" by "&fctname("
1514: // and the quotes inside functions: "&fct(1, "a")" -> "&fct(1, "a")"
1515: var ta = document.getElementById(id);
1516: var value = ta.value;
1.360 damieng 1517: var in_element = false; // in the m or chem element
1518: var tagname = ""; // m or chem
1519: var in_text = false; // in the text inside the element
1520: var im = -1; // position of start tag
1.359 damieng 1521: var it = -1; // position of the text inside
1522: for (var i=0; i<value.length; i++) {
1.360 damieng 1523: if (value.substr(i, 2) == "<m" || value.substr(i, 5) == "<chem") {
1524: // ignore previous tags if found twice
1525: in_element = true;
1526: if (value.substr(i, 2) == "<m")
1527: tagname = "m";
1528: else
1529: tagname = "chem";
1.359 damieng 1530: in_text = false;
1531: im = i;
1532: it = -1;
1.360 damieng 1533: } else if (in_element) {
1.359 damieng 1534: if (!in_text) {
1535: if (value.charAt(i) == ">") {
1536: in_text = true;
1537: it = i+1;
1538: }
1.360 damieng 1539: } else if (value.substr(i, 3+tagname.length) == "</"+tagname+">") {
1540: in_element = false;
1.359 damieng 1541: var text = value.substr(it, i-it);
1542: var l1 = text.length;
1543: text = text.replace(/</g, "<");
1544: text = text.replace(/>/g, ">");
1545: var l2 = text.length;
1.360 damieng 1546: value = value.substr(0, it) + text + value.substr(i);
1.359 damieng 1547: i = i + (l2-l1);
1548: }
1549: }
1550: }
1551: // fix function names
1552: value = value.replace(/&([a-zA-Z_]+)\(/g, "&$1(");
1553: // fix quotes in functions
1554: var pos_next_fct = value.search(/&[a-zA-Z_]+\(/);
1555: var depth = 0;
1556: for (var i=0; i<value.length; i++) {
1557: if (i == pos_next_fct) {
1558: depth++;
1559: var sub = value.substring(i+1);
1560: var pos2 = sub.search(/&[a-zA-Z_]+\(/);
1561: if (pos2 == -1)
1562: pos_next_fct = -1;
1563: else
1564: pos_next_fct = i + 1 + pos2;
1565: } else if (depth > 0) {
1566: if (value.charAt(i) == ")")
1567: depth--;
1568: else if (value.substr(i, 6) == """)
1569: value = value.substr(0, i) + "\"" + value.substr(i+6);
1570: }
1571: }
1572: // replace the text value
1573: ta.value = value;
1.72 www 1574: }
1.255 faziophi 1575:
1576: function editorHandler(event) {
1577: var rawid = $(this).attr("id");
1.281 raeburn 1578: var id = new RegExp("LC_rt_(.*)").exec(rawid)[1];
1.255 faziophi 1579: event.preventDefault();
1.281 raeburn 1580: var rt_enabled = $(this).hasClass("LC_enable_rt");
1581: if (rt_enabled) {
1.255 faziophi 1582: startRichEditor(id);
1.343 bisitz 1583: $("#LC_rt_"+id).html("<b>« '.$lt{'plain'}.'</b>");
1584: $("#LC_rt_"+id).attr("title", "'.$lt{'plain_title'}.'");
1.255 faziophi 1585: $("#LC_rt_"+id).addClass("LC_disable_rt");
1586: $("#LC_rt_"+id).removeClass("LC_enable_rt");
1587: } else {
1588: destroyRichEditor(id);
1.343 bisitz 1589: $("#LC_rt_"+id).html("<b>'.$lt{'rich'}.' »</b>");
1590: $("#LC_rt_"+id).attr("title", "'.$lt{'rich_title'}.'");
1.255 faziophi 1591: $("#LC_rt_"+id).addClass("LC_enable_rt");
1592: $("#LC_rt_"+id).removeClass("LC_disable_rt");
1.281 raeburn 1593: }';
1594: if ($dragmath_prefix ne '') {
1595: $output .= "\n var visible = '';
1596: if (rt_enabled) {
1597: visible = 'none';
1598: }
1599: editmath_visibility(id,visible);\n";
1600: }
1601: $output .= '
1602: }
1.255 faziophi 1603: $(document).ready(function(){
1604: $(".LC_richAlwaysOn").each(function() {
1605: startRichEditor($(this).attr("id"));
1606: });
1607: $(".LC_richDetectHtml").each(function() {
1608: var id = $(this).attr("id");
1.281 raeburn 1609: var rt_enabled = containsBlockHtml(id);
1610: if(rt_enabled) {
1.343 bisitz 1611: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"'.$lt{'plain_title'}.'\" class=\"LC_disable_rt\"><b>« '.$lt{'plain'}.'</b></a></div>");
1.255 faziophi 1612: startRichEditor(id);
1.281 raeburn 1613: $("#LC_rt_"+id).click(editorHandler);
1.255 faziophi 1614: }
1615: else {
1.343 bisitz 1616: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"'.$lt{'rich_title'}.'\" class=\"LC_enable_rt\"><b>'.$lt{'rich'}.' »</b></a></div>");
1.255 faziophi 1617: $("#LC_rt_"+id).click(editorHandler);
1.281 raeburn 1618: }';
1619: if ($dragmath_prefix ne '') {
1620: $output .= "\n var visible = '';
1621: if (rt_enabled) {
1622: visible = 'none';
1623: }
1624: editmath_visibility(id,visible);\n";
1625: }
1626: $output .= '
1.255 faziophi 1627: });
1628: $(".LC_richDefaultOn").each(function() {
1629: var id = $(this).attr("id");
1.343 bisitz 1630: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"'.$lt{'plain_title'}.'\" class=\"LC_disable_rt\"><b>« '.$lt{'plain'}.'</b></a></div>");
1.255 faziophi 1631: startRichEditor(id);
1632: $("#LC_rt_"+id).click(editorHandler);
1633: });
1634: $(".LC_richDefaultOff").each(function() {
1635: var id = $(this).attr("id");
1.343 bisitz 1636: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"'.$lt{'rich_title'}.'\" class=\"LC_enable_rt\"><b>'.$lt{'rich'}.' »</b></a></div>");
1.281 raeburn 1637: $("#LC_rt_"+id).click(editorHandler);
1.255 faziophi 1638: });
1.301 foxr 1639:
1.304 foxr 1640:
1.302 foxr 1641: });
1.281 raeburn 1642: ';
1.391 raeburn 1643: $output .= &color_picker();
1.306 foxr 1644:
1.391 raeburn 1645: $output .= &countdown();
1.307 foxr 1646:
1.391 raeburn 1647: $output .= <<"JAVASCRIPT";
1.322 foxr 1648:
1649: /* This code describes the spellcheck options that will be used for
1650: items with class 'spellchecked'. It is necessary for those objects'
1651: to explicitly request checking (e.g. onblur is a nice event for that).
1652: */
1653: \$(document).ready(function() {
1654: \$(".spellchecked").spellchecker({
1655: url: "/ajax/spellcheck",
1656: lang: "en",
1657: engine: "pspell",
1658: suggestionBoxPosition: "below",
1659: innerDocument: true
1660: });
1661: \$("textarea.spellchecked").spellchecker({
1662: url: "/ajax/spellcheck",
1663: lang: "en",
1664: engine: "pspell",
1665: suggestionBoxPosition: "below",
1666: innerDocument: true
1667: });
1668:
1669: });
1670:
1.325 foxr 1671: /* the muli colored editor can generate spellcheck with language 'none'
1672: to disable spellcheck as well
1673: */
1.324 foxr 1674: function doSpellcheck(element, lang) {
1.325 foxr 1675: if (lang != 'none') {
1676: \$(element).spellchecker('option', {lang: lang});
1677: \$(element).spellchecker('check');
1678: }
1.324 foxr 1679: }
1680:
1.322 foxr 1681:
1.306 foxr 1682: JAVASCRIPT
1.281 raeburn 1683: if ($dragmath_prefix ne '') {
1684: $output .= '
1685:
1686: function editmath_visibility(id,value) {
1687:
1688: if ((id == "") || (id == null)) {
1689: return;
1690: }
1691: var mathid = "'.$dragmath_prefix.'_"+id;
1692: mathele = document.getElementById(mathid);
1693: if (mathele == null) {
1694: return;
1695: }
1696: mathele.style.display = value;
1.282 raeburn 1697: var mathhelpicon = "'.$dragmath_prefix.'helpicon'.'_"+id;
1698: mathhelpiconele = document.getElementById(mathhelpicon);
1699: if (mathhelpiconele == null) {
1700: return;
1701: }
1702: if (value == "none") {
1703: mathhelpiconele.src = "'.$dragmath_whitespace.'";
1704: } else {
1705: mathhelpiconele.src = "'.$dragmath_helpicon.'";
1706: }
1.281 raeburn 1707: }
1708: ';
1709:
1710: }
1.218 bisitz 1711: $output.="\nwindow.status='Activated Editfields';\n"
1.347 raeburn 1712: .'// END LON-CAPA Internal -->'."\n"
1.230 bisitz 1713: .'// ]]>'."\n"
1.281 raeburn 1714: .'</script>';
1.72 www 1715: return $output;
1716: }
1717:
1.61 www 1718: # --------------------------------------------------------------------- Blocked
1719:
1720: sub htmlareablocked {
1.104 albertel 1721: unless ($env{'environment.wysiwygeditor'} eq 'on') { return 1; }
1.71 www 1722: return 0;
1.52 www 1723: }
1724:
1725: # ---------------------------------------- Browser capable of running HTMLArea?
1726:
1727: sub htmlareabrowser {
1728: return 1;
1729: }
1.53 matthew 1730:
1.287 www 1731: #
1732: # Should the "return to content" link be shown?
1733: #
1734:
1735: sub show_return_link {
1.289 www 1736:
1737: unless ($env{'request.course.id'}) { return 0; }
1738: if ($env{'request.noversionuri'}=~m{^/priv/} ||
1.318 raeburn 1739: $env{'request.uri'}=~m{^/priv/}) { return 1; }
1.410 ! raeburn 1740: return if (($env{'request.noversionuri'} eq '/adm/supplemental') &&
! 1741: ($env{'form.folder'} ne 'supplemental'));
! 1742: return if (($env{'form.folderpath'} ne '') &&
! 1743: (($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) ||
! 1744: ($env{'request.noversionuri'} =~ m{^/public/$match_domain/$match_courseid/syllabus$})));
1.371 raeburn 1745: return if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
1746: (!$env{'request.role.adv'}));
1.404 raeburn 1747: if (($env{'request.noversionuri'} =~ m{^/adm/viewclasslist($|\?)})
1.287 www 1748: || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
1749:
1750: return if ($env{'form.register'});
1751: }
1.410 ! raeburn 1752: if ((($env{'request.symb'} ne '') || ($env{'form.folderpath'} ne '')) &&
! 1753: ($env{'request.noversionuri'} =~m{^/adm/coursedocs/showdoc/uploaded/($match_domain)/($match_courseid)/(docs|supplemental)/})) {
! 1754: my ($cdom,$cnum,$area) = ($1,$2,$3);
! 1755: if (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $cdom) &&
! 1756: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $cnum)) {
! 1757: if (($env{'request.symb'}) && ($area eq 'docs')) {
! 1758: my ($map,$resid,$url) = &Apache::lonnet::decode_symb($env{'request.symb'});
! 1759: return if ($env{'request.noversionuri'} eq '/adm/coursedocs/showdoc/'.$url);
! 1760: } elsif (($env{'form.folderpath'}) && ($area eq 'supplemental')) {
! 1761: return;
! 1762: }
! 1763: }
! 1764: }
1.287 www 1765: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
1766: $env{'request.symb'} eq '')
1767: ||
1768: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
1769: ||
1770: (($env{'request.noversionuri'}=~/^\/adm\//) &&
1771: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
1772: ($env{'request.noversionuri'}!~
1.386 raeburn 1773: m{^/adm/.*/(smppg|bulletinboard|ext\.tool)($|\?)})
1.287 www 1774: ));
1775: }
1776:
1777:
1.304 foxr 1778: ##
1779: # Set the dueDate variable...note this is done in the timezone
1780: # of the browser.
1781: #
1782: # @param epoch relative time at which the problem is due.
1783: #
1784: # @return the javascript fragment to set the date:
1785: #
1786: sub set_due_date {
1787: my $dueStamp = shift;
1788: my $duems = $dueStamp * 1000; # Javascript Date object needs ms not seconds.
1789:
1790: my $now = time()*1000;
1791:
1792: # This slightly obscure bit of javascript sets the dueDate variable
1793: # to the time in the browser at which the problem was due.
1794: # The code should correct for gross differences between the server
1795: # and client's time setting
1796:
1.315 raeburn 1797: return <<"END";
1798:
1799: <script type="text/javascript">
1.304 foxr 1800: //<![CDATA[
1801: var serverDueDate = $duems;
1802: var serverTime = $now;
1803: var clientTime = (new Date()).getTime();
1804: var dueDate = new Date(serverDueDate + (clientTime - serverTime));
1805:
1806: //]]>
1807: </script>
1808:
1.315 raeburn 1809: END
1.307 foxr 1810: }
1811: ##
1812: # Sets the time at which the problem finished computing.
1813: # This just updates the serverTime and clientTime variables above.
1814: # Calling this in e.g. end_problem provides a better estimate of the
1815: # difference beetween the server and client time setting as
1816: # the difference contains less of the latency/problem compute time.
1817: #
1818: sub set_compute_end_time {
1819:
1820: my $now = time()*1000; # Javascript times are in ms.
1.316 raeburn 1821: return <<"END";
1822:
1823: <script type="text/javascript">
1.307 foxr 1824: //<![CDATA[
1825: serverTime = $now;
1826: clientTime = (new Date()).getTime();
1827: //]]>
1828: </script>
1829:
1.316 raeburn 1830: END
1.304 foxr 1831: }
1832:
1.409 raeburn 1833: ##
1834: # Client-side javascript to convert any dashes in text pasted
1835: # into textbox(es) for numericalresponse item(s) to a standard
1836: # minus, i.e., - . Calls to dash_to_minus_js() in end_problem()
1837: # and in loncommon::endbodytag() for a .page (arg: dashjs => 1)
1838: #
1839: # Will apply to any input tag with class: LC_numresponse_text.
1840: # Currently set in start_textline for numericalresponse items.
1841: #
1842:
1843: sub dash_to_minus_js {
1844: return <<'ENDJS';
1845:
1846: <script type="text/javascript">
1847: //<![CDATA[
1848: //<!-- BEGIN LON-CAPA Internal
1849: document.addEventListener("DOMContentLoaded", (event) => {
1850: const numresp = document.querySelectorAll("input.LC_numresponse_text");
1851: if (numresp.length > 0) {
1852: numresp.forEach((el) => {
1853: el.addEventListener("paste", (e) => {
1854: e.preventDefault();
1855: e.stopPropagation();
1856: let p = (e.clipboardData || window.clipboardData).getData("text");
1857: p.toString();
1858: p = p.replace(/\p{Dash}/gu, '-');
1859: putInText(p);
1860: });
1861: });
1862: }
1863: const putInText = (newText, el = document.activeElement) => {
1864: const [start, end] = [el.selectionStart, el.selectionEnd];
1865: el.setRangeText(newText, start, end, 'end');
1866: }
1867: });
1868: // END LON-CAPA Internal -->
1869: //]]>
1870: </script>
1871:
1872: ENDJS
1873: }
1874:
1.53 matthew 1875: ############################################################
1876: ############################################################
1877:
1878: =pod
1879:
1.309 raeburn 1880: =item &breadcrumbs()
1.53 matthew 1881:
1882: Compiles the previously registered breadcrumbs into an series of links.
1883: Additionally supports a 'component', which will be displayed on the
1.223 droeschl 1884: right side of the breadcrumbs enclosing div (without a link).
1.53 matthew 1885: A link to help for the component will be included if one is specified.
1886:
1887: All inputs can be undef without problems.
1888:
1.361 musolffc 1889: =over
1890:
1891: =item Inputs:
1892:
1893: =over
1894:
1895: =item $component
1896:
1897: the text on the right side of the breadcrumbs trail
1898:
1899: =item $component_help
1900:
1.365 raeburn 1901: the help item filename (without .tex extension).
1902:
1.361 musolffc 1903: =item $menulink
1904:
1905: boolean, controls whether to include a link to /adm/menu
1906:
1907: =item $helplink
1908:
1909: if 'nohelp' don't include the orange help link
1.362 raeburn 1910:
1.361 musolffc 1911: =item $css_class
1912:
1913: optional name for the class to apply to the table for CSS
1.362 raeburn 1914:
1.361 musolffc 1915: =item $no_mt
1916:
1917: optional flag, 1 if &mt() is _not_ to be applied to $component when including the text on the right
1918:
1.365 raeburn 1919: =item $CourseBreadcrumbs
1920:
1921: optional flag, 1 if &breadcrumbs called from &docs_breadcrumbs, because breadcrumbs are being
1922: used to display hierarchy for current folder shown in the Course Editor.
1923:
1924: =item $topic_help
1925:
1926: optional help item to be displayed on right side of the breadcrumbs row, using
1927: loncommon::help_open_topic() to generate the link.
1928:
1929: =item $topic_help_text
1930:
1931: text to include in the link in the optional help item ($topic_help) on the right
1932: side of the breadcrumbs row.
1933:
1.403 raeburn 1934: =item $links_target
1935:
1936: optionally includes the target (_top, _parent or _self) for (i) initial
1937: $menulink item in the breadcrumbs (if present), (ii) return to last location
1938: (if present), and (iii) help item at the right side of breadcrumbs menu,
1939: created by loncommon::help_open_topic() or loncommon::help_open_menu().
1940:
1.361 musolffc 1941: =back
1942:
1943: =back
1944:
1.53 matthew 1945: Returns a string containing breadcrumbs for the current page.
1946:
1.309 raeburn 1947: =item &clear_breadcrumbs()
1.53 matthew 1948:
1949: Clears the previously stored breadcrumbs.
1950:
1.309 raeburn 1951: =item &add_breadcrumb()
1.53 matthew 1952:
1953: Pushes a breadcrumb on the stack of crumbs.
1954:
1955: input: $breadcrumb, a hash reference. The keys 'href','title', and 'text'
1956: are required. If present the keys 'faq' and 'bug' will be used to provide
1.156 albertel 1957: links to the FAQ and bug sites. If the key 'no_mt' is present the 'title'
1958: and 'text' values won't be sent through &mt()
1.53 matthew 1959:
1960: returns: nothing
1961:
1962: =cut
1963:
1964: ############################################################
1965: ############################################################
1966: {
1967: my @Crumbs;
1.242 droeschl 1968: my %tools = ();
1.57 matthew 1969:
1.53 matthew 1970: sub breadcrumbs {
1.314 raeburn 1971: my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt,
1.403 raeburn 1972: $CourseBreadcrumbs,$topic_help,$topic_help_text,$links_target) = @_;
1.53 matthew 1973: #
1.215 droeschl 1974: $css_class ||= 'LC_breadcrumbs';
1.205 amueller 1975:
1.57 matthew 1976: # Make the faq and bug data cascade
1.223 droeschl 1977: my $faq = '';
1978: my $bug = '';
1979: my $help = '';
1.215 droeschl 1980: # Crumb Symbol
1.223 droeschl 1981: my $crumbsymbol = '»';
1.60 www 1982: # The last breadcrumb does not have a link, so handle it separately.
1.53 matthew 1983: my $last = pop(@Crumbs);
1.57 matthew 1984: #
1.70 matthew 1985: # The first one should be the course or a menu link
1.215 droeschl 1986: if (!defined($menulink)) { $menulink=1; }
1.70 matthew 1987: if ($menulink) {
1.399 raeburn 1988: if ($env{'request.course.id'}) {
1989: my ($menucoll,$deeplinkmenu,$menuref) = &Apache::loncommon::menucoll_in_effect();
1990: if (($menucoll) && (ref($menuref) eq 'HASH')) {
1991: if ($menuref->{'main'} eq 'n') {
1992: undef($menulink);
1993: }
1994: }
1995: }
1996: }
1997: if ($menulink) {
1.70 matthew 1998: my $description = 'Menu';
1.172 raeburn 1999: my $no_mt_descr = 0;
1.269 raeburn 2000: if ((exists($env{'request.course.id'})) &&
2001: ($env{'request.course.id'} ne '') &&
2002: ($env{'course.'.$env{'request.course.id'}.'.description'} ne '')) {
1.70 matthew 2003: $description =
1.104 albertel 2004: $env{'course.'.$env{'request.course.id'}.'.description'};
1.172 raeburn 2005: $no_mt_descr = 1;
1.330 raeburn 2006: if ($env{'request.noversionuri'} =~
1.382 raeburn 2007: m{^/?public/($match_domain)/($match_courseid)/syllabus$}) {
1.330 raeburn 2008: unless (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $1) &&
1.332 raeburn 2009: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $2)) {
1.330 raeburn 2010: $description = 'Menu';
2011: $no_mt_descr = 0;
2012: }
2013: }
1.70 matthew 2014: }
1.393 raeburn 2015: my $target = '_top';
1.403 raeburn 2016: if ($links_target) {
2017: $target = $links_target;
2018: } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
2019: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1.393 raeburn 2020: $target='';
1.392 raeburn 2021: }
1.215 droeschl 2022: $menulink = { href =>'/adm/menu',
2023: title =>'Go to main menu',
1.392 raeburn 2024: target =>$target,
1.215 droeschl 2025: text =>$description,
2026: no_mt =>$no_mt_descr, };
2027: if($last) {
2028: #$last set, so we have some crumbs
2029: unshift(@Crumbs,$menulink);
2030: } else {
2031: #only menulink crumb present
2032: $last = $menulink;
2033: }
1.53 matthew 2034: }
1.287 www 2035: my $links;
1.330 raeburn 2036: if ((&show_return_link) && (!$CourseBreadcrumbs) && (ref($last) eq 'HASH')) {
1.299 raeburn 2037: my $alttext = &mt('Go Back');
1.355 raeburn 2038: my $hashref = { href => '/adm/flip?postdata=return:',
2039: title => &mt('Back to most recent content resource'),
2040: class => 'LC_menubuttons_link',
2041: };
1.403 raeburn 2042: if ($links_target) {
2043: $hashref->{'target'} = $links_target;
1.355 raeburn 2044: }
1.317 raeburn 2045: $links=&htmltag( 'a','<img src="/res/adm/pages/tolastloc.png" alt="'.$alttext.'" class="LC_icon" />',
1.355 raeburn 2046: $hashref);
1.299 raeburn 2047: $links=&htmltag('li',$links);
1.287 www 2048: }
2049: $links.= join "",
1.261 droeschl 2050: map {
2051: $faq = $_->{'faq'} if (exists($_->{'faq'}));
2052: $bug = $_->{'bug'} if (exists($_->{'bug'}));
2053: $help = $_->{'help'} if (exists($_->{'help'}));
2054:
1.287 www 2055: my $result = $_->{no_mt} ? $_->{text} : &mt($_->{text});
1.261 droeschl 2056:
2057: if ($_->{href}){
1.287 www 2058: $result = &htmltag( 'a', $result,
1.261 droeschl 2059: { href => $_->{href},
1.287 www 2060: title => $_->{no_mt} ? $_->{title} : &mt($_->{title}),
1.261 droeschl 2061: target => $_->{target}, });
2062: }
2063:
1.287 www 2064: $result = &htmltag( 'li', "$result $crumbsymbol");
1.261 droeschl 2065: } @Crumbs;
1.223 droeschl 2066:
2067: #should the last Element be translated?
1.261 droeschl 2068:
2069: my $lasttext = $last->{'no_mt'} ? $last->{'text'}
2070: : mt( $last->{'text'} );
2071:
1.274 droeschl 2072: # last breadcrumb is the first order heading of a page
2073: # for course breadcrumbs it's just bold
1.304 foxr 2074:
1.330 raeburn 2075: if ($lasttext ne '') {
2076: $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
2077: $lasttext), {title => $lasttext});
2078: }
1.223 droeschl 2079:
1.54 matthew 2080: my $icons = '';
1.223 droeschl 2081: $faq = $last->{'faq'} if (exists($last->{'faq'}));
2082: $bug = $last->{'bug'} if (exists($last->{'bug'}));
1.106 www 2083: $help = $last->{'help'} if (exists($last->{'help'}));
2084: $component_help=($component_help?$component_help:$help);
1.145 albertel 2085: # if ($faq ne '') {
2086: # $icons .= &Apache::loncommon::help_open_faq($faq);
2087: # }
1.79 raeburn 2088: # if ($bug ne '') {
2089: # $icons .= &Apache::loncommon::help_open_bug($bug);
2090: # }
1.223 droeschl 2091: if ($faq ne '' || $component_help ne '' || $bug ne '') {
2092: $icons .= &Apache::loncommon::help_open_menu($component,
2093: $component_help,
1.403 raeburn 2094: $faq,$bug,'','','','',
2095: $links_target);
1.223 droeschl 2096: }
1.364 raeburn 2097: if ($topic_help && $topic_help_text) {
2098: $icons .= ' '.&Apache::loncommon::help_open_topic($topic_help,&mt($topic_help_text),'',
1.403 raeburn 2099: undef,600,'',$links_target);
1.364 raeburn 2100: }
1.54 matthew 2101: #
1.304 foxr 2102:
1.205 amueller 2103:
1.330 raeburn 2104: if ($links ne '') {
2105: unless ($CourseBreadcrumbs) {
2106: $links = &htmltag('ol', $links, { id => "LC_MenuBreadcrumbs" });
2107: } else {
2108: $links = &htmltag('ul', $links, { class => "LC_CourseBreadcrumbs" });
2109: }
1.53 matthew 2110: }
1.223 droeschl 2111:
1.304 foxr 2112:
1.364 raeburn 2113: if (($component) || ($topic_help && $topic_help_text)) {
1.287 www 2114: $links = &htmltag('span',
1.223 droeschl 2115: ( $no_mt ? $component : mt($component) ).
2116: ( $icons ? $icons : '' ),
2117: { class => 'LC_breadcrumbs_component' } )
1.304 foxr 2118: .$links
2119: ;
1.223 droeschl 2120: }
1.339 raeburn 2121: my $nav_and_tools = 0;
2122: foreach my $item ('navigation','tools') {
2123: if (ref($tools{$item}) eq 'ARRAY') {
2124: $nav_and_tools += scalar(@{$tools{$item}})
2125: }
2126: }
2127: if (($links ne '') || ($nav_and_tools)) {
2128: &render_tools(\$links);
2129: $links = &htmltag('div', $links,
2130: { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;
2131: }
2132: my $adv_tools = 0;
2133: if (ref($tools{'advtools'}) eq 'ARRAY') {
2134: $adv_tools = scalar(@{$tools{'advtools'}});
2135: }
2136: if (($links ne '') || ($adv_tools)) {
2137: &render_advtools(\$links);
2138: }
1.223 droeschl 2139:
1.53 matthew 2140: # Return the @Crumbs stack to what we started with
2141: push(@Crumbs,$last);
2142: shift(@Crumbs);
1.304 foxr 2143:
2144:
1.223 droeschl 2145: # Return the breadcrumb's line
1.304 foxr 2146:
2147:
2148:
1.223 droeschl 2149: return "$links";
1.53 matthew 2150: }
2151:
2152: sub clear_breadcrumbs {
2153: undef(@Crumbs);
1.242 droeschl 2154: undef(%tools);
1.53 matthew 2155: }
2156:
2157: sub add_breadcrumb {
1.232 raeburn 2158: push(@Crumbs,@_);
1.53 matthew 2159: }
1.242 droeschl 2160:
1.309 raeburn 2161: =item &add_breadcrumb_tool($category, $html)
1.261 droeschl 2162:
2163: Adds $html to $category of the breadcrumb toolbar container.
2164:
2165: $html is usually a link to a page that invokes a function on the currently
2166: displayed data (e.g. print when viewing a problem)
2167:
1.361 musolffc 2168: =over
2169:
2170: =item Currently there are 3 possible values for $category:
1.261 droeschl 2171:
2172: =over
2173:
2174: =item navigation
2175: left of breadcrumbs line
2176:
2177: =item tools
1.314 raeburn 2178: remaining items in right of breadcrumbs line
1.261 droeschl 2179:
2180: =item advtools
2181: advanced tools shown in a separate box below breadcrumbs line
2182:
2183: =back
1.361 musolffc 2184:
2185: =back
2186:
1.261 droeschl 2187: returns: nothing
2188:
2189: =cut
1.242 droeschl 2190:
2191: sub add_breadcrumb_tool {
1.261 droeschl 2192: my ($category, @html) = @_;
2193: return unless @html;
1.285 raeburn 2194: if (!keys(%tools)) {
1.261 droeschl 2195: %tools = ( navigation => [], tools => [], advtools => []);
1.242 droeschl 2196: }
1.261 droeschl 2197:
2198: #this cleans data received from lonmenu::innerregister
2199: @html = grep {defined $_ && $_ ne ''} @html;
2200: for (@html) {
2201: s/align="(right|left)"//;
1.288 www 2202: # s/<span.*?\/span>// if $category ne 'advtools';
1.261 droeschl 2203: }
2204:
2205: push @{$tools{$category}}, @html;
1.242 droeschl 2206: }
2207:
1.309 raeburn 2208: =item &clear_breadcrumb_tools()
1.261 droeschl 2209:
2210: Clears the breadcrumb toolbar container.
2211:
2212: returns: nothing
2213:
2214: =cut
2215:
1.245 droeschl 2216: sub clear_breadcrumb_tools {
2217: undef(%tools);
2218: }
2219:
1.368 raeburn 2220: =item ¤t_breadcrumb_tools()
2221:
2222: returns: a hash containing the current breadcrumb tools.
2223:
2224: =cut
2225:
2226: sub current_breadcrumb_tools {
2227: return %tools;
2228: }
2229:
1.309 raeburn 2230: =item &render_tools(\$breadcrumbs)
1.261 droeschl 2231:
2232: Creates html for breadcrumb tools (categories navigation and tools) and inserts
2233: \$breadcrumbs at the correct position.
2234:
1.361 musolffc 2235: =over
2236:
2237: =item input:
2238:
2239: =over
2240:
2241: =item \$breadcrumbs - a reference to the string containing prepared breadcrumbs.
2242:
2243: =back
2244:
2245: =back
1.261 droeschl 2246:
2247: returns: nothing
1.309 raeburn 2248:
1.261 droeschl 2249: =cut
2250:
2251: #TODO might split this in separate functions for each category
2252: sub render_tools {
2253: my ($breadcrumbs) = @_;
1.285 raeburn 2254: return unless (keys(%tools));
1.261 droeschl 2255:
2256: my $navigation = list_from_array($tools{navigation},
2257: { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
2258: my $tools = list_from_array($tools{tools},
2259: { listattr => { class=>"LC_breadcrumb_tools_tools" } });
2260: $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs],
2261: { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });
2262: }
2263:
1.309 raeburn 2264: =pod
2265:
2266: =item &render_advtools(\$breadcrumbs)
1.261 droeschl 2267:
2268: Creates html for advanced tools (category advtools) and inserts \$breadcrumbs
2269: at the correct position.
2270:
1.361 musolffc 2271: =over
2272:
2273: =item input:
2274:
2275: =over
2276:
2277: =item \$breadcrumbs - a reference to the string containing prepared breadcrumbs (after render_tools call).
2278:
2279: =back
2280:
2281: =back
1.261 droeschl 2282:
2283: returns: nothing
1.309 raeburn 2284:
1.261 droeschl 2285: =cut
2286:
2287: sub render_advtools {
2288: my ($breadcrumbs) = @_;
2289: return unless (defined $tools{'advtools'})
2290: and (scalar(@{$tools{'advtools'}}) > 0);
2291:
2292: $$breadcrumbs .= Apache::loncommon::head_subbox(
2293: funclist_from_array($tools{'advtools'}) );
1.242 droeschl 2294: }
1.53 matthew 2295:
1.57 matthew 2296: } # End of scope for @Crumbs
1.53 matthew 2297:
1.331 raeburn 2298: sub docs_breadcrumbs {
1.405 raeburn 2299: my ($allowed,$crstype,$contenteditor,$title,$precleared,$checklinkprot)=@_;
1.342 raeburn 2300: my ($folderpath,@folders,$supplementalflag);
1.340 raeburn 2301: @folders = split('&',$env{'form.folderpath'});
1.342 raeburn 2302: if ($env{'form.folderpath'} =~ /^supplemental/) {
2303: $supplementalflag = 1;
2304: }
1.331 raeburn 2305: my $plain='';
1.336 raeburn 2306: my $container = 'sequence';
1.331 raeburn 2307: my ($randompick,$isencrypted,$ishidden,$is_random_order) = (-1,0,0,0);
1.332 raeburn 2308: my @docs_crumbs;
1.331 raeburn 2309: while (@folders) {
2310: my $folder=shift(@folders);
2311: my $foldername=shift(@folders);
2312: if ($folderpath) {$folderpath.='&';}
2313: $folderpath.=$folder.'&'.$foldername;
1.380 raeburn 2314: my $url = $env{'request.use_absolute'};
1.331 raeburn 2315: if ($allowed) {
1.380 raeburn 2316: $url .= '/adm/coursedocs?folderpath=';
1.331 raeburn 2317: } else {
1.380 raeburn 2318: $url .= '/adm/supplemental?folderpath=';
1.331 raeburn 2319: }
2320: $url .= &escape($folderpath);
2321: my $name=&unescape($foldername);
1.336 raeburn 2322: # each of randompick number, hidden, encrypted, random order, is_page
2323: # are appended with ":"s to the foldername
2324: $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)\:?(\d*)$//;
1.408 raeburn 2325: if ($contenteditor) {
1.407 raeburn 2326: if ($supplementalflag) {
2327: if ($2) { $ishidden=1; }
2328: } else {
1.342 raeburn 2329: if ($1 ne '') {
2330: $randompick=$1;
2331: } else {
2332: $randompick=-1;
2333: }
2334: if ($2) { $ishidden=1; }
2335: if ($3) { $isencrypted=1; }
2336: if ($4 ne '') { $is_random_order = 1; }
2337: if ($5 == 1) {$container = 'page'; }
1.331 raeburn 2338: }
2339: }
2340: if ($folder eq 'supplemental') {
1.345 raeburn 2341: $name = &mt('Supplemental Content');
1.331 raeburn 2342: }
2343: if ($contenteditor) {
2344: $plain.=$name.' > ';
2345: }
1.332 raeburn 2346: push(@docs_crumbs,
1.331 raeburn 2347: {'href' => $url,
2348: 'title' => $name,
2349: 'text' => $name,
2350: 'no_mt' => 1,
2351: });
2352: }
1.333 raeburn 2353: if ($title) {
2354: push(@docs_crumbs,
2355: {'title' => $title,
2356: 'text' => $title,
2357: 'no_mt' => 1,}
2358: );
2359: }
1.332 raeburn 2360: if (wantarray) {
2361: unless ($precleared) {
2362: &clear_breadcrumbs();
2363: }
2364: &add_breadcrumb(@docs_crumbs);
2365: if ($contenteditor) {
2366: $plain=~s/\>\;\s*$//;
2367: }
2368: my $menulink = 0;
1.410 ! raeburn 2369: if (!$allowed && !$contenteditor && !$supplementalflag) {
1.332 raeburn 2370: $menulink = 1;
2371: }
1.405 raeburn 2372: if ($checklinkprot) {
2373: if ($env{'request.deeplink.login'}) {
2374: my $linkprotout = &Apache::lonmenu::linkprot_exit();
2375: if ($linkprotout) {
2376: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
2377: }
2378: }
2379: }
1.332 raeburn 2380: return (&breadcrumbs(undef,undef,$menulink,'nohelp',undef,undef,
2381: $contenteditor),
2382: $randompick,$ishidden,$isencrypted,$plain,
1.336 raeburn 2383: $is_random_order,$container);
1.331 raeburn 2384: } else {
1.332 raeburn 2385: return \@docs_crumbs;
1.331 raeburn 2386: }
2387: }
2388:
1.53 matthew 2389: ############################################################
2390: ############################################################
2391:
1.112 raeburn 2392: # Nested table routines.
2393: #
2394: # Routines to display form items in a multi-row table with 2 columns.
2395: # Uses nested tables to divide form elements into segments.
2396: # For examples of use see loncom/interface/lonnotify.pm
2397: #
2398: # Can be used in following order: ...
2399: # &start_pick_box()
2400: # row1
2401: # row2
2402: # row3 ... etc.
1.173 raeburn 2403: # &submit_row()
1.161 raeburn 2404: # &end_pick_box()
1.112 raeburn 2405: #
2406: # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
2407: # &status_select_row and &email_default_row
2408: #
2409: # Can also be used in following order:
2410: #
2411: # &start_pick_box()
2412: # &row_title()
2413: # &row_closure()
2414: # &row_title()
2415: # &row_closure() ... etc.
2416: # &submit_row()
2417: # &end_pick_box()
2418: #
2419: # In general a &submit_row() call should proceed the call to &end_pick_box(),
2420: # as this routine adds a button for form submission.
1.113 raeburn 2421: # &submit_row() does not require a &row_closure after it.
1.112 raeburn 2422: #
2423: # &start_pick_box() creates a bounding table with 1-pixel wide black border.
2424: # rows should be placed between calls to &start_pick_box() and &end_pick_box.
2425: #
2426: # &row_title() adds a title in the left column for each segment.
2427: # &row_closure() closes a row with a 1-pixel wide black line.
2428: #
2429: # &role_select_row() provides a select box from which to choose 1 or more roles
2430: # &course_select_row provides ways of picking groups of courses
2431: # radio buttons: all, by category or by picking from a course picker pop-up
2432: # note: by category option is only displayed if a domain has implemented
2433: # selection by year, semester, department, number etc.
2434: #
2435: # &status_select_row() provides a select box from which to choose 1 or more
2436: # access types (current access, prior access, and future access)
2437: #
2438: # &email_default_row() provides text boxes for default e-mail suffixes for
2439: # different authentication types in a domain.
2440: #
2441: # &row_title() and &row_closure() are called internally by the &*_select_row
2442: # routines, but can also be called directly to start and end rows which have
2443: # needs that are not accommodated by the *_select_row() routines.
2444:
1.193 bisitz 2445: { # Start: row_count block for pick_box
2446: my @row_count;
2447:
1.112 raeburn 2448: sub start_pick_box {
1.313 raeburn 2449: my ($css_class,$id) = @_;
1.142 albertel 2450: if (defined($css_class)) {
2451: $css_class = 'class="'.$css_class.'"';
2452: } else {
2453: $css_class= 'class="LC_pick_box"';
2454: }
1.313 raeburn 2455: my $table_id;
2456: if (defined($id)) {
2457: $table_id = ' id="'.$id.'"';
2458: }
1.193 bisitz 2459: unshift(@row_count,0);
1.112 raeburn 2460: my $output = <<"END";
1.313 raeburn 2461: <table $css_class $table_id>
1.112 raeburn 2462: END
2463: return $output;
2464: }
2465:
2466: sub end_pick_box {
1.193 bisitz 2467: shift(@row_count);
1.112 raeburn 2468: my $output = <<"END";
2469: </table>
2470: END
2471: return $output;
2472: }
2473:
1.181 bisitz 2474: sub row_headline {
2475: my $output = <<"END";
2476: <tr><td colspan="2">
2477: END
2478: return $output;
2479: }
2480:
1.112 raeburn 2481: sub row_title {
1.243 amueller 2482: my ($title,$css_title_class,$css_value_class, $css_value_furtherAttributes) = @_;
1.193 bisitz 2483: $row_count[0]++;
2484: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.142 albertel 2485: $css_title_class ||= 'LC_pick_box_title';
2486: $css_title_class = 'class="'.$css_title_class.'"';
2487:
2488: $css_value_class ||= 'LC_pick_box_value';
2489:
1.173 raeburn 2490: if ($title ne '') {
2491: $title .= ':';
2492: }
1.112 raeburn 2493: my $output = <<"ENDONE";
1.243 amueller 2494: <tr class="LC_pick_box_row" $css_value_furtherAttributes>
1.142 albertel 2495: <td $css_title_class>
1.173 raeburn 2496: $title
1.112 raeburn 2497: </td>
1.193 bisitz 2498: <td class="$css_value_class $css_class">
1.112 raeburn 2499: ENDONE
2500: return $output;
2501: }
2502:
2503: sub row_closure {
1.143 albertel 2504: my ($no_separator) =@_;
1.113 raeburn 2505: my $output = <<"ENDTWO";
1.112 raeburn 2506: </td>
2507: </tr>
1.143 albertel 2508: ENDTWO
2509: if (!$no_separator) {
2510: $output .= <<"ENDTWO";
1.112 raeburn 2511: <tr>
1.143 albertel 2512: <td colspan="2" class="LC_pick_box_separator">
1.112 raeburn 2513: </td>
2514: </tr>
2515: ENDTWO
1.143 albertel 2516: }
1.112 raeburn 2517: return $output;
2518: }
2519:
1.193 bisitz 2520: } # End: row_count block for pick_box
2521:
1.112 raeburn 2522: sub role_select_row {
1.147 raeburn 2523: my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
1.236 raeburn 2524: my $crstype = 'Course';
2525: if ($cdom ne '' && $cnum ne '') {
2526: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
2527: }
1.116 raeburn 2528: my $output;
2529: if (defined($title)) {
1.142 albertel 2530: $output = &row_title($title,$css_class);
1.116 raeburn 2531: }
1.142 albertel 2532: $output .= qq|
1.198 bisitz 2533: <select name="roles" multiple="multiple">\n|;
1.113 raeburn 2534: foreach my $role (@$roles) {
1.114 raeburn 2535: my $plrole;
2536: if ($role eq 'ow') {
2537: $plrole = &mt('Course Owner');
1.147 raeburn 2538: } elsif ($role eq 'cr') {
2539: if ($show_separate_custom) {
2540: if ($cdom ne '' && $cnum ne '') {
2541: my %course_customroles = &course_custom_roles($cdom,$cnum);
2542: foreach my $crrole (sort(keys(%course_customroles))) {
2543: my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|);
2544: $output .= ' <option value="'.$crrole.'">'.$plcrrole.
2545: '</option>';
2546: }
2547: }
2548: } else {
2549: $plrole = &mt('Custom Role');
2550: }
1.114 raeburn 2551: } else {
1.236 raeburn 2552: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.114 raeburn 2553: }
1.147 raeburn 2554: if (($role ne 'cr') || (!$show_separate_custom)) {
2555: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
2556: }
1.112 raeburn 2557: }
1.142 albertel 2558: $output .= qq| </select>\n|;
1.116 raeburn 2559: if (defined($title)) {
2560: $output .= &row_closure();
2561: }
1.112 raeburn 2562: return $output;
2563: }
2564:
2565: sub course_select_row {
1.142 albertel 2566: my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles,
1.280 raeburn 2567: $css_class,$crstype,$standardnames) = @_;
1.142 albertel 2568: my $output = &row_title($title,$css_class);
1.280 raeburn 2569: $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames);
1.169 raeburn 2570: $output .= &row_closure();
2571: return $output;
2572: }
2573:
2574: sub course_selection {
1.280 raeburn 2575: my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames) = @_;
1.169 raeburn 2576: my $output = qq|
1.142 albertel 2577: <script type="text/javascript">
1.218 bisitz 2578: // <![CDATA[
1.112 raeburn 2579: function coursePick (formname) {
2580: for (var i=0; i<formname.coursepick.length; i++) {
1.114 raeburn 2581: if (formname.coursepick[i].value == 'category') {
2582: courseSet('');
2583: }
1.112 raeburn 2584: if (!formname.coursepick[i].checked) {
2585: if (formname.coursepick[i].value == 'specific') {
2586: formname.coursetotal.value = 0;
2587: formname.courselist = '';
2588: }
2589: }
2590: }
2591: }
1.114 raeburn 2592: function setPick (formname) {
2593: for (var i=0; i<formname.coursepick.length; i++) {
2594: if (formname.coursepick[i].value == 'category') {
2595: formname.coursepick[i].checked = true;
2596: }
2597: formname.coursetotal.value = 0;
2598: formname.courselist = '';
2599: }
2600: }
1.218 bisitz 2601: // ]]>
1.112 raeburn 2602: </script>
2603: |;
1.237 raeburn 2604:
2605: my ($allcrs,$pickspec);
2606: if ($crstype eq 'Community') {
2607: $allcrs = &mt('All communities');
2608: $pickspec = &mt('Pick specific communities:');
2609: } else {
2610: $allcrs = &mt('All courses');
2611: $pickspec = &mt('Pick specific course(s):');
2612: }
2613:
1.112 raeburn 2614: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.237 raeburn 2615: ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).'</b>';
1.341 bisitz 2616: $output .= '<label><input type="radio" name="coursepick" value="all" onclick="coursePick(this.form)" />'.$allcrs.'</label><br />';
1.112 raeburn 2617: if ($totcodes > 0) {
2618: my $numtitles = @$codetitles;
2619: if ($numtitles > 0) {
1.366 damieng 2620: $output .= '<label><input type="radio" name="coursepick" value="category" onclick="coursePick(this.form);alert('."'".&html_escape(&mt('Choose categories, from left to right'))."'".')" />'.&mt('Pick courses by category:').'</label><br />';
1.112 raeburn 2621: $output .= '<table><tr><td>'.$$codetitles[0].'<br />'."\n".
1.280 raeburn 2622: '<select name="'.$standardnames->[0].
1.351 bisitz 2623: '" onchange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
1.112 raeburn 2624: ' <option value="-1" />Select'."\n";
2625: my @items = ();
2626: my @longitems = ();
2627: if ($$idlist{$$codetitles[0]} =~ /","/) {
1.113 raeburn 2628: @items = split(/","/,$$idlist{$$codetitles[0]});
1.112 raeburn 2629: } else {
2630: $items[0] = $$idlist{$$codetitles[0]};
2631: }
2632: if (defined($$idlist_titles{$$codetitles[0]})) {
2633: if ($$idlist_titles{$$codetitles[0]} =~ /","/) {
1.113 raeburn 2634: @longitems = split(/","/,$$idlist_titles{$$codetitles[0]});
1.112 raeburn 2635: } else {
2636: $longitems[0] = $$idlist_titles{$$codetitles[0]};
2637: }
2638: for (my $i=0; $i<@longitems; $i++) {
2639: if ($longitems[$i] eq '') {
2640: $longitems[$i] = $items[$i];
2641: }
2642: }
2643: } else {
2644: @longitems = @items;
2645: }
2646: for (my $i=0; $i<@items; $i++) {
2647: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
2648: }
2649: $output .= '</select></td>';
2650: for (my $i=1; $i<$numtitles; $i++) {
2651: $output .= '<td>'.$$codetitles[$i].'<br />'."\n".
1.280 raeburn 2652: '<select name="'.$standardnames->[$i].
1.351 bisitz 2653: '" onchange="courseSet('."'$$codetitles[$i]'".')">'."\n".
1.112 raeburn 2654: '<option value="-1"><-Pick '.$$codetitles[$i-1].'</option>'."\n".
2655: '</select>'."\n".
2656: '</td>';
2657: }
2658: $output .= '</tr></table><br />';
2659: }
2660: }
1.341 bisitz 2661: $output .=
2662: '<label><input type="radio" name="coursepick" value="specific"'
2663: .' onclick="coursePick(this.form);opencrsbrowser('."'".$formname."','dccourse','dcdomain','coursedesc','','1','$crstype'".')" />'
2664: .$pickspec.'</label>'
2665: .' '.$courseform.' '
2666: .&mt('[_1] selected.',
2667: '<input type="text" value="0" size="4" name="coursetotal" readonly="readonly" />'
2668: .'<input type="hidden" name="courselist" value="" />')
2669: .'<br />'."\n";
1.112 raeburn 2670: return $output;
2671: }
2672:
2673: sub status_select_row {
1.142 albertel 2674: my ($types,$title,$css_class) = @_;
1.117 raeburn 2675: my $output;
2676: if (defined($title)) {
1.142 albertel 2677: $output = &row_title($title,$css_class,'LC_pick_box_select');
1.117 raeburn 2678: }
1.142 albertel 2679: $output .= qq|
1.198 bisitz 2680: <select name="types" multiple="multiple">\n|;
1.113 raeburn 2681: foreach my $status_type (sort(keys(%{$types}))) {
1.112 raeburn 2682: $output .= ' <option value="'.$status_type.'">'.$$types{$status_type}.'</option>';
2683: }
1.142 albertel 2684: $output .= qq| </select>\n|;
1.117 raeburn 2685: if (defined($title)) {
2686: $output .= &row_closure();
2687: }
1.112 raeburn 2688: return $output;
2689: }
2690:
2691: sub email_default_row {
1.142 albertel 2692: my ($authtypes,$title,$descrip,$css_class) = @_;
2693: my $output = &row_title($title,$css_class);
2694: $output .= $descrip.
2695: &Apache::loncommon::start_data_table().
2696: &Apache::loncommon::start_data_table_header_row().
2697: '<th>'.&mt('Authentication Method').'</th>'.
2698: '<th align="right">'.&mt('Username -> e-mail conversion').'</th>'."\n".
2699: &Apache::loncommon::end_data_table_header_row();
1.112 raeburn 2700: my $rownum = 0;
1.113 raeburn 2701: foreach my $auth (sort(keys(%{$authtypes}))) {
1.112 raeburn 2702: my ($userentry,$size);
2703: if ($auth =~ /^krb/) {
2704: $userentry = '';
2705: $size = 25;
2706: } else {
2707: $userentry = 'username@';
2708: $size = 15;
2709: }
1.142 albertel 2710: $output .= &Apache::loncommon::start_data_table_row().
2711: '<td> '.$$authtypes{$auth}.'</td>'.
2712: '<td align="right">'.$userentry.
2713: '<input type="text" name="'.$auth.'" size="'.$size.'" /></td>'.
2714: &Apache::loncommon::end_data_table_row();
1.112 raeburn 2715: }
1.142 albertel 2716: $output .= &Apache::loncommon::end_data_table();
1.112 raeburn 2717: $output .= &row_closure();
2718: return $output;
2719: }
2720:
2721:
2722: sub submit_row {
1.142 albertel 2723: my ($title,$cmd,$submit_text,$css_class) = @_;
2724: my $output = &row_title($title,$css_class,'LC_pick_box_submit');
1.112 raeburn 2725: $output .= qq|
2726: <br />
2727: <input type="hidden" name="command" value="$cmd" />
2728: <input type="submit" value="$submit_text"/>
2729: <br /><br />
1.142 albertel 2730: \n|;
1.112 raeburn 2731: return $output;
2732: }
1.1 stredwic 2733:
1.147 raeburn 2734: sub course_custom_roles {
2735: my ($cdom,$cnum) = @_;
2736: my %returnhash=();
2737: my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
2738: foreach my $person (sort(keys(%coursepersonnel))) {
2739: my ($role) = ($person =~ /^([^:]+):/);
2740: my ($end,$start) = split(/:/,$coursepersonnel{$person});
2741: if ($end == -1 && $start == -1) {
2742: next;
2743: }
2744: if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) {
2745: $returnhash{$role} ++;
2746: }
2747: }
2748: return %returnhash;
2749: }
2750:
2751:
1.270 www 2752: sub resource_info_box {
1.396 raeburn 2753: my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp,$divforres)=@_;
1.270 www 2754: my $return='';
1.396 raeburn 2755: if (($stuvcurrent ne '') || ($divforres)) {
1.300 raeburn 2756: $return = '<div class="LC_left_float">';
2757: }
1.270 www 2758: if ($symb) {
1.300 raeburn 2759: $return.=&Apache::loncommon::start_data_table();
1.271 www 2760: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symb);
2761: my $folder=&Apache::lonnet::gettitle($map);
2762: $return.=&Apache::loncommon::start_data_table_row().
1.300 raeburn 2763: '<th align="left">'.&mt('Folder:').'</th><td>'.$folder.'</td>'.
1.271 www 2764: &Apache::loncommon::end_data_table_row();
1.270 www 2765: unless ($onlyfolderflag) {
2766: $return.=&Apache::loncommon::start_data_table_row().
1.300 raeburn 2767: '<th align="left">'.&mt('Resource:').'</th><td>'.&Apache::lonnet::gettitle($symb).'</td>'.
2768: &Apache::loncommon::end_data_table_row();
2769: }
2770: if ($stuvcurrent ne '') {
2771: $return .= &Apache::loncommon::start_data_table_row().
2772: '<th align="left">'.&mt("Student's current version:").'</th><td>'.$stuvcurrent.'</td>'.
2773: &Apache::loncommon::end_data_table_row();
2774: }
2775: if ($stuvdisp ne '') {
2776: $return .= &Apache::loncommon::start_data_table_row().
2777: '<th align="left">'.&mt("Student's version displayed:").'</th><td>'.$stuvdisp.'</td>'.
1.270 www 2778: &Apache::loncommon::end_data_table_row();
2779: }
1.271 www 2780: $return.=&Apache::loncommon::end_data_table();
1.270 www 2781: } else {
2782: $return='<p><span class="LC_error">'.&mt('No context provided.').'</span></p>';
2783: }
1.396 raeburn 2784: if (($stuvcurrent ne '') || ($divforres)) {
1.300 raeburn 2785: $return .= '</div>';
2786: }
1.270 www 2787: return $return;
2788: }
2789:
1.348 raeburn 2790: # display_usage
2791: #
2792: # Generates a div containing a block, filled to show percentage of current quota used
2793: #
2794: # Quotas available for user portfolios, group portfolios, authoring spaces, and course
2795: # content stored directly within a course (i.e., excluding published content).
2796: #
2797:
2798: sub display_usage {
1.372 raeburn 2799: my ($current_disk_usage,$disk_quota,$context) = @_;
2800: my $usage = $current_disk_usage/1024;
2801: my $quota = $disk_quota/1024;
1.348 raeburn 2802: my $percent;
2803: if ($disk_quota == 0) {
2804: $percent = 100.0;
2805: } else {
2806: $percent = 100*($current_disk_usage/$disk_quota);
2807: }
2808: $usage = sprintf("%.2f",$usage);
2809: $quota = sprintf("%.2f",$quota);
2810: $percent = sprintf("%.0f",$percent);
2811: my ($color,$cssclass);
2812: if ($percent <= 60) {
2813: $color = '#00A000';
2814: } elsif ($percent > 60 && $percent < 90) {
2815: $color = '#FFD300';
2816: $cssclass = 'class="LC_warning"';
2817: } elsif( $percent >= 90) {
2818: $color = '#FF0000';
2819: $cssclass = 'class="LC_error"';
2820: }
2821: my $prog_width = $percent;
2822: if ($prog_width > 100) {
2823: $prog_width = 100;
2824: }
1.372 raeburn 2825: my $display = 'block';
2826: if ($context eq 'authoring') {
2827: $display = 'inline';
2828: }
1.348 raeburn 2829: return '
1.372 raeburn 2830: <div id="meter1" align="left" style="display:'.$display.'" '.$cssclass.'>'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB <span style="font-weight:bold;">('.$percent.'%)</span>',$quota.' MB')."\n".
2831: ' <div id="meter2" style="display:block; margin-top:3px; margin-bottom:3px; margin-left:0px; margin-right:0px; width:400px; border:1px solid #000000; height:10px;">'."\n".
1.348 raeburn 2832: ' <div id="meter3" style="display:block; background-color:'.$color.'; width:'.$prog_width.'%; height:10px; color:#000000; margin:0px;"></div>'."\n".
2833: ' </div>'."\n".
2834: ' </div>';
2835: }
2836:
1.119 raeburn 2837: ##############################################
2838: ##############################################
1.179 raeburn 2839:
2840: # topic_bar
2841: #
1.248 wenzelju 2842: # Generates a div containing an (optional) number with a white background followed by a
1.240 raeburn 2843: # title with a background color defined in the corresponding CSS: LC_topic_bar
2844: # Inputs:
1.248 wenzelju 2845: # 1. number to display.
2846: # If input for number is empty only the title will be displayed.
1.240 raeburn 2847: # 2. title text to display.
1.313 raeburn 2848: # 3. optional id for the <div>
1.240 raeburn 2849: # Outputs - a scalar containing html mark-up for the div.
2850:
1.179 raeburn 2851: sub topic_bar {
1.313 raeburn 2852: my ($num,$title,$id) = @_;
1.248 wenzelju 2853: my $number = '';
2854: if ($num ne '') {
2855: $number = '<span>'.$num.'</span>';
1.239 amueller 2856: }
1.313 raeburn 2857: if ($id ne '') {
2858: $id = 'id="'.$id.'"';
2859: }
2860: return '<div class="LC_topic_bar" '.$id.'>'.$number.$title.'</div>';
1.179 raeburn 2861: }
2862:
2863: ##############################################
2864: ##############################################
1.119 raeburn 2865: # echo_form_input
2866: #
2867: # Generates html markup to add form elements from the referrer page
2868: # as hidden form elements (values encoded) in the new page.
2869: #
2870: # Intended to support two types of use
2871: # (a) to allow backing up to earlier pages in a multi-page
2872: # form submission process using a breadcrumb trail.
2873: #
2874: # (b) to allow the current page to be reloaded with form elements
2875: # set on previous page to remain unchanged. An example would
2876: # be where the a page containing a dynamically-built table of data is
2877: # is to be redisplayed, with only the sort order of the data changed.
2878: #
2879: # Inputs:
2880: # 1. Reference to array of form elements in the submitted form on
2881: # the referrer page which are to be excluded from the echoed elements.
2882: #
2883: # 2. Reference to array of regular expressions, which if matched in the
2884: # name of the form element n the referrer page will be omitted from echo.
2885: #
2886: # Outputs: A scalar containing the html markup for the echoed form
2887: # elements (all as hidden elements, with values encoded).
2888:
2889:
2890: sub echo_form_input {
2891: my ($excluded,$regexps) = @_;
2892: my $output = '';
2893: foreach my $key (keys(%env)) {
2894: if ($key =~ /^form\.(.+)$/) {
2895: my $name = $1;
2896: my $match = 0;
1.285 raeburn 2897: if (ref($excluded) eq 'ARRAY') {
2898: next if (grep(/^\Q$name\E$/,@{$excluded}));
2899: }
2900: if (ref($regexps) eq 'ARRAY') {
2901: if (@{$regexps} > 0) {
2902: foreach my $regexp (@{$regexps}) {
2903: if ($name =~ /$regexp/) {
2904: $match = 1;
2905: last;
1.119 raeburn 2906: }
2907: }
2908: }
1.285 raeburn 2909: }
2910: next if ($match);
2911: if (ref($env{$key}) eq 'ARRAY') {
2912: foreach my $value (@{$env{$key}}) {
2913: $value = &HTML::Entities::encode($value,'<>&"');
2914: $output .= '<input type="hidden" name="'.$name.
2915: '" value="'.$value.'" />'."\n";
1.119 raeburn 2916: }
1.285 raeburn 2917: } else {
2918: my $value = &HTML::Entities::encode($env{$key},'<>&"');
2919: $output .= '<input type="hidden" name="'.$name.
2920: '" value="'.$value.'" />'."\n";
1.119 raeburn 2921: }
2922: }
2923: }
2924: return $output;
2925: }
2926:
2927: ##############################################
2928: ##############################################
2929: # set_form_elements
2930: #
2931: # Generates javascript to set form elements to values based on
2932: # corresponding values for the same form elements when the page was
2933: # previously submitted.
2934: #
2935: # Last submission values are read from hidden form elements in referring
2936: # page which have the same name, i.e., generated by &echo_form_input().
2937: #
2938: # Intended to be called by onload event.
2939: #
1.121 raeburn 2940: # Inputs:
2941: # (a) Reference to hash of echoed form elements to be set.
1.119 raeburn 2942: #
2943: # In the hash, keys are the form element names, and the values are the
2944: # element type (selectbox, radio, checkbox or text -for textbox, textarea or
2945: # hidden).
1.121 raeburn 2946: #
2947: # (b) Optional reference to hash of stored elements to be set.
2948: #
2949: # If the page being displayed is a page which permits modification of
2950: # previously stored data, e.g., the first page in a multi-page submission,
2951: # then if stored is supplied, form elements will be set to the last stored
2952: # values. If user supplied values are also available for the same elements
2953: # these will replace the stored values.
2954: #
1.119 raeburn 2955: # Output:
2956: #
2957: # javascript function - set_form_elements() which sets form elements,
2958: # expects an argument: formname - the name of the form according to
2959: # the DOM, e.g., document.compose
2960:
2961: sub set_form_elements {
1.121 raeburn 2962: my ($elements,$stored) = @_;
2963: my %values;
1.119 raeburn 2964: my $output .= 'function setFormElements(courseForm) {
1.121 raeburn 2965: ';
2966: if (defined($stored)) {
2967: foreach my $name (keys(%{$stored})) {
2968: if (exists($$elements{$name})) {
2969: if (ref($$stored{$name}) eq 'ARRAY') {
2970: $values{$name} = $$stored{$name};
2971: } else {
2972: @{$values{$name}} = ($$stored{$name});
2973: }
2974: }
2975: }
2976: }
2977:
1.119 raeburn 2978: foreach my $key (keys(%env)) {
2979: if ($key =~ /^form\.(.+)$/) {
2980: my $name = $1;
2981: if (exists($$elements{$name})) {
1.121 raeburn 2982: @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
2983: }
2984: }
2985: }
2986:
2987: foreach my $name (keys(%values)) {
2988: for (my $i=0; $i<@{$values{$name}}; $i++) {
2989: $values{$name}[$i] = &HTML::Entities::decode($values{$name}[$i],'<>&"');
2990: $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
2991: $values{$name}[$i] =~ s/"/\\"/g;
2992: }
1.234 raeburn 2993: if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) {
1.121 raeburn 2994: my $numvalues = @{$values{$name}};
2995: if ($numvalues > 1) {
2996: my $valuestring = join('","',@{$values{$name}});
2997: $output .= qq|
1.119 raeburn 2998: var textvalues = new Array ("$valuestring");
1.147 raeburn 2999: var total = courseForm.elements['$name'].length;
1.119 raeburn 3000: if (total > $numvalues) {
3001: total = $numvalues;
3002: }
3003: for (var i=0; i<total; i++) {
1.147 raeburn 3004: courseForm.elements['$name']\[i].value = textvalues[i];
1.119 raeburn 3005: }
3006: |;
1.121 raeburn 3007: } else {
3008: $output .= qq|
1.147 raeburn 3009: courseForm.elements['$name'].value = "$values{$name}[0]";
1.119 raeburn 3010: |;
1.121 raeburn 3011: }
3012: } else {
3013: $output .= qq|
1.147 raeburn 3014: var elementLength = courseForm.elements['$name'].length;
1.119 raeburn 3015: if (elementLength==undefined) {
3016: |;
1.121 raeburn 3017: foreach my $value (@{$values{$name}}) {
3018: if ($$elements{$name} eq 'selectbox') {
3019: $output .= qq|
1.147 raeburn 3020: if (courseForm.elements['$name'].options[0].value == "$value") {
3021: courseForm.elements['$name'].options[0].selected = true;
1.119 raeburn 3022: }|;
1.121 raeburn 3023: } elsif (($$elements{$name} eq 'radio') ||
3024: ($$elements{$name} eq 'checkbox')) {
3025: $output .= qq|
1.147 raeburn 3026: if (courseForm.elements['$name'].value == "$value") {
1.148 albertel 3027: courseForm.elements['$name'].checked = true;
1.234 raeburn 3028: } else {
3029: courseForm.elements['$name'].checked = false;
1.119 raeburn 3030: }|;
1.121 raeburn 3031: }
3032: }
3033: $output .= qq|
1.119 raeburn 3034: }
3035: else {
1.147 raeburn 3036: for (var i=0; i<courseForm.elements['$name'].length; i++) {
1.119 raeburn 3037: |;
1.121 raeburn 3038: if ($$elements{$name} eq 'selectbox') {
3039: $output .= qq|
1.147 raeburn 3040: courseForm.elements['$name'].options[i].selected = false;|;
1.121 raeburn 3041: } elsif (($$elements{$name} eq 'radio') ||
3042: ($$elements{$name} eq 'checkbox')) {
3043: $output .= qq|
1.147 raeburn 3044: courseForm.elements['$name']\[i].checked = false;|;
1.121 raeburn 3045: }
3046: $output .= qq|
1.119 raeburn 3047: }
1.147 raeburn 3048: for (var j=0; j<courseForm.elements['$name'].length; j++) {
1.119 raeburn 3049: |;
1.121 raeburn 3050: foreach my $value (@{$values{$name}}) {
3051: if ($$elements{$name} eq 'selectbox') {
3052: $output .= qq|
1.147 raeburn 3053: if (courseForm.elements['$name'].options[j].value == "$value") {
3054: courseForm.elements['$name'].options[j].selected = true;
1.119 raeburn 3055: }|;
1.121 raeburn 3056: } elsif (($$elements{$name} eq 'radio') ||
3057: ($$elements{$name} eq 'checkbox')) {
3058: $output .= qq|
1.147 raeburn 3059: if (courseForm.elements['$name']\[j].value == "$value") {
3060: courseForm.elements['$name']\[j].checked = true;
1.119 raeburn 3061: }|;
1.121 raeburn 3062: }
3063: }
3064: $output .= qq|
1.119 raeburn 3065: }
3066: }
3067: |;
3068: }
3069: }
3070: $output .= "
1.235 raeburn 3071: return;
1.119 raeburn 3072: }\n";
3073: return $output;
3074: }
3075:
1.158 raeburn 3076: ##############################################
3077: ##############################################
3078:
1.291 raeburn 3079: sub file_submissionchk_js {
3080: my ($turninpaths,$multiples) = @_;
1.366 damieng 3081: my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item')."\n".
1.291 raeburn 3082: &mt('Continue submission and overwrite the file(s)?');
1.366 damieng 3083: &js_escape(\$overwritewarn);
3084: my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.')."\n".
1.291 raeburn 3085: &mt('Continue submission with these files removed?');
1.366 damieng 3086: &js_escape(\$delfilewarn);
1.292 raeburn 3087: my ($turninpathtext,$multtext,$arrayindexofjs);
1.291 raeburn 3088: if (ref($turninpaths) eq 'HASH') {
3089: foreach my $key (sort(keys(%{$turninpaths}))) {
3090: $turninpathtext .= " if (prefix == '$key') {\n".
3091: " return '$turninpaths->{$key}';\n".
3092: " }\n";
3093: }
3094: }
3095: $turninpathtext .= " return '';\n";
3096: if (ref($multiples) eq 'HASH') {
3097: foreach my $key (sort(keys(%{$multiples}))) {
3098: $multtext .= " if (prefix == '$key') {\n".
3099: " return '$multiples->{$key}';\n".
3100: " }\n";
3101: }
3102: }
3103: $multtext .= " return '';\n";
1.292 raeburn 3104:
1.293 raeburn 3105: $arrayindexofjs = &Apache::loncommon::javascript_array_indexof();
1.291 raeburn 3106: return <<"ENDSCRIPT";
3107: <script type="text/javascript">
3108: // <![CDATA[
3109:
3110: function file_submission_check(formname,path,multiresp) {
3111: var elemnum = formname.elements.length;
3112: if (elemnum == 0) {
3113: return true;
3114: }
3115: var alloverwrites = [];
3116: var alldelconfirm = [];
3117: var result = [];
3118: var submitter;
3119: var subprefix;
3120: var allsub = getIndexByName(formname,'all_submit');
3121: if (allsub == -1) {
3122: var idx = getIndexByName(formname,'submitted');
3123: if (idx != -1) {
3124: var subval = String(formname.elements[idx].value);
3125: submitter = subval.replace(/^part_/,'');
3126: result = overwritten_check(formname,path,multiresp,submitter);
3127: alloverwrites.push.apply(alloverwrites,result['overwrite']);
3128: alldelconfirm.push.apply(alldelconfirm,result['delete']);
3129: }
3130: } else {
3131: if (formname.elements[allsub].type == 'submit') {
3132: var partsub = /^\\d+\\.\\d+_submit_.+\$/;
3133: var allprefixes = [];
3134: var allparts = [];
3135: for (var i=0; i<formname.elements.length; i++) {
3136: if (formname.elements[i].type == 'submit') {
3137: var elemname = formname.elements[i].name;
3138: var subname = String(elemname);
3139: var savesub = String(elemname);
3140: if (partsub.test(subname)) {
3141: var prefix = subname.replace(/_submit_.+\$/,'');
3142: if (allprefixes.indexOf(prefix) == -1) {
3143: allprefixes.push(prefix);
3144: allparts[prefix] = [];
3145: }
3146: var part = savesub.replace(/^\\d+\\.\\d+_submit_/,'');
3147: allparts[prefix].push(part);
3148: }
3149: }
3150: }
3151: for (var k=0; k<allprefixes.length; k++) {
3152: var idx = getIndexByName(formname,allprefixes[k]+'_submitted');
3153: if (idx > -1) {
3154: if (formname.elements[idx].value != 'yes') {
3155: submitterval = formname.elements[idx].value;
3156: submitter = submitterval.replace(/^part_/,'');
3157: subprefix = allprefixes[k];
3158: result = overwritten_check(formname,path,multiresp,submitter,subprefix);
3159: alloverwrites.push.apply(alloverwrites,result['overwrite']);
3160: alldelconfirm.push.apply(alldelconfirm,result['delete']);
3161: break;
3162: }
3163: }
3164: }
3165: if (submitter == '' || submitter == undefined) {
3166: for (var m=0; m<allprefixes.length; m++) {
3167: for (var n=0; n<allparts[allprefixes[m]].length; n++) {
3168: var result = overwritten_check(formname,path,multiresp,allparts[allprefixes[m]][n],allprefixes[m]);
3169: alloverwrites.push.apply(alloverwrites,result['overwrite']);
3170: alldelconfirm.push.apply(alldelconfirm,result['delete']);
3171: }
3172: }
3173: }
3174: }
3175: }
3176: if (alloverwrites.length > 0) {
3177: if (!confirm("$overwritewarn")) {
3178: for (var n=0; n<alloverwrites.length; n++) {
3179: formname.elements[alloverwrites[n]].value = "";
3180: }
3181: return false;
3182: }
3183: }
3184: if (alldelconfirm.length > 0) {
3185: if (!confirm("$delfilewarn")) {
3186: for (var p=0; p<alldelconfirm.length; p++) {
3187: formname.elements[alldelconfirm[p]].checked = false;
3188: }
3189: return false;
3190: }
3191: }
3192: return true;
3193: }
3194:
3195: function getIndexByName(formname,item) {
3196: for (var i=0;i<formname.elements.length;i++) {
3197: if (formname.elements[i].name == item) {
3198: return i;
3199: }
3200: }
3201: return -1;
3202: }
3203:
3204: function overwritten_check(formname,path,multiresp,part,prefix) {
3205: var result = [];
3206: result['overwrite'] = [];
3207: result['delete'] = [];
3208: var elemnum = formname.elements.length;
3209: if (elemnum == 0) {
3210: return result;
3211: }
3212: var uploadstr;
3213: var deletestr;
3214: if ((prefix != undefined) && (prefix != '')) {
3215: var prepend = prefix+'_';
3216: uploadstr = new RegExp("^"+prepend+"HWFILE"+part+".+\$");
3217: deletestr = new RegExp("^"+prepend+"HWFILE"+part+".+_\\\\d+_delete\$");
3218: multiresp = check_for_multiples(prepend);
3219: path = check_for_turninpath(prepend);
3220: } else {
3221: uploadstr = new RegExp("^HWFILE"+part+".+\$");
3222: deletestr = new RegExp("^HWFILE"+part+".+_\\\\d+_delete\$");
3223: }
3224: var alluploads = [];
3225: var allchecked = [];
3226: var allskipdel = [];
3227: var fnametrim = /[^\\/\\\\]+\$/;
3228: for (var i=0; i<formname.elements.length; i++) {
3229: var id = formname.elements[i].id;
3230: if (id != '') {
3231: if (uploadstr.test(id)) {
3232: if (formname.elements[i].type == 'file') {
3233: alluploads.push(id);
3234: } else {
3235: if (deletestr.test(id)) {
3236: if (formname.elements[i].type == 'checkbox') {
3237: if (formname.elements[i].checked) {
3238: allchecked.push(id);
3239: }
3240: }
3241: }
3242: }
3243: }
3244: }
3245: }
3246: for (var j=0; j<alluploads.length; j++) {
3247: var delstr = new RegExp("^"+alluploads[j]+"_\\\\d+_delete\$");
3248: var delboxes = [];
3249: for (var k=0; k<formname.elements.length; k++) {
3250: var id = formname.elements[k].id;
3251: if ((id != '') && (id != undefined)) {
3252: if (delstr.test(id)) {
3253: if (formname.elements[k].type == 'checkbox') {
3254: delboxes.push(id);
3255: }
3256: }
3257: }
3258: }
3259: if (delboxes.length > 0) {
3260: if ((formname.elements[alluploads[j]].value != undefined) &&
3261: (formname.elements[alluploads[j]].value != '')) {
3262: var filepath = formname.elements[alluploads[j]].value;
3263: var newfilename = fnametrim.exec(filepath);
3264: if (newfilename != null) {
3265: var filename = String(newfilename);
3266: var nospaces = filename.replace(/\\s+/g,'_');
3267: var nospecials = nospaces.replace(/[^\\/\\w\\.\\-]/g,'');
3268: var cleanfilename = nospecials.replace(/\\.(\\d+\\.)/g,"_\$1");
3269: if (cleanfilename != '') {
3270: var fullpath = path+"/"+cleanfilename;
3271: if (multiresp == 1) {
3272: var partid = String(alluploads[i]);
3273: var subdir = partid.replace(/^\\d*.?\\d*_?HWFILE/,'');
3274: if (subdir != "" && subdir != undefined) {
3275: fullpath = path+"/"+subdir+"/"+cleanfilename;
3276: }
3277: }
3278: for (var m=0; m<delboxes.length; m++) {
3279: if (fullpath == formname.elements[delboxes[m]].value) {
3280: if (formname.elements[delboxes[m]].checked) {
3281: allskipdel.push(delboxes[m]);
3282: } else {
3283: result['overwrite'].push(alluploads[j]);
3284: }
3285: break;
3286: }
3287: }
3288: }
3289: }
3290: }
3291: }
3292: }
3293: if (allchecked.length > 0) {
3294: if (allskipdel.length > 0) {
3295: for (var n=0; n<allchecked.length; n++) {
3296: if (allskipdel.indexOf(allchecked[n]) == -1) {
3297: result['delete'].push(allchecked[n]);
3298: }
3299: }
3300: } else {
3301: result['delete'].push.apply(result['delete'],allchecked);
3302: }
3303: }
3304: return result;
3305: }
3306:
3307: function check_for_multiples(prefix) {
3308: $multtext
3309: }
3310:
3311: function check_for_turninpath(prefix) {
3312: $turninpathtext
3313: }
3314:
3315: // ]]>
3316: </script>
3317:
1.292 raeburn 3318: $arrayindexofjs
3319:
1.291 raeburn 3320: ENDSCRIPT
3321: }
3322:
3323: ##############################################
3324: ##############################################
3325:
1.313 raeburn 3326: sub resize_scrollbox_js {
1.353 raeburn 3327: my ($context,$tabidstr,$tid) = @_;
1.313 raeburn 3328: my (%names,$paddingwfrac,$offsetwfrac,$offsetv,$minw,$minv);
3329: if ($context eq 'docs') {
3330: %names = (
3331: boxw => 'contenteditor',
3332: item => 'contentlist',
3333: header => 'uploadfileresult',
3334: scroll => 'contentscroll',
3335: boxh => 'contenteditor',
3336: );
1.350 raeburn 3337: $paddingwfrac = 0.09;
1.313 raeburn 3338: $offsetwfrac = 0.015;
3339: $offsetv = 20;
3340: $minw = 250;
3341: $minv = 200;
3342: } elsif ($context eq 'params') {
3343: %names = (
3344: boxw => 'parameditor',
3345: item => 'mapmenuinner',
3346: header => 'parmstep1',
3347: scroll => 'mapmenuscroll',
3348: boxh => 'parmlevel',
3349: );
3350: $paddingwfrac = 0.2;
3351: $offsetwfrac = 0.015;
3352: $offsetv = 80;
3353: $minw = 100;
3354: $minv = 100;
3355: }
3356: my $viewport_js = &Apache::loncommon::viewport_geometry_js();
3357: my $output = '
3358:
3359: window.onresize=callResize;
3360:
3361: ';
3362: if ($context eq 'docs') {
1.353 raeburn 3363: if ($env{'form.active'}) {
3364: $output .= "\nvar activeTab = '$env{'form.active'}$tid';\n";
3365: } else {
3366: $output .= "\nvar activeTab = '';\n";
3367: }
1.313 raeburn 3368: }
3369: $output .= <<"FIRST";
3370:
3371: $viewport_js
3372:
3373: function resize_scrollbox(scrollboxname,chkw,chkh) {
3374: var scrollboxid = 'div_'+scrollboxname;
3375: var scrolltableid = 'table_'+scrollboxname;
3376: var scrollbox;
3377: var scrolltable;
1.350 raeburn 3378: var ismobile = '$env{'browser.mobile'}';
1.313 raeburn 3379:
3380: if (document.getElementById("$names{'boxw'}") == null) {
3381: return;
3382: }
3383:
3384: if (document.getElementById(scrollboxid) == null) {
3385: return;
3386: } else {
3387: scrollbox = document.getElementById(scrollboxid);
3388: }
3389:
3390:
3391: if (document.getElementById(scrolltableid) == null) {
3392: return;
3393: } else {
3394: scrolltable = document.getElementById(scrolltableid);
3395: }
3396:
3397: init_geometry();
3398: var vph = Geometry.getViewportHeight();
3399: var vpw = Geometry.getViewportWidth();
3400:
3401: FIRST
3402: if ($context eq 'docs') {
3403: $output .= "
3404: var alltabs = ['$tabidstr'];
3405: ";
3406: } elsif ($context eq 'params') {
3407: $output .= "
3408: if (document.getElementById('$names{'boxh'}') == null) {
3409: return;
3410: }
3411: ";
3412: }
3413: $output .= <<"SECOND";
3414: var listwchange;
1.350 raeburn 3415: var scrollchange;
1.313 raeburn 3416: if (chkw == 1) {
3417: var boxw = document.getElementById("$names{'boxw'}").offsetWidth;
3418: var itemw;
3419: var itemid = document.getElementById("$names{'item'}");
3420: if (itemid != null) {
3421: itemw = itemid.offsetWidth;
3422: }
3423: var itemwstart = itemw;
3424:
3425: var scrollboxw = scrollbox.offsetWidth;
3426: var scrollboxscrollw = scrollbox.scrollWidth;
1.350 raeburn 3427: var scrollstart = scrollboxw;
1.313 raeburn 3428:
3429: var offsetw = parseInt(vpw * $offsetwfrac);
3430: var paddingw = parseInt(vpw * $paddingwfrac);
3431:
3432: var minscrollboxw = $minw;
3433: var maxcolw = 0;
3434: SECOND
3435: if ($context eq 'docs') {
3436: $output .= <<"DOCSONE";
3437: var actabw = 0;
3438: for (var i=0; i<alltabs.length; i++) {
3439: if (activeTab == alltabs[i]) {
3440: actabw = document.getElementById(alltabs[i]).offsetWidth;
3441: if (actabw > maxcolw) {
3442: maxcolw = actabw;
3443: }
3444: } else {
3445: if (document.getElementById(alltabs[i]) != null) {
3446: var thistab = document.getElementById(alltabs[i]);
3447: thistab.style.visibility = 'hidden';
3448: thistab.style.display = 'block';
3449: var tabw = document.getElementById(alltabs[i]).offsetWidth;
3450: thistab.style.display = 'none';
3451: thistab.style.visibility = '';
3452: if (tabw > maxcolw) {
3453: maxcolw = tabw;
3454: }
3455: }
3456: }
3457: }
3458: DOCSONE
3459: } elsif ($context eq 'params') {
3460: $output .= <<"PARAMSONE";
3461: var parmlevelrows = new Array();
3462: var mapmenucells = new Array();
3463: parmlevelrows = document.getElementById("$names{'boxh'}").rows;
3464: var numrows = parmlevelrows.length;
3465: if (numrows > 1) {
3466: mapmenucells = parmlevelrows[2].getElementsByTagName('td');
3467: }
3468: maxcolw = mapmenucells[0].offsetWidth;
3469: PARAMSONE
3470: }
3471: $output .= <<"THIRD";
3472: if (maxcolw > 0) {
3473: var newscrollboxw;
3474: if (maxcolw+paddingw+scrollboxscrollw<boxw) {
3475: newscrollboxw = boxw-paddingw-maxcolw;
3476: if (newscrollboxw < minscrollboxw) {
3477: newscrollboxw = minscrollboxw;
3478: }
3479: scrollbox.style.width = newscrollboxw+"px";
3480: if (newscrollboxw != scrollboxw) {
3481: var newitemw = newscrollboxw-offsetw;
3482: itemid.style.width = newitemw+"px";
3483: }
3484: } else {
3485: newscrollboxw = boxw-paddingw-maxcolw;
3486: if (newscrollboxw < minscrollboxw) {
3487: newscrollboxw = minscrollboxw;
3488: }
3489: scrollbox.style.width = newscrollboxw+"px";
3490: if (newscrollboxw != scrollboxw) {
3491: var newitemw = newscrollboxw-offsetw;
3492: itemid.style.width = newitemw+"px";
3493: }
3494: }
3495:
3496: if (newscrollboxw != scrollboxw) {
3497: var newscrolltablew = newscrollboxw+offsetw;
3498: scrolltable.style.width = newscrolltablew+"px";
3499: }
3500: }
3501:
1.350 raeburn 3502: if (newscrollboxw != scrollboxw) {
3503: scrollchange = 1;
3504: }
3505:
1.313 raeburn 3506: if (itemid.offsetWidth != itemwstart) {
3507: listwchange = 1;
3508: }
3509: }
3510: if ((chkh == 1) || (listwchange)) {
1.350 raeburn 3511: var itemid = document.getElementById("$names{'item'}");
3512: if (itemid != null) {
3513: itemh = itemid.offsetHeight;
3514: }
1.400 raeburn 3515: var primaryheight = 0;
3516: if (document.getElementById('LC_nav_bar') != null) {
3517: primaryheight = document.getElementById('LC_nav_bar').offsetHeight;
3518: }
3519: var secondaryheight = 0;
1.339 raeburn 3520: if (document.getElementById('LC_secondary_menu') != null) {
3521: secondaryheight = document.getElementById('LC_secondary_menu').offsetHeight;
3522: }
1.400 raeburn 3523: var crumbsheight = 0;
3524: if (document.getElementById('LC_breadcrumbs') != null) {
3525: crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight;
3526: }
1.313 raeburn 3527: var dccidheight = 0;
3528: if (document.getElementById('dccid') != null) {
3529: dccidheight = document.getElementById('dccid').offsetHeight;
3530: }
3531: var headerheight = 0;
3532: if (document.getElementById("$names{'header'}") != null) {
3533: headerheight = document.getElementById("$names{'header'}").offsetHeight;
3534: }
3535: var tabbedheight = document.getElementById("tabbededitor").offsetHeight;
3536: var boxheight = document.getElementById("$names{'boxh'}").offsetHeight;
3537: var freevspace = vph-(primaryheight+secondaryheight+crumbsheight+dccidheight+headerheight+tabbedheight+boxheight);
3538:
3539: var scrollboxheight = scrollbox.offsetHeight;
3540: var scrollboxscrollheight = scrollbox.scrollHeight;
1.350 raeburn 3541: var scrollboxh = scrollboxheight;
1.313 raeburn 3542:
3543: var minvscrollbox = $minv;
3544: var offsetv = $offsetv;
3545: var newscrollboxheight;
3546: if (freevspace < 0) {
3547: newscrollboxheight = scrollboxheight+freevspace-offsetv;
3548: if (newscrollboxheight < minvscrollbox) {
3549: newscrollboxheight = minvscrollbox;
3550: }
3551: scrollbox.style.height = newscrollboxheight + "px";
3552: } else {
3553: if (scrollboxscrollheight > scrollboxheight) {
3554: if (freevspace > offsetv) {
3555: newscrollboxheight = scrollboxheight+freevspace-offsetv;
3556: if (newscrollboxheight < minvscrollbox) {
3557: newscrollboxheight = minvscrollbox;
3558: }
3559: scrollbox.style.height = newscrollboxheight+"px";
3560: }
3561: }
3562: }
3563: scrollboxheight = scrollbox.offsetHeight;
3564: var itemh = document.getElementById("$names{'item'}").offsetHeight;
3565:
3566: if (scrollboxscrollheight <= scrollboxheight) {
3567: if ((itemh+offsetv)<scrollboxheight) {
3568: newscrollheight = itemh+offsetv;
3569: scrollbox.style.height = newscrollheight+"px";
3570: }
3571: }
1.350 raeburn 3572: var newscrollboxh = scrollbox.offsetHeight;
3573: if (scrollboxh != newscrollboxh) {
3574: scrollchange = 1;
3575: }
3576: }
3577: if (ismobile && scrollchange) {
3578: \$("#div_$names{'scroll'}").getNiceScroll().onResize();
1.313 raeburn 3579: }
3580: return;
3581: }
3582:
3583: function callResize() {
3584: var timer;
3585: clearTimeout(timer);
3586: timer=setTimeout('resize_scrollbox("$names{'scroll'}","1","1")',500);
3587: }
3588:
1.329 raeburn 3589: THIRD
1.313 raeburn 3590: return $output;
3591: }
3592:
1.328 raeburn 3593: ##############################################
3594: ##############################################
3595:
3596: sub javascript_jumpto_resource {
1.366 damieng 3597: my $confirm_switch = &mt("Editing requires switching to the resource's home server.")."\n".
1.328 raeburn 3598: &mt('Switch server?');
1.406 raeburn 3599: my $confirm_new_tab = &mt("Editing requires using the resource's home server.")."\n".
3600: &mt('Open a new browser tab?');
1.366 damieng 3601: &js_escape(\$confirm_switch);
1.406 raeburn 3602: &js_escape(\$confirm_new_tab);
1.328 raeburn 3603: return (<<ENDUTILITY)
3604:
3605: function go(url) {
3606: if (url!='' && url!= null) {
3607: currentURL = null;
3608: currentSymb= null;
1.384 raeburn 3609: var lcHostname = setLCHost();
1.394 raeburn 3610: if (lcHostname!='' && lcHostname!= null) {
3611: var RegExp = /^https?\:/;
3612: if (RegExp.test(url)) {
3613: window.location.href=url;
3614: } else {
3615: window.location.href=lcHostname+url;
3616: }
3617: } else {
3618: window.location.href=url;
3619: }
1.328 raeburn 3620: }
3621: }
3622:
1.406 raeburn 3623: function need_switchserver(url,target) {
1.328 raeburn 3624: if (url!='' && url!= null) {
1.406 raeburn 3625: if (target == '_blank') {
3626: if (confirm("$confirm_new_tab")) {
3627: window.open(url,target);
3628: }
3629: } else if (confirm("$confirm_switch")) {
1.328 raeburn 3630: go(url);
3631: }
3632: }
3633: return;
3634: }
3635:
3636: ENDUTILITY
3637:
3638: }
3639:
3640: sub jump_to_editres {
1.406 raeburn 3641: my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb,$shownsymb,
3642: $folderpath,$title,$hostname,$idx,$suppurl,$todocs,$suppanchor) = @_;
3643: my ($jscall,$anchor,$usehttp,$usehttps,$is_ext,$target);
1.328 raeburn 3644: if ($switchserver) {
1.332 raeburn 3645: if ($home) {
1.406 raeburn 3646: my $resedit;
3647: if ($cfile =~ m{^/priv/($match_domain)/($match_username)/}) {
3648: my ($audom,$auname) = ($1,$2);
3649: unless (&Apache::lonnet::is_course($audom,$auname)) {
3650: unless ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$audom)) &&
3651: (&Apache::lonnet::will_trust('coaurem',$audom,$env{'user.domain'}))) {
3652: return;
3653: }
3654: if (($symb ne '') && ($env{'request.course.id'}) &&
3655: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
3656: unless (&Apache::lonnet::can_switchserver($env{'user.domain'},$home)) {
3657: $target = '_blank';
3658: $resedit = 1;
3659: }
3660: }
3661: }
3662: }
1.328 raeburn 3663: $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
1.332 raeburn 3664: &HTML::Entities::encode($env{'request.role'},'"<>&');
1.406 raeburn 3665: if ($shownsymb) {
3666: $cfile .= '&symb='.&HTML::Entities::encode($shownsymb,'"<>&');
3667: if ($resedit) {
3668: $cfile .= '&edit=1';
3669: }
1.332 raeburn 3670: } elsif ($folderpath) {
3671: $cfile .= '&folderpath='.&HTML::Entities::encode($folderpath,'"<>&');
3672: }
1.330 raeburn 3673: if ($forceedit) {
1.328 raeburn 3674: $cfile .= '&forceedit=1';
3675: }
1.330 raeburn 3676: if ($forcereg) {
3677: $cfile .= '&register=1';
3678: }
1.406 raeburn 3679: $jscall = "need_switchserver('".&Apache::loncommon::escape_single($cfile)."','$target')";
1.328 raeburn 3680: }
3681: } else {
1.330 raeburn 3682: unless ($cfile =~ m{^/priv/}) {
1.395 raeburn 3683: if ($cfile =~ m{^(/adm/wrapper/ext/([^#]+))(?:|#([^#]+))$}) {
1.375 raeburn 3684: $cfile = $1;
1.383 raeburn 3685: my $extlink = $2;
3686: $anchor = $3;
3687: $is_ext = 1;
3688: if (($extlink !~ /^https:/) && ($ENV{'SERVER_PORT'} == 443)) {
1.398 raeburn 3689: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.394 raeburn 3690: $usehttp = 1;
3691: }
1.383 raeburn 3692: } elsif ($env{'request.use_absolute'}) {
3693: if ($env{'request.use_absolute'} =~ m{^https://}) {
3694: $usehttps = 1;
3695: }
3696: }
1.382 raeburn 3697: } elsif ($cfile =~ m{^/?public/($match_domain)/($match_courseid)/syllabus}) {
1.380 raeburn 3698: if ($ENV{'SERVER_PORT'} == 443) {
3699: my ($cdom,$cnum) = ($1,$2);
3700: if (($env{'request.course.id'}) &&
3701: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $cnum) &&
3702: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $cdom)) {
3703: if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
1.398 raeburn 3704: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.394 raeburn 3705: $usehttp = 1;
3706: }
1.380 raeburn 3707: }
3708: }
1.381 raeburn 3709: } elsif ($env{'request.use_absolute'}) {
3710: if ($env{'request.use_absolute'} =~ m{^https://}) {
3711: $usehttps = 1;
3712: }
1.380 raeburn 3713: }
1.375 raeburn 3714: }
1.330 raeburn 3715: if ($symb) {
1.375 raeburn 3716: if ($anchor ne '') {
3717: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
3718: $symb = $1.&escape(&escape('#')).$anchor;
3719: }
3720: }
1.332 raeburn 3721: $cfile .= (($cfile=~/\?/)?'&':'?')."symb=$symb";
3722: } elsif ($folderpath) {
3723: $cfile .= (($cfile=~/\?/)?'&':'?').
3724: 'folderpath='.&HTML::Entities::encode(&escape($folderpath),'"<>&');
3725: if ($title) {
3726: $cfile .= (($cfile=~/\?/)?'&':'?').
3727: 'title='.&HTML::Entities::encode(&escape($title),'"<>&');
3728: }
3729: if ($idx) {
3730: $cfile .= (($cfile=~/\?/)?'&':'?').'idx='.$idx;
3731: }
3732: if ($suppurl) {
3733: $cfile .= (($cfile=~/\?/)?'&':'?').
3734: 'suppurl='.&HTML::Entities::encode(&escape($suppurl));
3735: }
1.330 raeburn 3736: }
3737: if ($forceedit) {
3738: $cfile .= (($cfile=~/\?/)?'&':'?').'forceedit=1';
1.382 raeburn 3739: if ($usehttps) {
3740: $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile;
1.381 raeburn 3741: }
1.380 raeburn 3742: } elsif ($usehttp) {
1.381 raeburn 3743: if ($hostname ne '') {
1.382 raeburn 3744: $cfile = 'http://'.$hostname.(($cfile =~ /^\//)? '':'/').$cfile;
1.381 raeburn 3745: }
1.395 raeburn 3746: $cfile .= (($cfile=~/\?/)?'&':'?').'usehttp=1';
1.382 raeburn 3747: } elsif ($usehttps) {
3748: $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile;
1.330 raeburn 3749: }
3750: if ($forcereg) {
3751: $cfile .= (($cfile=~/\?/)?'&':'?').'register=1';
3752: }
1.337 raeburn 3753: if ($todocs) {
1.376 raeburn 3754: $cfile .= (($cfile=~/\?/)?'&':'?').'todocs=1';
3755: }
3756: if ($suppanchor ne '') {
3757: $cfile .= (($cfile=~/\?/)?'&':'?').'anchor='.
3758: &HTML::Entities::encode($suppanchor,'"<>&');
1.337 raeburn 3759: }
1.328 raeburn 3760: }
1.375 raeburn 3761: if ($anchor ne '') {
3762: $cfile .= '#'.$anchor;
3763: }
1.358 raeburn 3764: $jscall = "go('".&Apache::loncommon::escape_single($cfile)."')";
1.328 raeburn 3765: }
3766: return $jscall;
3767: }
1.313 raeburn 3768:
3769: ##############################################
3770: ##############################################
3771:
1.158 raeburn 3772: # javascript_valid_email
3773: #
3774: # Generates javascript to validate an e-mail address.
1.388 raeburn 3775: # Returns a javascript function which accepts a form field as argument, and
1.158 raeburn 3776: # returns false if field.value does not satisfy two regular expression matches
3777: # for a valid e-mail address. Backwards compatible with old browsers without
3778: # support for javascript RegExp (just checks for @ in field.value in this case).
3779:
3780: sub javascript_valid_email {
3781: my $scripttag .= <<'END';
1.388 raeburn 3782: function validmail(field,suffix) {
1.158 raeburn 3783: var str = field.value;
1.388 raeburn 3784: if (suffix != '' && suffix != undefined) {
3785: str += suffix;
3786: }
1.158 raeburn 3787: if (window.RegExp) {
3788: var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
3789: var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
3790: var reg1 = new RegExp(reg1str);
3791: var reg2 = new RegExp(reg2str);
3792: if (!reg1.test(str) && reg2.test(str)) {
3793: return true;
3794: }
3795: return false;
3796: }
3797: else
3798: {
3799: if(str.indexOf("@") >= 0) {
3800: return true;
3801: }
3802: return false;
3803: }
3804: }
3805: END
3806: return $scripttag;
3807: }
3808:
1.219 droeschl 3809:
3810: # USAGE: htmltag(element, content, {attribute => value,...});
3811: #
3812: # EXAMPLES:
3813: # - htmltag('a', 'this is an anchor', {href => 'www.example.com',
3814: # title => 'this is a title'})
3815: #
3816: # - You might want to set up needed tags like:
3817: #
3818: # my $h3 = sub { return htmltag( "h3", @_ ) };
3819: #
3820: # ... and use them: $h3->("This is a headline")
3821: #
3822: # - To set up a couple of tags, see sub inittags
3823: #
3824: # NOTES:
3825: # - Empty elements, such as <br/> are correctly terminated,
3826: # i.e. htmltag('br') returns <br/>
3827: # - Empty attributes (title="") are filtered out.
3828: # - The function will not check for deprecated attributes.
3829: #
3830: # OUTPUT: content enclosed in xhtml conform tags
3831: sub htmltag{
3832: return
3833: qq|<$_[0]|
1.357 raeburn 3834: . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys(%{ $_[2] }) )
1.219 droeschl 3835: . ($_[1] ? qq|>$_[1]</$_[0]>| : qq|/>|). "\n";
3836: };
3837:
3838:
3839: # USAGE: inittags(@tags);
3840: #
3841: # EXAMPLES:
1.261 droeschl 3842: # - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )
1.219 droeschl 3843: # $h1->("This is a headline") #Returns: <h1>This is a headline</h1>
3844: #
3845: # NOTES: See sub htmltag for further information.
3846: #
3847: # OUTPUT: List of subroutines.
3848: sub inittags {
3849: my @tags = @_;
3850: return map { my $tag = $_;
3851: sub { return htmltag( $tag, @_ ) }
3852: } @tags;
3853: }
3854:
3855:
1.231 droeschl 3856: # USAGE: scripttag(scriptcode, [start|end|both]);
1.229 droeschl 3857: #
3858: # EXAMPLES:
1.231 droeschl 3859: # - scripttag("alert('Hello World!')", 'both')
3860: # returns:
3861: # <script type="text/javascript">
3862: # // BEGIN LON-CAPA Internal
3863: # alert(Hello World!')
3864: # // END LON-CAPA Internal
3865: # </script>
1.229 droeschl 3866: #
3867: # NOTES:
3868: # - works currently only for javascripts
3869: #
1.231 droeschl 3870: # OUTPUT:
3871: # Scriptcode properly enclosed in <script> and CDATA tags (and LC
3872: # Internal markers if 2nd argument is given)
1.229 droeschl 3873: sub scripttag {
1.231 droeschl 3874: my ( $content, $marker ) = @_;
3875: return unless defined $content;
3876:
3877: my $begin = "\n// BEGIN LON-CAPA Internal\n";
3878: my $end = "\n// END LON-CAPA Internal\n";
3879:
3880: if ($marker) {
3881: $content = $begin . $content if $marker eq 'start' or $marker eq 'both';
3882: $content .= $end if $marker eq 'end' or $marker eq 'both';
3883: }
3884:
1.229 droeschl 3885: $content = "\n// <![CDATA[\n$content\n// ]]>\n";
1.231 droeschl 3886:
3887: return htmltag('script', $content, {type => 'text/javascript'});
1.229 droeschl 3888: };
3889:
1.309 raeburn 3890: =pod
1.229 droeschl 3891:
1.309 raeburn 3892: =item &list_from_array( \@array, { listattr =>{}, itemattr =>{} } )
1.261 droeschl 3893:
3894: Constructs a XHTML list from \@array.
3895:
1.361 musolffc 3896: =over
3897:
3898: =item input:
1.261 droeschl 3899:
3900: =over
3901:
3902: =item \@array
3903:
3904: A reference to the array containing text that will be wrapped in <li></li> tags.
3905:
3906: =item { listattr => {}, itemattr =>{} }
3907:
3908: Attributes for <ul> and <li> passed in as hash references.
3909: See htmltag() for more details.
3910:
3911: =back
1.361 musolffc 3912:
3913: =back
1.362 raeburn 3914:
1.261 droeschl 3915: returns: XHTML list as String.
3916:
3917: =cut
3918:
3919: # \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}
3920: sub list_from_array {
3921: my ($items, $args) = @_;
1.285 raeburn 3922: return unless (ref($items) eq 'ARRAY');
1.273 droeschl 3923: return unless scalar @$items;
1.261 droeschl 3924: my ($ul, $li) = inittags( qw(ul li) );
3925: my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;
3926: return $ul->( $listitems, $args->{listattr} );
3927: }
3928:
3929:
1.183 droeschl 3930: ##############################################
3931: ##############################################
3932:
3933: # generate_menu
3934: #
3935: # Generates html markup for a menu.
3936: #
3937: # Inputs:
3938: # An array of following structure:
3939: # ({ categorytitle => 'Categorytitle',
3940: # items => [
1.201 droeschl 3941: # {
3942: # linktext => 'Text to be displayed',
3943: # url => 'URL the link is pointing to, i.e. /adm/site?action=dosomething',
1.183 droeschl 3944: # permission => 'Contains permissions as returned from lonnet::allowed(),
1.201 droeschl 3945: # must evaluate to true in order to activate the link',
1.184 droeschl 3946: # icon => 'icon filename',
1.186 droeschl 3947: # alttext => 'alt text for the icon',
1.183 droeschl 3948: # help => 'Name of the corresponding helpfile',
3949: # linktitle => 'Description of the link (used for title tag)'
3950: # },
3951: # ...
3952: # ]
3953: # },
3954: # ...
3955: # )
3956: #
3957: # Outputs: A scalar containing the html markup for the menu.
3958:
3959: sub generate_menu {
3960: my @menu = @_;
1.201 droeschl 3961: # subs for specific html elements
1.219 droeschl 3962: my ($h3, $div, $ul, $li, $a, $img) = inittags( qw(h3 div ul li a img) );
1.201 droeschl 3963:
3964: my @categories; # each element represents the entire markup for a category
3965:
3966: foreach my $category (@menu) {
3967: my @links; # contains the links for the current $category
3968: foreach my $link (@{$$category{items}}) {
3969: next unless $$link{permission};
3970:
3971: # create the markup for the current $link and push it into @links.
3972: # each entry consists of an image and a text optionally followed
3973: # by a help link.
1.283 raeburn 3974: my $src;
3975: if ($$link{icon} ne '') {
3976: $src = '/res/adm/pages/'.$$link{icon};
3977: }
1.232 raeburn 3978: push(@links,$li->(
1.201 droeschl 3979: $a->(
3980: $img->("", {
3981: class => "LC_noBorder LC_middle",
1.283 raeburn 3982: src => $src,
1.202 droeschl 3983: alt => mt(defined($$link{alttext}) ?
3984: $$link{alttext} : $$link{linktext})
1.201 droeschl 3985: }), {
3986: href => $$link{url},
1.308 raeburn 3987: title => mt($$link{linktitle}),
3988: class => 'LC_menubuttons_link'
1.201 droeschl 3989: }).
1.202 droeschl 3990: $a->(mt($$link{linktext}), {
1.201 droeschl 3991: href => $$link{url},
1.202 droeschl 3992: title => mt($$link{linktitle}),
1.201 droeschl 3993: class => "LC_menubuttons_link"
3994: }).
3995: (defined($$link{help}) ?
3996: Apache::loncommon::help_open_topic($$link{help}) : ''),
1.232 raeburn 3997: {class => "LC_menubuttons_inline_text"}));
1.201 droeschl 3998: }
3999:
4000: # wrap categorytitle in <h3>, concatenate with
4001: # joined and in <ul> tags wrapped @links
4002: # and wrap everything in an enclosing <div> and push it into
4003: # @categories
4004: # such that each element looks like:
4005: # <div><h3>title</h3><ul><li>...</li>...</ul></div>
4006: # the category won't be added if there aren't any links
1.232 raeburn 4007: push(@categories,
1.202 droeschl 4008: $div->($h3->(mt($$category{categorytitle}), {class=>"LC_hcell"}).
1.201 droeschl 4009: $ul->(join('' ,@links), {class =>"LC_ListStyleNormal" }),
1.232 raeburn 4010: {class=>"LC_Box LC_400Box"})) if scalar(@links);
1.183 droeschl 4011: }
1.201 droeschl 4012:
4013: # wrap the joined @categories in another <div> (column layout)
4014: return $div->(join('', @categories), {class => "LC_columnSection"});
1.183 droeschl 4015: }
1.176 foxr 4016:
1.224 bisitz 4017: ##############################################
4018: ##############################################
4019:
4020: =pod
4021:
1.309 raeburn 4022: =item &start_funclist()
1.224 bisitz 4023:
4024: Start list of available functions
4025:
4026: Typically used to offer a simple list of available functions
4027: at top or bottom of page.
4028: All available functions/actions for the current page
4029: should be included in this list.
4030:
4031: If the optional headline text is not provided, a default text will be used.
4032:
1.361 musolffc 4033: =over
4034:
4035: =item Related routines:
1.224 bisitz 4036:
4037: =over 4
1.361 musolffc 4038:
4039: =item add_item_funclist
4040:
4041: =item end_funclist
4042:
1.224 bisitz 4043: =back
4044:
1.361 musolffc 4045: =back
1.224 bisitz 4046:
4047: Inputs: (optional) headline text
4048:
4049: Returns: HTML code with function list start
4050:
4051: =cut
4052:
4053: ##############################################
4054: ##############################################
4055:
4056: sub start_funclist {
4057: my($legendtext)=@_;
4058: $legendtext=&mt('Functions') if !$legendtext;
1.244 droeschl 4059: return '<ul class="LC_funclist"><li style="font-weight:bold; margin-left:0.8em;">'.$legendtext.'</li>'."\n";
1.224 bisitz 4060: }
4061:
4062:
4063: ##############################################
4064: ##############################################
4065:
4066: =pod
4067:
1.309 raeburn 4068: =item &add_item_funclist()
1.224 bisitz 4069:
4070: Adds an item to the list of available functions
4071:
1.361 musolffc 4072: =over
4073:
4074: =item Related routines:
4075:
1.224 bisitz 4076: =over 4
1.361 musolffc 4077:
4078: =item start_funclist
4079:
4080: =item end_funclist
4081:
4082: =back
4083:
1.224 bisitz 4084: =back
4085:
4086: Inputs: content item with text and link to function
4087:
4088: Returns: HTML code with list item for funclist
4089:
4090: =cut
4091:
4092: ##############################################
4093: ##############################################
4094:
4095: sub add_item_funclist {
4096: my($content) = @_;
4097: return '<li>'.$content.'</li>'."\n";
4098: }
4099:
4100: =pod
4101:
1.309 raeburn 4102: =item &end_funclist()
1.224 bisitz 4103:
4104: End list of available functions
4105:
1.361 musolffc 4106: =over
4107:
4108: =item Related routines:
4109:
4110: start_funclist
4111: add_item_funclist
4112:
4113: =back
4114:
1.224 bisitz 4115: Inputs: ./.
4116:
4117: Returns: HTML code with function list end
1.362 raeburn 4118:
1.224 bisitz 4119: =cut
4120:
4121: sub end_funclist {
1.246 bisitz 4122: return "</ul>\n";
1.224 bisitz 4123: }
4124:
1.362 raeburn 4125: =pod
1.261 droeschl 4126:
1.309 raeburn 4127: =item &funclist_from_array( \@array, {legend => 'text for legend'} )
1.261 droeschl 4128:
4129: Constructs a XHTML list from \@array with the first item being visually
4130: highlighted and set to the value of legend or 'Functions' if legend is
4131: empty.
4132:
4133: =over
4134:
4135: =item \@array
4136:
4137: A reference to the array containing text that will be wrapped in <li></li> tags.
4138:
4139: =item { legend => 'text' }
4140:
4141: A string that's used as visually highlighted first item. 'Functions' is used if
4142: it's value evaluates to false.
4143:
4144: =back
1.362 raeburn 4145:
1.261 droeschl 4146: returns: XHTML list as string.
4147:
4148: =back
4149:
4150: =cut
4151:
4152: sub funclist_from_array {
4153: my ($items, $args) = @_;
1.285 raeburn 4154: return unless(ref($items) eq 'ARRAY');
1.261 droeschl 4155: $args->{legend} ||= mt('Functions');
4156: return list_from_array( [$args->{legend}, @$items],
4157: { listattr => {class => 'LC_funclist'} });
1.362 raeburn 4158: }
4159:
4160: =pod
1.261 droeschl 4161:
1.361 musolffc 4162: =over
1.335 bisitz 4163:
4164: =item &actionbox( \@array )
4165:
4166: Constructs a XHTML list from \@array with the first item being visually
4167: highlighted and set to the value 'Actions'. The list is wrapped in a division.
4168:
4169: The actionlist is used to offer contextual actions, mostly at the bottom
4170: of a page, on which the outcome of an processed action is shown,
1.346 raeburn 4171: e.g. a file operation in Authoring Space.
1.335 bisitz 4172:
4173: =over
4174:
4175: =item \@array
4176:
4177: A reference to the array containing text. Details: sub funclist_from_array
4178:
4179: =back
1.362 raeburn 4180:
1.335 bisitz 4181: Returns: XHTML div as string.
4182:
4183: =back
4184:
4185: =cut
4186:
4187: sub actionbox {
4188: my ($items) = @_;
4189: return unless(ref($items) eq 'ARRAY');
4190: return
4191: '<div class="LC_actionbox">'
4192: .&funclist_from_array($items, {legend => &mt('Actions')})
4193: .'</div>';
4194: }
4195:
1.1 stredwic 4196: 1;
1.23 matthew 4197:
1.1 stredwic 4198: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>