--- loncom/interface/lonhtmlcommon.pm	2002/09/17 15:32:46	1.10
+++ loncom/interface/lonhtmlcommon.pm	2003/04/30 15:49:45	1.20
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.10 2002/09/17 15:32:46 matthew Exp $
+# $Id: lonhtmlcommon.pm,v 1.20 2003/04/30 15:49:45 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -249,6 +249,67 @@ sub get_date_from_form {
 ##############################################
 ##############################################
 
+=pod
+
+=item &pjump_javascript_definition()
+
+Returns javascript defining the 'pjump' function, which opens up a
+parameter setting wizard.
+
+=cut
+
+##############################################
+##############################################
+sub pjump_javascript_definition {
+    my $Str = <<END;
+    function pjump(type,dis,value,marker,ret,call) {
+        parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
+                 +"&value="+escape(value)+"&marker="+escape(marker)
+                 +"&return="+escape(ret)
+                 +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
+                 "height=350,width=350,scrollbars=no,menubar=no");
+    }
+END
+    return $Str;
+}
+
+##############################################
+##############################################
+
+=pod
+
+=item &javascript_nothing()
+
+Return an appropriate null for the users browser.  This is used
+as the first arguement for window.open calls when you want a blank
+window that you can then write to.
+
+=cut
+
+##############################################
+##############################################
+sub javascript_nothing {
+    # mozilla and other browsers work with "''", but IE on mac does not.
+    my $nothing = "''";
+    my $user_browser;
+    my $user_os;
+    $user_browser = $ENV{'browser.type'} if (exists($ENV{'browser.type'}));
+    $user_os      = $ENV{'browser.os'}   if (exists($ENV{'browser.os'}));
+    if (! defined($user_browser) || ! defined($user_os)) {
+        (undef,$user_browser,undef,undef,undef,$user_os) = 
+                           &Apache::loncommon::decode_user_agent();
+    }
+    if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
+        $nothing = "'javascript:void(0);'";
+    }
+    return $nothing;
+}
+
+##############################################
+##############################################
+
+
+
 sub AscendOrderOptions {
     my ($order, $page, $formName)=@_;
 
@@ -438,13 +499,42 @@ sub StatusOptions {
     $Str .= '</select>'."\n";
 }
 
+
+########################################################
+########################################################
+
+=pod
+
+=item &MultipleSectionSelect()
+
+Inputs: 
+
+=over 4
+
+=item $sections A references to an array containing the names of all the
+sections used in a class.
+
+=item $selectedSections A reference to an array containing the names of the
+currently selected sections.
+
+=back 
+
+Returns: a string containing HTML for a multiple select box for
+selecting sections of a course.  
+
+The form element name is 'Section'.  @$sections is sorted prior to output.
+
+=cut
+
+########################################################
+########################################################
 sub MultipleSectionSelect {
     my ($sections,$selectedSections)=@_;
 
     my $Str = '';
     $Str .= '<select name="Section" multiple="true" size="4">'."\n";
 
-    foreach (@$sections) {
+    foreach (sort @$sections) {
         $Str .= '<option';
         foreach my $selected (@$selectedSections) {
             if($_ eq $selected) {
@@ -454,10 +544,29 @@ sub MultipleSectionSelect {
         $Str .= '>'.$_.'</option>'."\n";
     }
     $Str .= '</select>'."\n";
-
+    
     return $Str;
 }
 
+########################################################
+########################################################
+
+=pod
+
+=item &Title()
+
+Inputs: $pageName a string containing the name of the page to be sent
+to &Apache::loncommon::bodytag.
+
+Returns: string containing being <html> and complete <head> and <title>
+as well as a <script> to focus the current window and change its width
+and height to 500.  Why?  I do not know.  If you find out, please update
+this documentation.
+
+=cut
+
+########################################################
+########################################################
 sub Title {
     my ($pageName)=@_;
 
@@ -471,9 +580,12 @@ sub Title {
     return $Str;
 }
 
+########################################################
+########################################################
+
 =pod
 
-=item &CreateTableHeadings()
+=item &CreateHeadings()
 
 This function generates the column headings for the chart.
 
@@ -498,6 +610,8 @@ $Str: A formatted string of the table co
 
 =cut
 
+########################################################
+########################################################
 sub CreateHeadings {
     my ($data,$keyID,$headings,$displayString,$format)=@_;
     my $Str='';
@@ -524,6 +638,9 @@ sub CreateHeadings {
     return $Str;
 }
 
+########################################################
+########################################################
+
 =pod
 
 =item &FormatStudentInformation()
@@ -553,6 +670,8 @@ $Str: Formatted string.
 
 =cut
 
+########################################################
+########################################################
 sub FormatStudentInformation {
     my ($data,$name,$keyID,$displayString,$format)=@_;
     my $Str='';
@@ -577,35 +696,79 @@ sub FormatStudentInformation {
     return $Str;
 }
 
+########################################################
+########################################################
+
 # Create progress
 sub Create_PrgWin {
-    my ($r, $title, $heading)=@_;
+    my ($r, $title, $heading, $number_to_do)=@_;
     $r->print('<script>'.
     "popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
-    "popwin.document.writeln(\'<html><body bgcolor=\"#88DDFF\">".
-              "<title>$title</title>".
+    "popwin.document.writeln(\'<html><head><title>$title</title></head>".
+	      "<body bgcolor=\"#88DDFF\">".
               "<h4>$heading</h4>".
               "<form name=popremain>".
-              "<input type=text size=35 name=remaining value=Starting></form>".
+              "<input type=text size=55 name=remaining value=Starting></form>".
               "</body></html>\');".
     "popwin.document.close();".
     "</script>");
 
+    my %prog_state;
+    $prog_state{'done'}=0;
+    $prog_state{'firststart'}=time;
+    $prog_state{'laststart'}=time;
+    $prog_state{'max'}=$number_to_do;
+
     $r->rflush();
+    return %prog_state;
 }
 
 # update progress
 sub Update_PrgWin {
-    my ($displayString,$r)=@_;
+    my ($r,$prog_state,$displayString)=@_;
     $r->print('<script>popwin.document.popremain.remaining.value="'.
               $displayString.'";</script>');
+    $$prog_state{'laststart'}=time;
+    $r->rflush();
+}
+
+# increment progress state
+sub Increment_PrgWin {
+    my ($r,$prog_state,$extraInfo)=@_;
+    $$prog_state{'done'}++;
+    my $time_est= (time - $$prog_state{'firststart'})/$$prog_state{'done'} *
+	($$prog_state{'max'}-$$prog_state{'done'});
+    $time_est = int($time_est);
+    if (int ($time_est/60) > 0) {
+	my $min = int($time_est/60);
+	my $sec = $time_est % 60;
+	$time_est = $min.' minutes';
+	if ($sec > 1) {
+	    $time_est.= ', '.$sec.' seconds';
+	} elsif ($sec > 0) {
+	    $time_est.= ', '.$sec.' second';
+	}
+    } else {
+	$time_est .= ' seconds';
+    }
+    my $lasttime = time-$$prog_state{'laststart'};
+    if ($lasttime == 1) {
+        $lasttime = '('.$lasttime.' second for '.$extraInfo.')';
+    } else {
+        $lasttime = '('.$lasttime.' seconds for '.$extraInfo.')';
+    }
+    $r->print('<script>popwin.document.popremain.remaining.value="'.
+	      $$prog_state{'done'}.'/'.$$prog_state{'max'}.
+	      ': '.$time_est.' remaining '.$lasttime.'";'.'</script>');
+    $$prog_state{'laststart'}=time;
     $r->rflush();
 }
 
 # close Progress Line
 sub Close_PrgWin {
-    my ($r)=@_;
+    my ($r,$prog_state)=@_;
     $r->print('<script>popwin.close()</script>'."\n");
+    undef(%$prog_state);
     $r->rflush(); 
 }