--- loncom/interface/Attic/lonspreadsheet.pm	2002/09/10 19:04:13	1.109
+++ loncom/interface/Attic/lonspreadsheet.pm	2002/09/30 18:03:39	1.113
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.109 2002/09/10 19:04:13 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.113 2002/09/30 18:03:39 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,6 +62,11 @@ use GDBM_File;
 use HTML::TokeParser;
 use Apache::lonhtmlcommon;
 #
+# Caches for coursewide information 
+#
+my %Section;
+
+#
 # Caches for previously calculated spreadsheets
 #
 
@@ -852,7 +857,7 @@ sub sett {
     }
     # Deal with the normal cells
     foreach (keys(%f)) {
-	if (($f{$_}) && ($_!~/template\_/)) {
+	if (exists($f{$_}) && ($_!~/template\_/)) {
             my $matches=($_=~/^$pattern(\d+)/);
             if  (($matches) && ($1)) {
 	        unless ($f{$_}=~/^\!/) {
@@ -1226,8 +1231,14 @@ sub rown {
                 if ($vl eq '') {
                     $vl='<font size=+2 color='.$bgcolor.'>&#35;</font>';
                 }
-                $rowdata.='<td bgcolor='.$bgcolor.'>'.
-                    '<a href="javascript:celledit('.$fm.');">'.$vl.'</a></td>';
+                $rowdata.='<td bgcolor='.$bgcolor.'>';
+                if ($ENV{'request.role'} =~ /^st\./) {
+                    $rowdata.=$vl;
+                } else {
+                    $rowdata.='<a href="javascript:celledit('.$fm.');">'.
+                        $vl.'</a>';
+                }
+                $rowdata.='</td>';
             } else {
                 $rowdata.='<td bgcolor='.$bgcolor.'>&nbsp;'.$vl.'&nbsp;</td>';
             }
@@ -1299,7 +1310,7 @@ sub outsheet {
         push (@sortby, $safeeval->reval('$f{"A'.$row.'"}'));
         push (@sortidx, $row-1);
     }
-    @sortidx=sort { $sortby[$a] cmp $sortby[$b]; } @sortidx;
+    @sortidx=sort { lc($sortby[$a]) cmp lc($sortby[$b]); } @sortidx;
     #
     # Determine the type of child spreadsheets
     my $what='Student';
@@ -1461,8 +1472,7 @@ sub makenewsheet {
     $sheetdata{'sheettype'} = $stype;
     $sheetdata{'usymb'} = $usymb;
     $sheetdata{'cid'}   = $ENV{'request.course.id'};
-    $sheetdata{'csec'}  = &Apache::lonnet::usection
-                               ($udom,$uname,$ENV{'request.course.id'});
+    $sheetdata{'csec'}  = $Section{$uname.':'.$udom};
     $sheetdata{'coursefilename'}   = $ENV{'request.course.fn'};
     $sheetdata{'cnum'}  = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
     $sheetdata{'cdom'}  = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
@@ -1670,6 +1680,9 @@ sub updateclasssheet {
     my $cid   =$sheetdata->{'cid'};
     my $chome =$sheetdata->{'chome'};
     #
+    %Section = ();
+
+    #
     # Read class list and row labels
     my %classlist;
     my @tmp = &Apache::lonnet::dump('classlist',$cdom,$cnum);
@@ -1693,6 +1706,7 @@ sub updateclasssheet {
             my ($studentName,$studentDomain)=split(/\:/,$student);
             my $studentSection=&Apache::lonnet::usection($studentDomain,
                                                          $studentName,$cid);
+            $Section{$studentName.':'.$studentDomain} = $studentSection;
 #            if ($studentSection==-1) {
 #                unless ($ENV{'form.showcsv'}) {
 #                    $rowlabel='<font color=red>Data not available: '.
@@ -2412,10 +2426,15 @@ sub cachedssheets {
 # Interactive call to screen
 #
 #
-
-
 sub handler {
     my $r=shift;
+
+    my $loaderror=&Apache::lonnet::overloaderror($r);
+    if ($loaderror) { return $loaderror; }
+    $loaderror= &Apache::lonnet::overloaderror($r,
+                      $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
+    if ($loaderror) { return $loaderror; } 
+
     if ($r->header_only) {
         $r->content_type('text/html');
         $r->send_http_header;
@@ -2434,6 +2453,10 @@ sub handler {
     # Get query string for limited number of parameters
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['uname','udom','usymb','ufn']);
+    if ($ENV{'request.role'} =~ /^st\./) {
+        delete $ENV{'form.unewfield'}   if (exists($ENV{'form.unewfield'}));
+        delete $ENV{'form.unewformula'} if (exists($ENV{'form.unewformula'}));
+    }
     if (($ENV{'form.usymb'}=~/^\_(\w+)/) && (!$ENV{'form.ufn'})) {
         $ENV{'form.ufn'}='default_'.$1;
     }
@@ -2460,7 +2483,8 @@ sub handler {
     $r->send_http_header;
     # Screen output
     $r->print('<html><head><title>LON-CAPA Spreadsheet</title>');
-    $r->print(<<ENDSCRIPT);
+    if ($ENV{'request.role'} !~ /^st\./) {
+        $r->print(<<ENDSCRIPT);
 <script language="JavaScript">
 
     function celledit(cn,cf) {
@@ -2486,6 +2510,7 @@ sub handler {
 
 </script>
 ENDSCRIPT
+    }
     $r->print('</head>'.&Apache::loncommon::bodytag('Grades Spreadsheet').
               '<form action="'.$r->uri.'" name=sheet method=post>');
     $r->print(&hiddenfield('uname',$ENV{'form.uname'}).