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

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 07 Oct 2002 19:11:39 -0000


This is a MIME encoded message

--matthew1034017899
Content-Type: text/plain

matthew		Mon Oct  7 15:11:39 2002 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm 
  Log:
  Note: this version has a lot of changes and has not been thoroughly tested.
  Big changes:
      Removed many of the get/set functions.  The variables set are in
  	%{$sheetdata}.
      &loadassessment was modified to cache unescaped, hashified data instead
         of caching the results of &reply.
  Many functions were changed to use $sheetdata to get/store information about
      the sheets.
  &handler was changed to use $sheet and $sheetdata instead of $asheet and 
  $asheetdata.  Also modified to not call the removed get/set functions.
  
  
--matthew1034017899
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20021007151139.txt"

Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.115 loncom/interface/lonspreadsheet.pm:1.116
--- loncom/interface/lonspreadsheet.pm:1.115	Tue Oct  1 03:09:05 2002
+++ loncom/interface/lonspreadsheet.pm	Mon Oct  7 15:11:39 2002
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.115 2002/10/01 07:09:05 albertel Exp $
+# $Id: lonspreadsheet.pm,v 1.116 2002/10/07 19:11:39 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1006,168 +1006,48 @@
 }
 
 # ------------------------------------------------ Add or change formula values
-
 sub setformulas {
     my ($safeeval,%f)=@_;
     %{$safeeval->varglob('f')}=%f;
 }
 
 # ------------------------------------------------ Add or change formula values
-
 sub setconstants {
     my ($safeeval,%c)=@_;
     %{$safeeval->varglob('c')}=%c;
 }
 
 # --------------------------------------------- Set names of other spreadsheets
-
 sub setothersheets {
     my ($safeeval,@os)=@_;
     @{$safeeval->varglob('os')}=@os;
 }
 
 # ------------------------------------------------ Add or change formula values
-
 sub setrowlabels {
     my ($safeeval,%rowlabel)=@_;
     %{$safeeval->varglob('rowlabel')}=%rowlabel;
 }
 
 # ------------------------------------------------------- Calculate spreadsheet
-
 sub calcsheet {
     my $safeeval=shift;
     return $safeeval->reval('&calc();');
 }
 
-# ------------------------------------------------------------------ Get values
-
-sub getvalues {
-    my $safeeval=shift;
-    return $safeeval->reval('%sheet_values');
-}
-
 # ---------------------------------------------------------------- Get formulas
-
 sub getformulas {
     my $safeeval=shift;
     return %{$safeeval->varglob('f')};
 }
 
 # ----------------------------------------------------- Get value of $f{'A'.$n}
-
 sub getfa {
     my ($safeeval,$n)=@_;
     return $safeeval->reval('$f{"A'.$n.'"}');
 }
 
-# -------------------------------------------------------------------- Get type
-
-sub gettype {
-    my $safeeval=shift;
-    return $safeeval->reval('$sheettype');
-}
-
-# ------------------------------------------------------------------ Set maxrow
-
-sub setmaxrow {
-    my ($safeeval,$row)=@_;
-    $safeeval->reval('$maxrow='.$row.';');
-}
-
-# ------------------------------------------------------------------ Get maxrow
-
-sub getmaxrow {
-    my $safeeval=shift;
-    return $safeeval->reval('$maxrow');
-}
-
-# ---------------------------------------------------------------- Set filename
-
-sub setfilename {
-    my ($safeeval,$fn)=@_;
-    $safeeval->reval('$filename="'.$fn.'";');
-}
-
-# ---------------------------------------------------------------- Get filename
-
-sub getfilename {
-    my $safeeval=shift;
-    return $safeeval->reval('$filename');
-}
-
-# --------------------------------------------------------------- Get course ID
-
-sub getcid {
-    my $safeeval=shift;
-    return $safeeval->reval('$cid');
-}
-
-# --------------------------------------------------------- Get course filename
-
-sub getcoursefilename {
-    my $safeeval=shift;
-    return $safeeval->reval('$coursefilename');
-}
-
-# ----------------------------------------------------------- Get course number
-
-sub getcnum {
-    my $safeeval=shift;
-    return $safeeval->reval('$cnum');
-}
-
-# ------------------------------------------------------------- Get course home
-
-sub getchome {
-    my $safeeval=shift;
-    return $safeeval->reval('$chome');
-}
-
-# ----------------------------------------------------------- Get course domain
-
-sub getcdom {
-    my $safeeval=shift;
-    return $safeeval->reval('$cdom');
-}
-
-# ---------------------------------------------------------- Get course section
-
-sub getcsec {
-    my $safeeval=shift;
-    return $safeeval->reval('$csec');
-}
-
-# --------------------------------------------------------------- Get user name
-
-sub getuname {
-    my $safeeval=shift;
-    return $safeeval->reval('$uname');
-}
-
-# ------------------------------------------------------------- Get user domain
-
-sub getudom {
-    my $safeeval=shift;
-    return $safeeval->reval('$udom');
-}
-
-# --------------------------------------------------------------- Get user home
-
-sub getuhome {
-    my $safeeval=shift;
-    return $safeeval->reval('$uhome');
-}
-
-# -------------------------------------------------------------------- Get symb
-
-sub getusymb {
-    my $safeeval=shift;
-    return $safeeval->reval('$usymb');
-}
-
 # ------------------------------------------------------------- Export of A-row
