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