version 1.47, 2005/05/13 21:16:09
|
version 1.54, 2005/08/26 20:46:46
|
Line 106 sub new {
|
Line 106 sub new {
|
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'}, |
chome => $env{'course.'.$env{'request.course.id'}.'.home'}, |
|
coursedesc => $env{'course.'.$env{'request.course.id'}.'.description'}, |
coursedesc => $env{'course.'.$env{'request.course.id'}.'.description'}, |
coursefilename => $env{'request.course.fn'}, |
coursefilename => $env{'request.course.fn'}, |
# |
# |
# Flags |
# Flags |
temporary => 0, # true if this sheet has been modified but not saved |
temporary => 0, # true if this sheet has been modified but not saved |
new_rows => 0, # true if this sheet has new rows |
new_rows => 0, # true if this sheet has new rows |
|
loaded => 0, # true if the formulas have been loaded |
# |
# |
# blackout is used to determine if any data needs to be hidden from the |
# blackout is used to determine if any data needs to be hidden from the |
# student. |
# student. |
Line 126 sub new {
|
Line 126 sub new {
|
othersheets => [], |
othersheets => [], |
}; |
}; |
# |
# |
$self->{'uhome'} = &Apache::lonnet::homeserver($name,$domain); |
|
# |
|
bless($self,$class); |
bless($self,$class); |
# |
|
# Load in the spreadsheet definition |
|
$self->filename($filename); |
$self->filename($filename); |
if (exists($env{'form.workcopy'}) && |
# |
$self->{'type'} eq $env{'form.workcopy'}) { |
|
$self->load_tmp(); |
|
} else { |
|
$self->load(); |
|
} |
|
return $self; |
return $self; |
} |
} |
|
|
Line 366 $filename = '';
|
Line 357 $filename = '';
|
# |
# |
# user data |
# user data |
$name = ''; |
$name = ''; |
$uhome = ''; |
|
$domain = ''; |
$domain = ''; |
# |
# |
# course data |
# course data |
$csec = ''; |
$csec = ''; |
$chome= ''; |
|
$cnum = ''; |
$cnum = ''; |
$cdom = ''; |
$cdom = ''; |
$cid = ''; |
$cid = ''; |
Line 770 ENDDEFS
|
Line 759 ENDDEFS
|
# itself |
# itself |
my $initstring = ''; |
my $initstring = ''; |
foreach (qw/name domain type symb cid csec coursefilename |
foreach (qw/name domain type symb cid csec coursefilename |
cnum cdom chome uhome/) { |
cnum cdom/) { |
$initstring.= qq{\$$_="$self->{$_}";}; |
$initstring.= qq{\$$_="$self->{$_}";}; |
} |
} |
$initstring.=qq{\$usection="$usection";}; |
$initstring.=qq{\$usection="$usection";}; |
Line 979 sub formulas {
|
Line 968 sub formulas {
|
$self->{'formulas'} = $formulas; |
$self->{'formulas'} = $formulas; |
$self->{'rows'} = []; |
$self->{'rows'} = []; |
$self->{'template_cells'} = []; |
$self->{'template_cells'} = []; |
|
$self->{'loaded'} = 1; |
return; |
return; |
} else { |
} else { |
|
$self->check_formulas_loaded(); |
return %{$self->{'formulas'}}; |
return %{$self->{'formulas'}}; |
} |
} |
} |
} |
|
|
|
sub check_formulas_loaded { |
|
my $self=shift; |
|
if (!$self->{'loaded'}) { |
|
$self->{'loaded'}=1; |
|
# Load in the spreadsheet definition |
|
if (exists($env{'form.workcopy'}) && |
|
$self->{'type'} eq $env{'form.workcopy'}) { |
|
$self->load_tmp(); |
|
} else { |
|
$self->load(); |
|
} |
|
} |
|
} |
|
|
sub set_formula { |
sub set_formula { |
my $self = shift; |
my $self = shift; |
my ($cell,$formula) = @_; |
my ($cell,$formula) = @_; |
|
$self->check_formulas_loaded(); |
$self->{'formulas'}->{$cell}=$formula; |
$self->{'formulas'}->{$cell}=$formula; |
return; |
return; |
} |
} |
Line 997 sub set_formula {
|
Line 1003 sub set_formula {
|
## |
## |
sub formulas_keys { |
sub formulas_keys { |
my $self = shift; |
my $self = shift; |
my @keys = keys(%{$self->{'formulas'}}); |
$self->check_formulas_loaded(); |
return keys(%{$self->{'formulas'}}); |
return keys(%{$self->{'formulas'}}); |
} |
} |
|
|
Line 1008 sub formulas_keys {
|
Line 1014 sub formulas_keys {
|
sub formula { |
sub formula { |
my $self = shift; |
my $self = shift; |
my $cell = shift; |
my $cell = shift; |
|
$self->check_formulas_loaded(); |
if (defined($cell) && exists($self->{'formulas'}->{$cell})) { |
if (defined($cell) && exists($self->{'formulas'}->{$cell})) { |
return $self->{'formulas'}->{$cell}; |
return $self->{'formulas'}->{$cell}; |
} |
} |
Line 1086 sub rebuild_stats {
|
Line 1093 sub rebuild_stats {
|
my $self = shift; |
my $self = shift; |
$self->{'rows'}=[]; |
$self->{'rows'}=[]; |
$self->{'template_cells'}=[]; |
$self->{'template_cells'}=[]; |
|
$self->check_formulas_loaded(); |
while (my ($cell,$formula) = each(%{$self->{'formulas'}})) { |
while (my ($cell,$formula) = each(%{$self->{'formulas'}})) { |
push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0); |
push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0); |
push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/); |
push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/); |
Line 1526 sub outsheet_xml {
|
Line 1534 sub outsheet_xml {
|
## Will be rendered for the user |
## Will be rendered for the user |
## But not on this day |
## But not on this day |
my $Str = '<spreadsheet type="'.$self->{'type'}.'">'."\n"; |
my $Str = '<spreadsheet type="'.$self->{'type'}.'">'."\n"; |
|
$self->check_formulas_loaded(); |
while (my ($cell,$formula) = each(%{$self->{'formulas'}})) { |
while (my ($cell,$formula) = each(%{$self->{'formulas'}})) { |
if ($cell =~ /^template_(\w+)/) { |
if ($cell =~ /^template_(\w+)/) { |
my $col = $1; |
my $col = $1; |
Line 1608 sub load {
|
Line 1617 sub load {
|
my $stype = $self->{'type'}; |
my $stype = $self->{'type'}; |
my $cnum = $self->{'cnum'}; |
my $cnum = $self->{'cnum'}; |
my $cdom = $self->{'cdom'}; |
my $cdom = $self->{'cdom'}; |
my $chome = $self->{'chome'}; |
|
# |
# |
my $filename = $self->filename(); |
my $filename = $self->filename(); |
my $cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
my $cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
Line 1617 sub load {
|
Line 1625 sub load {
|
my ($formulas); |
my ($formulas); |
if (exists($spreadsheets{$cachekey})) { |
if (exists($spreadsheets{$cachekey})) { |
$formulas = $spreadsheets{$cachekey}->{'formulas'}; |
$formulas = $spreadsheets{$cachekey}->{'formulas'}; |
} else { |
$self->formulas($formulas); |
|
$self->{'row_source'}=$spreadsheets{$cachekey}->{'row_source'}; |
|
$self->{'row_numbers'}=$spreadsheets{$cachekey}->{'row_numbers'}; |
|
$self->{'maxrow'}=$spreadsheets{$cachekey}->{'maxrow'}; |
|
} else { |
# Not cached, need to read |
# Not cached, need to read |
if (! defined($filename)) { |
if (! defined($filename)) { |
$formulas = $self->load_system_default_sheet(); |
$formulas = $self->load_system_default_sheet(); |
Line 1651 sub load {
|
Line 1663 sub load {
|
} |
} |
} |
} |
$filename=$self->filename(); # filename may have changed |
$filename=$self->filename(); # filename may have changed |
$cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
$cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
%{$spreadsheets{$cachekey}->{'formulas'}} = %{$formulas}; |
if (ref($formulas) eq 'HASH') { |
|
%{$spreadsheets{$cachekey}->{'formulas'}} = %{$formulas}; |
|
} |
|
$self->formulas($formulas); |
|
$self->set_row_sources(); |
|
$self->set_row_numbers(); |
|
if (ref($self->{'row_source'})) { |
|
%{$spreadsheets{$cachekey}->{'row_source'}} = |
|
%{$self->{'row_source'}}; |
|
} |
|
if (ref($self->{'row_numbers'})) { |
|
%{$spreadsheets{$cachekey}->{'row_numbers'}} = |
|
%{$self->{'row_numbers'}}; |
|
} |
|
$spreadsheets{$cachekey}->{'maxrow'} = $self->{'maxrow'}; |
} |
} |
$self->formulas($formulas); |
|
$self->set_row_sources(); |
|
$self->set_row_numbers(); |
|
} |
} |
|
|
sub set_row_sources { |
sub set_row_sources { |
my $self = shift; |
my $self = shift; |
|
$self->check_formulas_loaded(); |
while (my ($cell,$value) = each(%{$self->{'formulas'}})) { |
while (my ($cell,$value) = each(%{$self->{'formulas'}})) { |
next if ($cell !~ /^A(\d+)/ || $1 < 1); |
next if ($cell !~ /^A(\d+)/ || $1 < 1); |
my $row = $1; |
my $row = $1; |
Line 1671 sub set_row_sources {
|
Line 1695 sub set_row_sources {
|
|
|
sub set_row_numbers { |
sub set_row_numbers { |
my $self = shift; |
my $self = shift; |
|
$self->check_formulas_loaded(); |
while (my ($cell,$value) = each(%{$self->{'formulas'}})) { |
while (my ($cell,$value) = each(%{$self->{'formulas'}})) { |
next if ($cell !~ /^A(\d+)$/); |
next if ($cell !~ /^A(\d+)$/); |
next if (! defined($value)); |
next if (! defined($value)); |
Line 1705 sub save {
|
Line 1730 sub save {
|
my $stype = $self->{'type'}; |
my $stype = $self->{'type'}; |
my $cnum = $self->{'cnum'}; |
my $cnum = $self->{'cnum'}; |
my $cdom = $self->{'cdom'}; |
my $cdom = $self->{'cdom'}; |
my $chome = $self->{'chome'}; |
|
my $filename = $self->{'filename'}; |
my $filename = $self->{'filename'}; |
my $cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
my $cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
# Cache new sheet |
# Cache new sheet |