Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.310
1.2 www 1: # The LearningOnline Network with CAPA
2: # a pile of common html routines
3: #
1.310 ! raeburn 4: # $Id: lonhtmlcommon.pm,v 1.309 2012/04/16 19:24:59 raeburn Exp $
1.2 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.10 matthew 28: ######################################################################
29: ######################################################################
30:
31: =pod
32:
33: =head1 NAME
34:
35: Apache::lonhtmlcommon - routines to do common html things
36:
37: =head1 SYNOPSIS
38:
39: Referenced by other mod_perl Apache modules.
40:
41: =head1 INTRODUCTION
42:
43: lonhtmlcommon is a collection of subroutines used to present information
44: in a consistent html format, or provide other functionality related to
45: html.
46:
47: =head2 General Subroutines
48:
49: =over 4
50:
51: =cut
52:
53: ######################################################################
54: ######################################################################
1.2 www 55:
1.1 stredwic 56: package Apache::lonhtmlcommon;
57:
1.104 albertel 58: use strict;
1.10 matthew 59: use Time::Local;
1.47 sakharuk 60: use Time::HiRes;
1.30 www 61: use Apache::lonlocal;
1.104 albertel 62: use Apache::lonnet;
1.286 www 63: use HTML::Entities();
1.130 www 64: use LONCAPA;
1.1 stredwic 65:
1.284 www 66: sub java_not_enabled {
67: return "\n".'<span class="LC_error">'.
68: &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.').
69: "</span>\n";
70: }
1.247 www 71:
72: sub coursepreflink {
73: my ($text,$category)=@_;
74: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
1.296 www 75: return '<a target="_top" href="'.&HTML::Entities::encode("/adm/courseprefs?phase=display&actions=$category",'<>&"').'"><span class="LC_setting">'.$text.'</span></a>';
1.247 www 76: } else {
77: return '';
78: }
79: }
80:
1.253 www 81: sub raw_href_to_link {
82: my ($message)=@_;
1.264 faziophi 83: $message=~s/(https?\:\/\/[^\s\'\"\<]+)([\s\<]|$)/<a href="$1"><tt>$1<\/tt><\/a>$2/gi;
1.253 www 84: return $message;
85: }
86:
1.286 www 87: sub entity_encode {
88: my ($text)=@_;
89: return &HTML::Entities::encode($text, '<>&"');
90: }
91:
92: sub direct_parm_link {
93: my ($linktext,$symb,$filter,$part,$target)=@_;
94: $symb=&entity_encode($symb);
95: $filter=&entity_encode($filter);
96: $part=&entity_encode($part);
97: if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) {
1.296 www 98: return "<a target='_top' href='/adm/parmset?symb=$symb&filter=$filter&part=$part'><span class='LC_setting'>$linktext</span></a>";
1.286 www 99: } else {
100: return $linktext;
101: }
102: }
1.208 www 103: ##############################################
104: ##############################################
105:
1.309 raeburn 106: =item &confirm_success()
1.208 www 107:
108: Successful completion of an operation message
109:
110: =cut
111:
112: sub confirm_success {
1.209 www 113: my ($message,$failure)=@_;
114: if ($failure) {
1.265 wenzelju 115: return '<span class="LC_error" style="font-size: inherit;">'."\n"
1.218 bisitz 116: .'<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.&mt('Error').'" /> '."\n"
1.211 bisitz 117: .$message."\n"
118: .'</span>'."\n";
1.209 www 119: } else {
1.211 bisitz 120: return '<span class="LC_success">'."\n"
1.233 raeburn 121: .'<img src="/adm/lonIcons/navmap.correct.gif" alt="'.&mt('OK').'" /> '."\n"
1.211 bisitz 122: .$message."\n"
123: .'</span>'."\n";
1.209 www 124: }
1.208 www 125: }
1.176 foxr 126:
127: ##############################################
128: ##############################################
129:
130: =pod
131:
1.309 raeburn 132: =item &dragmath_button()
1.176 foxr 133:
1.177 raeburn 134: Creates a button that launches a dragmath popup-window, in which an
135: expression can be edited and pasted as LaTeX into a specified textarea.
136:
137: textarea - Name of the textarea to edit.
138: helpicon - If true, show a help icon to the right of the button.
1.176 foxr 139:
140: =cut
141:
1.177 raeburn 142: sub dragmath_button {
143: my ($textarea,$helpicon) = @_;
144: my $help_text;
145: if ($helpicon) {
1.282 raeburn 146: $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor',undef,undef,undef,undef,'mathhelpicon_'.$textarea);
1.177 raeburn 147: }
1.178 bisitz 148: my $buttontext=&mt('Edit Math');
1.177 raeburn 149: return <<ENDDRAGMATH;
1.246 bisitz 150: <input type="button" value="$buttontext" onclick="javascript:mathedit('$textarea',document)" />$help_text
1.177 raeburn 151: ENDDRAGMATH
152: }
153:
1.176 foxr 154: ##############################################
155:
1.177 raeburn 156: =pod
157:
1.309 raeburn 158: =item &dragmath_js()
1.177 raeburn 159:
160: Javascript used to open pop-up window containing dragmath applet which
161: can be used to paste LaTeX into a textarea.
1.309 raeburn 162:
1.177 raeburn 163: =cut
1.176 foxr 164:
1.177 raeburn 165: sub dragmath_js {
1.182 foxr 166: my ($popup) = @_;
1.177 raeburn 167: return <<ENDDRAGMATHJS;
168: <script type="text/javascript">
1.218 bisitz 169: // <![CDATA[
1.176 foxr 170: function mathedit(textarea, doc) {
171: targetEntry = textarea;
1.177 raeburn 172: targetDoc = doc;
1.182 foxr 173: newwin = window.open("/adm/dragmath/applet/$popup.html","","width=565,height=500,resizable");
1.176 foxr 174: }
1.218 bisitz 175: // ]]>
1.176 foxr 176: </script>
1.177 raeburn 177:
178: ENDDRAGMATHJS
1.176 foxr 179: }
180:
1.309 raeburn 181: ##############################################
182: ##############################################
183:
184: =pod
185:
186: =item &dependencies_button()
187:
188: Creates a button that launches a popup-window, in which dependencies
189: for the web page in the main window can be added to, replaced or deleted.
190:
191: =cut
192:
193: sub dependencies_button {
194: my $buttontext=&mt('Manage Dependencies');
195: return <<"END";
196: <input type="button" value="$buttontext" onclick="javascript:dependencycheck();" />
197: END
198: }
199:
200: ##############################################
201:
202: =pod
203:
204: =item &dependencycheck_js()
205:
206: Javascript used to open pop-up window containing interface to manage
207: dependencies for a web page uploaded diretcly to a course.
208:
209: =cut
210:
211: sub dependencycheck_js {
212: my ($symb,$title) = @_;
213: my $link = '/adm/dependencies?symb='.&HTML::Entities::encode($symb,'<>&"').
214: '&title='.&HTML::Entities::encode($title,'<>&"');
215: return <<ENDJS;
216: <script type="text/javascript">
217: // <![CDATA[
218: function dependencycheck() {
219: depwin = window.open("$link","","width=750,height=500,resizable,scrollbars=yes");
220: }
221: // ]]>
222: </script>
223: ENDJS
224: }
1.182 foxr 225:
1.40 www 226: ##############################################
227: ##############################################
228:
229: =pod
230:
1.309 raeburn 231: =item &authorbombs()
1.40 www 232:
233: =cut
234:
235: ##############################################
236: ##############################################
237:
238: sub authorbombs {
239: my $url=shift;
240: $url=&Apache::lonnet::declutter($url);
1.155 albertel 241: my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/});
1.40 www 242: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.232 raeburn 243: foreach my $bomb (keys(%bombs)) {
244: if ($bomb =~ /^$udom\/$uname\//) {
1.40 www 245: return '<a href="/adm/bombs/'.$url.
1.218 bisitz 246: '"><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/bomb.gif').'" alt="'.&mt('Bomb').'" border="0" /></a>'.
1.40 www 247: &Apache::loncommon::help_open_topic('About_Bombs');
248: }
249: }
250: return '';
251: }
1.26 matthew 252:
253: ##############################################
254: ##############################################
255:
1.41 www 256: sub recent_filename {
257: my $area=shift;
1.130 www 258: return 'nohist_recent_'.&escape($area);
1.41 www 259: }
260:
261: sub store_recent {
1.136 albertel 262: my ($area,$name,$value,$freeze)=@_;
1.41 www 263: my $file=&recent_filename($area);
264: my %recent=&Apache::lonnet::dump($file);
1.111 www 265: if (scalar(keys(%recent))>20) {
1.41 www 266: # remove oldest value
1.136 albertel 267: my $oldest=time();
1.41 www 268: my $delkey='';
1.136 albertel 269: foreach my $item (keys(%recent)) {
270: my $thistime=(split(/\&/,$recent{$item}))[0];
271: if (($thistime ne "always_include") && ($thistime<$oldest)) {
1.41 www 272: $oldest=$thistime;
1.136 albertel 273: $delkey=$item;
1.41 www 274: }
275: }
276: &Apache::lonnet::del($file,[$delkey]);
277: }
278: # store new value
1.136 albertel 279: my $timestamp;
280: if ($freeze) {
281: $timestamp = "always_include";
282: } else {
283: $timestamp = time();
284: }
1.41 www 285: &Apache::lonnet::put($file,{ $name =>
1.136 albertel 286: $timestamp.'&'.&escape($value) });
1.41 www 287: }
288:
1.89 banghart 289: sub remove_recent {
290: my ($area,$names)=@_;
291: my $file=&recent_filename($area);
292: return &Apache::lonnet::del($file,$names);
293: }
294:
1.41 www 295: sub select_recent {
296: my ($area,$fieldname,$event)=@_;
297: my %recent=&Apache::lonnet::dump(&recent_filename($area));
298: my $return="\n<select name='$fieldname'".
1.96 albertel 299: ($event?" onchange='$event'":'').
1.41 www 300: ">\n<option value=''>--- ".&mt('Recent')." ---</option>";
1.136 albertel 301: foreach my $value (sort(keys(%recent))) {
302: unless ($value =~/^error\:/) {
303: my $escaped = &Apache::loncommon::escape_url($value);
1.160 albertel 304: &Apache::loncommon::inhibit_menu_check(\$escaped);
1.251 raeburn 305: if ($area eq 'residx') {
306: next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value)));
307: }
1.94 foxr 308: $return.="\n<option value='$escaped'>".
1.136 albertel 309: &unescape((split(/\&/,$recent{$value}))[1]).
1.41 www 310: '</option>';
311: }
312: }
313: $return.="\n</select>\n";
314: return $return;
315: }
316:
1.97 albertel 317: sub get_recent {
318: my ($area, $n) = @_;
319: my %recent=&Apache::lonnet::dump(&recent_filename($area));
320:
321: # Create hash with key as time and recent as value
1.136 albertel 322: # Begin filling return_hash with any 'always_include' option
1.97 albertel 323: my %time_hash = ();
1.136 albertel 324: my %return_hash = ();
1.232 raeburn 325: foreach my $item (keys(%recent)) {
1.136 albertel 326: my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
327: if ($thistime eq 'always_include') {
328: $return_hash{$item} = &unescape($thisvalue);
329: $n--;
330: } else {
331: $time_hash{$thistime} = $item;
1.133 albertel 332: }
1.97 albertel 333: }
334:
335: # Sort by decreasing time and return key value pairs
336: my $idx = 1;
1.136 albertel 337: foreach my $item (reverse(sort(keys(%time_hash)))) {
338: $return_hash{$time_hash{$item}} =
339: &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]);
1.97 albertel 340: if ($n && ($idx++ >= $n)) {last;}
341: }
342:
343: return %return_hash;
344: }
345:
1.136 albertel 346: sub get_recent_frozen {
347: my ($area) = @_;
348: my %recent=&Apache::lonnet::dump(&recent_filename($area));
349:
350: # Create hash with all 'frozen' items
351: my %return_hash = ();
352: foreach my $item (keys(%recent)) {
353: my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
354: if ($thistime eq 'always_include') {
355: $return_hash{$item} = &unescape($thisvalue);
356: }
357: }
358: return %return_hash;
359: }
360:
1.97 albertel 361:
1.41 www 362:
1.26 matthew 363: =pod
364:
1.309 raeburn 365: =item &textbox()
1.26 matthew 366:
367: =cut
368:
369: ##############################################
370: ##############################################
371: sub textbox {
372: my ($name,$value,$size,$special) = @_;
373: $size = 40 if (! defined($size));
1.128 albertel 374: $value = &HTML::Entities::encode($value,'<>&"');
1.26 matthew 375: my $Str = '<input type="text" name="'.$name.'" size="'.$size.'" '.
376: 'value="'.$value.'" '.$special.' />';
377: return $Str;
378: }
379:
380: ##############################################
381: ##############################################
382:
383: =pod
384:
1.309 raeburn 385: =item &checkbox()
1.26 matthew 386:
387: =cut
388:
389: ##############################################
390: ##############################################
391: sub checkbox {
1.68 matthew 392: my ($name,$checked,$value) = @_;
393: my $Str = '<input type="checkbox" name="'.$name.'" ';
394: if (defined($value)) {
395: $Str .= 'value="'.$value.'"';
396: }
397: if ($checked) {
1.206 bisitz 398: $Str .= ' checked="checked"';
1.68 matthew 399: }
400: $Str .= ' />';
1.26 matthew 401: return $Str;
402: }
403:
1.120 albertel 404:
405: =pod
406:
1.309 raeburn 407: =item &radiobutton()
1.120 albertel 408:
409: =cut
410:
411: ##############################################
412: ##############################################
413: sub radio {
414: my ($name,$checked,$value) = @_;
415: my $Str = '<input type="radio" name="'.$name.'" ';
416: if (defined($value)) {
417: $Str .= 'value="'.$value.'"';
418: }
419: if ($checked eq $value) {
1.206 bisitz 420: $Str .= ' checked="checked"';
1.120 albertel 421: }
422: $Str .= ' />';
423: return $Str;
424: }
425:
1.10 matthew 426: ##############################################
427: ##############################################
428:
429: =pod
430:
1.309 raeburn 431: =item &date_setter()
1.10 matthew 432:
1.22 matthew 433: &date_setter returns html and javascript for a compact date-setting form.
1.309 raeburn 434: To retrieve values from it, use &get_date_from_form.
1.22 matthew 435:
1.10 matthew 436: Inputs
437:
438: =over 4
439:
440: =item $dname
441:
442: The name to prepend to the form elements.
443: The form elements defined will be dname_year, dname_month, dname_day,
444: dname_hour, dname_min, and dname_sec.
445:
446: =item $currentvalue
447:
448: The current setting for this time parameter. A unix format time
449: (time in seconds since the beginning of Jan 1st, 1970, GMT.
1.257 faziophi 450: An undefined value is taken to indicate the value is the current time
451: unless it is requested to leave it empty. See $includeempty.
1.10 matthew 452: Also, to be explicit, a value of 'now' also indicates the current time.
453:
1.26 matthew 454: =item $special
455:
456: Additional html/javascript to be associated with each element in
457: the date_setter. See lonparmset for example usage.
458:
1.59 matthew 459: =item $includeempty
460:
1.257 faziophi 461: If it is set (true) and no date/time value is provided,
462: the date/time fields are left empty.
463:
1.59 matthew 464: =item $state
465:
466: Specifies the initial state of the form elements. Either 'disabled' or empty.
467: Defaults to empty, which indiciates the form elements are not disabled.
468:
1.22 matthew 469: =back
470:
471: Bugs
472:
473: The method used to restrict user input will fail in the year 2400.
474:
1.10 matthew 475: =cut
476:
477: ##############################################
478: ##############################################
479: sub date_setter {
1.67 matthew 480: my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
1.134 raeburn 481: $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_;
1.175 raeburn 482: my $now = time;
1.257 faziophi 483:
484: my $tzname;
485: my ($sec,$min,$hour,$mday,$month,$year) = ('', '', undef,''.''.'');
486: #other potentially useful values: wkday,yrday,is_daylight_savings
487:
1.59 matthew 488: if (! defined($state) || $state ne 'disabled') {
489: $state = '';
490: }
1.67 matthew 491: if (! defined($no_hh_mm_ss)) {
492: $no_hh_mm_ss = 0;
493: }
1.110 www 494: if ($currentvalue eq 'now') {
1.257 faziophi 495: $currentvalue = $now;
1.110 www 496: }
1.257 faziophi 497:
498: # Default value: Set empty date field to current time
499: # unless empty inclusion is requested
500: if ((!$includeempty) && (!$currentvalue)) {
501: $currentvalue = $now;
1.10 matthew 502: }
1.257 faziophi 503: # Do we have a date? Split it!
1.39 www 504: if ($currentvalue) {
1.257 faziophi 505: ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue);
506:
507: #No values provided for hour, min, sec? Use default 0
508: if (($defhour) || ($defmin) || ($defsec)) {
509: $sec = ($defsec ? $defsec : 0);
510: $min = ($defmin ? $defmin : 0);
511: $hour = ($defhour ? $defhour : 0);
512: }
1.107 www 513: }
1.10 matthew 514: my $result = "\n<!-- $dname date setting form -->\n";
515: $result .= <<ENDJS;
1.135 albertel 516: <script type="text/javascript">
1.218 bisitz 517: // <![CDATA[
1.10 matthew 518: function $dname\_checkday() {
519: var day = document.$formname.$dname\_day.value;
520: var month = document.$formname.$dname\_month.value;
521: var year = document.$formname.$dname\_year.value;
522: var valid = true;
523: if (day < 1) {
524: document.$formname.$dname\_day.value = 1;
525: }
526: if (day > 31) {
527: document.$formname.$dname\_day.value = 31;
528: }
529: if ((month == 1) || (month == 3) || (month == 5) ||
530: (month == 7) || (month == 8) || (month == 10) ||
531: (month == 12)) {
532: if (day > 31) {
533: document.$formname.$dname\_day.value = 31;
534: day = 31;
535: }
536: } else if (month == 2 ) {
537: if ((year % 4 == 0) && (year % 100 != 0)) {
538: if (day > 29) {
539: document.$formname.$dname\_day.value = 29;
540: }
541: } else if (day > 29) {
542: document.$formname.$dname\_day.value = 28;
543: }
544: } else if (day > 30) {
545: document.$formname.$dname\_day.value = 30;
546: }
547: }
1.95 matthew 548:
1.59 matthew 549: function $dname\_disable() {
550: document.$formname.$dname\_month.disabled=true;
551: document.$formname.$dname\_day.disabled=true;
552: document.$formname.$dname\_year.disabled=true;
553: document.$formname.$dname\_hour.disabled=true;
554: document.$formname.$dname\_minute.disabled=true;
555: document.$formname.$dname\_second.disabled=true;
556: }
557:
558: function $dname\_enable() {
559: document.$formname.$dname\_month.disabled=false;
560: document.$formname.$dname\_day.disabled=false;
561: document.$formname.$dname\_year.disabled=false;
562: document.$formname.$dname\_hour.disabled=false;
563: document.$formname.$dname\_minute.disabled=false;
564: document.$formname.$dname\_second.disabled=false;
565: }
566:
1.29 www 567: function $dname\_opencalendar() {
1.59 matthew 568: if (! document.$formname.$dname\_month.disabled) {
569: var calwin=window.open(
1.29 www 570: "/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
571: document.$formname.$dname\_month.value+"&year="+
572: document.$formname.$dname\_year.value,
573: "LONCAPAcal",
574: "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
1.59 matthew 575: }
1.29 www 576:
577: }
1.218 bisitz 578: // ]]>
1.10 matthew 579: </script>
580: ENDJS
1.192 bisitz 581: $result .= ' <span class="LC_nobreak">';
1.96 albertel 582: my $monthselector = qq{<select name="$dname\_month" $special $state onchange="javascript:$dname\_checkday()" >};
1.67 matthew 583: # Month
1.10 matthew 584: my @Months = qw/January February March April May June
585: July August September October November December/;
586: # Pad @Months with a bogus value to make indexing easier
587: unshift(@Months,'If you can read this an error occurred');
1.95 matthew 588: if ($includeempty) { $monthselector.="<option value=''></option>"; }
1.10 matthew 589: for(my $m = 1;$m <=$#Months;$m++) {
1.228 bisitz 590: $monthselector .= qq{ <option value="$m"};
591: $monthselector .= ' selected="selected"' if ($m-1 eq $month);
592: $monthselector .= '> '.&mt($Months[$m]).' </option>'."\n";
1.10 matthew 593: }
1.95 matthew 594: $monthselector.= ' </select>';
1.67 matthew 595: # Day
1.96 albertel 596: my $dayselector = qq{<input type="text" name="$dname\_day" $state value="$mday" size="3" $special onchange="javascript:$dname\_checkday()" />};
1.67 matthew 597: # Year
1.226 bisitz 598: my $yearselector = qq{<input type="text" name="$dname\_year" $state value="$year" size="5" $special onchange="javascript:$dname\_checkday()" />};
1.95 matthew 599: #
600: my $hourselector = qq{<select name="$dname\_hour" $special $state >};
601: if ($includeempty) {
602: $hourselector.=qq{<option value=''></option>};
603: }
604: for (my $h = 0;$h<24;$h++) {
1.228 bisitz 605: $hourselector .= qq{<option value="$h"};
606: $hourselector .= ' selected="selected"' if (defined($hour) && $hour == $h);
1.95 matthew 607: $hourselector .= ">";
608: my $timest='';
609: if ($h == 0) {
610: $timest .= "12 am";
611: } elsif($h == 12) {
612: $timest .= "12 noon";
613: } elsif($h < 12) {
614: $timest .= "$h am";
615: } else {
616: $timest .= $h-12 ." pm";
617: }
618: $timest=&mt($timest);
619: $hourselector .= $timest." </option>\n";
620: }
621: $hourselector .= " </select>\n";
622: my $minuteselector = qq{<input type="text" name="$dname\_minute" $special $state value="$min" size="3" />};
623: my $secondselector= qq{<input type="text" name="$dname\_second" $special $state value="$sec" size="3" />};
1.134 raeburn 624: my $cal_link;
625: if (!$nolink) {
626: $cal_link = qq{<a href="javascript:$dname\_opencalendar()">};
627: }
1.95 matthew 628: #
1.175 raeburn 629: my $tzone = ' '.$tzname.' ';
1.95 matthew 630: if ($no_hh_mm_ss) {
1.134 raeburn 631: $result .= &mt('[_1] [_2] [_3] ',
1.174 raeburn 632: $monthselector,$dayselector,$yearselector).
633: $tzone;
1.134 raeburn 634: if (!$nolink) {
1.141 albertel 635: $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
1.134 raeburn 636: }
1.95 matthew 637: } else {
1.134 raeburn 638: $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ',
639: $monthselector,$dayselector,$yearselector,
1.174 raeburn 640: $hourselector,$minuteselector,$secondselector).
641: $tzone;
1.134 raeburn 642: if (!$nolink) {
1.141 albertel 643: $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
1.134 raeburn 644: }
1.67 matthew 645: }
1.135 albertel 646: $result .= "</span>\n<!-- end $dname date setting form -->\n";
1.10 matthew 647: return $result;
648: }
649:
1.175 raeburn 650: sub get_timedates {
651: my ($epoch) = @_;
652: my $dt = DateTime->from_epoch(epoch => $epoch)
653: ->set_time_zone(&Apache::lonlocal::gettimezone());
654: my $tzname = $dt->time_zone_short_name();
655: my $sec = $dt->second;
656: my $min = $dt->minute;
657: my $hour = $dt->hour;
658: my $mday = $dt->day;
659: my $month = $dt->month;
660: if ($month) {
661: $month --;
662: }
663: my $year = $dt->year;
664: return ($tzname,$sec,$min,$hour,$mday,$month,$year);
665: }
1.166 banghart 666:
667: sub build_url {
668: my ($base, $fields)=@_;
669: my $url;
670: $url = $base.'?';
1.168 albertel 671: foreach my $key (keys(%$fields)) {
672: $url.=&escape($key).'='.&escape($$fields{$key}).'&';
1.166 banghart 673: }
674: $url =~ s/&$//;
675: return $url;
676: }
677:
678:
1.10 matthew 679: ##############################################
680: ##############################################
681:
1.22 matthew 682: =pod
683:
1.309 raeburn 684: =item &get_date_from_form()
1.22 matthew 685:
686: get_date_from_form retrieves the date specified in an &date_setter form.
1.10 matthew 687:
688: Inputs:
689:
690: =over 4
691:
692: =item $dname
693:
1.226 bisitz 694: The name passed to &date_setter, which prefixes the form elements.
1.10 matthew 695:
696: =item $defaulttime
697:
698: The unix time to use as the default in case of poor inputs.
699:
700: =back
701:
702: Returns: Unix time represented in the form.
703:
704: =cut
705:
706: ##############################################
707: ##############################################
708: sub get_date_from_form {
709: my ($dname) = @_;
710: my ($sec,$min,$hour,$day,$month,$year);
711: #
1.104 albertel 712: if (defined($env{'form.'.$dname.'_second'})) {
713: my $tmpsec = $env{'form.'.$dname.'_second'};
1.10 matthew 714: if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
715: $sec = $tmpsec;
716: }
1.64 albertel 717: if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
1.67 matthew 718: } else {
719: $sec = 0;
1.10 matthew 720: }
1.104 albertel 721: if (defined($env{'form.'.$dname.'_minute'})) {
722: my $tmpmin = $env{'form.'.$dname.'_minute'};
1.10 matthew 723: if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
724: $min = $tmpmin;
725: }
1.64 albertel 726: if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
1.67 matthew 727: } else {
728: $min = 0;
1.10 matthew 729: }
1.104 albertel 730: if (defined($env{'form.'.$dname.'_hour'})) {
731: my $tmphour = $env{'form.'.$dname.'_hour'};
1.33 matthew 732: if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
1.10 matthew 733: $hour = $tmphour;
734: }
1.67 matthew 735: } else {
736: $hour = 0;
1.10 matthew 737: }
1.104 albertel 738: if (defined($env{'form.'.$dname.'_day'})) {
739: my $tmpday = $env{'form.'.$dname.'_day'};
1.10 matthew 740: if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
741: $day = $tmpday;
742: }
743: }
1.104 albertel 744: if (defined($env{'form.'.$dname.'_month'})) {
745: my $tmpmonth = $env{'form.'.$dname.'_month'};
1.10 matthew 746: if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
1.175 raeburn 747: $month = $tmpmonth;
1.10 matthew 748: }
749: }
1.104 albertel 750: if (defined($env{'form.'.$dname.'_year'})) {
751: my $tmpyear = $env{'form.'.$dname.'_year'};
1.175 raeburn 752: if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) {
753: $year = $tmpyear;
1.10 matthew 754: }
755: }
1.175 raeburn 756: if (($year<1970) || ($year>2037)) { return undef; }
1.33 matthew 757: if (defined($sec) && defined($min) && defined($hour) &&
1.175 raeburn 758: defined($day) && defined($month) && defined($year)) {
759: my $timezone = &Apache::lonlocal::gettimezone();
760: my $dt = DateTime->new( year => $year,
761: month => $month,
762: day => $day,
763: hour => $hour,
764: minute => $min,
765: second => $sec,
766: time_zone => $timezone,
767: );
768: my $epoch_time = $dt->epoch;
769: if ($epoch_time ne '') {
770: return $epoch_time;
771: } else {
772: return undef;
773: }
1.10 matthew 774: } else {
775: return undef;
776: }
1.20 matthew 777: }
778:
779: ##############################################
780: ##############################################
781:
782: =pod
783:
784: =item &pjump_javascript_definition()
785:
786: Returns javascript defining the 'pjump' function, which opens up a
787: parameter setting wizard.
788:
789: =cut
790:
791: ##############################################
792: ##############################################
793: sub pjump_javascript_definition {
794: my $Str = <<END;
1.109 www 795: function pjump(type,dis,value,marker,ret,call,hour,min,sec) {
1.295 www 796: openMyModal("/adm/rat/parameter.html?type="+escape(type)
1.20 matthew 797: +"&value="+escape(value)+"&marker="+escape(marker)
798: +"&return="+escape(ret)
1.109 www 799: +"&call="+escape(call)+"&name="+escape(dis)
800: +"&defhour="+escape(hour)+"&defmin="+escape(min)
1.295 www 801: +"&defsec="+escape(sec)+"&modal=1",350,350,'no');
1.20 matthew 802: }
803: END
804: return $Str;
1.10 matthew 805: }
806:
807: ##############################################
808: ##############################################
1.17 matthew 809:
810: =pod
811:
812: =item &javascript_nothing()
813:
814: Return an appropriate null for the users browser. This is used
815: as the first arguement for window.open calls when you want a blank
816: window that you can then write to.
817:
818: =cut
819:
820: ##############################################
821: ##############################################
822: sub javascript_nothing {
823: # mozilla and other browsers work with "''", but IE on mac does not.
824: my $nothing = "''";
825: my $user_browser;
826: my $user_os;
1.104 albertel 827: $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
828: $user_os = $env{'browser.os'} if (exists($env{'browser.os'}));
1.17 matthew 829: if (! defined($user_browser) || ! defined($user_os)) {
830: (undef,$user_browser,undef,undef,undef,$user_os) =
831: &Apache::loncommon::decode_user_agent();
832: }
833: if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
834: $nothing = "'javascript:void(0);'";
835: }
836: return $nothing;
837: }
838:
1.90 www 839: ##############################################
840: ##############################################
841: sub javascript_docopen {
1.171 albertel 842: my ($mimetype) = @_;
843: $mimetype ||= 'text/html';
1.90 www 844: # safari does not understand document.open() and loads "text/html"
845: my $nothing = "''";
846: my $user_browser;
847: my $user_os;
1.104 albertel 848: $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
849: $user_os = $env{'browser.os'} if (exists($env{'browser.os'}));
1.90 www 850: if (! defined($user_browser) || ! defined($user_os)) {
851: (undef,$user_browser,undef,undef,undef,$user_os) =
852: &Apache::loncommon::decode_user_agent();
853: }
854: if ($user_browser eq 'safari' && $user_os =~ 'mac') {
855: $nothing = "document.clear()";
856: } else {
1.171 albertel 857: $nothing = "document.open('$mimetype','replace')";
1.90 www 858: }
859: return $nothing;
860: }
861:
1.21 matthew 862:
1.17 matthew 863: ##############################################
864: ##############################################
865:
1.21 matthew 866: =pod
1.17 matthew 867:
1.21 matthew 868: =item &StatusOptions()
1.10 matthew 869:
1.21 matthew 870: Returns html for a selection box which allows the user to choose the
871: enrollment status of students. The selection box name is 'Status'.
1.6 stredwic 872:
1.21 matthew 873: Inputs:
1.6 stredwic 874:
1.21 matthew 875: $status: the currently selected status. If undefined the value of
1.104 albertel 876: $env{'form.Status'} is taken. If that is undefined, a value of 'Active'
1.21 matthew 877: is used.
1.6 stredwic 878:
1.21 matthew 879: $formname: The name of the form. If defined the onchange attribute of
880: the selection box is set to document.$formname.submit().
1.6 stredwic 881:
1.21 matthew 882: $size: the size (number of lines) of the selection box.
1.6 stredwic 883:
1.27 matthew 884: $onchange: javascript to use when the value is changed. Enclosed in
885: double quotes, ""s, not single quotes.
886:
1.21 matthew 887: Returns: a perl string as described.
1.1 stredwic 888:
1.21 matthew 889: =cut
1.9 stredwic 890:
1.21 matthew 891: ##############################################
892: ##############################################
893: sub StatusOptions {
1.165 banghart 894: my ($status, $formName,$size,$onchange,$mult)=@_;
1.21 matthew 895: $size = 1 if (!defined($size));
896: if (! defined($status)) {
897: $status = 'Active';
1.104 albertel 898: $status = $env{'form.Status'} if (exists($env{'form.Status'}));
1.9 stredwic 899: }
1.1 stredwic 900:
901: my $Str = '';
902: $Str .= '<select name="Status"';
1.165 banghart 903: if (defined($mult)){
904: $Str .= ' multiple="multiple" ';
905: }
1.27 matthew 906: if(defined($formName) && $formName ne '' && ! defined($onchange)) {
1.1 stredwic 907: $Str .= ' onchange="document.'.$formName.'.submit()"';
1.27 matthew 908: }
909: if (defined($onchange)) {
910: $Str .= ' onchange="'.$onchange.'"';
1.1 stredwic 911: }
1.21 matthew 912: $Str .= ' size="'.$size.'" ';
1.1 stredwic 913: $Str .= '>'."\n";
1.153 raeburn 914: foreach my $type (['Active', &mt('Currently Has Access')],
915: ['Future', &mt('Will Have Future Access')],
916: ['Expired', &mt('Previously Had Access')],
917: ['Any', &mt('Any Access Status')]) {
1.151 albertel 918: my ($name,$label) = @$type;
919: $Str .= '<option value="'.$name.'" ';
920: if ($status eq $name) {
921: $Str .= 'selected="selected" ';
922: }
923: $Str .= '>'.$label.'</option>'."\n";
924: }
925:
1.1 stredwic 926: $Str .= '</select>'."\n";
1.7 stredwic 927: }
1.12 matthew 928:
929: ########################################################
930: ########################################################
1.7 stredwic 931:
1.23 matthew 932: =pod
933:
934: =item Progess Window Handling Routines
935:
936: These routines handle the creation, update, increment, and closure of
937: progress windows. The progress window reports to the user the number
938: of items completed and an estimate of the time required to complete the rest.
939:
940: =over 4
941:
942:
1.309 raeburn 943: =item &Create_PrgWin()
1.23 matthew 944:
945: Writes javascript to the client to open a progress window and returns a
946: data structure used for bookkeeping.
947:
948: Inputs
949:
950: =over 4
951:
952: =item $r Apache request
953:
954: =item $title The title of the progress window
955:
956: =item $heading A description (usually 1 line) of the process being initiated.
957:
958: =item $number_to_do The total number of items being processed.
1.50 albertel 959:
960: =item $type Either 'popup' or 'inline' (popup is assumed if nothing is
961: specified)
962:
1.51 albertel 963: =item $width Specify the width in charaters of the input field.
964:
1.50 albertel 965: =item $formname Only useful in the inline case, if a form already exists, this needs to be used and specfiy the name of the form, otherwise the Progress line will be created in a new form of it's own
966:
967: =item $inputname Only useful in the inline case, if a form and an input of type text exists, use this to specify the name of the input field
1.23 matthew 968:
969: =back
970:
971: Returns a hash containing the progress state data structure.
972:
973:
1.309 raeburn 974: =item &Update_PrgWin()
1.23 matthew 975:
976: Updates the text in the progress indicator. Does not increment the count.
977: See &Increment_PrgWin.
978:
979: Inputs:
980:
981: =over 4
982:
983: =item $r Apache request
984:
985: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
986:
987: =item $displaystring The string to write to the status indicator
988:
989: =back
990:
991: Returns: none
992:
993:
1.309 raeburn 994: =item Increment_PrgWin()
1.23 matthew 995:
1.276 bisitz 996: Increment the count of items completed for the progress window by $step or 1 if no step is provided.
1.23 matthew 997:
998: Inputs:
999:
1000: =over 4
1001:
1002: =item $r Apache request
1003:
1004: =item $prog_state Pointer to the data structure returned by Create_PrgWin
1005:
1006: =item $extraInfo A description of the items being iterated over. Typically
1007: 'student'.
1008:
1.279 bisitz 1009: =item $step (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
1.276 bisitz 1010:
1.23 matthew 1011: =back
1012:
1013: Returns: none
1014:
1015:
1.309 raeburn 1016: =item &Close_PrgWin()
1.23 matthew 1017:
1018: Closes the progress window.
1019:
1020: Inputs:
1021:
1022: =over 4
1023:
1024: =item $r Apache request
1025:
1026: =item $prog_state Pointer to the data structure returned by Create_PrgWin
1027:
1028: =back
1029:
1030: Returns: none
1031:
1032: =back
1033:
1034: =cut
1035:
1036: ########################################################
1037: ########################################################
1038:
1.51 albertel 1039:
1.7 stredwic 1040: # Create progress
1041: sub Create_PrgWin {
1.297 www 1042: my ($r,$number_to_do)=@_;
1.49 albertel 1043: my %prog_state;
1.16 albertel 1044: $prog_state{'done'}=0;
1.23 matthew 1045: $prog_state{'firststart'}=&Time::HiRes::time();
1046: $prog_state{'laststart'}=&Time::HiRes::time();
1.16 albertel 1047: $prog_state{'max'}=$number_to_do;
1.297 www 1048: &Apache::loncommon::LCprogressbar($r);
1.14 albertel 1049: return %prog_state;
1.7 stredwic 1050: }
1051:
1052: # update progress
1053: sub Update_PrgWin {
1.14 albertel 1054: my ($r,$prog_state,$displayString)=@_;
1.297 www 1055: &Apache::loncommon::LCprogressbarUpdate($r,undef,$displayString);
1.23 matthew 1056: $$prog_state{'laststart'}=&Time::HiRes::time();
1.14 albertel 1057: }
1058:
1059: # increment progress state
1060: sub Increment_PrgWin {
1.275 bisitz 1061: my ($r,$prog_state,$extraInfo,$step)=@_;
1.279 bisitz 1062: $step = $step > 0 ? $step : 1;
1.275 bisitz 1063: $$prog_state{'done'} += $step;
1064:
1065: # Catch (max modulo step) <> 0
1066: my $current = $$prog_state{'done'};
1067: my $last = ($$prog_state{'max'} - $current);
1068: if ($last <= 0) {
1069: $last = 1;
1070: $current = $$prog_state{'max'};
1071: }
1072:
1.23 matthew 1073: my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
1.275 bisitz 1074: $current * $last;
1.16 albertel 1075: $time_est = int($time_est);
1.80 matthew 1076: #
1077: my $min = int($time_est/60);
1078: my $sec = $time_est % 60;
1.278 bisitz 1079:
1.23 matthew 1080: my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
1081: if ($lasttime > 9) {
1082: $lasttime = int($lasttime);
1083: } elsif ($lasttime < 0.01) {
1084: $lasttime = 0;
1085: } else {
1086: $lasttime = sprintf("%3.2f",$lasttime);
1087: }
1.278 bisitz 1088:
1089: $sec = 0 if ($min >= 10); # Don't show seconds if remaining time >= 10 min.
1090: $sec = 1 if ( ($min == 0) && ($sec == 0) ); # Little cheating: pretend to have 1 second remaining instead of 0 to have something to display
1091:
1092: my $timeinfo =
1093: &mt('[_1]/[_2]:'
1094: .' [quant,_3,minute,minutes,] [quant,_4,second ,seconds ,]remaining'
1095: .' ([quant,_5,second] for '.$extraInfo.')',
1096: $current,
1097: $$prog_state{'max'},
1098: $min,
1099: $sec,
1100: $lasttime);
1.297 www 1101: my $percent=0;
1102: if ($$prog_state{'max'}) {
1103: $percent=int(100.*$current/$$prog_state{'max'});
1104: }
1105: &Apache::loncommon::LCprogressbarUpdate($r,$percent,$timeinfo);
1.23 matthew 1106: $$prog_state{'laststart'}=&Time::HiRes::time();
1.7 stredwic 1107: }
1108:
1109: # close Progress Line
1110: sub Close_PrgWin {
1.14 albertel 1111: my ($r,$prog_state)=@_;
1.297 www 1112: &Apache::loncommon::LCprogressbarClose($r);
1.48 albertel 1113: undef(%$prog_state);
1114: }
1115:
1.34 www 1116: # ------------------------------------------------------- Puts directory header
1117:
1118: sub crumbs {
1.252 bisitz 1119: my ($uri,$target,$prefix,$form,$skiplast)=@_;
1.303 www 1120: # You cannot crumbnify uploaded or adm resources
1121: if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Group Content)'); }
1.100 raeburn 1122: if ($target) {
1123: $target = ' target="'.
1124: &Apache::loncommon::escape_single($target).'"';
1125: }
1.252 bisitz 1126: my $output='<span class="LC_filename">';
1127: $output.=$prefix.'/';
1.249 raeburn 1128: if (($env{'user.adv'}) || ($env{'user.author'})) {
1.252 bisitz 1129: my $path=$prefix.'/';
1130: foreach my $dir (split('/',$uri)) {
1.99 matthew 1131: if (! $dir) { next; }
1132: $path .= $dir;
1.252 bisitz 1133: if ($path eq $uri) {
1134: if ($skiplast) {
1135: $output.=$dir;
1.132 www 1136: last;
1.252 bisitz 1137: }
1138: } else {
1139: $path.='/';
1140: }
1.157 albertel 1141: my $href_path = &HTML::Entities::encode($path,'<>&"');
1.252 bisitz 1142: &Apache::loncommon::inhibit_menu_check(\$href_path);
1143: if ($form) {
1144: my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
1145: $output.=qq{<a href="$href"$target>$dir</a>/};
1146: } else {
1147: $output.=qq{<a href="$href_path"$target>$dir</a>/};
1148: }
1149: }
1.35 www 1150: } else {
1.252 bisitz 1151: foreach my $dir (split('/',$uri)) {
1.149 albertel 1152: if (! $dir) { next; }
1.252 bisitz 1153: $output.=$dir.'/';
1154: }
1.34 www 1155: }
1.149 albertel 1156: if ($uri !~ m|/$|) { $output=~s|/$||; }
1.252 bisitz 1157: $output.='</span>';
1158:
1.304 foxr 1159:
1.252 bisitz 1160: return $output;
1.34 www 1161: }
1162:
1.85 www 1163: # --------------------- A function that generates a window for the spellchecker
1164:
1165: sub spellheader {
1.123 albertel 1166: my $start_page=
1167: &Apache::loncommon::start_page('Speller Suggestions',undef,
1.140 albertel 1168: {'only_body' => 1,
1169: 'js_ready' => 1,
1170: 'bgcolor' => '#DDDDDD',
1171: 'add_entries' => {
1172: 'onload' =>
1173: 'document.forms.spellcheckform.submit()',
1174: }
1175: });
1.123 albertel 1176: my $end_page=
1177: &Apache::loncommon::end_page({'js_ready' => 1});
1178:
1.105 www 1179: my $nothing=&javascript_nothing();
1.85 www 1180: return (<<ENDCHECK);
1181: <script type="text/javascript">
1.218 bisitz 1182: // <![CDATA[
1.92 albertel 1183: //<!-- BEGIN LON-CAPA Internal
1.85 www 1184: var checkwin;
1185:
1.140 albertel 1186: function spellcheckerwindow(string) {
1187: var esc_string = string.replace(/\"/g,'"');
1.105 www 1188: checkwin=window.open($nothing,'spellcheckwin','height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.154 albertel 1189: checkwin.document.writeln('$start_page<form name="spellcheckform" action="/adm/spellcheck" method="post"><input type="hidden" name="text" value="'+esc_string+'" /><\\/form>$end_page');
1.85 www 1190: checkwin.document.close();
1191: }
1.92 albertel 1192: // END LON-CAPA Internal -->
1.218 bisitz 1193: // ]]>
1.85 www 1194: </script>
1195: ENDCHECK
1196: }
1197:
1198: # ---------------------------------- Generate link to spell checker for a field
1199:
1200: sub spelllink {
1201: my ($form,$field)=@_;
1202: my $linktext=&mt('Check Spelling');
1203: return (<<ENDLINK);
1.140 albertel 1204: <a href="javascript:if (typeof(document.$form.onsubmit)!='undefined') { if (document.$form.onsubmit!=null) { document.$form.onsubmit();}};spellcheckerwindow(this.document.forms.$form.$field.value);">$linktext</a>
1.85 www 1205: ENDLINK
1206: }
1207:
1.281 raeburn 1208: # ------------------------------------------------- Output headers for CKEditor
1.124 albertel 1209:
1.52 www 1210: sub htmlareaheaders {
1.255 faziophi 1211: my $s="";
1.260 faziophi 1212: if (&htmlareabrowser()) {
1.255 faziophi 1213: $s.=(<<ENDEDITOR);
1214: <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
1215: ENDEDITOR
1216: }
1217: $s.=(<<ENDJQUERY);
1.294 raeburn 1218: <script type="text/javascript" src="/adm/jQuery/js/jquery-1.6.2.min.js"></script>
1219: <script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.8.16.custom.min.js"></script>
1220: <link rel="stylesheet" type="text/css" href="/adm/jQuery/css/smoothness/jquery-ui-1.8.16.custom.css" />
1.301 foxr 1221: <script type="text/javascript" src="/adm/jpicker/js/jpicker-1.1.6.min.js" >
1222: </script>
1223: <link rel="stylesheet" type="text/css" href="/adm/jpicker/css/jPicker-1.1.6.min.css" />
1.310 ! raeburn 1224: <script type="text/javascript" src="/adm/countdown/js/jquery.countdown.js"></script>
! 1225: <link rel="stylesheet" type="text/css" href="/adm/countdown/css/jquery.countdown.css" />
1.255 faziophi 1226: ENDJQUERY
1227: return $s;
1.52 www 1228: }
1229:
1.76 www 1230: # ----------------------------------------------------------------- Preferences
1231:
1.167 albertel 1232: # ------------------------------------------------- lang to use in html editor
1233: sub htmlarea_lang {
1234: my $lang='en';
1235: if (&mt('htmlarea_lang') ne 'htmlarea_lang') {
1236: $lang=&mt('htmlarea_lang');
1237: }
1238: return $lang;
1239: }
1240:
1.72 www 1241: # ----------------------------------------- Script to activate only some fields
1242:
1243: sub htmlareaselectactive {
1.281 raeburn 1244: my ($args) = @_;
1.76 www 1245: unless (&htmlareabrowser()) { return ''; }
1.262 raeburn 1246: my $output='<script type="text/javascript" defer="defer">'."\n"
1.230 bisitz 1247: .'// <![CDATA['."\n";
1.167 albertel 1248: my $lang = &htmlarea_lang();
1.281 raeburn 1249: my $fullpage = 'false';
1.282 raeburn 1250: my ($dragmath_prefix,$dragmath_helpicon,$dragmath_whitespace);
1.281 raeburn 1251: if (ref($args) eq 'HASH') {
1252: if (exists($args->{'lang'})) {
1253: if ($args->{'lang'} ne '') {
1254: $lang = $args->{'lang'};
1255: }
1256: }
1257: if (exists($args->{'fullpage'})) {
1258: if ($args->{'fullpage'} eq 'true') {
1259: $fullpage = $args->{'fullpage'};
1260: }
1261: }
1262: if (exists($args->{'dragmath'})) {
1263: if ($args->{'dragmath'} ne '') {
1264: $dragmath_prefix = $args->{'dragmath'};
1.282 raeburn 1265: $dragmath_helpicon=&Apache::loncommon::lonhttpdurl("/adm/help/help.png");
1266: $dragmath_whitespace=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/transparent1x1.gif");
1.281 raeburn 1267: }
1268: }
1269: }
1.255 faziophi 1270: $output.='
1271:
1272: function containsBlockHtml(id) {
1.281 raeburn 1273: var re = $("#"+id).html().search(/(?:\<\;|\<)(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)[\s]*((?:[\/]*[\s]*(?:\>\;|\>)|(?:\>\;|\>)[\s\S]*(?:\<\;|\<)\/[\s]*\1[\s]*\(?:\>\;|\>))/im);
1.255 faziophi 1274: return (re >= 0);
1275: }
1276:
1277: function startRichEditor(id) {
1278: CKEDITOR.replace(id,
1279: {
1.281 raeburn 1280: customConfig: "/ckeditor/loncapaconfig.js",
1281: language : "'.$lang.'",
1282: fullPage : '.$fullpage.',
1.255 faziophi 1283: }
1284: );
1285: }
1286:
1287: function destroyRichEditor(id) {
1288: CKEDITOR.instances[id].destroy();
1.72 www 1289: }
1.255 faziophi 1290:
1291: function editorHandler(event) {
1292: var rawid = $(this).attr("id");
1.281 raeburn 1293: var id = new RegExp("LC_rt_(.*)").exec(rawid)[1];
1.255 faziophi 1294: event.preventDefault();
1.281 raeburn 1295: var rt_enabled = $(this).hasClass("LC_enable_rt");
1296: if (rt_enabled) {
1.255 faziophi 1297: startRichEditor(id);
1298: $("#LC_rt_"+id).html("<b>« Plain text</b>");
1299: $("#LC_rt_"+id).attr("title", "Disable rich text formatting and edit in plain text");
1300: $("#LC_rt_"+id).addClass("LC_disable_rt");
1301: $("#LC_rt_"+id).removeClass("LC_enable_rt");
1302: } else {
1303: destroyRichEditor(id);
1304: $("#LC_rt_"+id).html("<b>Rich formatting »</b>");
1305: $("#LC_rt_"+id).attr("title", "Enable rich text formatting (bold, italic, etc.)");
1306: $("#LC_rt_"+id).addClass("LC_enable_rt");
1307: $("#LC_rt_"+id).removeClass("LC_disable_rt");
1.281 raeburn 1308: }';
1309: if ($dragmath_prefix ne '') {
1310: $output .= "\n var visible = '';
1311: if (rt_enabled) {
1312: visible = 'none';
1313: }
1314: editmath_visibility(id,visible);\n";
1315: }
1316: $output .= '
1317: }
1.255 faziophi 1318: $(document).ready(function(){
1319: $(".LC_richAlwaysOn").each(function() {
1320: startRichEditor($(this).attr("id"));
1321: });
1322: $(".LC_richDetectHtml").each(function() {
1323: var id = $(this).attr("id");
1.281 raeburn 1324: var rt_enabled = containsBlockHtml(id);
1325: if(rt_enabled) {
1.255 faziophi 1326: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>« Plain text</b></a></div>");
1327: startRichEditor(id);
1.281 raeburn 1328: $("#LC_rt_"+id).click(editorHandler);
1.255 faziophi 1329: }
1330: else {
1331: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting »</b></a></div>");
1332: $("#LC_rt_"+id).click(editorHandler);
1.281 raeburn 1333: }';
1334: if ($dragmath_prefix ne '') {
1335: $output .= "\n var visible = '';
1336: if (rt_enabled) {
1337: visible = 'none';
1338: }
1339: editmath_visibility(id,visible);\n";
1340: }
1341: $output .= '
1.255 faziophi 1342: });
1343: $(".LC_richDefaultOn").each(function() {
1344: var id = $(this).attr("id");
1345: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>« Plain text</b></a></div>");
1346: startRichEditor(id);
1347: $("#LC_rt_"+id).click(editorHandler);
1348: });
1349: $(".LC_richDefaultOff").each(function() {
1350: var id = $(this).attr("id");
1351: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting »</b></a></div>");
1.281 raeburn 1352: $("#LC_rt_"+id).click(editorHandler);
1.255 faziophi 1353: });
1.301 foxr 1354: $.fn.jPicker.defaults.images.clientPath="/adm/jpicker/images/";
1355: $(".colorchooser").jPicker();
1356:
1.304 foxr 1357:
1.302 foxr 1358: });
1.281 raeburn 1359: ';
1.306 foxr 1360: # Code to put a due date countdown in 'duedatecountdown' span.
1361: # This is currently located in the breadcrumb headers.
1362: # note that the dueDateLayout is internatinoalized below.
1363: # Here document is used to support the substitution into the javascript below.
1.307 foxr 1364: # ..which unforunately necessitates escaping the $'s in the javascript.
1365: # There are several times of importance
1366: #
1367: # serverDueDate - The absolute time at which the problem expires.
1368: # serverTime - The server's time when the problem finished computing.
1369: # clientTime - The client's time...as close to serverTime as possible.
1370: # The clientTime will be slightly later due to
1371: # 1. The latency between problem computation and
1372: # the first network action.
1373: # 2. The time required between the page load-start and the actual
1374: # initial javascript execution that got clientTime.
1375: # These are used as follows:
1376: # The difference between clientTime and serverTime are used to
1377: # correct for differences in clock settings between the browser's system and the
1378: # server's.
1379: #
1380: # The difference between clientTime and the time at which the ready() method
1381: # starts executing is used to estimate latencies for page load and submission.
1382: # Since this is an estimate, it is doubled. The latency estimate + one minute
1383: # is used to determine when the countdown timer turns red to warn the user
1384: # to think about submitting.
1.306 foxr 1385:
1.307 foxr 1386: my $dueDateLayout = '<b>' . &mt('Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn} - Submit early!') . '</b>';
1.306 foxr 1387: $output .= <<JAVASCRIPT;
1.307 foxr 1388:
1389: var documentReadyTime;
1390:
1.306 foxr 1391: \$(document).ready(function() {
1392: if (typeof(dueDate) != "undefined") {
1.307 foxr 1393: documentReadyTime = (new Date()).getTime();
1.306 foxr 1394: \$("#duedatecountdown").countdown({until: dueDate, compact: true,
1395: layout: "$dueDateLayout",
1396: onTick: function (periods) {
1.307 foxr 1397: var latencyEstimate = (documentReadyTime - clientTime) * 2;
1398: if(\$.countdown.periodsToSeconds(periods) < (60 + latencyEstimate)) {
1.306 foxr 1399: \$(this).css("color", "red"); //Highlight last minute.
1400: }
1401: }
1402: });
1403: }
1404: });
1405: JAVASCRIPT
1.281 raeburn 1406: if ($dragmath_prefix ne '') {
1407: $output .= '
1408:
1409: function editmath_visibility(id,value) {
1410:
1411: if ((id == "") || (id == null)) {
1412: return;
1413: }
1414: var mathid = "'.$dragmath_prefix.'_"+id;
1415: mathele = document.getElementById(mathid);
1416: if (mathele == null) {
1417: return;
1418: }
1419: mathele.style.display = value;
1.282 raeburn 1420: var mathhelpicon = "'.$dragmath_prefix.'helpicon'.'_"+id;
1421: mathhelpiconele = document.getElementById(mathhelpicon);
1422: if (mathhelpiconele == null) {
1423: return;
1424: }
1425: if (value == "none") {
1426: mathhelpiconele.src = "'.$dragmath_whitespace.'";
1427: } else {
1428: mathhelpiconele.src = "'.$dragmath_helpicon.'";
1429: }
1.281 raeburn 1430: }
1431: ';
1432:
1433: }
1.218 bisitz 1434: $output.="\nwindow.status='Activated Editfields';\n"
1.230 bisitz 1435: .'// ]]>'."\n"
1.281 raeburn 1436: .'</script>';
1.72 www 1437: return $output;
1438: }
1439:
1.61 www 1440: # --------------------------------------------------------------------- Blocked
1441:
1442: sub htmlareablocked {
1.104 albertel 1443: unless ($env{'environment.wysiwygeditor'} eq 'on') { return 1; }
1.71 www 1444: return 0;
1.52 www 1445: }
1446:
1447: # ---------------------------------------- Browser capable of running HTMLArea?
1448:
1449: sub htmlareabrowser {
1450: return 1;
1451: }
1.53 matthew 1452:
1.287 www 1453: #
1454: # Should the "return to content" link be shown?
1455: #
1456:
1457: sub show_return_link {
1.289 www 1458:
1459: unless ($env{'request.course.id'}) { return 0; }
1460: if ($env{'request.noversionuri'}=~m{^/priv/} ||
1461: $env{'request.uri'}=~m{^/~}) { return 1; }
1462:
1.287 www 1463: if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
1464: || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
1465:
1466: return if ($env{'form.register'});
1467: }
1468: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
1469: $env{'request.symb'} eq '')
1470: ||
1471: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
1472: ||
1473: (($env{'request.noversionuri'}=~/^\/adm\//) &&
1474: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
1475: ($env{'request.noversionuri'}!~
1476: m{^/adm/.*/(smppg|bulletinboard)($|\?)})
1477: ));
1478: }
1479:
1480:
1.304 foxr 1481: ##
1482: # Set the dueDate variable...note this is done in the timezone
1483: # of the browser.
1484: #
1485: # @param epoch relative time at which the problem is due.
1486: #
1487: # @return the javascript fragment to set the date:
1488: #
1489: sub set_due_date {
1490: my $dueStamp = shift;
1491: my $duems = $dueStamp * 1000; # Javascript Date object needs ms not seconds.
1492:
1493: my $now = time()*1000;
1494:
1495: # This slightly obscure bit of javascript sets the dueDate variable
1496: # to the time in the browser at which the problem was due.
1497: # The code should correct for gross differences between the server
1498: # and client's time setting
1499:
1500: my $js = "
1501: <script type='text/javascript'>
1502: //<![CDATA[
1503: var serverDueDate = $duems;
1504: var serverTime = $now;
1505: var clientTime = (new Date()).getTime();
1506: var dueDate = new Date(serverDueDate + (clientTime - serverTime));
1507:
1508: //]]>
1509: </script>
1510: ";
1511:
1.307 foxr 1512: return $js;
1513: }
1514: ##
1515: # Sets the time at which the problem finished computing.
1516: # This just updates the serverTime and clientTime variables above.
1517: # Calling this in e.g. end_problem provides a better estimate of the
1518: # difference beetween the server and client time setting as
1519: # the difference contains less of the latency/problem compute time.
1520: #
1521: sub set_compute_end_time {
1522:
1523: my $now = time()*1000; # Javascript times are in ms.
1524: my $js = "
1525: <script type='text/javascript'>
1526: //<![CDATA[
1527: serverTime = $now;
1528: clientTime = (new Date()).getTime();
1529: //]]>
1530: </script>
1531:
1532: ";
1533: return $js;
1534:
1.304 foxr 1535: }
1536:
1.53 matthew 1537: ############################################################
1538: ############################################################
1539:
1540: =pod
1541:
1.309 raeburn 1542: =item &breadcrumbs()
1.53 matthew 1543:
1544: Compiles the previously registered breadcrumbs into an series of links.
1545: Additionally supports a 'component', which will be displayed on the
1.223 droeschl 1546: right side of the breadcrumbs enclosing div (without a link).
1.53 matthew 1547: A link to help for the component will be included if one is specified.
1548:
1549: All inputs can be undef without problems.
1550:
1.223 droeschl 1551: Inputs: $component (the text on the right side of the breadcrumbs trail),
1.53 matthew 1552: $component_help
1.63 albertel 1553: $menulink (boolean, controls whether to include a link to /adm/menu)
1.138 albertel 1554: $helplink (if 'nohelp' don't include the orange help link)
1555: $css_class (optional name for the class to apply to the table for CSS)
1.197 raeburn 1556: $no_mt (optional flag, 1 if &mt() is _not_ to be applied to $component
1557: when including the text on the right.
1.53 matthew 1558: Returns a string containing breadcrumbs for the current page.
1559:
1.309 raeburn 1560: =item &clear_breadcrumbs()
1.53 matthew 1561:
1562: Clears the previously stored breadcrumbs.
1563:
1.309 raeburn 1564: =item &add_breadcrumb()
1.53 matthew 1565:
1566: Pushes a breadcrumb on the stack of crumbs.
1567:
1568: input: $breadcrumb, a hash reference. The keys 'href','title', and 'text'
1569: are required. If present the keys 'faq' and 'bug' will be used to provide
1.156 albertel 1570: links to the FAQ and bug sites. If the key 'no_mt' is present the 'title'
1571: and 'text' values won't be sent through &mt()
1.53 matthew 1572:
1573: returns: nothing
1574:
1575: =cut
1576:
1577: ############################################################
1578: ############################################################
1579: {
1580: my @Crumbs;
1.242 droeschl 1581: my %tools = ();
1.57 matthew 1582:
1.53 matthew 1583: sub breadcrumbs {
1.216 bisitz 1584: my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, $CourseBreadcrumbs) = @_;
1.53 matthew 1585: #
1.215 droeschl 1586: $css_class ||= 'LC_breadcrumbs';
1.205 amueller 1587:
1.57 matthew 1588: # Make the faq and bug data cascade
1.223 droeschl 1589: my $faq = '';
1590: my $bug = '';
1591: my $help = '';
1.215 droeschl 1592: # Crumb Symbol
1.223 droeschl 1593: my $crumbsymbol = '»';
1.60 www 1594: # The last breadcrumb does not have a link, so handle it separately.
1.53 matthew 1595: my $last = pop(@Crumbs);
1.57 matthew 1596: #
1.70 matthew 1597: # The first one should be the course or a menu link
1.215 droeschl 1598: if (!defined($menulink)) { $menulink=1; }
1.70 matthew 1599: if ($menulink) {
1600: my $description = 'Menu';
1.172 raeburn 1601: my $no_mt_descr = 0;
1.269 raeburn 1602: if ((exists($env{'request.course.id'})) &&
1603: ($env{'request.course.id'} ne '') &&
1604: ($env{'course.'.$env{'request.course.id'}.'.description'} ne '')) {
1.70 matthew 1605: $description =
1.104 albertel 1606: $env{'course.'.$env{'request.course.id'}.'.description'};
1.172 raeburn 1607: $no_mt_descr = 1;
1.70 matthew 1608: }
1.215 droeschl 1609: $menulink = { href =>'/adm/menu',
1610: title =>'Go to main menu',
1611: target =>'_top',
1612: text =>$description,
1613: no_mt =>$no_mt_descr, };
1614: if($last) {
1615: #$last set, so we have some crumbs
1616: unshift(@Crumbs,$menulink);
1617: } else {
1618: #only menulink crumb present
1619: $last = $menulink;
1620: }
1.53 matthew 1621: }
1.287 www 1622: my $links;
1623: if ((&show_return_link) && (!$CourseBreadcrumbs)) {
1.299 raeburn 1624: my $alttext = &mt('Go Back');
1.298 raeburn 1625: $links=&htmltag( 'a',"<img src='/res/adm/pages/reload.png' border='0' style='vertical-align:middle;' alt='$alttext' />",
1.287 www 1626: { href => '/adm/flip?postdata=return:',
1627: title => &mt("Back to most recent content resource") });
1.299 raeburn 1628: $links=&htmltag('li',$links);
1.287 www 1629: }
1630: $links.= join "",
1.261 droeschl 1631: map {
1632: $faq = $_->{'faq'} if (exists($_->{'faq'}));
1633: $bug = $_->{'bug'} if (exists($_->{'bug'}));
1634: $help = $_->{'help'} if (exists($_->{'help'}));
1635:
1.287 www 1636: my $result = $_->{no_mt} ? $_->{text} : &mt($_->{text});
1.261 droeschl 1637:
1638: if ($_->{href}){
1.287 www 1639: $result = &htmltag( 'a', $result,
1.261 droeschl 1640: { href => $_->{href},
1.287 www 1641: title => $_->{no_mt} ? $_->{title} : &mt($_->{title}),
1.261 droeschl 1642: target => $_->{target}, });
1643: }
1644:
1.287 www 1645: $result = &htmltag( 'li', "$result $crumbsymbol");
1.261 droeschl 1646: } @Crumbs;
1.223 droeschl 1647:
1648: #should the last Element be translated?
1.261 droeschl 1649:
1650: my $lasttext = $last->{'no_mt'} ? $last->{'text'}
1651: : mt( $last->{'text'} );
1652:
1.274 droeschl 1653: # last breadcrumb is the first order heading of a page
1654: # for course breadcrumbs it's just bold
1.304 foxr 1655:
1.287 www 1656: $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
1.274 droeschl 1657: $lasttext), {title => $lasttext});
1.223 droeschl 1658:
1.304 foxr 1659: $links .= '<li> <span id="duedatecountdown"></span></li>';
1660:
1.54 matthew 1661: my $icons = '';
1.223 droeschl 1662: $faq = $last->{'faq'} if (exists($last->{'faq'}));
1663: $bug = $last->{'bug'} if (exists($last->{'bug'}));
1.106 www 1664: $help = $last->{'help'} if (exists($last->{'help'}));
1665: $component_help=($component_help?$component_help:$help);
1.145 albertel 1666: # if ($faq ne '') {
1667: # $icons .= &Apache::loncommon::help_open_faq($faq);
1668: # }
1.79 raeburn 1669: # if ($bug ne '') {
1670: # $icons .= &Apache::loncommon::help_open_bug($bug);
1671: # }
1.223 droeschl 1672: if ($faq ne '' || $component_help ne '' || $bug ne '') {
1673: $icons .= &Apache::loncommon::help_open_menu($component,
1674: $component_help,
1675: $faq,$bug);
1676: }
1.54 matthew 1677: #
1.304 foxr 1678:
1.205 amueller 1679:
1680:
1.223 droeschl 1681: unless ($CourseBreadcrumbs) {
1.287 www 1682: $links = &htmltag('ol', $links, { id => "LC_MenuBreadcrumbs" });
1.223 droeschl 1683: } else {
1.287 www 1684: $links = &htmltag('ul', $links, { class => "LC_CourseBreadcrumbs" });
1.53 matthew 1685: }
1.223 droeschl 1686:
1.304 foxr 1687:
1.223 droeschl 1688: if ($component) {
1.287 www 1689: $links = &htmltag('span',
1.223 droeschl 1690: ( $no_mt ? $component : mt($component) ).
1691: ( $icons ? $icons : '' ),
1692: { class => 'LC_breadcrumbs_component' } )
1.304 foxr 1693: .$links
1694: ;
1.223 droeschl 1695: }
1696:
1.287 www 1697: &render_tools(\$links);
1698: $links = &htmltag('div', $links,
1.225 bisitz 1699: { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;
1.287 www 1700: &render_advtools(\$links);
1.223 droeschl 1701:
1.53 matthew 1702: # Return the @Crumbs stack to what we started with
1703: push(@Crumbs,$last);
1704: shift(@Crumbs);
1.304 foxr 1705:
1706:
1.223 droeschl 1707: # Return the breadcrumb's line
1.304 foxr 1708:
1709:
1710:
1.223 droeschl 1711: return "$links";
1.53 matthew 1712: }
1713:
1714: sub clear_breadcrumbs {
1715: undef(@Crumbs);
1.242 droeschl 1716: undef(%tools);
1.53 matthew 1717: }
1718:
1719: sub add_breadcrumb {
1.232 raeburn 1720: push(@Crumbs,@_);
1.53 matthew 1721: }
1.242 droeschl 1722:
1.309 raeburn 1723: =item &add_breadcrumb_tool($category, $html)
1.261 droeschl 1724:
1725: Adds $html to $category of the breadcrumb toolbar container.
1726:
1727: $html is usually a link to a page that invokes a function on the currently
1728: displayed data (e.g. print when viewing a problem)
1729:
1730: Currently there are 3 possible values for $category:
1731:
1732: =over
1733:
1734: =item navigation
1735: left of breadcrumbs line
1736:
1737: =item tools
1738: right of breadcrumbs line
1739:
1740: =item advtools
1741: advanced tools shown in a separate box below breadcrumbs line
1742:
1743: =back
1744:
1745: returns: nothing
1746:
1747: =cut
1.242 droeschl 1748:
1749: sub add_breadcrumb_tool {
1.261 droeschl 1750: my ($category, @html) = @_;
1751: return unless @html;
1.285 raeburn 1752: if (!keys(%tools)) {
1.261 droeschl 1753: %tools = ( navigation => [], tools => [], advtools => []);
1.242 droeschl 1754: }
1.261 droeschl 1755:
1756: #this cleans data received from lonmenu::innerregister
1757: @html = grep {defined $_ && $_ ne ''} @html;
1758: for (@html) {
1759: s/align="(right|left)"//;
1.288 www 1760: # s/<span.*?\/span>// if $category ne 'advtools';
1.261 droeschl 1761: }
1762:
1763: push @{$tools{$category}}, @html;
1.242 droeschl 1764: }
1765:
1.309 raeburn 1766: =item &clear_breadcrumb_tools()
1.261 droeschl 1767:
1768: Clears the breadcrumb toolbar container.
1769:
1770: returns: nothing
1771:
1772: =cut
1773:
1.245 droeschl 1774: sub clear_breadcrumb_tools {
1775: undef(%tools);
1776: }
1777:
1.309 raeburn 1778: =item &render_tools(\$breadcrumbs)
1.261 droeschl 1779:
1780: Creates html for breadcrumb tools (categories navigation and tools) and inserts
1781: \$breadcrumbs at the correct position.
1782:
1783: input: \$breadcrumbs - a reference to the string containing prepared
1784: breadcrumbs.
1785:
1786: returns: nothing
1.309 raeburn 1787:
1.261 droeschl 1788: =cut
1789:
1790: #TODO might split this in separate functions for each category
1791: sub render_tools {
1792: my ($breadcrumbs) = @_;
1.285 raeburn 1793: return unless (keys(%tools));
1.261 droeschl 1794:
1795: my $navigation = list_from_array($tools{navigation},
1796: { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
1797: my $tools = list_from_array($tools{tools},
1798: { listattr => { class=>"LC_breadcrumb_tools_tools" } });
1799: $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs],
1800: { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });
1801: }
1802:
1.309 raeburn 1803: =pod
1804:
1805: =item &render_advtools(\$breadcrumbs)
1.261 droeschl 1806:
1807: Creates html for advanced tools (category advtools) and inserts \$breadcrumbs
1808: at the correct position.
1809:
1810: input: \$breadcrumbs - a reference to the string containing prepared
1811: breadcrumbs (after render_tools call).
1812:
1813: returns: nothing
1.309 raeburn 1814:
1.261 droeschl 1815: =cut
1816:
1817: sub render_advtools {
1818: my ($breadcrumbs) = @_;
1819: return unless (defined $tools{'advtools'})
1820: and (scalar(@{$tools{'advtools'}}) > 0);
1821:
1822: $$breadcrumbs .= Apache::loncommon::head_subbox(
1823: funclist_from_array($tools{'advtools'}) );
1.242 droeschl 1824: }
1.53 matthew 1825:
1.57 matthew 1826: } # End of scope for @Crumbs
1.53 matthew 1827:
1828: ############################################################
1829: ############################################################
1830:
1.112 raeburn 1831: # Nested table routines.
1832: #
1833: # Routines to display form items in a multi-row table with 2 columns.
1834: # Uses nested tables to divide form elements into segments.
1835: # For examples of use see loncom/interface/lonnotify.pm
1836: #
1837: # Can be used in following order: ...
1838: # &start_pick_box()
1839: # row1
1840: # row2
1841: # row3 ... etc.
1.173 raeburn 1842: # &submit_row()
1.161 raeburn 1843: # &end_pick_box()
1.112 raeburn 1844: #
1845: # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
1846: # &status_select_row and &email_default_row
1847: #
1848: # Can also be used in following order:
1849: #
1850: # &start_pick_box()
1851: # &row_title()
1852: # &row_closure()
1853: # &row_title()
1854: # &row_closure() ... etc.
1855: # &submit_row()
1856: # &end_pick_box()
1857: #
1858: # In general a &submit_row() call should proceed the call to &end_pick_box(),
1859: # as this routine adds a button for form submission.
1.113 raeburn 1860: # &submit_row() does not require a &row_closure after it.
1.112 raeburn 1861: #
1862: # &start_pick_box() creates a bounding table with 1-pixel wide black border.
1863: # rows should be placed between calls to &start_pick_box() and &end_pick_box.
1864: #
1865: # &row_title() adds a title in the left column for each segment.
1866: # &row_closure() closes a row with a 1-pixel wide black line.
1867: #
1868: # &role_select_row() provides a select box from which to choose 1 or more roles
1869: # &course_select_row provides ways of picking groups of courses
1870: # radio buttons: all, by category or by picking from a course picker pop-up
1871: # note: by category option is only displayed if a domain has implemented
1872: # selection by year, semester, department, number etc.
1873: #
1874: # &status_select_row() provides a select box from which to choose 1 or more
1875: # access types (current access, prior access, and future access)
1876: #
1877: # &email_default_row() provides text boxes for default e-mail suffixes for
1878: # different authentication types in a domain.
1879: #
1880: # &row_title() and &row_closure() are called internally by the &*_select_row
1881: # routines, but can also be called directly to start and end rows which have
1882: # needs that are not accommodated by the *_select_row() routines.
1883:
1.193 bisitz 1884: { # Start: row_count block for pick_box
1885: my @row_count;
1886:
1.112 raeburn 1887: sub start_pick_box {
1.142 albertel 1888: my ($css_class) = @_;
1889: if (defined($css_class)) {
1890: $css_class = 'class="'.$css_class.'"';
1891: } else {
1892: $css_class= 'class="LC_pick_box"';
1893: }
1.193 bisitz 1894: unshift(@row_count,0);
1.112 raeburn 1895: my $output = <<"END";
1.142 albertel 1896: <table $css_class>
1.112 raeburn 1897: END
1898: return $output;
1899: }
1900:
1901: sub end_pick_box {
1.193 bisitz 1902: shift(@row_count);
1.112 raeburn 1903: my $output = <<"END";
1904: </table>
1905: END
1906: return $output;
1907: }
1908:
1.181 bisitz 1909: sub row_headline {
1910: my $output = <<"END";
1911: <tr><td colspan="2">
1912: END
1913: return $output;
1914: }
1915:
1.112 raeburn 1916: sub row_title {
1.243 amueller 1917: my ($title,$css_title_class,$css_value_class, $css_value_furtherAttributes) = @_;
1.193 bisitz 1918: $row_count[0]++;
1919: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.142 albertel 1920: $css_title_class ||= 'LC_pick_box_title';
1921: $css_title_class = 'class="'.$css_title_class.'"';
1922:
1923: $css_value_class ||= 'LC_pick_box_value';
1924:
1.173 raeburn 1925: if ($title ne '') {
1926: $title .= ':';
1927: }
1.112 raeburn 1928: my $output = <<"ENDONE";
1.243 amueller 1929: <tr class="LC_pick_box_row" $css_value_furtherAttributes>
1.142 albertel 1930: <td $css_title_class>
1.173 raeburn 1931: $title
1.112 raeburn 1932: </td>
1.193 bisitz 1933: <td class="$css_value_class $css_class">
1.112 raeburn 1934: ENDONE
1935: return $output;
1936: }
1937:
1938: sub row_closure {
1.143 albertel 1939: my ($no_separator) =@_;
1.113 raeburn 1940: my $output = <<"ENDTWO";
1.112 raeburn 1941: </td>
1942: </tr>
1.143 albertel 1943: ENDTWO
1944: if (!$no_separator) {
1945: $output .= <<"ENDTWO";
1.112 raeburn 1946: <tr>
1.143 albertel 1947: <td colspan="2" class="LC_pick_box_separator">
1.112 raeburn 1948: </td>
1949: </tr>
1950: ENDTWO
1.143 albertel 1951: }
1.112 raeburn 1952: return $output;
1953: }
1954:
1.193 bisitz 1955: } # End: row_count block for pick_box
1956:
1.112 raeburn 1957: sub role_select_row {
1.147 raeburn 1958: my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
1.236 raeburn 1959: my $crstype = 'Course';
1960: if ($cdom ne '' && $cnum ne '') {
1961: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1962: }
1.116 raeburn 1963: my $output;
1964: if (defined($title)) {
1.142 albertel 1965: $output = &row_title($title,$css_class);
1.116 raeburn 1966: }
1.142 albertel 1967: $output .= qq|
1.198 bisitz 1968: <select name="roles" multiple="multiple">\n|;
1.113 raeburn 1969: foreach my $role (@$roles) {
1.114 raeburn 1970: my $plrole;
1971: if ($role eq 'ow') {
1972: $plrole = &mt('Course Owner');
1.147 raeburn 1973: } elsif ($role eq 'cr') {
1974: if ($show_separate_custom) {
1975: if ($cdom ne '' && $cnum ne '') {
1976: my %course_customroles = &course_custom_roles($cdom,$cnum);
1977: foreach my $crrole (sort(keys(%course_customroles))) {
1978: my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|);
1979: $output .= ' <option value="'.$crrole.'">'.$plcrrole.
1980: '</option>';
1981: }
1982: }
1983: } else {
1984: $plrole = &mt('Custom Role');
1985: }
1.114 raeburn 1986: } else {
1.236 raeburn 1987: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.114 raeburn 1988: }
1.147 raeburn 1989: if (($role ne 'cr') || (!$show_separate_custom)) {
1990: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
1991: }
1.112 raeburn 1992: }
1.142 albertel 1993: $output .= qq| </select>\n|;
1.116 raeburn 1994: if (defined($title)) {
1995: $output .= &row_closure();
1996: }
1.112 raeburn 1997: return $output;
1998: }
1999:
2000: sub course_select_row {
1.142 albertel 2001: my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles,
1.280 raeburn 2002: $css_class,$crstype,$standardnames) = @_;
1.142 albertel 2003: my $output = &row_title($title,$css_class);
1.280 raeburn 2004: $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames);
1.169 raeburn 2005: $output .= &row_closure();
2006: return $output;
2007: }
2008:
2009: sub course_selection {
1.280 raeburn 2010: my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames) = @_;
1.169 raeburn 2011: my $output = qq|
1.142 albertel 2012: <script type="text/javascript">
1.218 bisitz 2013: // <![CDATA[
1.112 raeburn 2014: function coursePick (formname) {
2015: for (var i=0; i<formname.coursepick.length; i++) {
1.114 raeburn 2016: if (formname.coursepick[i].value == 'category') {
2017: courseSet('');
2018: }
1.112 raeburn 2019: if (!formname.coursepick[i].checked) {
2020: if (formname.coursepick[i].value == 'specific') {
2021: formname.coursetotal.value = 0;
2022: formname.courselist = '';
2023: }
2024: }
2025: }
2026: }
1.114 raeburn 2027: function setPick (formname) {
2028: for (var i=0; i<formname.coursepick.length; i++) {
2029: if (formname.coursepick[i].value == 'category') {
2030: formname.coursepick[i].checked = true;
2031: }
2032: formname.coursetotal.value = 0;
2033: formname.courselist = '';
2034: }
2035: }
1.218 bisitz 2036: // ]]>
1.112 raeburn 2037: </script>
2038: |;
1.237 raeburn 2039:
2040: my ($allcrs,$pickspec);
2041: if ($crstype eq 'Community') {
2042: $allcrs = &mt('All communities');
2043: $pickspec = &mt('Pick specific communities:');
2044: } else {
2045: $allcrs = &mt('All courses');
2046: $pickspec = &mt('Pick specific course(s):');
2047: }
2048:
1.112 raeburn 2049: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.237 raeburn 2050: ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).'</b>';
2051: $output .= '<input type="radio" name="coursepick" value="all" onclick="coursePick(this.form)" />'.$allcrs.'<br />';
1.112 raeburn 2052: if ($totcodes > 0) {
2053: my $numtitles = @$codetitles;
2054: if ($numtitles > 0) {
1.129 raeburn 2055: $output .= '<input type="radio" name="coursepick" value="category" onclick="coursePick(this.form);alert('."'".&mt('Choose categories, from left to right')."'".')" />'.&mt('Pick courses by category:').' <br />';
1.112 raeburn 2056: $output .= '<table><tr><td>'.$$codetitles[0].'<br />'."\n".
1.280 raeburn 2057: '<select name="'.$standardnames->[0].
1.114 raeburn 2058: '" onChange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
1.112 raeburn 2059: ' <option value="-1" />Select'."\n";
2060: my @items = ();
2061: my @longitems = ();
2062: if ($$idlist{$$codetitles[0]} =~ /","/) {
1.113 raeburn 2063: @items = split(/","/,$$idlist{$$codetitles[0]});
1.112 raeburn 2064: } else {
2065: $items[0] = $$idlist{$$codetitles[0]};
2066: }
2067: if (defined($$idlist_titles{$$codetitles[0]})) {
2068: if ($$idlist_titles{$$codetitles[0]} =~ /","/) {
1.113 raeburn 2069: @longitems = split(/","/,$$idlist_titles{$$codetitles[0]});
1.112 raeburn 2070: } else {
2071: $longitems[0] = $$idlist_titles{$$codetitles[0]};
2072: }
2073: for (my $i=0; $i<@longitems; $i++) {
2074: if ($longitems[$i] eq '') {
2075: $longitems[$i] = $items[$i];
2076: }
2077: }
2078: } else {
2079: @longitems = @items;
2080: }
2081: for (my $i=0; $i<@items; $i++) {
2082: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
2083: }
2084: $output .= '</select></td>';
2085: for (my $i=1; $i<$numtitles; $i++) {
2086: $output .= '<td>'.$$codetitles[$i].'<br />'."\n".
1.280 raeburn 2087: '<select name="'.$standardnames->[$i].
1.112 raeburn 2088: '" onChange="courseSet('."'$$codetitles[$i]'".')">'."\n".
2089: '<option value="-1"><-Pick '.$$codetitles[$i-1].'</option>'."\n".
2090: '</select>'."\n".
2091: '</td>';
2092: }
2093: $output .= '</tr></table><br />';
2094: }
2095: }
1.238 raeburn 2096: $output .= '<input type="radio" name="coursepick" value="specific" onclick="coursePick(this.form);opencrsbrowser('."'".$formname."','dccourse','dcdomain','coursedesc','','1','$crstype'".')" />'.$pickspec.' '.$courseform.' <input type="text" value="0" size="4" name="coursetotal" /><input type="hidden" name="courselist" value="" />selected.<br />'."\n";
1.112 raeburn 2097: return $output;
2098: }
2099:
2100: sub status_select_row {
1.142 albertel 2101: my ($types,$title,$css_class) = @_;
1.117 raeburn 2102: my $output;
2103: if (defined($title)) {
1.142 albertel 2104: $output = &row_title($title,$css_class,'LC_pick_box_select');
1.117 raeburn 2105: }
1.142 albertel 2106: $output .= qq|
1.198 bisitz 2107: <select name="types" multiple="multiple">\n|;
1.113 raeburn 2108: foreach my $status_type (sort(keys(%{$types}))) {
1.112 raeburn 2109: $output .= ' <option value="'.$status_type.'">'.$$types{$status_type}.'</option>';
2110: }
1.142 albertel 2111: $output .= qq| </select>\n|;
1.117 raeburn 2112: if (defined($title)) {
2113: $output .= &row_closure();
2114: }
1.112 raeburn 2115: return $output;
2116: }
2117:
2118: sub email_default_row {
1.142 albertel 2119: my ($authtypes,$title,$descrip,$css_class) = @_;
2120: my $output = &row_title($title,$css_class);
2121: $output .= $descrip.
2122: &Apache::loncommon::start_data_table().
2123: &Apache::loncommon::start_data_table_header_row().
2124: '<th>'.&mt('Authentication Method').'</th>'.
2125: '<th align="right">'.&mt('Username -> e-mail conversion').'</th>'."\n".
2126: &Apache::loncommon::end_data_table_header_row();
1.112 raeburn 2127: my $rownum = 0;
1.113 raeburn 2128: foreach my $auth (sort(keys(%{$authtypes}))) {
1.112 raeburn 2129: my ($userentry,$size);
2130: if ($auth =~ /^krb/) {
2131: $userentry = '';
2132: $size = 25;
2133: } else {
2134: $userentry = 'username@';
2135: $size = 15;
2136: }
1.142 albertel 2137: $output .= &Apache::loncommon::start_data_table_row().
2138: '<td> '.$$authtypes{$auth}.'</td>'.
2139: '<td align="right">'.$userentry.
2140: '<input type="text" name="'.$auth.'" size="'.$size.'" /></td>'.
2141: &Apache::loncommon::end_data_table_row();
1.112 raeburn 2142: }
1.142 albertel 2143: $output .= &Apache::loncommon::end_data_table();
1.112 raeburn 2144: $output .= &row_closure();
2145: return $output;
2146: }
2147:
2148:
2149: sub submit_row {
1.142 albertel 2150: my ($title,$cmd,$submit_text,$css_class) = @_;
2151: my $output = &row_title($title,$css_class,'LC_pick_box_submit');
1.112 raeburn 2152: $output .= qq|
2153: <br />
2154: <input type="hidden" name="command" value="$cmd" />
2155: <input type="submit" value="$submit_text"/>
2156: <br /><br />
1.142 albertel 2157: \n|;
1.112 raeburn 2158: return $output;
2159: }
1.1 stredwic 2160:
1.147 raeburn 2161: sub course_custom_roles {
2162: my ($cdom,$cnum) = @_;
2163: my %returnhash=();
2164: my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
2165: foreach my $person (sort(keys(%coursepersonnel))) {
2166: my ($role) = ($person =~ /^([^:]+):/);
2167: my ($end,$start) = split(/:/,$coursepersonnel{$person});
2168: if ($end == -1 && $start == -1) {
2169: next;
2170: }
2171: if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) {
2172: $returnhash{$role} ++;
2173: }
2174: }
2175: return %returnhash;
2176: }
2177:
2178:
1.270 www 2179: sub resource_info_box {
1.300 raeburn 2180: my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp)=@_;
1.270 www 2181: my $return='';
1.300 raeburn 2182: if ($stuvcurrent ne '') {
2183: $return = '<div class="LC_left_float">';
2184: }
1.270 www 2185: if ($symb) {
1.300 raeburn 2186: $return.=&Apache::loncommon::start_data_table();
1.271 www 2187: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symb);
2188: my $folder=&Apache::lonnet::gettitle($map);
2189: $return.=&Apache::loncommon::start_data_table_row().
1.300 raeburn 2190: '<th align="left">'.&mt('Folder:').'</th><td>'.$folder.'</td>'.
1.271 www 2191: &Apache::loncommon::end_data_table_row();
1.270 www 2192: unless ($onlyfolderflag) {
2193: $return.=&Apache::loncommon::start_data_table_row().
1.300 raeburn 2194: '<th align="left">'.&mt('Resource:').'</th><td>'.&Apache::lonnet::gettitle($symb).'</td>'.
2195: &Apache::loncommon::end_data_table_row();
2196: }
2197: if ($stuvcurrent ne '') {
2198: $return .= &Apache::loncommon::start_data_table_row().
2199: '<th align="left">'.&mt("Student's current version:").'</th><td>'.$stuvcurrent.'</td>'.
2200: &Apache::loncommon::end_data_table_row();
2201: }
2202: if ($stuvdisp ne '') {
2203: $return .= &Apache::loncommon::start_data_table_row().
2204: '<th align="left">'.&mt("Student's version displayed:").'</th><td>'.$stuvdisp.'</td>'.
1.270 www 2205: &Apache::loncommon::end_data_table_row();
2206: }
1.271 www 2207: $return.=&Apache::loncommon::end_data_table();
1.270 www 2208: } else {
2209: $return='<p><span class="LC_error">'.&mt('No context provided.').'</span></p>';
2210: }
1.300 raeburn 2211: if ($stuvcurrent ne '') {
2212: $return .= '</div>';
2213: }
1.270 www 2214: return $return;
2215: }
2216:
1.119 raeburn 2217: ##############################################
2218: ##############################################
1.179 raeburn 2219:
2220: # topic_bar
2221: #
1.248 wenzelju 2222: # Generates a div containing an (optional) number with a white background followed by a
1.240 raeburn 2223: # title with a background color defined in the corresponding CSS: LC_topic_bar
2224: # Inputs:
1.248 wenzelju 2225: # 1. number to display.
2226: # If input for number is empty only the title will be displayed.
1.240 raeburn 2227: # 2. title text to display.
2228: # Outputs - a scalar containing html mark-up for the div.
2229:
1.179 raeburn 2230: sub topic_bar {
1.248 wenzelju 2231: my ($num,$title) = @_;
2232: my $number = '';
2233: if ($num ne '') {
2234: $number = '<span>'.$num.'</span>';
1.239 amueller 2235: }
1.248 wenzelju 2236: return '<div class="LC_topic_bar">'.$number.$title.'</div>';
1.179 raeburn 2237: }
2238:
2239: ##############################################
2240: ##############################################
1.119 raeburn 2241: # echo_form_input
2242: #
2243: # Generates html markup to add form elements from the referrer page
2244: # as hidden form elements (values encoded) in the new page.
2245: #
2246: # Intended to support two types of use
2247: # (a) to allow backing up to earlier pages in a multi-page
2248: # form submission process using a breadcrumb trail.
2249: #
2250: # (b) to allow the current page to be reloaded with form elements
2251: # set on previous page to remain unchanged. An example would
2252: # be where the a page containing a dynamically-built table of data is
2253: # is to be redisplayed, with only the sort order of the data changed.
2254: #
2255: # Inputs:
2256: # 1. Reference to array of form elements in the submitted form on
2257: # the referrer page which are to be excluded from the echoed elements.
2258: #
2259: # 2. Reference to array of regular expressions, which if matched in the
2260: # name of the form element n the referrer page will be omitted from echo.
2261: #
2262: # Outputs: A scalar containing the html markup for the echoed form
2263: # elements (all as hidden elements, with values encoded).
2264:
2265:
2266: sub echo_form_input {
2267: my ($excluded,$regexps) = @_;
2268: my $output = '';
2269: foreach my $key (keys(%env)) {
2270: if ($key =~ /^form\.(.+)$/) {
2271: my $name = $1;
2272: my $match = 0;
1.285 raeburn 2273: if (ref($excluded) eq 'ARRAY') {
2274: next if (grep(/^\Q$name\E$/,@{$excluded}));
2275: }
2276: if (ref($regexps) eq 'ARRAY') {
2277: if (@{$regexps} > 0) {
2278: foreach my $regexp (@{$regexps}) {
2279: if ($name =~ /$regexp/) {
2280: $match = 1;
2281: last;
1.119 raeburn 2282: }
2283: }
2284: }
1.285 raeburn 2285: }
2286: next if ($match);
2287: if (ref($env{$key}) eq 'ARRAY') {
2288: foreach my $value (@{$env{$key}}) {
2289: $value = &HTML::Entities::encode($value,'<>&"');
2290: $output .= '<input type="hidden" name="'.$name.
2291: '" value="'.$value.'" />'."\n";
1.119 raeburn 2292: }
1.285 raeburn 2293: } else {
2294: my $value = &HTML::Entities::encode($env{$key},'<>&"');
2295: $output .= '<input type="hidden" name="'.$name.
2296: '" value="'.$value.'" />'."\n";
1.119 raeburn 2297: }
2298: }
2299: }
2300: return $output;
2301: }
2302:
2303: ##############################################
2304: ##############################################
2305: # set_form_elements
2306: #
2307: # Generates javascript to set form elements to values based on
2308: # corresponding values for the same form elements when the page was
2309: # previously submitted.
2310: #
2311: # Last submission values are read from hidden form elements in referring
2312: # page which have the same name, i.e., generated by &echo_form_input().
2313: #
2314: # Intended to be called by onload event.
2315: #
1.121 raeburn 2316: # Inputs:
2317: # (a) Reference to hash of echoed form elements to be set.
1.119 raeburn 2318: #
2319: # In the hash, keys are the form element names, and the values are the
2320: # element type (selectbox, radio, checkbox or text -for textbox, textarea or
2321: # hidden).
1.121 raeburn 2322: #
2323: # (b) Optional reference to hash of stored elements to be set.
2324: #
2325: # If the page being displayed is a page which permits modification of
2326: # previously stored data, e.g., the first page in a multi-page submission,
2327: # then if stored is supplied, form elements will be set to the last stored
2328: # values. If user supplied values are also available for the same elements
2329: # these will replace the stored values.
2330: #
1.119 raeburn 2331: # Output:
2332: #
2333: # javascript function - set_form_elements() which sets form elements,
2334: # expects an argument: formname - the name of the form according to
2335: # the DOM, e.g., document.compose
2336:
2337: sub set_form_elements {
1.121 raeburn 2338: my ($elements,$stored) = @_;
2339: my %values;
1.119 raeburn 2340: my $output .= 'function setFormElements(courseForm) {
1.121 raeburn 2341: ';
2342: if (defined($stored)) {
2343: foreach my $name (keys(%{$stored})) {
2344: if (exists($$elements{$name})) {
2345: if (ref($$stored{$name}) eq 'ARRAY') {
2346: $values{$name} = $$stored{$name};
2347: } else {
2348: @{$values{$name}} = ($$stored{$name});
2349: }
2350: }
2351: }
2352: }
2353:
1.119 raeburn 2354: foreach my $key (keys(%env)) {
2355: if ($key =~ /^form\.(.+)$/) {
2356: my $name = $1;
2357: if (exists($$elements{$name})) {
1.121 raeburn 2358: @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
2359: }
2360: }
2361: }
2362:
2363: foreach my $name (keys(%values)) {
2364: for (my $i=0; $i<@{$values{$name}}; $i++) {
2365: $values{$name}[$i] = &HTML::Entities::decode($values{$name}[$i],'<>&"');
2366: $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
2367: $values{$name}[$i] =~ s/"/\\"/g;
2368: }
1.234 raeburn 2369: if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) {
1.121 raeburn 2370: my $numvalues = @{$values{$name}};
2371: if ($numvalues > 1) {
2372: my $valuestring = join('","',@{$values{$name}});
2373: $output .= qq|
1.119 raeburn 2374: var textvalues = new Array ("$valuestring");
1.147 raeburn 2375: var total = courseForm.elements['$name'].length;
1.119 raeburn 2376: if (total > $numvalues) {
2377: total = $numvalues;
2378: }
2379: for (var i=0; i<total; i++) {
1.147 raeburn 2380: courseForm.elements['$name']\[i].value = textvalues[i];
1.119 raeburn 2381: }
2382: |;
1.121 raeburn 2383: } else {
2384: $output .= qq|
1.147 raeburn 2385: courseForm.elements['$name'].value = "$values{$name}[0]";
1.119 raeburn 2386: |;
1.121 raeburn 2387: }
2388: } else {
2389: $output .= qq|
1.147 raeburn 2390: var elementLength = courseForm.elements['$name'].length;
1.119 raeburn 2391: if (elementLength==undefined) {
2392: |;
1.121 raeburn 2393: foreach my $value (@{$values{$name}}) {
2394: if ($$elements{$name} eq 'selectbox') {
2395: $output .= qq|
1.147 raeburn 2396: if (courseForm.elements['$name'].options[0].value == "$value") {
2397: courseForm.elements['$name'].options[0].selected = true;
1.119 raeburn 2398: }|;
1.121 raeburn 2399: } elsif (($$elements{$name} eq 'radio') ||
2400: ($$elements{$name} eq 'checkbox')) {
2401: $output .= qq|
1.147 raeburn 2402: if (courseForm.elements['$name'].value == "$value") {
1.148 albertel 2403: courseForm.elements['$name'].checked = true;
1.234 raeburn 2404: } else {
2405: courseForm.elements['$name'].checked = false;
1.119 raeburn 2406: }|;
1.121 raeburn 2407: }
2408: }
2409: $output .= qq|
1.119 raeburn 2410: }
2411: else {
1.147 raeburn 2412: for (var i=0; i<courseForm.elements['$name'].length; i++) {
1.119 raeburn 2413: |;
1.121 raeburn 2414: if ($$elements{$name} eq 'selectbox') {
2415: $output .= qq|
1.147 raeburn 2416: courseForm.elements['$name'].options[i].selected = false;|;
1.121 raeburn 2417: } elsif (($$elements{$name} eq 'radio') ||
2418: ($$elements{$name} eq 'checkbox')) {
2419: $output .= qq|
1.147 raeburn 2420: courseForm.elements['$name']\[i].checked = false;|;
1.121 raeburn 2421: }
2422: $output .= qq|
1.119 raeburn 2423: }
1.147 raeburn 2424: for (var j=0; j<courseForm.elements['$name'].length; j++) {
1.119 raeburn 2425: |;
1.121 raeburn 2426: foreach my $value (@{$values{$name}}) {
2427: if ($$elements{$name} eq 'selectbox') {
2428: $output .= qq|
1.147 raeburn 2429: if (courseForm.elements['$name'].options[j].value == "$value") {
2430: courseForm.elements['$name'].options[j].selected = true;
1.119 raeburn 2431: }|;
1.121 raeburn 2432: } elsif (($$elements{$name} eq 'radio') ||
2433: ($$elements{$name} eq 'checkbox')) {
2434: $output .= qq|
1.147 raeburn 2435: if (courseForm.elements['$name']\[j].value == "$value") {
2436: courseForm.elements['$name']\[j].checked = true;
1.119 raeburn 2437: }|;
1.121 raeburn 2438: }
2439: }
2440: $output .= qq|
1.119 raeburn 2441: }
2442: }
2443: |;
2444: }
2445: }
2446: $output .= "
1.235 raeburn 2447: return;
1.119 raeburn 2448: }\n";
2449: return $output;
2450: }
2451:
1.158 raeburn 2452: ##############################################
2453: ##############################################
2454:
1.291 raeburn 2455: sub file_submissionchk_js {
2456: my ($turninpaths,$multiples) = @_;
2457: my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item').'\\n'.
2458: &mt('Continue submission and overwrite the file(s)?');
2459: my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'.
2460: &mt('Continue submission with these files removed?');
1.292 raeburn 2461: my ($turninpathtext,$multtext,$arrayindexofjs);
1.291 raeburn 2462: if (ref($turninpaths) eq 'HASH') {
2463: foreach my $key (sort(keys(%{$turninpaths}))) {
2464: $turninpathtext .= " if (prefix == '$key') {\n".
2465: " return '$turninpaths->{$key}';\n".
2466: " }\n";
2467: }
2468: }
2469: $turninpathtext .= " return '';\n";
2470: if (ref($multiples) eq 'HASH') {
2471: foreach my $key (sort(keys(%{$multiples}))) {
2472: $multtext .= " if (prefix == '$key') {\n".
2473: " return '$multiples->{$key}';\n".
2474: " }\n";
2475: }
2476: }
2477: $multtext .= " return '';\n";
1.292 raeburn 2478:
1.293 raeburn 2479: $arrayindexofjs = &Apache::loncommon::javascript_array_indexof();
1.291 raeburn 2480: return <<"ENDSCRIPT";
2481: <script type="text/javascript">
2482: // <![CDATA[
2483:
2484: function file_submission_check(formname,path,multiresp) {
2485: var elemnum = formname.elements.length;
2486: if (elemnum == 0) {
2487: return true;
2488: }
2489: var alloverwrites = [];
2490: var alldelconfirm = [];
2491: var result = [];
2492: var submitter;
2493: var subprefix;
2494: var allsub = getIndexByName(formname,'all_submit');
2495: if (allsub == -1) {
2496: var idx = getIndexByName(formname,'submitted');
2497: if (idx != -1) {
2498: var subval = String(formname.elements[idx].value);
2499: submitter = subval.replace(/^part_/,'');
2500: result = overwritten_check(formname,path,multiresp,submitter);
2501: alloverwrites.push.apply(alloverwrites,result['overwrite']);
2502: alldelconfirm.push.apply(alldelconfirm,result['delete']);
2503: }
2504: } else {
2505: if (formname.elements[allsub].type == 'submit') {
2506: var partsub = /^\\d+\\.\\d+_submit_.+\$/;
2507: var allprefixes = [];
2508: var allparts = [];
2509: for (var i=0; i<formname.elements.length; i++) {
2510: if (formname.elements[i].type == 'submit') {
2511: var elemname = formname.elements[i].name;
2512: var subname = String(elemname);
2513: var savesub = String(elemname);
2514: if (partsub.test(subname)) {
2515: var prefix = subname.replace(/_submit_.+\$/,'');
2516: if (allprefixes.indexOf(prefix) == -1) {
2517: allprefixes.push(prefix);
2518: allparts[prefix] = [];
2519: }
2520: var part = savesub.replace(/^\\d+\\.\\d+_submit_/,'');
2521: allparts[prefix].push(part);
2522: }
2523: }
2524: }
2525: for (var k=0; k<allprefixes.length; k++) {
2526: var idx = getIndexByName(formname,allprefixes[k]+'_submitted');
2527: if (idx > -1) {
2528: if (formname.elements[idx].value != 'yes') {
2529: submitterval = formname.elements[idx].value;
2530: submitter = submitterval.replace(/^part_/,'');
2531: subprefix = allprefixes[k];
2532: result = overwritten_check(formname,path,multiresp,submitter,subprefix);
2533: alloverwrites.push.apply(alloverwrites,result['overwrite']);
2534: alldelconfirm.push.apply(alldelconfirm,result['delete']);
2535: break;
2536: }
2537: }
2538: }
2539: if (submitter == '' || submitter == undefined) {
2540: for (var m=0; m<allprefixes.length; m++) {
2541: for (var n=0; n<allparts[allprefixes[m]].length; n++) {
2542: var result = overwritten_check(formname,path,multiresp,allparts[allprefixes[m]][n],allprefixes[m]);
2543: alloverwrites.push.apply(alloverwrites,result['overwrite']);
2544: alldelconfirm.push.apply(alldelconfirm,result['delete']);
2545: }
2546: }
2547: }
2548: }
2549: }
2550: if (alloverwrites.length > 0) {
2551: if (!confirm("$overwritewarn")) {
2552: for (var n=0; n<alloverwrites.length; n++) {
2553: formname.elements[alloverwrites[n]].value = "";
2554: }
2555: return false;
2556: }
2557: }
2558: if (alldelconfirm.length > 0) {
2559: if (!confirm("$delfilewarn")) {
2560: for (var p=0; p<alldelconfirm.length; p++) {
2561: formname.elements[alldelconfirm[p]].checked = false;
2562: }
2563: return false;
2564: }
2565: }
2566: return true;
2567: }
2568:
2569: function getIndexByName(formname,item) {
2570: for (var i=0;i<formname.elements.length;i++) {
2571: if (formname.elements[i].name == item) {
2572: return i;
2573: }
2574: }
2575: return -1;
2576: }
2577:
2578: function overwritten_check(formname,path,multiresp,part,prefix) {
2579: var result = [];
2580: result['overwrite'] = [];
2581: result['delete'] = [];
2582: var elemnum = formname.elements.length;
2583: if (elemnum == 0) {
2584: return result;
2585: }
2586: var uploadstr;
2587: var deletestr;
2588: if ((prefix != undefined) && (prefix != '')) {
2589: var prepend = prefix+'_';
2590: uploadstr = new RegExp("^"+prepend+"HWFILE"+part+".+\$");
2591: deletestr = new RegExp("^"+prepend+"HWFILE"+part+".+_\\\\d+_delete\$");
2592: multiresp = check_for_multiples(prepend);
2593: path = check_for_turninpath(prepend);
2594: } else {
2595: uploadstr = new RegExp("^HWFILE"+part+".+\$");
2596: deletestr = new RegExp("^HWFILE"+part+".+_\\\\d+_delete\$");
2597: }
2598: var alluploads = [];
2599: var allchecked = [];
2600: var allskipdel = [];
2601: var fnametrim = /[^\\/\\\\]+\$/;
2602: for (var i=0; i<formname.elements.length; i++) {
2603: var id = formname.elements[i].id;
2604: if (id != '') {
2605: if (uploadstr.test(id)) {
2606: if (formname.elements[i].type == 'file') {
2607: alluploads.push(id);
2608: } else {
2609: if (deletestr.test(id)) {
2610: if (formname.elements[i].type == 'checkbox') {
2611: if (formname.elements[i].checked) {
2612: allchecked.push(id);
2613: }
2614: }
2615: }
2616: }
2617: }
2618: }
2619: }
2620: for (var j=0; j<alluploads.length; j++) {
2621: var delstr = new RegExp("^"+alluploads[j]+"_\\\\d+_delete\$");
2622: var delboxes = [];
2623: for (var k=0; k<formname.elements.length; k++) {
2624: var id = formname.elements[k].id;
2625: if ((id != '') && (id != undefined)) {
2626: if (delstr.test(id)) {
2627: if (formname.elements[k].type == 'checkbox') {
2628: delboxes.push(id);
2629: }
2630: }
2631: }
2632: }
2633: if (delboxes.length > 0) {
2634: if ((formname.elements[alluploads[j]].value != undefined) &&
2635: (formname.elements[alluploads[j]].value != '')) {
2636: var filepath = formname.elements[alluploads[j]].value;
2637: var newfilename = fnametrim.exec(filepath);
2638: if (newfilename != null) {
2639: var filename = String(newfilename);
2640: var nospaces = filename.replace(/\\s+/g,'_');
2641: var nospecials = nospaces.replace(/[^\\/\\w\\.\\-]/g,'');
2642: var cleanfilename = nospecials.replace(/\\.(\\d+\\.)/g,"_\$1");
2643: if (cleanfilename != '') {
2644: var fullpath = path+"/"+cleanfilename;
2645: if (multiresp == 1) {
2646: var partid = String(alluploads[i]);
2647: var subdir = partid.replace(/^\\d*.?\\d*_?HWFILE/,'');
2648: if (subdir != "" && subdir != undefined) {
2649: fullpath = path+"/"+subdir+"/"+cleanfilename;
2650: }
2651: }
2652: for (var m=0; m<delboxes.length; m++) {
2653: if (fullpath == formname.elements[delboxes[m]].value) {
2654: if (formname.elements[delboxes[m]].checked) {
2655: allskipdel.push(delboxes[m]);
2656: } else {
2657: result['overwrite'].push(alluploads[j]);
2658: }
2659: break;
2660: }
2661: }
2662: }
2663: }
2664: }
2665: }
2666: }
2667: if (allchecked.length > 0) {
2668: if (allskipdel.length > 0) {
2669: for (var n=0; n<allchecked.length; n++) {
2670: if (allskipdel.indexOf(allchecked[n]) == -1) {
2671: result['delete'].push(allchecked[n]);
2672: }
2673: }
2674: } else {
2675: result['delete'].push.apply(result['delete'],allchecked);
2676: }
2677: }
2678: return result;
2679: }
2680:
2681: function check_for_multiples(prefix) {
2682: $multtext
2683: }
2684:
2685: function check_for_turninpath(prefix) {
2686: $turninpathtext
2687: }
2688:
2689: // ]]>
2690: </script>
2691:
1.292 raeburn 2692: $arrayindexofjs
2693:
1.291 raeburn 2694: ENDSCRIPT
2695: }
2696:
2697: ##############################################
2698: ##############################################
2699:
1.158 raeburn 2700: # javascript_valid_email
2701: #
2702: # Generates javascript to validate an e-mail address.
2703: # Returns a javascript function which accetps a form field as argumnent, and
2704: # returns false if field.value does not satisfy two regular expression matches
2705: # for a valid e-mail address. Backwards compatible with old browsers without
2706: # support for javascript RegExp (just checks for @ in field.value in this case).
2707:
2708: sub javascript_valid_email {
2709: my $scripttag .= <<'END';
2710: function validmail(field) {
2711: var str = field.value;
2712: if (window.RegExp) {
2713: var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
2714: var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
2715: var reg1 = new RegExp(reg1str);
2716: var reg2 = new RegExp(reg2str);
2717: if (!reg1.test(str) && reg2.test(str)) {
2718: return true;
2719: }
2720: return false;
2721: }
2722: else
2723: {
2724: if(str.indexOf("@") >= 0) {
2725: return true;
2726: }
2727: return false;
2728: }
2729: }
2730: END
2731: return $scripttag;
2732: }
2733:
1.219 droeschl 2734:
2735: # USAGE: htmltag(element, content, {attribute => value,...});
2736: #
2737: # EXAMPLES:
2738: # - htmltag('a', 'this is an anchor', {href => 'www.example.com',
2739: # title => 'this is a title'})
2740: #
2741: # - You might want to set up needed tags like:
2742: #
2743: # my $h3 = sub { return htmltag( "h3", @_ ) };
2744: #
2745: # ... and use them: $h3->("This is a headline")
2746: #
2747: # - To set up a couple of tags, see sub inittags
2748: #
2749: # NOTES:
2750: # - Empty elements, such as <br/> are correctly terminated,
2751: # i.e. htmltag('br') returns <br/>
2752: # - Empty attributes (title="") are filtered out.
2753: # - The function will not check for deprecated attributes.
2754: #
2755: # OUTPUT: content enclosed in xhtml conform tags
2756: sub htmltag{
2757: return
2758: qq|<$_[0]|
2759: . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } )
2760: . ($_[1] ? qq|>$_[1]</$_[0]>| : qq|/>|). "\n";
2761: };
2762:
2763:
2764: # USAGE: inittags(@tags);
2765: #
2766: # EXAMPLES:
1.261 droeschl 2767: # - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )
1.219 droeschl 2768: # $h1->("This is a headline") #Returns: <h1>This is a headline</h1>
2769: #
2770: # NOTES: See sub htmltag for further information.
2771: #
2772: # OUTPUT: List of subroutines.
2773: sub inittags {
2774: my @tags = @_;
2775: return map { my $tag = $_;
2776: sub { return htmltag( $tag, @_ ) }
2777: } @tags;
2778: }
2779:
2780:
1.231 droeschl 2781: # USAGE: scripttag(scriptcode, [start|end|both]);
1.229 droeschl 2782: #
2783: # EXAMPLES:
1.231 droeschl 2784: # - scripttag("alert('Hello World!')", 'both')
2785: # returns:
2786: # <script type="text/javascript">
2787: # // BEGIN LON-CAPA Internal
2788: # alert(Hello World!')
2789: # // END LON-CAPA Internal
2790: # </script>
1.229 droeschl 2791: #
2792: # NOTES:
2793: # - works currently only for javascripts
2794: #
1.231 droeschl 2795: # OUTPUT:
2796: # Scriptcode properly enclosed in <script> and CDATA tags (and LC
2797: # Internal markers if 2nd argument is given)
1.229 droeschl 2798: sub scripttag {
1.231 droeschl 2799: my ( $content, $marker ) = @_;
2800: return unless defined $content;
2801:
2802: my $begin = "\n// BEGIN LON-CAPA Internal\n";
2803: my $end = "\n// END LON-CAPA Internal\n";
2804:
2805: if ($marker) {
2806: $content = $begin . $content if $marker eq 'start' or $marker eq 'both';
2807: $content .= $end if $marker eq 'end' or $marker eq 'both';
2808: }
2809:
1.229 droeschl 2810: $content = "\n// <![CDATA[\n$content\n// ]]>\n";
1.231 droeschl 2811:
2812: return htmltag('script', $content, {type => 'text/javascript'});
1.229 droeschl 2813: };
2814:
1.309 raeburn 2815: =pod
1.229 droeschl 2816:
1.309 raeburn 2817: =item &list_from_array( \@array, { listattr =>{}, itemattr =>{} } )
1.261 droeschl 2818:
2819: Constructs a XHTML list from \@array.
2820:
2821: input:
2822:
2823: =over
2824:
2825: =item \@array
2826:
2827: A reference to the array containing text that will be wrapped in <li></li> tags.
2828:
2829: =item { listattr => {}, itemattr =>{} }
2830:
2831: Attributes for <ul> and <li> passed in as hash references.
2832: See htmltag() for more details.
2833:
2834: =back
2835:
2836: returns: XHTML list as String.
2837:
2838: =cut
2839:
2840: # \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}
2841: sub list_from_array {
2842: my ($items, $args) = @_;
1.285 raeburn 2843: return unless (ref($items) eq 'ARRAY');
1.273 droeschl 2844: return unless scalar @$items;
1.261 droeschl 2845: my ($ul, $li) = inittags( qw(ul li) );
2846: my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;
2847: return $ul->( $listitems, $args->{listattr} );
2848: }
2849:
2850:
1.183 droeschl 2851: ##############################################
2852: ##############################################
2853:
2854: # generate_menu
2855: #
2856: # Generates html markup for a menu.
2857: #
2858: # Inputs:
2859: # An array of following structure:
2860: # ({ categorytitle => 'Categorytitle',
2861: # items => [
1.201 droeschl 2862: # {
2863: # linktext => 'Text to be displayed',
2864: # url => 'URL the link is pointing to, i.e. /adm/site?action=dosomething',
1.183 droeschl 2865: # permission => 'Contains permissions as returned from lonnet::allowed(),
1.201 droeschl 2866: # must evaluate to true in order to activate the link',
1.184 droeschl 2867: # icon => 'icon filename',
1.186 droeschl 2868: # alttext => 'alt text for the icon',
1.183 droeschl 2869: # help => 'Name of the corresponding helpfile',
2870: # linktitle => 'Description of the link (used for title tag)'
2871: # },
2872: # ...
2873: # ]
2874: # },
2875: # ...
2876: # )
2877: #
2878: # Outputs: A scalar containing the html markup for the menu.
2879:
2880: sub generate_menu {
2881: my @menu = @_;
1.201 droeschl 2882: # subs for specific html elements
1.219 droeschl 2883: my ($h3, $div, $ul, $li, $a, $img) = inittags( qw(h3 div ul li a img) );
1.201 droeschl 2884:
2885: my @categories; # each element represents the entire markup for a category
2886:
2887: foreach my $category (@menu) {
2888: my @links; # contains the links for the current $category
2889: foreach my $link (@{$$category{items}}) {
2890: next unless $$link{permission};
2891:
2892: # create the markup for the current $link and push it into @links.
2893: # each entry consists of an image and a text optionally followed
2894: # by a help link.
1.283 raeburn 2895: my $src;
2896: if ($$link{icon} ne '') {
2897: $src = '/res/adm/pages/'.$$link{icon};
2898: }
1.232 raeburn 2899: push(@links,$li->(
1.201 droeschl 2900: $a->(
2901: $img->("", {
2902: class => "LC_noBorder LC_middle",
1.283 raeburn 2903: src => $src,
1.202 droeschl 2904: alt => mt(defined($$link{alttext}) ?
2905: $$link{alttext} : $$link{linktext})
1.201 droeschl 2906: }), {
2907: href => $$link{url},
1.308 raeburn 2908: title => mt($$link{linktitle}),
2909: class => 'LC_menubuttons_link'
1.201 droeschl 2910: }).
1.202 droeschl 2911: $a->(mt($$link{linktext}), {
1.201 droeschl 2912: href => $$link{url},
1.202 droeschl 2913: title => mt($$link{linktitle}),
1.201 droeschl 2914: class => "LC_menubuttons_link"
2915: }).
2916: (defined($$link{help}) ?
2917: Apache::loncommon::help_open_topic($$link{help}) : ''),
1.232 raeburn 2918: {class => "LC_menubuttons_inline_text"}));
1.201 droeschl 2919: }
2920:
2921: # wrap categorytitle in <h3>, concatenate with
2922: # joined and in <ul> tags wrapped @links
2923: # and wrap everything in an enclosing <div> and push it into
2924: # @categories
2925: # such that each element looks like:
2926: # <div><h3>title</h3><ul><li>...</li>...</ul></div>
2927: # the category won't be added if there aren't any links
1.232 raeburn 2928: push(@categories,
1.202 droeschl 2929: $div->($h3->(mt($$category{categorytitle}), {class=>"LC_hcell"}).
1.201 droeschl 2930: $ul->(join('' ,@links), {class =>"LC_ListStyleNormal" }),
1.232 raeburn 2931: {class=>"LC_Box LC_400Box"})) if scalar(@links);
1.183 droeschl 2932: }
1.201 droeschl 2933:
2934: # wrap the joined @categories in another <div> (column layout)
2935: return $div->(join('', @categories), {class => "LC_columnSection"});
1.183 droeschl 2936: }
1.176 foxr 2937:
1.224 bisitz 2938: ##############################################
2939: ##############################################
2940:
2941: =pod
2942:
1.309 raeburn 2943: =item &start_funclist()
1.224 bisitz 2944:
2945: Start list of available functions
2946:
2947: Typically used to offer a simple list of available functions
2948: at top or bottom of page.
2949: All available functions/actions for the current page
2950: should be included in this list.
2951:
2952: If the optional headline text is not provided, a default text will be used.
2953:
2954:
2955: Related routines:
2956: =over 4
2957: add_item_funclist
2958: end_funclist
2959: =back
2960:
2961:
2962: Inputs: (optional) headline text
2963:
2964: Returns: HTML code with function list start
2965:
2966: =cut
2967:
2968: ##############################################
2969: ##############################################
2970:
2971: sub start_funclist {
2972: my($legendtext)=@_;
2973: $legendtext=&mt('Functions') if !$legendtext;
1.244 droeschl 2974: return '<ul class="LC_funclist"><li style="font-weight:bold; margin-left:0.8em;">'.$legendtext.'</li>'."\n";
1.224 bisitz 2975: }
2976:
2977:
2978: ##############################################
2979: ##############################################
2980:
2981: =pod
2982:
1.309 raeburn 2983: =item &add_item_funclist()
1.224 bisitz 2984:
2985: Adds an item to the list of available functions
2986:
2987: Related routines:
2988: =over 4
2989: start_funclist
2990: end_funclist
2991: =back
2992:
2993: Inputs: content item with text and link to function
2994:
2995: Returns: HTML code with list item for funclist
2996:
2997: =cut
2998:
2999: ##############################################
3000: ##############################################
3001:
3002: sub add_item_funclist {
3003: my($content) = @_;
3004: return '<li>'.$content.'</li>'."\n";
3005: }
3006:
3007: =pod
3008:
1.309 raeburn 3009: =item &end_funclist()
1.224 bisitz 3010:
3011: End list of available functions
3012:
3013: Related routines:
3014: =over 4
3015: start_funclist
3016: add_item_funclist
3017: =back
3018:
3019: Inputs: ./.
3020:
3021: Returns: HTML code with function list end
3022: =cut
3023:
3024: sub end_funclist {
1.246 bisitz 3025: return "</ul>\n";
1.224 bisitz 3026: }
3027:
1.261 droeschl 3028: =pod
3029:
1.309 raeburn 3030: =item &funclist_from_array( \@array, {legend => 'text for legend'} )
1.261 droeschl 3031:
3032: Constructs a XHTML list from \@array with the first item being visually
3033: highlighted and set to the value of legend or 'Functions' if legend is
3034: empty.
3035:
3036: =over
3037:
3038: =item \@array
3039:
3040: A reference to the array containing text that will be wrapped in <li></li> tags.
3041:
3042: =item { legend => 'text' }
3043:
3044: A string that's used as visually highlighted first item. 'Functions' is used if
3045: it's value evaluates to false.
3046:
3047: =back
3048:
3049: returns: XHTML list as string.
3050:
3051: =back
3052:
3053: =cut
3054:
3055: sub funclist_from_array {
3056: my ($items, $args) = @_;
1.285 raeburn 3057: return unless(ref($items) eq 'ARRAY');
1.261 droeschl 3058: $args->{legend} ||= mt('Functions');
3059: return list_from_array( [$args->{legend}, @$items],
3060: { listattr => {class => 'LC_funclist'} });
3061: }
3062:
1.1 stredwic 3063: 1;
1.23 matthew 3064:
1.1 stredwic 3065: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>