--- loncom/interface/spreadsheet/Spreadsheet.pm 2003/08/26 19:14:06 1.21 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2003/12/05 22:24:20 1.21.2.1 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.21 2003/08/26 19:14:06 matthew Exp $ +# $Id: Spreadsheet.pm,v 1.21.2.1 2003/12/05 22:24:20 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -659,7 +659,7 @@ sub calc { return $lastcalc.': Maximum calculation depth exceeded'; } } - return ''; + return 'okay'; } # ------------------------------------------- End of "Inside of the safe space" @@ -1121,9 +1121,51 @@ 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 @@ -1150,6 +1192,18 @@ sub display { ############################################ ## 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) = @_; @@ -1365,6 +1419,7 @@ 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('
'. @@ -1405,6 +1460,7 @@ sub outsheet_csv { # # Close the csv file close($file); + $r->print($self->html_report_error()); $r->print('

'. 'Your CSV spreadsheet.'."\n"); #