[LON-CAPA-cvs] cvs: modules /matthew/spreadsheet Spreadsheet.pm assesscalc.pm classcalc.pm lonspreadsheet.pm studentcalc.pm

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 17 Apr 2003 14:53:36 -0000


This is a MIME encoded message

--matthew1050591216
Content-Type: text/plain

matthew		Thu Apr 17 10:53:36 2003 EDT

  Modified files:              
    /modules/matthew/spreadsheet	Spreadsheet.pm assesscalc.pm 
                                	classcalc.pm lonspreadsheet.pm 
                                	studentcalc.pm 
  Log:
  Editing of cells now works.
  Assess spreadsheets now show parameter descriptions.
  All data is exported properly.
  All spreadsheets compute properly.
  Still need to enable saving of spreadsheets, selecting other spreadsheet
  definitions, selection of assess spreadsheets in the student spreadsheet,
  excel output and csv output.
  
  
--matthew1050591216
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20030417105336.txt"

Index: modules/matthew/spreadsheet/Spreadsheet.pm
diff -u modules/matthew/spreadsheet/Spreadsheet.pm:1.2 modules/matthew/spreadsheet/Spreadsheet.pm:1.3
--- modules/matthew/spreadsheet/Spreadsheet.pm:1.2	Thu Apr 10 17:12:21 2003
+++ modules/matthew/spreadsheet/Spreadsheet.pm	Thu Apr 17 10:53:36 2003
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.2 2003/04/10 21:12:21 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.3 2003/04/17 14:53:36 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -87,6 +87,30 @@
         coursedesc => $ENV{'course.'.$ENV{'request.course.id'}.'.description'},
     };
     $self->{'coursefilename'} = $ENV{'request.course.fn'};
+    #
+    # Determine filename of spreadsheet
+    my $filename;
+    $filename = $ENV{'form.filename'} if (exists($ENV{'form.filename'}));
+    if (! defined($filename) || 
+        $filename !~ /\w/    || 
+        $filename =~ /\W/) {
+        &Apache::lonnet::logthis('getting filename....');
+        my %tmphash = &Apache::lonnet::get('environment',
+                                  ['spreadsheet_default_'.$self->{'type'}],
+                                           $self->{'cdom'},$self->{'cnum'});
+        my ($tmp) = keys(%tmphash);
+        if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
+            $filename = $tmphash{'spreadsheet_default_'.$stype};
+        } 
+    }
+    if (! defined($filename) || 
+        $filename !~ /\w/    || 
+        $filename =~ /\W/) {
+        $filename = 'default_'.$stype;
+    }
+    $self->{'filename'} = $filename;
+#    &Apache::lonnet::logthis('filename = '.$filename);
+    #
     $self->{'uhome'} = &Apache::lonnet::homeserver($name,$domain);
     #
     $self->{'formulas'} = {};
@@ -94,7 +118,11 @@
     $self->{'othersheets'} = [];
     #
     bless($self,$class);
-    $self->load();
+    if (exists($ENV{'form.workcopy'}) && $class eq 'Apache::'.$ENV{'form.workcopy'}) {
+        $self->load_tmp();
+    } else {
+        $self->load();
+    }
     return $self;
 }
 
@@ -869,6 +897,7 @@
     my $self = shift;
     my ($cell,$formula) = @_;
     $self->{'formulas'}->{$cell}=$formula;
+    return;
 }
 
 ##
@@ -964,7 +993,7 @@
     my $self = shift;
     $self->{'rows'}=[];
     $self->{'template_cells'}=[];
-    foreach my $cell($self->formulas_keys()) {
+    while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {
         push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0);
         push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/);
     }
@@ -1022,6 +1051,41 @@
 ############################################
 ##         HTML output routines           ##
 ############################################
