--- loncom/interface/Attic/lonspreadsheet.pm	2003/03/07 23:32:05	1.175
+++ loncom/interface/Attic/lonspreadsheet.pm	2003/05/27 15:50:30	1.179
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.175 2003/03/07 23:32:05 albertel Exp $
+# $Id: lonspreadsheet.pm,v 1.179 2003/05/27 15:50:30 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -57,6 +57,7 @@ use strict;
 use Apache::Constants qw(:common :http);
 use Apache::lonnet;
 use Apache::lonhtmlcommon;
+use Apache::lonmenu;
 use HTML::Entities();
 
 # --------------------------------------------------------- Various form fields
@@ -152,9 +153,9 @@ sub handler {
                                              $ENV{'form.ufn'} eq 'default')) {
         $ENV{'form.ufn'}='default_'.$1;
     }
-    if (!$ENV{'form.ufn'} || $ENV{'form.ufn'} eq 'default') {
-        $ENV{'form.ufn'}='course_default_'.$sheettype;
-    }
+#    if (!$ENV{'form.ufn'} || $ENV{'form.ufn'} eq 'default') {
+#        $ENV{'form.ufn'}='course_default_'.$sheettype;
+#    }
     #
     # Interactive loading of specific sheet?
     #
@@ -183,10 +184,7 @@ sub handler {
     # Header....
     #
     $r->print('<html><head><title>LON-CAPA Spreadsheet</title>');
-    my $nothing = "''";
-    if ($ENV{'browser.type'} eq 'explorer') {
-        $nothing = "'javascript:void(0);'";
-    }
+    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 
     if ($ENV{'request.role'} !~ /^st\./) {
         $r->print(<<ENDSCRIPT);
@@ -247,7 +245,8 @@ ENDSCRIPT
               &hiddenfield('udom',$ENV{'form.udom'}).
               &hiddenfield('usymb',$ENV{'form.usymb'}).
               &hiddenfield('unewfield','').
-              &hiddenfield('unewformula',''));
+              &hiddenfield('unewformula','').
+              &Apache::lonmenu::regflush());
     $r->rflush();
     #
     # Full recalc?
@@ -355,6 +354,7 @@ ENDSCRIPT
         $oldsheets{'course'} ne $sheet->{'cid'}) {
         undef %oldsheets;
         undef %loadedcaches;
+        &Apache::lonspreadsheet::Spreadsheet::clear_package_variables();
     }
     $oldsheets{'course'} = $sheet->{'cid'};
     #
@@ -537,6 +537,25 @@ my %defaultsheets;
 my %rowlabel_cache;
 #my %oldsheets;
 
+sub clear_package_variables {
+    undef %courseopt;
+    undef %useropt;
+    undef %parmhash;
+    undef %Section;
+    undef %expiredates;
+    undef $cachedassess;
+    undef %cachedstores;
+    undef %starttimes;
+    undef %usedtimes;
+    undef %numbertimes;
+    undef $includedir;
+    undef %spreadsheets;
+    undef %courserdatas;
+    undef %userrdatas;
+    undef %defaultsheets;
+    undef %rowlabel_cache;
+}
+
 sub complete_recalc {
     my $self = shift;
     undef %spreadsheets;
@@ -754,6 +773,15 @@ sub new {
     #
     my ($uname,$udom,$stype,$usymb)=@_;
     #
+    if (! exists($Section{$uname.':'.$udom})) {
+        my $classlist = &Apache::loncoursedata::get_classlist();
+        #
+        foreach my $student (keys(%$classlist)) {
+            my ($studentDomain,$studentName,undef,undef,undef,$studentSection,
+                undef,undef) = @{$classlist->{$student}};
+            $Section{$studentName.':'.$studentDomain} = $studentSection;
+        }
+    }
     my $self = {
         uname => $uname,
         udom  => $udom,
@@ -1526,7 +1554,7 @@ sub expandnamed {
 	foreach my $varname ( @vars ) {
             if ($varname=~/\D/) {
                $formula=~s/$varname/'$c{\''.$varname.'\'}'/ge;
-               $varname=~s/$var/\([\\w:- ]\+\)/g;
+               $varname=~s/$var/\([\\w:\\- ]\+\)/g;
 	       foreach (keys(%{$self->{'constants'}})) {
 		  if ($_=~/$varname/) {
 		      $values{$1}=1;