File:  [LON-CAPA] / loncom / interface / lonhtmlcommon.pm
Revision 1.48: download - view: text, annotated - select for diffs
Mon Feb 16 21:49:16 2004 UTC (20 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- better solution to the "no request object" problem

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

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