+sub html_export_row {
+    my $self = shift();
+    my $row_html;
+    my @rowdata = $self->get_row(0);
+    foreach my $cell (@rowdata) {
+        if ($cell->{'name'} =~ /^[A-Z]/) {
+	    $row_html .= '<td bgcolor="#CCCCFF">'.
+                &html_editable_cell($cell,'#CCCCFF').'</td>';
+        } else {
+	    $row_html .= '<td bgcolor="#DDCCFF">'.
+                &html_editable_cell($cell,'#DDCCFF').'</td>';
+        }
+    }
+    return $row_html;
+}
+
+sub html_template_row {
+    my $self = shift();
+    my ($num_uneditable) = @_;
+    my $row_html;
+    my @rowdata = $self->get_template_row();
+    my $count = 0;
+    for (my $i = 0; $i<=$#rowdata; $i++) {
+        my $cell = $rowdata[$i];
+        if ($i < $num_uneditable) {
+	    $row_html .= '<td bgcolor="#DDCCFF">'.
+                &html_editable_cell($cell,'#DDCCFF').'</td>';
+        } else {
+	    $row_html .= '<td bgcolor="#EOFFDD">'.
+                &html_editable_cell($cell,'#EOFFDD').'</td>';
+        }
+    }
+    return $row_html;
+}
+
 sub html_editable_cell {
     my ($cell,$bgcolor) = @_;
     my $result;
@@ -1298,21 +1362,21 @@
         while( my ($cell,$formula) = each(%f)) {
             print $fh &Apache::lonnet::escape($cell)."=".&Apache::lonnet::escape($formula)."\n";
         }
+        $fh->close();
     }
 }
 
 sub load_tmp {
     my $self = shift;
-    my ($nfield,$nform)=@_;
-    my $fn=$ENV{'user.name'}.'_'.
-           $ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.
-           $self->{'filename'};
-    $fn=~s/\W/\_/g;
-    $fn=$Apache::lonnet::tmpdir.$fn.'.tmp';
+    my $filename=$ENV{'user.name'}.'_'.
+        $ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.
+            $self->{'filename'};
+    $filename=~s/\W/\_/g;
+    $filename=$Apache::lonnet::tmpdir.$filename.'.tmp';
     my $fh;
     my %fo=();
     my $countrows=0;
-    if ($fh=Apache::File->new($fn)) {
+    if ($fh=Apache::File->new($filename)) {
         while (<$fh>) {
 	    chomp;
             my ($cell,$formula) = split(/=/);
@@ -1320,17 +1384,24 @@
             $formula = &Apache::lonnet::unescape($formula);
             $fo{$cell} = $formula;
         }
-    }
-    if ($nform eq 'changesheet') {
-        $fo{'A'.$nfield}=(split(/__&&&\__/,$fo{'A'.$nfield}))[0];
-        unless ($ENV{'form.sel_'.$nfield} eq 'Default') {
-	    $fo{'A'.$nfield}.='__&&&__'.$ENV{'form.sel_'.$nfield};
-        }
-    } else {
-       if ($nfield) { $fo{$nfield}=$nform; }
+        $fh->close();
     }
     $self->formulas(\%fo);
     $self->set_row_numbers();
+    return;
+}
+
+sub modify_cell {
+    my $self = shift;
+    my ($cell,$formula) = @_;
+    if ($cell =~ /([A-z])\-/) {
+        $cell = 'template_'.$1;
+    } elsif ($cell !~ /^([A-z](\d+)|template_[A-z])$/) {
+        return;
+    }
+    $self->set_formula($cell,$formula);
+    $self->rebuild_stats();
+    return;
 }
 
 ###########################################
@@ -1347,7 +1418,7 @@
     my @alternatives=();
     my %results=&Apache::lonnet::dump($stype.'_spreadsheets',$cdom,$cnum);
     my ($tmp) = keys(%results);
-    unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
+    unless ($tmp =~ /^(con_lost|error|no_such_host)/i ) {
         @alternatives = sort (keys(%results));
     }
     return @alternatives; 
@@ -1372,12 +1443,12 @@
     my $self = shift;
     my @cols=();
     foreach my $col ('A','B','C','D','E','F','G','H','I','J','K','L','M',
-                   'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
-                   'a','b','c','d','e','f','g','h','i','j','k','l','m',
-                   'n','o','p','q','r','s','t','u','v','w','x','y','z') {
+                     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
+                     'a','b','c','d','e','f','g','h','i','j','k','l','m',
+                     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
         push(@cols,{ name    => 'template_'.$col,
                      formula => $self->formula('template_'.$col),
-                     value   => $self->value('template_'.$col) });
+                     value   => $self->formula('template_'.$col) });
     }
     return @cols;
 }
