version 1.51, 2005/05/17 20:17:03
|
version 1.66, 2006/04/06 16:43:49
|
Line 85 sub new {
|
Line 85 sub new {
|
my $class = ref($this) || $this; |
my $class = ref($this) || $this; |
my ($stype) = ($class =~ /Apache::(.*)$/); |
my ($stype) = ($class =~ /Apache::(.*)$/); |
# |
# |
my ($name,$domain,$filename,$usymb)=@_; |
my ($name,$domain,$filename,$usymb,$section)=@_; |
if (defined($usymb) && ref($usymb)) { |
if (defined($usymb) && ref($usymb)) { |
$usymb = $usymb->symb; |
$usymb = $usymb->symb; |
} |
} |
Line 95 sub new {
|
Line 95 sub new {
|
if (! defined($domain) || $domain eq '') { |
if (! defined($domain) || $domain eq '') { |
$domain = $env{'user.domain'}; |
$domain = $env{'user.domain'}; |
} |
} |
|
if (! defined($section) || $section eq '') { |
|
$section = &Apache::lonnet::getsection($domain,$name, |
|
$env{'request.course.id'}); |
|
} |
# |
# |
my $self = { |
my $self = { |
name => $name, |
name => $name, |
domain => $domain, |
domain => $domain, |
|
section => $section, |
type => $stype, |
type => $stype, |
symb => $usymb, |
symb => $usymb, |
errorlog => '', |
errorlog => '', |
Line 191 sub make_default {
|
Line 196 sub make_default {
|
{'spreadsheet_default_'.$self->{'type'} => $self->filename()}, |
{'spreadsheet_default_'.$self->{'type'} => $self->filename()}, |
$self->{'cdom'},$self->{'cnum'}); |
$self->{'cdom'},$self->{'cnum'}); |
return $result if ($result ne 'ok'); |
return $result if ($result ne 'ok'); |
|
&Apache::lonnet::appenv('course.'.$self->{'cid'}.'.spreadsheet_default_'. |
|
$self->{'type'} => $self->filename()); |
my $symb = $self->{'symb'}; |
my $symb = $self->{'symb'}; |
$symb = '' if (! defined($symb)); |
$symb = '' if (! defined($symb)); |
&Apache::lonnet::expirespread('','',$self->{'type'},$symb); |
&Apache::lonnet::expirespread('','',$self->{'type'},$symb); |
Line 211 course environment. Returns 0 otherwise
|
Line 218 course environment. Returns 0 otherwise
|
sub is_default { |
sub is_default { |
my $self = shift; |
my $self = shift; |
# Check to find out if we are the default spreadsheet (filenames match) |
# Check to find out if we are the default spreadsheet (filenames match) |
my $default_filename = ''; |
my $default_filename = $env{'course.'.$self->{'cid'}. |
my %tmphash = &Apache::lonnet::get('environment', |
'.spreadsheet_default_'.$self->{'type'}}; |
['spreadsheet_default_'. |
|
$self->{'type'}], |
|
$self->{'cdom'}, |
|
$self->{'cnum'}); |
|
my ($tmp) = keys(%tmphash); |
|
if ($tmp !~ /^(con_lost|error|no_such_host)/i) { |
|
$default_filename = $tmphash{'spreadsheet_default_'.$self->{'type'}}; |
|
} |
|
if ($default_filename =~ /^\s*$/) { |
if ($default_filename =~ /^\s*$/) { |
$default_filename = 'default_'.$self->{'type'}; |
$default_filename = 'default_'.$self->{'type'}; |
} |
} |
Line 384 Calls the system EXT function to determi
|
Line 383 Calls the system EXT function to determi
|
|
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub EXT { |
sub EXT { |
my ($parameter) = @_; |
my ($parameter,$specific_symb) = @_; |
return '' if (! defined($parameter) || $parameter eq ''); |
return '' if (! defined($parameter) || $parameter eq ''); |
$parameter =~ s/^parameter\./resource\./; |
$parameter =~ s/^parameter\./resource\./; |
my $value = &Apache::lonnet::EXT($parameter,$symb,$domain,$name,$usection); |
if ($specific_symb eq '') { $specific_symb = $symb; } |
|
my $value = &Apache::lonnet::EXT($parameter,$specific_symb,$domain,$name, |
|
$usection); |
return $value; |
return $value; |
} |
} |
|
|
Line 703 sub get_values {
|
Line 704 sub get_values {
|
} |
} |
return \@values; |
return \@values; |
} else { |
} else { |
$num = '(\d+)'; |
$num = '([1-9]\d*)'; |
} |
} |
if (($la eq '*') || ($ua eq '*')) { |
if (($la eq '*') || ($ua eq '*')) { |
$alpha='[A-z]'; |
$alpha='[A-z]'; |
Line 812 sub expandnamed {
|
Line 813 sub expandnamed {
|
$result.=$thissum.'+'; |
$result.=$thissum.'+'; |
} |
} |
$result=~s/\+$//; |
$result=~s/\+$//; |
return $result; |
return '('.$result.')'; |
} else { |
} else { |
return 0; |
return 0; |
} |
} |
Line 968 sub formulas {
|
Line 969 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 { |
if (!$self->{'loaded'}) { |
$self->check_formulas_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(); |
|
} |
|
} |
|
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 996 sub set_formula {
|
Line 1004 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 1007 sub formulas_keys {
|
Line 1015 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 1085 sub rebuild_stats {
|
Line 1094 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 1190 sub display {
|
Line 1200 sub display {
|
last; |
last; |
} |
} |
} |
} |
|
$self->{outputmode} = $outputmode; |
if ($outputmode eq 'html') { |
if ($outputmode eq 'html') { |
$self->compute($r); |
$self->compute($r); |
$self->outsheet_html($r); |
$self->outsheet_html($r); |
} elsif ($outputmode eq 'htmlclasslist') { |
} elsif ($outputmode eq 'htmlclasslist') { |
# No computation neccessary... This is kludgy |
# No computation neccessary... This is kludgy |
$self->outsheet_htmlclasslist($r); |
$self->outsheet_htmlclasslist($r); |
|
} elsif ($outputmode eq 'source') { |
|
# No computation necessary. Rumor has it that this is some |
|
# sort of kludge w.r.t. not "computing". It's also |
|
# a bit of of a kludge that we call "outsheet_html" and |
|
# let the 'outputmode' cause the outputting of source. |
|
$self->outsheet_html($r); |
} elsif ($outputmode eq 'excel') { |
} elsif ($outputmode eq 'excel') { |
$self->compute($r); |
$self->compute($r); |
$self->outsheet_excel($r); |
$self->outsheet_excel($r); |
Line 1235 sub html_export_row {
|
Line 1252 sub html_export_row {
|
foreach my $cell (@rowdata) { |
foreach my $cell (@rowdata) { |
if ($cell->{'name'} =~ /^[A-Z]/) { |
if ($cell->{'name'} =~ /^[A-Z]/) { |
$row_html .= '<td bgcolor="'.$color.'">'. |
$row_html .= '<td bgcolor="'.$color.'">'. |
&html_editable_cell($cell,$color,$allowed).'</td>'; |
&html_editable_cell($cell,$color,$allowed, |
|
$self->{outputmode} eq 'source').'</td>'; |
} else { |
} else { |
$row_html .= '<td bgcolor="#DDCCFF">'. |
$row_html .= '<td bgcolor="#DDCCFF">'. |
&html_editable_cell($cell,'#DDCCFF',$allowed).'</td>'; |
&html_editable_cell($cell,'#DDCCFF',$allowed, |
|
$self->{outputmode} eq 'source').'</td>'; |
} |
} |
} |
} |
return $row_html; |
return $row_html; |
Line 1258 sub html_template_row {
|
Line 1277 sub html_template_row {
|
&html_uneditable_cell($cell,'#FFDDDD',$allowed).'</td>'; |
&html_uneditable_cell($cell,'#FFDDDD',$allowed).'</td>'; |
} else { |
} else { |
$row_html .= '<td bgcolor="#EOFFDD">'. |
$row_html .= '<td bgcolor="#EOFFDD">'. |
&html_editable_cell($cell,'#EOFFDD',$allowed).'</td>'; |
&html_editable_cell($cell,'#EOFFDD',$allowed, |
|
$self->{outputmode} eq 'source').'</td>'; |
} |
} |
} |
} |
return $row_html; |
return $row_html; |
} |
} |
|
|
sub html_editable_cell { |
sub html_editable_cell { |
my ($cell,$bgcolor,$allowed) = @_; |
my ($cell,$bgcolor,$allowed,$showsource) = @_; |
my $result; |
my $result; |
my ($name,$formula,$value); |
my ($name,$formula,$value); |
if (defined($cell)) { |
if (defined($cell)) { |
Line 1275 sub html_editable_cell {
|
Line 1295 sub html_editable_cell {
|
} |
} |
$name = '' if (! defined($name)); |
$name = '' if (! defined($name)); |
$formula = '' if (! defined($formula)); |
$formula = '' if (! defined($formula)); |
if (! defined($value)) { |
if ($showsource) { |
|
if (!defined($formula) || $formula =~ /^\s*$/) { |
|
$value = '<font color="'.$bgcolor.'">#</font>'; |
|
} else { |
|
$value = &HTML::Entities::encode($formula, '<>&"'); |
|
} |
|
} elsif (! defined($value)) { |
$value = '<font color="'.$bgcolor.'">#</font>'; |
$value = '<font color="'.$bgcolor.'">#</font>'; |
if ($formula ne '') { |
if ($formula ne '') { |
$value = '<i>undefined value</i>'; |
$value = '<i>undefined value</i>'; |
Line 1328 sub html_row {
|
Line 1354 sub html_row {
|
$row_html .= &html_uneditable_cell($cell,'#FFDDDD'); |
$row_html .= &html_uneditable_cell($cell,'#FFDDDD'); |
} else { |
} else { |
$row_html .= '<td bgcolor="#EOFFDD">'; |
$row_html .= '<td bgcolor="#EOFFDD">'; |
$row_html .= &html_editable_cell($cell,'#E0FFDD',$allowed); |
$row_html .= &html_editable_cell($cell,'#E0FFDD',$allowed, |
|
$self->{outputmode} eq 'source'); |
} |
} |
$row_html .= '</td>'; |
$row_html .= '</td>'; |
} |
} |
Line 1352 sub output_options {
|
Line 1379 sub output_options {
|
description => 'HTML'}, |
description => 'HTML'}, |
{value => 'excel', |
{value => 'excel', |
description => 'Excel'}, |
description => 'Excel'}, |
|
{value => 'source', |
|
description => 'Show Source'}, |
# {value => 'xml', |
# {value => 'xml', |
# description => 'XML'}, |
# description => 'XML'}, |
{value => 'csv', |
{value => 'csv', |
Line 1525 sub outsheet_xml {
|
Line 1554 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 1619 sub load {
|
Line 1649 sub load {
|
$self->{'row_source'}=$spreadsheets{$cachekey}->{'row_source'}; |
$self->{'row_source'}=$spreadsheets{$cachekey}->{'row_source'}; |
$self->{'row_numbers'}=$spreadsheets{$cachekey}->{'row_numbers'}; |
$self->{'row_numbers'}=$spreadsheets{$cachekey}->{'row_numbers'}; |
$self->{'maxrow'}=$spreadsheets{$cachekey}->{'maxrow'}; |
$self->{'maxrow'}=$spreadsheets{$cachekey}->{'maxrow'}; |
} else { |
} 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 1652 sub load {
|
Line 1682 sub load {
|
$formulas = $self->load_system_default_sheet(); |
$formulas = $self->load_system_default_sheet(); |
} |
} |
} |
} |
$filename=$self->filename(); # filename may have changed |
|
$cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
|
%{$spreadsheets{$cachekey}->{'formulas'}} = %{$formulas}; |
|
$self->formulas($formulas); |
$self->formulas($formulas); |
$self->set_row_sources(); |
$self->set_row_sources(); |
$self->set_row_numbers(); |
$self->set_row_numbers(); |
%{$spreadsheets{$cachekey}->{'row_source'}} = %{$self->{'row_source'}}; |
$self->cache_sheet($formulas); |
%{$spreadsheets{$cachekey}->{'row_numbers'}} = %{$self->{'row_numbers'}}; |
} |
$spreadsheets{$cachekey}->{'maxrow'} = $self->{'maxrow'}; |
} |
|
|
|
sub cache_sheet { |
|
my $self = shift; |
|
my ($formulas) = @_; |
|
my $stype = $self->{'type'}; |
|
my $cnum = $self->{'cnum'}; |
|
my $cdom = $self->{'cdom'}; |
|
# |
|
my $filename = $self->filename(); |
|
my $cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
|
|
|
if (ref($formulas) eq 'HASH') { |
|
%{$spreadsheets{$cachekey}->{'formulas'}} = %{$formulas}; |
|
} |
|
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'}; |
} |
} |
|
|
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 1676 sub set_row_sources {
|
Line 1724 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 1711 sub save {
|
Line 1760 sub save {
|
my $cnum = $self->{'cnum'}; |
my $cnum = $self->{'cnum'}; |
my $cdom = $self->{'cdom'}; |
my $cdom = $self->{'cdom'}; |
my $filename = $self->{'filename'}; |
my $filename = $self->{'filename'}; |
my $cachekey = join('_',($cnum,$cdom,$stype,$filename)); |
|
# Cache new sheet |
# Cache new sheet |
%{$spreadsheets{$cachekey}->{'formulas'}}=%f; |
$self->cache_sheet(\%f); |
# Write sheet |
# Write sheet |
foreach (keys(%f)) { |
foreach (keys(%f)) { |
delete($f{$_}) if ($f{$_} eq 'import'); |
delete($f{$_}) if ($f{$_} eq 'import'); |
Line 1729 sub save {
|
Line 1777 sub save {
|
{'spreadsheet_default_'.$stype => $filename }, |
{'spreadsheet_default_'.$stype => $filename }, |
$cdom,$cnum); |
$cdom,$cnum); |
return $reply if ($reply ne 'ok'); |
return $reply if ($reply ne 'ok'); |
|
&Apache::lonnet::appenv('course.'.$self->{'cid'}.'.spreadsheet_default_'. |
|
$self->{'type'} => $self->filename()); |
} |
} |
if ($self->is_default()) { |
if ($self->is_default()) { |
if ($self->{'type'} eq 'studentcalc') { |
if ($self->{'type'} eq 'studentcalc') { |