version 1.29, 2003/11/11 14:17:20
|
version 1.34, 2004/01/15 21:20:07
|
Line 160 sub filename {
|
Line 160 sub filename {
|
if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) { |
if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) { |
$newfilename = 'default_'.$self->{'type'}; |
$newfilename = 'default_'.$self->{'type'}; |
} |
} |
if ($newfilename !~ /^default\.$self->{'type'}$/ ) { |
if ($newfilename !~ /^default\.$self->{'type'}$/ && |
|
$newfilename !~ /^\/res\/(.*)spreadsheet$/) { |
if ($newfilename !~ /_$self->{'type'}$/) { |
if ($newfilename !~ /_$self->{'type'}$/) { |
$newfilename =~ s/[\s_]*$//; |
$newfilename =~ s/[\s_]*$//; |
$newfilename .= '_'.$self->{'type'}; |
$newfilename .= '_'.$self->{'type'}; |
Line 678 sub calc {
|
Line 679 sub calc {
|
return $lastcalc.': Maximum calculation depth exceeded'; |
return $lastcalc.': Maximum calculation depth exceeded'; |
} |
} |
} |
} |
return ''; |
return 'okay'; |
} |
} |
|
|
# ------------------------------------------- End of "Inside of the safe space" |
# ------------------------------------------- End of "Inside of the safe space" |
Line 1139 sub calcsheet {
|
Line 1140 sub calcsheet {
|
# $self->logthis($self->get_errorlog()); |
# $self->logthis($self->get_errorlog()); |
%{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')}; |
%{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')}; |
# $self->logthis($self->get_errorlog()); |
# $self->logthis($self->get_errorlog()); |
|
if ($result ne 'okay') { |
|
$self->set_calcerror($result); |
|
} |
return $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 |
## Output Helpers |
Line 1150 sub calcsheet {
|
Line 1191 sub calcsheet {
|
sub display { |
sub display { |
my $self = shift; |
my $self = shift; |
my ($r) = @_; |
my ($r) = @_; |
$self->compute($r); |
|
my $outputmode = 'html'; |
my $outputmode = 'html'; |
if ($ENV{'form.output_format'} =~ /^(html|excel|csv)$/) { |
foreach ($self->output_options()) { |
$outputmode = $ENV{'form.output_format'}; |
if ($ENV{'form.output_format'} eq $_->{'value'}) { |
|
$outputmode = $_->{'value'}; |
|
last; |
|
} |
} |
} |
if ($outputmode eq 'html') { |
if ($outputmode eq 'html') { |
|
$self->compute($r); |
$self->outsheet_html($r); |
$self->outsheet_html($r); |
|
} elsif ($outputmode eq 'htmlclasslist') { |
|
# No computation neccessary... This is kludgy |
|
$self->outsheet_htmlclasslist($r); |
} elsif ($outputmode eq 'excel') { |
} elsif ($outputmode eq 'excel') { |
|
$self->compute($r); |
$self->outsheet_excel($r); |
$self->outsheet_excel($r); |
} elsif ($outputmode eq 'csv') { |
} elsif ($outputmode eq 'csv') { |
|
$self->compute($r); |
$self->outsheet_csv($r); |
$self->outsheet_csv($r); |
|
} elsif ($outputmode eq 'xml') { |
|
# $self->compute($r); |
|
$self->outsheet_xml($r); |
} |
} |
$self->cleanup(); |
$self->cleanup(); |
return; |
return; |
Line 1169 sub display {
|
Line 1221 sub display {
|
############################################ |
############################################ |
## HTML output routines ## |
## HTML output routines ## |
############################################ |
############################################ |
|
sub html_report_error { |
|
my $self = shift(); |
|
my $Str = ''; |
|
if ($self->badcalc()) { |
|
$Str = '<h3 style="color:red">'. |
|
&mt('An error occurred while calculating this spreadsheet'). |
|
"</h3>\n". |
|
'<pre>'.$self->calcerror()."</pre>\n"; |
|
} |
|
return $Str; |
|
} |
|
|
sub html_export_row { |
sub html_export_row { |
my $self = shift(); |
my $self = shift(); |
my ($color) = @_; |
my ($color) = @_; |
Line 1284 sub html_header {
|
Line 1348 sub html_header {
|
return '' if (! $ENV{'request.role.adv'}); |
return '' if (! $ENV{'request.role.adv'}); |
return "<table>\n". |
return "<table>\n". |
'<tr><th align="center">'.&mt('Output Format').'</th></tr>'."\n". |
'<tr><th align="center">'.&mt('Output Format').'</th></tr>'."\n". |
'<tr><td>'.&output_selector()."</td></tr>\n". |
'<tr><td>'.$self->output_selector()."</td></tr>\n". |
"</table>\n"; |
"</table>\n"; |
} |
} |
|
|
|
## |
|
## Default output types are HTML, Excel, and CSV |
|
sub output_options { |
|
my $self = shift(); |
|
return ({value => 'html', |
|
description => 'HTML'}, |
|
{value => 'excel', |
|
description => 'Excel'}, |
|
# {value => 'xml', |
|
# description => 'XML'}, |
|
{value => 'csv', |
|
description => 'Comma Separated Values'},); |
|
} |
|
|
sub output_selector { |
sub output_selector { |
|
my $self = shift(); |
my $output_selector = '<select name="output_format" size="3">'."\n"; |
my $output_selector = '<select name="output_format" size="3">'."\n"; |
my $default = 'html'; |
my $default = 'html'; |
if (exists($ENV{'form.output_format'})) { |
if (exists($ENV{'form.output_format'})) { |
Line 1296 sub output_selector {
|
Line 1375 sub output_selector {
|
} else { |
} else { |
$ENV{'form.output_format'} = $default; |
$ENV{'form.output_format'} = $default; |
} |
} |
foreach (['html','HTML'], |
foreach ($self->output_options()) { |
['excel','Excel'], |
$output_selector.='<option value="'.$_->{'value'}.'"'; |
['csv','Comma Separated Values']) { |
if ($_->{'value'} eq $default) { |
my ($name,$description) = @{$_}; |
|
$output_selector.=qq{<option value="$name"}; |
|
if ($name eq $default) { |
|
$output_selector .= ' selected'; |
$output_selector .= ' selected'; |
} |
} |
$output_selector .= ">".&mt($description)."</option>\n"; |
$output_selector .= ">".&mt($_->{'description'})."</option>\n"; |
} |
} |
$output_selector .= "</select>\n"; |
$output_selector .= "</select>\n"; |
return $output_selector; |
return $output_selector; |
Line 1353 sub create_excel_spreadsheet {
|
Line 1429 sub create_excel_spreadsheet {
|
return ($workbook,$filename); |
return ($workbook,$filename); |
} |
} |
|
|
|
# |
|
# This routine is just a stub |
|
sub outsheet_htmlclasslist { |
|
my $self = shift; |
|
my ($r) = @_; |
|
$r->print('<h2>'.&mt("This output is not supported").'</h2>'); |
|
$r->rflush(); |
|
return; |
|
} |
|
|
sub outsheet_excel { |
sub outsheet_excel { |
my $self = shift; |
my $self = shift; |
my ($r) = @_; |
my ($r) = @_; |
my $connection = $r->connection(); |
my $connection = $r->connection(); |
|
# |
|
$r->print($self->html_report_error()); |
|
$r->rflush(); |
|
# |
$r->print("<h2>".&mt('Preparing Excel Spreadsheet')."</h2>"); |
$r->print("<h2>".&mt('Preparing Excel Spreadsheet')."</h2>"); |
# |
# |
# Create excel worksheet |
# Create excel worksheet |
Line 1399 sub outsheet_csv {
|
Line 1489 sub outsheet_csv {
|
my $self = shift; |
my $self = shift; |
my ($r) = @_; |
my ($r) = @_; |
my $connection = $r->connection(); |
my $connection = $r->connection(); |
|
# |
|
$r->print($self->html_report_error()); |
|
$r->rflush(); |
|
# |
my $csvdata = ''; |
my $csvdata = ''; |
my @Values; |
my @Values; |
# |
# |
Line 1463 sub outsheet_xml {
|
Line 1557 sub outsheet_xml {
|
## But not on this day |
## But not on this day |
my $Str = '<spreadsheet type="'.$self->{'type'}.'">'."\n"; |
my $Str = '<spreadsheet type="'.$self->{'type'}.'">'."\n"; |
while (my ($cell,$formula) = each(%{$self->{'formulas'}})) { |
while (my ($cell,$formula) = each(%{$self->{'formulas'}})) { |
if ($cell =~ /^template_(\d+)/) { |
if ($cell =~ /^template_(\w+)/) { |
my $col = $1; |
my $col = $1; |
$Str .= '<template col="'.$col.'">'.$formula.'</template>'."\n"; |
$Str .= '<template col="'.$col.'">'.$formula.'</template>'."\n"; |
} else { |
} else { |
my ($row,$col) = ($cell =~ /^([A-z])(\d+)/); |
my ($col,$row) = ($cell =~ /^([A-z])(\d+)/); |
next if (! defined($row) || ! defined($col)); |
next if (! defined($row) || ! defined($col)); |
$Str .= '<field row="'.$row.'" col="'.$col.'" >'.$formula.'</cell>' |
next if ($row != 0); |
|
$Str .= |
|
'<field row="'.$row.'" col="'.$col.'" >'.$formula.'</field>' |
."\n"; |
."\n"; |
} |
} |
} |
} |
$Str.="</spreadsheet>"; |
$Str.="</spreadsheet>"; |
|
$r->print("<pre>\n\n\n".$Str."\n\n\n</pre>"); |
return $Str; |
return $Str; |
} |
} |
|
|
Line 1500 sub parse_sheet {
|
Line 1597 sub parse_sheet {
|
$formulas{$cell} = $formula; |
$formulas{$cell} = $formula; |
$sources{$cell} = $source if (defined($source)); |
$sources{$cell} = $source if (defined($source)); |
$parser->get_text('/field'); |
$parser->get_text('/field'); |
} |
} elsif ($token->[1] eq 'template') { |
if ($token->[1] eq 'template') { |
|
$formulas{'template_'.$token->[2]->{'col'}}= |
$formulas{'template_'.$token->[2]->{'col'}}= |
$parser->get_text('/template'); |
$parser->get_text('/template'); |
} |
} |
Line 1555 sub load {
|
Line 1651 sub load {
|
# 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(); |
} elsif($self->filename() =~ /^\/res\/.*\.spreadsheet$/) { |
} elsif($filename =~ /^\/res\/.*\.spreadsheet$/) { |
# Load a spreadsheet definition file |
# Load a spreadsheet definition file |
my $sheetxml=&Apache::lonnet::getfile |
my $sheetxml=&Apache::lonnet::getfile |
(&Apache::lonnet::filelocation('',$filename)); |
(&Apache::lonnet::filelocation('',$filename)); |
Line 1618 sub set_row_numbers {
|
Line 1714 sub set_row_numbers {
|
## |
## |
sub exportrow { |
sub exportrow { |
my $self = shift; |
my $self = shift; |
|
if (exists($self->{'badcalc'}) && $self->{'badcalc'}) { |
|
return (); |
|
} |
my @exportarray; |
my @exportarray; |
foreach my $column (@UC_Columns) { |
foreach my $column (@UC_Columns) { |
push(@exportarray,$self->value($column.'0')); |
push(@exportarray,$self->value($column.'0')); |