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

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 10 Apr 2002 15:30:13 -0000


matthew		Wed Apr 10 11:30:13 2002 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm 
  Log:
  Load spreadsheets from resource space now works properly.
  
  
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.82 loncom/interface/lonspreadsheet.pm:1.83
--- loncom/interface/lonspreadsheet.pm:1.82	Tue Apr  9 14:41:11 2002
+++ loncom/interface/lonspreadsheet.pm	Wed Apr 10 11:30:13 2002
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.82 2002/04/09 18:41:11 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.83 2002/04/10 15:30:13 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -774,7 +774,7 @@
 	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
         my $fm=$f{$_.$n};
         $fm=~s/[\'\"]/\&\#34;/g;
-        $cols[$#cols+1]="'$_$n','$fm'".'___eq___'.$v{$_.$n};
+        push(@cols,"'$_$n','$fm'".'___eq___'.$v{$_.$n});
     }
     return @cols;
 }
@@ -1189,7 +1189,7 @@
   my $cdom=&getcdom($safeeval);
   my $chome=&getchome($safeeval);
 
-  if (! defined($fn) || $fn eq '') {
+  if (! defined($fn)) {
       # There is no filename. Look for defaults in course and global, cache
       unless ($fn=$defaultsheets{$cnum.'_'.$cdom.'_'.$stype}) {
           my %tmphash = &Apache::lonnet::get('environment',
@@ -1203,19 +1203,6 @@
           } 
           $defaultsheets{$cnum.'_'.$cdom.'_'.$stype}=$fn; 
       }
-  } else {
-      # We do have a filename, do a get on it.
-      my %tmphash = &Apache::lonnet::get('environment',
-                                         [$fn],
-                                         $cdom,$cnum);
-      my ($tmp) = keys(%tmphash);
-      if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
-          # On error, grab the default filename
-          $fn = 'default_'.$stype;
-      } else {
-          $fn = $tmphash{$fn};
-      }
-      $defaultsheets{$cnum.'_'.$cdom.'_'.$stype}=$fn; 
   }
 
 # ---------------------------------------------------------- fn now has a value
@@ -1242,26 +1229,21 @@
          } else {
              $sheetxml='<field row="0" col="A">"Error"</field>';
          }
-         %f=&parse_sheet(\$sheetxml);
+         %f=%{&parse_sheet(\$sheetxml)};
      } elsif($fn=~/\/*\.spreadsheet$/) {
-         my $sheetxml='';
-         my $fh;
-         my $dfn=$fn;
-         $dfn=~s/\_/\./g;
-
-         if ($fn !~ /^$Apache::lonnet::perlvar{'lonDocRoot'}\/res/) {
-             $fn = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'.$fn;
-         }
-         if ($fn !~ /^$Apache::lonnet::perlvar{'lonDocRoot'}/) {
-             $fn = $Apache::lonnet::perlvar{'lonDocRoot'}.$fn;
-         }
-         if ($fh=Apache::File->new($fn)) {
-             $sheetxml=join('',<$fh>);
-         } else {
+         my $sheetxml=&Apache::lonnet::getfile
+             (&Apache::lonnet::filelocation('',$fn));
+         print "<pre>$sheetxml</pre>";
+         if ($sheetxml == -1) {
              $sheetxml='<field row="0" col="A">"Error loading spreadsheet '
                  .$fn.'"</field>';
          }
-         %f=&parse_sheet(\$sheetxml);
+         %f=%{&parse_sheet(\$sheetxml)};
+         print "<pre>";
+         foreach (sort( keys(%f))) {
+             print "$_ = $f{$_}\n";
+         }
+         print "</pre>";
      } else {
          my $sheet='';
          my %tmphash = &Apache::lonnet::dump($fn,$cdom,$cnum);