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