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