Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.26
1.2 www 1: # The LearningOnline Network with CAPA
2: # a pile of common html routines
3: #
1.26 ! matthew 4: # $Id: lonhtmlcommon.pm,v 1.25 2003/06/19 15:02:37 matthew Exp $
1.2 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.10 matthew 28: ######################################################################
29: ######################################################################
30:
31: =pod
32:
33: =head1 NAME
34:
35: Apache::lonhtmlcommon - routines to do common html things
36:
37: =head1 SYNOPSIS
38:
39: Referenced by other mod_perl Apache modules.
40:
41: =head1 INTRODUCTION
42:
43: lonhtmlcommon is a collection of subroutines used to present information
44: in a consistent html format, or provide other functionality related to
45: html.
46:
47: =head2 General Subroutines
48:
49: =over 4
50:
51: =cut
52:
53: ######################################################################
54: ######################################################################
1.2 www 55:
1.1 stredwic 56: package Apache::lonhtmlcommon;
57:
1.10 matthew 58: use Time::Local;
1.1 stredwic 59: use strict;
60:
1.26 ! matthew 61:
! 62: ##############################################
! 63: ##############################################
! 64:
! 65: =pod
! 66:
! 67: =item textbox
! 68:
! 69: =cut
! 70:
! 71: ##############################################
! 72: ##############################################
! 73: sub textbox {
! 74: my ($name,$value,$size,$special) = @_;
! 75: $size = 40 if (! defined($size));
! 76: my $Str = '<input type="text" name="'.$name.'" size="'.$size.'" '.
! 77: 'value="'.$value.'" '.$special.' />';
! 78: return $Str;
! 79: }
! 80:
! 81: ##############################################
! 82: ##############################################
! 83:
! 84: =pod
! 85:
! 86: =item checkbox
! 87:
! 88: =cut
! 89:
! 90: ##############################################
! 91: ##############################################
! 92: sub checkbox {
! 93: my ($name) = @_;
! 94: my $Str = '<input type="checkbox" name="'.$name.'" />';
! 95: return $Str;
! 96: }
! 97:
! 98:
! 99:
1.10 matthew 100: ##############################################
101: ##############################################
102:
103: =pod
104:
105: =item &date_setter
106:
1.22 matthew 107: &date_setter returns html and javascript for a compact date-setting form.
108: To retrieve values from it, use &get_date_from_form().
109:
1.10 matthew 110: Inputs
111:
112: =over 4
113:
114: =item $dname
115:
116: The name to prepend to the form elements.
117: The form elements defined will be dname_year, dname_month, dname_day,
118: dname_hour, dname_min, and dname_sec.
119:
120: =item $currentvalue
121:
122: The current setting for this time parameter. A unix format time
123: (time in seconds since the beginning of Jan 1st, 1970, GMT.
124: An undefined value is taken to indicate the value is the current time.
125: Also, to be explicit, a value of 'now' also indicates the current time.
126:
1.26 ! matthew 127: =item $special
! 128:
! 129: Additional html/javascript to be associated with each element in
! 130: the date_setter. See lonparmset for example usage.
! 131:
1.22 matthew 132: =back
133:
134: Bugs
135:
136: The method used to restrict user input will fail in the year 2400.
137:
1.10 matthew 138: =cut
139:
140: ##############################################
141: ##############################################
142: sub date_setter {
1.26 ! matthew 143: my ($formname,$dname,$currentvalue,$special) = @_;
1.10 matthew 144: if (! defined($currentvalue) || $currentvalue eq 'now') {
145: $currentvalue = time;
146: }
147: # other potentially useful values: wkday,yrday,is_daylight_savings
148: my ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) =
149: localtime($currentvalue);
150: $year += 1900;
151: my $result = "\n<!-- $dname date setting form -->\n";
152: $result .= <<ENDJS;
153: <script language="Javascript">
154: function $dname\_checkday() {
155: var day = document.$formname.$dname\_day.value;
156: var month = document.$formname.$dname\_month.value;
157: var year = document.$formname.$dname\_year.value;
158: var valid = true;
159: if (day < 1) {
160: document.$formname.$dname\_day.value = 1;
161: }
162: if (day > 31) {
163: document.$formname.$dname\_day.value = 31;
164: }
165: if ((month == 1) || (month == 3) || (month == 5) ||
166: (month == 7) || (month == 8) || (month == 10) ||
167: (month == 12)) {
168: if (day > 31) {
169: document.$formname.$dname\_day.value = 31;
170: day = 31;
171: }
172: } else if (month == 2 ) {
173: if ((year % 4 == 0) && (year % 100 != 0)) {
174: if (day > 29) {
175: document.$formname.$dname\_day.value = 29;
176: }
177: } else if (day > 29) {
178: document.$formname.$dname\_day.value = 28;
179: }
180: } else if (day > 30) {
181: document.$formname.$dname\_day.value = 30;
182: }
183: }
184: </script>
185: ENDJS
1.26 ! matthew 186: $result .= " <nobr><select name=\"$dname\_month\" ".$special.' '.
1.10 matthew 187: "onChange=\"javascript:$dname\_checkday()\" >\n";
188: my @Months = qw/January February March April May June
189: July August September October November December/;
190: # Pad @Months with a bogus value to make indexing easier
191: unshift(@Months,'If you can read this an error occurred');
192: for(my $m = 1;$m <=$#Months;$m++) {
193: $result .= " <option value=\"$m\" ";
194: $result .= "selected " if ($m-1 == $month);
195: $result .= "> $Months[$m] </option>\n";
196: }
197: $result .= " </select>\n";
198: $result .= " <input type=\"text\" name=\"$dname\_day\" ".
1.26 ! matthew 199: "value=\"$mday\" size=\"3\" ".$special.' '.
1.10 matthew 200: "onChange=\"javascript:$dname\_checkday()\" />\n";
201: $result .= " <input type=\"year\" name=\"$dname\_year\" ".
1.26 ! matthew 202: "value=\"$year\" size=\"5\" ".$special.' '.
1.10 matthew 203: "onChange=\"javascript:$dname\_checkday()\" />\n";
204: $result .= " ";
1.26 ! matthew 205: $result .= " <select name=\"$dname\_hour\" ".$special." >\n";
1.10 matthew 206: for (my $h = 0;$h<24;$h++) {
207: $result .= " <option value=\"$h\" ";
208: $result .= "selected " if ($hour == $h);
209: $result .= "> ";
210: if ($h == 0) {
211: $result .= "12 am";
212: } elsif($h == 12) {
213: $result .= "12 noon";
214: } elsif($h < 12) {
215: $result .= "$h am";
216: } else {
217: $result .= $h-12 ." pm";
218: }
219: $result .= " </option>\n";
220: }
221: $result .= " </select>\n";
1.26 ! matthew 222: $result .= " <input type=\"text\" name=\"$dname\_minute\" ".$special.' '.
1.10 matthew 223: "value=\"$min\" size=\"3\" /> m\n";
1.26 ! matthew 224: $result .= " <input type=\"text\" name=\"$dname\_second\" ".$special.' '.
1.10 matthew 225: "value=\"$sec\" size=\"3\" /> s\n";
1.26 ! matthew 226: $result .= "</nobr>\n<!-- end $dname date setting form -->\n";
1.10 matthew 227: return $result;
228: }
229:
230: ##############################################
231: ##############################################
232:
1.22 matthew 233: =pod
234:
1.10 matthew 235: =item &get_date_from_form
1.22 matthew 236:
237: get_date_from_form retrieves the date specified in an &date_setter form.
1.10 matthew 238:
239: Inputs:
240:
241: =over 4
242:
243: =item $dname
244:
245: The name passed to &datesetter, which prefixes the form elements.
246:
247: =item $defaulttime
248:
249: The unix time to use as the default in case of poor inputs.
250:
251: =back
252:
253: Returns: Unix time represented in the form.
254:
255: =cut
256:
257: ##############################################
258: ##############################################
259: sub get_date_from_form {
260: my ($dname) = @_;
261: my ($sec,$min,$hour,$day,$month,$year);
262: #
263: if (defined($ENV{'form.'.$dname.'_second'})) {
264: my $tmpsec = $ENV{'form.'.$dname.'_second'};
265: if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
266: $sec = $tmpsec;
267: }
268: }
269: if (defined($ENV{'form.'.$dname.'_minute'})) {
270: my $tmpmin = $ENV{'form.'.$dname.'_minute'};
271: if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
272: $min = $tmpmin;
273: }
274: }
275: if (defined($ENV{'form.'.$dname.'_hour'})) {
276: my $tmphour = $ENV{'form.'.$dname.'_hour'};
277: if (($tmphour =~ /^\d+$/) && ($tmphour > 0) && ($tmphour < 32)) {
278: $hour = $tmphour;
279: }
280: }
281: if (defined($ENV{'form.'.$dname.'_day'})) {
282: my $tmpday = $ENV{'form.'.$dname.'_day'};
283: if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
284: $day = $tmpday;
285: }
286: }
287: if (defined($ENV{'form.'.$dname.'_month'})) {
288: my $tmpmonth = $ENV{'form.'.$dname.'_month'};
289: if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
290: $month = $tmpmonth - 1;
291: }
292: }
293: if (defined($ENV{'form.'.$dname.'_year'})) {
294: my $tmpyear = $ENV{'form.'.$dname.'_year'};
295: if (($tmpyear =~ /^\d+$/) && ($tmpyear > 1900)) {
296: $year = $tmpyear - 1900;
297: }
298: }
1.24 www 299: if (($year<70) || ($year>137)) { return undef; }
1.10 matthew 300: if (eval(&timelocal($sec,$min,$hour,$day,$month,$year))) {
301: return &timelocal($sec,$min,$hour,$day,$month,$year);
302: } else {
303: return undef;
304: }
1.20 matthew 305: }
306:
307: ##############################################
308: ##############################################
309:
310: =pod
311:
312: =item &pjump_javascript_definition()
313:
314: Returns javascript defining the 'pjump' function, which opens up a
315: parameter setting wizard.
316:
317: =cut
318:
319: ##############################################
320: ##############################################
321: sub pjump_javascript_definition {
322: my $Str = <<END;
323: function pjump(type,dis,value,marker,ret,call) {
324: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
325: +"&value="+escape(value)+"&marker="+escape(marker)
326: +"&return="+escape(ret)
327: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
328: "height=350,width=350,scrollbars=no,menubar=no");
329: }
330: END
331: return $Str;
1.10 matthew 332: }
333:
334: ##############################################
335: ##############################################
1.17 matthew 336:
337: =pod
338:
339: =item &javascript_nothing()
340:
341: Return an appropriate null for the users browser. This is used
342: as the first arguement for window.open calls when you want a blank
343: window that you can then write to.
344:
345: =cut
346:
347: ##############################################
348: ##############################################
349: sub javascript_nothing {
350: # mozilla and other browsers work with "''", but IE on mac does not.
351: my $nothing = "''";
352: my $user_browser;
353: my $user_os;
354: $user_browser = $ENV{'browser.type'} if (exists($ENV{'browser.type'}));
355: $user_os = $ENV{'browser.os'} if (exists($ENV{'browser.os'}));
356: if (! defined($user_browser) || ! defined($user_os)) {
357: (undef,$user_browser,undef,undef,undef,$user_os) =
358: &Apache::loncommon::decode_user_agent();
359: }
360: if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
361: $nothing = "'javascript:void(0);'";
362: }
363: return $nothing;
364: }
365:
1.21 matthew 366:
1.17 matthew 367: ##############################################
368: ##############################################
369:
1.21 matthew 370: =pod
1.17 matthew 371:
1.21 matthew 372: =item &StatusOptions()
1.10 matthew 373:
1.21 matthew 374: Returns html for a selection box which allows the user to choose the
375: enrollment status of students. The selection box name is 'Status'.
1.6 stredwic 376:
1.21 matthew 377: Inputs:
1.6 stredwic 378:
1.21 matthew 379: $status: the currently selected status. If undefined the value of
380: $ENV{'form.Status'} is taken. If that is undefined, a value of 'Active'
381: is used.
1.6 stredwic 382:
1.21 matthew 383: $formname: The name of the form. If defined the onchange attribute of
384: the selection box is set to document.$formname.submit().
1.6 stredwic 385:
1.21 matthew 386: $size: the size (number of lines) of the selection box.
1.6 stredwic 387:
1.21 matthew 388: Returns: a perl string as described.
1.1 stredwic 389:
1.21 matthew 390: =cut
1.9 stredwic 391:
1.21 matthew 392: ##############################################
393: ##############################################
394: sub StatusOptions {
395: my ($status, $formName,$size)=@_;
396: $size = 1 if (!defined($size));
397: if (! defined($status)) {
398: $status = 'Active';
399: $status = $ENV{'form.Status'} if (exists($ENV{'form.Status'}));
1.9 stredwic 400: }
1.1 stredwic 401:
402: my $OpSel1 = '';
403: my $OpSel2 = '';
404: my $OpSel3 = '';
405:
406: if($status eq 'Any') { $OpSel3 = ' selected'; }
407: elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
408: else { $OpSel1 = ' selected'; }
409:
410: my $Str = '';
411: $Str .= '<select name="Status"';
412: if(defined($formName) && $formName ne '') {
413: $Str .= ' onchange="document.'.$formName.'.submit()"';
414: }
1.21 matthew 415: $Str .= ' size="'.$size.'" ';
1.1 stredwic 416: $Str .= '>'."\n";
1.21 matthew 417: $Str .= '<option value="Active" '.$OpSel1.'>'.
418: 'Currently Enrolled</option>'."\n";
419: $Str .= '<option value="Expired" '.$OpSel2.'>'.
420: 'Previously Enrolled</option>'."\n";
421: $Str .= '<option value="Any" '.$OpSel3.'>'.
422: 'Any Enrollment Status</option>'."\n";
1.1 stredwic 423: $Str .= '</select>'."\n";
424: }
425:
1.12 matthew 426:
427: ########################################################
428: ########################################################
429:
430: =pod
431:
432: =item &MultipleSectionSelect()
433:
434: Inputs:
435:
436: =over 4
437:
438: =item $sections A references to an array containing the names of all the
439: sections used in a class.
440:
441: =item $selectedSections A reference to an array containing the names of the
442: currently selected sections.
443:
444: =back
445:
446: Returns: a string containing HTML for a multiple select box for
447: selecting sections of a course.
448:
449: The form element name is 'Section'. @$sections is sorted prior to output.
450:
451: =cut
452:
453: ########################################################
454: ########################################################
1.5 stredwic 455: sub MultipleSectionSelect {
456: my ($sections,$selectedSections)=@_;
457:
458: my $Str = '';
1.7 stredwic 459: $Str .= '<select name="Section" multiple="true" size="4">'."\n";
1.5 stredwic 460:
1.11 minaeibi 461: foreach (sort @$sections) {
1.5 stredwic 462: $Str .= '<option';
463: foreach my $selected (@$selectedSections) {
464: if($_ eq $selected) {
465: $Str .= ' selected=""';
466: }
467: }
468: $Str .= '>'.$_.'</option>'."\n";
469: }
470: $Str .= '</select>'."\n";
1.12 matthew 471:
1.5 stredwic 472: return $Str;
473: }
474:
1.12 matthew 475: ########################################################
476: ########################################################
477:
478: =pod
479:
480: =item &Title()
481:
482: Inputs: $pageName a string containing the name of the page to be sent
483: to &Apache::loncommon::bodytag.
484:
485: Returns: string containing being <html> and complete <head> and <title>
486: as well as a <script> to focus the current window and change its width
487: and height to 500. Why? I do not know. If you find out, please update
488: this documentation.
489:
490: =cut
491:
492: ########################################################
493: ########################################################
1.1 stredwic 494: sub Title {
495: my ($pageName)=@_;
496:
497: my $Str = '';
498:
499: $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
1.8 www 500: $Str .= &Apache::loncommon::bodytag($pageName)."\n";
1.1 stredwic 501: $Str .= '<script>window.focus(); window.width=500;window.height=500;';
502: $Str .= '</script>'."\n";
503:
504: return $Str;
505: }
506:
1.12 matthew 507: ########################################################
508: ########################################################
509:
1.1 stredwic 510: =pod
511:
1.13 matthew 512: =item &CreateHeadings()
1.1 stredwic 513:
514: This function generates the column headings for the chart.
515:
516: =over 4
517:
1.4 stredwic 518: Inputs: $CacheData, $keyID, $headings, $spacePadding
1.1 stredwic 519:
520: $CacheData: pointer to a hash tied to the cached data database
521:
1.4 stredwic 522: $keyID: a pointer to an array containing the names of the data
1.1 stredwic 523: held in a column and is used as part of a key into $CacheData
524:
525: $headings: The names of the headings for the student information
526:
527: $spacePadding: The spaces to go between columns
528:
529: Output: $Str
530:
531: $Str: A formatted string of the table column headings.
532:
533: =back
534:
535: =cut
536:
1.12 matthew 537: ########################################################
538: ########################################################
1.4 stredwic 539: sub CreateHeadings {
540: my ($data,$keyID,$headings,$displayString,$format)=@_;
1.1 stredwic 541: my $Str='';
1.4 stredwic 542: my $formatting = '';
1.1 stredwic 543:
544: for(my $index=0; $index<(scalar @$headings); $index++) {
1.4 stredwic 545: my $currentHeading=$headings->[$index];
546: if($format eq 'preformatted') {
547: my @dataLength=split(//,$currentHeading);
548: my $length=scalar @dataLength;
549: $formatting = (' 'x
550: ($data->{$keyID->[$index].':columnWidth'}-$length));
551: }
552: my $linkdata=$keyID->[$index];
553:
1.1 stredwic 554: my $tempString = $displayString;
555: $tempString =~ s/LINKDATA/$linkdata/;
1.4 stredwic 556: $tempString =~ s/DISPLAYDATA/$currentHeading/;
557: $tempString =~ s/FORMATTING/$formatting/;
558:
1.1 stredwic 559: $Str .= $tempString;
560: }
561:
562: return $Str;
563: }
564:
1.12 matthew 565: ########################################################
566: ########################################################
567:
1.1 stredwic 568: =pod
569:
570: =item &FormatStudentInformation()
571:
1.10 matthew 572: This function produces a formatted string of the student\'s information:
1.1 stredwic 573: username, domain, section, full name, and PID.
574:
575: =over 4
576:
1.4 stredwic 577: Input: $cache, $name, $keyID, $spacePadding
1.1 stredwic 578:
579: $cache: This is a pointer to a hash that is tied to the cached data
580:
581: $name: The name and domain of the current student in name:domain format
582:
1.4 stredwic 583: $keyID: A pointer to an array holding the names used to
1.1 stredwic 584:
585: remove data from the hash. They represent the name of the data to be removed.
586:
587: $spacePadding: Extra spaces that represent the space between columns
588:
589: Output: $Str
590:
591: $Str: Formatted string.
592:
593: =back
594:
595: =cut
596:
1.12 matthew 597: ########################################################
598: ########################################################
1.1 stredwic 599: sub FormatStudentInformation {
1.4 stredwic 600: my ($data,$name,$keyID,$displayString,$format)=@_;
1.1 stredwic 601: my $Str='';
1.4 stredwic 602: my $currentColumn;
603:
604: for(my $index=0; $index<(scalar @$keyID); $index++) {
605: $currentColumn=$data->{$name.':'.$keyID->[$index]};
1.1 stredwic 606:
1.4 stredwic 607: if($format eq 'preformatted') {
608: my @dataLength=split(//,$currentColumn);
609: my $length=scalar @dataLength;
610: $currentColumn.= (' 'x
611: ($data->{$keyID->[$index].':columnWidth'}-$length));
1.1 stredwic 612: }
613:
1.4 stredwic 614: my $tempString = $displayString;
615: $tempString =~ s/DISPLAYDATA/$currentColumn/;
616:
617: $Str .= $tempString;
1.1 stredwic 618: }
619:
620: return $Str;
1.7 stredwic 621: }
1.12 matthew 622:
623: ########################################################
624: ########################################################
1.7 stredwic 625:
1.23 matthew 626: =pod
627:
628: =item Progess Window Handling Routines
629:
630: These routines handle the creation, update, increment, and closure of
631: progress windows. The progress window reports to the user the number
632: of items completed and an estimate of the time required to complete the rest.
633:
634: =over 4
635:
636:
637: =item &Create_PrgWin
638:
639: Writes javascript to the client to open a progress window and returns a
640: data structure used for bookkeeping.
641:
642: Inputs
643:
644: =over 4
645:
646: =item $r Apache request
647:
648: =item $title The title of the progress window
649:
650: =item $heading A description (usually 1 line) of the process being initiated.
651:
652: =item $number_to_do The total number of items being processed.
653:
654: =back
655:
656: Returns a hash containing the progress state data structure.
657:
658:
659: =item &Update_PrgWin
660:
661: Updates the text in the progress indicator. Does not increment the count.
662: See &Increment_PrgWin.
663:
664: Inputs:
665:
666: =over 4
667:
668: =item $r Apache request
669:
670: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
671:
672: =item $displaystring The string to write to the status indicator
673:
674: =back
675:
676: Returns: none
677:
678:
679: =item Increment_PrgWin
680:
681: Increment the count of items completed for the progress window by 1.
682:
683: Inputs:
684:
685: =over 4
686:
687: =item $r Apache request
688:
689: =item $prog_state Pointer to the data structure returned by Create_PrgWin
690:
691: =item $extraInfo A description of the items being iterated over. Typically
692: 'student'.
693:
694: =back
695:
696: Returns: none
697:
698:
699: =item Close_PrgWin
700:
701: Closes the progress window.
702:
703: Inputs:
704:
705: =over 4
706:
707: =item $r Apache request
708:
709: =item $prog_state Pointer to the data structure returned by Create_PrgWin
710:
711: =back
712:
713: Returns: none
714:
715: =back
716:
717: =cut
718:
719: ########################################################
720: ########################################################
721:
1.7 stredwic 722: # Create progress
723: sub Create_PrgWin {
1.14 albertel 724: my ($r, $title, $heading, $number_to_do)=@_;
1.7 stredwic 725: $r->print('<script>'.
726: "popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
1.14 albertel 727: "popwin.document.writeln(\'<html><head><title>$title</title></head>".
728: "<body bgcolor=\"#88DDFF\">".
1.7 stredwic 729: "<h4>$heading</h4>".
730: "<form name=popremain>".
1.14 albertel 731: "<input type=text size=55 name=remaining value=Starting></form>".
1.7 stredwic 732: "</body></html>\');".
733: "popwin.document.close();".
734: "</script>");
735:
1.14 albertel 736: my %prog_state;
1.16 albertel 737: $prog_state{'done'}=0;
1.23 matthew 738: $prog_state{'firststart'}=&Time::HiRes::time();
739: $prog_state{'laststart'}=&Time::HiRes::time();
1.16 albertel 740: $prog_state{'max'}=$number_to_do;
1.14 albertel 741:
1.7 stredwic 742: $r->rflush();
1.14 albertel 743: return %prog_state;
1.7 stredwic 744: }
745:
746: # update progress
747: sub Update_PrgWin {
1.14 albertel 748: my ($r,$prog_state,$displayString)=@_;
1.7 stredwic 749: $r->print('<script>popwin.document.popremain.remaining.value="'.
750: $displayString.'";</script>');
1.23 matthew 751: $$prog_state{'laststart'}=&Time::HiRes::time();
1.14 albertel 752: $r->rflush();
753: }
754:
755: # increment progress state
756: sub Increment_PrgWin {
757: my ($r,$prog_state,$extraInfo)=@_;
1.16 albertel 758: $$prog_state{'done'}++;
1.23 matthew 759: my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
760: $$prog_state{'done'} *
1.16 albertel 761: ($$prog_state{'max'}-$$prog_state{'done'});
762: $time_est = int($time_est);
763: if (int ($time_est/60) > 0) {
764: my $min = int($time_est/60);
765: my $sec = $time_est % 60;
766: $time_est = $min.' minutes';
1.25 matthew 767: if ($min < 10) {
768: if ($sec > 1) {
769: $time_est.= ', '.$sec.' seconds';
770: } elsif ($sec > 0) {
771: $time_est.= ', '.$sec.' second';
772: }
773: }
1.16 albertel 774: } else {
775: $time_est .= ' seconds';
776: }
1.23 matthew 777: my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
778: if ($lasttime > 9) {
779: $lasttime = int($lasttime);
780: } elsif ($lasttime < 0.01) {
781: $lasttime = 0;
782: } else {
783: $lasttime = sprintf("%3.2f",$lasttime);
784: }
1.19 matthew 785: if ($lasttime == 1) {
786: $lasttime = '('.$lasttime.' second for '.$extraInfo.')';
787: } else {
788: $lasttime = '('.$lasttime.' seconds for '.$extraInfo.')';
789: }
1.14 albertel 790: $r->print('<script>popwin.document.popremain.remaining.value="'.
1.16 albertel 791: $$prog_state{'done'}.'/'.$$prog_state{'max'}.
1.19 matthew 792: ': '.$time_est.' remaining '.$lasttime.'";'.'</script>');
1.23 matthew 793: $$prog_state{'laststart'}=&Time::HiRes::time();
1.7 stredwic 794: $r->rflush();
795: }
796:
797: # close Progress Line
798: sub Close_PrgWin {
1.14 albertel 799: my ($r,$prog_state)=@_;
1.7 stredwic 800: $r->print('<script>popwin.close()</script>'."\n");
1.14 albertel 801: undef(%$prog_state);
1.7 stredwic 802: $r->rflush();
1.1 stredwic 803: }
804:
805: 1;
1.23 matthew 806:
1.1 stredwic 807: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>