--- loncom/interface/Attic/lonspreadsheet.pm 2002/09/01 18:06:52 1.106
+++ loncom/interface/Attic/lonspreadsheet.pm 2002/09/30 18:03:39 1.113
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.106 2002/09/01 18:06:52 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.113 2002/09/30 18:03:39 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,16 +26,6 @@
# The LearningOnline Network with CAPA
# Spreadsheet/Grades Display Handler
#
-# 11/11,11/15,11/27,12/04,12/05,12/06,12/07,
-# 12/08,12/09,12/11,12/12,12/15,12/16,12/18,12/19,12/30,
-# 01/01/01,02/01,03/01,19/01,20/01,22/01,
-# 03/05,03/08,03/10,03/12,03/13,03/15,03/17,
-# 03/19,03/20,03/21,03/27,04/05,04/09,
-# 07/09,07/14,07/21,09/01,09/10,9/11,9/12,9/13,9/14,9/17,
-# 10/16,10/17,10/20,11/05,11/28,12/27 Gerd Kortemeyer
-# 01/14/02 Matthew
-# 02/04/02 Matthew
-
# POD required stuff:
=head1 NAME
@@ -54,7 +44,6 @@ not the grades of their peers. The spre
offering the ability to use Perl code to manipulate data, as well as many
built-in functions.
-
=head2 Functions available to user of lonspreadsheet
=over 4
@@ -73,6 +62,11 @@ use GDBM_File;
use HTML::TokeParser;
use Apache::lonhtmlcommon;
#
+# Caches for coursewide information
+#
+my %Section;
+
+#
# Caches for previously calculated spreadsheets
#
@@ -167,7 +161,7 @@ $chome= '';
$cnum = '';
$cdom = '';
$cid = '';
-$cfn = '';
+$coursefilename = '';
# symb
@@ -863,7 +857,7 @@ sub sett {
}
# Deal with the normal cells
foreach (keys(%f)) {
- if (($f{$_}) && ($_!~/template\_/)) {
+ if (exists($f{$_}) && ($_!~/template\_/)) {
my $matches=($_=~/^$pattern(\d+)/);
if (($matches) && ($1)) {
unless ($f{$_}=~/^\!/) {
@@ -1111,9 +1105,9 @@ sub getcid {
# --------------------------------------------------------- Get course filename
-sub getcfn {
+sub getcoursefilename {
my $safeeval=shift;
- return $safeeval->reval('$cfn');
+ return $safeeval->reval('$coursefilename');
}
# ----------------------------------------------------------- Get course number
@@ -1237,8 +1231,14 @@ sub rown {
if ($vl eq '') {
$vl='#';
}
- $rowdata.='
'.
- ''.$vl.' | ';
+ $rowdata.='';
+ if ($ENV{'request.role'} =~ /^st\./) {
+ $rowdata.=$vl;
+ } else {
+ $rowdata.=''.
+ $vl.'';
+ }
+ $rowdata.=' | ';
} else {
$rowdata.=' '.$vl.' | ';
}
@@ -1310,7 +1310,7 @@ sub outsheet {
push (@sortby, $safeeval->reval('$f{"A'.$row.'"}'));
push (@sortidx, $row-1);
}
- @sortidx=sort { $sortby[$a] cmp $sortby[$b]; } @sortidx;
+ @sortidx=sort { lc($sortby[$a]) cmp lc($sortby[$b]); } @sortidx;
#
# Determine the type of child spreadsheets
my $what='Student';
@@ -1393,14 +1393,14 @@ sub parse_sheet {
#
# -------------------------------------- Read spreadsheet formulas for a course
#
-
sub readsheet {
- my ($safeeval,$fn)=@_;
- my $stype = &gettype($safeeval);
- my $cnum = &getcnum($safeeval);
- my $cdom = &getcdom($safeeval);
- my $chome = &getchome($safeeval);
-
+ my ($safeeval,$sheetdata,$fn)=@_;
+ #
+ my $stype = $sheetdata->{'sheettype'};
+ my $cnum = $sheetdata->{'cnum'};
+ my $cdom = $sheetdata->{'cdom'};
+ my $chome = $sheetdata->{'chome'};
+ #
if (! defined($fn)) {
# There is no filename. Look for defaults in course and global, cache
unless ($fn=$defaultsheets{$cnum.'_'.$cdom.'_'.$stype}) {
@@ -1464,7 +1464,6 @@ sub readsheet {
}
# -------------------------------------------------------- Make new spreadsheet
-
sub makenewsheet {
my ($uname,$udom,$stype,$usymb)=@_;
my %sheetdata=();
@@ -1473,9 +1472,8 @@ sub makenewsheet {
$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{'csec'} = $Section{$uname.':'.$udom};
+ $sheetdata{'coursefilename'} = $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'};
@@ -1491,7 +1489,6 @@ sub makenewsheet {
}
# ------------------------------------------------------------ Save spreadsheet
-
sub writesheet {
my ($safeeval,$makedef)=@_;
my $cid=&getcid($safeeval);
@@ -1543,7 +1540,6 @@ sub writesheet {
# ----------------------------------------------- Make a temp copy of the sheet
# "Modified workcopy" - interactive only
#
-
sub tmpwrite {
my $safeeval=shift;
my $fn=$ENV{'user.name'}.'_'.
@@ -1558,7 +1554,6 @@ sub tmpwrite {
}
# ---------------------------------------------------------- Read the temp copy
-
sub tmpread {
my ($safeeval,$nfield,$nform)=@_;
my $fn=$ENV{'user.name'}.'_'.
@@ -1679,11 +1674,14 @@ sub parmval {
# ---------------------------------------------- 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);
+ my ($safeeval,$sheetdata) = @_;
+ my $cnum =$sheetdata->{'cnum'};
+ my $cdom =$sheetdata->{'cdom'};
+ my $cid =$sheetdata->{'cid'};
+ my $chome =$sheetdata->{'chome'};
+ #
+ %Section = ();
+
#
# Read class list and row labels
my %classlist;
@@ -1708,15 +1706,16 @@ sub updateclasssheet {
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 {
- $rowlabel='ERROR","'.$studentName.
- '","Data not available","","","';
- }
- } else {
+ $Section{$studentName.':'.$studentDomain} = $studentSection;
+# if ($studentSection==-1) {
+# unless ($ENV{'form.showcsv'}) {
+# $rowlabel='Data not available: '.
+# $studentName.'';
+# } else {
+# $rowlabel='ERROR","'.$studentName.
+# '","Data not available","","","';
+# }
+# } else {
my %reply=&Apache::lonnet::idrget($studentDomain,$studentName);
my %studentInformation=&Apache::lonnet::get
('environment',
@@ -1741,7 +1740,7 @@ sub updateclasssheet {
$studentInformation{'generation'})
).'"';
}
- }
+ # }
$currentlist{$student}=$rowlabel;
} # end of if ($active)
} # end of foreach my $student (keys(%classlist))
@@ -1783,13 +1782,17 @@ sub updateclasssheet {
# ----------------------------------- Update rows for student and assess sheets
sub updatestudentassesssheet {
- my $safeeval=shift;
+ my ($safeeval,$sheetdata) = @_;
my %bighash;
- my $stype=&gettype($safeeval);
+ my $stype=$sheetdata->{'sheettype'};
+ my $uname=$sheetdata->{'uname'};
+ my $udom =$sheetdata->{'udom'};
my %current=();
- if ($updatedata{$ENV{'request.course.fn'}.'_'.$stype}) {
+ if ($updatedata
+ {$ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom}) {
%current=split(/\_\_\_\;\_\_\_/,
- $updatedata{$ENV{'request.course.fn'}.'_'.$stype});
+ $updatedata{$ENV{'request.course.fn'}.
+ '_'.$stype.'_'.$uname.'_'.$udom});
} else {
# Tie hash
tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
@@ -1807,10 +1810,8 @@ sub updatestudentassesssheet {
'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);
+ if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})){
+ $adduserstr='&uname='.$uname.'&udom='.$udom;
}
my %allassess =
('_feedback' =>'Discussion'
);
- foreach (keys(%bighash)) {
+ while (($_,undef) = each(%bighash)) {
next if ($_!~/^src\_(\d+)\.(\d+)$/);
my $mapid=$1;
my $resid=$2;
@@ -1861,7 +1862,7 @@ sub updatestudentassesssheet {
} elsif ($stype eq 'studentcalc') {
%current=%allassess;
}
- $updatedata{$ENV{'request.course.fn'}.'_'.$stype}=
+ $updatedata{$ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom}=
join('___;___',%current);
# Get current from cache
}
@@ -1953,7 +1954,7 @@ sub loadstudent {
}
# --------------------------------------------------- Load data for one student
-
+#
sub loadcourse {
my ($safeeval,$sheetdata,$r)=@_;
my %c=();
@@ -2015,7 +2016,7 @@ ENDPOP
}
# ------------------------------------------------ Load data for one assessment
-
+#
sub loadassessment {
my ($safeeval,$sheetdata)=@_;
@@ -2047,26 +2048,20 @@ sub loadassessment {
#
# 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++) {
+ %returnhash = &Apache::lonnet::restore($symb,$namespace,$udom,$uname);
+ for (my $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
+ #
+ # This is dumb. It is also necessary :(
my @oldkeys=keys %returnhash;
-
+ #
foreach (@oldkeys) {
my $name=$_;
my $value=$returnhash{$_};
@@ -2096,15 +2091,14 @@ sub loadassessment {
&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;
- }
+ 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)}=
@@ -2126,7 +2120,7 @@ sub loadassessment {
#
my %c=();
if (tie(%parmhash,'GDBM_File',
- &getcfn($safeeval).'_parms.db',&GDBM_READER(),0640)) {
+ &getcoursefilename($safeeval).'_parms.db',&GDBM_READER(),0640)) {
my %f=&getformulas($safeeval);
foreach (keys(%f)) {
next if ($_!~/^A/);
@@ -2184,9 +2178,9 @@ sub updatesheet {
my ($safeeval,$sheetdata)=@_;
my $stype=$sheetdata->{'sheettype'};
if ($stype eq 'classcalc') {
- return &updateclasssheet($safeeval);
+ return &updateclasssheet($safeeval,$sheetdata);
} else {
- return &updatestudentassesssheet($safeeval);
+ return &updatestudentassesssheet($safeeval,$sheetdata);
}
}
@@ -2292,7 +2286,7 @@ sub exportsheet {
# Not cached
#
my ($thissheet,$sheetdata)=&makenewsheet($uname,$udom,$stype,$usymb);
- &readsheet($thissheet,$fn);
+ &readsheet($thissheet,$sheetdata,$fn);
&updatesheet($thissheet,$sheetdata);
&loadrows($thissheet,$sheetdata);
&calcsheet($thissheet,$sheetdata);
@@ -2432,10 +2426,15 @@ sub cachedssheets {
# Interactive call to screen
#
#
-
-
sub handler {
my $r=shift;
+
+ my $loaderror=&Apache::lonnet::overloaderror($r);
+ if ($loaderror) { return $loaderror; }
+ $loaderror= &Apache::lonnet::overloaderror($r,
+ $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
+ if ($loaderror) { return $loaderror; }
+
if ($r->header_only) {
$r->content_type('text/html');
$r->send_http_header;
@@ -2454,6 +2453,10 @@ sub handler {
# Get query string for limited number of parameters
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['uname','udom','usymb','ufn']);
+ if ($ENV{'request.role'} =~ /^st\./) {
+ delete $ENV{'form.unewfield'} if (exists($ENV{'form.unewfield'}));
+ delete $ENV{'form.unewformula'} if (exists($ENV{'form.unewformula'}));
+ }
if (($ENV{'form.usymb'}=~/^\_(\w+)/) && (!$ENV{'form.ufn'})) {
$ENV{'form.ufn'}='default_'.$1;
}
@@ -2480,7 +2483,8 @@ sub handler {
$r->send_http_header;
# Screen output
$r->print('LON-CAPA Spreadsheet');
- $r->print(<print(<
function celledit(cn,cf) {
@@ -2506,6 +2510,7 @@ sub handler {
ENDSCRIPT
+ }
$r->print(''.&Apache::loncommon::bodytag('Grades Spreadsheet').
'