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