[LON-CAPA-cvs] cvs: loncom /interface/spreadsheet Spreadsheet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Sun, 03 Sep 2006 00:45:52 -0000


albertel		Sat Sep  2 20:45:52 2006 EDT

  Modified files:              
    /loncom/interface/spreadsheet	Spreadsheet.pm 
  Log:
  - wasn't properly defaulting to the standard system spreadsheets when
     accessing the SPRS for the first time
  - add ability to reset a SPRS back to the system standard ones
  
  
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.70 loncom/interface/spreadsheet/Spreadsheet.pm:1.71
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.70	Sat Sep  2 20:39:57 2006
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Sat Sep  2 20:45:51 2006
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.70 2006/09/03 00:39:57 albertel Exp $
+# $Id: Spreadsheet.pm,v 1.71 2006/09/03 00:45:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -172,16 +172,20 @@
                 $newfilename = 'default_'.$self->{'type'};
             }
         }
-        if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) {
-            $newfilename = 'default_'.$self->{'type'};
-        }
-        if ($newfilename !~ /^default\.$self->{'type'}$/ &&
-            $newfilename !~ /^\/res\/(.*)spreadsheet$/) {
-            if ($newfilename !~ /_$self->{'type'}$/) {
-                $newfilename =~ s/[\s_]*$//;
-                $newfilename .= '_'.$self->{'type'};
-            }
-        }
+	if ($newfilename eq &mt('LON-CAPA Standard')) {
+	    undef($newfilename);
+	} else {
+	    if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) {
+		$newfilename = 'default_'.$self->{'type'};
+	    }
+	    if ($newfilename !~ /^default\.$self->{'type'}$/ &&
+		$newfilename !~ /^\/res\/(.*)spreadsheet$/) {
+		if ($newfilename !~ /_$self->{'type'}$/) {
+		    $newfilename =~ s/[\s_]*$//;
+		    $newfilename .= '_'.$self->{'type'};
+		}
+	    }
+	}
         $self->{'filename'} = $newfilename;
         return;
     }
@@ -1684,7 +1688,8 @@
             # Load the spreadsheet definition file from the save file
             my %tmphash = &Apache::lonnet::dump($filename,$cdom,$cnum);
             my ($tmp) = keys(%tmphash);
-            if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
+            if (%tmphash
+		&& $tmp !~ /^(con_lost|error|no_such_host)/i) {
                 while (my ($cell,$formula) = each(%tmphash)) {
                     $formulas->{$cell}=$formula;
                 }
@@ -1881,14 +1886,13 @@
     my ($stype) = @_;
     $stype = $self->{'type'} if (! defined($stype) || $stype !~ /calc$/);
     #
-    my @alternatives=();
+    my @alternatives=(&mt('Default'), &mt('LON-CAPA Standard'));
     my %results=&Apache::lonnet::dump($stype.'_spreadsheets',
                                       $self->{'cdom'}, $self->{'cnum'});
     my ($tmp) = keys(%results);
-    if ($tmp =~ /^(con_lost|error|no_such_host)/i ) {
-        @alternatives = (&mt('Default'));
-    } else {
-        @alternatives = (&mt('Default'), sort (keys(%results)));
+    if (%results
+	&& $tmp =~ /^(con_lost|error|no_such_host)/i ) {
+        push(@alternatives, sort(keys(%results)));
     }
     return @alternatives; 
 }