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