--- loncom/interface/Attic/lonspreadsheet.pm	2003/01/30 21:35:13	1.167
+++ loncom/interface/Attic/lonspreadsheet.pm	2003/03/03 22:00:03	1.173
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.167 2003/01/30 21:35:13 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.173 2003/03/03 22:00:03 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -262,7 +262,6 @@ ENDSCRIPT
     # Global directory configs
     #
     $sheet->includedir($r->dir_config('lonIncludes'));
-    $sheet->tmpdir($r->dir_config('lonDaemons').'/tmp/');
     #
     # Check user permissions
     if (($sheet->{'type'}  eq 'classcalc'       ) || 
@@ -524,18 +523,12 @@ my %numbertimes;
 # Directories
 #
 my $includedir;
-my $tmpdir;
 
 sub includedir {
     my $self = shift;
     $includedir = shift;
 }
 
-sub tmpdir {
-    my $self = shift;
-    $tmpdir = shift;
-}
-
 my %spreadsheets;
 #my %loadedcaches;
 my %courserdatas;
@@ -1744,6 +1737,7 @@ sub calcsheet {
     $self->sett();
     my $result =  $self->{'safe'}->reval('&calc();');
     %{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')};
+#    $self->logthis($self->get_errorlog());
     return $result;
 }
 
@@ -1892,6 +1886,22 @@ sub dump_values_to_log {
     }
     $self->logthis("--------------------------------------------------------");}
 
+##
+## Yet another debugging function
+##
+sub dump_hash_to_log {
+    my $self= shift();
+    my %tmp = @_;
+    if (@_<2) {
+        %tmp = %{$_[0]};
+    }
+    $self->logthis('---------------------------- (entries end with ":"');
+    while (my ($key,$val) = each (%tmp)) {
+        $self->logthis($key.' = '.$val.':');
+    }
+    $self->logthis('---------------------------- (entries end with ":"');
+}
+
 ################################
 ##      Helper functions      ##
 ################################
@@ -2540,6 +2550,7 @@ sub export_sheet_as_excel {
             }
             next if ($row_is_empty);
         }
+        $worksheet->write($rows_output,$cols_output++,$rownum);
         $worksheet->write($rows_output,$cols_output++,$label);
         if (ref($label)) {
             $cols_output = (scalar(@$label));
@@ -2776,7 +2787,7 @@ sub tmpwrite {
         $ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.
            $self->{'filename'};
     $fn=~s/\W/\_/g;
-    $fn=$tmpdir.$fn.'.tmp';
+    $fn=$Apache::lonnet::tmpdir.$fn.'.tmp';
     my $fh;
     if ($fh=Apache::File->new('>'.$fn)) {
         my %f = $self->formulas();
@@ -2795,7 +2806,7 @@ sub tmpread {
            $ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.
            $self->{'filename'};
     $fn=~s/\W/\_/g;
-    $fn=$tmpdir.$fn.'.tmp';
+    $fn=$Apache::lonnet::tmpdir.$fn.'.tmp';
     my $fh;
     my %fo=();
     my $countrows=0;
@@ -3131,14 +3142,17 @@ sub loadstudent{
     my %formulas  = $self->formulas();
     $cachedassess = $self->{'uname'}.':'.$self->{'udom'};
     # Get ALL the student preformance data
-    my @tmp = &Apache::lonnet::currentdump($self->{'cid'},
-                                           $self->{'udom'},
-                                           $self->{'uname'});
+    my @tmp = &Apache::loncoursedata::get_current_state($self->{'uname'},
+                                                        $self->{'udom'},
+                                                        undef,
+                                                        $self->{'cid'});
     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
         %cachedstores = @tmp;
     }
     undef @tmp;
-    # 
+    # debugging code
+    # $self->dump_hash_to_log(\%cachedstores);
+    #
     my @assessdata=();
     foreach my $row ($self->rows()) {
         my $cell = 'A'.$row;
@@ -3171,7 +3185,7 @@ sub loadstudent{
     $self->constants(\%constants);
 }
 
-# --------------------------------------------------- Load data for one student
+# --------------------------------------------------- Load Course Sheet
 #
 sub loadcourse {
     my $self = shift;
@@ -3184,20 +3198,12 @@ sub loadcourse {
     foreach ($self->rows()) {
         $total++ if ($formulas{'A'.$_} !~ /^[!~-]/);
     }
-    my $now=0;
-    my $since=time;
-    $r->print(<<ENDPOP);
-<script>
-    popwin=open('','popwin','width=400,height=100');
-    popwin.document.writeln('<html><body bgcolor="#FFFFFF">'+
-      '<h3>Spreadsheet Calculation Progress</h3>'+
-      '<form name=popremain>'+
-      '<input type=text size=45 name=remaining value=Starting></form>'+
-      '</body></html>');
-    popwin.document.close();
-</script>
-ENDPOP
-    $r->rflush();
+
+    my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
+	      'Spreadsheet Status','Spreadsheet Calculation Progress', $total);
+    &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
+					  'Processing Course Assessment Data');
+
     # It would be nice to load in the classlist and assessment info at this 
     # point, before attacking the student spreadsheets.
     foreach my $row ($self->rows()) {
@@ -3211,12 +3217,8 @@ ENDPOP
         my @studentdata=$self->exportsheet($sname,$sdom,'studentcalc',
                                      undef,undef,$r);
         undef %userrdatas;
-        $now++;
-        $r->print('<script>popwin.document.popremain.remaining.value="'.
-                  $now.'/'.$total.': '.int((time-$since)/$now*($total-$now)).
-                  ' secs remaining '.(time-$started).' last";</script>');
-        $r->rflush(); 
-        #
+	&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
+						 'last student');
         my $index=0;
         foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
                  'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {
@@ -3236,8 +3238,7 @@ ENDPOP
     }
     $self->formulas(\%formulas);
     $self->constants(\%constants);
-    $r->print('<script>popwin.close()</script>');
-    $r->rflush(); 
+    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
 }
 
 # ------------------------------------------------ Load data for one assessment