File:  [LON-CAPA] / loncom / interface / lonhtmlcommon.pm
Revision 1.46: download - view: text, annotated - select for diffs
Thu Feb 12 22:23:30 2004 UTC (20 years, 3 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
lonstatistics: Removed use of lonhtmlcommon::Title.
lonhtmlcommon: Removed unused statistics subroutines.

    1: # The LearningOnline Network with CAPA
    2: # a pile of common html routines
    3: #
    4: # $Id: lonhtmlcommon.pm,v 1.46 2004/02/12 22:23:30 matthew 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 Time::Local;
   59: use Apache::lonlocal;
   60: use strict;
   61: 
   62: 
   63: ##############################################
   64: ##############################################
   65: 
   66: =pod
   67: 
   68: =item authorbombs
   69: 
   70: =cut
   71: 
   72: ##############################################
   73: ##############################################
   74: 
   75: sub authorbombs {
   76:     my $url=shift;
   77:     $url=&Apache::lonnet::declutter($url);
   78:     my ($udom,$uname)=($url=~/^(\w+)\/(\w+)\//);
   79:     my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
   80:     foreach (keys %bombs) {
   81: 	if ($_=~/^$udom\/$uname\//) {
   82: 	    return '<a href="/adm/bombs/'.$url.
   83: 		'"><img src="/adm/lonMisc/bomb.gif" border="0" /></a>'.
   84: 		&Apache::loncommon::help_open_topic('About_Bombs');
   85: 	}
   86:     }
   87:     return '';
   88: }
   89: 
   90: ##############################################
   91: ##############################################
   92: 
   93: sub recent_filename {
   94:     my $area=shift;
   95:     return 'nohist_recent_'.&Apache::lonnet::escape($area);
   96: }
   97: 
   98: sub store_recent {
   99:     my ($area,$name,$value)=@_;
  100:     my $file=&recent_filename($area);
  101:     my %recent=&Apache::lonnet::dump($file);
  102:     if (scalar(keys(%recent))>10) {
  103: # remove oldest value
  104: 	my $oldest=time;
  105: 	my $delkey='';
  106: 	foreach (keys %recent) {
  107: 	    my $thistime=(split(/\&/,$recent{$_}))[0];
  108: 	    if ($thistime<$oldest) {
  109: 		$oldest=$thistime;
  110: 		$delkey=$_;
  111: 	    }
  112: 	}
  113: 	&Apache::lonnet::del($file,[$delkey]);
  114:     }
  115: # store new value
  116:     &Apache::lonnet::put($file,{ $name => 
  117: 				 time.'&'.&Apache::lonnet::escape($value) });
  118: }
  119: 
  120: sub select_recent {
  121:     my ($area,$fieldname,$event)=@_;
  122:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
  123:     my $return="\n<select name='$fieldname'".
  124: 	($event?" onChange='$event'":'').
  125: 	">\n<option value=''>--- ".&mt('Recent')." ---</option>";
  126:     foreach (sort keys %recent) {
  127: 	unless ($_=~/^error\:/) {
  128: 	    $return.="\n<option value='$_'>".
  129: 		&Apache::lonnet::unescape((split(/\&/,$recent{$_}))[1]).
  130: 		'</option>';
  131: 	}
  132:     }
  133:     $return.="\n</select>\n";
  134:     return $return;
  135: }
  136: 
  137: 
  138: =pod
  139: 
  140: =item textbox
  141: 
  142: =cut
  143: 
  144: ##############################################
  145: ##############################################
  146: sub textbox {
  147:     my ($name,$value,$size,$special) = @_;
  148:     $size = 40 if (! defined($size));
  149:     my $Str = '<input type="text" name="'.$name.'" size="'.$size.'" '.
  150:         'value="'.$value.'" '.$special.' />';
  151:     return $Str;
  152: }
  153: 
  154: ##############################################
  155: ##############################################
  156: 
  157: =pod
  158: 
  159: =item checkbox
  160: 
  161: =cut
  162: 
  163: ##############################################
  164: ##############################################
  165: sub checkbox {
  166:     my ($name,$value) = @_;
  167:     my $Str = '<input type="checkbox" name="'.$name.'"'.
  168: 	($value?' checked="1"':'').' />';
  169:     return $Str;
  170: }
  171: 
  172: ##############################################
  173: ##############################################
  174: 
  175: =pod
  176: 
  177: =item &date_setter
  178: 
  179: &date_setter returns html and javascript for a compact date-setting form.
  180: To retrieve values from it, use &get_date_from_form().
  181: 
  182: Inputs
  183: 
  184: =over 4
  185: 
  186: =item $dname 
  187: 
  188: The name to prepend to the form elements.  
  189: The form elements defined will be dname_year, dname_month, dname_day,
  190: dname_hour, dname_min, and dname_sec.
  191: 
  192: =item $currentvalue
  193: 
  194: The current setting for this time parameter.  A unix format time
  195: (time in seconds since the beginning of Jan 1st, 1970, GMT.  
  196: An undefined value is taken to indicate the value is the current time.
  197: Also, to be explicit, a value of 'now' also indicates the current time.
  198: 
  199: =item $special
  200: 
  201: Additional html/javascript to be associated with each element in
  202: the date_setter.  See lonparmset for example usage.
  203: 
  204: =back
  205: 
  206: Bugs
  207: 
  208: The method used to restrict user input will fail in the year 2400.
  209: 
  210: =cut
  211: 
  212: ##############################################
  213: ##############################################
  214: sub date_setter {
  215:     my ($formname,$dname,$currentvalue,$special,$includeempty) = @_;
  216:     if (! defined($currentvalue) || $currentvalue eq 'now') {
  217: 	unless ($includeempty) {
  218: 	    $currentvalue = time;
  219: 	} else {
  220: 	    $currentvalue = 0;
  221: 	}
  222:     }
  223:     # other potentially useful values:     wkday,yrday,is_daylight_savings
  224:     my ($sec,$min,$hour,$mday,$month,$year)=('','','','','','');
  225:     if ($currentvalue) {
  226: 	($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = 
  227: 	    localtime($currentvalue);
  228: 	$year += 1900;
  229:     }
  230:     my $result = "\n<!-- $dname date setting form -->\n";
  231:     $result .= <<ENDJS;
  232: <script language="Javascript">
  233:     function $dname\_checkday() {
  234:         var day   = document.$formname.$dname\_day.value;
  235:         var month = document.$formname.$dname\_month.value;
  236:         var year  = document.$formname.$dname\_year.value;
  237:         var valid = true;
  238:         if (day < 1) {
  239:             document.$formname.$dname\_day.value = 1;
  240:         } 
  241:         if (day > 31) {
  242:             document.$formname.$dname\_day.value = 31;
  243:         }
  244:         if ((month == 1)  || (month == 3)  || (month == 5)  ||
  245:             (month == 7)  || (month == 8)  || (month == 10) ||
  246:             (month == 12)) {
  247:             if (day > 31) {
  248:                 document.$formname.$dname\_day.value = 31;
  249:                 day = 31;
  250:             }
  251:         } else if (month == 2 ) {
  252:             if ((year % 4 == 0) && (year % 100 != 0)) {
  253:                 if (day > 29) {
  254:                     document.$formname.$dname\_day.value = 29;
  255:                 }
  256:             } else if (day > 29) {
  257:                 document.$formname.$dname\_day.value = 28;
  258:             }
  259:         } else if (day > 30) {
  260:             document.$formname.$dname\_day.value = 30;
  261:         }
  262:     }
  263: 
  264:     function $dname\_opencalendar() {
  265:        var calwin=window.open(
  266: "/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
  267: document.$formname.$dname\_month.value+"&year="+
  268: document.$formname.$dname\_year.value,
  269:              "LONCAPAcal",
  270:               "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
  271: 
  272:     }
  273: </script>
  274: ENDJS
  275:     $result .= "  <nobr><select name=\"$dname\_month\" ".$special.' '.
  276:         "onChange=\"javascript:$dname\_checkday()\" >\n";
  277:     my @Months = qw/January February  March     April   May      June 
  278:                     July    August    September October November December/;
  279:     # Pad @Months with a bogus value to make indexing easier
  280:     unshift(@Months,'If you can read this an error occurred');
  281:     if ($includeempty) { $result.="<option value=''></option>"; }
  282:     for(my $m = 1;$m <=$#Months;$m++) {
  283:         $result .= "      <option value=\"$m\" ";
  284:         $result .= "selected " if ($m-1 eq $month);
  285:         $result .= "> ".&mt($Months[$m])." </option>\n";
  286:     }
  287:     $result .= "  </select>\n";
  288:     $result .= "  <input type=\"text\" name=\"$dname\_day\" ".
  289:             "value=\"$mday\" size=\"3\" ".$special.' '.
  290:             "onChange=\"javascript:$dname\_checkday()\" />\n";
  291:     $result .= "  <input type=\"year\" name=\"$dname\_year\" ".
  292:             "value=\"$year\" size=\"5\" ".$special.' '.
  293:             "onChange=\"javascript:$dname\_checkday()\" />\n";
  294:     $result .= "&nbsp;&nbsp;";
  295:     $result .= "  <select name=\"$dname\_hour\" ".$special." >\n";
  296:     if ($includeempty) { $result.="<option value=''></option>"; }
  297:     for (my $h = 0;$h<24;$h++) {
  298:         $result .= "      <option value=\"$h\" ";
  299:         $result .= "selected " if ($hour == $h);
  300:         $result .= "> ";
  301: 	my $timest='';
  302:         if ($h == 0) {
  303:             $timest .= "12 am";
  304:         } elsif($h == 12) {
  305:             $timest .= "12 noon";
  306:         } elsif($h < 12) {
  307:             $timest .= "$h am";
  308:         } else {
  309:             $timest .= $h-12 ." pm";
  310:         }
  311: 	$timest=&mt($timest);
  312:         $result .= $timest." </option>\n";
  313:     } 
  314:     $result .= "  </select>\n";
  315:     $result .= "  <input type=\"text\" name=\"$dname\_minute\" ".$special.' '.
  316:         "value=\"$min\" size=\"3\" /> m\n";
  317:     $result .= "  <input type=\"text\" name=\"$dname\_second\" ".$special.' '.
  318:         "value=\"$sec\" size=\"3\" /> s\n";
  319:     $result .= "<a href=\"javascript:$dname\_opencalendar()\">".
  320:     &mt('Select Date')."</a></nobr>\n<!-- end $dname date setting form -->\n";
  321:     return $result;
  322: }
  323: 
  324: ##############################################
  325: ##############################################
  326: 
  327: =pod
  328: 
  329: =item &get_date_from_form
  330: 
  331: get_date_from_form retrieves the date specified in an &date_setter form.
  332: 
  333: Inputs:
  334: 
  335: =over 4
  336: 
  337: =item $dname
  338: 
  339: The name passed to &datesetter, which prefixes the form elements.
  340: 
  341: =item $defaulttime
  342: 
  343: The unix time to use as the default in case of poor inputs.
  344: 
  345: =back
  346: 
  347: Returns: Unix time represented in the form.
  348: 
  349: =cut
  350: 
  351: ##############################################
  352: ##############################################
  353: sub get_date_from_form {
  354:     my ($dname) = @_;
  355:     my ($sec,$min,$hour,$day,$month,$year);
  356:     #
  357:     if (defined($ENV{'form.'.$dname.'_second'})) {
  358:         my $tmpsec = $ENV{'form.'.$dname.'_second'};
  359:         if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
  360:             $sec = $tmpsec;
  361:         }
  362:     }
  363:     if (defined($ENV{'form.'.$dname.'_minute'})) {
  364:         my $tmpmin = $ENV{'form.'.$dname.'_minute'};
  365:         if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
  366:             $min = $tmpmin;
  367:         }
  368:     }
  369:     if (defined($ENV{'form.'.$dname.'_hour'})) {
  370:         my $tmphour = $ENV{'form.'.$dname.'_hour'};
  371:         if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
  372:             $hour = $tmphour;
  373:         }
  374:     }
  375:     if (defined($ENV{'form.'.$dname.'_day'})) {
  376:         my $tmpday = $ENV{'form.'.$dname.'_day'};
  377:         if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
  378:             $day = $tmpday;
  379:         }
  380:     }
  381:     if (defined($ENV{'form.'.$dname.'_month'})) {
  382:         my $tmpmonth = $ENV{'form.'.$dname.'_month'};
  383:         if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
  384:             $month = $tmpmonth - 1;
  385:         }
  386:     }
  387:     if (defined($ENV{'form.'.$dname.'_year'})) {
  388:         my $tmpyear = $ENV{'form.'.$dname.'_year'};
  389:         if (($tmpyear =~ /^\d+$/) && ($tmpyear > 1900)) {
  390:             $year = $tmpyear - 1900;
  391:         }
  392:     }
  393:     if (($year<70) || ($year>137)) { return undef; }
  394:     if (defined($sec) && defined($min)   && defined($hour) &&
  395:         defined($day) && defined($month) && defined($year) &&
  396:         eval(&timelocal($sec,$min,$hour,$day,$month,$year))) {
  397:         return &timelocal($sec,$min,$hour,$day,$month,$year);
  398:     } else {
  399:         return undef;
  400:     }
  401: }
  402: 
  403: ##############################################
  404: ##############################################
  405: 
  406: =pod
  407: 
  408: =item &pjump_javascript_definition()
  409: 
  410: Returns javascript defining the 'pjump' function, which opens up a
  411: parameter setting wizard.
  412: 
  413: =cut
  414: 
  415: ##############################################
  416: ##############################################
  417: sub pjump_javascript_definition {
  418:     my $Str = <<END;
  419:     function pjump(type,dis,value,marker,ret,call) {
  420:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
  421:                  +"&value="+escape(value)+"&marker="+escape(marker)
  422:                  +"&return="+escape(ret)
  423:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
  424:                  "height=350,width=350,scrollbars=no,menubar=no");
  425:     }
  426: END
  427:     return $Str;
  428: }
  429: 
  430: ##############################################
  431: ##############################################
  432: 
  433: =pod
  434: 
  435: =item &javascript_nothing()
  436: 
  437: Return an appropriate null for the users browser.  This is used
  438: as the first arguement for window.open calls when you want a blank
  439: window that you can then write to.
  440: 
  441: =cut
  442: 
  443: ##############################################
  444: ##############################################
  445: sub javascript_nothing {
  446:     # mozilla and other browsers work with "''", but IE on mac does not.
  447:     my $nothing = "''";
  448:     my $user_browser;
  449:     my $user_os;
  450:     $user_browser = $ENV{'browser.type'} if (exists($ENV{'browser.type'}));
  451:     $user_os      = $ENV{'browser.os'}   if (exists($ENV{'browser.os'}));
  452:     if (! defined($user_browser) || ! defined($user_os)) {
  453:         (undef,$user_browser,undef,undef,undef,$user_os) = 
  454:                            &Apache::loncommon::decode_user_agent();
  455:     }
  456:     if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
  457:         $nothing = "'javascript:void(0);'";
  458:     }
  459:     return $nothing;
  460: }
  461: 
  462: 
  463: ##############################################
  464: ##############################################
  465: 
  466: =pod
  467: 
  468: =item &StatusOptions()
  469: 
  470: Returns html for a selection box which allows the user to choose the
  471: enrollment status of students.  The selection box name is 'Status'.
  472: 
  473: Inputs:
  474: 
  475: $status: the currently selected status.  If undefined the value of
  476: $ENV{'form.Status'} is taken.  If that is undefined, a value of 'Active'
  477: is used.
  478: 
  479: $formname: The name of the form.  If defined the onchange attribute of
  480: the selection box is set to document.$formname.submit().
  481: 
  482: $size: the size (number of lines) of the selection box.
  483: 
  484: $onchange: javascript to use when the value is changed.  Enclosed in 
  485: double quotes, ""s, not single quotes.
  486: 
  487: Returns: a perl string as described.
  488: 
  489: =cut
  490: 
  491: ##############################################
  492: ##############################################
  493: sub StatusOptions {
  494:     my ($status, $formName,$size,$onchange)=@_;
  495:     $size = 1 if (!defined($size));
  496:     if (! defined($status)) {
  497:         $status = 'Active';
  498:         $status = $ENV{'form.Status'} if (exists($ENV{'form.Status'}));
  499:     }
  500: 
  501:     my $OpSel1 = '';
  502:     my $OpSel2 = '';
  503:     my $OpSel3 = '';
  504: 
  505:     if($status eq 'Any')         { $OpSel3 = ' selected'; }
  506:     elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
  507:     else                         { $OpSel1 = ' selected'; }
  508: 
  509:     my $Str = '';
  510:     $Str .= '<select name="Status"';
  511:     if(defined($formName) && $formName ne '' && ! defined($onchange)) {
  512:         $Str .= ' onchange="document.'.$formName.'.submit()"';
  513:     }
  514:     if (defined($onchange)) {
  515:         $Str .= ' onchange="'.$onchange.'"';
  516:     }
  517:     $Str .= ' size="'.$size.'" ';
  518:     $Str .= '>'."\n";
  519:     $Str .= '<option value="Active" '.$OpSel1.'>'.
  520:         &mt('Currently Enrolled').'</option>'."\n";
  521:     $Str .= '<option value="Expired" '.$OpSel2.'>'.
  522:         &mt('Previously Enrolled').'</option>'."\n";
  523:     $Str .= '<option value="Any" '.$OpSel3.'>'.
  524:         &mt('Any Enrollment Status').'</option>'."\n";
  525:     $Str .= '</select>'."\n";
  526: }
  527: 
  528: ########################################################
  529: ########################################################
  530: 
  531: =pod
  532: 
  533: =item Progess Window Handling Routines
  534: 
  535: These routines handle the creation, update, increment, and closure of 
  536: progress windows.  The progress window reports to the user the number
  537: of items completed and an estimate of the time required to complete the rest.
  538: 
  539: =over 4
  540: 
  541: 
  542: =item &Create_PrgWin
  543: 
  544: Writes javascript to the client to open a progress window and returns a
  545: data structure used for bookkeeping.
  546: 
  547: Inputs
  548: 
  549: =over 4
  550: 
  551: =item $r Apache request
  552: 
  553: =item $title The title of the progress window
  554: 
  555: =item $heading A description (usually 1 line) of the process being initiated.
  556: 
  557: =item $number_to_do The total number of items being processed.
  558: 
  559: =back
  560: 
  561: Returns a hash containing the progress state data structure.
  562: 
  563: 
  564: =item &Update_PrgWin
  565: 
  566: Updates the text in the progress indicator.  Does not increment the count.
  567: See &Increment_PrgWin.
  568: 
  569: Inputs:
  570: 
  571: =over 4
  572: 
  573: =item $r Apache request
  574: 
  575: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
  576: 
  577: =item $displaystring The string to write to the status indicator
  578: 
  579: =back
  580: 
  581: Returns: none
  582: 
  583: 
  584: =item Increment_PrgWin
  585: 
  586: Increment the count of items completed for the progress window by 1.  
  587: 
  588: Inputs:
  589: 
  590: =over 4
  591: 
  592: =item $r Apache request
  593: 
  594: =item $prog_state Pointer to the data structure returned by Create_PrgWin
  595: 
  596: =item $extraInfo A description of the items being iterated over.  Typically
  597: 'student'.
  598: 
  599: =back
  600: 
  601: Returns: none
  602: 
  603: 
  604: =item Close_PrgWin
  605: 
  606: Closes the progress window.
  607: 
  608: Inputs:
  609: 
  610: =over 4 
  611: 
  612: =item $r Apache request
  613: 
  614: =item $prog_state Pointer to the data structure returned by Create_PrgWin
  615: 
  616: =back
  617: 
  618: Returns: none
  619: 
  620: =back
  621: 
  622: =cut
  623: 
  624: ########################################################
  625: ########################################################
  626: 
  627: # Create progress
  628: sub Create_PrgWin {
  629:     my ($r, $title, $heading, $number_to_do)=@_;
  630:     #the whole function called through timeout is due to issues
  631:     #in mozilla Read BUG #2665 if you want to know the whole story
  632:     $r->print('<script>'.
  633:     "var popwin;
  634:      function openpopwin () {
  635:      popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
  636:     "popwin.document.writeln(\'<html><head><title>$title</title></head>".
  637: 	      "<body bgcolor=\"#88DDFF\">".
  638:               "<h4>$heading</h4>".
  639:               "<form name=popremain>".
  640:               '<input type="text" size="55" name="remaining" value="'.
  641: 	      &mt('Starting').'"></form>'.
  642:               "</body></html>\');".
  643:     "popwin.document.close();}".
  644:     "\nwindow.setTimeout(openpopwin,0)</script>");
  645: 
  646:     my %prog_state;
  647:     $prog_state{'done'}=0;
  648:     $prog_state{'firststart'}=&Time::HiRes::time();
  649:     $prog_state{'laststart'}=&Time::HiRes::time();
  650:     $prog_state{'max'}=$number_to_do;
  651: 
  652:     $r->rflush();
  653:     return %prog_state;
  654: }
  655: 
  656: # update progress
  657: sub Update_PrgWin {
  658:     my ($r,$prog_state,$displayString)=@_;
  659:     $r->print('<script>popwin.document.popremain.remaining.value="'.
  660:               $displayString.'";</script>');
  661:     $$prog_state{'laststart'}=&Time::HiRes::time();
  662:     $r->rflush();
  663: }
  664: 
  665: # increment progress state
  666: sub Increment_PrgWin {
  667:     my ($r,$prog_state,$extraInfo)=@_;
  668:     $$prog_state{'done'}++;
  669:     my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
  670:         $$prog_state{'done'} *
  671: 	($$prog_state{'max'}-$$prog_state{'done'});
  672:     $time_est = int($time_est);
  673:     if (int ($time_est/60) > 0) {
  674: 	my $min = int($time_est/60);
  675: 	my $sec = $time_est % 60;
  676: 	$time_est = $min.' '.&mt('minutes');
  677:         if ($min < 10)  {
  678:             if ($sec > 1) {
  679:                 $time_est.= ', '.$sec.' '.&mt('seconds');
  680:             } elsif ($sec > 0) {
  681:                 $time_est.= ', '.$sec.' '.&mt('second');
  682:             }
  683:         }
  684:     } else {
  685: 	$time_est .= ' '.&mt('seconds');
  686:     }
  687:     my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
  688:     if ($lasttime > 9) {
  689:         $lasttime = int($lasttime);
  690:     } elsif ($lasttime < 0.01) {
  691:         $lasttime = 0;
  692:     } else {
  693:         $lasttime = sprintf("%3.2f",$lasttime);
  694:     }
  695:     if ($lasttime == 1) {
  696:         $lasttime = '('.$lasttime.' '.&mt('second for').' '.$extraInfo.')';
  697:     } else {
  698:         $lasttime = '('.$lasttime.' '.&mt('seconds for').' '.$extraInfo.')';
  699:     }
  700:     #
  701:     my $user_browser = $ENV{'browser.type'} if (exists($ENV{'browser.type'}));
  702:     my $user_os      = $ENV{'browser.os'}   if (exists($ENV{'browser.os'}));
  703:     if (! defined($user_browser) || ! defined($user_os)) {
  704:         (undef,$user_browser,undef,undef,undef,$user_os) = 
  705:                            &Apache::loncommon::decode_user_agent();
  706:     }
  707:     if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
  708:         $lasttime = '';
  709:     }
  710:     $r->print('<script>popwin.document.popremain.remaining.value="'.
  711: 	      $$prog_state{'done'}.'/'.$$prog_state{'max'}.
  712: 	      ': '.$time_est.' '.&mt('remaining').' '.$lasttime.'";'.'</script>');
  713:     $$prog_state{'laststart'}=&Time::HiRes::time();
  714:     $r->rflush();
  715: }
  716: 
  717: # close Progress Line
  718: sub Close_PrgWin {
  719:     my ($r,$prog_state)=@_;
  720:     $r->print('<script>popwin.close()</script>'."\n");
  721:     undef(%$prog_state);
  722:     $r->rflush(); 
  723: }
  724: 
  725: 
  726: # ------------------------------------------------------- Puts directory header
  727: 
  728: sub crumbs {
  729:     my ($uri,$target,$prefix,$form)=@_;
  730:     my $output='<br /><tt><b><font size="+2">'.$prefix.'/';
  731:     if ($ENV{'user.adv'}) {
  732: 	my $path=$prefix.'/';
  733: 	foreach (split('/',$uri)) {
  734: 	    unless ($_) { next; }
  735: 	    $path.=$_;
  736: 	    unless ($path eq $uri) { $path.='/'; }
  737: 	    my $linkpath=$path;
  738: 	    if ($form) {
  739: 		$linkpath="javascript:$form.action='$path';$form.submit();";
  740: 	    }
  741: 	    $output.='<a href="'.$linkpath.'"'.($target?' target="'.$target.'"':'').'>'.$_.'</a>/';
  742: 	}
  743:     } else {
  744: 	$output.=$uri;
  745:     }
  746:     unless ($uri=~/\/$/) { $output=~s/\/$//; }
  747:     return $output.'</font></b></tt><br />';
  748: }
  749: 
  750: 
  751: 1;
  752: 
  753: __END__

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