version 1.17.2.3, 2003/12/05 22:24:20
|
version 1.19, 2003/09/05 01:57:54
|
Line 44 assesscalc
|
Line 44 assesscalc
|
package Apache::assesscalc; |
package Apache::assesscalc; |
|
|
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 Apache::loncommon; |
use Apache::loncommon; |
use Apache::Spreadsheet; |
use Apache::Spreadsheet; |
use Apache::loncoursedata(); |
|
use HTML::Entities(); |
use HTML::Entities(); |
use Spreadsheet::WriteExcel; |
use Spreadsheet::WriteExcel; |
use GDBM_File; |
use GDBM_File; |
Line 126 sub clear_package {
|
Line 127 sub clear_package {
|
|
|
sub initialize { |
sub initialize { |
&clear_package(); |
&clear_package(); |
&Apache::loncoursedata::clear_internal_caches(); |
|
} |
} |
|
|
######################################################## |
######################################################## |
Line 150 sub initialize_package {
|
Line 150 sub initialize_package {
|
} |
} |
&load_cached_export_rows(); |
&load_cached_export_rows(); |
&load_parameter_caches(); |
&load_parameter_caches(); |
&Apache::loncoursedata::clear_internal_caches(); |
|
} |
} |
|
|
######################################################## |
######################################################## |
Line 170 sub load_parameter_caches {
|
Line 169 sub load_parameter_caches {
|
# |
# |
# Course Parameters Cache |
# Course Parameters Cache |
if (! %courseopt) { |
if (! %courseopt) { |
&Apache::lonnet::logthis("loading course options"); |
|
$current_course = $ENV{'request.course.id'}; |
$current_course = $ENV{'request.course.id'}; |
undef(%courseopt); |
undef(%courseopt); |
if (! defined($current_name) || ! defined($current_domain)) { |
if (! defined($current_name) || ! defined($current_domain)) { |
Line 210 sub load_parameter_caches {
|
Line 208 sub load_parameter_caches {
|
######################################################## |
######################################################## |
sub ensure_current_parameter_caches { |
sub ensure_current_parameter_caches { |
my $self = shift; |
my $self = shift; |
|
## |
|
## Check for a modified parameters |
|
## |
if (! defined($current_course) || |
if (! defined($current_course) || |
$current_course ne $ENV{'request.course.id'} ) { |
$current_course ne $ENV{'request.course.id'} ) { |
$current_course = $ENV{'request.course.id'}; |
$current_course = $ENV{'request.course.id'}; |
undef(%courseopt); |
undef(%courseopt); |
} |
} |
|
## |
|
## Check for new user |
|
## |
if (! defined($current_name) || $current_name ne $self->{'name'} || |
if (! defined($current_name) || $current_name ne $self->{'name'} || |
! defined($current_domain) || $current_domain ne $self->{'domain'}) { |
! defined($current_domain) || $current_domain ne $self->{'domain'}) { |
$current_domain = $self->{'domain'}; |
$current_domain = $self->{'domain'}; |
Line 374 sub parent_link {
|
Line 378 sub parent_link {
|
sub outsheet_html { |
sub outsheet_html { |
my $self = shift; |
my $self = shift; |
my ($r) = @_; |
my ($r) = @_; |
#################################### |
|
# Report any calculation errors # |
|
#################################### |
|
$r->print($self->html_report_error()); |
|
################################### |
################################### |
# Determine table structure |
# Determine table structure |
################################### |
################################### |
Line 524 sub excel_rows {
|
Line 524 sub excel_rows {
|
|
|
sub compute { |
sub compute { |
my $self = shift; |
my $self = shift; |
|
my ($r) = @_; |
|
my $connection = $r->connection(); |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
# $self->logthis('computing'); |
# $self->logthis('computing'); |
$self->initialize_safe_space(); |
$self->initialize_safe_space(); |
######################################### |
######################################### |
Line 562 sub compute {
|
Line 565 sub compute {
|
} |
} |
# |
# |
# Get the values of the metadata fields |
# Get the values of the metadata fields |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
$self->ensure_current_parameter_caches(); |
$self->ensure_current_parameter_caches(); |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
my $filename = $self->{'coursefilename'}.'_parms.db'; |
my $filename = $self->{'coursefilename'}.'_parms.db'; |
if (tie(%parmhash,'GDBM_File', |
if (tie(%parmhash,'GDBM_File', |
$self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) { |
$self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) { |
Line 574 sub compute {
|
Line 579 sub compute {
|
} else { |
} else { |
$self->logthis('unable to tie '.$filename); |
$self->logthis('unable to tie '.$filename); |
} |
} |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
# |
# |
# Clean out unnecessary parameters |
# Clean out unnecessary parameters |
foreach (keys(%parameters)) { |
foreach (keys(%parameters)) { |
Line 601 sub compute {
|
Line 607 sub compute {
|
while (my ($parm,$value) = each(%parameters)) { |
while (my ($parm,$value) = each(%parameters)) { |
last if ($self->blackout()); |
last if ($self->blackout()); |
next if ($parm !~ /^(parameter_.*)_problemstatus$/); |
next if ($parm !~ /^(parameter_.*)_problemstatus$/); |
if ($parameters{$1.'_answerdate'} ne '' && |
next if ($parameters{$1.'_answerdate'}<time); |
$parameters{$1.'_answerdate'} < time) { |
|
next; |
|
} |
|
if (lc($value) eq 'no') { |
if (lc($value) eq 'no') { |
# We must blackout this sheet |
# We must blackout this sheet |
$self->blackout(1); |
$self->blackout(1); |
} |
} |
} |
} |
} |
} |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
# |
# |
# Move the parameters into the spreadsheet |
# Move the parameters into the spreadsheet |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
while (my ($parm,$value) = each(%parameters)) { |
while (my ($parm,$value) = each(%parameters)) { |
my $cell = 'A'.$self->get_row_number_from_key($parm); |
my $cell = 'A'.$self->get_row_number_from_key($parm); |
$f{$cell} = $parm; |
$f{$cell} = $parm; |
Line 621 sub compute {
|
Line 626 sub compute {
|
} |
} |
$self->formulas(\%f); |
$self->formulas(\%f); |
$self->constants(\%c); |
$self->constants(\%c); |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
$self->calcsheet(); |
$self->calcsheet(); |
# |
# |
# Store export row in cache |
# Store export row in cache |
Line 631 sub compute {
|
Line 637 sub compute {
|
# Save the export data |
# Save the export data |
$self->save_export_data(); |
$self->save_export_data(); |
$self->save() if ($self->need_to_save()); |
$self->save() if ($self->need_to_save()); |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
return; |
return; |
} |
} |
|
|
Line 699 These rows are saved in the students dir
|
Line 706 These rows are saved in the students dir
|
######################################################## |
######################################################## |
######################################################## |
######################################################## |
sub load_cached_export_rows { |
sub load_cached_export_rows { |
%Exportrows = undef; |
undef(%Exportrows); |
my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'. |
my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'. |
$ENV{'request.course.id'}, |
$ENV{'request.course.id'}, |
$current_domain,$current_name,undef); |
$current_domain,$current_name,undef); |
Line 740 spreadsheet only if necessary.
|
Line 747 spreadsheet only if necessary.
|
############################################# |
############################################# |
sub export_data { |
sub export_data { |
my $self = shift; |
my $self = shift; |
|
my ($r) = @_; |
|
my $connection = $r->connection(); |
my $symb = $self->{'symb'}; |
my $symb = $self->{'symb'}; |
if (! exists($ENV{'request.role.adv'}) || ! $ENV{'request.role.adv'} || |
if (! exists($ENV{'request.role.adv'}) || ! $ENV{'request.role.adv'} || |
! exists($Exportrows{$symb}) || ! defined($Exportrows{$symb}) || |
! exists($Exportrows{$symb}) || ! defined($Exportrows{$symb}) || |
! $self->check_expiration_time($Exportrows{$symb}->{'time'}) || |
! $self->check_expiration_time($Exportrows{$symb}->{'time'}) || |
! exists($Exportrows{$symb}->{$self->{'filename'}}) || |
! exists($Exportrows{$symb}->{$self->{'filename'}}) || |
! defined($Exportrows{$symb}->{$self->{'filename'}})) { |
! defined($Exportrows{$symb}->{$self->{'filename'}}) || |
$self->compute(); |
! ref($Exportrows{$symb}->{$self->{'filename'}}) |
|
) { |
|
$self->compute($r); |
|
} |
|
if ($connection->aborted()) { $self->cleanup(); return; } |
|
my @Data = @{$Exportrows{$symb}->{$self->{'filename'}}}; |
|
if ($Data[0] =~ /^(.*)___=___/) { |
|
$self->{'sheetname'} = $1; |
|
$Data[0] =~ s/^(.*)___=___//; |
} |
} |
my @Data; |
for (my $i=0;$i<$#Data;$i++) { |
if ($self->badcalc()) { |
$Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i])); |
@Data = (); |
|
} else { |
|
@Data = @{$Exportrows{$symb}->{$self->{'filename'}}}; |
|
if ($Data[0] =~ /^(.*)___=___/) { |
|
$self->{'sheetname'} = $1; |
|
$Data[0] =~ s/^(.*)___=___//; |
|
} |
|
for (my $i=0;$i<$#Data;$i++) { |
|
if ($Data[$i]=~/\D/ && defined($Data[$i])) { |
|
$Data[$i]="'".$Data[$i]."'"; |
|
} |
|
} |
|
} |
} |
return @Data; |
return @Data; |
} |
} |
Line 784 sub save_export_data {
|
Line 789 sub save_export_data {
|
return if ($self->temporary()); |
return if ($self->temporary()); |
my $student = $self->{'name'}.':'.$self->{'domain'}; |
my $student = $self->{'name'}.':'.$self->{'domain'}; |
my $symb = $self->{'symb'}; |
my $symb = $self->{'symb'}; |
if ($self->badcalc()){ |
|
# do not save data away when calculations have not been done properly. |
|
delete($Exportrows{$symb}); |
|
return; |
|
} |
|
if (! exists($Exportrows{$symb}) || |
if (! exists($Exportrows{$symb}) || |
! exists($Exportrows{$symb}->{$self->{'filename'}})) { |
! exists($Exportrows{$symb}->{$self->{'filename'}})) { |
return; |
return; |