Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.303
1.2 www 1: # The LearningOnline Network with CAPA
2: # a pile of common html routines
3: #
1.303 ! www 4: # $Id: lonhtmlcommon.pm,v 1.302 2012/02/29 09:58:21 foxr 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.130 www 64: use LONCAPA;
1.1 stredwic 65:
1.284 www 66: sub java_not_enabled {
67: return "\n".'<span class="LC_error">'.
68: &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.').
69: "</span>\n";
70: }
1.247 www 71:
72: sub coursepreflink {
73: my ($text,$category)=@_;
74: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
1.296 www 75: return '<a target="_top" href="'.&HTML::Entities::encode("/adm/courseprefs?phase=display&actions=$category",'<>&"').'"><span class="LC_setting">'.$text.'</span></a>';
1.247 www 76: } else {
77: return '';
78: }
79: }
80:
1.253 www 81: sub raw_href_to_link {
82: my ($message)=@_;
1.264 faziophi 83: $message=~s/(https?\:\/\/[^\s\'\"\<]+)([\s\<]|$)/<a href="$1"><tt>$1<\/tt><\/a>$2/gi;
1.253 www 84: return $message;
85: }
86:
1.286 www 87: sub entity_encode {
88: my ($text)=@_;
89: return &HTML::Entities::encode($text, '<>&"');
90: }
91:
92: sub direct_parm_link {
93: my ($linktext,$symb,$filter,$part,$target)=@_;
94: $symb=&entity_encode($symb);
95: $filter=&entity_encode($filter);
96: $part=&entity_encode($part);
97: if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) {
1.296 www 98: return "<a target='_top' href='/adm/parmset?symb=$symb&filter=$filter&part=$part'><span class='LC_setting'>$linktext</span></a>";
1.286 www 99: } else {
100: return $linktext;
101: }
102: }
1.208 www 103: ##############################################
104: ##############################################
105:
106: =item confirm_success
107:
108: Successful completion of an operation message
109:
110: =cut
111:
112: sub confirm_success {
1.209 www 113: my ($message,$failure)=@_;
114: if ($failure) {
1.265 wenzelju 115: return '<span class="LC_error" style="font-size: inherit;">'."\n"
1.218 bisitz 116: .'<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.&mt('Error').'" /> '."\n"
1.211 bisitz 117: .$message."\n"
118: .'</span>'."\n";
1.209 www 119: } else {
1.211 bisitz 120: return '<span class="LC_success">'."\n"
1.233 raeburn 121: .'<img src="/adm/lonIcons/navmap.correct.gif" alt="'.&mt('OK').'" /> '."\n"
1.211 bisitz 122: .$message."\n"
123: .'</span>'."\n";
1.209 www 124: }
1.208 www 125: }
1.176 foxr 126:
127: ##############################################
128: ##############################################
129:
130: =pod
131:
1.177 raeburn 132: =item dragmath_button
1.176 foxr 133:
1.177 raeburn 134: Creates a button that launches a dragmath popup-window, in which an
135: expression can be edited and pasted as LaTeX into a specified textarea.
136:
137: textarea - Name of the textarea to edit.
138: helpicon - If true, show a help icon to the right of the button.
1.176 foxr 139:
140: =cut
141:
1.177 raeburn 142: sub dragmath_button {
143: my ($textarea,$helpicon) = @_;
144: my $help_text;
145: if ($helpicon) {
1.282 raeburn 146: $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor',undef,undef,undef,undef,'mathhelpicon_'.$textarea);
1.177 raeburn 147: }
1.178 bisitz 148: my $buttontext=&mt('Edit Math');
1.177 raeburn 149: return <<ENDDRAGMATH;
1.246 bisitz 150: <input type="button" value="$buttontext" onclick="javascript:mathedit('$textarea',document)" />$help_text
1.177 raeburn 151: ENDDRAGMATH
152: }
153:
1.176 foxr 154: ##############################################
155:
1.177 raeburn 156: =pod
157:
158: =item dragmath_js
159:
160: Javascript used to open pop-up window containing dragmath applet which
161: can be used to paste LaTeX into a textarea.
162: =cut
1.176 foxr 163:
1.177 raeburn 164: sub dragmath_js {
1.182 foxr 165: my ($popup) = @_;
1.177 raeburn 166: return <<ENDDRAGMATHJS;
167: <script type="text/javascript">
1.218 bisitz 168: // <![CDATA[
1.176 foxr 169: function mathedit(textarea, doc) {
170: targetEntry = textarea;
1.177 raeburn 171: targetDoc = doc;
1.182 foxr 172: newwin = window.open("/adm/dragmath/applet/$popup.html","","width=565,height=500,resizable");
1.176 foxr 173: }
1.218 bisitz 174: // ]]>
1.176 foxr 175: </script>
1.177 raeburn 176:
177: ENDDRAGMATHJS
1.176 foxr 178: }
179:
1.182 foxr 180:
1.40 www 181: ##############################################
182: ##############################################
183:
184: =pod
185:
186: =item authorbombs
187:
188: =cut
189:
190: ##############################################
191: ##############################################
192:
193: sub authorbombs {
194: my $url=shift;
195: $url=&Apache::lonnet::declutter($url);
1.155 albertel 196: my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/});
1.40 www 197: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.232 raeburn 198: foreach my $bomb (keys(%bombs)) {
199: if ($bomb =~ /^$udom\/$uname\//) {
1.40 www 200: return '<a href="/adm/bombs/'.$url.
1.218 bisitz 201: '"><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/bomb.gif').'" alt="'.&mt('Bomb').'" border="0" /></a>'.
1.40 www 202: &Apache::loncommon::help_open_topic('About_Bombs');
203: }
204: }
205: return '';
206: }
1.26 matthew 207:
208: ##############################################
209: ##############################################
210:
1.41 www 211: sub recent_filename {
212: my $area=shift;
1.130 www 213: return 'nohist_recent_'.&escape($area);
1.41 www 214: }
215:
216: sub store_recent {
1.136 albertel 217: my ($area,$name,$value,$freeze)=@_;
1.41 www 218: my $file=&recent_filename($area);
219: my %recent=&Apache::lonnet::dump($file);
1.111 www 220: if (scalar(keys(%recent))>20) {
1.41 www 221: # remove oldest value
1.136 albertel 222: my $oldest=time();
1.41 www 223: my $delkey='';
1.136 albertel 224: foreach my $item (keys(%recent)) {
225: my $thistime=(split(/\&/,$recent{$item}))[0];
226: if (($thistime ne "always_include") && ($thistime<$oldest)) {
1.41 www 227: $oldest=$thistime;
1.136 albertel 228: $delkey=$item;
1.41 www 229: }
230: }
231: &Apache::lonnet::del($file,[$delkey]);
232: }
233: # store new value
1.136 albertel 234: my $timestamp;
235: if ($freeze) {
236: $timestamp = "always_include";
237: } else {
238: $timestamp = time();
239: }
1.41 www 240: &Apache::lonnet::put($file,{ $name =>
1.136 albertel 241: $timestamp.'&'.&escape($value) });
1.41 www 242: }
243:
1.89 banghart 244: sub remove_recent {
245: my ($area,$names)=@_;
246: my $file=&recent_filename($area);
247: return &Apache::lonnet::del($file,$names);
248: }
249:
1.41 www 250: sub select_recent {
251: my ($area,$fieldname,$event)=@_;
252: my %recent=&Apache::lonnet::dump(&recent_filename($area));
253: my $return="\n<select name='$fieldname'".
1.96 albertel 254: ($event?" onchange='$event'":'').
1.41 www 255: ">\n<option value=''>--- ".&mt('Recent')." ---</option>";
1.136 albertel 256: foreach my $value (sort(keys(%recent))) {
257: unless ($value =~/^error\:/) {
258: my $escaped = &Apache::loncommon::escape_url($value);
1.160 albertel 259: &Apache::loncommon::inhibit_menu_check(\$escaped);
1.251 raeburn 260: if ($area eq 'residx') {
261: next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value)));
262: }
1.94 foxr 263: $return.="\n<option value='$escaped'>".
1.136 albertel 264: &unescape((split(/\&/,$recent{$value}))[1]).
1.41 www 265: '</option>';
266: }
267: }
268: $return.="\n</select>\n";
269: return $return;
270: }
271:
1.97 albertel 272: sub get_recent {
273: my ($area, $n) = @_;
274: my %recent=&Apache::lonnet::dump(&recent_filename($area));
275:
276: # Create hash with key as time and recent as value
1.136 albertel 277: # Begin filling return_hash with any 'always_include' option
1.97 albertel 278: my %time_hash = ();
1.136 albertel 279: my %return_hash = ();
1.232 raeburn 280: foreach my $item (keys(%recent)) {
1.136 albertel 281: my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
282: if ($thistime eq 'always_include') {
283: $return_hash{$item} = &unescape($thisvalue);
284: $n--;
285: } else {
286: $time_hash{$thistime} = $item;
1.133 albertel 287: }
1.97 albertel 288: }
289:
290: # Sort by decreasing time and return key value pairs
291: my $idx = 1;
1.136 albertel 292: foreach my $item (reverse(sort(keys(%time_hash)))) {
293: $return_hash{$time_hash{$item}} =
294: &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]);
1.97 albertel 295: if ($n && ($idx++ >= $n)) {last;}
296: }
297:
298: return %return_hash;
299: }
300:
1.136 albertel 301: sub get_recent_frozen {
302: my ($area) = @_;
303: my %recent=&Apache::lonnet::dump(&recent_filename($area));
304:
305: # Create hash with all 'frozen' items
306: my %return_hash = ();
307: foreach my $item (keys(%recent)) {
308: my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
309: if ($thistime eq 'always_include') {
310: $return_hash{$item} = &unescape($thisvalue);
311: }
312: }
313: return %return_hash;
314: }
315:
1.97 albertel 316:
1.41 www 317:
1.26 matthew 318: =pod
319:
320: =item textbox
321:
322: =cut
323:
324: ##############################################
325: ##############################################
326: sub textbox {
327: my ($name,$value,$size,$special) = @_;
328: $size = 40 if (! defined($size));
1.128 albertel 329: $value = &HTML::Entities::encode($value,'<>&"');
1.26 matthew 330: my $Str = '<input type="text" name="'.$name.'" size="'.$size.'" '.
331: 'value="'.$value.'" '.$special.' />';
332: return $Str;
333: }
334:
335: ##############################################
336: ##############################################
337:
338: =pod
339:
340: =item checkbox
341:
342: =cut
343:
344: ##############################################
345: ##############################################
346: sub checkbox {
1.68 matthew 347: my ($name,$checked,$value) = @_;
348: my $Str = '<input type="checkbox" name="'.$name.'" ';
349: if (defined($value)) {
350: $Str .= 'value="'.$value.'"';
351: }
352: if ($checked) {
1.206 bisitz 353: $Str .= ' checked="checked"';
1.68 matthew 354: }
355: $Str .= ' />';
1.26 matthew 356: return $Str;
357: }
358:
1.120 albertel 359:
360: =pod
361:
362: =item radiobutton
363:
364: =cut
365:
366: ##############################################
367: ##############################################
368: sub radio {
369: my ($name,$checked,$value) = @_;
370: my $Str = '<input type="radio" name="'.$name.'" ';
371: if (defined($value)) {
372: $Str .= 'value="'.$value.'"';
373: }
374: if ($checked eq $value) {
1.206 bisitz 375: $Str .= ' checked="checked"';
1.120 albertel 376: }
377: $Str .= ' />';
378: return $Str;
379: }
380:
1.10 matthew 381: ##############################################
382: ##############################################
383:
384: =pod
385:
386: =item &date_setter
387:
1.22 matthew 388: &date_setter returns html and javascript for a compact date-setting form.
389: To retrieve values from it, use &get_date_from_form().
390:
1.10 matthew 391: Inputs
392:
393: =over 4
394:
395: =item $dname
396:
397: The name to prepend to the form elements.
398: The form elements defined will be dname_year, dname_month, dname_day,
399: dname_hour, dname_min, and dname_sec.
400:
401: =item $currentvalue
402:
403: The current setting for this time parameter. A unix format time
404: (time in seconds since the beginning of Jan 1st, 1970, GMT.
1.257 faziophi 405: An undefined value is taken to indicate the value is the current time
406: unless it is requested to leave it empty. See $includeempty.
1.10 matthew 407: Also, to be explicit, a value of 'now' also indicates the current time.
408:
1.26 matthew 409: =item $special
410:
411: Additional html/javascript to be associated with each element in
412: the date_setter. See lonparmset for example usage.
413:
1.59 matthew 414: =item $includeempty
415:
1.257 faziophi 416: If it is set (true) and no date/time value is provided,
417: the date/time fields are left empty.
418:
1.59 matthew 419: =item $state
420:
421: Specifies the initial state of the form elements. Either 'disabled' or empty.
422: Defaults to empty, which indiciates the form elements are not disabled.
423:
1.22 matthew 424: =back
425:
426: Bugs
427:
428: The method used to restrict user input will fail in the year 2400.
429:
1.10 matthew 430: =cut
431:
432: ##############################################
433: ##############################################
434: sub date_setter {
1.67 matthew 435: my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
1.134 raeburn 436: $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_;
1.175 raeburn 437: my $now = time;
1.257 faziophi 438:
439: my $tzname;
440: my ($sec,$min,$hour,$mday,$month,$year) = ('', '', undef,''.''.'');
441: #other potentially useful values: wkday,yrday,is_daylight_savings
442:
1.59 matthew 443: if (! defined($state) || $state ne 'disabled') {
444: $state = '';
445: }
1.67 matthew 446: if (! defined($no_hh_mm_ss)) {
447: $no_hh_mm_ss = 0;
448: }
1.110 www 449: if ($currentvalue eq 'now') {
1.257 faziophi 450: $currentvalue = $now;
1.110 www 451: }
1.257 faziophi 452:
453: # Default value: Set empty date field to current time
454: # unless empty inclusion is requested
455: if ((!$includeempty) && (!$currentvalue)) {
456: $currentvalue = $now;
1.10 matthew 457: }
1.257 faziophi 458: # Do we have a date? Split it!
1.39 www 459: if ($currentvalue) {
1.257 faziophi 460: ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue);
461:
462: #No values provided for hour, min, sec? Use default 0
463: if (($defhour) || ($defmin) || ($defsec)) {
464: $sec = ($defsec ? $defsec : 0);
465: $min = ($defmin ? $defmin : 0);
466: $hour = ($defhour ? $defhour : 0);
467: }
1.107 www 468: }
1.10 matthew 469: my $result = "\n<!-- $dname date setting form -->\n";
470: $result .= <<ENDJS;
1.135 albertel 471: <script type="text/javascript">
1.218 bisitz 472: // <![CDATA[
1.10 matthew 473: function $dname\_checkday() {
474: var day = document.$formname.$dname\_day.value;
475: var month = document.$formname.$dname\_month.value;
476: var year = document.$formname.$dname\_year.value;
477: var valid = true;
478: if (day < 1) {
479: document.$formname.$dname\_day.value = 1;
480: }
481: if (day > 31) {
482: document.$formname.$dname\_day.value = 31;
483: }
484: if ((month == 1) || (month == 3) || (month == 5) ||
485: (month == 7) || (month == 8) || (month == 10) ||
486: (month == 12)) {
487: if (day > 31) {
488: document.$formname.$dname\_day.value = 31;
489: day = 31;
490: }
491: } else if (month == 2 ) {
492: if ((year % 4 == 0) && (year % 100 != 0)) {
493: if (day > 29) {
494: document.$formname.$dname\_day.value = 29;
495: }
496: } else if (day > 29) {
497: document.$formname.$dname\_day.value = 28;
498: }
499: } else if (day > 30) {
500: document.$formname.$dname\_day.value = 30;
501: }
502: }
1.95 matthew 503:
1.59 matthew 504: function $dname\_disable() {
505: document.$formname.$dname\_month.disabled=true;
506: document.$formname.$dname\_day.disabled=true;
507: document.$formname.$dname\_year.disabled=true;
508: document.$formname.$dname\_hour.disabled=true;
509: document.$formname.$dname\_minute.disabled=true;
510: document.$formname.$dname\_second.disabled=true;
511: }
512:
513: function $dname\_enable() {
514: document.$formname.$dname\_month.disabled=false;
515: document.$formname.$dname\_day.disabled=false;
516: document.$formname.$dname\_year.disabled=false;
517: document.$formname.$dname\_hour.disabled=false;
518: document.$formname.$dname\_minute.disabled=false;
519: document.$formname.$dname\_second.disabled=false;
520: }
521:
1.29 www 522: function $dname\_opencalendar() {
1.59 matthew 523: if (! document.$formname.$dname\_month.disabled) {
524: var calwin=window.open(
1.29 www 525: "/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
526: document.$formname.$dname\_month.value+"&year="+
527: document.$formname.$dname\_year.value,
528: "LONCAPAcal",
529: "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
1.59 matthew 530: }
1.29 www 531:
532: }
1.218 bisitz 533: // ]]>
1.10 matthew 534: </script>
535: ENDJS
1.192 bisitz 536: $result .= ' <span class="LC_nobreak">';
1.96 albertel 537: my $monthselector = qq{<select name="$dname\_month" $special $state onchange="javascript:$dname\_checkday()" >};
1.67 matthew 538: # Month
1.10 matthew 539: my @Months = qw/January February March April May June
540: July August September October November December/;
541: # Pad @Months with a bogus value to make indexing easier
542: unshift(@Months,'If you can read this an error occurred');
1.95 matthew 543: if ($includeempty) { $monthselector.="<option value=''></option>"; }
1.10 matthew 544: for(my $m = 1;$m <=$#Months;$m++) {
1.228 bisitz 545: $monthselector .= qq{ <option value="$m"};
546: $monthselector .= ' selected="selected"' if ($m-1 eq $month);
547: $monthselector .= '> '.&mt($Months[$m]).' </option>'."\n";
1.10 matthew 548: }
1.95 matthew 549: $monthselector.= ' </select>';
1.67 matthew 550: # Day
1.96 albertel 551: my $dayselector = qq{<input type="text" name="$dname\_day" $state value="$mday" size="3" $special onchange="javascript:$dname\_checkday()" />};
1.67 matthew 552: # Year
1.226 bisitz 553: my $yearselector = qq{<input type="text" name="$dname\_year" $state value="$year" size="5" $special onchange="javascript:$dname\_checkday()" />};
1.95 matthew 554: #
555: my $hourselector = qq{<select name="$dname\_hour" $special $state >};
556: if ($includeempty) {
557: $hourselector.=qq{<option value=''></option>};
558: }
559: for (my $h = 0;$h<24;$h++) {
1.228 bisitz 560: $hourselector .= qq{<option value="$h"};
561: $hourselector .= ' selected="selected"' if (defined($hour) && $hour == $h);
1.95 matthew 562: $hourselector .= ">";
563: my $timest='';
564: if ($h == 0) {
565: $timest .= "12 am";
566: } elsif($h == 12) {
567: $timest .= "12 noon";
568: } elsif($h < 12) {
569: $timest .= "$h am";
570: } else {
571: $timest .= $h-12 ." pm";
572: }
573: $timest=&mt($timest);
574: $hourselector .= $timest." </option>\n";
575: }
576: $hourselector .= " </select>\n";
577: my $minuteselector = qq{<input type="text" name="$dname\_minute" $special $state value="$min" size="3" />};
578: my $secondselector= qq{<input type="text" name="$dname\_second" $special $state value="$sec" size="3" />};
1.134 raeburn 579: my $cal_link;
580: if (!$nolink) {
581: $cal_link = qq{<a href="javascript:$dname\_opencalendar()">};
582: }
1.95 matthew 583: #
1.175 raeburn 584: my $tzone = ' '.$tzname.' ';
1.95 matthew 585: if ($no_hh_mm_ss) {
1.134 raeburn 586: $result .= &mt('[_1] [_2] [_3] ',
1.174 raeburn 587: $monthselector,$dayselector,$yearselector).
588: $tzone;
1.134 raeburn 589: if (!$nolink) {
1.141 albertel 590: $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
1.134 raeburn 591: }
1.95 matthew 592: } else {
1.134 raeburn 593: $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ',
594: $monthselector,$dayselector,$yearselector,
1.174 raeburn 595: $hourselector,$minuteselector,$secondselector).
596: $tzone;
1.134 raeburn 597: if (!$nolink) {
1.141 albertel 598: $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
1.134 raeburn 599: }
1.67 matthew 600: }
1.135 albertel 601: $result .= "</span>\n<!-- end $dname date setting form -->\n";
1.10 matthew 602: return $result;
603: }
604:
1.175 raeburn 605: sub get_timedates {
606: my ($epoch) = @_;
607: my $dt = DateTime->from_epoch(epoch => $epoch)
608: ->set_time_zone(&Apache::lonlocal::gettimezone());
609: my $tzname = $dt->time_zone_short_name();
610: my $sec = $dt->second;
611: my $min = $dt->minute;
612: my $hour = $dt->hour;
613: my $mday = $dt->day;
614: my $month = $dt->month;
615: if ($month) {
616: $month --;
617: }
618: my $year = $dt->year;
619: return ($tzname,$sec,$min,$hour,$mday,$month,$year);
620: }
1.166 banghart 621:
622: sub build_url {
623: my ($base, $fields)=@_;
624: my $url;
625: $url = $base.'?';
1.168 albertel 626: foreach my $key (keys(%$fields)) {
627: $url.=&escape($key).'='.&escape($$fields{$key}).'&';
1.166 banghart 628: }
629: $url =~ s/&$//;
630: return $url;
631: }
632:
633:
1.10 matthew 634: ##############################################
635: ##############################################
636:
1.22 matthew 637: =pod
638:
1.10 matthew 639: =item &get_date_from_form
1.22 matthew 640:
641: get_date_from_form retrieves the date specified in an &date_setter form.
1.10 matthew 642:
643: Inputs:
644:
645: =over 4
646:
647: =item $dname
648:
1.226 bisitz 649: The name passed to &date_setter, which prefixes the form elements.
1.10 matthew 650:
651: =item $defaulttime
652:
653: The unix time to use as the default in case of poor inputs.
654:
655: =back
656:
657: Returns: Unix time represented in the form.
658:
659: =cut
660:
661: ##############################################
662: ##############################################
663: sub get_date_from_form {
664: my ($dname) = @_;
665: my ($sec,$min,$hour,$day,$month,$year);
666: #
1.104 albertel 667: if (defined($env{'form.'.$dname.'_second'})) {
668: my $tmpsec = $env{'form.'.$dname.'_second'};
1.10 matthew 669: if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
670: $sec = $tmpsec;
671: }
1.64 albertel 672: if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
1.67 matthew 673: } else {
674: $sec = 0;
1.10 matthew 675: }
1.104 albertel 676: if (defined($env{'form.'.$dname.'_minute'})) {
677: my $tmpmin = $env{'form.'.$dname.'_minute'};
1.10 matthew 678: if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
679: $min = $tmpmin;
680: }
1.64 albertel 681: if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
1.67 matthew 682: } else {
683: $min = 0;
1.10 matthew 684: }
1.104 albertel 685: if (defined($env{'form.'.$dname.'_hour'})) {
686: my $tmphour = $env{'form.'.$dname.'_hour'};
1.33 matthew 687: if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
1.10 matthew 688: $hour = $tmphour;
689: }
1.67 matthew 690: } else {
691: $hour = 0;
1.10 matthew 692: }
1.104 albertel 693: if (defined($env{'form.'.$dname.'_day'})) {
694: my $tmpday = $env{'form.'.$dname.'_day'};
1.10 matthew 695: if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
696: $day = $tmpday;
697: }
698: }
1.104 albertel 699: if (defined($env{'form.'.$dname.'_month'})) {
700: my $tmpmonth = $env{'form.'.$dname.'_month'};
1.10 matthew 701: if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
1.175 raeburn 702: $month = $tmpmonth;
1.10 matthew 703: }
704: }
1.104 albertel 705: if (defined($env{'form.'.$dname.'_year'})) {
706: my $tmpyear = $env{'form.'.$dname.'_year'};
1.175 raeburn 707: if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) {
708: $year = $tmpyear;
1.10 matthew 709: }
710: }
1.175 raeburn 711: if (($year<1970) || ($year>2037)) { return undef; }
1.33 matthew 712: if (defined($sec) && defined($min) && defined($hour) &&
1.175 raeburn 713: defined($day) && defined($month) && defined($year)) {
714: my $timezone = &Apache::lonlocal::gettimezone();
715: my $dt = DateTime->new( year => $year,
716: month => $month,
717: day => $day,
718: hour => $hour,
719: minute => $min,
720: second => $sec,
721: time_zone => $timezone,
722: );
723: my $epoch_time = $dt->epoch;
724: if ($epoch_time ne '') {
725: return $epoch_time;
726: } else {
727: return undef;
728: }
1.10 matthew 729: } else {
730: return undef;
731: }
1.20 matthew 732: }
733:
734: ##############################################
735: ##############################################
736:
737: =pod
738:
739: =item &pjump_javascript_definition()
740:
741: Returns javascript defining the 'pjump' function, which opens up a
742: parameter setting wizard.
743:
744: =cut
745:
746: ##############################################
747: ##############################################
748: sub pjump_javascript_definition {
749: my $Str = <<END;
1.109 www 750: function pjump(type,dis,value,marker,ret,call,hour,min,sec) {
1.295 www 751: openMyModal("/adm/rat/parameter.html?type="+escape(type)
1.20 matthew 752: +"&value="+escape(value)+"&marker="+escape(marker)
753: +"&return="+escape(ret)
1.109 www 754: +"&call="+escape(call)+"&name="+escape(dis)
755: +"&defhour="+escape(hour)+"&defmin="+escape(min)
1.295 www 756: +"&defsec="+escape(sec)+"&modal=1",350,350,'no');
1.20 matthew 757: }
758: END
759: return $Str;
1.10 matthew 760: }
761:
762: ##############################################
763: ##############################################
1.17 matthew 764:
765: =pod
766:
767: =item &javascript_nothing()
768:
769: Return an appropriate null for the users browser. This is used
770: as the first arguement for window.open calls when you want a blank
771: window that you can then write to.
772:
773: =cut
774:
775: ##############################################
776: ##############################################
777: sub javascript_nothing {
778: # mozilla and other browsers work with "''", but IE on mac does not.
779: my $nothing = "''";
780: my $user_browser;
781: my $user_os;
1.104 albertel 782: $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
783: $user_os = $env{'browser.os'} if (exists($env{'browser.os'}));
1.17 matthew 784: if (! defined($user_browser) || ! defined($user_os)) {
785: (undef,$user_browser,undef,undef,undef,$user_os) =
786: &Apache::loncommon::decode_user_agent();
787: }
788: if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
789: $nothing = "'javascript:void(0);'";
790: }
791: return $nothing;
792: }
793:
1.90 www 794: ##############################################
795: ##############################################
796: sub javascript_docopen {
1.171 albertel 797: my ($mimetype) = @_;
798: $mimetype ||= 'text/html';
1.90 www 799: # safari does not understand document.open() and loads "text/html"
800: my $nothing = "''";
801: my $user_browser;
802: my $user_os;
1.104 albertel 803: $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
804: $user_os = $env{'browser.os'} if (exists($env{'browser.os'}));
1.90 www 805: if (! defined($user_browser) || ! defined($user_os)) {
806: (undef,$user_browser,undef,undef,undef,$user_os) =
807: &Apache::loncommon::decode_user_agent();
808: }
809: if ($user_browser eq 'safari' && $user_os =~ 'mac') {
810: $nothing = "document.clear()";
811: } else {
1.171 albertel 812: $nothing = "document.open('$mimetype','replace')";
1.90 www 813: }
814: return $nothing;
815: }
816:
1.21 matthew 817:
1.17 matthew 818: ##############################################
819: ##############################################
820:
1.21 matthew 821: =pod
1.17 matthew 822:
1.21 matthew 823: =item &StatusOptions()
1.10 matthew 824:
1.21 matthew 825: Returns html for a selection box which allows the user to choose the
826: enrollment status of students. The selection box name is 'Status'.
1.6 stredwic 827:
1.21 matthew 828: Inputs:
1.6 stredwic 829:
1.21 matthew 830: $status: the currently selected status. If undefined the value of
1.104 albertel 831: $env{'form.Status'} is taken. If that is undefined, a value of 'Active'
1.21 matthew 832: is used.
1.6 stredwic 833:
1.21 matthew 834: $formname: The name of the form. If defined the onchange attribute of
835: the selection box is set to document.$formname.submit().
1.6 stredwic 836:
1.21 matthew 837: $size: the size (number of lines) of the selection box.
1.6 stredwic 838:
1.27 matthew 839: $onchange: javascript to use when the value is changed. Enclosed in
840: double quotes, ""s, not single quotes.
841:
1.21 matthew 842: Returns: a perl string as described.
1.1 stredwic 843:
1.21 matthew 844: =cut
1.9 stredwic 845:
1.21 matthew 846: ##############################################
847: ##############################################
848: sub StatusOptions {
1.165 banghart 849: my ($status, $formName,$size,$onchange,$mult)=@_;
1.21 matthew 850: $size = 1 if (!defined($size));
851: if (! defined($status)) {
852: $status = 'Active';
1.104 albertel 853: $status = $env{'form.Status'} if (exists($env{'form.Status'}));
1.9 stredwic 854: }
1.1 stredwic 855:
856: my $Str = '';
857: $Str .= '<select name="Status"';
1.165 banghart 858: if (defined($mult)){
859: $Str .= ' multiple="multiple" ';
860: }
1.27 matthew 861: if(defined($formName) && $formName ne '' && ! defined($onchange)) {
1.1 stredwic 862: $Str .= ' onchange="document.'.$formName.'.submit()"';
1.27 matthew 863: }
864: if (defined($onchange)) {
865: $Str .= ' onchange="'.$onchange.'"';
1.1 stredwic 866: }
1.21 matthew 867: $Str .= ' size="'.$size.'" ';
1.1 stredwic 868: $Str .= '>'."\n";
1.153 raeburn 869: foreach my $type (['Active', &mt('Currently Has Access')],
870: ['Future', &mt('Will Have Future Access')],
871: ['Expired', &mt('Previously Had Access')],
872: ['Any', &mt('Any Access Status')]) {
1.151 albertel 873: my ($name,$label) = @$type;
874: $Str .= '<option value="'.$name.'" ';
875: if ($status eq $name) {
876: $Str .= 'selected="selected" ';
877: }
878: $Str .= '>'.$label.'</option>'."\n";
879: }
880:
1.1 stredwic 881: $Str .= '</select>'."\n";
1.7 stredwic 882: }
1.12 matthew 883:
884: ########################################################
885: ########################################################
1.7 stredwic 886:
1.23 matthew 887: =pod
888:
889: =item Progess Window Handling Routines
890:
891: These routines handle the creation, update, increment, and closure of
892: progress windows. The progress window reports to the user the number
893: of items completed and an estimate of the time required to complete the rest.
894:
895: =over 4
896:
897:
898: =item &Create_PrgWin
899:
900: Writes javascript to the client to open a progress window and returns a
901: data structure used for bookkeeping.
902:
903: Inputs
904:
905: =over 4
906:
907: =item $r Apache request
908:
909: =item $title The title of the progress window
910:
911: =item $heading A description (usually 1 line) of the process being initiated.
912:
913: =item $number_to_do The total number of items being processed.
1.50 albertel 914:
915: =item $type Either 'popup' or 'inline' (popup is assumed if nothing is
916: specified)
917:
1.51 albertel 918: =item $width Specify the width in charaters of the input field.
919:
1.50 albertel 920: =item $formname Only useful in the inline case, if a form already exists, this needs to be used and specfiy the name of the form, otherwise the Progress line will be created in a new form of it's own
921:
922: =item $inputname Only useful in the inline case, if a form and an input of type text exists, use this to specify the name of the input field
1.23 matthew 923:
924: =back
925:
926: Returns a hash containing the progress state data structure.
927:
928:
929: =item &Update_PrgWin
930:
931: Updates the text in the progress indicator. Does not increment the count.
932: See &Increment_PrgWin.
933:
934: Inputs:
935:
936: =over 4
937:
938: =item $r Apache request
939:
940: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
941:
942: =item $displaystring The string to write to the status indicator
943:
944: =back
945:
946: Returns: none
947:
948:
949: =item Increment_PrgWin
950:
1.276 bisitz 951: Increment the count of items completed for the progress window by $step or 1 if no step is provided.
1.23 matthew 952:
953: Inputs:
954:
955: =over 4
956:
957: =item $r Apache request
958:
959: =item $prog_state Pointer to the data structure returned by Create_PrgWin
960:
961: =item $extraInfo A description of the items being iterated over. Typically
962: 'student'.
963:
1.279 bisitz 964: =item $step (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
1.276 bisitz 965:
1.23 matthew 966: =back
967:
968: Returns: none
969:
970:
971: =item Close_PrgWin
972:
973: Closes the progress window.
974:
975: Inputs:
976:
977: =over 4
978:
979: =item $r Apache request
980:
981: =item $prog_state Pointer to the data structure returned by Create_PrgWin
982:
983: =back
984:
985: Returns: none
986:
987: =back
988:
989: =cut
990:
991: ########################################################
992: ########################################################
993:
1.51 albertel 994:
1.7 stredwic 995: # Create progress
996: sub Create_PrgWin {
1.297 www 997: my ($r,$number_to_do)=@_;
1.49 albertel 998: my %prog_state;
1.16 albertel 999: $prog_state{'done'}=0;
1.23 matthew 1000: $prog_state{'firststart'}=&Time::HiRes::time();
1001: $prog_state{'laststart'}=&Time::HiRes::time();
1.16 albertel 1002: $prog_state{'max'}=$number_to_do;
1.297 www 1003: &Apache::loncommon::LCprogressbar($r);
1.14 albertel 1004: return %prog_state;
1.7 stredwic 1005: }
1006:
1007: # update progress
1008: sub Update_PrgWin {
1.14 albertel 1009: my ($r,$prog_state,$displayString)=@_;
1.297 www 1010: &Apache::loncommon::LCprogressbarUpdate($r,undef,$displayString);
1.23 matthew 1011: $$prog_state{'laststart'}=&Time::HiRes::time();
1.14 albertel 1012: }
1013:
1014: # increment progress state
1015: sub Increment_PrgWin {
1.275 bisitz 1016: my ($r,$prog_state,$extraInfo,$step)=@_;
1.279 bisitz 1017: $step = $step > 0 ? $step : 1;
1.275 bisitz 1018: $$prog_state{'done'} += $step;
1019:
1020: # Catch (max modulo step) <> 0
1021: my $current = $$prog_state{'done'};
1022: my $last = ($$prog_state{'max'} - $current);
1023: if ($last <= 0) {
1024: $last = 1;
1025: $current = $$prog_state{'max'};
1026: }
1027:
1.23 matthew 1028: my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
1.275 bisitz 1029: $current * $last;
1.16 albertel 1030: $time_est = int($time_est);
1.80 matthew 1031: #
1032: my $min = int($time_est/60);
1033: my $sec = $time_est % 60;
1.278 bisitz 1034:
1.23 matthew 1035: my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
1036: if ($lasttime > 9) {
1037: $lasttime = int($lasttime);
1038: } elsif ($lasttime < 0.01) {
1039: $lasttime = 0;
1040: } else {
1041: $lasttime = sprintf("%3.2f",$lasttime);
1042: }
1.278 bisitz 1043:
1044: $sec = 0 if ($min >= 10); # Don't show seconds if remaining time >= 10 min.
1045: $sec = 1 if ( ($min == 0) && ($sec == 0) ); # Little cheating: pretend to have 1 second remaining instead of 0 to have something to display
1046:
1047: my $timeinfo =
1048: &mt('[_1]/[_2]:'
1049: .' [quant,_3,minute,minutes,] [quant,_4,second ,seconds ,]remaining'
1050: .' ([quant,_5,second] for '.$extraInfo.')',
1051: $current,
1052: $$prog_state{'max'},
1053: $min,
1054: $sec,
1055: $lasttime);
1.297 www 1056: my $percent=0;
1057: if ($$prog_state{'max'}) {
1058: $percent=int(100.*$current/$$prog_state{'max'});
1059: }
1060: &Apache::loncommon::LCprogressbarUpdate($r,$percent,$timeinfo);
1.23 matthew 1061: $$prog_state{'laststart'}=&Time::HiRes::time();
1.7 stredwic 1062: }
1063:
1064: # close Progress Line
1065: sub Close_PrgWin {
1.14 albertel 1066: my ($r,$prog_state)=@_;
1.297 www 1067: &Apache::loncommon::LCprogressbarClose($r);
1.48 albertel 1068: undef(%$prog_state);
1069: }
1070:
1.34 www 1071: # ------------------------------------------------------- Puts directory header
1072:
1073: sub crumbs {
1.252 bisitz 1074: my ($uri,$target,$prefix,$form,$skiplast)=@_;
1.303 ! www 1075: # You cannot crumbnify uploaded or adm resources
! 1076: if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Group Content)'); }
1.100 raeburn 1077: if ($target) {
1078: $target = ' target="'.
1079: &Apache::loncommon::escape_single($target).'"';
1080: }
1.252 bisitz 1081: my $output='<span class="LC_filename">';
1082: $output.=$prefix.'/';
1.249 raeburn 1083: if (($env{'user.adv'}) || ($env{'user.author'})) {
1.252 bisitz 1084: my $path=$prefix.'/';
1085: foreach my $dir (split('/',$uri)) {
1.99 matthew 1086: if (! $dir) { next; }
1087: $path .= $dir;
1.252 bisitz 1088: if ($path eq $uri) {
1089: if ($skiplast) {
1090: $output.=$dir;
1.132 www 1091: last;
1.252 bisitz 1092: }
1093: } else {
1094: $path.='/';
1095: }
1.157 albertel 1096: my $href_path = &HTML::Entities::encode($path,'<>&"');
1.252 bisitz 1097: &Apache::loncommon::inhibit_menu_check(\$href_path);
1098: if ($form) {
1099: my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
1100: $output.=qq{<a href="$href"$target>$dir</a>/};
1101: } else {
1102: $output.=qq{<a href="$href_path"$target>$dir</a>/};
1103: }
1104: }
1.35 www 1105: } else {
1.252 bisitz 1106: foreach my $dir (split('/',$uri)) {
1.149 albertel 1107: if (! $dir) { next; }
1.252 bisitz 1108: $output.=$dir.'/';
1109: }
1.34 www 1110: }
1.149 albertel 1111: if ($uri !~ m|/$|) { $output=~s|/$||; }
1.252 bisitz 1112: $output.='</span>';
1113:
1114: return $output;
1.34 www 1115: }
1116:
1.85 www 1117: # --------------------- A function that generates a window for the spellchecker
1118:
1119: sub spellheader {
1.123 albertel 1120: my $start_page=
1121: &Apache::loncommon::start_page('Speller Suggestions',undef,
1.140 albertel 1122: {'only_body' => 1,
1123: 'js_ready' => 1,
1124: 'bgcolor' => '#DDDDDD',
1125: 'add_entries' => {
1126: 'onload' =>
1127: 'document.forms.spellcheckform.submit()',
1128: }
1129: });
1.123 albertel 1130: my $end_page=
1131: &Apache::loncommon::end_page({'js_ready' => 1});
1132:
1.105 www 1133: my $nothing=&javascript_nothing();
1.85 www 1134: return (<<ENDCHECK);
1135: <script type="text/javascript">
1.218 bisitz 1136: // <![CDATA[
1.92 albertel 1137: //<!-- BEGIN LON-CAPA Internal
1.85 www 1138: var checkwin;
1139:
1.140 albertel 1140: function spellcheckerwindow(string) {
1141: var esc_string = string.replace(/\"/g,'"');
1.105 www 1142: checkwin=window.open($nothing,'spellcheckwin','height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.154 albertel 1143: 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 1144: checkwin.document.close();
1145: }
1.92 albertel 1146: // END LON-CAPA Internal -->
1.218 bisitz 1147: // ]]>
1.85 www 1148: </script>
1149: ENDCHECK
1150: }
1151:
1152: # ---------------------------------- Generate link to spell checker for a field
1153:
1154: sub spelllink {
1155: my ($form,$field)=@_;
1156: my $linktext=&mt('Check Spelling');
1157: return (<<ENDLINK);
1.140 albertel 1158: <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 1159: ENDLINK
1160: }
1161:
1.281 raeburn 1162: # ------------------------------------------------- Output headers for CKEditor
1.124 albertel 1163:
1.52 www 1164: sub htmlareaheaders {
1.255 faziophi 1165: my $s="";
1.260 faziophi 1166: if (&htmlareabrowser()) {
1.255 faziophi 1167: $s.=(<<ENDEDITOR);
1168: <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
1169: ENDEDITOR
1170: }
1171: $s.=(<<ENDJQUERY);
1.294 raeburn 1172: <script type="text/javascript" src="/adm/jQuery/js/jquery-1.6.2.min.js"></script>
1173: <script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.8.16.custom.min.js"></script>
1174: <link rel="stylesheet" type="text/css" href="/adm/jQuery/css/smoothness/jquery-ui-1.8.16.custom.css" />
1.301 foxr 1175: <script type="text/javascript" src="/adm/jpicker/js/jpicker-1.1.6.min.js" >
1176: </script>
1177: <link rel="stylesheet" type="text/css" href="/adm/jpicker/css/jPicker-1.1.6.min.css" />
1.255 faziophi 1178: ENDJQUERY
1179: return $s;
1.52 www 1180: }
1181:
1.76 www 1182: # ----------------------------------------------------------------- Preferences
1183:
1.167 albertel 1184: # ------------------------------------------------- lang to use in html editor
1185: sub htmlarea_lang {
1186: my $lang='en';
1187: if (&mt('htmlarea_lang') ne 'htmlarea_lang') {
1188: $lang=&mt('htmlarea_lang');
1189: }
1190: return $lang;
1191: }
1192:
1.72 www 1193: # ----------------------------------------- Script to activate only some fields
1194:
1195: sub htmlareaselectactive {
1.281 raeburn 1196: my ($args) = @_;
1.76 www 1197: unless (&htmlareabrowser()) { return ''; }
1.262 raeburn 1198: my $output='<script type="text/javascript" defer="defer">'."\n"
1.230 bisitz 1199: .'// <![CDATA['."\n";
1.167 albertel 1200: my $lang = &htmlarea_lang();
1.281 raeburn 1201: my $fullpage = 'false';
1.282 raeburn 1202: my ($dragmath_prefix,$dragmath_helpicon,$dragmath_whitespace);
1.281 raeburn 1203: if (ref($args) eq 'HASH') {
1204: if (exists($args->{'lang'})) {
1205: if ($args->{'lang'} ne '') {
1206: $lang = $args->{'lang'};
1207: }
1208: }
1209: if (exists($args->{'fullpage'})) {
1210: if ($args->{'fullpage'} eq 'true') {
1211: $fullpage = $args->{'fullpage'};
1212: }
1213: }
1214: if (exists($args->{'dragmath'})) {
1215: if ($args->{'dragmath'} ne '') {
1216: $dragmath_prefix = $args->{'dragmath'};
1.282 raeburn 1217: $dragmath_helpicon=&Apache::loncommon::lonhttpdurl("/adm/help/help.png");
1218: $dragmath_whitespace=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/transparent1x1.gif");
1.281 raeburn 1219: }
1220: }
1221: }
1.255 faziophi 1222: $output.='
1223:
1224: function containsBlockHtml(id) {
1.281 raeburn 1225: 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 1226: return (re >= 0);
1227: }
1228:
1229: function startRichEditor(id) {
1230: CKEDITOR.replace(id,
1231: {
1.281 raeburn 1232: customConfig: "/ckeditor/loncapaconfig.js",
1233: language : "'.$lang.'",
1234: fullPage : '.$fullpage.',
1.255 faziophi 1235: }
1236: );
1237: }
1238:
1239: function destroyRichEditor(id) {
1240: CKEDITOR.instances[id].destroy();
1.72 www 1241: }
1.255 faziophi 1242:
1243: function editorHandler(event) {
1244: var rawid = $(this).attr("id");
1.281 raeburn 1245: var id = new RegExp("LC_rt_(.*)").exec(rawid)[1];
1.255 faziophi 1246: event.preventDefault();
1.281 raeburn 1247: var rt_enabled = $(this).hasClass("LC_enable_rt");
1248: if (rt_enabled) {
1.255 faziophi 1249: startRichEditor(id);
1250: $("#LC_rt_"+id).html("<b>« Plain text</b>");
1251: $("#LC_rt_"+id).attr("title", "Disable rich text formatting and edit in plain text");
1252: $("#LC_rt_"+id).addClass("LC_disable_rt");
1253: $("#LC_rt_"+id).removeClass("LC_enable_rt");
1254: } else {
1255: destroyRichEditor(id);
1256: $("#LC_rt_"+id).html("<b>Rich formatting »</b>");
1257: $("#LC_rt_"+id).attr("title", "Enable rich text formatting (bold, italic, etc.)");
1258: $("#LC_rt_"+id).addClass("LC_enable_rt");
1259: $("#LC_rt_"+id).removeClass("LC_disable_rt");
1.281 raeburn 1260: }';
1261: if ($dragmath_prefix ne '') {
1262: $output .= "\n var visible = '';
1263: if (rt_enabled) {
1264: visible = 'none';
1265: }
1266: editmath_visibility(id,visible);\n";
1267: }
1268: $output .= '
1269: }
1.255 faziophi 1270: $(document).ready(function(){
1271: $(".LC_richAlwaysOn").each(function() {
1272: startRichEditor($(this).attr("id"));
1273: });
1274: $(".LC_richDetectHtml").each(function() {
1275: var id = $(this).attr("id");
1.281 raeburn 1276: var rt_enabled = containsBlockHtml(id);
1277: if(rt_enabled) {
1.255 faziophi 1278: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>« Plain text</b></a></div>");
1279: startRichEditor(id);
1.281 raeburn 1280: $("#LC_rt_"+id).click(editorHandler);
1.255 faziophi 1281: }
1282: else {
1283: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting »</b></a></div>");
1284: $("#LC_rt_"+id).click(editorHandler);
1.281 raeburn 1285: }';
1286: if ($dragmath_prefix ne '') {
1287: $output .= "\n var visible = '';
1288: if (rt_enabled) {
1289: visible = 'none';
1290: }
1291: editmath_visibility(id,visible);\n";
1292: }
1293: $output .= '
1.255 faziophi 1294: });
1295: $(".LC_richDefaultOn").each(function() {
1296: var id = $(this).attr("id");
1297: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>« Plain text</b></a></div>");
1298: startRichEditor(id);
1299: $("#LC_rt_"+id).click(editorHandler);
1300: });
1301: $(".LC_richDefaultOff").each(function() {
1302: var id = $(this).attr("id");
1303: $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting »</b></a></div>");
1.281 raeburn 1304: $("#LC_rt_"+id).click(editorHandler);
1.255 faziophi 1305: });
1.301 foxr 1306: $.fn.jPicker.defaults.images.clientPath="/adm/jpicker/images/";
1307: $(".colorchooser").jPicker();
1308:
1.302 foxr 1309: });
1.281 raeburn 1310: ';
1311: if ($dragmath_prefix ne '') {
1312: $output .= '
1313:
1314: function editmath_visibility(id,value) {
1315:
1316: if ((id == "") || (id == null)) {
1317: return;
1318: }
1319: var mathid = "'.$dragmath_prefix.'_"+id;
1320: mathele = document.getElementById(mathid);
1321: if (mathele == null) {
1322: return;
1323: }
1324: mathele.style.display = value;
1.282 raeburn 1325: var mathhelpicon = "'.$dragmath_prefix.'helpicon'.'_"+id;
1326: mathhelpiconele = document.getElementById(mathhelpicon);
1327: if (mathhelpiconele == null) {
1328: return;
1329: }
1330: if (value == "none") {
1331: mathhelpiconele.src = "'.$dragmath_whitespace.'";
1332: } else {
1333: mathhelpiconele.src = "'.$dragmath_helpicon.'";
1334: }
1.281 raeburn 1335: }
1336: ';
1337:
1338: }
1.218 bisitz 1339: $output.="\nwindow.status='Activated Editfields';\n"
1.230 bisitz 1340: .'// ]]>'."\n"
1.281 raeburn 1341: .'</script>';
1.72 www 1342: return $output;
1343: }
1344:
1.61 www 1345: # --------------------------------------------------------------------- Blocked
1346:
1347: sub htmlareablocked {
1.104 albertel 1348: unless ($env{'environment.wysiwygeditor'} eq 'on') { return 1; }
1.71 www 1349: return 0;
1.52 www 1350: }
1351:
1352: # ---------------------------------------- Browser capable of running HTMLArea?
1353:
1354: sub htmlareabrowser {
1355: return 1;
1356: }
1.53 matthew 1357:
1.287 www 1358: #
1359: # Should the "return to content" link be shown?
1360: #
1361:
1362: sub show_return_link {
1.289 www 1363:
1364: unless ($env{'request.course.id'}) { return 0; }
1365: if ($env{'request.noversionuri'}=~m{^/priv/} ||
1366: $env{'request.uri'}=~m{^/~}) { return 1; }
1367:
1.287 www 1368: if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
1369: || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
1370:
1371: return if ($env{'form.register'});
1372: }
1373: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
1374: $env{'request.symb'} eq '')
1375: ||
1376: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
1377: ||
1378: (($env{'request.noversionuri'}=~/^\/adm\//) &&
1379: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
1380: ($env{'request.noversionuri'}!~
1381: m{^/adm/.*/(smppg|bulletinboard)($|\?)})
1382: ));
1383: }
1384:
1385:
1.53 matthew 1386: ############################################################
1387: ############################################################
1388:
1389: =pod
1390:
1391: =item breadcrumbs
1392:
1393: Compiles the previously registered breadcrumbs into an series of links.
1394: Additionally supports a 'component', which will be displayed on the
1.223 droeschl 1395: right side of the breadcrumbs enclosing div (without a link).
1.53 matthew 1396: A link to help for the component will be included if one is specified.
1397:
1398: All inputs can be undef without problems.
1399:
1.223 droeschl 1400: Inputs: $component (the text on the right side of the breadcrumbs trail),
1.53 matthew 1401: $component_help
1.63 albertel 1402: $menulink (boolean, controls whether to include a link to /adm/menu)
1.138 albertel 1403: $helplink (if 'nohelp' don't include the orange help link)
1404: $css_class (optional name for the class to apply to the table for CSS)
1.197 raeburn 1405: $no_mt (optional flag, 1 if &mt() is _not_ to be applied to $component
1406: when including the text on the right.
1.53 matthew 1407: Returns a string containing breadcrumbs for the current page.
1408:
1409: =item clear_breadcrumbs
1410:
1411: Clears the previously stored breadcrumbs.
1412:
1413: =item add_breadcrumb
1414:
1415: Pushes a breadcrumb on the stack of crumbs.
1416:
1417: input: $breadcrumb, a hash reference. The keys 'href','title', and 'text'
1418: are required. If present the keys 'faq' and 'bug' will be used to provide
1.156 albertel 1419: links to the FAQ and bug sites. If the key 'no_mt' is present the 'title'
1420: and 'text' values won't be sent through &mt()
1.53 matthew 1421:
1422: returns: nothing
1423:
1424: =cut
1425:
1426: ############################################################
1427: ############################################################
1428: {
1429: my @Crumbs;
1.242 droeschl 1430: my %tools = ();
1.57 matthew 1431:
1.53 matthew 1432: sub breadcrumbs {
1.216 bisitz 1433: my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, $CourseBreadcrumbs) = @_;
1.53 matthew 1434: #
1.215 droeschl 1435: $css_class ||= 'LC_breadcrumbs';
1.205 amueller 1436:
1.57 matthew 1437: # Make the faq and bug data cascade
1.223 droeschl 1438: my $faq = '';
1439: my $bug = '';
1440: my $help = '';
1.215 droeschl 1441: # Crumb Symbol
1.223 droeschl 1442: my $crumbsymbol = '»';
1.60 www 1443: # The last breadcrumb does not have a link, so handle it separately.
1.53 matthew 1444: my $last = pop(@Crumbs);
1.57 matthew 1445: #
1.70 matthew 1446: # The first one should be the course or a menu link
1.215 droeschl 1447: if (!defined($menulink)) { $menulink=1; }
1.70 matthew 1448: if ($menulink) {
1449: my $description = 'Menu';
1.172 raeburn 1450: my $no_mt_descr = 0;
1.269 raeburn 1451: if ((exists($env{'request.course.id'})) &&
1452: ($env{'request.course.id'} ne '') &&
1453: ($env{'course.'.$env{'request.course.id'}.'.description'} ne '')) {
1.70 matthew 1454: $description =
1.104 albertel 1455: $env{'course.'.$env{'request.course.id'}.'.description'};
1.172 raeburn 1456: $no_mt_descr = 1;
1.70 matthew 1457: }
1.215 droeschl 1458: $menulink = { href =>'/adm/menu',
1459: title =>'Go to main menu',
1460: target =>'_top',
1461: text =>$description,
1462: no_mt =>$no_mt_descr, };
1463: if($last) {
1464: #$last set, so we have some crumbs
1465: unshift(@Crumbs,$menulink);
1466: } else {
1467: #only menulink crumb present
1468: $last = $menulink;
1469: }
1.53 matthew 1470: }
1.287 www 1471: my $links;
1472: if ((&show_return_link) && (!$CourseBreadcrumbs)) {
1.299 raeburn 1473: my $alttext = &mt('Go Back');
1.298 raeburn 1474: $links=&htmltag( 'a',"<img src='/res/adm/pages/reload.png' border='0' style='vertical-align:middle;' alt='$alttext' />",
1.287 www 1475: { href => '/adm/flip?postdata=return:',
1476: title => &mt("Back to most recent content resource") });
1.299 raeburn 1477: $links=&htmltag('li',$links);
1.287 www 1478: }
1479: $links.= join "",
1.261 droeschl 1480: map {
1481: $faq = $_->{'faq'} if (exists($_->{'faq'}));
1482: $bug = $_->{'bug'} if (exists($_->{'bug'}));
1483: $help = $_->{'help'} if (exists($_->{'help'}));
1484:
1.287 www 1485: my $result = $_->{no_mt} ? $_->{text} : &mt($_->{text});
1.261 droeschl 1486:
1487: if ($_->{href}){
1.287 www 1488: $result = &htmltag( 'a', $result,
1.261 droeschl 1489: { href => $_->{href},
1.287 www 1490: title => $_->{no_mt} ? $_->{title} : &mt($_->{title}),
1.261 droeschl 1491: target => $_->{target}, });
1492: }
1493:
1.287 www 1494: $result = &htmltag( 'li', "$result $crumbsymbol");
1.261 droeschl 1495: } @Crumbs;
1.223 droeschl 1496:
1497: #should the last Element be translated?
1.261 droeschl 1498:
1499: my $lasttext = $last->{'no_mt'} ? $last->{'text'}
1500: : mt( $last->{'text'} );
1501:
1.274 droeschl 1502: # last breadcrumb is the first order heading of a page
1503: # for course breadcrumbs it's just bold
1.287 www 1504: $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
1.274 droeschl 1505: $lasttext), {title => $lasttext});
1.223 droeschl 1506:
1.54 matthew 1507: my $icons = '';
1.223 droeschl 1508: $faq = $last->{'faq'} if (exists($last->{'faq'}));
1509: $bug = $last->{'bug'} if (exists($last->{'bug'}));
1.106 www 1510: $help = $last->{'help'} if (exists($last->{'help'}));
1511: $component_help=($component_help?$component_help:$help);
1.145 albertel 1512: # if ($faq ne '') {
1513: # $icons .= &Apache::loncommon::help_open_faq($faq);
1514: # }
1.79 raeburn 1515: # if ($bug ne '') {
1516: # $icons .= &Apache::loncommon::help_open_bug($bug);
1517: # }
1.223 droeschl 1518: if ($faq ne '' || $component_help ne '' || $bug ne '') {
1519: $icons .= &Apache::loncommon::help_open_menu($component,
1520: $component_help,
1521: $faq,$bug);
1522: }
1.54 matthew 1523: #
1.205 amueller 1524:
1525:
1.223 droeschl 1526: unless ($CourseBreadcrumbs) {
1.287 www 1527: $links = &htmltag('ol', $links, { id => "LC_MenuBreadcrumbs" });
1.223 droeschl 1528: } else {
1.287 www 1529: $links = &htmltag('ul', $links, { class => "LC_CourseBreadcrumbs" });
1.53 matthew 1530: }
1.223 droeschl 1531:
1532: if ($component) {
1.287 www 1533: $links = &htmltag('span',
1.223 droeschl 1534: ( $no_mt ? $component : mt($component) ).
1535: ( $icons ? $icons : '' ),
1536: { class => 'LC_breadcrumbs_component' } )
1537: .$links;
1538: }
1539:
1.287 www 1540: &render_tools(\$links);
1541: $links = &htmltag('div', $links,
1.225 bisitz 1542: { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;
1.287 www 1543: &render_advtools(\$links);
1.223 droeschl 1544:
1.53 matthew 1545: # Return the @Crumbs stack to what we started with
1546: push(@Crumbs,$last);
1547: shift(@Crumbs);
1.223 droeschl 1548: # Return the breadcrumb's line
1549: return "$links";
1.53 matthew 1550: }
1551:
1552: sub clear_breadcrumbs {
1553: undef(@Crumbs);
1.242 droeschl 1554: undef(%tools);
1.53 matthew 1555: }
1556:
1557: sub add_breadcrumb {
1.232 raeburn 1558: push(@Crumbs,@_);
1.53 matthew 1559: }
1.242 droeschl 1560:
1.261 droeschl 1561: =item add_breadcrumb_tool($category, $html)
1562:
1563: Adds $html to $category of the breadcrumb toolbar container.
1564:
1565: $html is usually a link to a page that invokes a function on the currently
1566: displayed data (e.g. print when viewing a problem)
1567:
1568: Currently there are 3 possible values for $category:
1569:
1570: =over
1571:
1572: =item navigation
1573: left of breadcrumbs line
1574:
1575: =item tools
1576: right of breadcrumbs line
1577:
1578: =item advtools
1579: advanced tools shown in a separate box below breadcrumbs line
1580:
1581: =back
1582:
1583: returns: nothing
1584:
1585: =cut
1.242 droeschl 1586:
1587: sub add_breadcrumb_tool {
1.261 droeschl 1588: my ($category, @html) = @_;
1589: return unless @html;
1.285 raeburn 1590: if (!keys(%tools)) {
1.261 droeschl 1591: %tools = ( navigation => [], tools => [], advtools => []);
1.242 droeschl 1592: }
1.261 droeschl 1593:
1594: #this cleans data received from lonmenu::innerregister
1595: @html = grep {defined $_ && $_ ne ''} @html;
1596: for (@html) {
1597: s/align="(right|left)"//;
1.288 www 1598: # s/<span.*?\/span>// if $category ne 'advtools';
1.261 droeschl 1599: }
1600:
1601: push @{$tools{$category}}, @html;
1.242 droeschl 1602: }
1603:
1.261 droeschl 1604: =item clear_breadcrumb_tools()
1605:
1606: Clears the breadcrumb toolbar container.
1607:
1608: returns: nothing
1609:
1610: =cut
1611:
1.245 droeschl 1612: sub clear_breadcrumb_tools {
1613: undef(%tools);
1614: }
1615:
1.261 droeschl 1616: =item render_tools(\$breadcrumbs)
1617:
1618: Creates html for breadcrumb tools (categories navigation and tools) and inserts
1619: \$breadcrumbs at the correct position.
1620:
1621: input: \$breadcrumbs - a reference to the string containing prepared
1622: breadcrumbs.
1623:
1624: returns: nothing
1625: =cut
1626:
1627: #TODO might split this in separate functions for each category
1628: sub render_tools {
1629: my ($breadcrumbs) = @_;
1.285 raeburn 1630: return unless (keys(%tools));
1.261 droeschl 1631:
1632: my $navigation = list_from_array($tools{navigation},
1633: { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
1634: my $tools = list_from_array($tools{tools},
1635: { listattr => { class=>"LC_breadcrumb_tools_tools" } });
1636: $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs],
1637: { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });
1638: }
1639:
1640: =item render_advtools(\$breadcrumbs)
1641:
1642: Creates html for advanced tools (category advtools) and inserts \$breadcrumbs
1643: at the correct position.
1644:
1645: input: \$breadcrumbs - a reference to the string containing prepared
1646: breadcrumbs (after render_tools call).
1647:
1648: returns: nothing
1649: =cut
1650:
1651: sub render_advtools {
1652: my ($breadcrumbs) = @_;
1653: return unless (defined $tools{'advtools'})
1654: and (scalar(@{$tools{'advtools'}}) > 0);
1655:
1656: $$breadcrumbs .= Apache::loncommon::head_subbox(
1657: funclist_from_array($tools{'advtools'}) );
1.242 droeschl 1658: }
1.53 matthew 1659:
1.57 matthew 1660: } # End of scope for @Crumbs
1.53 matthew 1661:
1662: ############################################################
1663: ############################################################
1664:
1.112 raeburn 1665: # Nested table routines.
1666: #
1667: # Routines to display form items in a multi-row table with 2 columns.
1668: # Uses nested tables to divide form elements into segments.
1669: # For examples of use see loncom/interface/lonnotify.pm
1670: #
1671: # Can be used in following order: ...
1672: # &start_pick_box()
1673: # row1
1674: # row2
1675: # row3 ... etc.
1.173 raeburn 1676: # &submit_row()
1.161 raeburn 1677: # &end_pick_box()
1.112 raeburn 1678: #
1679: # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
1680: # &status_select_row and &email_default_row
1681: #
1682: # Can also be used in following order:
1683: #
1684: # &start_pick_box()
1685: # &row_title()
1686: # &row_closure()
1687: # &row_title()
1688: # &row_closure() ... etc.
1689: # &submit_row()
1690: # &end_pick_box()
1691: #
1692: # In general a &submit_row() call should proceed the call to &end_pick_box(),
1693: # as this routine adds a button for form submission.
1.113 raeburn 1694: # &submit_row() does not require a &row_closure after it.
1.112 raeburn 1695: #
1696: # &start_pick_box() creates a bounding table with 1-pixel wide black border.
1697: # rows should be placed between calls to &start_pick_box() and &end_pick_box.
1698: #
1699: # &row_title() adds a title in the left column for each segment.
1700: # &row_closure() closes a row with a 1-pixel wide black line.
1701: #
1702: # &role_select_row() provides a select box from which to choose 1 or more roles
1703: # &course_select_row provides ways of picking groups of courses
1704: # radio buttons: all, by category or by picking from a course picker pop-up
1705: # note: by category option is only displayed if a domain has implemented
1706: # selection by year, semester, department, number etc.
1707: #
1708: # &status_select_row() provides a select box from which to choose 1 or more
1709: # access types (current access, prior access, and future access)
1710: #
1711: # &email_default_row() provides text boxes for default e-mail suffixes for
1712: # different authentication types in a domain.
1713: #
1714: # &row_title() and &row_closure() are called internally by the &*_select_row
1715: # routines, but can also be called directly to start and end rows which have
1716: # needs that are not accommodated by the *_select_row() routines.
1717:
1.193 bisitz 1718: { # Start: row_count block for pick_box
1719: my @row_count;
1720:
1.112 raeburn 1721: sub start_pick_box {
1.142 albertel 1722: my ($css_class) = @_;
1723: if (defined($css_class)) {
1724: $css_class = 'class="'.$css_class.'"';
1725: } else {
1726: $css_class= 'class="LC_pick_box"';
1727: }
1.193 bisitz 1728: unshift(@row_count,0);
1.112 raeburn 1729: my $output = <<"END";
1.142 albertel 1730: <table $css_class>
1.112 raeburn 1731: END
1732: return $output;
1733: }
1734:
1735: sub end_pick_box {
1.193 bisitz 1736: shift(@row_count);
1.112 raeburn 1737: my $output = <<"END";
1738: </table>
1739: END
1740: return $output;
1741: }
1742:
1.181 bisitz 1743: sub row_headline {
1744: my $output = <<"END";
1745: <tr><td colspan="2">
1746: END
1747: return $output;
1748: }
1749:
1.112 raeburn 1750: sub row_title {
1.243 amueller 1751: my ($title,$css_title_class,$css_value_class, $css_value_furtherAttributes) = @_;
1.193 bisitz 1752: $row_count[0]++;
1753: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.142 albertel 1754: $css_title_class ||= 'LC_pick_box_title';
1755: $css_title_class = 'class="'.$css_title_class.'"';
1756:
1757: $css_value_class ||= 'LC_pick_box_value';
1758:
1.173 raeburn 1759: if ($title ne '') {
1760: $title .= ':';
1761: }
1.112 raeburn 1762: my $output = <<"ENDONE";
1.243 amueller 1763: <tr class="LC_pick_box_row" $css_value_furtherAttributes>
1.142 albertel 1764: <td $css_title_class>
1.173 raeburn 1765: $title
1.112 raeburn 1766: </td>
1.193 bisitz 1767: <td class="$css_value_class $css_class">
1.112 raeburn 1768: ENDONE
1769: return $output;
1770: }
1771:
1772: sub row_closure {
1.143 albertel 1773: my ($no_separator) =@_;
1.113 raeburn 1774: my $output = <<"ENDTWO";
1.112 raeburn 1775: </td>
1776: </tr>
1.143 albertel 1777: ENDTWO
1778: if (!$no_separator) {
1779: $output .= <<"ENDTWO";
1.112 raeburn 1780: <tr>
1.143 albertel 1781: <td colspan="2" class="LC_pick_box_separator">
1.112 raeburn 1782: </td>
1783: </tr>
1784: ENDTWO
1.143 albertel 1785: }
1.112 raeburn 1786: return $output;
1787: }
1788:
1.193 bisitz 1789: } # End: row_count block for pick_box
1790:
1.112 raeburn 1791: sub role_select_row {
1.147 raeburn 1792: my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
1.236 raeburn 1793: my $crstype = 'Course';
1794: if ($cdom ne '' && $cnum ne '') {
1795: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1796: }
1.116 raeburn 1797: my $output;
1798: if (defined($title)) {
1.142 albertel 1799: $output = &row_title($title,$css_class);
1.116 raeburn 1800: }
1.142 albertel 1801: $output .= qq|
1.198 bisitz 1802: <select name="roles" multiple="multiple">\n|;
1.113 raeburn 1803: foreach my $role (@$roles) {
1.114 raeburn 1804: my $plrole;
1805: if ($role eq 'ow') {
1806: $plrole = &mt('Course Owner');
1.147 raeburn 1807: } elsif ($role eq 'cr') {
1808: if ($show_separate_custom) {
1809: if ($cdom ne '' && $cnum ne '') {
1810: my %course_customroles = &course_custom_roles($cdom,$cnum);
1811: foreach my $crrole (sort(keys(%course_customroles))) {
1812: my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|);
1813: $output .= ' <option value="'.$crrole.'">'.$plcrrole.
1814: '</option>';
1815: }
1816: }
1817: } else {
1818: $plrole = &mt('Custom Role');
1819: }
1.114 raeburn 1820: } else {
1.236 raeburn 1821: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.114 raeburn 1822: }
1.147 raeburn 1823: if (($role ne 'cr') || (!$show_separate_custom)) {
1824: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
1825: }
1.112 raeburn 1826: }
1.142 albertel 1827: $output .= qq| </select>\n|;
1.116 raeburn 1828: if (defined($title)) {
1829: $output .= &row_closure();
1830: }
1.112 raeburn 1831: return $output;
1832: }
1833:
1834: sub course_select_row {
1.142 albertel 1835: my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles,
1.280 raeburn 1836: $css_class,$crstype,$standardnames) = @_;
1.142 albertel 1837: my $output = &row_title($title,$css_class);
1.280 raeburn 1838: $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames);
1.169 raeburn 1839: $output .= &row_closure();
1840: return $output;
1841: }
1842:
1843: sub course_selection {
1.280 raeburn 1844: my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames) = @_;
1.169 raeburn 1845: my $output = qq|
1.142 albertel 1846: <script type="text/javascript">
1.218 bisitz 1847: // <![CDATA[
1.112 raeburn 1848: function coursePick (formname) {
1849: for (var i=0; i<formname.coursepick.length; i++) {
1.114 raeburn 1850: if (formname.coursepick[i].value == 'category') {
1851: courseSet('');
1852: }
1.112 raeburn 1853: if (!formname.coursepick[i].checked) {
1854: if (formname.coursepick[i].value == 'specific') {
1855: formname.coursetotal.value = 0;
1856: formname.courselist = '';
1857: }
1858: }
1859: }
1860: }
1.114 raeburn 1861: function setPick (formname) {
1862: for (var i=0; i<formname.coursepick.length; i++) {
1863: if (formname.coursepick[i].value == 'category') {
1864: formname.coursepick[i].checked = true;
1865: }
1866: formname.coursetotal.value = 0;
1867: formname.courselist = '';
1868: }
1869: }
1.218 bisitz 1870: // ]]>
1.112 raeburn 1871: </script>
1872: |;
1.237 raeburn 1873:
1874: my ($allcrs,$pickspec);
1875: if ($crstype eq 'Community') {
1876: $allcrs = &mt('All communities');
1877: $pickspec = &mt('Pick specific communities:');
1878: } else {
1879: $allcrs = &mt('All courses');
1880: $pickspec = &mt('Pick specific course(s):');
1881: }
1882:
1.112 raeburn 1883: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.237 raeburn 1884: ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).'</b>';
1885: $output .= '<input type="radio" name="coursepick" value="all" onclick="coursePick(this.form)" />'.$allcrs.'<br />';
1.112 raeburn 1886: if ($totcodes > 0) {
1887: my $numtitles = @$codetitles;
1888: if ($numtitles > 0) {
1.129 raeburn 1889: $output .= '<input type="radio" name="coursepick" value="category" onclick="coursePick(this.form);alert('."'".&mt('Choose categories, from left to right')."'".')" />'.&mt('Pick courses by category:').' <br />';
1.112 raeburn 1890: $output .= '<table><tr><td>'.$$codetitles[0].'<br />'."\n".
1.280 raeburn 1891: '<select name="'.$standardnames->[0].
1.114 raeburn 1892: '" onChange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
1.112 raeburn 1893: ' <option value="-1" />Select'."\n";
1894: my @items = ();
1895: my @longitems = ();
1896: if ($$idlist{$$codetitles[0]} =~ /","/) {
1.113 raeburn 1897: @items = split(/","/,$$idlist{$$codetitles[0]});
1.112 raeburn 1898: } else {
1899: $items[0] = $$idlist{$$codetitles[0]};
1900: }
1901: if (defined($$idlist_titles{$$codetitles[0]})) {
1902: if ($$idlist_titles{$$codetitles[0]} =~ /","/) {
1.113 raeburn 1903: @longitems = split(/","/,$$idlist_titles{$$codetitles[0]});
1.112 raeburn 1904: } else {
1905: $longitems[0] = $$idlist_titles{$$codetitles[0]};
1906: }
1907: for (my $i=0; $i<@longitems; $i++) {
1908: if ($longitems[$i] eq '') {
1909: $longitems[$i] = $items[$i];
1910: }
1911: }
1912: } else {
1913: @longitems = @items;
1914: }
1915: for (my $i=0; $i<@items; $i++) {
1916: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
1917: }
1918: $output .= '</select></td>';
1919: for (my $i=1; $i<$numtitles; $i++) {
1920: $output .= '<td>'.$$codetitles[$i].'<br />'."\n".
1.280 raeburn 1921: '<select name="'.$standardnames->[$i].
1.112 raeburn 1922: '" onChange="courseSet('."'$$codetitles[$i]'".')">'."\n".
1923: '<option value="-1"><-Pick '.$$codetitles[$i-1].'</option>'."\n".
1924: '</select>'."\n".
1925: '</td>';
1926: }
1927: $output .= '</tr></table><br />';
1928: }
1929: }
1.238 raeburn 1930: $output .= '<input type="radio" name="coursepick" value="specific" onclick="coursePick(this.form);opencrsbrowser('."'".$formname."','dccourse','dcdomain','coursedesc','','1','$crstype'".')" />'.$pickspec.' '.$courseform.' <input type="text" value="0" size="4" name="coursetotal" /><input type="hidden" name="courselist" value="" />selected.<br />'."\n";
1.112 raeburn 1931: return $output;
1932: }
1933:
1934: sub status_select_row {
1.142 albertel 1935: my ($types,$title,$css_class) = @_;
1.117 raeburn 1936: my $output;
1937: if (defined($title)) {
1.142 albertel 1938: $output = &row_title($title,$css_class,'LC_pick_box_select');
1.117 raeburn 1939: }
1.142 albertel 1940: $output .= qq|
1.198 bisitz 1941: <select name="types" multiple="multiple">\n|;
1.113 raeburn 1942: foreach my $status_type (sort(keys(%{$types}))) {
1.112 raeburn 1943: $output .= ' <option value="'.$status_type.'">'.$$types{$status_type}.'</option>';
1944: }
1.142 albertel 1945: $output .= qq| </select>\n|;
1.117 raeburn 1946: if (defined($title)) {
1947: $output .= &row_closure();
1948: }
1.112 raeburn 1949: return $output;
1950: }
1951:
1952: sub email_default_row {
1.142 albertel 1953: my ($authtypes,$title,$descrip,$css_class) = @_;
1954: my $output = &row_title($title,$css_class);
1955: $output .= $descrip.
1956: &Apache::loncommon::start_data_table().
1957: &Apache::loncommon::start_data_table_header_row().
1958: '<th>'.&mt('Authentication Method').'</th>'.
1959: '<th align="right">'.&mt('Username -> e-mail conversion').'</th>'."\n".
1960: &Apache::loncommon::end_data_table_header_row();
1.112 raeburn 1961: my $rownum = 0;
1.113 raeburn 1962: foreach my $auth (sort(keys(%{$authtypes}))) {
1.112 raeburn 1963: my ($userentry,$size);
1964: if ($auth =~ /^krb/) {
1965: $userentry = '';
1966: $size = 25;
1967: } else {
1968: $userentry = 'username@';
1969: $size = 15;
1970: }
1.142 albertel 1971: $output .= &Apache::loncommon::start_data_table_row().
1972: '<td> '.$$authtypes{$auth}.'</td>'.
1973: '<td align="right">'.$userentry.
1974: '<input type="text" name="'.$auth.'" size="'.$size.'" /></td>'.
1975: &Apache::loncommon::end_data_table_row();
1.112 raeburn 1976: }
1.142 albertel 1977: $output .= &Apache::loncommon::end_data_table();
1.112 raeburn 1978: $output .= &row_closure();
1979: return $output;
1980: }
1981:
1982:
1983: sub submit_row {
1.142 albertel 1984: my ($title,$cmd,$submit_text,$css_class) = @_;
1985: my $output = &row_title($title,$css_class,'LC_pick_box_submit');
1.112 raeburn 1986: $output .= qq|
1987: <br />
1988: <input type="hidden" name="command" value="$cmd" />
1989: <input type="submit" value="$submit_text"/>
1990: <br /><br />
1.142 albertel 1991: \n|;
1.112 raeburn 1992: return $output;
1993: }
1.1 stredwic 1994:
1.147 raeburn 1995: sub course_custom_roles {
1996: my ($cdom,$cnum) = @_;
1997: my %returnhash=();
1998: my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
1999: foreach my $person (sort(keys(%coursepersonnel))) {
2000: my ($role) = ($person =~ /^([^:]+):/);
2001: my ($end,$start) = split(/:/,$coursepersonnel{$person});
2002: if ($end == -1 && $start == -1) {
2003: next;
2004: }
2005: if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) {
2006: $returnhash{$role} ++;
2007: }
2008: }
2009: return %returnhash;
2010: }
2011:
2012:
1.270 www 2013: sub resource_info_box {
1.300 raeburn 2014: my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp)=@_;
1.270 www 2015: my $return='';
1.300 raeburn 2016: if ($stuvcurrent ne '') {
2017: $return = '<div class="LC_left_float">';
2018: }
1.270 www 2019: if ($symb) {
1.300 raeburn 2020: $return.=&Apache::loncommon::start_data_table();
1.271 www 2021: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symb);
2022: my $folder=&Apache::lonnet::gettitle($map);
2023: $return.=&Apache::loncommon::start_data_table_row().
1.300 raeburn 2024: '<th align="left">'.&mt('Folder:').'</th><td>'.$folder.'</td>'.
1.271 www 2025: &Apache::loncommon::end_data_table_row();
1.270 www 2026: unless ($onlyfolderflag) {
2027: $return.=&Apache::loncommon::start_data_table_row().
1.300 raeburn 2028: '<th align="left">'.&mt('Resource:').'</th><td>'.&Apache::lonnet::gettitle($symb).'</td>'.
2029: &Apache::loncommon::end_data_table_row();
2030: }
2031: if ($stuvcurrent ne '') {
2032: $return .= &Apache::loncommon::start_data_table_row().
2033: '<th align="left">'.&mt("Student's current version:").'</th><td>'.$stuvcurrent.'</td>'.
2034: &Apache::loncommon::end_data_table_row();
2035: }
2036: if ($stuvdisp ne '') {
2037: $return .= &Apache::loncommon::start_data_table_row().
2038: '<th align="left">'.&mt("Student's version displayed:").'</th><td>'.$stuvdisp.'</td>'.
1.270 www 2039: &Apache::loncommon::end_data_table_row();
2040: }
1.271 www 2041: $return.=&Apache::loncommon::end_data_table();
1.270 www 2042: } else {
2043: $return='<p><span class="LC_error">'.&mt('No context provided.').'</span></p>';
2044: }
1.300 raeburn 2045: if ($stuvcurrent ne '') {
2046: $return .= '</div>';
2047: }
1.270 www 2048: return $return;
2049: }
2050:
1.119 raeburn 2051: ##############################################
2052: ##############################################
1.179 raeburn 2053:
2054: # topic_bar
2055: #
1.248 wenzelju 2056: # Generates a div containing an (optional) number with a white background followed by a
1.240 raeburn 2057: # title with a background color defined in the corresponding CSS: LC_topic_bar
2058: # Inputs:
1.248 wenzelju 2059: # 1. number to display.
2060: # If input for number is empty only the title will be displayed.
1.240 raeburn 2061: # 2. title text to display.
2062: # Outputs - a scalar containing html mark-up for the div.
2063:
1.179 raeburn 2064: sub topic_bar {
1.248 wenzelju 2065: my ($num,$title) = @_;
2066: my $number = '';
2067: if ($num ne '') {
2068: $number = '<span>'.$num.'</span>';
1.239 amueller 2069: }
1.248 wenzelju 2070: return '<div class="LC_topic_bar">'.$number.$title.'</div>';
1.179 raeburn 2071: }
2072:
2073: ##############################################
2074: ##############################################
1.119 raeburn 2075: # echo_form_input
2076: #
2077: # Generates html markup to add form elements from the referrer page
2078: # as hidden form elements (values encoded) in the new page.
2079: #
2080: # Intended to support two types of use
2081: # (a) to allow backing up to earlier pages in a multi-page
2082: # form submission process using a breadcrumb trail.
2083: #
2084: # (b) to allow the current page to be reloaded with form elements
2085: # set on previous page to remain unchanged. An example would
2086: # be where the a page containing a dynamically-built table of data is
2087: # is to be redisplayed, with only the sort order of the data changed.
2088: #
2089: # Inputs:
2090: # 1. Reference to array of form elements in the submitted form on
2091: # the referrer page which are to be excluded from the echoed elements.
2092: #
2093: # 2. Reference to array of regular expressions, which if matched in the
2094: # name of the form element n the referrer page will be omitted from echo.
2095: #
2096: # Outputs: A scalar containing the html markup for the echoed form
2097: # elements (all as hidden elements, with values encoded).
2098:
2099:
2100: sub echo_form_input {
2101: my ($excluded,$regexps) = @_;
2102: my $output = '';
2103: foreach my $key (keys(%env)) {
2104: if ($key =~ /^form\.(.+)$/) {
2105: my $name = $1;
2106: my $match = 0;
1.285 raeburn 2107: if (ref($excluded) eq 'ARRAY') {
2108: next if (grep(/^\Q$name\E$/,@{$excluded}));
2109: }
2110: if (ref($regexps) eq 'ARRAY') {
2111: if (@{$regexps} > 0) {
2112: foreach my $regexp (@{$regexps}) {
2113: if ($name =~ /$regexp/) {
2114: $match = 1;
2115: last;
1.119 raeburn 2116: }
2117: }
2118: }
1.285 raeburn 2119: }
2120: next if ($match);
2121: if (ref($env{$key}) eq 'ARRAY') {
2122: foreach my $value (@{$env{$key}}) {
2123: $value = &HTML::Entities::encode($value,'<>&"');
2124: $output .= '<input type="hidden" name="'.$name.
2125: '" value="'.$value.'" />'."\n";
1.119 raeburn 2126: }
1.285 raeburn 2127: } else {
2128: my $value = &HTML::Entities::encode($env{$key},'<>&"');
2129: $output .= '<input type="hidden" name="'.$name.
2130: '" value="'.$value.'" />'."\n";
1.119 raeburn 2131: }
2132: }
2133: }
2134: return $output;
2135: }
2136:
2137: ##############################################
2138: ##############################################
2139: # set_form_elements
2140: #
2141: # Generates javascript to set form elements to values based on
2142: # corresponding values for the same form elements when the page was
2143: # previously submitted.
2144: #
2145: # Last submission values are read from hidden form elements in referring
2146: # page which have the same name, i.e., generated by &echo_form_input().
2147: #
2148: # Intended to be called by onload event.
2149: #
1.121 raeburn 2150: # Inputs:
2151: # (a) Reference to hash of echoed form elements to be set.
1.119 raeburn 2152: #
2153: # In the hash, keys are the form element names, and the values are the
2154: # element type (selectbox, radio, checkbox or text -for textbox, textarea or
2155: # hidden).
1.121 raeburn 2156: #
2157: # (b) Optional reference to hash of stored elements to be set.
2158: #
2159: # If the page being displayed is a page which permits modification of
2160: # previously stored data, e.g., the first page in a multi-page submission,
2161: # then if stored is supplied, form elements will be set to the last stored
2162: # values. If user supplied values are also available for the same elements
2163: # these will replace the stored values.
2164: #
1.119 raeburn 2165: # Output:
2166: #
2167: # javascript function - set_form_elements() which sets form elements,
2168: # expects an argument: formname - the name of the form according to
2169: # the DOM, e.g., document.compose
2170:
2171: sub set_form_elements {
1.121 raeburn 2172: my ($elements,$stored) = @_;
2173: my %values;
1.119 raeburn 2174: my $output .= 'function setFormElements(courseForm) {
1.121 raeburn 2175: ';
2176: if (defined($stored)) {
2177: foreach my $name (keys(%{$stored})) {
2178: if (exists($$elements{$name})) {
2179: if (ref($$stored{$name}) eq 'ARRAY') {
2180: $values{$name} = $$stored{$name};
2181: } else {
2182: @{$values{$name}} = ($$stored{$name});
2183: }
2184: }
2185: }
2186: }
2187:
1.119 raeburn 2188: foreach my $key (keys(%env)) {
2189: if ($key =~ /^form\.(.+)$/) {
2190: my $name = $1;
2191: if (exists($$elements{$name})) {
1.121 raeburn 2192: @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
2193: }
2194: }
2195: }
2196:
2197: foreach my $name (keys(%values)) {
2198: for (my $i=0; $i<@{$values{$name}}; $i++) {
2199: $values{$name}[$i] = &HTML::Entities::decode($values{$name}[$i],'<>&"');
2200: $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
2201: $values{$name}[$i] =~ s/"/\\"/g;
2202: }
1.234 raeburn 2203: if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) {
1.121 raeburn 2204: my $numvalues = @{$values{$name}};
2205: if ($numvalues > 1) {
2206: my $valuestring = join('","',@{$values{$name}});
2207: $output .= qq|
1.119 raeburn 2208: var textvalues = new Array ("$valuestring");
1.147 raeburn 2209: var total = courseForm.elements['$name'].length;
1.119 raeburn 2210: if (total > $numvalues) {
2211: total = $numvalues;
2212: }
2213: for (var i=0; i<total; i++) {
1.147 raeburn 2214: courseForm.elements['$name']\[i].value = textvalues[i];
1.119 raeburn 2215: }
2216: |;
1.121 raeburn 2217: } else {
2218: $output .= qq|
1.147 raeburn 2219: courseForm.elements['$name'].value = "$values{$name}[0]";
1.119 raeburn 2220: |;
1.121 raeburn 2221: }
2222: } else {
2223: $output .= qq|
1.147 raeburn 2224: var elementLength = courseForm.elements['$name'].length;
1.119 raeburn 2225: if (elementLength==undefined) {
2226: |;
1.121 raeburn 2227: foreach my $value (@{$values{$name}}) {
2228: if ($$elements{$name} eq 'selectbox') {
2229: $output .= qq|
1.147 raeburn 2230: if (courseForm.elements['$name'].options[0].value == "$value") {
2231: courseForm.elements['$name'].options[0].selected = true;
1.119 raeburn 2232: }|;
1.121 raeburn 2233: } elsif (($$elements{$name} eq 'radio') ||
2234: ($$elements{$name} eq 'checkbox')) {
2235: $output .= qq|
1.147 raeburn 2236: if (courseForm.elements['$name'].value == "$value") {
1.148 albertel 2237: courseForm.elements['$name'].checked = true;
1.234 raeburn 2238: } else {
2239: courseForm.elements['$name'].checked = false;
1.119 raeburn 2240: }|;
1.121 raeburn 2241: }
2242: }
2243: $output .= qq|
1.119 raeburn 2244: }
2245: else {
1.147 raeburn 2246: for (var i=0; i<courseForm.elements['$name'].length; i++) {
1.119 raeburn 2247: |;
1.121 raeburn 2248: if ($$elements{$name} eq 'selectbox') {
2249: $output .= qq|
1.147 raeburn 2250: courseForm.elements['$name'].options[i].selected = false;|;
1.121 raeburn 2251: } elsif (($$elements{$name} eq 'radio') ||
2252: ($$elements{$name} eq 'checkbox')) {
2253: $output .= qq|
1.147 raeburn 2254: courseForm.elements['$name']\[i].checked = false;|;
1.121 raeburn 2255: }
2256: $output .= qq|
1.119 raeburn 2257: }
1.147 raeburn 2258: for (var j=0; j<courseForm.elements['$name'].length; j++) {
1.119 raeburn 2259: |;
1.121 raeburn 2260: foreach my $value (@{$values{$name}}) {
2261: if ($$elements{$name} eq 'selectbox') {
2262: $output .= qq|
1.147 raeburn 2263: if (courseForm.elements['$name'].options[j].value == "$value") {
2264: courseForm.elements['$name'].options[j].selected = true;
1.119 raeburn 2265: }|;
1.121 raeburn 2266: } elsif (($$elements{$name} eq 'radio') ||
2267: ($$elements{$name} eq 'checkbox')) {
2268: $output .= qq|
1.147 raeburn 2269: if (courseForm.elements['$name']\[j].value == "$value") {
2270: courseForm.elements['$name']\[j].checked = true;
1.119 raeburn 2271: }|;
1.121 raeburn 2272: }
2273: }
2274: $output .= qq|
1.119 raeburn 2275: }
2276: }
2277: |;
2278: }
2279: }
2280: $output .= "
1.235 raeburn 2281: return;
1.119 raeburn 2282: }\n";
2283: return $output;
2284: }
2285:
1.158 raeburn 2286: ##############################################
2287: ##############################################
2288:
1.291 raeburn 2289: sub file_submissionchk_js {
2290: my ($turninpaths,$multiples) = @_;
2291: my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item').'\\n'.
2292: &mt('Continue submission and overwrite the file(s)?');
2293: my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'.
2294: &mt('Continue submission with these files removed?');
1.292 raeburn 2295: my ($turninpathtext,$multtext,$arrayindexofjs);
1.291 raeburn 2296: if (ref($turninpaths) eq 'HASH') {
2297: foreach my $key (sort(keys(%{$turninpaths}))) {
2298: $turninpathtext .= " if (prefix == '$key') {\n".
2299: " return '$turninpaths->{$key}';\n".
2300: " }\n";
2301: }
2302: }
2303: $turninpathtext .= " return '';\n";
2304: if (ref($multiples) eq 'HASH') {
2305: foreach my $key (sort(keys(%{$multiples}))) {
2306: $multtext .= " if (prefix == '$key') {\n".
2307: " return '$multiples->{$key}';\n".
2308: " }\n";
2309: }
2310: }
2311: $multtext .= " return '';\n";
1.292 raeburn 2312:
1.293 raeburn 2313: $arrayindexofjs = &Apache::loncommon::javascript_array_indexof();
1.291 raeburn 2314: return <<"ENDSCRIPT";
2315: <script type="text/javascript">
2316: // <![CDATA[
2317:
2318: function file_submission_check(formname,path,multiresp) {
2319: var elemnum = formname.elements.length;
2320: if (elemnum == 0) {
2321: return true;
2322: }
2323: var alloverwrites = [];
2324: var alldelconfirm = [];
2325: var result = [];
2326: var submitter;
2327: var subprefix;
2328: var allsub = getIndexByName(formname,'all_submit');
2329: if (allsub == -1) {
2330: var idx = getIndexByName(formname,'submitted');
2331: if (idx != -1) {
2332: var subval = String(formname.elements[idx].value);
2333: submitter = subval.replace(/^part_/,'');
2334: result = overwritten_check(formname,path,multiresp,submitter);
2335: alloverwrites.push.apply(alloverwrites,result['overwrite']);
2336: alldelconfirm.push.apply(alldelconfirm,result['delete']);
2337: }
2338: } else {
2339: if (formname.elements[allsub].type == 'submit') {
2340: var partsub = /^\\d+\\.\\d+_submit_.+\$/;
2341: var allprefixes = [];
2342: var allparts = [];
2343: for (var i=0; i<formname.elements.length; i++) {
2344: if (formname.elements[i].type == 'submit') {
2345: var elemname = formname.elements[i].name;
2346: var subname = String(elemname);
2347: var savesub = String(elemname);
2348: if (partsub.test(subname)) {
2349: var prefix = subname.replace(/_submit_.+\$/,'');
2350: if (allprefixes.indexOf(prefix) == -1) {
2351: allprefixes.push(prefix);
2352: allparts[prefix] = [];
2353: }
2354: var part = savesub.replace(/^\\d+\\.\\d+_submit_/,'');
2355: allparts[prefix].push(part);
2356: }
2357: }
2358: }
2359: for (var k=0; k<allprefixes.length; k++) {
2360: var idx = getIndexByName(formname,allprefixes[k]+'_submitted');
2361: if (idx > -1) {
2362: if (formname.elements[idx].value != 'yes') {
2363: submitterval = formname.elements[idx].value;
2364: submitter = submitterval.replace(/^part_/,'');
2365: subprefix = allprefixes[k];
2366: result = overwritten_check(formname,path,multiresp,submitter,subprefix);
2367: alloverwrites.push.apply(alloverwrites,result['overwrite']);
2368: alldelconfirm.push.apply(alldelconfirm,result['delete']);
2369: break;
2370: }
2371: }
2372: }
2373: if (submitter == '' || submitter == undefined) {
2374: for (var m=0; m<allprefixes.length; m++) {
2375: for (var n=0; n<allparts[allprefixes[m]].length; n++) {
2376: var result = overwritten_check(formname,path,multiresp,allparts[allprefixes[m]][n],allprefixes[m]);
2377: alloverwrites.push.apply(alloverwrites,result['overwrite']);
2378: alldelconfirm.push.apply(alldelconfirm,result['delete']);
2379: }
2380: }
2381: }
2382: }
2383: }
2384: if (alloverwrites.length > 0) {
2385: if (!confirm("$overwritewarn")) {
2386: for (var n=0; n<alloverwrites.length; n++) {
2387: formname.elements[alloverwrites[n]].value = "";
2388: }
2389: return false;
2390: }
2391: }
2392: if (alldelconfirm.length > 0) {
2393: if (!confirm("$delfilewarn")) {
2394: for (var p=0; p<alldelconfirm.length; p++) {
2395: formname.elements[alldelconfirm[p]].checked = false;
2396: }
2397: return false;
2398: }
2399: }
2400: return true;
2401: }
2402:
2403: function getIndexByName(formname,item) {
2404: for (var i=0;i<formname.elements.length;i++) {
2405: if (formname.elements[i].name == item) {
2406: return i;
2407: }
2408: }
2409: return -1;
2410: }
2411:
2412: function overwritten_check(formname,path,multiresp,part,prefix) {
2413: var result = [];
2414: result['overwrite'] = [];
2415: result['delete'] = [];
2416: var elemnum = formname.elements.length;
2417: if (elemnum == 0) {
2418: return result;
2419: }
2420: var uploadstr;
2421: var deletestr;
2422: if ((prefix != undefined) && (prefix != '')) {
2423: var prepend = prefix+'_';
2424: uploadstr = new RegExp("^"+prepend+"HWFILE"+part+".+\$");
2425: deletestr = new RegExp("^"+prepend+"HWFILE"+part+".+_\\\\d+_delete\$");
2426: multiresp = check_for_multiples(prepend);
2427: path = check_for_turninpath(prepend);
2428: } else {
2429: uploadstr = new RegExp("^HWFILE"+part+".+\$");
2430: deletestr = new RegExp("^HWFILE"+part+".+_\\\\d+_delete\$");
2431: }
2432: var alluploads = [];
2433: var allchecked = [];
2434: var allskipdel = [];
2435: var fnametrim = /[^\\/\\\\]+\$/;
2436: for (var i=0; i<formname.elements.length; i++) {
2437: var id = formname.elements[i].id;
2438: if (id != '') {
2439: if (uploadstr.test(id)) {
2440: if (formname.elements[i].type == 'file') {
2441: alluploads.push(id);
2442: } else {
2443: if (deletestr.test(id)) {
2444: if (formname.elements[i].type == 'checkbox') {
2445: if (formname.elements[i].checked) {
2446: allchecked.push(id);
2447: }
2448: }
2449: }
2450: }
2451: }
2452: }
2453: }
2454: for (var j=0; j<alluploads.length; j++) {
2455: var delstr = new RegExp("^"+alluploads[j]+"_\\\\d+_delete\$");
2456: var delboxes = [];
2457: for (var k=0; k<formname.elements.length; k++) {
2458: var id = formname.elements[k].id;
2459: if ((id != '') && (id != undefined)) {
2460: if (delstr.test(id)) {
2461: if (formname.elements[k].type == 'checkbox') {
2462: delboxes.push(id);
2463: }
2464: }
2465: }
2466: }
2467: if (delboxes.length > 0) {
2468: if ((formname.elements[alluploads[j]].value != undefined) &&
2469: (formname.elements[alluploads[j]].value != '')) {
2470: var filepath = formname.elements[alluploads[j]].value;
2471: var newfilename = fnametrim.exec(filepath);
2472: if (newfilename != null) {
2473: var filename = String(newfilename);
2474: var nospaces = filename.replace(/\\s+/g,'_');
2475: var nospecials = nospaces.replace(/[^\\/\\w\\.\\-]/g,'');
2476: var cleanfilename = nospecials.replace(/\\.(\\d+\\.)/g,"_\$1");
2477: if (cleanfilename != '') {
2478: var fullpath = path+"/"+cleanfilename;
2479: if (multiresp == 1) {
2480: var partid = String(alluploads[i]);
2481: var subdir = partid.replace(/^\\d*.?\\d*_?HWFILE/,'');
2482: if (subdir != "" && subdir != undefined) {
2483: fullpath = path+"/"+subdir+"/"+cleanfilename;
2484: }
2485: }
2486: for (var m=0; m<delboxes.length; m++) {
2487: if (fullpath == formname.elements[delboxes[m]].value) {
2488: if (formname.elements[delboxes[m]].checked) {
2489: allskipdel.push(delboxes[m]);
2490: } else {
2491: result['overwrite'].push(alluploads[j]);
2492: }
2493: break;
2494: }
2495: }
2496: }
2497: }
2498: }
2499: }
2500: }
2501: if (allchecked.length > 0) {
2502: if (allskipdel.length > 0) {
2503: for (var n=0; n<allchecked.length; n++) {
2504: if (allskipdel.indexOf(allchecked[n]) == -1) {
2505: result['delete'].push(allchecked[n]);
2506: }
2507: }
2508: } else {
2509: result['delete'].push.apply(result['delete'],allchecked);
2510: }
2511: }
2512: return result;
2513: }
2514:
2515: function check_for_multiples(prefix) {
2516: $multtext
2517: }
2518:
2519: function check_for_turninpath(prefix) {
2520: $turninpathtext
2521: }
2522:
2523: // ]]>
2524: </script>
2525:
1.292 raeburn 2526: $arrayindexofjs
2527:
1.291 raeburn 2528: ENDSCRIPT
2529: }
2530:
2531: ##############################################
2532: ##############################################
2533:
1.158 raeburn 2534: # javascript_valid_email
2535: #
2536: # Generates javascript to validate an e-mail address.
2537: # Returns a javascript function which accetps a form field as argumnent, and
2538: # returns false if field.value does not satisfy two regular expression matches
2539: # for a valid e-mail address. Backwards compatible with old browsers without
2540: # support for javascript RegExp (just checks for @ in field.value in this case).
2541:
2542: sub javascript_valid_email {
2543: my $scripttag .= <<'END';
2544: function validmail(field) {
2545: var str = field.value;
2546: if (window.RegExp) {
2547: var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
2548: var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
2549: var reg1 = new RegExp(reg1str);
2550: var reg2 = new RegExp(reg2str);
2551: if (!reg1.test(str) && reg2.test(str)) {
2552: return true;
2553: }
2554: return false;
2555: }
2556: else
2557: {
2558: if(str.indexOf("@") >= 0) {
2559: return true;
2560: }
2561: return false;
2562: }
2563: }
2564: END
2565: return $scripttag;
2566: }
2567:
1.219 droeschl 2568:
2569: # USAGE: htmltag(element, content, {attribute => value,...});
2570: #
2571: # EXAMPLES:
2572: # - htmltag('a', 'this is an anchor', {href => 'www.example.com',
2573: # title => 'this is a title'})
2574: #
2575: # - You might want to set up needed tags like:
2576: #
2577: # my $h3 = sub { return htmltag( "h3", @_ ) };
2578: #
2579: # ... and use them: $h3->("This is a headline")
2580: #
2581: # - To set up a couple of tags, see sub inittags
2582: #
2583: # NOTES:
2584: # - Empty elements, such as <br/> are correctly terminated,
2585: # i.e. htmltag('br') returns <br/>
2586: # - Empty attributes (title="") are filtered out.
2587: # - The function will not check for deprecated attributes.
2588: #
2589: # OUTPUT: content enclosed in xhtml conform tags
2590: sub htmltag{
2591: return
2592: qq|<$_[0]|
2593: . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } )
2594: . ($_[1] ? qq|>$_[1]</$_[0]>| : qq|/>|). "\n";
2595: };
2596:
2597:
2598: # USAGE: inittags(@tags);
2599: #
2600: # EXAMPLES:
1.261 droeschl 2601: # - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )
1.219 droeschl 2602: # $h1->("This is a headline") #Returns: <h1>This is a headline</h1>
2603: #
2604: # NOTES: See sub htmltag for further information.
2605: #
2606: # OUTPUT: List of subroutines.
2607: sub inittags {
2608: my @tags = @_;
2609: return map { my $tag = $_;
2610: sub { return htmltag( $tag, @_ ) }
2611: } @tags;
2612: }
2613:
2614:
1.231 droeschl 2615: # USAGE: scripttag(scriptcode, [start|end|both]);
1.229 droeschl 2616: #
2617: # EXAMPLES:
1.231 droeschl 2618: # - scripttag("alert('Hello World!')", 'both')
2619: # returns:
2620: # <script type="text/javascript">
2621: # // BEGIN LON-CAPA Internal
2622: # alert(Hello World!')
2623: # // END LON-CAPA Internal
2624: # </script>
1.229 droeschl 2625: #
2626: # NOTES:
2627: # - works currently only for javascripts
2628: #
1.231 droeschl 2629: # OUTPUT:
2630: # Scriptcode properly enclosed in <script> and CDATA tags (and LC
2631: # Internal markers if 2nd argument is given)
1.229 droeschl 2632: sub scripttag {
1.231 droeschl 2633: my ( $content, $marker ) = @_;
2634: return unless defined $content;
2635:
2636: my $begin = "\n// BEGIN LON-CAPA Internal\n";
2637: my $end = "\n// END LON-CAPA Internal\n";
2638:
2639: if ($marker) {
2640: $content = $begin . $content if $marker eq 'start' or $marker eq 'both';
2641: $content .= $end if $marker eq 'end' or $marker eq 'both';
2642: }
2643:
1.229 droeschl 2644: $content = "\n// <![CDATA[\n$content\n// ]]>\n";
1.231 droeschl 2645:
2646: return htmltag('script', $content, {type => 'text/javascript'});
1.229 droeschl 2647: };
2648:
2649:
1.261 droeschl 2650: =item list_from_array( \@array, { listattr =>{}, itemattr =>{} } )
2651:
2652: Constructs a XHTML list from \@array.
2653:
2654: input:
2655:
2656: =over
2657:
2658: =item \@array
2659:
2660: A reference to the array containing text that will be wrapped in <li></li> tags.
2661:
2662: =item { listattr => {}, itemattr =>{} }
2663:
2664: Attributes for <ul> and <li> passed in as hash references.
2665: See htmltag() for more details.
2666:
2667: =back
2668:
2669: returns: XHTML list as String.
2670:
2671: =cut
2672:
2673: # \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}
2674: sub list_from_array {
2675: my ($items, $args) = @_;
1.285 raeburn 2676: return unless (ref($items) eq 'ARRAY');
1.273 droeschl 2677: return unless scalar @$items;
1.261 droeschl 2678: my ($ul, $li) = inittags( qw(ul li) );
2679: my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;
2680: return $ul->( $listitems, $args->{listattr} );
2681: }
2682:
2683:
1.183 droeschl 2684: ##############################################
2685: ##############################################
2686:
2687: # generate_menu
2688: #
2689: # Generates html markup for a menu.
2690: #
2691: # Inputs:
2692: # An array of following structure:
2693: # ({ categorytitle => 'Categorytitle',
2694: # items => [
1.201 droeschl 2695: # {
2696: # linktext => 'Text to be displayed',
2697: # url => 'URL the link is pointing to, i.e. /adm/site?action=dosomething',
1.183 droeschl 2698: # permission => 'Contains permissions as returned from lonnet::allowed(),
1.201 droeschl 2699: # must evaluate to true in order to activate the link',
1.184 droeschl 2700: # icon => 'icon filename',
1.186 droeschl 2701: # alttext => 'alt text for the icon',
1.183 droeschl 2702: # help => 'Name of the corresponding helpfile',
2703: # linktitle => 'Description of the link (used for title tag)'
2704: # },
2705: # ...
2706: # ]
2707: # },
2708: # ...
2709: # )
2710: #
2711: # Outputs: A scalar containing the html markup for the menu.
2712:
2713: sub generate_menu {
2714: my @menu = @_;
1.201 droeschl 2715: # subs for specific html elements
1.219 droeschl 2716: my ($h3, $div, $ul, $li, $a, $img) = inittags( qw(h3 div ul li a img) );
1.201 droeschl 2717:
2718: my @categories; # each element represents the entire markup for a category
2719:
2720: foreach my $category (@menu) {
2721: my @links; # contains the links for the current $category
2722: foreach my $link (@{$$category{items}}) {
2723: next unless $$link{permission};
2724:
2725: # create the markup for the current $link and push it into @links.
2726: # each entry consists of an image and a text optionally followed
2727: # by a help link.
1.283 raeburn 2728: my $src;
2729: if ($$link{icon} ne '') {
2730: $src = '/res/adm/pages/'.$$link{icon};
2731: }
1.232 raeburn 2732: push(@links,$li->(
1.201 droeschl 2733: $a->(
2734: $img->("", {
2735: class => "LC_noBorder LC_middle",
1.283 raeburn 2736: src => $src,
1.202 droeschl 2737: alt => mt(defined($$link{alttext}) ?
2738: $$link{alttext} : $$link{linktext})
1.201 droeschl 2739: }), {
2740: href => $$link{url},
1.202 droeschl 2741: title => mt($$link{linktitle})
1.201 droeschl 2742: }).
1.202 droeschl 2743: $a->(mt($$link{linktext}), {
1.201 droeschl 2744: href => $$link{url},
1.202 droeschl 2745: title => mt($$link{linktitle}),
1.201 droeschl 2746: class => "LC_menubuttons_link"
2747: }).
2748: (defined($$link{help}) ?
2749: Apache::loncommon::help_open_topic($$link{help}) : ''),
1.232 raeburn 2750: {class => "LC_menubuttons_inline_text"}));
1.201 droeschl 2751: }
2752:
2753: # wrap categorytitle in <h3>, concatenate with
2754: # joined and in <ul> tags wrapped @links
2755: # and wrap everything in an enclosing <div> and push it into
2756: # @categories
2757: # such that each element looks like:
2758: # <div><h3>title</h3><ul><li>...</li>...</ul></div>
2759: # the category won't be added if there aren't any links
1.232 raeburn 2760: push(@categories,
1.202 droeschl 2761: $div->($h3->(mt($$category{categorytitle}), {class=>"LC_hcell"}).
1.201 droeschl 2762: $ul->(join('' ,@links), {class =>"LC_ListStyleNormal" }),
1.232 raeburn 2763: {class=>"LC_Box LC_400Box"})) if scalar(@links);
1.183 droeschl 2764: }
1.201 droeschl 2765:
2766: # wrap the joined @categories in another <div> (column layout)
2767: return $div->(join('', @categories), {class => "LC_columnSection"});
1.183 droeschl 2768: }
1.176 foxr 2769:
1.224 bisitz 2770: ##############################################
2771: ##############################################
2772:
2773: =pod
2774:
2775: =item &start_funclist
2776:
2777: Start list of available functions
2778:
2779: Typically used to offer a simple list of available functions
2780: at top or bottom of page.
2781: All available functions/actions for the current page
2782: should be included in this list.
2783:
2784: If the optional headline text is not provided, a default text will be used.
2785:
2786:
2787: Related routines:
2788: =over 4
2789: add_item_funclist
2790: end_funclist
2791: =back
2792:
2793:
2794: Inputs: (optional) headline text
2795:
2796: Returns: HTML code with function list start
2797:
2798: =cut
2799:
2800: ##############################################
2801: ##############################################
2802:
2803: sub start_funclist {
2804: my($legendtext)=@_;
2805: $legendtext=&mt('Functions') if !$legendtext;
1.244 droeschl 2806: return '<ul class="LC_funclist"><li style="font-weight:bold; margin-left:0.8em;">'.$legendtext.'</li>'."\n";
1.224 bisitz 2807: }
2808:
2809:
2810: ##############################################
2811: ##############################################
2812:
2813: =pod
2814:
2815: =item &add_item_funclist
2816:
2817: Adds an item to the list of available functions
2818:
2819: Related routines:
2820: =over 4
2821: start_funclist
2822: end_funclist
2823: =back
2824:
2825: Inputs: content item with text and link to function
2826:
2827: Returns: HTML code with list item for funclist
2828:
2829: =cut
2830:
2831: ##############################################
2832: ##############################################
2833:
2834: sub add_item_funclist {
2835: my($content) = @_;
2836: return '<li>'.$content.'</li>'."\n";
2837: }
2838:
2839: =pod
2840:
2841: =item &end_funclist
2842:
2843: End list of available functions
2844:
2845: Related routines:
2846: =over 4
2847: start_funclist
2848: add_item_funclist
2849: =back
2850:
2851: Inputs: ./.
2852:
2853: Returns: HTML code with function list end
2854: =cut
2855:
2856: sub end_funclist {
1.246 bisitz 2857: return "</ul>\n";
1.224 bisitz 2858: }
2859:
1.261 droeschl 2860: =pod
2861:
2862: =item funclist_from_array( \@array, {legend => 'text for legend'} )
2863:
2864: Constructs a XHTML list from \@array with the first item being visually
2865: highlighted and set to the value of legend or 'Functions' if legend is
2866: empty.
2867:
2868: =over
2869:
2870: =item \@array
2871:
2872: A reference to the array containing text that will be wrapped in <li></li> tags.
2873:
2874: =item { legend => 'text' }
2875:
2876: A string that's used as visually highlighted first item. 'Functions' is used if
2877: it's value evaluates to false.
2878:
2879: =back
2880:
2881: returns: XHTML list as string.
2882:
2883: =back
2884:
2885: =cut
2886:
2887: sub funclist_from_array {
2888: my ($items, $args) = @_;
1.285 raeburn 2889: return unless(ref($items) eq 'ARRAY');
1.261 droeschl 2890: $args->{legend} ||= mt('Functions');
2891: return list_from_array( [$args->{legend}, @$items],
2892: { listattr => {class => 'LC_funclist'} });
2893: }
2894:
1.1 stredwic 2895: 1;
1.23 matthew 2896:
1.1 stredwic 2897: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>