1: # The LearningOnline Network with CAPA
2: # a pile of common html routines
3: #
4: # $Id: lonhtmlcommon.pm,v 1.41 2004/01/26 19:55:44 www 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: ##############################################
176:
177: =pod
178:
179: =item &date_setter
180:
181: &date_setter returns html and javascript for a compact date-setting form.
182: To retrieve values from it, use &get_date_from_form().
183:
184: Inputs
185:
186: =over 4
187:
188: =item $dname
189:
190: The name to prepend to the form elements.
191: The form elements defined will be dname_year, dname_month, dname_day,
192: dname_hour, dname_min, and dname_sec.
193:
194: =item $currentvalue
195:
196: The current setting for this time parameter. A unix format time
197: (time in seconds since the beginning of Jan 1st, 1970, GMT.
198: An undefined value is taken to indicate the value is the current time.
199: Also, to be explicit, a value of 'now' also indicates the current time.
200:
201: =item $special
202:
203: Additional html/javascript to be associated with each element in
204: the date_setter. See lonparmset for example usage.
205:
206: =back
207:
208: Bugs
209:
210: The method used to restrict user input will fail in the year 2400.
211:
212: =cut
213:
214: ##############################################
215: ##############################################
216: sub date_setter {
217: my ($formname,$dname,$currentvalue,$special,$includeempty) = @_;
218: if (! defined($currentvalue) || $currentvalue eq 'now') {
219: unless ($includeempty) {
220: $currentvalue = time;
221: } else {
222: $currentvalue = 0;
223: }
224: }
225: # other potentially useful values: wkday,yrday,is_daylight_savings
226: my ($sec,$min,$hour,$mday,$month,$year)=('','','','','','');
227: if ($currentvalue) {
228: ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) =
229: localtime($currentvalue);
230: $year += 1900;
231: }
232: my $result = "\n<!-- $dname date setting form -->\n";
233: $result .= <<ENDJS;
234: <script language="Javascript">
235: function $dname\_checkday() {
236: var day = document.$formname.$dname\_day.value;
237: var month = document.$formname.$dname\_month.value;
238: var year = document.$formname.$dname\_year.value;
239: var valid = true;
240: if (day < 1) {
241: document.$formname.$dname\_day.value = 1;
242: }
243: if (day > 31) {
244: document.$formname.$dname\_day.value = 31;
245: }
246: if ((month == 1) || (month == 3) || (month == 5) ||
247: (month == 7) || (month == 8) || (month == 10) ||
248: (month == 12)) {
249: if (day > 31) {
250: document.$formname.$dname\_day.value = 31;
251: day = 31;
252: }
253: } else if (month == 2 ) {
254: if ((year % 4 == 0) && (year % 100 != 0)) {
255: if (day > 29) {
256: document.$formname.$dname\_day.value = 29;
257: }
258: } else if (day > 29) {
259: document.$formname.$dname\_day.value = 28;
260: }
261: } else if (day > 30) {
262: document.$formname.$dname\_day.value = 30;
263: }
264: }
265:
266: function $dname\_opencalendar() {
267: var calwin=window.open(
268: "/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
269: document.$formname.$dname\_month.value+"&year="+
270: document.$formname.$dname\_year.value,
271: "LONCAPAcal",
272: "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
273:
274: }
275: </script>
276: ENDJS
277: $result .= " <nobr><select name=\"$dname\_month\" ".$special.' '.
278: "onChange=\"javascript:$dname\_checkday()\" >\n";
279: my @Months = qw/January February March April May June
280: July August September October November December/;
281: # Pad @Months with a bogus value to make indexing easier
282: unshift(@Months,'If you can read this an error occurred');
283: if ($includeempty) { $result.="<option value=''></option>"; }
284: for(my $m = 1;$m <=$#Months;$m++) {
285: $result .= " <option value=\"$m\" ";
286: $result .= "selected " if ($m-1 eq $month);
287: $result .= "> ".&mt($Months[$m])." </option>\n";
288: }
289: $result .= " </select>\n";
290: $result .= " <input type=\"text\" name=\"$dname\_day\" ".
291: "value=\"$mday\" size=\"3\" ".$special.' '.
292: "onChange=\"javascript:$dname\_checkday()\" />\n";
293: $result .= " <input type=\"year\" name=\"$dname\_year\" ".
294: "value=\"$year\" size=\"5\" ".$special.' '.
295: "onChange=\"javascript:$dname\_checkday()\" />\n";
296: $result .= " ";
297: $result .= " <select name=\"$dname\_hour\" ".$special." >\n";
298: if ($includeempty) { $result.="<option value=''></option>"; }
299: for (my $h = 0;$h<24;$h++) {
300: $result .= " <option value=\"$h\" ";
301: $result .= "selected " if ($hour == $h);
302: $result .= "> ";
303: my $timest='';
304: if ($h == 0) {
305: $timest .= "12 am";
306: } elsif($h == 12) {
307: $timest .= "12 noon";
308: } elsif($h < 12) {
309: $timest .= "$h am";
310: } else {
311: $timest .= $h-12 ." pm";
312: }
313: $timest=&mt($timest);
314: $result .= $timest." </option>\n";
315: }
316: $result .= " </select>\n";
317: $result .= " <input type=\"text\" name=\"$dname\_minute\" ".$special.' '.
318: "value=\"$min\" size=\"3\" /> m\n";
319: $result .= " <input type=\"text\" name=\"$dname\_second\" ".$special.' '.
320: "value=\"$sec\" size=\"3\" /> s\n";
321: $result .= "<a href=\"javascript:$dname\_opencalendar()\">".
322: &mt('Select Date')."</a></nobr>\n<!-- end $dname date setting form -->\n";
323: return $result;
324: }
325:
326: ##############################################
327: ##############################################
328:
329: =pod
330:
331: =item &get_date_from_form
332:
333: get_date_from_form retrieves the date specified in an &date_setter form.
334:
335: Inputs:
336:
337: =over 4
338:
339: =item $dname
340:
341: The name passed to &datesetter, which prefixes the form elements.
342:
343: =item $defaulttime
344:
345: The unix time to use as the default in case of poor inputs.
346:
347: =back
348:
349: Returns: Unix time represented in the form.
350:
351: =cut
352:
353: ##############################################
354: ##############################################
355: sub get_date_from_form {
356: my ($dname) = @_;
357: my ($sec,$min,$hour,$day,$month,$year);
358: #
359: if (defined($ENV{'form.'.$dname.'_second'})) {
360: my $tmpsec = $ENV{'form.'.$dname.'_second'};
361: if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
362: $sec = $tmpsec;
363: }
364: }
365: if (defined($ENV{'form.'.$dname.'_minute'})) {
366: my $tmpmin = $ENV{'form.'.$dname.'_minute'};
367: if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
368: $min = $tmpmin;
369: }
370: }
371: if (defined($ENV{'form.'.$dname.'_hour'})) {
372: my $tmphour = $ENV{'form.'.$dname.'_hour'};
373: if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
374: $hour = $tmphour;
375: }
376: }
377: if (defined($ENV{'form.'.$dname.'_day'})) {
378: my $tmpday = $ENV{'form.'.$dname.'_day'};
379: if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
380: $day = $tmpday;
381: }
382: }
383: if (defined($ENV{'form.'.$dname.'_month'})) {
384: my $tmpmonth = $ENV{'form.'.$dname.'_month'};
385: if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
386: $month = $tmpmonth - 1;
387: }
388: }
389: if (defined($ENV{'form.'.$dname.'_year'})) {
390: my $tmpyear = $ENV{'form.'.$dname.'_year'};
391: if (($tmpyear =~ /^\d+$/) && ($tmpyear > 1900)) {
392: $year = $tmpyear - 1900;
393: }
394: }
395: if (($year<70) || ($year>137)) { return undef; }
396: if (defined($sec) && defined($min) && defined($hour) &&
397: defined($day) && defined($month) && defined($year) &&
398: eval(&timelocal($sec,$min,$hour,$day,$month,$year))) {
399: return &timelocal($sec,$min,$hour,$day,$month,$year);
400: } else {
401: return undef;
402: }
403: }
404:
405: ##############################################
406: ##############################################
407:
408: =pod
409:
410: =item &pjump_javascript_definition()
411:
412: Returns javascript defining the 'pjump' function, which opens up a
413: parameter setting wizard.
414:
415: =cut
416:
417: ##############################################
418: ##############################################
419: sub pjump_javascript_definition {
420: my $Str = <<END;
421: function pjump(type,dis,value,marker,ret,call) {
422: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
423: +"&value="+escape(value)+"&marker="+escape(marker)
424: +"&return="+escape(ret)
425: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
426: "height=350,width=350,scrollbars=no,menubar=no");
427: }
428: END
429: return $Str;
430: }
431:
432: ##############################################
433: ##############################################
434:
435: =pod
436:
437: =item &javascript_nothing()
438:
439: Return an appropriate null for the users browser. This is used
440: as the first arguement for window.open calls when you want a blank
441: window that you can then write to.
442:
443: =cut
444:
445: ##############################################
446: ##############################################
447: sub javascript_nothing {
448: # mozilla and other browsers work with "''", but IE on mac does not.
449: my $nothing = "''";
450: my $user_browser;
451: my $user_os;
452: $user_browser = $ENV{'browser.type'} if (exists($ENV{'browser.type'}));
453: $user_os = $ENV{'browser.os'} if (exists($ENV{'browser.os'}));
454: if (! defined($user_browser) || ! defined($user_os)) {
455: (undef,$user_browser,undef,undef,undef,$user_os) =
456: &Apache::loncommon::decode_user_agent();
457: }
458: if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
459: $nothing = "'javascript:void(0);'";
460: }
461: return $nothing;
462: }
463:
464:
465: ##############################################
466: ##############################################
467:
468: =pod
469:
470: =item &StatusOptions()
471:
472: Returns html for a selection box which allows the user to choose the
473: enrollment status of students. The selection box name is 'Status'.
474:
475: Inputs:
476:
477: $status: the currently selected status. If undefined the value of
478: $ENV{'form.Status'} is taken. If that is undefined, a value of 'Active'
479: is used.
480:
481: $formname: The name of the form. If defined the onchange attribute of
482: the selection box is set to document.$formname.submit().
483:
484: $size: the size (number of lines) of the selection box.
485:
486: $onchange: javascript to use when the value is changed. Enclosed in
487: double quotes, ""s, not single quotes.
488:
489: Returns: a perl string as described.
490:
491: =cut
492:
493: ##############################################
494: ##############################################
495: sub StatusOptions {
496: my ($status, $formName,$size,$onchange)=@_;
497: $size = 1 if (!defined($size));
498: if (! defined($status)) {
499: $status = 'Active';
500: $status = $ENV{'form.Status'} if (exists($ENV{'form.Status'}));
501: }
502:
503: my $OpSel1 = '';
504: my $OpSel2 = '';
505: my $OpSel3 = '';
506:
507: if($status eq 'Any') { $OpSel3 = ' selected'; }
508: elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
509: else { $OpSel1 = ' selected'; }
510:
511: my $Str = '';
512: $Str .= '<select name="Status"';
513: if(defined($formName) && $formName ne '' && ! defined($onchange)) {
514: $Str .= ' onchange="document.'.$formName.'.submit()"';
515: }
516: if (defined($onchange)) {
517: $Str .= ' onchange="'.$onchange.'"';
518: }
519: $Str .= ' size="'.$size.'" ';
520: $Str .= '>'."\n";
521: $Str .= '<option value="Active" '.$OpSel1.'>'.
522: &mt('Currently Enrolled').'</option>'."\n";
523: $Str .= '<option value="Expired" '.$OpSel2.'>'.
524: &mt('Previously Enrolled').'</option>'."\n";
525: $Str .= '<option value="Any" '.$OpSel3.'>'.
526: &mt('Any Enrollment Status').'</option>'."\n";
527: $Str .= '</select>'."\n";
528: }
529:
530:
531: ########################################################
532: ########################################################
533:
534: =pod
535:
536: =item &MultipleSectionSelect()
537:
538: Inputs:
539:
540: =over 4
541:
542: =item $sections A references to an array containing the names of all the
543: sections used in a class.
544:
545: =item $selectedSections A reference to an array containing the names of the
546: currently selected sections.
547:
548: =back
549:
550: Returns: a string containing HTML for a multiple select box for
551: selecting sections of a course.
552:
553: The form element name is 'Section'. @$sections is sorted prior to output.
554:
555: =cut
556:
557: ########################################################
558: ########################################################
559: sub MultipleSectionSelect {
560: my ($sections,$selectedSections)=@_;
561:
562: my $Str = '';
563: $Str .= '<select name="Section" multiple="true" size="4">'."\n";
564:
565: foreach (sort @$sections) {
566: $Str .= '<option';
567: foreach my $selected (@$selectedSections) {
568: if($_ eq $selected) {
569: $Str .= ' selected=""';
570: }
571: }
572: $Str .= '>'.$_.'</option>'."\n";
573: }
574: $Str .= '</select>'."\n";
575:
576: return $Str;
577: }
578:
579: ########################################################
580: ########################################################
581:
582: =pod
583:
584: =item &Title()
585:
586: Inputs: $pageName a string containing the name of the page to be sent
587: to &Apache::loncommon::bodytag.
588:
589: Returns: string containing being <html> and complete <head> and <title>
590: as well as a <script> to focus the current window and change its width
591: and height to 500. Why? I do not know. If you find out, please update
592: this documentation.
593:
594: =cut
595:
596: ########################################################
597: ########################################################
598: sub Title {
599: my ($pageName)=@_;
600:
601: my $Str = '';
602:
603: $Str .= '<html><head><title>'.$pageName.'</title></head>'."\n";
604: $Str .= &Apache::loncommon::bodytag($pageName)."\n";
605: $Str .= '<script>window.focus(); window.width=500;window.height=500;';
606: $Str .= '</script>'."\n";
607:
608: return $Str;
609: }
610:
611: ########################################################
612: ########################################################
613:
614: =pod
615:
616: =item &CreateHeadings()
617:
618: This function generates the column headings for the chart.
619:
620: =over 4
621:
622: Inputs: $CacheData, $keyID, $headings, $spacePadding
623:
624: $CacheData: pointer to a hash tied to the cached data database
625:
626: $keyID: a pointer to an array containing the names of the data
627: held in a column and is used as part of a key into $CacheData
628:
629: $headings: The names of the headings for the student information
630:
631: $spacePadding: The spaces to go between columns
632:
633: Output: $Str
634:
635: $Str: A formatted string of the table column headings.
636:
637: =back
638:
639: =cut
640:
641: ########################################################
642: ########################################################
643: sub CreateHeadings {
644: my ($data,$keyID,$headings,$displayString,$format)=@_;
645: my $Str='';
646: my $formatting = '';
647:
648: for(my $index=0; $index<(scalar @$headings); $index++) {
649: my $currentHeading=$headings->[$index];
650: if($format eq 'preformatted') {
651: my @dataLength=split(//,$currentHeading);
652: my $length=scalar @dataLength;
653: $formatting = (' 'x
654: ($data->{$keyID->[$index].':columnWidth'}-$length));
655: }
656: my $linkdata=$keyID->[$index];
657:
658: my $tempString = $displayString;
659: $tempString =~ s/LINKDATA/$linkdata/;
660: $tempString =~ s/DISPLAYDATA/$currentHeading/;
661: $tempString =~ s/FORMATTING/$formatting/;
662:
663: $Str .= $tempString;
664: }
665:
666: return $Str;
667: }
668:
669: ########################################################
670: ########################################################
671:
672: =pod
673:
674: =item &FormatStudentInformation()
675:
676: This function produces a formatted string of the student\'s information:
677: username, domain, section, full name, and PID.
678:
679: =over 4
680:
681: Input: $cache, $name, $keyID, $spacePadding
682:
683: $cache: This is a pointer to a hash that is tied to the cached data
684:
685: $name: The name and domain of the current student in name:domain format
686:
687: $keyID: A pointer to an array holding the names used to
688:
689: remove data from the hash. They represent the name of the data to be removed.
690:
691: $spacePadding: Extra spaces that represent the space between columns
692:
693: Output: $Str
694:
695: $Str: Formatted string.
696:
697: =back
698:
699: =cut
700:
701: ########################################################
702: ########################################################
703: sub FormatStudentInformation {
704: my ($data,$name,$keyID,$displayString,$format)=@_;
705: my $Str='';
706: my $currentColumn;
707:
708: for(my $index=0; $index<(scalar @$keyID); $index++) {
709: $currentColumn=$data->{$name.':'.$keyID->[$index]};
710:
711: if($format eq 'preformatted') {
712: my @dataLength=split(//,$currentColumn);
713: my $length=scalar @dataLength;
714: $currentColumn.= (' 'x
715: ($data->{$keyID->[$index].':columnWidth'}-$length));
716: }
717:
718: my $tempString = $displayString;
719: $tempString =~ s/DISPLAYDATA/$currentColumn/;
720:
721: $Str .= $tempString;
722: }
723:
724: return $Str;
725: }
726:
727: ########################################################
728: ########################################################
729:
730: =pod
731:
732: =item Progess Window Handling Routines
733:
734: These routines handle the creation, update, increment, and closure of
735: progress windows. The progress window reports to the user the number
736: of items completed and an estimate of the time required to complete the rest.
737:
738: =over 4
739:
740:
741: =item &Create_PrgWin
742:
743: Writes javascript to the client to open a progress window and returns a
744: data structure used for bookkeeping.
745:
746: Inputs
747:
748: =over 4
749:
750: =item $r Apache request
751:
752: =item $title The title of the progress window
753:
754: =item $heading A description (usually 1 line) of the process being initiated.
755:
756: =item $number_to_do The total number of items being processed.
757:
758: =back
759:
760: Returns a hash containing the progress state data structure.
761:
762:
763: =item &Update_PrgWin
764:
765: Updates the text in the progress indicator. Does not increment the count.
766: See &Increment_PrgWin.
767:
768: Inputs:
769:
770: =over 4
771:
772: =item $r Apache request
773:
774: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
775:
776: =item $displaystring The string to write to the status indicator
777:
778: =back
779:
780: Returns: none
781:
782:
783: =item Increment_PrgWin
784:
785: Increment the count of items completed for the progress window by 1.
786:
787: Inputs:
788:
789: =over 4
790:
791: =item $r Apache request
792:
793: =item $prog_state Pointer to the data structure returned by Create_PrgWin
794:
795: =item $extraInfo A description of the items being iterated over. Typically
796: 'student'.
797:
798: =back
799:
800: Returns: none
801:
802:
803: =item Close_PrgWin
804:
805: Closes the progress window.
806:
807: Inputs:
808:
809: =over 4
810:
811: =item $r Apache request
812:
813: =item $prog_state Pointer to the data structure returned by Create_PrgWin
814:
815: =back
816:
817: Returns: none
818:
819: =back
820:
821: =cut
822:
823: ########################################################
824: ########################################################
825:
826: # Create progress
827: sub Create_PrgWin {
828: my ($r, $title, $heading, $number_to_do)=@_;
829: $r->print('<script>'.
830: "popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
831: "popwin.document.writeln(\'<html><head><title>$title</title></head>".
832: "<body bgcolor=\"#88DDFF\">".
833: "<h4>$heading</h4>".
834: "<form name=popremain>".
835: '<input type="text" size="55" name="remaining" value="'.
836: &mt('Starting').'"></form>'.
837: "</body></html>\');".
838: "popwin.document.close();".
839: "</script>");
840:
841: my %prog_state;
842: $prog_state{'done'}=0;
843: $prog_state{'firststart'}=&Time::HiRes::time();
844: $prog_state{'laststart'}=&Time::HiRes::time();
845: $prog_state{'max'}=$number_to_do;
846:
847: $r->rflush();
848: return %prog_state;
849: }
850:
851: # update progress
852: sub Update_PrgWin {
853: my ($r,$prog_state,$displayString)=@_;
854: $r->print('<script>popwin.document.popremain.remaining.value="'.
855: $displayString.'";</script>');
856: $$prog_state{'laststart'}=&Time::HiRes::time();
857: $r->rflush();
858: }
859:
860: # increment progress state
861: sub Increment_PrgWin {
862: my ($r,$prog_state,$extraInfo)=@_;
863: $$prog_state{'done'}++;
864: my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
865: $$prog_state{'done'} *
866: ($$prog_state{'max'}-$$prog_state{'done'});
867: $time_est = int($time_est);
868: if (int ($time_est/60) > 0) {
869: my $min = int($time_est/60);
870: my $sec = $time_est % 60;
871: $time_est = $min.' '.&mt('minutes');
872: if ($min < 10) {
873: if ($sec > 1) {
874: $time_est.= ', '.$sec.' '.&mt('seconds');
875: } elsif ($sec > 0) {
876: $time_est.= ', '.$sec.' '.&mt('second');
877: }
878: }
879: } else {
880: $time_est .= ' '.&mt('seconds');
881: }
882: my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
883: if ($lasttime > 9) {
884: $lasttime = int($lasttime);
885: } elsif ($lasttime < 0.01) {
886: $lasttime = 0;
887: } else {
888: $lasttime = sprintf("%3.2f",$lasttime);
889: }
890: if ($lasttime == 1) {
891: $lasttime = '('.$lasttime.' '.&mt('second for').' '.$extraInfo.')';
892: } else {
893: $lasttime = '('.$lasttime.' '.&mt('seconds for').' '.$extraInfo.')';
894: }
895: #
896: my $user_browser = $ENV{'browser.type'} if (exists($ENV{'browser.type'}));
897: my $user_os = $ENV{'browser.os'} if (exists($ENV{'browser.os'}));
898: if (! defined($user_browser) || ! defined($user_os)) {
899: (undef,$user_browser,undef,undef,undef,$user_os) =
900: &Apache::loncommon::decode_user_agent();
901: }
902: if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
903: $lasttime = '';
904: }
905: $r->print('<script>popwin.document.popremain.remaining.value="'.
906: $$prog_state{'done'}.'/'.$$prog_state{'max'}.
907: ': '.$time_est.' '.&mt('remaining').' '.$lasttime.'";'.'</script>');
908: $$prog_state{'laststart'}=&Time::HiRes::time();
909: $r->rflush();
910: }
911:
912: # close Progress Line
913: sub Close_PrgWin {
914: my ($r,$prog_state)=@_;
915: $r->print('<script>popwin.close()</script>'."\n");
916: undef(%$prog_state);
917: $r->rflush();
918: }
919:
920:
921: # ------------------------------------------------------- Puts directory header
922:
923: sub crumbs {
924: my ($uri,$target,$prefix,$form)=@_;
925: my $output='<br /><tt><b><font size="+2">'.$prefix.'/';
926: if ($ENV{'user.adv'}) {
927: my $path=$prefix;
928: foreach (split('/',$uri)) {
929: unless ($_) { next; }
930: $path.='/'.$_;
931: my $linkpath=$path;
932: if ($form) {
933: $linkpath="javascript:$form.action='$path';$form.submit();";
934: }
935: $output.='<a href="'.$linkpath.'"'.($target?' target="'.$target.'"':'').'>'.$_.'</a>/';
936: }
937: } else {
938: $output.=$uri;
939: }
940: unless ($uri=~/\/$/) { $output=~s/\/$//; }
941: return $output.'</font></b></tt><br />';
942: }
943:
944:
945: 1;
946:
947: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>