version 1.135, 2002/11/07 15:37:02
|
version 1.136, 2002/11/08 15:28:03
|
Line 64 use Apache::lonhtmlcommon;
|
Line 64 use Apache::lonhtmlcommon;
|
use Apache::loncoursedata; |
use Apache::loncoursedata; |
use Apache::File(); |
use Apache::File(); |
use Spreadsheet::WriteExcel; |
use Spreadsheet::WriteExcel; |
|
|
# |
# |
# Caches for coursewide information |
# Caches for coursewide information |
# |
# |
Line 93 my %spreadsheets;
|
Line 94 my %spreadsheets;
|
my %courserdatas; |
my %courserdatas; |
my %userrdatas; |
my %userrdatas; |
my %defaultsheets; |
my %defaultsheets; |
my %updatedata; |
my %rowlabel_cache; |
|
|
# |
# |
# These global hashes are dependent on user, course and resource, |
# These global hashes are dependent on user, course and resource, |
Line 1107 sub exportdata {
|
Line 1108 sub exportdata {
|
return @exportarray; |
return @exportarray; |
} |
} |
|
|
|
|
|
|
|
sub update_student_sheet{ |
|
my $sheet = shift; |
|
# Load in the studentcalc sheet |
|
&readsheet($sheet,'default_studentcalc'); |
|
# Determine the structure (contained assessments, etc) of the sheet |
|
&updatesheet($sheet); |
|
# Load in the cached sheets for this student |
|
&cachedssheets($sheet); |
|
# Load in the (possibly cached) data from the assessment sheets |
|
&loadstudent($sheet); |
|
# Compute the sheet |
|
&calcsheet($sheet); |
|
} |
|
|
# ========================================================== End of Spreadsheet |
# ========================================================== End of Spreadsheet |
# ============================================================================= |
# ============================================================================= |
# |
# |
Line 1275 END
|
Line 1292 END
|
my $rows_output=0; |
my $rows_output=0; |
foreach my $rownum (@Rows) { |
foreach my $rownum (@Rows) { |
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
|
next if ($rowlabel =~ /^\s*$/); |
# |
# |
my $defaultbg='#E0FF'; |
my $defaultbg='#E0FF'; |
# |
# |
Line 1369 sub outsheet_csv {
|
Line 1387 sub outsheet_csv {
|
my $rows_output=0; |
my $rows_output=0; |
foreach my $rownum (@Rows) { |
foreach my $rownum (@Rows) { |
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
|
next if ($rowlabel =~ /^\s*$/); |
push (@Values,&format_csv_rowlabel($rowlabel)); |
push (@Values,&format_csv_rowlabel($rowlabel)); |
foreach my $cell (@rowdata) { |
foreach my $cell (@rowdata) { |
push (@Values,'"'.$cell->{'value'}.'"'); |
push (@Values,'"'.$cell->{'value'}.'"'); |
Line 1404 sub outsheet_csv {
|
Line 1423 sub outsheet_csv {
|
############################################ |
############################################ |
sub outsheet_recursive_excel { |
sub outsheet_recursive_excel { |
my ($sheet,$r) = @_; |
my ($sheet,$r) = @_; |
|
my $c = $r->connection; |
return undef if ($sheet->{'sheettype'} ne 'classcalc'); |
return undef if ($sheet->{'sheettype'} ne 'classcalc'); |
my ($workbook,$filename) = &create_excel_spreadsheet($sheet,$r); |
my ($workbook,$filename) = &create_excel_spreadsheet($sheet,$r); |
return undef if (! defined($workbook)); |
return undef if (! defined($workbook)); |
Line 1414 sub outsheet_recursive_excel {
|
Line 1434 sub outsheet_recursive_excel {
|
# Figure out who the students are |
# Figure out who the students are |
my %f=&getformulas($sheet); |
my %f=&getformulas($sheet); |
my $count = 0; |
my $count = 0; |
$r->print("<br />\n"); |
$r->print(<<END); |
|
<p> |
|
Compiling Excel Workbook with a worksheet for each student. |
|
</p><p> |
|
This operation may take longer than a complete recalculation of the |
|
spreadsheet. |
|
</p><p> |
|
To abort this operation, hit the stop button on your browser. |
|
</p><p> |
|
A link to the spreadsheet will be available at the end of this process. |
|
</p> |
|
<p> |
|
END |
$r->rflush(); |
$r->rflush(); |
|
my $starttime = time; |
foreach (keys(%f)) { |
foreach (keys(%f)) { |
next if ($_!~/^A(\d+)/ || $1 == 0 || ($f{$_}=~/^[!~-]/)); |
next if ($_!~/^A(\d+)/ || $1 == 0 || ($f{$_}=~/^[!~-]/)); |
$count++; |
$count++; |
Line 1424 sub outsheet_recursive_excel {
|
Line 1457 sub outsheet_recursive_excel {
|
# Create a new spreadsheet |
# Create a new spreadsheet |
my $studentsheet = &makenewsheet($sname,$sdom,'studentcalc',undef); |
my $studentsheet = &makenewsheet($sname,$sdom,'studentcalc',undef); |
# Read in the spreadsheet definition |
# Read in the spreadsheet definition |
&readsheet($studentsheet,'default_studentcalc'); |
&update_student_sheet($studentsheet); |
# Determine the structure (contained assessments, etc) of the sheet |
|
&updatesheet($studentsheet); |
|
# Load in the (possibly cached) data from the assessment sheets |
|
&loadrows($studentsheet); |
|
# Compute the sheet |
|
&calcsheet($studentsheet); |
|
&Apache::lonnet::logthis("Sheet value for A0 = ".$sheet->{'values'}->{'A0'}); |
|
# Stuff the sheet into excel |
# Stuff the sheet into excel |
&export_sheet_as_excel($studentsheet,$student_excel_worksheet); |
&export_sheet_as_excel($studentsheet,$student_excel_worksheet); |
|
my $totaltime = int((time - $starttime) / $count * $sheet->{'maxrow'}); |
|
my $timeleft = int((time - $starttime) / $count * ($sheet->{'maxrow'} - $count)); |
if ($count % 5 == 0) { |
if ($count % 5 == 0) { |
$r->print($count.' students completed<br />'); |
$r->print($count.' students completed.'. |
|
' Time remaining: '.$timeleft.' sec. '. |
|
' Estimated total time: '.$totaltime." sec <br />\n"); |
$r->rflush(); |
$r->rflush(); |
} |
} |
|
if(defined($c) && ($c->aborted())) { |
|
last; |
|
} |
} |
} |
# |
# |
$r->print('All students spreadsheets completed<br />'); |
if(! $c->aborted() ) { |
$r->rflush(); |
$r->print('All students spreadsheets completed!<br />'); |
# |
$r->rflush(); |
# &export_sheet_as_excel fills $worksheet with the data from $sheet |
# |
&export_sheet_as_excel($sheet,$main_worksheet); |
# &export_sheet_as_excel fills $worksheet with the data from $sheet |
# |
&export_sheet_as_excel($sheet,$main_worksheet); |
$workbook->close(); |
# |
# Okay, the spreadsheet is taken care of, so give the user a link. |
$workbook->close(); |
$r->print('<br /><br />'. |
# Okay, the spreadsheet is taken care of, so give the user a link. |
'<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n"); |
$r->print('<br /><br />'. |
|
'<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n"); |
|
} else { |
|
$workbook->close(); # Not sure how necessary this is. |
|
#unlink('/home/httpd'.$filename); # No need to keep this around? |
|
} |
return 1; |
return 1; |
} |
} |
|
|
Line 1514 sub export_sheet_as_excel {
|
Line 1552 sub export_sheet_as_excel {
|
my $rows_output=0; |
my $rows_output=0; |
foreach my $rownum (@Rows) { |
foreach my $rownum (@Rows) { |
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
|
next if ($rowlabel =~ /^\s*$/); |
my $cols_output = 0; |
my $cols_output = 0; |
my $label = &format_excel_rowlabel($rowlabel); |
my $label = &format_excel_rowlabel($rowlabel); |
$worksheet->write($rows_output,$cols_output++,$label); |
$worksheet->write($rows_output,$cols_output++,$label); |
Line 1975 sub updateclasssheet {
|
Line 2014 sub updateclasssheet {
|
my $chome =$sheet->{'chome'}; |
my $chome =$sheet->{'chome'}; |
# |
# |
%Section = (); |
%Section = (); |
|
|
# |
# |
# Read class list and row labels |
# Read class list and row labels |
my $classlist = &Apache::loncoursedata::get_classlist(); |
my $classlist = &Apache::loncoursedata::get_classlist(); |
Line 2034 sub updateclasssheet {
|
Line 2072 sub updateclasssheet {
|
} |
} |
|
|
# ----------------------------------- Update rows for student and assess sheets |
# ----------------------------------- Update rows for student and assess sheets |
sub updatestudentassesssheet { |
sub get_student_rowlabels { |
my ($sheet) = @_; |
my ($sheet) = @_; |
# |
# |
my %bighash; |
my %course_db; |
# |
# |
my $stype = $sheet->{'sheettype'}; |
my $stype = $sheet->{'sheettype'}; |
my $uname = $sheet->{'uname'}; |
my $uname = $sheet->{'uname'}; |
my $udom = $sheet->{'udom'}; |
my $udom = $sheet->{'udom'}; |
|
# |
|
$sheet->{'rowlabel'} = {}; |
|
# |
|
my $identifier =$sheet->{'coursefilename'}.'_'.$stype; |
|
if ($rowlabel_cache{$identifier}) { |
|
%{$sheet->{'rowlabel'}}=split(/___;___/,$rowlabel_cache{$identifier}); |
|
} else { |
|
# Get the data and store it in the cache |
|
# Tie hash |
|
tie(%course_db,'GDBM_File',$sheet->{'coursefilename'}.'.db', |
|
&GDBM_READER(),0640); |
|
if (! tied(%course_db)) { |
|
return 'Could not access course data'; |
|
} |
|
# |
|
my %assesslist; |
|
foreach ('Feedback','Evaluation','Tutoring','Discussion') { |
|
my $symb = '_'.lc($_); |
|
$assesslist{$symb} = join(':',('symb',$symb,$uname,$udom,$_)); |
|
} |
|
# |
|
while (my ($key,$srcf) = each(%course_db)) { |
|
next if ($key !~ /^src_(\d+)\.(\d+)$/); |
|
my $mapid = $1; |
|
my $resid = $2; |
|
my $id = $mapid.'.'.$resid; |
|
if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) { |
|
my $symb= |
|
&Apache::lonnet::declutter($course_db{'map_id_'.$mapid}). |
|
'___'.$resid.'___'.&Apache::lonnet::declutter($srcf); |
|
$assesslist{$symb}='symb:'.&Apache::lonnet::escape($symb).':' |
|
.$uname.':'.$udom.':'.$course_db{'title_'.$id}; |
|
} |
|
} |
|
untie(%course_db); |
|
# Store away the data |
|
$sheet->{'rowlabel'} = \%assesslist; |
|
$rowlabel_cache{$identifier}=join('___;___',%{$sheet->{'rowlabel'}}); |
|
} |
|
|
|
} |
|
|
|
sub get_assess_rowlabels { |
|
my ($sheet) = @_; |
|
# |
|
my %course_db; |
|
# |
|
my $stype = $sheet->{'sheettype'}; |
|
my $uname = $sheet->{'uname'}; |
|
my $udom = $sheet->{'udom'}; |
|
my $usymb = $sheet->{'usymb'}; |
|
# |
$sheet->{'rowlabel'} = {}; |
$sheet->{'rowlabel'} = {}; |
my $identifier =$sheet->{'coursefilename'}.'_'.$stype.'_'.$uname.'_'.$udom; |
my $identifier =$sheet->{'coursefilename'}.'_'.$stype.'_'.$usymb; |
if ($updatedata{$identifier}) { |
# |
%{$sheet->{'rowlabel'}}=split(/___;___/,$updatedata{$identifier}); |
if ($rowlabel_cache{$identifier}) { |
|
%{$sheet->{'rowlabel'}}=split(/___;___/,$rowlabel_cache{$identifier}); |
} else { |
} else { |
|
# Get the data and store it in the cache |
# Tie hash |
# Tie hash |
tie(%bighash,'GDBM_File',$sheet->{'coursefilename'}.'.db', |
tie(%course_db,'GDBM_File',$sheet->{'coursefilename'}.'.db', |
&GDBM_READER(),0640); |
&GDBM_READER(),0640); |
if (! tied(%bighash)) { |
if (! tied(%course_db)) { |
return 'Could not access course data'; |
return 'Could not access course data'; |
} |
} |
# Get all assessments |
|
# |
# |
# parameter_labels is used in the assessment sheets to provide labels |
|
# for the parameters. |
|
my %parameter_labels= |
my %parameter_labels= |
('timestamp' => |
('timestamp' => |
'parameter:Timestamp of Last Transaction<br>timestamp', |
'parameter:Timestamp of Last Transaction<br>timestamp', |
Line 2066 sub updatestudentassesssheet {
|
Line 2155 sub updatestudentassesssheet {
|
'parameter:Number of Tutor Responses<br>tutornumber', |
'parameter:Number of Tutor Responses<br>tutornumber', |
'totalpoints' => |
'totalpoints' => |
'parameter:Total Points Granted<br>totalpoints'); |
'parameter:Total Points Granted<br>totalpoints'); |
# |
while (my ($key,$srcf) = each(%course_db)) { |
# assesslist holds the descriptions of all assessments |
next if ($key !~ /^src_(\d+)\.(\d+)$/); |
my %assesslist; |
my $mapid = $1; |
foreach ('Feedback','Evaluation','Tutoring','Discussion') { |
my $resid = $2; |
my $symb = '_'.lc($_); |
my $id = $mapid.'.'.$resid; |
$assesslist{$symb} = join(':',('symb',$symb,$uname,$udom,$_)); |
|
} |
|
while (($_,undef) = each(%bighash)) { |
|
next if ($_!~/^src\_(\d+)\.(\d+)$/); |
|
my $mapid=$1; |
|
my $resid=$2; |
|
my $id=$mapid.'.'.$resid; |
|
my $srcf=$bighash{$_}; |
|
if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) { |
if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) { |
my $symb= |
# Loop through the metadata for this key |
&Apache::lonnet::declutter($bighash{'map_id_'.$mapid}). |
my @Metadata = split(/,/, |
'___'.$resid.'___'.&Apache::lonnet::declutter($srcf); |
&Apache::lonnet::metadata($srcf,'keys')); |
$assesslist{$symb}='symb:'.&Apache::lonnet::escape($symb).':' |
foreach my $key (@Metadata) { |
.$uname.':'.$udom.':'.$bighash{'title_'.$id}; |
|
next if ($stype ne 'assesscalc'); |
|
foreach my $key (split(/\,/, |
|
&Apache::lonnet::metadata($srcf,'keys') |
|
)) { |
|
next if ($key !~ /^(stores|parameter)_/); |
next if ($key !~ /^(stores|parameter)_/); |
my $display= |
my $display= |
&Apache::lonnet::metadata($srcf,$key.'.display'); |
&Apache::lonnet::metadata($srcf,$key.'.display'); |
Line 2100 sub updatestudentassesssheet {
|
Line 2176 sub updatestudentassesssheet {
|
$parameter_labels{$key}='parameter:'.$display; |
$parameter_labels{$key}='parameter:'.$display; |
} # end of foreach |
} # end of foreach |
} |
} |
} # end of foreach (keys(%bighash)) |
} |
untie(%bighash); |
untie(%course_db); |
# |
# Store away the results |
# %parameter_labels has a list of storage and parameter displays by |
$sheet->{'rowlabel'} = \%parameter_labels; |
# unikey |
$rowlabel_cache{$identifier}=join('___;___',%{$sheet->{'rowlabel'}}); |
# %assesslist has a list of all resource, by symb |
|
# |
|
if ($stype eq 'assesscalc') { |
|
$sheet->{'rowlabel'} = \%parameter_labels; |
|
} elsif ($stype eq 'studentcalc') { |
|
$sheet->{'rowlabel'} = \%assesslist; |
|
} |
|
$updatedata{$sheet->{'coursefilename'}.'_'.$stype.'_' |
|
.$uname.'_'.$udom}= |
|
join('___;___',%{$sheet->{'rowlabel'}}); |
|
# Get current from cache |
|
} |
} |
# Find discrepancies between the course row table and this |
|
# |
} |
|
|
|
sub updatestudentassesssheet { |
|
my $sheet = shift; |
|
if ($sheet->{'sheettype'} eq 'studentcalc') { |
|
&get_student_rowlabels($sheet); |
|
} else { |
|
&get_assess_rowlabels($sheet); |
|
} |
|
# Determine if any of the information has changed |
my %f=&getformulas($sheet); |
my %f=&getformulas($sheet); |
my $changed=0; |
my $changed=0; |
|
|
$sheet->{'maxrow'} = 0; |
$sheet->{'maxrow'} = 0; |
my %existing=(); |
my %existing=(); |
# Now obsolete rows |
# Now obsolete rows |
foreach (keys(%f)) { |
while (my ($cell, $formula) = each (%f)) { |
next if ($_!~/^A(\d+)/); |
next if ($cell !~ /^A(\d+)/); |
if ($1 > $sheet->{'maxrow'}) { |
$sheet->{'maxrow'} = $1 if ($1 > $sheet->{'maxrow'}); |
$sheet->{'maxrow'} = $1; |
my ($usy,$ufn)=split(/__&&&\__/,$formula); |
} |
|
my ($usy,$ufn)=split(/__&&&\__/,$f{$_}); |
|
$existing{$usy}=1; |
$existing{$usy}=1; |
unless ((exists($sheet->{'rowlabel'}->{$usy}) && |
unless ((exists($sheet->{'rowlabel'}->{$usy}) && |
(defined($sheet->{'rowlabel'}->{$usy})) || (!$1) || |
(defined($sheet->{'rowlabel'}->{$usy})) || (!$1) || |
($f{$_}=~/^(~~~|---)/))){ |
($formula =~ /^(~~~|---)/) )) { |
$f{$_}='!!! Obsolete'; |
$f{$_}='!!! Obsolete'; |
$changed=1; |
$changed=1; |
} elsif ($ufn) { |
} elsif ($ufn) { |
|
# I do not think this works any more |
$sheet->{'rowlabel'}->{$usy} |
$sheet->{'rowlabel'}->{$usy} |
=~s/assesscalc\?usymb\=/assesscalc\?ufn\=$ufn\&usymb\=/; |
=~s/assesscalc\?usymb\=/assesscalc\?ufn\=$ufn&\usymb\=/; |
} |
} |
} |
} |
# New and unknown keys |
# New and unknown keys |
Line 2154 sub updatestudentassesssheet {
|
Line 2227 sub updatestudentassesssheet {
|
$sheet->{'f'} = \%f; |
$sheet->{'f'} = \%f; |
&setformulas($sheet); |
&setformulas($sheet); |
} |
} |
# |
|
undef %existing; |
|
} |
} |
|
|
# ------------------------------------------------ Load data for one assessment |
# ------------------------------------------------ Load data for one assessment |
Line 2176 sub loadstudent{
|
Line 2247 sub loadstudent{
|
undef @tmp; |
undef @tmp; |
# |
# |
my @assessdata=(); |
my @assessdata=(); |
foreach (keys(%f)) { |
while (my ($cell,$value) = each (%f)) { |
next if ($_!~/^A(\d+)/); |
next if ($cell !~ /^A(\d+)/); |
my $row=$1; |
my $row=$1; |
next if (($f{$_}=~/^[\!\~\-]/) || ($row==0)); |
next if (($value =~ /^[!~-]/) || ($row==0)); |
my ($usy,$ufn)=split(/__&&&\__/,$f{$_}); |
my ($usy,$ufn)=split(/__&&&\__/,$value); |
@assessdata=&exportsheet($sheet,$sheet->{'uname'}, |
@assessdata=&exportsheet($sheet,$sheet->{'uname'}, |
$sheet->{'udom'}, |
$sheet->{'udom'}, |
'assesscalc',$usy,$ufn); |
'assesscalc',$usy,$ufn); |
my $index=0; |
my $index=0; |
foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M', |
foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M', |
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') { |
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') { |
if ($assessdata[$index]) { |
if (defined($assessdata[$index])) { |
my $col=$_; |
my $col=$_; |
if ($assessdata[$index]=~/\D/) { |
if ($assessdata[$index]=~/\D/) { |
$c{$col.$row}="'".$assessdata[$index]."'"; |
$c{$col.$row}="'".$assessdata[$index]."'"; |
Line 2426 sub selectbox {
|
Line 2497 sub selectbox {
|
|
|
sub updatesheet { |
sub updatesheet { |
my ($sheet)=@_; |
my ($sheet)=@_; |
my $stype=$sheet->{'sheettype'}; |
if ($sheet->{'sheettype'} eq 'classcalc') { |
if ($stype eq 'classcalc') { |
|
return &updateclasssheet($sheet); |
return &updateclasssheet($sheet); |
} else { |
} else { |
return &updatestudentassesssheet($sheet); |
return &updatestudentassesssheet($sheet); |
Line 2503 sub exportsheet {
|
Line 2573 sub exportsheet {
|
my $key=$uname.':'.$udom.':'.$stype.':'.$usymb; |
my $key=$uname.':'.$udom.':'.$stype.':'.$usymb; |
my $found=''; |
my $found=''; |
if ($oldsheets{$key}) { |
if ($oldsheets{$key}) { |
|
&Apache::lonnet::logthis("got cached $stype for $uname"); |
foreach (split(/___&\___/,$oldsheets{$key})) { |
foreach (split(/___&\___/,$oldsheets{$key})) { |
my ($name,$value)=split(/___=___/,$_); |
my ($name,$value)=split(/___=___/,$_); |
if ($name eq $fn) { |
if ($name eq $fn) { |
Line 2513 sub exportsheet {
|
Line 2584 sub exportsheet {
|
unless ($found) { |
unless ($found) { |
&cachedssheets($sheet,$uname,$udom); |
&cachedssheets($sheet,$uname,$udom); |
if ($oldsheets{$key}) { |
if ($oldsheets{$key}) { |
|
&Apache::lonnet::logthis("got cached $stype for $uname"); |
foreach (split(/___&\___/,$oldsheets{$key})) { |
foreach (split(/___&\___/,$oldsheets{$key})) { |
my ($name,$value)=split(/___=___/,$_); |
my ($name,$value)=split(/___=___/,$_); |
if ($name eq $fn) { |
if ($name eq $fn) { |
Line 2602 sub exportsheet {
|
Line 2674 sub exportsheet {
|
# |
# |
# Load previously cached student spreadsheets for this course |
# Load previously cached student spreadsheets for this course |
# |
# |
sub expirationdates { |
sub load_spreadsheet_expirationdates { |
undef %expiredates; |
undef %expiredates; |
my $cid=$ENV{'request.course.id'}; |
my $cid=$ENV{'request.course.id'}; |
my @tmp = &Apache::lonnet::dump('nohist_expirationdates', |
my @tmp = &Apache::lonnet::dump('nohist_expirationdates', |
Line 2640 sub cachedssheets {
|
Line 2712 sub cachedssheets {
|
my ($sheet,$uname,$udom) = @_; |
my ($sheet,$uname,$udom) = @_; |
$uname = $uname || $sheet->{'uname'}; |
$uname = $uname || $sheet->{'uname'}; |
$udom = $udom || $sheet->{'udom'}; |
$udom = $udom || $sheet->{'udom'}; |
if (! $loadedcaches{$sheet->{'uname'}.'_'.$sheet->{'udom'}}) { |
if (! $loadedcaches{$uname.'_'.$udom}) { |
my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets', |
my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets', |
$sheet->{'udom'}, |
$sheet->{'udom'}, |
$sheet->{'uname'}); |
$sheet->{'uname'}); |
if ($tmp[0] !~ /^error/) { |
if ($tmp[0] !~ /^error/) { |
my %StupidTempHash = @tmp; |
my %TempHash = @tmp; |
while (my ($key,$value) = each %StupidTempHash) { |
my $count = 0; |
|
while (my ($key,$value) = each %TempHash) { |
$oldsheets{$key} = $value; |
$oldsheets{$key} = $value; |
|
$count++; |
} |
} |
|
&Apache::lonnet::logthis('saved '.$count.' cached sheets for '.$uname); |
$loadedcaches{$sheet->{'uname'}.'_'.$sheet->{'udom'}}=1; |
$loadedcaches{$sheet->{'uname'}.'_'.$sheet->{'udom'}}=1; |
} |
} |
} |
} |
|
|
} |
} |
|
|
# ===================================================== Calculated sheets cache |
# ===================================================== Calculated sheets cache |
Line 2677 sub handler {
|
Line 2753 sub handler {
|
lc($ENV{'form.output'}) eq 'recursive excel')) { |
lc($ENV{'form.output'}) eq 'recursive excel')) { |
$ENV{'form.output'} = 'HTML'; |
$ENV{'form.output'} = 'HTML'; |
} |
} |
|
# |
|
# Overload checking |
|
# |
# Check this server |
# Check this server |
my $loaderror=&Apache::lonnet::overloaderror($r); |
my $loaderror=&Apache::lonnet::overloaderror($r); |
if ($loaderror) { return $loaderror; } |
if ($loaderror) { return $loaderror; } |
Line 2684 sub handler {
|
Line 2763 sub handler {
|
$loaderror= &Apache::lonnet::overloaderror($r, |
$loaderror= &Apache::lonnet::overloaderror($r, |
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
if ($loaderror) { return $loaderror; } |
if ($loaderror) { return $loaderror; } |
|
# |
|
# HTML Header |
|
# |
if ($r->header_only) { |
if ($r->header_only) { |
$r->content_type('text/html'); |
$r->content_type('text/html'); |
$r->send_http_header; |
$r->send_http_header; |
return OK; |
return OK; |
} |
} |
|
# |
# Global directory configs |
# Global directory configs |
|
# |
$includedir = $r->dir_config('lonIncludes'); |
$includedir = $r->dir_config('lonIncludes'); |
$tmpdir = $r->dir_config('lonDaemons').'/tmp/'; |
$tmpdir = $r->dir_config('lonDaemons').'/tmp/'; |
|
# |
|
# Roles Checking |
|
# |
# Needs to be in a course |
# Needs to be in a course |
if (! $ENV{'request.course.fn'}) { |
if (! $ENV{'request.course.fn'}) { |
# Not in a course, or not allowed to modify parms |
# Not in a course, or not allowed to modify parms |
Line 2700 sub handler {
|
Line 2786 sub handler {
|
$r->uri.":opa:0:0:Cannot modify spreadsheet"; |
$r->uri.":opa:0:0:Cannot modify spreadsheet"; |
return HTTP_NOT_ACCEPTABLE; |
return HTTP_NOT_ACCEPTABLE; |
} |
} |
|
# |
# Get query string for limited number of parameters |
# Get query string for limited number of parameters |
|
# |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['uname','udom','usymb','ufn']); |
['uname','udom','usymb','ufn']); |
|
# |
|
# Deal with restricted student permissions |
|
# |
if ($ENV{'request.role'} =~ /^st\./) { |
if ($ENV{'request.role'} =~ /^st\./) { |
delete $ENV{'form.unewfield'} if (exists($ENV{'form.unewfield'})); |
delete $ENV{'form.unewfield'} if (exists($ENV{'form.unewfield'})); |
delete $ENV{'form.unewformula'} if (exists($ENV{'form.unewformula'})); |
delete $ENV{'form.unewformula'} if (exists($ENV{'form.unewformula'})); |
} |
} |
|
# |
|
# Clean up symb and spreadsheet filename |
|
# |
if (($ENV{'form.usymb'}=~/^\_(\w+)/) && (!$ENV{'form.ufn'})) { |
if (($ENV{'form.usymb'}=~/^\_(\w+)/) && (!$ENV{'form.ufn'})) { |
$ENV{'form.ufn'}='default_'.$1; |
$ENV{'form.ufn'}='default_'.$1; |
} |
} |
|
# |
# Interactive loading of specific sheet? |
# Interactive loading of specific sheet? |
|
# |
if (($ENV{'form.load'}) && ($ENV{'form.loadthissheet'} ne 'Default')) { |
if (($ENV{'form.load'}) && ($ENV{'form.loadthissheet'} ne 'Default')) { |
$ENV{'form.ufn'}=$ENV{'form.loadthissheet'}; |
$ENV{'form.ufn'}=$ENV{'form.loadthissheet'}; |
} |
} |
Line 2726 sub handler {
|
Line 2822 sub handler {
|
$adom=$ENV{'form.udom'}; |
$adom=$ENV{'form.udom'}; |
} |
} |
# |
# |
# Open page |
# Open page, try to prevent browser cache. |
|
# |
$r->content_type('text/html'); |
$r->content_type('text/html'); |
$r->header_out('Cache-control','no-cache'); |
$r->header_out('Cache-control','no-cache'); |
$r->header_out('Pragma','no-cache'); |
$r->header_out('Pragma','no-cache'); |
$r->send_http_header; |
$r->send_http_header; |
# Screen output |
# |
|
# Header.... |
|
# |
$r->print('<html><head><title>LON-CAPA Spreadsheet</title>'); |
$r->print('<html><head><title>LON-CAPA Spreadsheet</title>'); |
if ($ENV{'request.role'} !~ /^st\./) { |
if ($ENV{'request.role'} !~ /^st\./) { |
$r->print(<<ENDSCRIPT); |
$r->print(<<ENDSCRIPT); |
Line 2771 ENDSCRIPT
|
Line 2870 ENDSCRIPT
|
$r->rflush(); |
$r->rflush(); |
# |
# |
# Full recalc? |
# Full recalc? |
|
# |
if ($ENV{'form.forcerecalc'}) { |
if ($ENV{'form.forcerecalc'}) { |
$r->print('<h4>Completely Recalculating Sheet ...</h4>'); |
$r->print('<h4>Completely Recalculating Sheet ...</h4>'); |
undef %spreadsheets; |
undef %spreadsheets; |
undef %courserdatas; |
undef %courserdatas; |
undef %userrdatas; |
undef %userrdatas; |
undef %defaultsheets; |
undef %defaultsheets; |
undef %updatedata; |
undef %rowlabel_cache; |
} |
} |
# Read new sheet or modified worksheet |
# Read new sheet or modified worksheet |
my ($sheet)=&makenewsheet($aname,$adom,$sheettype,$ENV{'form.usymb'}); |
my ($sheet)=&makenewsheet($aname,$adom,$sheettype,$ENV{'form.usymb'}); |
Line 2861 ENDSCRIPT
|
Line 2961 ENDSCRIPT
|
&othersheets($sheet,'assesscalc')); |
&othersheets($sheet,'assesscalc')); |
} |
} |
} |
} |
# Cached sheets |
# |
&expirationdates(); |
# Set up caching mechanisms |
undef %oldsheets; |
# |
undef %loadedcaches; |
&load_spreadsheet_expirationdates(); |
|
# Clear out old caches if we have not seen this class before. |
|
if (exists($oldsheets{'course'}) && |
|
$oldsheets{'course'} ne $sheet->{'cid'}) { |
|
undef %oldsheets; |
|
undef %loadedcaches; |
|
} |
|
$oldsheets{'course'} = $sheet->{'cid'}; |
|
# |
if ($sheet->{'sheettype'} eq 'classcalc') { |
if ($sheet->{'sheettype'} eq 'classcalc') { |
$r->print("Loading previously calculated student sheets ...\n"); |
$r->print("Loading previously calculated student sheets ...\n"); |
$r->rflush(); |
$r->rflush(); |