Index: modules/matthew/spreadsheet/assesscalc.pm
diff -u modules/matthew/spreadsheet/assesscalc.pm:1.2 modules/matthew/spreadsheet/assesscalc.pm:1.3
--- modules/matthew/spreadsheet/assesscalc.pm:1.2	Thu Apr 10 17:12:21 2003
+++ modules/matthew/spreadsheet/assesscalc.pm	Thu Apr 17 10:53:36 2003
@@ -1,5 +1,5 @@
 #
-# $Id: assesscalc.pm,v 1.2 2003/04/10 21:12:21 matthew Exp $
+# $Id: assesscalc.pm,v 1.3 2003/04/17 14:53:36 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,47 +61,66 @@
 my $current_name;
 my $current_domain;
 my $current_course;
+
+my %parmhash;
+my %nice_parameter_name;
+
 my %useropt;
 my %courseopt;
-my %parmhash;
 
-my $count = 0;
+sub clear_package {
+    undef(%Exportrows);
+    undef($current_name);
+    undef($current_domain);
+    undef($current_course);
+    undef(%useropt);
+    undef(%courseopt);
+}
 
 sub initialize_package {
     my ($sname,$sdomain) = @_;
+    $current_course = $ENV{'request.course.id'};
     $current_name = $sname;
     $current_domain = $sdomain;
-    ############################
-    ## Set up the export rows ##
-    ############################
+    &load_cached_export_rows();
+    &load_parameter_caches();
+}
+
+sub load_cached_export_rows {
+    #################################
+    ## Set up the export row cache ##
+    #################################
     %Exportrows = undef;
     my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'.
                                     $ENV{'request.course.id'},
-                                    $sdomain,$sname,undef);
+                                    $current_domain,$current_name,undef);
     if ($tmp[0]!~/^error/) {
         my %tmp = @tmp;
+        my $default_filename =  $ENV{'course.'.$ENV{'request.course.id'}.
+                                         '.spreadsheet_default_assesscalc'};
         # We only got one key, so we will access it directly.
         while (my ($key,$sheetdata) = each(%tmp)) {
             my ($sname,$sdom,$sheettype,$symb) = split(':',$key);
             if ($symb =~ /\.time/) {
                 $Exportrows{$symb}->{'time'} = $sheetdata;
             } else {
-                $sheetdata =~ s/^___=___//;
+                $sheetdata =~ s/^(.*)___=___//;
+                my $filename = $1;
+                $filename = $default_filename if (! defined($filename));
                 my @Data = split('___;___',$sheetdata);
-                $Exportrows{$symb}->{'data'} = \@Data;
+                $Exportrows{$symb.':'.$filename}->{'data'} = \@Data;
             }
         }
     }
