--- loncom/interface/Attic/lonspreadsheet.pm 2002/10/24 15:30:25 1.126
+++ loncom/interface/Attic/lonspreadsheet.pm 2002/10/30 15:07:20 1.131
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.126 2002/10/24 15:30:25 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.131 2002/10/30 15:07:20 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -828,9 +828,11 @@ sub expandnamed {
foreach $parameter (keys(%c)) {
push @matches,$parameter if ($parameter =~ /$expression/);
}
- if ($#matches == 0) {
+ if (scalar(@matches) == 0) {
+ $returnvalue = 'unmatched parameter: '.$parameter;
+ } elsif (scalar(@matches) == 1) {
$returnvalue = '$c{\''.$matches[0].'\'}';
- } elsif ($#matches > 0) {
+ } elsif (scalar(@matches) > 0) {
# more than one match. Look for a concise one
$returnvalue = "'non-unique parameter name : $expression'";
foreach (@matches) {
@@ -839,7 +841,9 @@ sub expandnamed {
}
}
} else {
- $returnvalue = "'bad parameter name : $expression'";
+ # There was a negative number of matches, which indicates
+ # something is wrong with reality. Better warn the user.
+ $returnvalue = 'bizzare parameter: '.$parameter;
}
return $returnvalue;
}
@@ -946,8 +950,7 @@ ENDDEFS
}
#
-# This is actually used for the student spreadsheet, not the assessment sheet
-# Do not be fooled by the name!
+#
#
sub templaterow {
my $sheet = shift;
@@ -1074,6 +1077,7 @@ sub calcsheet {
}
# ---------------------------------------------------------------- Get formulas
+# Return a copy of the formulas
sub getformulas {
my $sheet = shift;
return %{$sheet->{'safe'}->varglob('f')};
@@ -1092,7 +1096,11 @@ sub exportdata {
my @exportarray=();
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') {
- push(@exportarray,$sheet->{'values'}->{$_.'0'});
+ if (exists($sheet->{'values'}->{$_.'0'})) {
+ push(@exportarray,$sheet->{'values'}->{$_.'0'});
+ } else {
+ push(@exportarray,'');
+ }
}
return @exportarray;
}
@@ -1232,6 +1240,8 @@ sub outsheet {
# Prepare to output rows
my $row;
#
+ # Sort the rows in some manner
+ #
my @sortby=();
my @sortidx=();
for ($row=1;$row<=$sheet->{'maxrow'};$row++) {
@@ -1445,31 +1455,19 @@ sub writesheet {
# 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{$_}).'&';
- }
+ delete($f{$_}) if ($f{$_} eq 'import');
}
- $sheetdata=~s/\&$//;
- my $reply=&Apache::lonnet::reply('put:'.$cdom.':'.$cnum.':'.$fn.':'.
- $sheetdata,$chome);
+ my $reply = &Apache::lonnet::put($fn,\%f,$cdom,$cnum);
if ($reply eq 'ok') {
- $reply=&Apache::lonnet::reply('put:'.$cdom.':'.$cnum.':'.
- $stype.'_spreadsheets:'.
- &Apache::lonnet::escape($fn).
- '='.$ENV{'user.name'}.'@'.
- $ENV{'user.domain'},
- $chome);
+ $reply = &Apache::lonnet::put($stype.'_spreadsheets',
+ {$fn => $ENV{'user.name'}.'@'.$ENV{'user.domain'}},
+ $cdom,$cnum);
if ($reply eq 'ok') {
if ($makedef) {
- return &Apache::lonnet::reply('put:'.$cdom.':'.$cnum.
- ':environment:'.
- 'spreadsheet_default_'.
- $stype.'='.
- &Apache::lonnet::escape($fn),
- $chome);
+ return &Apache::lonnet::put('environment',
+ {'spreadsheet_default_'.$stype => $fn },
+ $cdom,$cnum);
}
return $reply;
}
@@ -1522,7 +1520,7 @@ sub tmpread {
}
}
if ($nform eq 'changesheet') {
- $fo{'A'.$nfield}=(split(/\_\_\&\&\&\_\_/,$fo{'A'.$nfield}))[0];
+ $fo{'A'.$nfield}=(split(/__&&&\__/,$fo{'A'.$nfield}))[0];
unless ($ENV{'form.sel_'.$nfield} eq 'Default') {
$fo{'A'.$nfield}.='__&&&__'.$ENV{'form.sel_'.$nfield};
}
@@ -1641,10 +1639,9 @@ sub format_rowlabel {
}
} elsif ($type eq 'parameter') {
if ($ENV{'form.showcsv'}) {
- $result = $labeldata =~ s/
//g;
- } else {
- $result = $labeldata;
+ $labeldata =~ s/
/ /g;
}
+ $result = $labeldata;
} else {
&Apache::lonnet::logthis("lonspreadsheet:bogus rowlabel type: $type");
}
@@ -1703,11 +1700,11 @@ sub updateclasssheet {
}
#
# New and unknown keys
- foreach (sort keys(%currentlist)) {
- unless ($existing{$_}) {
+ foreach my $student (sort keys(%currentlist)) {
+ unless ($existing{$student}) {
$changed=1;
$sheet->{'maxrow'}++;
- $f{'A'.$sheet->{'maxrow'}}=$_;
+ $f{'A'.$sheet->{'maxrow'}}=$student;
}
}
if ($changed) {
@@ -1721,45 +1718,42 @@ sub updateclasssheet {
# ----------------------------------- Update rows for student and assess sheets
sub updatestudentassesssheet {
my ($sheet) = @_;
+ #
my %bighash;
- my $stype=$sheet->{'sheettype'};
- my $uname=$sheet->{'uname'};
- my $udom =$sheet->{'udom'};
+ #
+ my $stype = $sheet->{'sheettype'};
+ my $uname = $sheet->{'uname'};
+ my $udom = $sheet->{'udom'};
$sheet->{'rowlabel'} = {};
- if ($updatedata
- {$ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom}) {
- %{$sheet->{'rowlabel'}}=split(/___;___/,
- $updatedata{$ENV{'request.course.fn'}.
- '_'.$stype.'_'.$uname.'_'.$udom});
+ my $identifier =$sheet->{'coursefilename'}.'_'.$stype.'_'.$uname.'_'.$udom;
+ if ($updatedata{$identifier}) {
+ %{$sheet->{'rowlabel'}}=split(/___;___/,$updatedata{$identifier});
} else {
# Tie hash
- tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
+ tie(%bighash,'GDBM_File',$sheet->{'coursefilename'}.'.db',
&GDBM_READER(),0640);
if (! tied(%bighash)) {
return 'Could not access course data';
}
# Get all assessments
#
- # allkeys is used in the assessment sheets to provide labels
+ # parameter_labels is used in the assessment sheets to provide labels
# for the parameters.
- my %allkeys=('timestamp' =>
- 'parameter:Timestamp of Last Transaction
timestamp',
- 'subnumber' =>
- 'parameter:Number of Submissions
subnumber',
- 'tutornumber' =>
- 'parameter:Number of Tutor Responses
tutornumber',
- 'totalpoints' =>
- 'parameter:Total Points Granted
totalpoints');
- my $adduserstr='';
- if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})){
- $adduserstr='&uname='.$uname.'&udom='.$udom;
- }
+ my %parameter_labels=
+ ('timestamp' =>
+ 'parameter:Timestamp of Last Transaction
timestamp',
+ 'subnumber' =>
+ 'parameter:Number of Submissions
subnumber',
+ 'tutornumber' =>
+ 'parameter:Number of Tutor Responses
tutornumber',
+ 'totalpoints' =>
+ 'parameter:Total Points Granted
totalpoints');
#
- # allassess holds the descriptions of all assessments
- my %allassess;
+ # assesslist holds the descriptions of all assessments
+ my %assesslist;
foreach ('Feedback','Evaluation','Tutoring','Discussion') {
my $symb = '_'.lc($_);
- $allassess{$symb} = join(':',('symb',$symb,$uname,$udom,$_));
+ $assesslist{$symb} = join(':',('symb',$symb,$uname,$udom,$_));
}
while (($_,undef) = each(%bighash)) {
next if ($_!~/^src\_(\d+)\.(\d+)$/);
@@ -1771,7 +1765,7 @@ sub updatestudentassesssheet {
my $symb=
&Apache::lonnet::declutter($bighash{'map_id_'.$mapid}).
'___'.$resid.'___'.&Apache::lonnet::declutter($srcf);
- $allassess{$symb}='symb:'.&Apache::lonnet::escape($symb).':'
+ $assesslist{$symb}='symb:'.&Apache::lonnet::escape($symb).':'
.$uname.':'.$udom.':'.$bighash{'title_'.$id};
next if ($stype ne 'assesscalc');
foreach my $key (split(/\,/,
@@ -1785,22 +1779,24 @@ sub updatestudentassesssheet {
&Apache::lonnet::metadata($srcf,$key.'.name');
}
$display.='
'.$key;
- $allkeys{$key}='parameter:'.$display;
+ $parameter_labels{$key}='parameter:'.$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
+ # %parameter_labels has a list of storage and parameter displays by
+ # unikey
+ # %assesslist has a list of all resource, by symb
#
if ($stype eq 'assesscalc') {
- $sheet->{'rowlabel'} = \%allkeys;
+ $sheet->{'rowlabel'} = \%parameter_labels;
} elsif ($stype eq 'studentcalc') {
- $sheet->{'rowlabel'} = \%allassess;
+ $sheet->{'rowlabel'} = \%assesslist;
}
- $updatedata{$ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom}=
- join('___;___',%{$sheet->{'rowlabel'}});
+ $updatedata{$sheet->{'coursefilename'}.'_'.$stype.'_'
+ .$uname.'_'.$udom}=
+ join('___;___',%{$sheet->{'rowlabel'}});
# Get current from cache
}
# Find discrepancies between the course row table and this
@@ -1867,7 +1863,7 @@ sub loadstudent {
my $row=$1;
next if (($f{$_}=~/^[\!\~\-]/) || ($row==0));
my ($usy,$ufn)=split(/__&&&\__/,$f{$_});
- @assessdata=&exportsheet($sheet->{'uname'},
+ @assessdata=&exportsheet($sheet,$sheet->{'uname'},
$sheet->{'udom'},
'assesscalc',$usy,$ufn);
my $index=0;
@@ -1924,8 +1920,8 @@ ENDPOP
next if ($_!~/^A(\d+)/);
my $row=$1;
next if (($f{$_}=~/^[\!\~\-]/) || ($row==0));
- my @studentdata=&exportsheet(split(/\:/,$f{$_}),
- 'studentcalc');
+ my ($sname,$sdom) = split(':',$f{$_});
+ my @studentdata=&exportsheet($sheet,$sname,$sdom,'studentcalc');
undef %userrdatas;
$now++;
$r->print('