--- loncom/interface/spreadsheet/Spreadsheet.pm 2003/09/15 20:31:01 1.26 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2004/01/14 16:47:39 1.33 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.26 2003/09/15 20:31:01 matthew Exp $ +# $Id: Spreadsheet.pm,v 1.33 2004/01/14 16:47:39 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,6 +59,7 @@ use HTML::Entities(); use HTML::TokeParser; use Spreadsheet::WriteExcel; use Time::HiRes; +use Apache::lonlocal; ## ## Package Variables @@ -159,7 +160,8 @@ sub filename { if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) { $newfilename = 'default_'.$self->{'type'}; } - if ($newfilename !~ /^default\.$self->{'type'}$/ ) { + if ($newfilename !~ /^default\.$self->{'type'}$/ && + $newfilename !~ /^\/res\/(.*)spreadsheet$/) { if ($newfilename !~ /_$self->{'type'}$/) { $newfilename =~ s/[\s_]*$//; $newfilename .= '_'.$self->{'type'}; @@ -677,7 +679,7 @@ sub calc { return $lastcalc.': Maximum calculation depth exceeded'; } } - return ''; + return 'okay'; } # ------------------------------------------- End of "Inside of the safe space" @@ -749,6 +751,11 @@ sub mask { if (($la eq '*') || ($ua eq '*')) { $alpha='[A-z]'; } else { + if ($la gt $ua) { + my $tmp = $ua; + $ua = $la; + $la = $ua; + } $alpha=qq/[$la-$ua]/; } if ($ld ne '*' && $ud ne '*') { @@ -1133,9 +1140,49 @@ 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 @@ -1144,17 +1191,28 @@ sub calcsheet { sub display { my $self = shift; my ($r) = @_; - $self->compute($r); my $outputmode = 'html'; - if ($ENV{'form.output_format'} =~ /^(html|excel|csv)$/) { - $outputmode = $ENV{'form.output_format'}; + foreach ($self->output_options()) { + if ($ENV{'form.output_format'} eq $_->{'value'}) { + $outputmode = $_->{'value'}; + last; + } } if ($outputmode eq 'html') { + $self->compute($r); $self->outsheet_html($r); + } elsif ($outputmode eq 'htmlclasslist') { + # No computation neccessary... This is kludgy + $self->outsheet_htmlclasslist($r); } elsif ($outputmode eq 'excel') { + $self->compute($r); $self->outsheet_excel($r); } elsif ($outputmode eq 'csv') { + $self->compute($r); $self->outsheet_csv($r); + } elsif ($outputmode eq 'xml') { +# $self->compute($r); + $self->outsheet_xml($r); } $self->cleanup(); return; @@ -1163,6 +1221,18 @@ sub display { ############################################ ## HTML output routines ## ############################################ +sub html_report_error { + my $self = shift(); + my $Str = ''; + if ($self->badcalc()) { + $Str = '
'.$self->calcerror()."\n"; + } + return $Str; +} + sub html_export_row { my $self = shift(); my ($color) = @_; @@ -1277,12 +1347,27 @@ sub html_header { my $self = shift; return '' if (! $ENV{'request.role.adv'}); return "
Output Format |
---|
'.&output_selector()." |
'.&mt('Output Format').' |
'.$self->output_selector()." |
\n".$csvdata."\n"); return 0; } @@ -1421,7 +1521,7 @@ sub outsheet_csv { # Close the csv file close($file); $r->print('
\n\n\n".$Str."\n\n\n"); return $Str; } @@ -1549,7 +1652,7 @@ sub load { # Not cached, need to read if (! defined($filename)) { $formulas = $self->load_system_default_sheet(); - } elsif($self->filename() =~ /^\/res\/.*\.spreadsheet$/) { + } elsif($filename =~ /^\/res\/.*\.spreadsheet$/) { # Load a spreadsheet definition file my $sheetxml=&Apache::lonnet::getfile (&Apache::lonnet::filelocation('',$filename)); @@ -1612,6 +1715,9 @@ sub set_row_numbers { ## sub exportrow { my $self = shift; + if (exists($self->{'badcalc'}) && $self->{'badcalc'}) { + return (); + } my @exportarray; foreach my $column (@UC_Columns) { push(@exportarray,$self->value($column.'0')); @@ -1747,9 +1853,9 @@ sub othersheets { $self->{'cdom'}, $self->{'cnum'}); my ($tmp) = keys(%results); if ($tmp =~ /^(con_lost|error|no_such_host)/i ) { - @alternatives = ('Default'); + @alternatives = (&mt('Default')); } else { - @alternatives = ('Default', sort (keys(%results))); + @alternatives = (&mt('Default'), sort (keys(%results))); } return @alternatives; }