version 1.27, 2003/09/16 15:36:32
|
version 1.30, 2003/11/17 19:55:41
|
Line 59 use HTML::Entities();
|
Line 59 use HTML::Entities();
|
use HTML::TokeParser; |
use HTML::TokeParser; |
use Spreadsheet::WriteExcel; |
use Spreadsheet::WriteExcel; |
use Time::HiRes; |
use Time::HiRes; |
|
use Apache::lonlocal; |
|
|
## |
## |
## Package Variables |
## Package Variables |
Line 677 sub calc {
|
Line 678 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 1138 sub calcsheet {
|
Line 1139 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 1168 sub display {
|
Line 1209 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 1282 sub html_header {
|
Line 1335 sub html_header {
|
my $self = shift; |
my $self = shift; |
return '' if (! $ENV{'request.role.adv'}); |
return '' if (! $ENV{'request.role.adv'}); |
return "<table>\n". |
return "<table>\n". |
'<tr><th align="center">Output Format</th><tr>'."\n". |
'<tr><th align="center">'.&mt('Output Format').'</th></tr>'."\n". |
'<tr><td>'.&output_selector()."</td></tr>\n". |
'<tr><td>'.&output_selector()."</td></tr>\n". |
"</table>\n"; |
"</table>\n"; |
} |
} |
Line 1297 sub output_selector {
|
Line 1350 sub output_selector {
|
} |
} |
foreach (['html','HTML'], |
foreach (['html','HTML'], |
['excel','Excel'], |
['excel','Excel'], |
['csv','Comma Seperated Values']) { |
['csv','Comma Separated Values']) { |
my ($name,$description) = @{$_}; |
my ($name,$description) = @{$_}; |
$output_selector.=qq{<option value="$name"}; |
$output_selector.=qq{<option value="$name"}; |
if ($name eq $default) { |
if ($name eq $default) { |
$output_selector .= ' selected'; |
$output_selector .= ' selected'; |
} |
} |
$output_selector .= ">$description</option>\n"; |
$output_selector .= ">".&mt($description)."</option>\n"; |
} |
} |
$output_selector .= "</select>\n"; |
$output_selector .= "</select>\n"; |
return $output_selector; |
return $output_selector; |
Line 1336 sub create_excel_spreadsheet {
|
Line 1389 sub create_excel_spreadsheet {
|
my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); |
my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); |
if (! defined($workbook)) { |
if (! defined($workbook)) { |
$r->log_error("Error creating excel spreadsheet $filename: $!"); |
$r->log_error("Error creating excel spreadsheet $filename: $!"); |
$r->print("Problems creating new Excel file. ". |
$r->print(&mt("Problems creating new Excel file. ". |
"This error has been logged. ". |
"This error has been logged. ". |
"Please alert your LON-CAPA administrator"); |
"Please alert your LON-CAPA administrator")); |
return undef; |
return undef; |
} |
} |
# |
# |
Line 1356 sub outsheet_excel {
|
Line 1409 sub outsheet_excel {
|
my $self = shift; |
my $self = shift; |
my ($r) = @_; |
my ($r) = @_; |
my $connection = $r->connection(); |
my $connection = $r->connection(); |
$r->print("<h2>Preparing Excel Spreadsheet</h2>"); |
$r->print("<h2>".&mt('Preparing Excel Spreadsheet')."</h2>"); |
# |
# |
# Create excel worksheet |
# Create excel worksheet |
my ($workbook,$filename) = $self->create_excel_spreadsheet($r); |
my ($workbook,$filename) = $self->create_excel_spreadsheet($r); |
Line 1408 sub outsheet_csv {
|
Line 1461 sub outsheet_csv {
|
my $file; |
my $file; |
unless ($file = Apache::File->new('>'.'/home/httpd'.$filename)) { |
unless ($file = Apache::File->new('>'.'/home/httpd'.$filename)) { |
$r->log_error("Couldn't open $filename for output $!"); |
$r->log_error("Couldn't open $filename for output $!"); |
$r->print("Problems occured in writing the csv file. ". |
$r->print(&mt("Problems occured in writing the csv file. ". |
"This error has been logged. ". |
"This error has been logged. ". |
"Please alert your LON-CAPA administrator."); |
"Please alert your LON-CAPA administrator.")); |
$r->print("<pre>\n".$csvdata."</pre>\n"); |
$r->print("<pre>\n".$csvdata."</pre>\n"); |
return 0; |
return 0; |
} |
} |
Line 1426 sub outsheet_csv {
|
Line 1479 sub outsheet_csv {
|
# Close the csv file |
# Close the csv file |
close($file); |
close($file); |
$r->print('<br /><br />'. |
$r->print('<br /><br />'. |
'<a href="'.$filename.'">Your CSV spreadsheet.</a>'."\n"); |
'<a href="'.$filename.'">'.&mt('Your CSV spreadsheet.').'</a>'."\n"); |
# |
# |
return 1; |
return 1; |
} |
} |
Line 1617 sub set_row_numbers {
|
Line 1670 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')); |
Line 1752 sub othersheets {
|
Line 1808 sub othersheets {
|
$self->{'cdom'}, $self->{'cnum'}); |
$self->{'cdom'}, $self->{'cnum'}); |
my ($tmp) = keys(%results); |
my ($tmp) = keys(%results); |
if ($tmp =~ /^(con_lost|error|no_such_host)/i ) { |
if ($tmp =~ /^(con_lost|error|no_such_host)/i ) { |
@alternatives = ('Default'); |
@alternatives = (&mt('Default')); |
} else { |
} else { |
@alternatives = ('Default', sort (keys(%results))); |
@alternatives = (&mt('Default'), sort (keys(%results))); |
} |
} |
return @alternatives; |
return @alternatives; |
} |
} |