-    foreach my $symb (keys(%Exportrows)) {
-        if (! exists($Exportrows{$symb}->{'data'}) ||
-            ! defined($Exportrows{$symb}->{'data'})) {
-            delete($Exportrows{$symb});
+    foreach my $key (keys(%Exportrows)) {
+        if (! exists($Exportrows{$key}->{'data'}) ||
+            ! defined($Exportrows{$key}->{'data'})) {
+            delete($Exportrows{$key});
         }
-
     }
 }
 
-sub setup_parameter_caches {
+sub load_parameter_caches {
     my $userprefix = $current_name.':'.$current_domain.'_';
     $userprefix =~ s/:/_/g;
     #
@@ -114,8 +133,8 @@
             &Apache::lonnet::logthis('bad call to setup_parameter_caches');
             return;
         }
-        my $dom =         $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
-        my $id =         $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+        my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+        my $id  = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
         my %Tmp = &Apache::lonnet::dump('resourcedata',$dom,$id);
         while (my ($name,$value) = each(%Tmp)) {
             $courseopt{$userprefix.$name}=$value;
@@ -133,15 +152,21 @@
     }
 }
 
-sub clear_package {
-    undef(%Exportrows);
-    undef($current_name);
-    undef($current_domain);
-    undef(%useropt);
-    undef(%courseopt);
+sub ensure_current_parameter_caches {
+    my $self = shift;
+    if (! defined($current_name)   || 
+        ! defined($current_domain) || 
+        ! defined($current_course) ||
+        $current_name ne $self->{'name'}     || 
+        $current_domain ne $self->{'domain'} ||
+        $current_course ne $ENV{'request.course.id'} ) {
+        #
+        $current_name = $self->{'name'};
+        $current_domain = $self->{'domain'};
+        &load_parameter_caches();
+    }
 }
 
-
 ##################################################
 ##################################################
 
@@ -236,7 +261,7 @@
     return '';
 }
 
-sub gettitle {
+sub get_title {
     my $self = shift;
     my $title;
     if (($self->{'usymb'} eq '_feedback') ||
@@ -245,15 +270,23 @@
         ($self->{'usymb'} eq '_tutoring')) {
         $title = $self->{'usymb'};
         $title =~ s/^_//;
-        $title = ucfirst($title);
-        return $title;
+        $title = '<h1>'.ucfirst($title)."</h1>\n";
+    } else {
+        $title = '<h1>'.&Apache::lonnet::gettitle($self->{'symb'})."</h1>\n";
     }
-    my $navmap = Apache::lonnavmaps::navmap->new(Apache->request,
-                                $ENV{'request.course.fn'}.'.db',
-                                $ENV{'request.coures.fn'}.'_parms.db',0,0);
-    my $resource = $navmap->getBySymb($self->{'symb'});
-    $title = $resource->title();
-    $navmap->untieHashes();
+    $title .= '<h2>'.$self->{'name'}.'@'.$self->{'domain'}."</h2>\n";
+    $title .= '<h3>'.localtime(time).'</h3>';
+    #
+    return $title;
+}
+
+sub parent_link {
+    my $self = shift;
+    my $link .= '<p><a href="/adm/studentcalc?'.
+        'sname='.$self->{'name'}.
+            '&sdomain='.$self->{'domain'}.'">'.
+                'Student level sheet</a></p>'."\n";
+    return $link;
 }
 
 sub outsheet_html {
@@ -289,11 +322,11 @@
     #
     # Print out template row
     $r->print('<tr><td>Template</td><td>&nbsp;</td>'.
-	      $self->html_row($num_uneditable,'-')."</tr>\n");
+	      $self->html_template_row($num_uneditable)."</tr>\n");
     #
     # Print out summary/export row
     $r->print('<tr><td>Export</td><td>0</td>'.
-	      $self->html_row(0,0)."</tr>\n");
+	      $self->html_export_row()."</tr>\n");
     #
     # Prepare to output rows
     $tableheader =<<"END";
@@ -328,7 +361,14 @@
     my $parameter_name = $self->{'formulas'}->{'A'.$row};
     my @rowdata = $self->get_row($row);
     my $num_cols_output = 0;
-    my $row_html = '<td>'.$parameter_name.'</td>';
+    my $row_html;
+    if (exists($nice_parameter_name{$parameter_name})) {
+        my $name = $nice_parameter_name{$parameter_name};
+        $name =~ s/ /\&nbsp;/g;
+        $row_html .= '<td>'.$name.'<br />'.$parameter_name.'</td>';
+    } else {
+        $row_html .= '<td>'.$parameter_name.'</td>';
+    }
     foreach my $cell (@rowdata) {
 	if ($requester_is_student || 
 	    $num_cols_output++ < $num_uneditable) {
@@ -360,16 +400,13 @@
     $self->outsheet_html($r);
 }
 
-my %CourseResourceData;
-my %UserResourceData;
-
 sub compute {
     my $self = shift;
     $self->initialize_safe_space();
     #
     # Definitions
+    undef(%nice_parameter_name);
     my %parameters;   # holds underscored parameters by name
-    my %parameter_names; # I have no idea.
     #
     # Get the metadata fields and determine their proper names
     my ($symap,$syid,$srcf)=split(/___/,$self->{'symb'});
@@ -385,13 +422,11 @@
             $display .= &Apache::lonnet::metadata($srcf,$cleaned_name.'.name');
         }
         $parameters{$cleaned_name}++;
-        $parameter_names{$cleaned_name} = $display;
-    } 
+        $nice_parameter_name{$cleaned_name} = $display;
+    }
     #
     # Get the values of the metadata fields
