Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.182.4.12

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>