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