--- loncom/interface/spreadsheet/Spreadsheet.pm 2003/07/16 16:48:51 1.19 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2003/09/05 01:57:54 1.23 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.19 2003/07/16 16:48:51 matthew Exp $ +# $Id: Spreadsheet.pm,v 1.23 2003/09/05 01:57:54 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'}, @@ -229,6 +231,16 @@ sub initialize { # the descendents of the spreadsheet class. } +sub clear_package { + # This method is here to remind you that it will be overridden by + # the descendents of the spreadsheet class. +} + +sub cleanup { + my $self = shift(); + $self->clear_package(); +} + sub initialize_spreadsheet_package { &load_spreadsheet_expirationdates(); &clear_spreadsheet_definition_cache(); @@ -248,6 +260,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 # @@ -794,8 +807,8 @@ sub expandnamed { my @vars=split(/\W+/,$formula); my %values=(); foreach my $varname ( @vars ) { - if ($varname=~/\D/) { - $formula=~s/$varname/'$c{\''.$varname.'\'}'/ge; + if ($varname=~/^(parameter|stores|timestamp)/) { + $formula=~s/$varname/'$c{\''.$varname.'\'}'/ge; $varname=~s/$var/\([\\w:\\- ]\+\)/g; foreach (keys(%{$self->{'constants'}})) { if ($_=~/$varname/) { @@ -1144,6 +1157,7 @@ sub display { } elsif ($outputmode eq 'csv') { $self->outsheet_csv($r); } + $self->cleanup(); return; } @@ -1217,7 +1231,9 @@ sub html_editable_cell { # # The encoding string "^A-blah" is placed in []'s inside a regexp, so # we specify the characters we want left alone by putting a '^' in front. - $formula = &HTML::Entities::encode($formula,"^A-z0-9 !#\$%-;=?~"); + $formula = &HTML::Entities::encode($formula,'^A-z0-9 !#$%-;=?~'); + # HTML::Entities::encode does not catch everything - we need '\' encoded + $formula =~ s/\\/&\#092/g; # Escape it again - this time the only encodable character is '&' $formula =~ s/\&/\&/g; # Glue everything together @@ -1335,6 +1351,7 @@ sub create_excel_spreadsheet { sub outsheet_excel { my $self = shift; my ($r) = @_; + my $connection = $r->connection(); $r->print("

Preparing Excel Spreadsheet

"); # # Create excel worksheet @@ -1358,7 +1375,7 @@ sub outsheet_excel { $self->excel_output_row($worksheet,0,$rows_output++,'Summary'); $rows_output++; # skip a line # - $self->excel_rows($worksheet,$cols_output,$rows_output); + $self->excel_rows($connection,$worksheet,$cols_output,$rows_output); # # # Close the excel file @@ -1376,6 +1393,7 @@ sub outsheet_excel { sub outsheet_csv { my $self = shift; my ($r) = @_; + my $connection = $r->connection(); my $csvdata = ''; my @Values; # @@ -1399,7 +1417,7 @@ sub outsheet_csv { } # # Output the body of the spreadsheet - $self->csv_rows($file); + $self->csv_rows($connection,$file); # # Close the csv file close($file); @@ -1573,7 +1591,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; } @@ -1635,8 +1653,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',''); } }