');
}
@@ -1296,9 +1342,9 @@ sub outsheet {
sub othersheets {
my ($safeeval,$stype)=@_;
#
- my $cnum=&getcnum($safeeval);
- my $cdom=&getcdom($safeeval);
- my $chome=&getchome($safeeval);
+ my $cnum = &getcnum($safeeval);
+ my $cdom = &getcdom($safeeval);
+ my $chome = &getchome($safeeval);
#
my @alternatives=();
my %results=&Apache::lonnet::dump($stype.'_spreadsheets',$cdom,$cnum);
@@ -1343,77 +1389,71 @@ sub parse_sheet {
#
sub readsheet {
- my ($safeeval,$fn)=@_;
- my $stype=&gettype($safeeval);
- my $cnum=&getcnum($safeeval);
- my $cdom=&getcdom($safeeval);
- my $chome=&getchome($safeeval);
-
- if (! defined($fn)) {
- # There is no filename. Look for defaults in course and global, cache
- unless ($fn=$defaultsheets{$cnum.'_'.$cdom.'_'.$stype}) {
- my %tmphash = &Apache::lonnet::get('environment',
- ['spreadsheet_default_'.$stype],
- $cdom,$cnum);
- my ($tmp) = keys(%tmphash);
- if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
- $fn = 'default_'.$stype;
- } else {
- $fn = $tmphash{'spreadsheet_default_'.$stype};
- }
- unless (($fn) && ($fn!~/^error\:/)) {
- $fn='default_'.$stype;
- }
- $defaultsheets{$cnum.'_'.$cdom.'_'.$stype}=$fn;
- }
- }
-
-# ---------------------------------------------------------- fn now has a value
-
- &setfilename($safeeval,$fn);
-
-# ------------------------------------------------------ see if sheet is cached
- my $fstring='';
- if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) {
- &setformulas($safeeval,split(/\_\_\_\;\_\_\_/,$fstring));
- } else {
-
-# ---------------------------------------------------- Not cached, need to read
-
- my %f=();
-
- if ($fn=~/^default\_/) {
- my $sheetxml='';
- my $fh;
- my $dfn=$fn;
- $dfn=~s/\_/\./g;
- if ($fh=Apache::File->new($includedir.'/'.$dfn)) {
- $sheetxml=join('',<$fh>);
- } else {
- $sheetxml='"Error"';
- }
- %f=%{&parse_sheet(\$sheetxml)};
- } elsif($fn=~/\/*\.spreadsheet$/) {
- my $sheetxml=&Apache::lonnet::getfile
- (&Apache::lonnet::filelocation('',$fn));
- if ($sheetxml == -1) {
- $sheetxml='"Error loading spreadsheet '
- .$fn.'"';
- }
- %f=%{&parse_sheet(\$sheetxml)};
- } else {
- my $sheet='';
- my %tmphash = &Apache::lonnet::dump($fn,$cdom,$cnum);
- my ($tmp) = keys(%tmphash);
- unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
- foreach (keys(%tmphash)) {
- $f{$_}=$tmphash{$_};
- }
- }
- }
-# --------------------------------------------------------------- Cache and set
- $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f);
- &setformulas($safeeval,%f);
+ my ($safeeval,$fn)=@_;
+ my $stype = &gettype($safeeval);
+ my $cnum = &getcnum($safeeval);
+ my $cdom = &getcdom($safeeval);
+ my $chome = &getchome($safeeval);
+
+ if (! defined($fn)) {
+ # There is no filename. Look for defaults in course and global, cache
+ unless ($fn=$defaultsheets{$cnum.'_'.$cdom.'_'.$stype}) {
+ my %tmphash = &Apache::lonnet::get('environment',
+ ['spreadsheet_default_'.$stype],
+ $cdom,$cnum);
+ my ($tmp) = keys(%tmphash);
+ if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
+ $fn = 'default_'.$stype;
+ } else {
+ $fn = $tmphash{'spreadsheet_default_'.$stype};
+ }
+ unless (($fn) && ($fn!~/^error\:/)) {
+ $fn='default_'.$stype;
+ }
+ $defaultsheets{$cnum.'_'.$cdom.'_'.$stype}=$fn;
+ }
+ }
+ # $fn now has a value
+ &setfilename($safeeval,$fn);
+ # see if sheet is cached
+ my $fstring='';
+ if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) {
+ &setformulas($safeeval,split(/\_\_\_\;\_\_\_/,$fstring));
+ } else {
+ # Not cached, need to read
+ my %f=();
+ if ($fn=~/^default\_/) {
+ my $sheetxml='';
+ my $fh;
+ my $dfn=$fn;
+ $dfn=~s/\_/\./g;
+ if ($fh=Apache::File->new($includedir.'/'.$dfn)) {
+ $sheetxml=join('',<$fh>);
+ } else {
+ $sheetxml='"Error"';
+ }
+ %f=%{&parse_sheet(\$sheetxml)};
+ } elsif($fn=~/\/*\.spreadsheet$/) {
+ my $sheetxml=&Apache::lonnet::getfile
+ (&Apache::lonnet::filelocation('',$fn));
+ if ($sheetxml == -1) {
+ $sheetxml='"Error loading spreadsheet '
+ .$fn.'"';
+ }
+ %f=%{&parse_sheet(\$sheetxml)};
+ } else {
+ my $sheet='';
+ my %tmphash = &Apache::lonnet::dump($fn,$cdom,$cnum);
+ my ($tmp) = keys(%tmphash);
+ unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
+ foreach (keys(%tmphash)) {
+ $f{$_}=$tmphash{$_};
+ }
+ }
+ }
+ # Cache and set
+ $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f);
+ &setformulas($safeeval,%f);
}
}
@@ -1421,72 +1461,77 @@ sub readsheet {
sub makenewsheet {
my ($uname,$udom,$stype,$usymb)=@_;
+ my %sheetdata=();
+ $sheetdata{'uname'} = $uname;
+ $sheetdata{'udom'} = $udom;
+ $sheetdata{'sheettype'} = $stype;
+ $sheetdata{'usymb'} = $usymb;
+ $sheetdata{'cid'} = $ENV{'request.course.id'};
+ $sheetdata{'csec'} = &Apache::lonnet::usection
+ ($udom,$uname,$ENV{'request.course.id'});
+ $sheetdata{'cfn'} = $ENV{'request.course.fn'};
+ $sheetdata{'cnum'} = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+ $sheetdata{'cdom'} = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ $sheetdata{'chome'} = $ENV{'course.'.$ENV{'request.course.id'}.'.home'};
+ $sheetdata{'uhome'} = &Apache::lonnet::homeserver($uname,$udom);
+
my $safeeval=initsheet($stype);
- $safeeval->reval(
- '$uname="'.$uname.
- '";$udom="'.$udom.
- '";$uhome="'.&Apache::lonnet::homeserver($uname,$udom).
- '";$sheettype="'.$stype.
- '";$usymb="'.$usymb.
- '";$csec="'.&Apache::lonnet::usection($udom,$uname,
- $ENV{'request.course.id'}).
- '";$cid="'.$ENV{'request.course.id'}.
- '";$cfn="'.$ENV{'request.course.fn'}.
- '";$cnum="'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
- '";$cdom="'.$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
- '";$chome="'.$ENV{'course.'.$ENV{'request.course.id'}.'.home'}.'";');
- return $safeeval;
+ my $initstring = '';
+ foreach (keys(%sheetdata)) {
+ $initstring.= qq{\$$_="$sheetdata{$_}";};
+ }
+ $safeeval->reval($initstring);
+ return $safeeval,\%sheetdata;
}
# ------------------------------------------------------------ Save spreadsheet
sub writesheet {
- my ($safeeval,$makedef)=@_;
- my $cid=&getcid($safeeval);
- if (&Apache::lonnet::allowed('opa',$cid)) {
- my %f=&getformulas($safeeval);
- my $stype=&gettype($safeeval);
- my $cnum=&getcnum($safeeval);
- my $cdom=&getcdom($safeeval);
- my $chome=&getchome($safeeval);
- my $fn=&getfilename($safeeval);
-
-# ------------------------------------------------------------- Cache new sheet
- $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f);
-# ----------------------------------------------------------------- Write sheet
- my $sheetdata='';
- foreach (keys(%f)) {
- unless ($f{$_} eq 'import') {
- $sheetdata.=&Apache::lonnet::escape($_).'='.
- &Apache::lonnet::escape($f{$_}).'&';
- }
- }
- $sheetdata=~s/\&$//;
- my $reply=&Apache::lonnet::reply('put:'.$cdom.':'.$cnum.':'.$fn.':'.
- $sheetdata,$chome);
- if ($reply eq 'ok') {
- $reply=&Apache::lonnet::reply('put:'.$cdom.':'.$cnum.':'.
- $stype.'_spreadsheets:'.
- &Apache::lonnet::escape($fn).'='.$ENV{'user.name'}.'@'.
- $ENV{'user.domain'},
- $chome);
- if ($reply eq 'ok') {
- if ($makedef) {
- return &Apache::lonnet::reply('put:'.$cdom.':'.$cnum.
- ':environment:spreadsheet_default_'.$stype.'='.
- &Apache::lonnet::escape($fn),
- $chome);
- } else {
- return $reply;
- }
- } else {
- return $reply;
- }
- } else {
- return $reply;
- }
- }
- return 'unauthorized';
+ my ($safeeval,$makedef)=@_;
+ my $cid=&getcid($safeeval);
+ if (&Apache::lonnet::allowed('opa',$cid)) {
+ my %f=&getformulas($safeeval);
+ my $stype=&gettype($safeeval);
+ my $cnum=&getcnum($safeeval);
+ my $cdom=&getcdom($safeeval);
+ my $chome=&getchome($safeeval);
+ my $fn=&getfilename($safeeval);
+ # Cache new sheet
+ $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f);
+ # Write sheet
+ my $sheetdata='';
+ foreach (keys(%f)) {
+ unless ($f{$_} eq 'import') {
+ $sheetdata.=&Apache::lonnet::escape($_).'='.
+ &Apache::lonnet::escape($f{$_}).'&';
+ }
+ }
+ $sheetdata=~s/\&$//;
+ my $reply=&Apache::lonnet::reply('put:'.$cdom.':'.$cnum.':'.$fn.':'.
+ $sheetdata,$chome);
+ if ($reply eq 'ok') {
+ $reply=&Apache::lonnet::reply('put:'.$cdom.':'.$cnum.':'.
+ $stype.'_spreadsheets:'.
+ &Apache::lonnet::escape($fn).
+ '='.$ENV{'user.name'}.'@'.
+ $ENV{'user.domain'},
+ $chome);
+ if ($reply eq 'ok') {
+ if ($makedef) {
+ return &Apache::lonnet::reply('put:'.$cdom.':'.$cnum.
+ ':environment:'.
+ 'spreadsheet_default_'.
+ $stype.'='.
+ &Apache::lonnet::escape($fn),
+ $chome);
+ }
+ return $reply;
+ }
+ return $reply;
+ }
+ return $reply;
+ }
+ return 'unauthorized';
}
# ----------------------------------------------- Make a temp copy of the sheet
@@ -1496,7 +1541,7 @@ sub writesheet {
sub tmpwrite {
my $safeeval=shift;
my $fn=$ENV{'user.name'}.'_'.
- $ENV{'user.domain'}.'_spreadsheet_'.&getusymb($safeeval).'_'.
+ $ENV{'user.domain'}.'_spreadsheet_'.&getusymb($safeeval).'_'.
&getfilename($safeeval);
$fn=~s/\W/\_/g;
$fn=$tmpdir.$fn.'.tmp';
@@ -1551,216 +1596,203 @@ sub tmpread {
&setformulas($safeeval,%fo);
}
-# ================================================================== Parameters
-# -------------------------------------------- Figure out a cascading parameter
-#
-# For this function to work
-#
-# * parmhash needs to be tied
-# * courseopt and useropt need to be initialized for this user and course
-#
+##################################################
+##################################################
-sub parmval {
- my ($what,$safeeval)=@_;
- my $cid=&getcid($safeeval);
- my $csec=&getcsec($safeeval);
- my $uname=&getuname($safeeval);
- my $udom=&getudom($safeeval);
- my $symb=&getusymb($safeeval);
+=pod
- unless ($symb) { return ''; }
- my $result='';
+=item &parmval()
- my ($mapname,$id,$fn)=split(/\_\_\_/,$symb);
-# ----------------------------------------------------- Cascading lookup scheme
- my $rwhat=$what;
- $what=~s/^parameter\_//;
- $what=~s/\_([^\_]+)$/\.$1/;
-
- my $symbparm=$symb.'.'.$what;
- my $mapparm=$mapname.'___(all).'.$what;
- my $usercourseprefix=$uname.'_'.$udom.'_'.$cid;
-
- my $seclevel=
- $usercourseprefix.'.['.
- $csec.'].'.$what;
- my $seclevelr=
- $usercourseprefix.'.['.
- $csec.'].'.$symbparm;
- my $seclevelm=
- $usercourseprefix.'.['.
- $csec.'].'.$mapparm;
-
- my $courselevel=
- $usercourseprefix.'.'.$what;
- my $courselevelr=
- $usercourseprefix.'.'.$symbparm;
- my $courselevelm=
- $usercourseprefix.'.'.$mapparm;
-
-# ---------------------------------------------------------- fourth, check user
-
- if ($uname) {
-
- if ($useropt{$courselevelr}) { return $useropt{$courselevelr}; }
-
- if ($useropt{$courselevelm}) { return $useropt{$courselevelm}; }
+Determine the value of a parameter.
- if ($useropt{$courselevel}) { return $useropt{$courselevel}; }
+Inputs: $what, the parameter needed, $safeeval, the safe space
- }
-
-# --------------------------------------------------------- third, check course
-
- if ($csec) {
-
- if ($courseopt{$seclevelr}) { return $courseopt{$seclevelr}; }
+Returns: The value of a parameter, or '' if none.
- if ($courseopt{$seclevelm}) { return $courseopt{$seclevelm}; }
+This function cascades through the possible levels searching for a value for
+a parameter. The levels are checked in the following order:
+user, course (at section level and course level), map, and lonnet::metadata.
+This function uses %parmhash, which must be tied prior to calling it.
+This function also requires %courseopt and %useropt to be initialized for
+this user and course.
- if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; }
-
- }
-
- if ($courseopt{$courselevelr}) { return $courseopt{$courselevelr}; }
-
- if ($courseopt{$courselevelm}) { return $courseopt{$courselevelm}; }
-
- if ($courseopt{$courselevel}) { return $courseopt{$courselevel}; }
-
-# ----------------------------------------------------- second, check map parms
-
- my $thisparm=$parmhash{$symbparm};
- if ($thisparm) { return $thisparm; }
-
-# -------------------------------------------------------- first, check default
+=cut
- return &Apache::lonnet::metadata($fn,$rwhat.'.default');
-
+##################################################
+##################################################
+sub parmval {
+ my ($what,$safeeval,$sheetdata)=@_;
+ my $symb = $sheetdata->{'usymb'};
+ unless ($symb) { return ''; }
+ #
+ my $cid = $sheetdata->{'cid'};
+ my $csec = $sheetdata->{'csec'};
+ my $uname = $sheetdata->{'uname'};
+ my $udom = $sheetdata->{'udom'};
+ my $result='';
+ #
+ my ($mapname,$id,$fn)=split(/\_\_\_/,$symb);
+ # Cascading lookup scheme
+ my $rwhat=$what;
+ $what =~ s/^parameter\_//;
+ $what =~ s/\_([^\_]+)$/\.$1/;
+ #
+ my $symbparm = $symb.'.'.$what;
+ my $mapparm = $mapname.'___(all).'.$what;
+ my $usercourseprefix = $uname.'_'.$udom.'_'.$cid;
+ #
+ my $seclevel = $usercourseprefix.'.['.$csec.'].'.$what;
+ my $seclevelr = $usercourseprefix.'.['.$csec.'].'.$symbparm;
+ my $seclevelm = $usercourseprefix.'.['.$csec.'].'.$mapparm;
+ #
+ my $courselevel = $usercourseprefix.'.'.$what;
+ my $courselevelr = $usercourseprefix.'.'.$symbparm;
+ my $courselevelm = $usercourseprefix.'.'.$mapparm;
+ # fourth, check user
+ if ($uname) {
+ return $useropt{$courselevelr} if ($useropt{$courselevelr});
+ return $useropt{$courselevelm} if ($useropt{$courselevelm});
+ return $useropt{$courselevel} if ($useropt{$courselevel});
+ }
+ # third, check course
+ if ($csec) {
+ return $courseopt{$seclevelr} if ($courseopt{$seclevelr});
+ return $courseopt{$seclevelm} if ($courseopt{$seclevelm});
+ return $courseopt{$seclevel} if ($courseopt{$seclevel});
+ }
+ #
+ return $courseopt{$courselevelr} if ($courseopt{$courselevelr});
+ return $courseopt{$courselevelm} if ($courseopt{$courselevelm});
+ return $courseopt{$courselevel} if ($courseopt{$courselevel});
+ # second, check map parms
+ my $thisparm = $parmhash{$symbparm};
+ return $thisparm if ($thisparm);
+ # first, check default
+ return &Apache::lonnet::metadata($fn,$rwhat.'.default');
}
# ---------------------------------------------- Update rows for course listing
-
sub updateclasssheet {
my $safeeval=shift;
my $cnum=&getcnum($safeeval);
my $cdom=&getcdom($safeeval);
my $cid=&getcid($safeeval);
my $chome=&getchome($safeeval);
-
-# ---------------------------------------------- Read class list and row labels
-
- my $classlst=&Apache::lonnet::reply
- ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
+ #
+ # Read class list and row labels
+ my %classlist;
+ my @tmp = &Apache::lonnet::dump('classlist',$cdom,$cnum);
+ if ($tmp[0] !~ /^error/) {
+ %classlist = @tmp;
+ } else {
+ return 'Could not access course data';
+ }
+ undef @tmp;
+ #
my %currentlist=();
my $now=time;
- unless ($classlst=~/^error\:/) {
- foreach (split(/\&/,$classlst)) {
- my ($name,$value)=split(/\=/,$_);
- my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
- my $active=1;
- if (($end) && ($now>$end)) { $active=0; }
- $active = 1 if ($ENV{'form.Status'} eq 'Any');
- $active = !$active if ($ENV{'form.Status'} eq 'Expired');
- if ($active) {
- my $rowlabel='';
- $name=&Apache::lonnet::unescape($name);
- my ($sname,$sdom)=split(/\:/,$name);
- my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
- if ($ssec==-1) {
- unless ($ENV{'form.showcsv'}) {
- $rowlabel='Data not available: '.$name.
- '';
- } else {
- $rowlabel='ERROR","'.$name.
- '","Data not available","","","';
- }
+ foreach my $student (keys(%classlist)) {
+ my ($end,$start)=split(/\:/,$classlist{$student});
+ my $active=1;
+ $active = 0 if (($end) && ($now>$end));
+ $active = 1 if ($ENV{'form.Status'} eq 'Any');
+ $active = !$active if ($ENV{'form.Status'} eq 'Expired');
+ if ($active) {
+ my $rowlabel='';
+ my ($studentName,$studentDomain)=split(/\:/,$student);
+ my $studentSection=&Apache::lonnet::usection($studentDomain,
+ $studentName,$cid);
+ if ($studentSection==-1) {
+ unless ($ENV{'form.showcsv'}) {
+ $rowlabel='Data not available: '.
+ $studentName.'';
} else {
- my %reply=&Apache::lonnet::idrget($sdom,$sname);
- my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
- ':environment:firstname&middlename&lastname&generation',
- &Apache::lonnet::homeserver($sname,$sdom));
- unless ($ENV{'form.showcsv'}) {
- $rowlabel=''.
- $ssec.' '.$reply{$sname}.' ';
- foreach ( split(/\&/,$reply)) {
- $rowlabel.=&Apache::lonnet::unescape($_).' ';
+ $rowlabel='ERROR","'.$studentName.
+ '","Data not available","","","';
+ }
+ } else {
+ my %reply=&Apache::lonnet::idrget($studentDomain,$studentName);
+ my %studentInformation=&Apache::lonnet::get
+ ('environment',
+ ['lastname','generation','firstname','middlename','id'],
+ $studentDomain,$studentName);
+ if (! $ENV{'form.showcsv'}) {
+ $rowlabel=''.
+ $studentSection.' ';
+ foreach ('id','firstname','middlename',
+ 'lastname','generation'){
+ $rowlabel.=$studentInformation{$_}." ";
}
$rowlabel.='';
- } else {
- $rowlabel=$ssec.'","'.$reply{$sname}.'"';
- my $ncount=0;
- foreach (split(/\&/,$reply)) {
- $rowlabel.=',"'.&Apache::lonnet::unescape($_).'"';
- $ncount++;
- }
- unless ($ncount==4) { $rowlabel.=',""'; }
- $rowlabel=~s/\"$//;
- }
+ } else {
+ $rowlabel= '"'.join('","',
+ ($studentSection,
+ $studentInformation{'id'},
+ $studentInformation{'firstname'},
+ $studentInformation{'middlename'},
+ $studentInformation{'lastname'},
+ $studentInformation{'generation'})
+ ).'"';
}
- $currentlist{&Apache::lonnet::unescape($name)}=$rowlabel;
}
- } # end of foreach (split(/\&/,$classlst))
-#
-# -------------------- Find discrepancies between the course row table and this
-#
- my %f=&getformulas($safeeval);
- my $changed=0;
-
- my $maxrow=0;
- my %existing=();
-
-# ----------------------------------------------------------- Now obsolete rows
- foreach (keys(%f)) {
- if ($_=~/^A(\d+)/) {
- $maxrow=($1>$maxrow)?$1:$maxrow;
- $existing{$f{$_}}=1;
- unless ((defined($currentlist{$f{$_}})) || (!$1) ||
- ($f{$_}=~/^(\~\~\~|\-\-\-)/)) {
- $f{$_}='!!! Obsolete';
- $changed=1;
- }
+ $currentlist{$student}=$rowlabel;
+ } # end of if ($active)
+ } # end of foreach my $student (keys(%classlist))
+ #
+ # Find discrepancies between the course row table and this
+ #
+ my %f=&getformulas($safeeval);
+ my $changed=0;
+ #
+ my $maxrow=0;
+ my %existing=();
+ #
+ # Now obsolete rows
+ foreach (keys(%f)) {
+ if ($_=~/^A(\d+)/) {
+ $maxrow=($1>$maxrow)?$1:$maxrow;
+ $existing{$f{$_}}=1;
+ unless ((defined($currentlist{$f{$_}})) || (!$1) ||
+ ($f{$_}=~/^(\~\~\~|\-\-\-)/)) {
+ $f{$_}='!!! Obsolete';
+ $changed=1;
}
}
-
-# -------------------------------------------------------- New and unknown keys
-
- foreach (sort keys(%currentlist)) {
- unless ($existing{$_}) {
- $changed=1;
- $maxrow++;
- $f{'A'.$maxrow}=$_;
- }
+ }
+ #
+ # New and unknown keys
+ foreach (sort keys(%currentlist)) {
+ unless ($existing{$_}) {
+ $changed=1;
+ $maxrow++;
+ $f{'A'.$maxrow}=$_;
}
-
- if ($changed) { &setformulas($safeeval,%f); }
-
- &setmaxrow($safeeval,$maxrow);
- &setrowlabels($safeeval,%currentlist);
-
- } else {
- return 'Could not access course data';
}
+ if ($changed) { &setformulas($safeeval,%f); }
+ #
+ &setmaxrow($safeeval,$maxrow);
+ &setrowlabels($safeeval,%currentlist);
}
# ----------------------------------- Update rows for student and assess sheets
-
sub updatestudentassesssheet {
my $safeeval=shift;
my %bighash;
my $stype=&gettype($safeeval);
- my $uname=&getuname($safeeval);
- my $udom =&getudom($safeeval);
my %current=();
- unless ($updatedata{
- $ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom}) {
-# -------------------------------------------------------------------- Tie hash
- if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
- &GDBM_READER(),0640)) {
-# --------------------------------------------------------- Get all assessments
-
- my %allkeys=('timestamp' =>
+ if ($updatedata{$ENV{'request.course.fn'}.'_'.$stype}) {
+ %current=split(/\_\_\_\;\_\_\_/,
+ $updatedata{$ENV{'request.course.fn'}.'_'.$stype});
+ } else {
+ # Tie hash
+ tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
+ &GDBM_READER(),0640);
+ if (! tied(%bighash)) {
+ return 'Could not access course data';
+ }
+ # Get all assessments
+ my %allkeys=('timestamp' =>
'Timestamp of Last Transaction timestamp',
'subnumber' =>
'Number of Submissions subnumber',
@@ -1768,174 +1800,144 @@ sub updatestudentassesssheet {
'Number of Tutor Responses tutornumber',
'totalpoints' =>
'Total Points Granted totalpoints');
-
my $adduserstr='';
if ((&getuname($safeeval) ne $ENV{'user.name'}) ||
(&getudom($safeeval) ne $ENV{'user.domain'})) {
$adduserstr='&uname='.&getuname($safeeval).
- '&udom='.&getudom($safeeval);
+ '&udom='.&getudom($safeeval);
}
-
- my %allassess=('_feedback' =>
- 'Feedback',
- '_evaluation' =>
- 'Evaluation',
- '_tutoring' =>
- 'Tutoring',
- '_discussion' =>
- 'Discussion'
- );
-
+ my %allassess =
+ ('_feedback' =>'Feedback',
+ '_evaluation' =>'Evaluation',
+ '_tutoring' =>'Tutoring',
+ '_discussion' =>'Discussion'
+ );
foreach (keys(%bighash)) {
- 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)$/) {
- my $symb=
- &Apache::lonnet::declutter($bighash{'map_id_'.$mapid}).
- '___'.$resid.'___'.
- &Apache::lonnet::declutter($srcf);
- $allassess{$symb}=
- ''.
- $bighash{'title_'.$id}.'';
- if ($stype eq 'assesscalc') {
- foreach (split(/\,/,
- &Apache::lonnet::metadata($srcf,'keys'))) {
- if (($_=~/^stores\_(.*)/) || ($_=~/^parameter\_(.*)/)) {
- my $key=$_;
- my $display=
- &Apache::lonnet::metadata($srcf,$key.'.display');
- unless ($display) {
- $display.=
- &Apache::lonnet::metadata($srcf,$key.'.name');
- }
- $display.=' '.$key;
- $allkeys{$key}=$display;
- }
- } # end of foreach
- }
- }
- }
+ 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)$/) {
+ my $symb=
+ &Apache::lonnet::declutter($bighash{'map_id_'.$mapid}).
+ '___'.$resid.'___'.&Apache::lonnet::declutter($srcf);
+ $allassess{$symb}=
+ ''.
+ $bighash{'title_'.$id}.'';
+ next if ($stype ne 'assesscalc');
+ foreach my $key (split(/\,/,
+ &Apache::lonnet::metadata($srcf,'keys')
+ )) {
+ next if ($key !~ /^(stores|parameter)_/);
+ my $display=
+ &Apache::lonnet::metadata($srcf,$key.'.display');
+ unless ($display) {
+ $display.=
+ &Apache::lonnet::metadata($srcf,$key.'.name');
+ }
+ $display.=' '.$key;
+ $allkeys{$key}=$display;
+ } # end of foreach
+ }
} # end of foreach (keys(%bighash))
untie(%bighash);
-
-#
-# %allkeys has a list of storage and parameter displays by unikey
-# %allassess has a list of all resource displays by symb
-#
-
+ #
+ # %allkeys has a list of storage and parameter displays by unikey
+ # %allassess has a list of all resource displays by symb
+ #
if ($stype eq 'assesscalc') {
- %current=%allkeys;
+ %current=%allkeys;
} elsif ($stype eq 'studentcalc') {
%current=%allassess;
}
- $updatedata{$ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom}=
- join('___;___',%current);
- } else {
- return 'Could not access course data';
- }
-# ------------------------------------------------------ Get current from cache
- } else {
- %current=split(/\_\_\_\;\_\_\_/,
- $updatedata{$ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom});
+ $updatedata{$ENV{'request.course.fn'}.'_'.$stype}=
+ join('___;___',%current);
+ # Get current from cache
}
-# -------------------- Find discrepancies between the course row table and this
-#
- my %f=&getformulas($safeeval);
- my $changed=0;
-
- my $maxrow=0;
- my %existing=();
-
-# ----------------------------------------------------------- Now obsolete rows
- foreach (keys(%f)) {
- if ($_=~/^A(\d+)/) {
- $maxrow=($1>$maxrow)?$1:$maxrow;
- my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{$_});
- $existing{$usy}=1;
- unless ((defined($current{$usy})) || (!$1) ||
- ($f{$_}=~/^(\~\~\~|\-\-\-)/)){
- $f{$_}='!!! Obsolete';
- $changed=1;
- } elsif ($ufn) {
- $current{$usy}
- =~s/assesscalc\?usymb\=/assesscalc\?ufn\=$ufn\&usymb\=/;
- }
- }
- }
-
-# -------------------------------------------------------- New and unknown keys
-
- foreach (keys(%current)) {
- unless ($existing{$_}) {
- $changed=1;
- $maxrow++;
- $f{'A'.$maxrow}=$_;
- }
- }
+ # Find discrepancies between the course row table and this
+ #
+ my %f=&getformulas($safeeval);
+ my $changed=0;
- if ($changed) { &setformulas($safeeval,%f); }
-
- &setmaxrow($safeeval,$maxrow);
- &setrowlabels($safeeval,%current);
-
- undef %current;
- undef %existing;
+ my $maxrow=0;
+ my %existing=();
+ # Now obsolete rows
+ foreach (keys(%f)) {
+ next if ($_!~/^A(\d+)/);
+ $maxrow=($1>$maxrow)?$1:$maxrow;
+ my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{$_});
+ $existing{$usy}=1;
+ unless ((defined($current{$usy})) || (!$1) ||
+ ($f{$_}=~/^(\~\~\~|\-\-\-)/)){
+ $f{$_}='!!! Obsolete';
+ $changed=1;
+ } elsif ($ufn) {
+ $current{$usy}
+ =~s/assesscalc\?usymb\=/assesscalc\?ufn\=$ufn\&usymb\=/;
+ }
+ }
+ # New and unknown keys
+ foreach (keys(%current)) {
+ unless ($existing{$_}) {
+ $changed=1;
+ $maxrow++;
+ $f{'A'.$maxrow}=$_;
+ }
+ }
+ if ($changed) { &setformulas($safeeval,%f); }
+ &setmaxrow($safeeval,$maxrow);
+ &setrowlabels($safeeval,%current);
+ #
+ undef %current;
+ undef %existing;
}
# ------------------------------------------------ Load data for one assessment
sub loadstudent {
- my $safeeval=shift;
+ my ($safeeval,$sheetdata)=@_;
my %c=();
my %f=&getformulas($safeeval);
- $cachedassess=&getuname($safeeval).':'.&getudom($safeeval);
- %cachedstores=();
- {
- my $reply=&Apache::lonnet::reply('dump:'.&getudom($safeeval).':'.
- &getuname($safeeval).':'.
- &getcid($safeeval),
- &getuhome($safeeval));
- unless ($reply=~/^error\:/) {
- foreach ( split(/\&/,$reply)) {
- my ($name,$value)=split(/\=/,$_);
- $cachedstores{&Apache::lonnet::unescape($name)}=
- &Apache::lonnet::unescape($value);
- }
- }
+ $cachedassess=$sheetdata->{'uname'}.':'.$sheetdata->{'udom'};
+ # Get ALL the student preformance data
+ my @tmp = &Apache::lonnet::dump($sheetdata->{'cid'},
+ $sheetdata->{'udom'},
+ $sheetdata->{'uname'},
+ undef);
+ if ($tmp[0] !~ /^error:/) {
+ %cachedstores = @tmp;
}
+ undef @tmp;
+ #
my @assessdata=();
foreach (keys(%f)) {
- if ($_=~/^A(\d+)/) {
- my $row=$1;
- unless (($f{$_}=~/^[\!\~\-]/) || ($row==0)) {
- my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{$_});
- @assessdata=&exportsheet(&getuname($safeeval),
- &getudom($safeeval),
- 'assesscalc',$usy,$ufn);
- 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') {
- if ($assessdata[$index]) {
- my $col=$_;
- if ($assessdata[$index]=~/\D/) {
- $c{$col.$row}="'".$assessdata[$index]."'";
- } else {
- $c{$col.$row}=$assessdata[$index];
- }
- unless ($col eq 'A') {
- $f{$col.$row}='import';
- }
- }
- $index++;
- }
- }
+ next if ($_!~/^A(\d+)/);
+ my $row=$1;
+ next if (($f{$_}=~/^[\!\~\-]/) || ($row==0));
+ my ($usy,$ufn)=split(/__&&&\__/,$f{$_});
+ @assessdata=&exportsheet($sheetdata->{'uname'},
+ $sheetdata->{'udom'},
+ 'assesscalc',$usy,$ufn);
+ 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') {
+ if ($assessdata[$index]) {
+ my $col=$_;
+ if ($assessdata[$index]=~/\D/) {
+ $c{$col.$row}="'".$assessdata[$index]."'";
+ } else {
+ $c{$col.$row}=$assessdata[$index];
+ }
+ unless ($col eq 'A') {
+ $f{$col.$row}='import';
+ }
+ }
+ $index++;
}
}
$cachedassess='';
@@ -1947,7 +1949,7 @@ sub loadstudent {
# --------------------------------------------------- Load data for one student
sub loadcourse {
- my ($safeeval,$r)=@_;
+ my ($safeeval,$sheetdata,$r)=@_;
my %c=();
my %f=&getformulas($safeeval);
my $total=0;
@@ -1971,35 +1973,33 @@ sub loadcourse {
ENDPOP
$r->rflush();
foreach (keys(%f)) {
- if ($_=~/^A(\d+)/) {
- my $row=$1;
- unless (($f{$_}=~/^[\!\~\-]/) || ($row==0)) {
- my @studentdata=&exportsheet(split(/\:/,$f{$_}),
- 'studentcalc');
- undef %userrdatas;
- $now++;
- $r->print('');
- $r->rflush();
-
- 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') {
- if ($studentdata[$index]) {
- 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++;
- }
- }
+ ' secs remaining";');
+ $r->rflush();
+ #
+ 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') {
+ if ($studentdata[$index]) {
+ 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++;
+ }
}
}
&setformulas($safeeval,%f);
@@ -2011,62 +2011,54 @@ ENDPOP
# ------------------------------------------------ Load data for one assessment
sub loadassessment {
- my $safeeval=shift;
+ my ($safeeval,$sheetdata)=@_;
- my $uhome=&getuhome($safeeval);
- my $uname=&getuname($safeeval);
- my $udom=&getudom($safeeval);
- my $symb=&getusymb($safeeval);
- my $cid=&getcid($safeeval);
- my $cnum=&getcnum($safeeval);
- my $cdom=&getcdom($safeeval);
- my $chome=&getchome($safeeval);
+ my $uhome = $sheetdata->{'uhome'};
+ my $uname = $sheetdata->{'uname'};
+ my $udom = $sheetdata->{'udom'};
+ my $symb = $sheetdata->{'usymb'};
+ my $cid = $sheetdata->{'cid'};
+ my $cnum = $sheetdata->{'cnum'};
+ my $cdom = $sheetdata->{'cdom'};
+ my $chome = $sheetdata->{'chome'};
my $namespace;
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++) {
- foreach (split(/\:/,$cachedstores{$scope.':keys:'.$symb})) {
- $returnhash{$_}=$cachedstores{$scope.':'.$symb.':'.$_};
- }
- }
-
- } else {
-#
-# restore individual
-#
-
- my $answer=&Apache::lonnet::reply(
- "restore:$udom:$uname:".
- &Apache::lonnet::escape($namespace).":".
- &Apache::lonnet::escape($symb),$uhome);
- foreach (split(/\&/,$answer)) {
- my ($name,$value)=split(/\=/,$_);
- $returnhash{&Apache::lonnet::unescape($name)}=
- &Apache::lonnet::unescape($value);
- }
- my $version;
- for ($version=1;$version<=$returnhash{'version'};$version++) {
- foreach (split(/\:/,$returnhash{$version.':keys'})) {
- $returnhash{$_}=$returnhash{$version.':'.$_};
- }
+ # 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++) {
+ foreach (split(/\:/,$cachedstores{$scope.':keys:'.$symb})) {
+ $returnhash{$_}=$cachedstores{$scope.':'.$symb.':'.$_};
+ }
+ }
+ } else {
+ #
+ # restore individual
+ #
+ my $answer=&Apache::lonnet::reply(
+ "restore:$udom:$uname:".
+ &Apache::lonnet::escape($namespace).":".
+ &Apache::lonnet::escape($symb),$uhome);
+ foreach (split(/\&/,$answer)) {
+ my ($name,$value)=split(/\=/,$_);
+ $returnhash{&Apache::lonnet::unescape($name)}=
+ &Apache::lonnet::unescape($value);
+ }
+ my $version;
+ for ($version=1;$version<=$returnhash{'version'};$version++) {
+ foreach (split(/\:/,$returnhash{$version.':keys'})) {
+ $returnhash{$_}=$returnhash{$version.':'.$_};
+ }
+ }
}
- }
-# ----------------------------- returnhash now has all stores for this resource
-
-# --------- convert all "_" to "." to be able to use libraries, multiparts, etc
-
+ # returnhash now has all stores for this resource
+ # convert all "_" to "." to be able to use libraries, multiparts, etc
my @oldkeys=keys %returnhash;
foreach (@oldkeys) {
@@ -2076,88 +2068,81 @@ sub loadassessment {
$name=~s/\_/\./g;
$returnhash{$name}=$value;
}
-
-# ---------------------------- initialize coursedata and userdata for this user
+ # initialize coursedata and userdata for this user
undef %courseopt;
undef %useropt;
my $userprefix=$uname.'_'.$udom.'_';
-
+
unless ($uhome eq 'no_host') {
-# -------------------------------------------------------------- Get coursedata
- unless
- ((time-$courserdatas{$cid.'.last_cache'})<240) {
- my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
- ':resourcedata',$chome);
- if ($reply!~/^error\:/) {
- $courserdatas{$cid}=$reply;
- $courserdatas{$cid.'.last_cache'}=time;
- }
- }
- foreach (split(/\&/,$courserdatas{$cid})) {
- my ($name,$value)=split(/\=/,$_);
- $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
- &Apache::lonnet::unescape($value);
- }
-# --------------------------------------------------- Get userdata (if present)
- unless
- ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
- my $reply=
- &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
- if ($reply!~/^error\:/) {
- $userrdatas{$uname.'___'.$udom}=$reply;
- $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
- }
- }
- foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
- my ($name,$value)=split(/\=/,$_);
- $useropt{$userprefix.&Apache::lonnet::unescape($name)}=
- &Apache::lonnet::unescape($value);
- }
+ # Get coursedata
+ unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
+ my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
+ ':resourcedata',$chome);
+ if ($reply!~/^error\:/) {
+ $courserdatas{$cid}=$reply;
+ $courserdatas{$cid.'.last_cache'}=time;
+ }
+ }
+ foreach (split(/\&/,$courserdatas{$cid})) {
+ my ($name,$value)=split(/\=/,$_);
+ $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
+ &Apache::lonnet::unescape($value);
+ }
+ # Get userdata (if present)
+ unless
+ ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
+ my $reply=
+ &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
+ if ($reply!~/^error\:/) {
+ $userrdatas{$uname.'___'.$udom}=$reply;
+ $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
+ }
+ }
+ foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
+ my ($name,$value)=split(/\=/,$_);
+ $useropt{$userprefix.&Apache::lonnet::unescape($name)}=
+ &Apache::lonnet::unescape($value);
+ }
}
-# ----------------- now courseopt, useropt initialized for this user and course
-# (used by parmval)
-
-#
-# Load keys for this assessment only
-#
+ # 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);
-
foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'keys'))) {
$thisassess{$_}=1;
}
-#
-# Load parameters
-#
- my %c=();
-
- if (tie(%parmhash,'GDBM_File',
- &getcfn($safeeval).'_parms.db',&GDBM_READER(),0640)) {
- my %f=&getformulas($safeeval);
- foreach (keys(%f)) {
- if ($_=~/^A/) {
- unless ($f{$_}=~/^[\!\~\-]/) {
- if ($f{$_}=~/^parameter/) {
- 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/\_/\./g;
- $c{$_}=$returnhash{$key};
- $c{$ckey}=$returnhash{$key};
- }
- }
+ #
+ # Load parameters
+ #
+ my %c=();
+ if (tie(%parmhash,'GDBM_File',
+ &getcfn($safeeval).'_parms.db',&GDBM_READER(),0640)) {
+ my %f=&getformulas($safeeval);
+ foreach (keys(%f)) {
+ next if ($_!~/^A/);
+ next if ($f{$_}=~/^[\!\~\-]/);
+ if ($f{$_}=~/^parameter/) {
+ if ($thisassess{$f{$_}}) {
+ my $val=&parmval($f{$_},$safeeval,$sheetdata);
+ $c{$_}=$val;
+ $c{$f{$_}}=$val;
+ }
+ } else {
+ my $key=$f{$_};
+ my $ckey=$key;
+ $key=~s/^stores\_/resource\./;
+ $key=~s/\_/\./g;
+ $c{$_}=$returnhash{$key};
+ $c{$ckey}=$returnhash{$key};
+ }
}
+ untie(%parmhash);
}
- untie(%parmhash);
- }
- &setconstants($safeeval,%c);
+ &setconstants($safeeval,%c);
}
# --------------------------------------------------------- Various form fields
@@ -2165,7 +2150,7 @@ sub loadassessment {
sub textfield {
my ($title,$name,$value)=@_;
return "\n
$title: ".
- '';
+ '';
}
sub hiddenfield {
@@ -2190,8 +2175,8 @@ sub selectbox {
#
sub updatesheet {
- my $safeeval=shift;
- my $stype=&gettype($safeeval);
+ my ($safeeval,$sheetdata)=@_;
+ my $stype=$sheetdata->{'sheettype'};
if ($stype eq 'classcalc') {
return &updateclasssheet($safeeval);
} else {
@@ -2205,14 +2190,14 @@ sub updatesheet {
#
sub loadrows {
- my ($safeeval,$r)=@_;
- my $stype=&gettype($safeeval);
+ my ($safeeval,$sheetdata,$r)=@_;
+ my $stype=$sheetdata->{'sheettype'};
if ($stype eq 'classcalc') {
- &loadcourse($safeeval,$r);
+ &loadcourse($safeeval,$sheetdata,$r);
} elsif ($stype eq 'studentcalc') {
- &loadstudent($safeeval);
+ &loadstudent($safeeval,$sheetdata);
} else {
- &loadassessment($safeeval);
+ &loadassessment($safeeval,$sheetdata);
}
}
@@ -2222,6 +2207,7 @@ sub checkthis {
my ($keyname,$time)=@_;
return ($time<$expiredates{$keyname});
}
+
sub forcedrecalc {
my ($uname,$udom,$stype,$usymb)=@_;
my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;
@@ -2253,131 +2239,121 @@ sub forcedrecalc {
#
sub exportsheet {
- my ($uname,$udom,$stype,$usymb,$fn)=@_;
- my @exportarr=();
-
- if (($usymb=~/^\_(\w+)/) && (!$fn)) {
- $fn='default_'.$1;
- }
-
-#
-# Check if cached
-#
-
- my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;
- my $found='';
-
- if ($oldsheets{$key}) {
- foreach (split(/\_\_\_\&\_\_\_/,$oldsheets{$key})) {
- my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
- if ($name eq $fn) {
- $found=$value;
- }
- }
- }
-
- unless ($found) {
- &cachedssheets($uname,$udom,&Apache::lonnet::homeserver($uname,$udom));
- if ($oldsheets{$key}) {
- foreach (split(/\_\_\_\&\_\_\_/,$oldsheets{$key})) {
+ my ($uname,$udom,$stype,$usymb,$fn)=@_;
+ my @exportarr=();
+ if (($usymb=~/^\_(\w+)/) && (!$fn)) {
+ $fn='default_'.$1;
+ }
+ #
+ # Check if cached
+ #
+ my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;
+ my $found='';
+ if ($oldsheets{$key}) {
+ foreach (split(/\_\_\_\&\_\_\_/,$oldsheets{$key})) {
my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
if ($name eq $fn) {
- $found=$value;
+ $found=$value;
}
- }
- }
- }
-#
-# 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);
- @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\:/) {
- foreach (split(/\_\_\_\&\_\_\_/,&Apache::lonnet::unescape($current))) {
- my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
- $currentlystored{$name}=$value;
- }
+ unless ($found) {
+ &cachedssheets($uname,$udom,&Apache::lonnet::homeserver($uname,$udom));
+ if ($oldsheets{$key}) {
+ foreach (split(/\_\_\_\&\_\_\_/,$oldsheets{$key})) {
+ my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
+ if ($name eq $fn) {
+ $found=$value;
+ }
+ }
+ }
}
- $currentlystored{$fn}=join('___;___',@exportarr);
-
- my $newstore='';
- foreach (keys(%currentlystored)) {
- if ($newstore) { $newstore.='___&___'; }
- $newstore.=$_.'___=___'.$currentlystored{$_};
+ #
+ # 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,$sheetdata)=&makenewsheet($uname,$udom,$stype,$usymb);
+ &readsheet($thissheet,$fn);
+ &updatesheet($thissheet,$sheetdata);
+ &loadrows($thissheet,$sheetdata);
+ &calcsheet($thissheet,$sheetdata);
+ @exportarr=&exportdata($thissheet,$sheetdata);
+ #
+ # 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:'.$sheetdata->{'udom'}.':'.
+ $sheetdata->{'uname'}.
+ ':nohist_calculatedsheets_'.
+ $ENV{'request.course.id'}.':'.
+ &Apache::lonnet::escape($key),
+ $sheetdata->{'uhome'});
+ }
+ my %currentlystored=();
+ unless ($current=~/^error\:/) {
+ foreach (split(/___&\___/,&Apache::lonnet::unescape($current))) {
+ my ($name,$value)=split(/___=___/,$_);
+ $currentlystored{$name}=$value;
+ }
+ }
+ $currentlystored{$fn}=join('___;___',@exportarr);
+ #
+ my $newstore='';
+ foreach (keys(%currentlystored)) {
+ if ($newstore) { $newstore.='___&___'; }
+ $newstore.=$_.'___=___'.$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:'.
+ $sheetdata->{'udom'}.':'.
+ $sheetdata->{'uname'}.
+ ':nohist_calculatedsheets_'.
+ $ENV{'request.course.id'}.':'.
+ &Apache::lonnet::escape($key).'='.
+ &Apache::lonnet::escape($newstore).'&'.
+ &Apache::lonnet::escape($key).'.time='.$now,
+ $sheetdata->{'uhome'});
+ }
}
- 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;
+ return @exportarr;
}
+
# ============================================================ Expiration Dates
#
# Load previously cached student spreadsheets for this course
#
-
sub expirationdates {
undef %expiredates;
my $cid=$ENV{'request.course.id'};
@@ -2454,59 +2430,45 @@ sub cachedssheets {
sub handler {
my $r=shift;
-
if ($r->header_only) {
- $r->content_type('text/html');
- $r->send_http_header;
- return OK;
- }
-
-# ---------------------------------------------------- Global directory configs
-
-$includedir=$r->dir_config('lonIncludes');
-$tmpdir=$r->dir_config('lonDaemons').'/tmp/';
-
-# ----------------------------------------------------- Needs to be in a course
-
- if ($ENV{'request.course.fn'}) {
-
-# --------------------------- Get query string for limited number of parameters
-
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['uname','udom','usymb','ufn']);
-
- if (($ENV{'form.usymb'}=~/^\_(\w+)/) && (!$ENV{'form.ufn'})) {
- $ENV{'form.ufn'}='default_'.$1;
- }
-
-# -------------------------------------- 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;
- my $adom;
-
- unless ($ENV{'form.uname'}) {
- $aname=$ENV{'user.name'};
- $adom=$ENV{'user.domain'};
- } else {
- $aname=$ENV{'form.uname'};
- $adom=$ENV{'form.udom'};
- }
-
-# ------------------------------------------------------------------- Open page
-
- $r->content_type('text/html');
- $r->header_out('Cache-control','no-cache');
- $r->header_out('Pragma','no-cache');
- $r->send_http_header;
-
-# --------------------------------------------------------------- Screen output
-
- $r->print('
LON-CAPA Spreadsheet');
- $r->print(<content_type('text/html');
+ $r->send_http_header;
+ return OK;
+ }
+ # Global directory configs
+ $includedir=$r->dir_config('lonIncludes');
+ $tmpdir=$r->dir_config('lonDaemons').'/tmp/';
+ # Needs to be in a course
+ if ($ENV{'request.course.fn'}) {
+ # Get query string for limited number of parameters
+ &Apache::loncommon::get_unprocessed_cgi
+ ($ENV{'QUERY_STRING'},['uname','udom','usymb','ufn']);
+ if (($ENV{'form.usymb'}=~/^\_(\w+)/) && (!$ENV{'form.ufn'})) {
+ $ENV{'form.ufn'}='default_'.$1;
+ }
+ # 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;
+ my $adom;
+
+ unless ($ENV{'form.uname'}) {
+ $aname=$ENV{'user.name'};
+ $adom=$ENV{'user.domain'};
+ } else {
+ $aname=$ENV{'form.uname'};
+ $adom=$ENV{'form.udom'};
+ }
+ # Open page
+ $r->content_type('text/html');
+ $r->header_out('Cache-control','no-cache');
+ $r->header_out('Pragma','no-cache');
+ $r->send_http_header;
+ # Screen output
+ $r->print('LON-CAPA Spreadsheet');
+ $r->print(<
function celledit(cn,cf) {
@@ -2532,200 +2494,164 @@ $tmpdir=$r->dir_config('lonDaemons').'/t
ENDSCRIPT
- $r->print(''.
- ''.
- '
LON-CAPA Spreadsheet
'.
- '');
- return OK;
+ # See if user can see this
+ if (($asheetdata->{'sheettype'} eq 'classcalc' ) ||
+ ($asheetdata->{'uname'} ne $ENV{'user.name'} ) ||
+ ($asheetdata->{'udom'} ne $ENV{'user.domain'})) {
+ unless (&Apache::lonnet::allowed('vgr',$asheetdata->{'cid'})) {
+ $r->print('