File:  [LON-CAPA] / loncom / interface / lonhtmlcommon.pm
Revision 1.117: download - view: text, annotated - select for diffs
Thu Oct 27 23:18:21 2005 UTC (18 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Add flexibility here too.

    1: # The LearningOnline Network with CAPA
    2: # a pile of common html routines
    3: #
    4: # $Id: lonhtmlcommon.pm,v 1.117 2005/10/27 23:18:21 raeburn Exp $
    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: #
   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: ######################################################################
   55: 
   56: package Apache::lonhtmlcommon;
   57: 
   58: use strict;
   59: use Time::Local;
   60: use Time::HiRes;
   61: use Apache::lonlocal;
   62: use Apache::lonnet;
   63: 
   64: ##############################################
   65: ##############################################
   66: 
   67: =pod
   68: 
   69: =item authorbombs
   70: 
   71: =cut
   72: 
   73: ##############################################
   74: ##############################################
   75: 
   76: sub authorbombs {
   77:     my $url=shift;
   78:     $url=&Apache::lonnet::declutter($url);
   79:     my ($udom,$uname)=($url=~/^(\w+)\/(\w+)\//);
   80:     my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
   81:     foreach (keys %bombs) {
   82: 	if ($_=~/^$udom\/$uname\//) {
   83: 	    return '<a href="/adm/bombs/'.$url.
   84: 		'"><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/bomb.gif').'" border="0" /></a>'.
   85: 		&Apache::loncommon::help_open_topic('About_Bombs');
   86: 	}
   87:     }
   88:     return '';
   89: }
   90: 
   91: ##############################################
   92: ##############################################
   93: 
   94: sub recent_filename {
   95:     my $area=shift;
   96:     return 'nohist_recent_'.&Apache::lonnet::escape($area);
   97: }
   98: 
   99: sub store_recent {
  100:     my ($area,$name,$value)=@_;
  101:     my $file=&recent_filename($area);
  102:     my %recent=&Apache::lonnet::dump($file);
  103:     if (scalar(keys(%recent))>20) {
  104: # remove oldest value
  105: 	my $oldest=time;
  106: 	my $delkey='';
  107: 	foreach (keys %recent) {
  108: 	    my $thistime=(split(/\&/,$recent{$_}))[0];
  109: 	    if ($thistime<$oldest) {
  110: 		$oldest=$thistime;
  111: 		$delkey=$_;
  112: 	    }
  113: 	}
  114: 	&Apache::lonnet::del($file,[$delkey]);
  115:     }
  116: # store new value
  117:     &Apache::lonnet::put($file,{ $name => 
  118: 				 time.'&'.&Apache::lonnet::escape($value) });
  119: }
  120: 
  121: sub remove_recent {
  122:     my ($area,$names)=@_;
  123:     my $file=&recent_filename($area);
  124:     return &Apache::lonnet::del($file,$names);
  125: }
  126: 
  127: sub select_recent {
  128:     my ($area,$fieldname,$event)=@_;
  129:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
  130:     my $return="\n<select name='$fieldname'".
  131: 	($event?" onchange='$event'":'').
  132: 	">\n<option value=''>--- ".&mt('Recent')." ---</option>";
  133:     foreach (sort keys %recent) {
  134: 	unless ($_=~/^error\:/) {
  135: 	    my $escaped = &Apache::loncommon::escape_url($_);
  136: 	    $return.="\n<option value='$escaped'>".
  137: 		&Apache::lonnet::unescape((split(/\&/,$recent{$_}))[1]).
  138: 		'</option>';
  139: 	}
  140:     }
  141:     $return.="\n</select>\n";
  142:     return $return;
  143: }
  144: 
  145: sub get_recent {
  146:     my ($area, $n) = @_;
  147:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
  148: 
  149: # Create hash with key as time and recent as value
  150:     my %time_hash = ();
  151:     foreach (keys %recent) {
  152:         my $thistime=(split(/\&/,$recent{$_}))[0];
  153:         $time_hash{$thistime} = $_;
  154:     }
  155: 
  156: # Sort by decreasing time and return key value pairs
  157:     my %return_hash = ();
  158:     my $idx = 1;
  159:     foreach (reverse sort keys %time_hash) {
  160:        $return_hash{$time_hash{$_}} =
  161:                   &Apache::lonnet::unescape((split(/\&/,$recent{$_}))[1]);
  162:        if ($n && ($idx++ >= $n)) {last;}
  163:     }
  164: 
  165:     return %return_hash;
  166: }
  167: 
  168: 
  169: 
  170: =pod
  171: 
  172: =item textbox
  173: 
  174: =cut
  175: 
  176: ##############################################
  177: ##############################################
  178: sub textbox {
  179:     my ($name,$value,$size,$special) = @_;
  180:     $size = 40 if (! defined($size));
  181:     my $Str = '<input type="text" name="'.$name.'" size="'.$size.'" '.
  182:         'value="'.$value.'" '.$special.' />';
  183:     return $Str;
  184: }
  185: 
  186: ##############################################
  187: ##############################################
  188: 
  189: =pod
  190: 
  191: =item checkbox
  192: 
  193: =cut
  194: 
  195: ##############################################
  196: ##############################################
  197: sub checkbox {
  198:     my ($name,$checked,$value) = @_;
  199:     my $Str = '<input type="checkbox" name="'.$name.'" ';
  200:     if (defined($value)) {
  201:         $Str .= 'value="'.$value.'"';
  202:     } 
  203:     if ($checked) {
  204:         $Str .= ' checked="1"';
  205:     }
  206:     $Str .= ' />';
  207:     return $Str;
  208: }
  209: 
  210: ##############################################
  211: ##############################################
  212: 
  213: =pod
  214: 
  215: =item &date_setter
  216: 
  217: &date_setter returns html and javascript for a compact date-setting form.
  218: To retrieve values from it, use &get_date_from_form().
  219: 
  220: Inputs
  221: 
  222: =over 4
  223: 
  224: =item $dname 
  225: 
  226: The name to prepend to the form elements.  
  227: The form elements defined will be dname_year, dname_month, dname_day,
  228: dname_hour, dname_min, and dname_sec.
  229: 
  230: =item $currentvalue
  231: 
  232: The current setting for this time parameter.  A unix format time
  233: (time in seconds since the beginning of Jan 1st, 1970, GMT.  
  234: An undefined value is taken to indicate the value is the current time.
  235: Also, to be explicit, a value of 'now' also indicates the current time.
  236: 
  237: =item $special
  238: 
  239: Additional html/javascript to be associated with each element in
  240: the date_setter.  See lonparmset for example usage.
  241: 
  242: =item $includeempty 
  243: 
  244: =item $state
  245: 
  246: Specifies the initial state of the form elements.  Either 'disabled' or empty.
  247: Defaults to empty, which indiciates the form elements are not disabled. 
  248: 
  249: =back
  250: 
  251: Bugs
  252: 
  253: The method used to restrict user input will fail in the year 2400.
  254: 
  255: =cut
  256: 
  257: ##############################################
  258: ##############################################
  259: sub date_setter {
  260:     my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
  261:         $no_hh_mm_ss,$defhour,$defmin,$defsec) = @_;
  262:     my $wasdefined=1;
  263:     if (! defined($state) || $state ne 'disabled') {
  264:         $state = '';
  265:     }
  266:     if (! defined($no_hh_mm_ss)) {
  267:         $no_hh_mm_ss = 0;
  268:     }
  269:     if ($currentvalue eq 'now') {
  270: 	$currentvalue=time;
  271:     }
  272:     if ((!defined($currentvalue)) || ($currentvalue eq '')) {
  273: 	$wasdefined=0;
  274: 	if ($includeempty) {
  275: 	    $currentvalue = 0;
  276: 	} else {
  277: 	    $currentvalue = time;
  278: 	}
  279:     }
  280:     # other potentially useful values:     wkday,yrday,is_daylight_savings
  281:     my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','','');
  282:     if ($currentvalue) {
  283: 	($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = 
  284: 	    localtime($currentvalue);
  285: 	$year += 1900;
  286:     }
  287:     unless ($wasdefined) {
  288: 	if (($defhour) || ($defmin) || ($defsec)) {
  289: 	    ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = 
  290: 		localtime(time);
  291: 	    $year += 1900;
  292: 	    $sec=($defsec?$defsec:0);
  293: 	    $min=($defmin?$defmin:0);
  294: 	    $hour=($defhour?$defhour:0);
  295: 	} elsif (!$includeempty) {
  296: 	    $sec=0;
  297: 	    $min=0;
  298: 	    $hour=0;
  299: 	}
  300:     }
  301:     my $result = "\n<!-- $dname date setting form -->\n";
  302:     $result .= <<ENDJS;
  303: <script language="Javascript">
  304:     function $dname\_checkday() {
  305:         var day   = document.$formname.$dname\_day.value;
  306:         var month = document.$formname.$dname\_month.value;
  307:         var year  = document.$formname.$dname\_year.value;
  308:         var valid = true;
  309:         if (day < 1) {
  310:             document.$formname.$dname\_day.value = 1;
  311:         } 
  312:         if (day > 31) {
  313:             document.$formname.$dname\_day.value = 31;
  314:         }
  315:         if ((month == 1)  || (month == 3)  || (month == 5)  ||
  316:             (month == 7)  || (month == 8)  || (month == 10) ||
  317:             (month == 12)) {
  318:             if (day > 31) {
  319:                 document.$formname.$dname\_day.value = 31;
  320:                 day = 31;
  321:             }
  322:         } else if (month == 2 ) {
  323:             if ((year % 4 == 0) && (year % 100 != 0)) {
  324:                 if (day > 29) {
  325:                     document.$formname.$dname\_day.value = 29;
  326:                 }
  327:             } else if (day > 29) {
  328:                 document.$formname.$dname\_day.value = 28;
  329:             }
  330:         } else if (day > 30) {
  331:             document.$formname.$dname\_day.value = 30;
  332:         }
  333:     }
  334:     
  335:     function $dname\_disable() {
  336:         document.$formname.$dname\_month.disabled=true;
  337:         document.$formname.$dname\_day.disabled=true;
  338:         document.$formname.$dname\_year.disabled=true;
  339:         document.$formname.$dname\_hour.disabled=true;
  340:         document.$formname.$dname\_minute.disabled=true;
  341:         document.$formname.$dname\_second.disabled=true;
  342:     }
  343: 
  344:     function $dname\_enable() {
  345:         document.$formname.$dname\_month.disabled=false;
  346:         document.$formname.$dname\_day.disabled=false;
  347:         document.$formname.$dname\_year.disabled=false;
  348:         document.$formname.$dname\_hour.disabled=false;
  349:         document.$formname.$dname\_minute.disabled=false;
  350:         document.$formname.$dname\_second.disabled=false;        
  351:     }
  352: 
  353:     function $dname\_opencalendar() {
  354:         if (! document.$formname.$dname\_month.disabled) {
  355:             var calwin=window.open(
  356: "/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
  357: document.$formname.$dname\_month.value+"&year="+
  358: document.$formname.$dname\_year.value,
  359:              "LONCAPAcal",
  360:               "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
  361:         }
  362: 
  363:     }
  364: </script>
  365: ENDJS
  366:     $result .= '  <nobr>';
  367:     my $monthselector = qq{<select name="$dname\_month" $special $state onchange="javascript:$dname\_checkday()" >};
  368:     # Month
  369:     my @Months = qw/January February  March     April   May      June 
  370:                     July    August    September October November December/;
  371:     # Pad @Months with a bogus value to make indexing easier
  372:     unshift(@Months,'If you can read this an error occurred');
  373:     if ($includeempty) { $monthselector.="<option value=''></option>"; }
  374:     for(my $m = 1;$m <=$#Months;$m++) {
  375:         $monthselector .= qq{      <option value="$m" };
  376:         $monthselector .= "selected " if ($m-1 eq $month);
  377:         $monthselector .= '> '.&mt($Months[$m]).' </option>';
  378:     }
  379:     $monthselector.= '  </select>';
  380:     # Day
  381:     my $dayselector = qq{<input type="text" name="$dname\_day" $state value="$mday" size="3" $special onchange="javascript:$dname\_checkday()" />};
  382:     # Year
  383:     my $yearselector = qq{<input type="year" name="$dname\_year" $state value="$year" size="5" $special onchange="javascript:$dname\_checkday()" />};
  384:     #
  385:     my $hourselector = qq{<select name="$dname\_hour" $special $state >};
  386:     if ($includeempty) { 
  387:         $hourselector.=qq{<option value=''></option>};
  388:     }
  389:     for (my $h = 0;$h<24;$h++) {
  390:         $hourselector .= qq{<option value="$h" };
  391:         $hourselector .= "selected " if (defined($hour) && $hour == $h);
  392:         $hourselector .= ">";
  393:         my $timest='';
  394:         if ($h == 0) {
  395:             $timest .= "12 am";
  396:         } elsif($h == 12) {
  397:             $timest .= "12 noon";
  398:         } elsif($h < 12) {
  399:             $timest .= "$h am";
  400:         } else {
  401:             $timest .= $h-12 ." pm";
  402:         }
  403:         $timest=&mt($timest);
  404:         $hourselector .= $timest." </option>\n";
  405:     }
  406:     $hourselector .= "  </select>\n";
  407:     my $minuteselector = qq{<input type="text" name="$dname\_minute" $special $state value="$min" size="3" />};
  408:     my $secondselector= qq{<input type="text" name="$dname\_second" $special $state value="$sec" size="3" />};
  409:     my $cal_link = qq{<a href="javascript:$dname\_opencalendar()">};
  410:     #
  411:     if ($no_hh_mm_ss) {
  412:         $result .= &mt('[_1] [_2] [_3] [_4]Select Date[_5]',
  413:                        $monthselector,$dayselector,$yearselector,
  414:                        $cal_link,'</a>');
  415:     } else {
  416:         $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s [_7]Select Date[_8]',
  417:                        $monthselector,$dayselector,$yearselector,
  418:                        $hourselector,$minuteselector,$secondselector,
  419:                        $cal_link,'</a>');
  420:     }
  421:     $result .= "</nobr>\n<!-- end $dname date setting form -->\n";
  422:     return $result;
  423: }
  424: 
  425: ##############################################
  426: ##############################################
  427: 
  428: =pod
  429: 
  430: =item &get_date_from_form
  431: 
  432: get_date_from_form retrieves the date specified in an &date_setter form.
  433: 
  434: Inputs:
  435: 
  436: =over 4
  437: 
  438: =item $dname
  439: 
  440: The name passed to &datesetter, which prefixes the form elements.
  441: 
  442: =item $defaulttime
  443: 
  444: The unix time to use as the default in case of poor inputs.
  445: 
  446: =back
  447: 
  448: Returns: Unix time represented in the form.
  449: 
  450: =cut
  451: 
  452: ##############################################
  453: ##############################################
  454: sub get_date_from_form {
  455:     my ($dname) = @_;
  456:     my ($sec,$min,$hour,$day,$month,$year);
  457:     #
  458:     if (defined($env{'form.'.$dname.'_second'})) {
  459:         my $tmpsec = $env{'form.'.$dname.'_second'};
  460:         if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
  461:             $sec = $tmpsec;
  462:         }
  463: 	if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
  464:     } else {
  465:         $sec = 0;
  466:     }
  467:     if (defined($env{'form.'.$dname.'_minute'})) {
  468:         my $tmpmin = $env{'form.'.$dname.'_minute'};
  469:         if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
  470:             $min = $tmpmin;
  471:         }
  472: 	if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
  473:     } else {
  474:         $min = 0;
  475:     }
  476:     if (defined($env{'form.'.$dname.'_hour'})) {
  477:         my $tmphour = $env{'form.'.$dname.'_hour'};
  478:         if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
  479:             $hour = $tmphour;
  480:         }
  481:     } else {
  482:         $hour = 0;
  483:     }
  484:     if (defined($env{'form.'.$dname.'_day'})) {
  485:         my $tmpday = $env{'form.'.$dname.'_day'};
  486:         if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
  487:             $day = $tmpday;
  488:         }
  489:     }
  490:     if (defined($env{'form.'.$dname.'_month'})) {
  491:         my $tmpmonth = $env{'form.'.$dname.'_month'};
  492:         if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
  493:             $month = $tmpmonth - 1;
  494:         }
  495:     }
  496:     if (defined($env{'form.'.$dname.'_year'})) {
  497:         my $tmpyear = $env{'form.'.$dname.'_year'};
  498:         if (($tmpyear =~ /^\d+$/) && ($tmpyear > 1900)) {
  499:             $year = $tmpyear - 1900;
  500:         }
  501:     }
  502:     if (($year<70) || ($year>137)) { return undef; }
  503:     if (defined($sec) && defined($min)   && defined($hour) &&
  504:         defined($day) && defined($month) && defined($year) &&
  505:         eval(&timelocal($sec,$min,$hour,$day,$month,$year))) {
  506:         return &timelocal($sec,$min,$hour,$day,$month,$year);
  507:     } else {
  508:         return undef;
  509:     }
  510: }
  511: 
  512: ##############################################
  513: ##############################################
  514: 
  515: =pod
  516: 
  517: =item &pjump_javascript_definition()
  518: 
  519: Returns javascript defining the 'pjump' function, which opens up a
  520: parameter setting wizard.
  521: 
  522: =cut
  523: 
  524: ##############################################
  525: ##############################################
  526: sub pjump_javascript_definition {
  527:     my $Str = <<END;
  528:     function pjump(type,dis,value,marker,ret,call,hour,min,sec) {
  529:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
  530:                  +"&value="+escape(value)+"&marker="+escape(marker)
  531:                  +"&return="+escape(ret)
  532:                  +"&call="+escape(call)+"&name="+escape(dis)
  533:                  +"&defhour="+escape(hour)+"&defmin="+escape(min)
  534:                  +"&defsec="+escape(sec),"LONCAPAparms",
  535:                  "height=350,width=350,scrollbars=no,menubar=no");
  536:     }
  537: END
  538:     return $Str;
  539: }
  540: 
  541: ##############################################
  542: ##############################################
  543: 
  544: =pod
  545: 
  546: =item &javascript_nothing()
  547: 
  548: Return an appropriate null for the users browser.  This is used
  549: as the first arguement for window.open calls when you want a blank
  550: window that you can then write to.
  551: 
  552: =cut
  553: 
  554: ##############################################
  555: ##############################################
  556: sub javascript_nothing {
  557:     # mozilla and other browsers work with "''", but IE on mac does not.
  558:     my $nothing = "''";
  559:     my $user_browser;
  560:     my $user_os;
  561:     $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
  562:     $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
  563:     if (! defined($user_browser) || ! defined($user_os)) {
  564:         (undef,$user_browser,undef,undef,undef,$user_os) = 
  565:                            &Apache::loncommon::decode_user_agent();
  566:     }
  567:     if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
  568:         $nothing = "'javascript:void(0);'";
  569:     }
  570:     return $nothing;
  571: }
  572: 
  573: ##############################################
  574: ##############################################
  575: sub javascript_docopen {
  576:     # safari does not understand document.open() and loads "text/html"
  577:     my $nothing = "''";
  578:     my $user_browser;
  579:     my $user_os;
  580:     $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
  581:     $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
  582:     if (! defined($user_browser) || ! defined($user_os)) {
  583:         (undef,$user_browser,undef,undef,undef,$user_os) = 
  584:                            &Apache::loncommon::decode_user_agent();
  585:     }
  586:     if ($user_browser eq 'safari' && $user_os =~ 'mac') {
  587:         $nothing = "document.clear()";
  588:     } else {
  589: 	$nothing = "document.open('text/html','replace')";
  590:     }
  591:     return $nothing;
  592: }
  593: 
  594: 
  595: ##############################################
  596: ##############################################
  597: 
  598: =pod
  599: 
  600: =item &StatusOptions()
  601: 
  602: Returns html for a selection box which allows the user to choose the
  603: enrollment status of students.  The selection box name is 'Status'.
  604: 
  605: Inputs:
  606: 
  607: $status: the currently selected status.  If undefined the value of
  608: $env{'form.Status'} is taken.  If that is undefined, a value of 'Active'
  609: is used.
  610: 
  611: $formname: The name of the form.  If defined the onchange attribute of
  612: the selection box is set to document.$formname.submit().
  613: 
  614: $size: the size (number of lines) of the selection box.
  615: 
  616: $onchange: javascript to use when the value is changed.  Enclosed in 
  617: double quotes, ""s, not single quotes.
  618: 
  619: Returns: a perl string as described.
  620: 
  621: =cut
  622: 
  623: ##############################################
  624: ##############################################
  625: sub StatusOptions {
  626:     my ($status, $formName,$size,$onchange)=@_;
  627:     $size = 1 if (!defined($size));
  628:     if (! defined($status)) {
  629:         $status = 'Active';
  630:         $status = $env{'form.Status'} if (exists($env{'form.Status'}));
  631:     }
  632: 
  633:     my $OpSel1 = '';
  634:     my $OpSel2 = '';
  635:     my $OpSel3 = '';
  636: 
  637:     if($status eq 'Any')         { $OpSel3 = ' selected'; }
  638:     elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
  639:     else                         { $OpSel1 = ' selected'; }
  640: 
  641:     my $Str = '';
  642:     $Str .= '<select name="Status"';
  643:     if(defined($formName) && $formName ne '' && ! defined($onchange)) {
  644:         $Str .= ' onchange="document.'.$formName.'.submit()"';
  645:     }
  646:     if (defined($onchange)) {
  647:         $Str .= ' onchange="'.$onchange.'"';
  648:     }
  649:     $Str .= ' size="'.$size.'" ';
  650:     $Str .= '>'."\n";
  651:     $Str .= '<option value="Active" '.$OpSel1.'>'.
  652:         &mt('Currently Enrolled').'</option>'."\n";
  653:     $Str .= '<option value="Expired" '.$OpSel2.'>'.
  654:         &mt('Previously Enrolled').'</option>'."\n";
  655:     $Str .= '<option value="Any" '.$OpSel3.'>'.
  656:         &mt('Any Enrollment Status').'</option>'."\n";
  657:     $Str .= '</select>'."\n";
  658: }
  659: 
  660: ########################################################
  661: ########################################################
  662: 
  663: =pod
  664: 
  665: =item Progess Window Handling Routines
  666: 
  667: These routines handle the creation, update, increment, and closure of 
  668: progress windows.  The progress window reports to the user the number
  669: of items completed and an estimate of the time required to complete the rest.
  670: 
  671: =over 4
  672: 
  673: 
  674: =item &Create_PrgWin
  675: 
  676: Writes javascript to the client to open a progress window and returns a
  677: data structure used for bookkeeping.
  678: 
  679: Inputs
  680: 
  681: =over 4
  682: 
  683: =item $r Apache request
  684: 
  685: =item $title The title of the progress window
  686: 
  687: =item $heading A description (usually 1 line) of the process being initiated.
  688: 
  689: =item $number_to_do The total number of items being processed.
  690: 
  691: =item $type Either 'popup' or 'inline' (popup is assumed if nothing is
  692:        specified)
  693: 
  694: =item $width Specify the width in charaters of the input field.
  695: 
  696: =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
  697: 
  698: =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 
  699: 
  700: =back
  701: 
  702: Returns a hash containing the progress state data structure.
  703: 
  704: 
  705: =item &Update_PrgWin
  706: 
  707: Updates the text in the progress indicator.  Does not increment the count.
  708: See &Increment_PrgWin.
  709: 
  710: Inputs:
  711: 
  712: =over 4
  713: 
  714: =item $r Apache request
  715: 
  716: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
  717: 
  718: =item $displaystring The string to write to the status indicator
  719: 
  720: =back
  721: 
  722: Returns: none
  723: 
  724: 
  725: =item Increment_PrgWin
  726: 
  727: Increment the count of items completed for the progress window by 1.  
  728: 
  729: Inputs:
  730: 
  731: =over 4
  732: 
  733: =item $r Apache request
  734: 
  735: =item $prog_state Pointer to the data structure returned by Create_PrgWin
  736: 
  737: =item $extraInfo A description of the items being iterated over.  Typically
  738: 'student'.
  739: 
  740: =back
  741: 
  742: Returns: none
  743: 
  744: 
  745: =item Close_PrgWin
  746: 
  747: Closes the progress window.
  748: 
  749: Inputs:
  750: 
  751: =over 4 
  752: 
  753: =item $r Apache request
  754: 
  755: =item $prog_state Pointer to the data structure returned by Create_PrgWin
  756: 
  757: =back
  758: 
  759: Returns: none
  760: 
  761: =back
  762: 
  763: =cut
  764: 
  765: ########################################################
  766: ########################################################
  767: 
  768: my $uniq=0;
  769: sub get_uniq_name {
  770:     $uniq++;
  771:     return 'uniquename'.$uniq;
  772: }
  773: 
  774: # Create progress
  775: sub Create_PrgWin {
  776:     my ($r, $title, $heading, $number_to_do,$type,$width,$formname,
  777: 	$inputname)=@_;
  778:     if (!defined($type)) { $type='popup'; }
  779:     if (!defined($width)) { $width=55; }
  780:     my %prog_state;
  781:     $prog_state{'type'}=$type;
  782:     if ($type eq 'popup') {
  783: 	$prog_state{'window'}='popwin';
  784: 	my $html=&Apache::lonxml::xmlbegin();
  785: 	#the whole function called through timeout is due to issues
  786: 	#in mozilla Read BUG #2665 if you want to know the whole story
  787: 	&r_print($r,'<script>'.
  788:         "var popwin;
  789:          function openpopwin () {
  790:          popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
  791:         "popwin.document.writeln(\'".$html."<head><title>$title</title></head>".
  792: 	      "<body bgcolor=\"#88DDFF\">".
  793:               "<h4>$heading</h4>".
  794:               "<form name=popremain>".
  795:               '<input type="text" size="'.$width.'" name="remaining" value="'.
  796: 	      &mt('Starting').'"></form>'.
  797:               "</body></html>\');".
  798:         "popwin.document.close();}".
  799:         "\nwindow.setTimeout(openpopwin,0)</script>");
  800: 	$prog_state{'formname'}='popremain';
  801: 	$prog_state{'inputname'}="remaining";
  802:     } elsif ($type eq 'inline') {
  803: 	$prog_state{'window'}='window';
  804: 	if (!$formname) {
  805: 	    $prog_state{'formname'}=&get_uniq_name();
  806: 	    &r_print($r,'<form name="'.$prog_state{'formname'}.'">');
  807: 	} else {
  808: 	    $prog_state{'formname'}=$formname;
  809: 	}
  810: 	if (!$inputname) {
  811: 	    $prog_state{'inputname'}=&get_uniq_name();
  812: 	    &r_print($r,$heading.' <input type="text" name="'.$prog_state{'inputname'}.
  813: 		     '" size="'.$width.'" />');
  814: 	} else {
  815: 	    $prog_state{'inputname'}=$inputname;
  816: 	    
  817: 	}
  818: 	if (!$formname) { &r_print($r,'</form>'); }
  819: 	&Update_PrgWin($r,\%prog_state,&mt('Starting'));
  820:     }
  821: 
  822:     $prog_state{'done'}=0;
  823:     $prog_state{'firststart'}=&Time::HiRes::time();
  824:     $prog_state{'laststart'}=&Time::HiRes::time();
  825:     $prog_state{'max'}=$number_to_do;
  826:     
  827:     return %prog_state;
  828: }
  829: 
  830: # update progress
  831: sub Update_PrgWin {
  832:     my ($r,$prog_state,$displayString)=@_;
  833:     &r_print($r,'<script>'.$$prog_state{'window'}.'.document.'.
  834: 	     $$prog_state{'formname'}.'.'.
  835: 	     $$prog_state{'inputname'}.'.value="'.
  836: 	     $displayString.'";</script>');
  837:     $$prog_state{'laststart'}=&Time::HiRes::time();
  838: }
  839: 
  840: # increment progress state
  841: sub Increment_PrgWin {
  842:     my ($r,$prog_state,$extraInfo)=@_;
  843:     $$prog_state{'done'}++;
  844:     my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
  845:         $$prog_state{'done'} *
  846: 	($$prog_state{'max'}-$$prog_state{'done'});
  847:     $time_est = int($time_est);
  848:     #
  849:     my $min = int($time_est/60);
  850:     my $sec = $time_est % 60;
  851:     # 
  852:     my $str;
  853:     if ($min == 0 && $sec > 1) {
  854:         $str = '[_2] seconds';
  855:     } elsif ($min == 1 && $sec > 1) {
  856:         $str = '1 minute [_2] seconds';
  857:     } elsif ($min == 1 && $sec < 2) {
  858:         $str = '1 minute';
  859:     } elsif ($min < 10 && $sec > 1) {
  860:         $str = '[_1] minutes, [_2] seconds';
  861:     } elsif ($min >= 10 || $sec < 2) {
  862:         $str = '[_1] minutes';
  863:     }
  864:     $time_est = &mt($str,$min,$sec);
  865:     #
  866:     my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
  867:     if ($lasttime > 9) {
  868:         $lasttime = int($lasttime);
  869:     } elsif ($lasttime < 0.01) {
  870:         $lasttime = 0;
  871:     } else {
  872:         $lasttime = sprintf("%3.2f",$lasttime);
  873:     }
  874:     if ($lasttime == 1) {
  875:         $lasttime = '('.$lasttime.' '.&mt('second for').' '.$extraInfo.')';
  876:     } else {
  877:         $lasttime = '('.$lasttime.' '.&mt('seconds for').' '.$extraInfo.')';
  878:     }
  879:     #
  880:     my $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
  881:     my $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
  882:     if (! defined($user_browser) || ! defined($user_os)) {
  883:         (undef,$user_browser,undef,undef,undef,$user_os) = 
  884:                            &Apache::loncommon::decode_user_agent();
  885:     }
  886:     if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
  887:         $lasttime = '';
  888:     }
  889:     &r_print($r,'<script>'.$$prog_state{'window'}.'.document.'.
  890: 	     $$prog_state{'formname'}.'.'.
  891: 	     $$prog_state{'inputname'}.'.value="'.
  892: 	     $$prog_state{'done'}.'/'.$$prog_state{'max'}.
  893: 	     ': '.$time_est.' '.&mt('remaining').' '.$lasttime.'";'.'</script>');
  894:     $$prog_state{'laststart'}=&Time::HiRes::time();
  895: }
  896: 
  897: # close Progress Line
  898: sub Close_PrgWin {
  899:     my ($r,$prog_state)=@_;
  900:     if ($$prog_state{'type'} eq 'popup') {
  901: 	&r_print($r,'<script>popwin.close()</script>'."\n");
  902:     } elsif ($$prog_state{'type'} eq 'inline') {
  903: 	&Update_PrgWin($r,$prog_state,&mt('Done'));
  904:     }
  905:     undef(%$prog_state);
  906: }
  907: 
  908: sub r_print {
  909:     my ($r,$to_print)=@_;
  910:     if ($r) {
  911: 	$r->print($to_print);
  912: 	$r->rflush();
  913:     } else {
  914: 	print($to_print);
  915:     }
  916: }
  917: 
  918: # ------------------------------------------------------- Puts directory header
  919: 
  920: sub crumbs {
  921:     my ($uri,$target,$prefix,$form,$size,$noformat)=@_;
  922:     if (! defined($size)) {
  923:         $size = '+2';
  924:     }
  925:     if ($target) {
  926:         $target = ' target="'.
  927:                   &Apache::loncommon::escape_single($target).'"';
  928:     }
  929:     my $output='';
  930:     unless ($noformat) { $output.='<br /><tt><b>'; }
  931:     $output.='<font size="'.$size.'">'.$prefix.'/';
  932:     if ($env{'user.adv'}) {
  933: 	my $path=$prefix.'/';
  934: 	foreach my $dir (split('/',$uri)) {
  935:             if (! $dir) { next; }
  936:             $path .= $dir;
  937: 	    unless ($path eq $uri) { $path.='/'; }
  938:             my $linkpath = &Apache::loncommon::escape_single($path);
  939:             if ($form) {
  940: 		$linkpath=
  941:                     qq{javascript:$form.action='$linkpath';$form.submit();};
  942:             }
  943: 	    $output.=qq{<a href="$linkpath" $target>$dir</a>/};
  944: 	}
  945:     } else {
  946: 	$output.=$uri;
  947:     }
  948:     unless ($uri=~/\/$/) { $output=~s/\/$//; }
  949:     return $output.'</font>'.($noformat?'':'</b></tt><br />');
  950: }
  951: 
  952: # --------------------- A function that generates a window for the spellchecker
  953: 
  954: sub spellheader {
  955:     my $html=&Apache::lonxml::xmlbegin();
  956:     my $nothing=&javascript_nothing();
  957:     return (<<ENDCHECK);
  958: <script type="text/javascript"> 
  959: //<!-- BEGIN LON-CAPA Internal
  960: var checkwin;
  961: 
  962: function spellcheckerwindow() {
  963:     checkwin=window.open($nothing,'spellcheckwin','height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
  964:     checkwin.document.writeln('$html<head></head><body bgcolor="#DDDDDD"><form name="spellcheckform" action="/adm/spellcheck" method="post"><input type="hidden" name="text" value="" /></form></body></html>');
  965:     checkwin.document.close();
  966: }
  967: // END LON-CAPA Internal -->
  968: </script>
  969: ENDCHECK
  970: }
  971: 
  972: # ---------------------------------- Generate link to spell checker for a field
  973: 
  974: sub spelllink {
  975:     my ($form,$field)=@_;
  976:     my $linktext=&mt('Check Spelling');
  977:     return (<<ENDLINK);
  978: <a href="javascript:if (typeof(document.$form.onsubmit)!='undefined') { if (document.$form.onsubmit!=null) { document.$form.onsubmit();}};spellcheckerwindow();checkwin.document.forms.spellcheckform.text.value=this.document.forms.$form.$field.value;checkwin.document.forms.spellcheckform.submit();">$linktext</a>
  979: ENDLINK
  980: }
  981: 
  982: # ------------------------------------------------- Output headers for HTMLArea
  983: 
  984: sub htmlareaheaders {
  985:     if (&htmlareablocked()) { return ''; }
  986:     unless (&htmlareabrowser()) { return ''; }
  987:     my $lang='en';
  988:     if (&mt('htmlarea_lang') ne 'htmlarea_lang') {
  989: 	$lang=&mt('htmlarea_lang');
  990:     }
  991:     return (<<ENDHEADERS);
  992: <script type="text/javascript">
  993: _editor_url='/htmlarea/';
  994: _editor_lang='$lang';
  995: </script>
  996: <script type="text/javascript" src="/htmlarea/htmlarea.js"></script>
  997: ENDHEADERS
  998: }
  999: 
 1000: # ------------------------------------------------- Activate additional buttons
 1001: 
 1002: sub htmlareaaddbuttons {
 1003:     if (&htmlareablocked()) { return ''; }
 1004:     unless (&htmlareabrowser()) { return ''; }
 1005:     return (<<ENDADDBUTTON);
 1006:     var config=new HTMLArea.Config();
 1007:     config.registerButton('ed_math','LaTeX Inline',
 1008: 			  '/htmlarea/images/ed_math.gif',false,
 1009: 			    function(editor,id) {
 1010: 			      editor.surroundHTML('&nbsp;<m>\$','\$</m>&nbsp;');
 1011: 			    }
 1012: 			  );
 1013:     config.registerButton('ed_math_eqn','LaTeX Equation',
 1014: 			  '/htmlarea/images/ed_math_eqn.gif',false,
 1015: 			    function(editor,id) {
 1016: 			      editor.surroundHTML(
 1017: 				     '&nbsp;\\n<center><m>\\\\[','\\\\]</m></center>\\n&nbsp;');
 1018: 			    }
 1019: 			  );
 1020:     config.toolbar.push(['ed_math','ed_math_eqn']);
 1021: ENDADDBUTTON
 1022: }
 1023: 
 1024: # ----------------------------------------------------------------- Preferences
 1025: 
 1026: sub disablelink {
 1027:     my @fields=@_;
 1028:     if (defined($#fields)) {
 1029: 	unless ($#fields>=0) { return ''; }
 1030:     }
 1031:     return '<a href="'.&HTML::Entities::encode('/adm/preferences?action=set_wysiwyg&wysiwyg=off&returnurl=','<>&"').&Apache::lonnet::escape($ENV{'REQUEST_URI'}).'">'.&mt('Disable WYSIWYG Editor').'</a>';
 1032: }
 1033: 
 1034: sub enablelink {
 1035:     my @fields=@_;
 1036:     if (defined($#fields)) {
 1037: 	unless ($#fields>=0) { return ''; }
 1038:     }
 1039:     return '<a href="'.&HTML::Entities::encode('/adm/preferences?action=set_wysiwyg&wysiwyg=on&returnurl=','<>&"').&Apache::lonnet::escape($ENV{'REQUEST_URI'}).'">'.&mt('Enable WYSIWYG Editor').'</a>';
 1040: }
 1041: 
 1042: # ----------------------------------------- Script to activate only some fields
 1043: 
 1044: sub htmlareaselectactive {
 1045:     my @fields=@_;
 1046:     unless (&htmlareabrowser()) { return ''; }
 1047:     if (&htmlareablocked()) { return '<br />'.&enablelink(@fields); }
 1048:     my $output='<script type="text/javascript" defer="1">'.
 1049: 	&htmlareaaddbuttons();
 1050:     foreach(@fields) {
 1051: 	$output.="\nHTMLArea.replace('$_',config);";
 1052:     }
 1053:     $output.="\nwindow.status='Activated Editfields';\n</script><br />".
 1054: 	&disablelink(@fields);
 1055:     return $output;
 1056: }
 1057: 
 1058: # --------------------------------------------------------------------- Blocked
 1059: 
 1060: sub htmlareablocked {
 1061:     unless ($env{'environment.wysiwygeditor'} eq 'on') { return 1; }
 1062:     return 0;
 1063: }
 1064: 
 1065: # ---------------------------------------- Browser capable of running HTMLArea?
 1066: 
 1067: sub htmlareabrowser {
 1068:     return 1;
 1069: }
 1070: 
 1071: ############################################################
 1072: ############################################################
 1073: 
 1074: =pod
 1075: 
 1076: =item breadcrumbs
 1077: 
 1078: Compiles the previously registered breadcrumbs into an series of links.
 1079: FAQ and BUG links will be placed on the left side of the table if they
 1080: are defined for the last registered breadcrumb.  
 1081: Additionally supports a 'component', which will be displayed on the
 1082: right side of the table (without a link).
 1083: A link to help for the component will be included if one is specified.
 1084: 
 1085: All inputs can be undef without problems.
 1086: 
 1087: Inputs: $color (the background color of the table returned),
 1088:         $component (the large text on the right side of the table),
 1089:         $component_help
 1090:         $function (role to get colors from)
 1091:         $domain   (domian of role)
 1092:         $menulink (boolean, controls whether to include a link to /adm/menu)
 1093: 
 1094: Returns a string containing breadcrumbs for the current page.
 1095: 
 1096: =item clear_breadcrumbs
 1097: 
 1098: Clears the previously stored breadcrumbs.
 1099: 
 1100: =item add_breadcrumb
 1101: 
 1102: Pushes a breadcrumb on the stack of crumbs.
 1103: 
 1104: input: $breadcrumb, a hash reference.  The keys 'href','title', and 'text'
 1105: are required.  If present the keys 'faq' and 'bug' will be used to provide
 1106: links to the FAQ and bug sites.
 1107: 
 1108: returns: nothing    
 1109: 
 1110: =cut
 1111: 
 1112: ############################################################
 1113: ############################################################
 1114: {
 1115:     my @Crumbs;
 1116:     
 1117:     sub breadcrumbs {
 1118:         my ($color,$component,$component_help,$function,$domain,$menulink,
 1119: 	    $helplink) = @_;
 1120:         if (! defined($color)) {
 1121:             if (! defined($function)) {
 1122:                 $function = &Apache::loncommon::get_users_function();
 1123:             }
 1124:             $color = &Apache::loncommon::designparm($function.'.tabbg',
 1125:                                                     $domain);
 1126:         }
 1127:         #
 1128:         my $Str = "\n".
 1129:             '<table width="100%" border="0" cellpadding="0" cellspacing="0">'.
 1130:             '<tr><td bgcolor="'.$color.'">'.
 1131:             '<font size="-1">';
 1132:         #
 1133:         # Make the faq and bug data cascade
 1134:         my $faq = '';
 1135:         my $bug = '';
 1136: 	my $help='';
 1137:         # The last breadcrumb does not have a link, so handle it separately.
 1138:         my $last = pop(@Crumbs);
 1139:         #
 1140:         # The first one should be the course or a menu link
 1141: 	if (!defined($menulink)) { $menulink=1; }
 1142:         if ($menulink) {
 1143:             my $description = 'Menu';
 1144:             if (exists($env{'request.course.id'}) && 
 1145:                 $env{'request.course.id'} ne '') {
 1146:                 $description = 
 1147:                     $env{'course.'.$env{'request.course.id'}.'.description'};
 1148:             }
 1149:             unshift(@Crumbs,{
 1150:                     href   =>'/adm/menu',
 1151:                     title  =>'Go to main menu',
 1152:                     target =>'_top',
 1153:                     text   =>$description,
 1154:                 });
 1155:         }
 1156:         my $links .= 
 1157:             join('-&gt;',
 1158:                  map {
 1159:                      $faq = $_->{'faq'} if (exists($_->{'faq'}));
 1160:                      $bug = $_->{'bug'} if (exists($_->{'bug'}));
 1161:                      $help = $_->{'help'} if (exists($_->{'help'}));
 1162:                      my $result = '<a href="'.$_->{'href'}.'" ';
 1163:                      if (defined($_->{'target'}) && $_->{'target'} ne '') {
 1164:                          $result .= 'target="'.$_->{'target'}.'" ';
 1165:                      }
 1166:                      $result .='title="'.&mt($_->{'title'}).'">'.
 1167:                          &mt($_->{'text'}).'</a>';
 1168:                      $result;
 1169:                      } @Crumbs
 1170:                  );
 1171:         $links .= '-&gt;' if ($links ne '');
 1172:         $links .= '<b>'.&mt($last->{'text'}).'</b>';
 1173:         #
 1174:         my $icons = '';
 1175:         $faq = $last->{'faq'} if (exists($last->{'faq'}));
 1176:         $bug = $last->{'bug'} if (exists($last->{'bug'}));
 1177:         $help = $last->{'help'} if (exists($last->{'help'}));
 1178:         $component_help=($component_help?$component_help:$help);
 1179: #        if ($faq ne '') {
 1180: #            $icons .= &Apache::loncommon::help_open_faq($faq);
 1181: #        }
 1182: #        if ($bug ne '') {
 1183: #            $icons .= &Apache::loncommon::help_open_bug($bug);
 1184: #        }
 1185: 	if ($helplink ne 'nohelp') {
 1186: 	    $icons .= &Apache::loncommon::help_open_menu($color,$component,$component_help,$function,$faq,$bug);
 1187: 	}
 1188:         if ($icons ne '') {
 1189:             $Str .= $icons.'&nbsp;';
 1190:         }
 1191:         #
 1192:         $Str .= $links.'</font></td>';
 1193:         #
 1194:         if (defined($component)) {
 1195:             $Str .= '<td align="right" bgcolor="'.$color.'">'.
 1196:                 '<font size="+1">'.&mt($component).'</font></td>';
 1197:         }
 1198:         $Str .= '</tr></table>'."\n";
 1199:         #
 1200:         # Return the @Crumbs stack to what we started with
 1201:         push(@Crumbs,$last);
 1202:         shift(@Crumbs);
 1203:         #
 1204:         return $Str;
 1205:     }
 1206: 
 1207:     sub clear_breadcrumbs {
 1208:         undef(@Crumbs);
 1209:     }
 1210: 
 1211:     sub add_breadcrumb {
 1212:         push (@Crumbs,@_);
 1213:     }
 1214: 
 1215: } # End of scope for @Crumbs
 1216: 
 1217: ############################################################
 1218: ############################################################
 1219: 
 1220: # Nested table routines.
 1221: #
 1222: # Routines to display form items in a multi-row table with 2 columns.
 1223: # Uses nested tables to divide form elements into segments.
 1224: # For examples of use see loncom/interface/lonnotify.pm 
 1225: #
 1226: # Can be used in following order: ...
 1227: # &start_pick_box()
 1228: # row1
 1229: # row2
 1230: # row3   ... etc.
 1231: # &submit_row(0
 1232: # &end_pickbox()
 1233: #
 1234: # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
 1235: # &status_select_row and &email_default_row
 1236: #
 1237: # Can also be used in following order:
 1238: #
 1239: # &start_pick_box()
 1240: # &row_title()
 1241: # &row_closure()
 1242: # &row_title()
 1243: # &row_closure()  ... etc.
 1244: # &submit_row()
 1245: # &end_pick_box()
 1246: #
 1247: # In general a &submit_row() call should proceed the call to &end_pick_box(),
 1248: # as this routine adds a button for form submission.
 1249: # &submit_row() does not require a &row_closure after it.
 1250: #  
 1251: # &start_pick_box() creates a bounding table with 1-pixel wide black border.
 1252: # rows should be placed between calls to &start_pick_box() and &end_pick_box.
 1253: #
 1254: # &row_title() adds a title in the left column for each segment.
 1255: # &row_closure() closes a row with a 1-pixel wide black line.
 1256: #
 1257: # &role_select_row() provides a select box from which to choose 1 or more roles 
 1258: # &course_select_row provides ways of picking groups of courses
 1259: #    radio buttons: all, by category or by picking from a course picker pop-up
 1260: #      note: by category option is only displayed if a domain has implemented 
 1261: #                selection by year, semester, department, number etc.
 1262: #
 1263: # &status_select_row() provides a select box from which to choose 1 or more
 1264: #  access types (current access, prior access, and future access)  
 1265: #
 1266: # &email_default_row() provides text boxes for default e-mail suffixes for
 1267: #  different authentication types in a domain.
 1268: #
 1269: # &row_title() and &row_closure() are called internally by the &*_select_row
 1270: # routines, but can also be called directly to start and end rows which have 
 1271: # needs that are not accommodated by the *_select_row() routines.    
 1272: 
 1273: sub start_pick_box {
 1274:     my ($table_width) = @_;
 1275:     my $output = <<"END";
 1276:  <table width="$table_width" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
 1277:   <tr>
 1278:       <td>
 1279:        <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
 1280:         <tr>
 1281:          <td>
 1282:           <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
 1283: END
 1284:     return $output;
 1285: }
 1286: 
 1287: sub end_pick_box {
 1288:     my $output = <<"END";
 1289:        </table>
 1290:       </td>
 1291:      </tr>
 1292:     </table>
 1293:    </td>
 1294:   </tr>
 1295:  </table>
 1296: END
 1297:     return $output;
 1298: }
 1299: 
 1300: sub row_title {
 1301:     my ($col_width,$tablecolor,$title) = @_;
 1302:     my $output = <<"ENDONE";
 1303:            <tr>
 1304:             <td width="$col_width" bgcolor="$tablecolor">
 1305:              <table width="$col_width" border="0" cellpadding="8" cellspacing="0">
 1306:               <tr>
 1307:                <td align="right"><b>$title:</b>
 1308:                </td>
 1309:               </tr>
 1310:              </table>
 1311:             </td>
 1312:             <td width="100%" valign="top">
 1313:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
 1314:               <tr>
 1315: ENDONE
 1316:     return $output;
 1317: }
 1318: 
 1319: sub row_closure {
 1320:     my $output = <<"ENDTWO";
 1321:               </tr>
 1322:              </table>
 1323:             </td>
 1324:            </tr>
 1325:            <tr>
 1326:             <td width="100%" colspan="2" bgcolor="#000000">
 1327:              <img src="/adm/lonMisc/blackdot.gif" /><br />
 1328:             </td>
 1329:            </tr>
 1330: ENDTWO
 1331:     return $output;
 1332: }
 1333: 
 1334: sub role_select_row {
 1335:     my ($roles,$col_width,$tablecolor,$title) = @_;
 1336:     my $output;
 1337:     if (defined($title)) {
 1338:         $output = &row_title($col_width,$tablecolor,$title);
 1339:     }
 1340:     $output .= qq|               <td>
 1341:                                   <select name="roles" multiple >\n|;
 1342:     foreach my $role (@$roles) {
 1343:         my $plrole;
 1344:         if ($role eq 'ow') {
 1345:             $plrole = &mt('Course Owner');
 1346:         } else {
 1347:             $plrole=&Apache::lonnet::plaintext($role);
 1348:         }
 1349:         $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
 1350:     }
 1351:     $output .= qq|                </select>
 1352:                                  </td>\n|;
 1353:     if (defined($title)) {
 1354:         $output .= &row_closure();
 1355:     }
 1356:     return $output;
 1357: }
 1358: 
 1359: sub course_select_row {
 1360:     my ($col_width,$tablecolor,$title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles) = @_;
 1361:     my $output = &row_title($col_width,$tablecolor,$title);
 1362:     $output .= "          <td>\n";
 1363:     $output .= qq|
 1364: <script type="text/javascript" language="Javascript" >
 1365:     function coursePick (formname) {
 1366:         for  (var i=0; i<formname.coursepick.length; i++) {
 1367:             if (formname.coursepick[i].value == 'category') {
 1368:                 courseSet('');
 1369:             }
 1370:             if (!formname.coursepick[i].checked) {
 1371:                 if (formname.coursepick[i].value == 'specific') {
 1372:                     formname.coursetotal.value = 0;
 1373:                     formname.courselist = '';
 1374:                 }
 1375:             }
 1376:         }
 1377:     }
 1378:     function setPick (formname) {
 1379:         for  (var i=0; i<formname.coursepick.length; i++) {
 1380:             if (formname.coursepick[i].value == 'category') {
 1381:                 formname.coursepick[i].checked = true;
 1382:             }
 1383:             formname.coursetotal.value = 0;
 1384:             formname.courselist = '';
 1385:         }
 1386:     }
 1387: </script>
 1388:     |;
 1389:     my $courseform='<b>'.&Apache::loncommon::selectcourse_link
 1390:                      ($formname,'pickcourse','pickdomain','coursedesc').'</b>';
 1391:     if ($totcodes > 0) {
 1392:         $output .= '<input type="radio" name="coursepick" value="all" onclick="coursePick(this.form)" />'.&mt('All courses');
 1393:         my $numtitles = @$codetitles;
 1394:         if ($numtitles > 0) {
 1395:             $output .= '<br /><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 />';
 1396:             $output .= '<table><tr><td>'.$$codetitles[0].'<br />'."\n".
 1397:                '<select name="'.$$codetitles[0].
 1398:                '" onChange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
 1399:                ' <option value="-1" />Select'."\n";
 1400:             my @items = ();
 1401:             my @longitems = ();
 1402:             if ($$idlist{$$codetitles[0]} =~ /","/) {
 1403:                 @items = split(/","/,$$idlist{$$codetitles[0]});
 1404:             } else {
 1405:                 $items[0] = $$idlist{$$codetitles[0]};
 1406:             }
 1407:             if (defined($$idlist_titles{$$codetitles[0]})) {
 1408:                 if ($$idlist_titles{$$codetitles[0]} =~ /","/) {
 1409:                     @longitems = split(/","/,$$idlist_titles{$$codetitles[0]});
 1410:                 } else {
 1411:                     $longitems[0] = $$idlist_titles{$$codetitles[0]};
 1412:                 }
 1413:                 for (my $i=0; $i<@longitems; $i++) {
 1414:                     if ($longitems[$i] eq '') {
 1415:                         $longitems[$i] = $items[$i];
 1416:                     }
 1417:                 }
 1418:             } else {
 1419:                 @longitems = @items;
 1420:             }
 1421:             for (my $i=0; $i<@items; $i++) {
 1422:                 $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
 1423:             }
 1424:             $output .= '</select></td>';
 1425:             for (my $i=1; $i<$numtitles; $i++) {
 1426:                 $output .= '<td>'.$$codetitles[$i].'<br />'."\n".
 1427:                           '<select name="'.$$codetitles[$i].
 1428:                           '" onChange="courseSet('."'$$codetitles[$i]'".')">'."\n".
 1429:                           '<option value="-1">&lt;-Pick '.$$codetitles[$i-1].'</option>'."\n".
 1430:                           '</select>'."\n".
 1431:                           '</td>';
 1432:             }
 1433:             $output .= '</tr></table><br />';
 1434:         }
 1435:     }
 1436:     $output .= '<input type="radio" name="coursepick" value="specific" onclick="coursePick(this.form);opencrsbrowser('."'".'rolefilter'."'".','."'".'dccourse'."'".','."'".'dcdomain'."'".','."'".'coursedesc'."',''".')" />'.&mt('Pick specific course(s):').' '.$courseform.'&nbsp;&nbsp;<input type="text" value="0" size="4" name="coursetotal" /><input type="hidden" name="courselist" value="" />selected.<br /></td>'."\n";
 1437:     $output .= &row_closure();
 1438:     return $output;
 1439: }
 1440: 
 1441: sub status_select_row {
 1442:     my ($types,$col_width,$tablecolor,$title) = @_;
 1443:     my $output; 
 1444:     if (defined($title)) {
 1445:         $output = &row_title($col_width,$tablecolor,$title);
 1446:     }
 1447:     $output .= qq|              <td>
 1448:                                     <select name="types" multiple>\n|;
 1449:     foreach my $status_type (sort(keys(%{$types}))) {
 1450:         $output .= '  <option value="'.$status_type.'">'.$$types{$status_type}.'</option>';
 1451:     }
 1452:     $output .= qq|                   </select>
 1453:                                     </td>\n|; 
 1454:     if (defined($title)) {
 1455:         $output .= &row_closure();
 1456:     }
 1457:     return $output;
 1458: }
 1459: 
 1460: sub email_default_row {
 1461:     my ($authtypes,$col_width,$tablecolor,$title,$descrip) = @_;
 1462:     my $output = &row_title($col_width,$tablecolor,$title);
 1463:     my @rowcols = ('#eeeeee','#dddddd');
 1464:     $output .= '              <td>'.$descrip;
 1465:     $output .= &start_pick_box(''); 
 1466:     $output .= '                <tr bgcolor="'.$tablecolor.'">
 1467:                                  <td><b>'.&mt('Authentication Method').'</b></td><td align="right"><b>'.&mt('Username -> e-mail conversion').'</b></td>
 1468:                                 </tr>'."\n";
 1469:     my $rownum = 0;
 1470:     foreach my $auth (sort(keys(%{$authtypes}))) {
 1471:         my ($userentry,$size);
 1472:         my $rowiter = $rownum%2;
 1473:         if ($auth =~ /^krb/) {
 1474:             $userentry = '';
 1475:             $size = 25;
 1476:         } else {
 1477:             $userentry = 'username@';
 1478:             $size = 15;
 1479:         }
 1480:         $output .= '<tr bgcolor="'.$rowcols[$rowiter].'"><td>  '.$$authtypes{$auth}.'</td><td align="right">'.$userentry.'<input type="text" name="'.$auth.'" size="'.$size.'" /></td></tr>';
 1481:         $rownum ++;
 1482:     }
 1483:     $output .= &end_pick_box();
 1484:     $output .= "                   <br /></td>\n"; 
 1485:     $output .= &row_closure();
 1486:     return $output;
 1487: }
 1488: 
 1489: 
 1490: sub submit_row {
 1491:     my ($col_width,$tablecolor,$title,$cmd,$submit_text) = @_;
 1492:     my $output = &row_title($col_width,$tablecolor,$title);
 1493:     $output .= qq|
 1494:             <td width="100%" valign="top" align="right">
 1495:              <br />
 1496:              <input type="hidden" name="command" value="$cmd" />
 1497:              <input type="submit" value="$submit_text"/> &nbsp;
 1498:              <br /><br />
 1499:             </td>\n|;
 1500:     return $output;
 1501: }
 1502: 
 1503: 1;
 1504: 
 1505: __END__

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