-    $current_name = $self->{'name'};
-    $current_domain = $self->{'domain'};
-    &setup_parameter_caches();
+    $self->ensure_current_parameter_caches();
     my $filename = $self->{'coursefilename'}.'_parms.db';
     if (tie(%parmhash,'GDBM_File',
             $self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) {
@@ -456,7 +491,9 @@
     return;
 }
 
-
+##
+## sett overrides Spreadsheet::sett
+##
 sub sett {
     my $self = shift;
     my %t=();
@@ -504,10 +541,13 @@
     my $symb = $self->{'symb'};
     if (! exists($Exportrows{$symb}) || ! defined($Exportrows{$symb}) ||
         ! $self->check_expiration_time($Exportrows{$symb}->{'time'})) {
-        $self->logthis('computing...');
         $self->compute();
     }
     my @Data = @{$Exportrows{$symb}->{'data'}};
+    if ($Data[0] =~ /^(.*)___=___/) {
+        $self->{'sheetname'} = $1;
+        $Data[0] =~ s/^(.*)___=___//;
+    }
     for (my $i=0;$i<$#Data;$i++) {
         $Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i]));
     }
Index: modules/matthew/spreadsheet/classcalc.pm
diff -u modules/matthew/spreadsheet/classcalc.pm:1.2 modules/matthew/spreadsheet/classcalc.pm:1.3
--- modules/matthew/spreadsheet/classcalc.pm:1.2	Thu Apr 10 17:12:21 2003
+++ modules/matthew/spreadsheet/classcalc.pm	Thu Apr 17 10:53:36 2003
@@ -1,5 +1,5 @@
 #
-# $Id: classcalc.pm,v 1.2 2003/04/10 21:12:21 matthew Exp $
+# $Id: classcalc.pm,v 1.3 2003/04/17 14:53:36 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -78,13 +78,17 @@
     return @SortedStudents;
 }
 
-sub gettitle {
+sub get_title {
     my $self = shift;
     my $title = '<h2>'.$self->{'coursedesc'}."</h2>\n";
     # Section info should be included
     return $title;
 }
 
+sub parent_link {
+    return '';
+}
+
 sub outsheet_html {
     my $self = shift;
     my ($r) = @_;
@@ -119,11 +123,11 @@
     #
     # Print out template row
     $r->print('<tr><td>Template</td><td>&nbsp;</td>'.
-	      $self->html_row($num_uneditable,'-')."</tr>\n");
+	      $self->html_template_row($num_uneditable)."</tr>\n");
     #
     # Print out summary/export row
     $r->print('<tr><td>Summary</td><td>0</td>'.
-	      $self->html_row($num_uneditable,0)."</tr>\n");
+	      $self->html_export_row()."</tr>\n");
     #
     # Prepare to output rows
     $tableheader =<<"END";
@@ -204,14 +208,19 @@
 	my @exportdata = $studentsheet->export_data();
 	my $rownum = $self->get_row_number_from_key
 	    ($student->{'username'}.':'.$student->{'domain'});
-	# I really want to try doing the following assignment using
-	# hash and array slices....
+        #
+        # The 'A' column formulas hold data that must be saved....
+        my $data = shift(@exportdata);
+        $c{'A'.$rownum} = $data if (defined($data));
+        # Okay, now deal with the remaining columns
 	my $i=0;
-	foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) {
+	foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
             my $cell = $_.$rownum;
             my $data = $exportdata[$i];
-            $f{$cell} = $data if (defined($data));
-            $c{$cell} = $data if (defined($data));
+            if (defined($data)) {
+                $f{$cell} = 'import';
+                $c{$cell} = $data;
+            }
             $i++;
 	}
         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
