+ popwin=open('','popwin','width=400,height=100');
+ popwin.document.writeln(''+
+ 'Spreadsheet Calculation Progress
'+
+ ''+
+ '');
+ popwin.document.close();
+
+ENDPOP
+ $r->rflush();
map {
if ($_=~/^A(\d+)/) {
my $row=$1;
- unless (($f{$_}=~/^\!/)
-
-|| ($row>25))
-
- {
- my @studentdata=&exportsheet(&getuname($safeeval),
- &getudom($safeeval),
+ unless (($f{$_}=~/^\!/) || ($row==0)) {
+ my @studentdata=&exportsheet(split(/\:/,$f{$_}),
'studentcalc');
+ undef %userrdatas;
+ $now++;
+ $r->print('');
+ $r->rflush();
+
my $index=0;
map {
if ($studentdata[$index]) {
- $c{$_.$row}=$studentdata[$index];
- unless ($_ eq 'A') {
- $f{$_.$row}='import';
+ my $col=$_;
+ if ($studentdata[$index]=~/\D/) {
+ $c{$col.$row}="'".$studentdata[$index]."'";
+ } else {
+ $c{$col.$row}=$studentdata[$index];
+ }
+ unless ($col eq 'A') {
+ $f{$col.$row}='import';
}
}
$index++;
@@ -1213,6 +1411,8 @@ sub loadcourse {
} keys %f;
&setformulas($safeeval,%f);
&setconstants($safeeval,%c);
+ $r->print('');
+ $r->rflush();
}
# ------------------------------------------------ Load data for one assessment
@@ -1233,11 +1433,31 @@ sub loadassessment {
unless ($namespace=$cid) { return ''; }
# ----------------------------------------------------------- Get stored values
+
+ my %returnhash=();
+
+ if ($cachedassess eq $uname.':'.$udom) {
+#
+# get data out of the dumped stores
+#
+
+ my $version=$cachedstores{'version:'.$symb};
+ my $scope;
+ for ($scope=1;$scope<=$version;$scope++) {
+ map {
+ $returnhash{$_}=$cachedstores{$scope.':'.$symb.':'.$_};
+ } split(/\:/,$cachedstores{$scope.':keys:'.$symb});
+ }
+
+ } else {
+#
+# restore individual
+#
+
my $answer=&Apache::lonnet::reply(
"restore:$udom:$uname:".
&Apache::lonnet::escape($namespace).":".
&Apache::lonnet::escape($symb),$uhome);
- my %returnhash=();
map {
my ($name,$value)=split(/\=/,$_);
$returnhash{&Apache::lonnet::unescape($name)}=
@@ -1249,6 +1469,7 @@ sub loadassessment {
$returnhash{$_}=$returnhash{$version.':'.$_};
} split(/\:/,$returnhash{$version.':keys'});
}
+ }
# ----------------------------- returnhash now has all stores for this resource
# ---------------------------- initialize coursedata and userdata for this user
@@ -1260,7 +1481,7 @@ sub loadassessment {
unless ($uhome eq 'no_host') {
# -------------------------------------------------------------- Get coursedata
unless
- ((time-$courserdatas{$cid.'.last_cache'})<120) {
+ ((time-$courserdatas{$cid.'.last_cache'})<240) {
my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
':resourcedata',$chome);
if ($reply!~/^error\:/) {
@@ -1272,10 +1493,10 @@ sub loadassessment {
my ($name,$value)=split(/\=/,$_);
$courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
&Apache::lonnet::unescape($value);
- } split(/\&/,$courserdatas{$ENV{'request.course.id'}});
+ } split(/\&/,$courserdatas{$cid});
# --------------------------------------------------- Get userdata (if present)
unless
- ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<120) {
+ ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
my $reply=
&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
if ($reply!~/^error\:/) {
@@ -1289,10 +1510,21 @@ sub loadassessment {
&Apache::lonnet::unescape($value);
} split(/\&/,$userrdatas{$uname.'___'.$udom});
}
-
# ----------------- now courseopt, useropt initialized for this user and course
# (used by parmval)
+#
+# Load keys for this assessment only
+#
+ my %thisassess=();
+ my ($symap,$syid,$srcf)=split(/\_\_\_/,$symb);
+
+ map {
+ $thisassess{$_}=1;
+ } split(/\,/,&Apache::lonnet::metadata($srcf,'keys'));
+#
+# Load parameters
+#
my %c=();
if (tie(%parmhash,'GDBM_File',
@@ -1302,12 +1534,18 @@ sub loadassessment {
if ($_=~/^A/) {
unless ($f{$_}=~/^\!/) {
if ($f{$_}=~/^parameter/) {
- $c{$_}=&parmval($f{$_},$safeeval);
+ if ($thisassess{$f{$_}}) {
+ my $val=&parmval($f{$_},$safeeval);
+ $c{$_}=$val;
+ $c{$f{$_}}=$val;
+ }
} else {
my $key=$f{$_};
+ my $ckey=$key;
$key=~s/^stores\_/resource\./;
$key=~s/\_/\./;
$c{$_}=$returnhash{$key};
+ $c{$ckey}=$returnhash{$key};
}
}
}
@@ -1361,11 +1599,11 @@ sub updatesheet {
# Import the data for rows
#
-sub loadrows() {
- my $safeeval=shift;
+sub loadrows {
+ my ($safeeval,$r)=@_;
my $stype=&gettype($safeeval);
if ($stype eq 'classcalc') {
- &loadcourse($safeeval);
+ &loadcourse($safeeval,$r);
} elsif ($stype eq 'studentcalc') {
&loadstudent($safeeval);
} else {
@@ -1373,22 +1611,229 @@ sub loadrows() {
}
}
+# ======================================================= Forced recalculation?
+
+sub checkthis {
+ my ($keyname,$time)=@_;
+ return ($time<$expiredates{$keyname});
+}
+sub forcedrecalc {
+ my ($uname,$udom,$stype,$usymb)=@_;
+ my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;
+ my $time=$oldsheets{$key.'.time'};
+ if ($ENV{'form.forcerecalc'}) { return 1; }
+ unless ($time) { return 1; }
+ if ($stype eq 'assesscalc') {
+ my $map=(split(/\_\_\_/,$usymb))[0];
+ if (&checkthis('::assesscalc:',$time) ||
+ &checkthis('::assesscalc:'.$map,$time) ||
+ &checkthis('::assesscalc:'.$usymb,$time) ||
+ &checkthis($uname.':'.$udom.':assesscalc:',$time) ||
+ &checkthis($uname.':'.$udom.':assesscalc:'.$map,$time) ||
+ &checkthis($uname.':'.$udom.':assesscalc:'.$usymb,$time)) {
+ return 1;
+ }
+ } else {
+ if (&checkthis('::studentcalc:',$time) ||
+ &checkthis($uname.':'.$udom.':studentcalc:',$time)) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
# ============================================================== Export handler
#
# Non-interactive call from with program
#
sub exportsheet {
- my ($uname,$udom,$stype,$usymb,$fn)=@_;
+ my ($uname,$udom,$stype,$usymb,$fn)=@_;
+ my @exportarr=();
+#
+# Check if cached
+#
+
+ my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;
+ my $found='';
+
+ if ($oldsheets{$key}) {
+ map {
+ my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
+ if ($name eq $fn) {
+ $found=$value;
+ }
+ } split(/\_\_\_\&\_\_\_/,$oldsheets{$key});
+ }
+
+ unless ($found) {
+ &cachedssheets($uname,$udom,&Apache::lonnet::homeserver($uname,$udom));
+ if ($oldsheets{$key}) {
+ map {
+ my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
+ if ($name eq $fn) {
+ $found=$value;
+ }
+ } split(/\_\_\_\&\_\_\_/,$oldsheets{$key});
+ }
+ }
+#
+# Check if still valid
+#
+ if ($found) {
+ if (&forcedrecalc($uname,$udom,$stype,$usymb)) {
+ $found='';
+ }
+ }
+
+ if ($found) {
+#
+# Return what was cached
+#
+ @exportarr=split(/\_\_\_\;\_\_\_/,$found);
+
+ } else {
+#
+# Not cached
+#
+
my $thissheet=&makenewsheet($uname,$udom,$stype,$usymb);
&readsheet($thissheet,$fn);
&updatesheet($thissheet);
&loadrows($thissheet);
- &calcsheet($thissheet);
- my @returnthis=&exportdata($thissheet);
- undef $thissheet;
- return @returnthis;
+ &calcsheet($thissheet);
+ @exportarr=&exportdata($thissheet);
+#
+# Store now
+#
+ my $cid=$ENV{'request.course.id'};
+ my $current='';
+ if ($stype eq 'studentcalc') {
+ $current=&Apache::lonnet::reply('get:'.
+ $ENV{'course.'.$cid.'.domain'}.':'.
+ $ENV{'course.'.$cid.'.num'}.
+ ':nohist_calculatedsheets:'.
+ &Apache::lonnet::escape($key),
+ $ENV{'course.'.$cid.'.home'});
+ } else {
+ $current=&Apache::lonnet::reply('get:'.
+ &getudom($thissheet).':'.
+ &getuname($thissheet).
+ ':nohist_calculatedsheets_'.
+ $ENV{'request.course.id'}.':'.
+ &Apache::lonnet::escape($key),
+ &getuhome($thissheet));
+
+ }
+ my %currentlystored=();
+ unless ($current=~/^error\:/) {
+ map {
+ my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
+ $currentlystored{$name}=$value;
+ } split(/\_\_\_\&\_\_\_/,&Apache::lonnet::unescape($current));
+ }
+ $currentlystored{$fn}=join('___;___',@exportarr);
+
+ my $newstore='';
+ map {
+ if ($newstore) { $newstore.='___&___'; }
+ $newstore.=$_.'___=___'.$currentlystored{$_};
+ } keys %currentlystored;
+ my $now=time;
+ if ($stype eq 'studentcalc') {
+ &Apache::lonnet::reply('put:'.
+ $ENV{'course.'.$cid.'.domain'}.':'.
+ $ENV{'course.'.$cid.'.num'}.
+ ':nohist_calculatedsheets:'.
+ &Apache::lonnet::escape($key).'='.
+ &Apache::lonnet::escape($newstore).'&'.
+ &Apache::lonnet::escape($key).'.time='.$now,
+ $ENV{'course.'.$cid.'.home'});
+ } else {
+ &Apache::lonnet::reply('put:'.
+ &getudom($thissheet).':'.
+ &getuname($thissheet).
+ ':nohist_calculatedsheets_'.
+ $ENV{'request.course.id'}.':'.
+ &Apache::lonnet::escape($key).'='.
+ &Apache::lonnet::escape($newstore).'&'.
+ &Apache::lonnet::escape($key).'.time='.$now,
+ &getuhome($thissheet));
+ }
+ }
+ return @exportarr;
}
+# ============================================================ Expiration Dates
+#
+# Load previously cached student spreadsheets for this course
+#
+
+sub expirationdates {
+ undef %expiredates;
+ my $cid=$ENV{'request.course.id'};
+ my $reply=&Apache::lonnet::reply('dump:'.
+ $ENV{'course.'.$cid.'.domain'}.':'.
+ $ENV{'course.'.$cid.'.num'}.
+ ':nohist_expirationdates',
+ $ENV{'course.'.$cid.'.home'});
+ unless ($reply=~/^error\:/) {
+ map {
+ my ($name,$value)=split(/\=/,$_);
+ $expiredates{&Apache::lonnet::unescape($name)}
+ =&Apache::lonnet::unescape($value);
+ } split(/\&/,$reply);
+ }
+}
+
+# ===================================================== Calculated sheets cache
+#
+# Load previously cached student spreadsheets for this course
+#
+
+sub cachedcsheets {
+ my $cid=$ENV{'request.course.id'};
+ my $reply=&Apache::lonnet::reply('dump:'.
+ $ENV{'course.'.$cid.'.domain'}.':'.
+ $ENV{'course.'.$cid.'.num'}.
+ ':nohist_calculatedsheets',
+ $ENV{'course.'.$cid.'.home'});
+ unless ($reply=~/^error\:/) {
+ map {
+ my ($name,$value)=split(/\=/,$_);
+ $oldsheets{&Apache::lonnet::unescape($name)}
+ =&Apache::lonnet::unescape($value);
+ } split(/\&/,$reply);
+ }
+}
+
+# ===================================================== Calculated sheets cache
+#
+# Load previously cached assessment spreadsheets for this student
+#
+
+sub cachedssheets {
+ my ($sname,$sdom,$shome)=@_;
+ unless (($loadedcaches{$sname.'_'.$sdom}) || ($shome eq 'no_host')) {
+ my $cid=$ENV{'request.course.id'};
+ my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.
+ ':nohist_calculatedsheets_'.
+ $ENV{'request.course.id'},
+ $shome);
+ unless ($reply=~/^error\:/) {
+ map {
+ my ($name,$value)=split(/\=/,$_);
+ $oldsheets{&Apache::lonnet::unescape($name)}
+ =&Apache::lonnet::unescape($value);
+ } split(/\&/,$reply);
+ }
+ $loadedcaches{$sname.'_'.$sdom}=1;
+ }
+}
+
+# ===================================================== Calculated sheets cache
+#
+# Load previously cached assessment spreadsheets for this student
+#
# ================================================================ Main handler
#
@@ -1429,6 +1874,10 @@ $tmpdir=$r->dir_config('lonDaemons').'/t
}
} (split(/&/,$ENV{'QUERY_STRING'}));
+# -------------------------------------- Interactive loading of specific sheet?
+ if (($ENV{'form.load'}) && ($ENV{'form.loadthissheet'} ne 'Default')) {
+ $ENV{'form.ufn'}=$ENV{'form.loadthissheet'};
+ }
# ------------------------------------------- Nothing there? Must be login user
my $aname;
@@ -1464,6 +1913,12 @@ $tmpdir=$r->dir_config('lonDaemons').'/t
}
}
+ function changesheet(cn) {
+ document.sheet.unewfield.value=cn;
+ document.sheet.unewformula.value='changesheet';
+ document.sheet.submit();
+ }
+
ENDSCRIPT
$r->print(''.
@@ -1480,6 +1935,18 @@ ENDSCRIPT
$r->rflush();
+# ---------------------------------------------------------------- Full recalc?
+
+
+ if ($ENV{'form.forcerecalc'}) {
+ $r->print('Completely Recalculating Sheet ...
');
+ undef %spreadsheets;
+ undef %courserdatas;
+ undef %userrdatas;
+ undef %defaultsheets;
+ undef %updatedata;
+ }
+
# ---------------------------------------- Read new sheet or modified worksheet
$r->uri=~/\/(\w+)$/;
@@ -1522,27 +1989,37 @@ ENDSCRIPT
$r->print(''.
$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.'
');
+# ---------------------------------------------------- See if user can see this
-# ---------------------------------------------------- See if something to save
-
- if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
- my $fname='';
- if ($ENV{'form.saveas'} && ($fname=$ENV{'form.newfn'})) {
- $fname=~s/\W/\_/g;
- if ($fname eq 'default') { $fname='course_default'; }
- $fname.='_'.&gettype($asheet);
- &setfilename($asheet,$fname);
- $ENV{'form.ufn'}=$fname;
- $r->print('Saving spreadsheet: '.
- &writesheet($asheet,$ENV{'form.makedefufn'}).'
');
- }
+ if ((&gettype($asheet) eq 'classcalc') ||
+ (&getuname($asheet) ne $ENV{'user.name'}) ||
+ (&getudom($asheet) ne $ENV{'user.domain'})) {
+ unless (&Apache::lonnet::allowed('vgr',&getcid($asheet))) {
+ $r->print(
+ '
Access Permission Denied