-
 sub exportdata {
     my $safeeval=shift;
     return $safeeval->reval('&exportrowa()');
@@ -1183,7 +1063,7 @@
 # --------------------------------------------- Produce output row n from sheet
 
 sub rown {
-    my ($safeeval,$n)=@_;
+    my ($safeeval,$n,$sheetdata)=@_;
     my $defaultbg;
     my $rowdata='';
     my $dataflag=0;
@@ -1200,7 +1080,7 @@
     my $showf=0;
     my $proc;
     my $maxred=1;
-    my $sheettype=&gettype($safeeval);
+    my $sheettype=$sheetdata->{'sheettype'};
     if ($sheettype eq 'studentcalc') {
         $proc='&outrowassess';
         $maxred=26;
@@ -1296,13 +1176,14 @@
             }
             $tabledata.="<b><font size=+1>$_</font></b></td>";
         }
-        $tabledata.='</tr>'.&rown($safeeval,'-').&rown($safeeval,0);
+        $tabledata.='</tr>'.&rown($safeeval,'-',$sheetdata).
+            &rown($safeeval,0,$sheetdata);
     }
     $r->print($tabledata);
     #
     # Prepare to output rows
     my $row;
-    my $maxrow=&getmaxrow($safeeval);
+    my $maxrow=$sheetdata->{'maxrow'};
     #
     my @sortby=();
     my @sortidx=();
