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