Index: modules/matthew/spreadsheet/lonspreadsheet.pm
diff -u modules/matthew/spreadsheet/lonspreadsheet.pm:1.1 modules/matthew/spreadsheet/lonspreadsheet.pm:1.2
--- modules/matthew/spreadsheet/lonspreadsheet.pm:1.1	Wed Apr  9 16:57:56 2003
+++ modules/matthew/spreadsheet/lonspreadsheet.pm	Thu Apr 17 10:53:36 2003
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.1 2003/04/09 20:57:56 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.2 2003/04/17 14:53:36 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -74,7 +74,7 @@
 
 sub hiddenfield {
     my ($name,$value)=@_;
-    return "\n".'<input type=hidden name="'.$name.'" value="'.$value.'">';
+    return "\n".'<input type=hidden name="'.$name.'" value="'.$value.'" />';
 }
 
 sub selectbox {
@@ -173,9 +173,9 @@
         edit_text += '</br>';
         edit_text += '<input type="button" name="accept" value="Accept"';
         edit_text += ' onClick=\\\'javascript:';
-        edit_text += 'opener.document.sheet.unewfield.value=';
+        edit_text += 'opener.document.sheet.cell.value=';
         edit_text +=     '"'+cellname+'";';
-        edit_text += 'opener.document.sheet.unewformula.value=';
+        edit_text += 'opener.document.sheet.newformula.value=';
         edit_text +=     'document.editwinform.newformula.value;';
         edit_text += 'opener.document.sheet.submit();';
         edit_text += 'self.close()\\\' />';
@@ -197,26 +197,39 @@
     }
     $r->print('</head>'.&Apache::loncommon::bodytag('Grades Spreadsheet').
               '<form action="'.$r->uri.'" name="sheet" method="post">');
-    $r->print(&hiddenfield('name'  ,$ENV{'form.sname'}).
-              &hiddenfield('domain',$ENV{'form.sdomain'}).
-              &hiddenfield('symb'  ,$ENV{'form.usymb'}).
+    $r->print(&hiddenfield('sname'  ,$ENV{'form.sname'}).
+              &hiddenfield('sdomain',$ENV{'form.sdomain'}).
+              &hiddenfield('usymb'  ,$ENV{'form.usymb'}).
               &hiddenfield('cell'  ,'').
               &hiddenfield('newformula',''));
     $r->rflush();
     #
     my $spreadsheet = undef;
     if ($sheettype eq 'classcalc') {
-        $spreadsheet = Apache::classcalc->new($name,$domain,
-                                                              $symb);
+        $spreadsheet = Apache::classcalc->new($name,$domain,undef);
     } elsif ($sheettype eq 'studentcalc') {
-        $spreadsheet = Apache::studentcalc->new($name,$domain,
-                                                                $symb);
-    } elsif ($sheettype eq 'assesscalc') {
-        $spreadsheet = Apache::assesscalc->new($name,$domain,
-                                                               $symb);
+        $spreadsheet = Apache::studentcalc->new($name,$domain,undef);
+    } elsif ($sheettype eq 'assesscalc' && defined($symb)) {
+        $spreadsheet = Apache::assesscalc->new($name,$domain,$symb);
     } else {
         &Apache::lonnet::logthis('Unable to determine spreadsheet type');
     }
+    ##
+    ## Deal with modified work copies
+    ##
+    if (exists($ENV{'form.newformula'}) && defined($ENV{'form.newformula'}) && 
+        exists($ENV{'form.cell'})       && defined($ENV{'form.cell'})) {
+        $spreadsheet->logthis("storing cell");
+        $spreadsheet->modify_cell($ENV{'form.cell'},$ENV{'form.newformula'});
+        $spreadsheet->logthis("saving sheet in temp");
+        $spreadsheet->save_tmp();
+        # output that we are dealing with a temporary file
+        $r->print(&hiddenfield('workcopy',$sheettype));
+        $r->print('<pre>'.$ENV{'form.cell'}.' = '.
+                  $ENV{'form.newformula'}.'</pre>'."\n");
+    }
+    $r->print($spreadsheet->get_title());
+    $r->print($spreadsheet->parent_link());
     if (defined($spreadsheet)) {
         $spreadsheet->display($r);
     }
@@ -227,3 +240,4 @@
 1;
 
 __END__
+
Index: modules/matthew/spreadsheet/studentcalc.pm
diff -u modules/matthew/spreadsheet/studentcalc.pm:1.2 modules/matthew/spreadsheet/studentcalc.pm:1.3
--- modules/matthew/spreadsheet/studentcalc.pm:1.2	Thu Apr 10 17:12:21 2003
+++ modules/matthew/spreadsheet/studentcalc.pm	Thu Apr 17 10:53:36 2003
@@ -1,5 +1,5 @@
 #
-# $Id: studentcalc.pm,v 1.2 2003/04/10 21:12:21 matthew Exp $
+# $Id: studentcalc.pm,v 1.3 2003/04/17 14:53:36 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,6 +61,11 @@
 my %Exportrows = ();
 
 sub initialize_package {
+    &initialize_sequence_cache();
+    &initialize_export_rows();
+}
+
+sub initialize_sequence_cache {
     #
     # Set up the sequences and assessments
     @Sequences = ();
@@ -72,6 +77,9 @@
         return;
     }
     @Sequences = @{$sequences} if (ref($sequences) eq 'ARRAY');
+}
+
+sub initialize_export_rows {
     ############################
     ## Set up the export rows ##
     ############################
@@ -79,6 +87,7 @@
     my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets',
 		     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'},undef);
+    my %Selected_Assess_Sheet;
     if ($tmp[0]!~/^error/) {
         my %tmp = @tmp;
         # We only got one key, so we will access it directly.
@@ -104,8 +113,23 @@
 }
 
 sub export_sheet_as_excel {} # spreadsheet, overridden by student
-sub gettitle {}
-sub exportrow {}
+
+sub get_title {
+    my $self = shift;
+    my $title = '';
+    $title .= '<h2>Spreadsheet for '.
+        $self->{'name'}.'@'.$self->{'domain'}.'</h2>';
+    return $title;
+}
+
+sub parent_link {
+    my $self = shift;
+    my $link .= '<p><a href="/adm/classcalc?'.
+        'sname='.$self->{'name'}.
+            '&sdomain='.$self->{'domain'}.'">'.
+                'Course level sheet</a></p>'."\n";
+    return $link;
+}
 
 sub outsheet_html {
     my $self = shift;
@@ -141,11 +165,11 @@
     #
     # Print out template row
     $r->print('<tr><td>Template</td><td>&nbsp;</td>'.
-	      $self->html_row($num_uneditable,'-')."</tr>\n");
+	      $self->html_template_row($num_uneditable)."</tr>\n");
     #
     # Print out summary/export row
     $r->print('<tr><td>Export</td><td>0</td>'.
-	      $self->html_row($num_uneditable,0)."</tr>\n");
+	      $self->html_export_row()."</tr>\n");
     $r->print("</table>\n");
     #
     # Prepare to output rows
