--- loncom/interface/Attic/lonspreadsheet.pm 2003/01/30 16:20:08 1.165
+++ loncom/interface/Attic/lonspreadsheet.pm 2003/05/27 15:50:30 1.179
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.165 2003/01/30 16:20:08 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.179 2003/05/27 15:50:30 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -57,6 +57,7 @@ use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
use Apache::lonhtmlcommon;
+use Apache::lonmenu;
use HTML::Entities();
# --------------------------------------------------------- Various form fields
@@ -152,9 +153,9 @@ sub handler {
$ENV{'form.ufn'} eq 'default')) {
$ENV{'form.ufn'}='default_'.$1;
}
- if (!$ENV{'form.ufn'} || $ENV{'form.ufn'} eq 'default') {
- $ENV{'form.ufn'}='course_default_'.$sheettype;
- }
+# if (!$ENV{'form.ufn'} || $ENV{'form.ufn'} eq 'default') {
+# $ENV{'form.ufn'}='course_default_'.$sheettype;
+# }
#
# Interactive loading of specific sheet?
#
@@ -183,10 +184,7 @@ sub handler {
# Header....
#
$r->print('
LON-CAPA Spreadsheet');
- my $nothing = "''";
- if ($ENV{'browser.type'} eq 'explorer') {
- $nothing = "'javascript:void(0);'";
- }
+ my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
if ($ENV{'request.role'} !~ /^st\./) {
$r->print(<rflush();
#
# Full recalc?
@@ -262,7 +261,6 @@ ENDSCRIPT
# Global directory configs
#
$sheet->includedir($r->dir_config('lonIncludes'));
- $sheet->tmpdir($r->dir_config('lonDaemons').'/tmp/');
#
# Check user permissions
if (($sheet->{'type'} eq 'classcalc' ) ||
@@ -356,6 +354,7 @@ ENDSCRIPT
$oldsheets{'course'} ne $sheet->{'cid'}) {
undef %oldsheets;
undef %loadedcaches;
+ &Apache::lonspreadsheet::Spreadsheet::clear_package_variables();
}
$oldsheets{'course'} = $sheet->{'cid'};
#
@@ -524,25 +523,38 @@ my %numbertimes;
# Directories
#
my $includedir;
-my $tmpdir;
sub includedir {
my $self = shift;
$includedir = shift;
}
-sub tmpdir {
- my $self = shift;
- $tmpdir = shift;
-}
-
my %spreadsheets;
-my %loadedcaches;
+#my %loadedcaches;
my %courserdatas;
my %userrdatas;
my %defaultsheets;
my %rowlabel_cache;
-my %oldsheets;
+#my %oldsheets;
+
+sub clear_package_variables {
+ undef %courseopt;
+ undef %useropt;
+ undef %parmhash;
+ undef %Section;
+ undef %expiredates;
+ undef $cachedassess;
+ undef %cachedstores;
+ undef %starttimes;
+ undef %usedtimes;
+ undef %numbertimes;
+ undef $includedir;
+ undef %spreadsheets;
+ undef %courserdatas;
+ undef %userrdatas;
+ undef %defaultsheets;
+ undef %rowlabel_cache;
+}
sub complete_recalc {
my $self = shift;
@@ -609,7 +621,7 @@ sub cachedssheets {
my ($uname,$udom) = @_;
$uname = $uname || $self->{'uname'};
$udom = $udom || $self->{'udom'};
- if (! $Apache::lonspreadsheet::loadedcaches{$uname.'_'.$udom}) {
+ if (! exists($Apache::lonspreadsheet::loadedcaches{$uname.'_'.$udom})) {
my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'.
$ENV{'request.course.id'},
$self->{'udom'},
@@ -729,8 +741,27 @@ sub parmval {
# second, check map parms
my $thisparm = $parmhash{$symbparm};
return $thisparm if (defined($thisparm));
+
# first, check default
- return &Apache::lonnet::metadata($fn,$rwhat.'.default');
+ $thisparm = &Apache::lonnet::metadata($fn,$rwhat.'.default');
+ return $thisparm if (defined($thisparm));
+
+ #Cascade Up
+ my $space=$what;
+ $space=~s/\.\w+$//;
+ if ($space ne '0') {
+ my @parts=split(/_/,$space);
+ my $id=pop(@parts);
+ my $part=join('_',@parts);
+ if ($part eq '') { $part='0'; }
+ my $newwhat=$rwhat;
+ $newwhat=~s/\Q$space\E/$part/;
+ my $partgeneral=&parmval($newwhat,$symb,$uname,$udom,$csec);
+ if (defined($partgeneral)) { return $partgeneral; }
+ }
+
+ #nothing defined
+ return '';
}
#
@@ -742,6 +773,15 @@ sub new {
#
my ($uname,$udom,$stype,$usymb)=@_;
#
+ if (! exists($Section{$uname.':'.$udom})) {
+ my $classlist = &Apache::loncoursedata::get_classlist();
+ #
+ foreach my $student (keys(%$classlist)) {
+ my ($studentDomain,$studentName,undef,undef,undef,$studentSection,
+ undef,undef) = @{$classlist->{$student}};
+ $Section{$studentName.':'.$studentDomain} = $studentSection;
+ }
+ }
my $self = {
uname => $uname,
udom => $udom,
@@ -1514,7 +1554,7 @@ sub expandnamed {
foreach my $varname ( @vars ) {
if ($varname=~/\D/) {
$formula=~s/$varname/'$c{\''.$varname.'\'}'/ge;
- $varname=~s/$var/\(\\w\+\)/g;
+ $varname=~s/$var/\([\\w:\\- ]\+\)/g;
foreach (keys(%{$self->{'constants'}})) {
if ($_=~/$varname/) {
$values{$1}=1;
@@ -1588,7 +1628,6 @@ sub sett {
foreach my $col ($self->template_cells()) {
next if ($col=~/^$pattern/);
foreach my $trow ($self->rows()) {
- next if ($trow eq '0');
# Get the name of this cell
my $lb=$col.$trow;
# Grab the template declaration
@@ -1745,6 +1784,7 @@ sub calcsheet {
$self->sett();
my $result = $self->{'safe'}->reval('&calc();');
%{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')};
+# $self->logthis($self->get_errorlog());
return $result;
}
@@ -1893,6 +1933,22 @@ sub dump_values_to_log {
}
$self->logthis("--------------------------------------------------------");}
+##
+## Yet another debugging function
+##
+sub dump_hash_to_log {
+ my $self= shift();
+ my %tmp = @_;
+ if (@_<2) {
+ %tmp = %{$_[0]};
+ }
+ $self->logthis('---------------------------- (entries end with ":"');
+ while (my ($key,$val) = each (%tmp)) {
+ $self->logthis($key.' = '.$val.':');
+ }
+ $self->logthis('---------------------------- (entries end with ":"');
+}
+
################################
## Helper functions ##
################################
@@ -1904,7 +1960,7 @@ sub rebuild_stats {
$self->{'rows'}=[];
$self->{'template_cells'}=[];
foreach my $cell($self->formulas_keys()) {
- push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/);
+ push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0);
push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/);
}
return;
@@ -1951,7 +2007,7 @@ sub rowlabels {
$self->{'rowlabel'}=$rowlabel;
return;
} else {
- return %{$self->{'rowlabel'}} if (defined($self->{'rowlabels'}));
+ return %{$self->{'rowlabel'}} if (defined($self->{'rowlabel'}));
}
}
@@ -2541,6 +2597,7 @@ sub export_sheet_as_excel {
}
next if ($row_is_empty);
}
+ $worksheet->write($rows_output,$cols_output++,$rownum);
$worksheet->write($rows_output,$cols_output++,$label);
if (ref($label)) {
$cols_output = (scalar(@$label));
@@ -2665,9 +2722,10 @@ sub readsheet {
# $fn now has a value
$self->{'filename'} = $fn;
# see if sheet is cached
- my $fstring='';
- if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) {
- my %tmp = split(/___;___/,$fstring);
+ if (exists($spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn})) {
+
+ my %tmp = split(/___;___/,
+ $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn});
$self->formulas(\%tmp);
} else {
# Not cached, need to read
@@ -2776,7 +2834,7 @@ sub tmpwrite {
$ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.
$self->{'filename'};
$fn=~s/\W/\_/g;
- $fn=$tmpdir.$fn.'.tmp';
+ $fn=$Apache::lonnet::tmpdir.$fn.'.tmp';
my $fh;
if ($fh=Apache::File->new('>'.$fn)) {
my %f = $self->formulas();
@@ -2795,7 +2853,7 @@ sub tmpread {
$ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.
$self->{'filename'};
$fn=~s/\W/\_/g;
- $fn=$tmpdir.$fn.'.tmp';
+ $fn=$Apache::lonnet::tmpdir.$fn.'.tmp';
my $fh;
my %fo=();
my $countrows=0;
@@ -2948,8 +3006,7 @@ sub updateclasssheet {
$self->{'maxrow'}= $rownum;
}
$existing{$f{$cell}}=1;
- unless ((defined($currentlist{$f{$cell}})) || ($rownum ne '0') ||
- ($f{$cell}=~/^(~~~|---)/)) {
+ if (! defined($currentlist{$f{$cell}}) && ($f{$cell}=~/^(~~~|---)/)) {
$f{$cell}='!!! Obsolete';
$changed=1;
}
@@ -2980,8 +3037,9 @@ sub get_student_rowlabels {
$self->{'rowlabel'} = {};
#
my $identifier =$self->{'coursefilename'}.'_'.$stype;
- if ($rowlabel_cache{$identifier}) {
- %{$self->{'rowlabel'}}=split(/___;___/,$rowlabel_cache{$identifier});
+ if (exists($rowlabel_cache{$identifier})) {
+ my %tmp = split(/___;___/,$rowlabel_cache{$identifier});
+ $self->rowlabels(\%tmp);
} else {
# Get the data and store it in the cache
# Tie hash
@@ -3033,8 +3091,9 @@ sub get_assess_rowlabels {
$self->rowlabels({});
my $identifier =$self->{'coursefilename'}.'_'.$stype.'_'.$usymb;
#
- if ($rowlabel_cache{$identifier}) {
- $self->rowlabels(split(/___;___/,$rowlabel_cache{$identifier}));
+ if (exists($rowlabel_cache{$identifier})) {
+ my %tmp = split('___;___',$rowlabel_cache{$identifier});
+ $self->rowlabels(\%tmp);
} else {
# Get the data and store it in the cache
# Tie hash
@@ -3078,9 +3137,8 @@ sub get_assess_rowlabels {
untie(%course_db);
# Store away the results
$self->rowlabels(\%parameter_labels);
- $rowlabel_cache{$identifier}=join('___;___',$self->rowlabels());
+ $rowlabel_cache{$identifier}=join('___;___',%parameter_labels);
}
-
}
sub updatestudentassesssheet {
@@ -3099,7 +3157,6 @@ sub updatestudentassesssheet {
foreach my $rownum ($self->rows()) {
my $cell = 'A'.$rownum;
my $formula = $f{$cell};
- next if ($rownum eq '0');
$self->{'maxrow'} = $rownum if ($rownum > $self->{'maxrow'});
my ($usy,$ufn)=split(/__&&&\__/,$formula);
$existing{$usy}=1;
@@ -3132,14 +3189,17 @@ sub loadstudent{
my %formulas = $self->formulas();
$cachedassess = $self->{'uname'}.':'.$self->{'udom'};
# Get ALL the student preformance data
- my @tmp = &Apache::lonnet::currentdump($self->{'cid'},
- $self->{'udom'},
- $self->{'uname'});
+ my @tmp = &Apache::loncoursedata::get_current_state($self->{'uname'},
+ $self->{'udom'},
+ undef,
+ $self->{'cid'});
if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
%cachedstores = @tmp;
}
undef @tmp;
- #
+ # debugging code
+ # $self->dump_hash_to_log(\%cachedstores);
+ #
my @assessdata=();
foreach my $row ($self->rows()) {
my $cell = 'A'.$row;
@@ -3147,7 +3207,7 @@ sub loadstudent{
if(defined($c) && ($c->aborted())) {
last;
}
- next if (($value =~ /^[!~-]/) || ($row==0));
+ next if ($value =~ /^[!~-]/);
my ($usy,$ufn)=split(/__&&&\__/,$value);
@assessdata=$self->exportsheet($self->{'uname'},
$self->{'udom'},
@@ -3172,7 +3232,7 @@ sub loadstudent{
$self->constants(\%constants);
}
-# --------------------------------------------------- Load data for one student
+# --------------------------------------------------- Load Course Sheet
#
sub loadcourse {
my $self = shift;
@@ -3185,37 +3245,27 @@ sub loadcourse {
foreach ($self->rows()) {
$total++ if ($formulas{'A'.$_} !~ /^[!~-]/);
}
- my $now=0;
- my $since=time;
- $r->print(<
- popwin=open('','popwin','width=400,height=100');
- popwin.document.writeln(''+
- 'Spreadsheet Calculation Progress
'+
- ''+
- '');
- popwin.document.close();
-
-ENDPOP
- $r->rflush();
+
+ my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
+ 'Spreadsheet Status','Spreadsheet Calculation Progress', $total);
+ &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
+ 'Processing Course Assessment Data');
+
+ # It would be nice to load in the classlist and assessment info at this
+ # point, before attacking the student spreadsheets.
foreach my $row ($self->rows()) {
if(defined($c) && ($c->aborted())) {
last;
}
my $cell = 'A'.$row;
- next if (($formulas{$cell}=~/^[\!\~\-]/) || ($row==0));
+ next if ($formulas{$cell}=~/^[\!\~\-]/);
my ($sname,$sdom) = split(':',$formulas{$cell});
my $started = time;
my @studentdata=$self->exportsheet($sname,$sdom,'studentcalc',
undef,undef,$r);
undef %userrdatas;
- $now++;
- $r->print('');
- $r->rflush();
- #
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
+ 'last student');
my $index=0;
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') {
@@ -3235,8 +3285,7 @@ ENDPOP
}
$self->formulas(\%formulas);
$self->constants(\%constants);
- $r->print('');
- $r->rflush();
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
}
# ------------------------------------------------ Load data for one assessment