version 1.19, 2003/07/16 16:48:51
|
version 1.24, 2003/09/08 20:32:22
|
Line 48 Spreadsheet
|
Line 48 Spreadsheet
|
package Apache::Spreadsheet; |
package Apache::Spreadsheet; |
|
|
use strict; |
use strict; |
|
#use warnings FATAL=>'all'; |
|
#no warnings 'uninitialized'; |
use Apache::Constants qw(:common :http); |
use Apache::Constants qw(:common :http); |
use Apache::lonnet; |
use Apache::lonnet; |
use Safe; |
use Safe; |
Line 90 sub new {
|
Line 92 sub new {
|
type => $stype, |
type => $stype, |
symb => $usymb, |
symb => $usymb, |
errorlog => '', |
errorlog => '', |
maxrow => '', |
maxrow => 0, |
cid => $ENV{'request.course.id'}, |
cid => $ENV{'request.course.id'}, |
cnum => $ENV{'course.'.$ENV{'request.course.id'}.'.num'}, |
cnum => $ENV{'course.'.$ENV{'request.course.id'}.'.num'}, |
cdom => $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, |
cdom => $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, |
Line 229 sub initialize {
|
Line 231 sub initialize {
|
# the descendents of the spreadsheet class. |
# 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 { |
sub initialize_spreadsheet_package { |
&load_spreadsheet_expirationdates(); |
&load_spreadsheet_expirationdates(); |
&clear_spreadsheet_definition_cache(); |
&clear_spreadsheet_definition_cache(); |
Line 248 sub load_spreadsheet_expirationdates {
|
Line 260 sub load_spreadsheet_expirationdates {
|
sub check_expiration_time { |
sub check_expiration_time { |
my $self = shift; |
my $self = shift; |
my ($time)=@_; |
my ($time)=@_; |
|
return 0 if (! defined($time)); |
my ($key1,$key2,$key3,$key4,$key5); |
my ($key1,$key2,$key3,$key4,$key5); |
# Description of keys |
# Description of keys |
# |
# |
Line 794 sub expandnamed {
|
Line 807 sub expandnamed {
|
my @vars=split(/\W+/,$formula); |
my @vars=split(/\W+/,$formula); |
my %values=(); |
my %values=(); |
foreach my $varname ( @vars ) { |
foreach my $varname ( @vars ) { |
if ($varname=~/\D/) { |
if ($varname=~/^(parameter|stores|timestamp)/) { |
$formula=~s/$varname/'$c{\''.$varname.'\'}'/ge; |
$formula=~s/$varname/'$c{\''.$varname.'\'}'/ge; |
$varname=~s/$var/\([\\w:\\- ]\+\)/g; |
$varname=~s/$var/\([\\w:\\- ]\+\)/g; |
foreach (keys(%{$self->{'constants'}})) { |
foreach (keys(%{$self->{'constants'}})) { |
if ($_=~/$varname/) { |
if ($_=~/$varname/) { |
Line 1144 sub display {
|
Line 1157 sub display {
|
} elsif ($outputmode eq 'csv') { |
} elsif ($outputmode eq 'csv') { |
$self->outsheet_csv($r); |
$self->outsheet_csv($r); |
} |
} |
|
$self->cleanup(); |
return; |
return; |
} |
} |
|
|
Line 1217 sub html_editable_cell {
|
Line 1231 sub html_editable_cell {
|
# |
# |
# The encoding string "^A-blah" is placed in []'s inside a regexp, so |
# 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. |
# 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 '&' |
# Escape it again - this time the only encodable character is '&' |
$formula =~ s/\&/\&/g; |
$formula =~ s/\&/\&/g; |
# Glue everything together |
# Glue everything together |
Line 1335 sub create_excel_spreadsheet {
|
Line 1351 sub create_excel_spreadsheet {
|
sub outsheet_excel { |
sub outsheet_excel { |
my $self = shift; |
my $self = shift; |
my ($r) = @_; |
my ($r) = @_; |
|
my $connection = $r->connection(); |
$r->print("<h2>Preparing Excel Spreadsheet</h2>"); |
$r->print("<h2>Preparing Excel Spreadsheet</h2>"); |
# |
# |
# Create excel worksheet |
# Create excel worksheet |
Line 1358 sub outsheet_excel {
|
Line 1375 sub outsheet_excel {
|
$self->excel_output_row($worksheet,0,$rows_output++,'Summary'); |
$self->excel_output_row($worksheet,0,$rows_output++,'Summary'); |
$rows_output++; # skip a line |
$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 |
# Close the excel file |
Line 1376 sub outsheet_excel {
|
Line 1393 sub outsheet_excel {
|
sub outsheet_csv { |
sub outsheet_csv { |
my $self = shift; |
my $self = shift; |
my ($r) = @_; |
my ($r) = @_; |
|
my $connection = $r->connection(); |
my $csvdata = ''; |
my $csvdata = ''; |
my @Values; |
my @Values; |
# |
# |
Line 1399 sub outsheet_csv {
|
Line 1417 sub outsheet_csv {
|
} |
} |
# |
# |
# Output the body of the spreadsheet |
# Output the body of the spreadsheet |
$self->csv_rows($file); |
$self->csv_rows($connection,$file); |
# |
# |
# Close the csv file |
# Close the csv file |
close($file); |
close($file); |
Line 1573 sub load {
|
Line 1591 sub load {
|
sub set_row_sources { |
sub set_row_sources { |
my $self = shift; |
my $self = shift; |
while (my ($cell,$value) = each(%{$self->{'formulas'}})) { |
while (my ($cell,$value) = each(%{$self->{'formulas'}})) { |
next if ($cell !~ /^A(\d+)/ && $1 > 0); |
next if ($cell !~ /^A(\d+)/ || $1 < 1); |
my $row = $1; |
my $row = $1; |
$self->{'row_source'}->{$row} = $value; |
$self->{'row_source'}->{$row} = $value; |
} |
} |
Line 1635 sub save {
|
Line 1653 sub save {
|
return $reply if ($reply ne 'ok'); |
return $reply if ($reply ne 'ok'); |
} |
} |
if ($self->is_default()) { |
if ($self->is_default()) { |
&Apache::lonnet::expirespread('','',$self->{'type'},''); |
if ($self->{'type'} eq 'studentcalc') { |
if ($self->{'type'} eq 'assesscalc') { |
&Apache::lonnet::expirespread('','','studentcalc',''); |
|
} elsif ($self->{'type'} eq 'assesscalc') { |
|
&Apache::lonnet::expirespread('','','assesscalc',''); |
&Apache::lonnet::expirespread('','','studentcalc',''); |
&Apache::lonnet::expirespread('','','studentcalc',''); |
} |
} |
} |
} |