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