@@ -164,11 +188,11 @@
     #
     my $num_output = 1;
     if (scalar(@Sequences)< 1) {
-        &initialize_package();
+        &initialize_sequence_cache();
     }
     foreach my $Sequence (@Sequences) {
 	next if ($Sequence->{'num_assess'} < 1);
-	$r->print("<h2>".$Sequence->{'title'}."</h2>\n");
+	$r->print("<h3>".$Sequence->{'title'}."</h3>\n");
  	$r->print($tableheader);
 	foreach my $resource (@{$Sequence->{'contents'}}) {
 	    next if ($resource->{'type'} ne 'assessment');
@@ -178,7 +202,9 @@
                       '<a href="/adm/assesscalc?sname='.$self->{'name'}.
                       '&sdomain='.$self->{'domain'}.
                       '&usymb='.$resource->{'symb'}.'">'.
-                      $resource->{'title'}.'</a></td>'.
+                      $resource->{'title'}.'</a>'.
+                      ''.'</td>'.
+
 		      $self->html_row($num_uneditable,$rownum)."</tr>\n");
 	}
 	$r->print("</table>\n");
@@ -232,15 +258,20 @@
             my @exportdata = $assessSheet->export_data();
             my $rownum = $self->get_row_number_from_key
                                ($resource->{'symb'});
-            # I really want to try doing the following assignment using
-            # hash and array slices....
+            #
+            # Be sure not to disturb the formulas in the 'A' column
+            my $data = shift(@exportdata);
+            $c{'A'.$rownum} = $data if (defined($data));
+            #
+            # Deal with the remaining columns
             my $i=0;
-            foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) {
+            foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
                 my $cell = $_.$rownum;
                 my $data = $exportdata[$i];
-#                $self->logthis("setting $cell = $data");
-                $f{$cell} = $data if (defined($data));
-                $c{$cell} = $data if (defined($data));
+                if (defined($data)) {
+                    $f{$cell} = 'import';
+                    $c{$cell} = $data;
+                }
                 $i++;
             }
         }

--matthew1050591216--