@@ -1323,7 +1204,7 @@
     # Loop through the rows and output them one at a time
     my $n=0;
     for ($row=0;$row<$maxrow;$row++) {
-        my $thisrow=&rown($safeeval,$sortidx[$row]+1);
+        my $thisrow=&rown($safeeval,$sortidx[$row]+1,$sheetdata);
         if ($thisrow) {
             if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) {
                 $r->print("</table>\n<br>\n");
@@ -1346,11 +1227,11 @@
 # ----------------------------------------------- Read list of available sheets
 # 
 sub othersheets {
-    my ($safeeval,$stype)=@_;
+    my ($safeeval,$stype,$sheetdata)=@_;
     #
-    my $cnum  = &getcnum($safeeval);
-    my $cdom  = &getcdom($safeeval);
-    my $chome = &getchome($safeeval);
+    my $cnum  = $sheetdata->{'cnum'};
+    my $cdom  = $sheetdata->{'cdom'};
+    my $chome = $sheetdata->{'chome'};
     #
     my @alternatives=();
     my %results=&Apache::lonnet::dump($stype.'_spreadsheets',$cdom,$cnum);
@@ -1420,7 +1301,7 @@
         }
     }
     # $fn now has a value
-    &setfilename($safeeval,$fn);
+    $sheetdata->{'filename'} = $fn;
     # see if sheet is cached
     my $fstring='';
     if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) {
@@ -1480,6 +1361,8 @@
     $sheetdata{'uhome'} = &Apache::lonnet::homeserver($uname,$udom);
     
     my $safeeval=initsheet($stype);
+    #
+    # Place all the %sheetdata items into the safe space
     my $initstring = '';
     foreach (keys(%sheetdata)) {
         $initstring.= qq{\$$_="$sheetdata{$_}";};
@@ -1490,15 +1373,15 @@
 
 # ------------------------------------------------------------ Save spreadsheet
 sub writesheet {
-    my ($safeeval,$makedef)=@_;
-    my $cid=&getcid($safeeval);
+    my ($safeeval,$makedef,$sheetdata)=@_;
+    my $cid=$sheetdata->{'cid'};
     if (&Apache::lonnet::allowed('opa',$cid)) {
         my %f=&getformulas($safeeval);
-        my $stype=&gettype($safeeval);
-        my $cnum=&getcnum($safeeval);
-        my $cdom=&getcdom($safeeval);
-        my $chome=&getchome($safeeval);
-        my $fn=&getfilename($safeeval);
+        my $stype= $sheetdata->{'sheettype'};
+        my $cnum = $sheetdata->{'cnum'};
+        my $cdom = $sheetdata->{'cdom'};
+        my $chome= $sheetdata->{'chome'};
+        my $fn   = $sheetdata->{'filename'};
         # Cache new sheet
         $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f);
         # Write sheet
@@ -1541,10 +1424,10 @@
 # "Modified workcopy" - interactive only
 #
 sub tmpwrite {
-    my $safeeval=shift;
+    my ($safeeval,$sheetdata) = @_;
     my $fn=$ENV{'user.name'}.'_'.
-        $ENV{'user.domain'}.'_spreadsheet_'.&getusymb($safeeval).'_'.
-           &getfilename($safeeval);
+        $ENV{'user.domain'}.'_spreadsheet_'.$sheetdata->{'usymb'}.'_'.
+           $sheetdata->{'filename'};
     $fn=~s/\W/\_/g;
     $fn=$tmpdir.$fn.'.tmp';
     my $fh;
@@ -1555,10 +1438,10 @@
 
 # ---------------------------------------------------------- Read the temp copy
 sub tmpread {
-    my ($safeeval,$nfield,$nform)=@_;
+    my ($safeeval,$sheetdata,$nfield,$nform)=@_;
     my $fn=$ENV{'user.name'}.'_'.
-           $ENV{'user.domain'}.'_spreadsheet_'.&getusymb($safeeval).'_'.
-           &getfilename($safeeval);
+           $ENV{'user.domain'}.'_spreadsheet_'.$sheetdata->{'usymb'}.'_'.
+           $sheetdata->{'filename'};
     $fn=~s/\W/\_/g;
     $fn=$tmpdir.$fn.'.tmp';
     my $fh;
@@ -1776,7 +1659,7 @@
     }
     if ($changed) { &setformulas($safeeval,%f); }
     #
-    &setmaxrow($safeeval,$maxrow);
+    $sheetdata->{'maxrow'} = $maxrow;
     &setrowlabels($safeeval,%currentlist);
 }
 
@@ -1897,7 +1780,7 @@
         }
     }
     if ($changed) { &setformulas($safeeval,%f); }
-    &setmaxrow($safeeval,$maxrow);
+    $sheetdata->{'maxrow'} = $maxrow;
     &setrowlabels($safeeval,%current);
     #
     undef %current;
@@ -2062,10 +1945,9 @@
     # This is dumb.  It is also necessary :(
     my @oldkeys=keys %returnhash;
     #
-    foreach (@oldkeys) {
-        my $name=$_;
-        my $value=$returnhash{$_};
-        delete $returnhash{$_};
+    foreach my $name (@oldkeys) {
+        my $value=$returnhash{$name};
+        delete $returnhash{$name};
         $name=~s/\_/\./g;
         $returnhash{$name}=$value;
     }
@@ -2074,38 +1956,28 @@
     undef %useropt;
 
     my $userprefix=$uname.'_'.$udom.'_';
-    
+
     unless ($uhome eq 'no_host') { 
         # Get coursedata
         unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
-            my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
-                                             ':resourcedata',$chome);
-            if ($reply!~/^error\:/) {
-                $courserdatas{$cid}=$reply;
-                $courserdatas{$cid.'.last_cache'}=time;
-            }
+            my %Tmp = &Apache::lonnet::dump('resourcedata',$cdom,$cnum);
+            $courserdatas{$cid}=\%Tmp;
+            $courserdatas{$cid.'.last_cache'}=time;
         }
-        foreach (split(/\&/,$courserdatas{$cid})) {
-            my ($name,$value)=split(/\=/,$_);
-            $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
-                &Apache::lonnet::unescape($value);  
+        while (my ($name,$value) = each(%{$courserdatas{$cid}})) {
+            $courseopt{$userprefix.$name}=$value;
         }
         # Get userdata (if present)
-        unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
-            my $reply=
-                &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
-            if ($reply!~/^error\:/) {
-                $userrdatas{$uname.'___'.$udom}=$reply;
-            }
+        unless ((time-$userrdatas{$uname.'@'.$udom.'.last_cache'})<240) {
+            my %Tmp = &Apache::lonnet::dump('resourcedata',$udom,$uname);
+            $userrdatas{$cid} = \%Tmp;
             # Most of the time the user does not have a 'resourcedata.db' 
             # file.  We need to cache that we got nothing instead of bothering
             # with requesting it every time.
-            $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
+            $userrdatas{$uname.'@'.$udom.'.last_cache'}=time;
         }
-        foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
-            my ($name,$value)=split(/\=/,$_);
-            $useropt{$userprefix.&Apache::lonnet::unescape($name)}=
-                &Apache::lonnet::unescape($value);
+        while (my ($name,$value) = each(%{$userrdatas{$cid}})) {
+            $useropt{$userprefix.$name}=$value;
         }
     }
     # now courseopt, useropt initialized for this user and course
@@ -2123,7 +1995,7 @@
     #
     my %c=();
     if (tie(%parmhash,'GDBM_File',
-            &getcoursefilename($safeeval).'_parms.db',&GDBM_READER(),0640)) {
+            $sheetdata->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) {
         my %f=&getformulas($safeeval);
         foreach (keys(%f))  {
             next if ($_!~/^A/);
@@ -2292,8 +2164,8 @@
         &readsheet($thissheet,$sheetdata,$fn);
         &updatesheet($thissheet,$sheetdata);
         &loadrows($thissheet,$sheetdata);
-        &calcsheet($thissheet,$sheetdata); 
-        @exportarr=&exportdata($thissheet,$sheetdata);
+        &calcsheet($thissheet); 
+        @exportarr=&exportdata($thissheet);
         #
         # Store now
         #
@@ -2432,12 +2304,14 @@
 sub handler {
     my $r=shift;
 
+    # Check this server
     my $loaderror=&Apache::lonnet::overloaderror($r);
     if ($loaderror) { return $loaderror; }
+    # Check the course homeserver
     $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;
@@ -2534,7 +2408,7 @@
     }
     # Read new sheet or modified worksheet
     $r->uri=~/\/(\w+)$/;
-    my ($asheet,$asheetdata)=&makenewsheet($aname,$adom,$1,$ENV{'form.usymb'});
+    my ($sheet,$sheetdata)=&makenewsheet($aname,$adom,$1,$ENV{'form.usymb'});
     #
     # If a new formula had been entered, go from work copy
     if ($ENV{'form.unewfield'}) {
@@ -2542,24 +2416,20 @@
         $ENV{'form.unewformula'}=~s/\'/\"/g;
         $r->print('<p>New formula: '.$ENV{'form.unewfield'}.'='.
                   $ENV{'form.unewformula'}.'<p>');
-        &setfilename($asheet,$ENV{'form.ufn'});
-        &tmpread($asheet,$ENV{'form.unewfield'},$ENV{'form.unewformula'});
+        $sheetdata->{'filename'} = $ENV{'form.ufn'};
+        &tmpread($sheet,$sheetdata,
+                 $ENV{'form.unewfield'},$ENV{'form.unewformula'});
     } elsif ($ENV{'form.saveas'}) {
-        &setfilename($asheet,$ENV{'form.ufn'});
-        &tmpread($asheet);
+        $sheetdata->{'filename'} = $ENV{'form.ufn'};
+        &tmpread($sheet,$sheetdata);
     } else {
-        &readsheet($asheet,$asheetdata,$ENV{'form.ufn'});
+        &readsheet($sheet,$sheetdata,$ENV{'form.ufn'});
     }
     # Print out user information
-    unless ($asheetdata->{'sheettype'} eq 'classcalc') {
-        $r->print('<p><b>User:</b> '.$asheetdata->{'uname'}.
-                  '<br><b>Domain:</b> '.$asheetdata->{'udom'});
-#        if (&getcsec($asheet) eq '-1') {
-#            $r->print('<h3><font color=red>'.
-#                      'Not a student in this course</font></h3>');
-#        } else {
-            $r->print('<br><b>Section/Group:</b> '.$asheetdata->{'csec'});
-#        }
+    unless ($sheetdata->{'sheettype'} eq 'classcalc') {
+        $r->print('<p><b>User:</b> '.$sheetdata->{'uname'}.
+                  '<br><b>Domain:</b> '.$sheetdata->{'udom'});
+        $r->print('<br><b>Section/Group:</b> '.$sheetdata->{'csec'});
         if ($ENV{'form.usymb'}) {
             $r->print('<br><b>Assessment:</b> <tt>'.
                       $ENV{'form.usymb'}.'</tt>');
@@ -2567,10 +2437,10 @@
     }
     #
     # Check user permissions
-    if (($asheetdata->{'sheettype'} eq 'classcalc'       ) || 
-        ($asheetdata->{'uname'}     ne $ENV{'user.name'} ) ||
-        ($asheetdata->{'udom'}      ne $ENV{'user.domain'})) {
-        unless (&Apache::lonnet::allowed('vgr',$asheetdata->{'cid'})) {
+    if (($sheetdata->{'sheettype'} eq 'classcalc'       ) || 
+        ($sheetdata->{'uname'}     ne $ENV{'user.name'} ) ||
+        ($sheetdata->{'udom'}      ne $ENV{'user.domain'})) {
+        unless (&Apache::lonnet::allowed('vgr',$sheetdata->{'cid'})) {
             $r->print('<h1>Access Permission Denied</h1>'.
                       '</form></body></html>');
             return OK;
@@ -2580,15 +2450,15 @@
     $r->print('<br />'.
               '<input type="submit" name="forcerecalc" '.
               'value="Completely Recalculate Sheet"><p>');
-    if ($asheetdata->{'sheettype'} eq 'assesscalc') {
+    if ($sheetdata->{'sheettype'} eq 'assesscalc') {
         $r->print('<p><font size=+2>'.
                   '<a href="/adm/studentcalc?'.
-                  'uname='.$asheetdata->{'uname'}.
-                  '&udom='.$asheetdata->{'udom'}.'">'.
+                  'uname='.$sheetdata->{'uname'}.
+                  '&udom='.$sheetdata->{'udom'}.'">'.
                   'Level up: Student Sheet</a></font><p>');
     }
-    if (($asheetdata->{'sheettype'} eq 'studentcalc') && 
-        (&Apache::lonnet::allowed('vgr',$asheetdata->{'cid'}))) {
+    if (($sheetdata->{'sheettype'} eq 'studentcalc') && 
+        (&Apache::lonnet::allowed('vgr',$sheetdata->{'cid'}))) {
         $r->print ('<p><font size=+2><a href="/adm/classcalc">'.
                    'Level up: Course Sheet</a></font><p>');
     }
@@ -2601,13 +2471,13 @@
                   '<input type=text size=20 name=newfn value="'.$fname.'">'.
                   'make default: <input type=checkbox name="makedefufn"><p>');
     }
-    $r->print(&hiddenfield('ufn',&getfilename($asheet)));
+    $r->print(&hiddenfield('ufn',$sheetdata->{'filename'}));
     # Load dialog
     if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
         $r->print('<p><input type=submit name=load value="Load ...">'.
                   '<select name="loadthissheet">'.
                   '<option name="default">Default</option>');
-        foreach (&othersheets($asheet,$asheetdata->{'sheettype'})) {
+        foreach (&othersheets($sheet,$sheetdata->{'sheettype'},$sheetdata)) {
             $r->print('<option name="'.$_.'"');
             if ($ENV{'form.ufn'} eq $_) {
                 $r->print(' selected');
@@ -2615,37 +2485,38 @@
             $r->print('>'.$_.'</option>');
         } 
         $r->print('</select><p>');
-        if ($asheetdata->{'sheettype'} eq 'studentcalc') {
-            &setothersheets($asheet,&othersheets($asheet,'assesscalc'));
+        if ($sheetdata->{'sheettype'} eq 'studentcalc') {
+            &setothersheets($sheet,
+                            &othersheets($sheet,'assesscalc',$sheetdata));
         }
     }
     # Cached sheets
     &expirationdates();
     undef %oldsheets;
     undef %loadedcaches;
-    if ($asheetdata->{'sheettype'} eq 'classcalc') {
+    if ($sheetdata->{'sheettype'} eq 'classcalc') {
         $r->print("Loading previously calculated student sheets ...\n");
         $r->rflush();
         &cachedcsheets();
-    } elsif ($asheetdata->{'sheettype'} eq 'studentcalc') {
+    } elsif ($sheetdata->{'sheettype'} eq 'studentcalc') {
         $r->print("Loading previously calculated assessment sheets ...\n");
         $r->rflush();
-        &cachedssheets($asheetdata->{'uname'},$asheetdata->{'udom'},
-                       $asheetdata->{'uhome'});
+        &cachedssheets($sheetdata->{'uname'},$sheetdata->{'udom'},
+                       $sheetdata->{'uhome'});
     }
     # Update sheet, load rows
     $r->print("Loaded sheet(s), updating rows ...<br>\n");
     $r->rflush();
     #
-    &updatesheet($asheet,$asheetdata);
+    &updatesheet($sheet,$sheetdata);
     $r->print("Updated rows, loading row data ...\n");
     $r->rflush();
     #
-    &loadrows($asheet,$asheetdata,$r);
+    &loadrows($sheet,$sheetdata,$r);
     $r->print("Loaded row data, calculating sheet ...<br>\n");
     $r->rflush();
     #
-    my $calcoutput=&calcsheet($asheet);
+    my $calcoutput=&calcsheet($sheet);
     $r->print('<h3><font color=red>'.$calcoutput.'</h3></font>');
     # See if something to save
     if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
@@ -2653,18 +2524,19 @@
         if ($ENV{'form.saveas'} && ($fname=$ENV{'form.newfn'})) {
             $fname=~s/\W/\_/g;
             if ($fname eq 'default') { $fname='course_default'; }
-            $fname.='_'.$asheetdata->{'sheettype'};
-            &setfilename($asheet,$fname);
+            $fname.='_'.$sheetdata->{'sheettype'};
+            $sheetdata->{'filename'}->$fname;
             $ENV{'form.ufn'}=$fname;
             $r->print('<p>Saving spreadsheet: '.
-                      &writesheet($asheet,$ENV{'form.makedefufn'}).'<p>');
+                      &writesheet($sheet,$ENV{'form.makedefufn'},$sheetdata).
+                      '<p>');
         }
     }
     #
-    #Write the modified worksheet
-    $r->print('<b>Current sheet:</b> '.&getfilename($asheet).'<p>');
-    &tmpwrite($asheet);
-    if ($asheetdata->{'sheettype'} eq 'studentcalc') {
+    # Write the modified worksheet
+    $r->print('<b>Current sheet:</b> '.$sheetdata->{'filename'}.'<p>');
+    &tmpwrite($sheet,$sheetdata);
+    if ($sheetdata->{'sheettype'} eq 'studentcalc') {
         $r->print('<br>Show rows with empty A column: ');
     } else {
         $r->print('<br>Show empty rows: ');
@@ -2687,7 +2559,7 @@
     $r->print('>');
     #
     # CSV format checkbox (classcalc sheets only)
-    if ($asheetdata->{'sheettype'} eq 'classcalc') {
+    if ($sheetdata->{'sheettype'} eq 'classcalc') {
         $r->print(' Output CSV format: <input type="checkbox" '.
                   'name="showcsv" onClick="submit()"');
         if ($ENV{'form.showcsv'}) { $r->print(' checked'); }
@@ -2706,7 +2578,7 @@
 value='Insert Row Bottom'><br>
 ENDINSERTBUTTONS
     # Print out sheet
-    &outsheet($r,$asheet,$asheetdata);
+    &outsheet($r,$sheet,$sheetdata);
     $r->print('</form></body></html>');
     #  Done
     return OK;

--matthew1034017899--