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