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