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