--- loncom/interface/spreadsheet/Spreadsheet.pm 2003/12/05 22:24:20 1.21.2.1 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2003/09/05 01:06:45 1.22 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.21.2.1 2003/12/05 22:24:20 matthew Exp $ +# $Id: Spreadsheet.pm,v 1.22 2003/09/05 01:06:45 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -48,6 +48,8 @@ Spreadsheet package Apache::Spreadsheet; use strict; +use warnings FATAL=>'all'; +no warnings 'uninitialized'; use Apache::Constants qw(:common :http); use Apache::lonnet; use Safe; @@ -90,7 +92,7 @@ sub new { type => $stype, symb => $usymb, errorlog => '', - maxrow => '', + maxrow => 0, cid => $ENV{'request.course.id'}, cnum => $ENV{'course.'.$ENV{'request.course.id'}.'.num'}, cdom => $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, @@ -248,6 +250,7 @@ sub load_spreadsheet_expirationdates { sub check_expiration_time { my $self = shift; my ($time)=@_; + return 0 if (! defined($time)); my ($key1,$key2,$key3,$key4,$key5); # Description of keys # @@ -659,7 +662,7 @@ sub calc { return $lastcalc.': Maximum calculation depth exceeded'; } } - return 'okay'; + return ''; } # ------------------------------------------- End of "Inside of the safe space" @@ -1121,51 +1124,9 @@ sub calcsheet { # $self->logthis($self->get_errorlog()); %{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')}; # $self->logthis($self->get_errorlog()); - if ($result ne 'okay') { - $self->set_calcerror($result); - } return $result; } - -sub set_badcalc { - my $self = shift(); - $self->{'badcalc'} =1; - return; -} - -sub badcalc { - my $self = shift; - if (exists($self->{'badcalc'}) && $self->{'badcalc'}) { - return 1; - } else { - return 0; - } -} - -sub set_calcerror { - my $self = shift; - if (@_) { - $self->set_badcalc(); - if (exists($self->{'calcerror'})) { - $self->{'calcerror'}.="\n".$_[0]; - } else { - $self->{'calcerror'}.=$_[0]; - } - } -} - -sub calcerror { - my $self = shift; - if ($self->badcalc()) { - if (exists($self->{'calcerror'})) { - return $self->{'calcerror'}; - } - } - return; -} - - ########################################################### ## ## Output Helpers @@ -1186,24 +1147,13 @@ sub display { } elsif ($outputmode eq 'csv') { $self->outsheet_csv($r); } + $self->cleanup(); return; } ############################################ ## HTML output routines ## ############################################ -sub html_report_error { - my $self = shift(); - my $Str = ''; - if ($self->badcalc()) { - $Str = '

'. - 'An error occurred while calculating this spreadsheet'. - "

\n". - '
'.$self->calcerror()."
\n"; - } - return $Str; -} - sub html_export_row { my $self = shift(); my ($color) = @_; @@ -1419,7 +1369,6 @@ sub outsheet_excel { # # Close the excel file $workbook->close(); - $r->print($self->html_report_error()); # # Write a link to allow them to download it $r->print('
'. @@ -1460,7 +1409,6 @@ sub outsheet_csv { # # Close the csv file close($file); - $r->print($self->html_report_error()); $r->print('

'. 'Your CSV spreadsheet.'."\n"); # @@ -1631,7 +1579,7 @@ sub load { sub set_row_sources { my $self = shift; while (my ($cell,$value) = each(%{$self->{'formulas'}})) { - next if ($cell !~ /^A(\d+)/ && $1 > 0); + next if ($cell !~ /^A(\d+)/ || $1 < 1); my $row = $1; $self->{'row_source'}->{$row} = $value; } @@ -1693,8 +1641,10 @@ sub save { return $reply if ($reply ne 'ok'); } if ($self->is_default()) { - &Apache::lonnet::expirespread('','',$self->{'type'},''); - if ($self->{'type'} eq 'assesscalc') { + if ($self->{'type'} eq 'studentcalc') { + &Apache::lonnet::expirespread('','','studentcalc',''); + } elsif ($self->{'type'} eq 'assesscalc') { + &Apache::lonnet::expirespread('','','assesscalc',''); &Apache::lonnet::expirespread('','','studentcalc',''); } }