[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 30 Oct 2002 15:07:20 -0000
matthew Wed Oct 30 10:07:20 2002 EDT
Modified files:
/loncom/interface lonspreadsheet.pm
Log:
Changes to &exportsheet and &writesheet.
Changed calls to lonnet::reply to lonnet::get and lonnet::put.
Fixed a bug introduced in r 1.120 (not distributed to users) which
passed a course id as a domain.
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.130 loncom/interface/lonspreadsheet.pm:1.131
--- loncom/interface/lonspreadsheet.pm:1.130 Tue Oct 29 11:04:13 2002
+++ loncom/interface/lonspreadsheet.pm Wed Oct 30 10:07:20 2002
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.130 2002/10/29 16:04:13 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.131 2002/10/30 15:07:20 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1077,6 +1077,7 @@
}
# ---------------------------------------------------------------- Get formulas
+# Return a copy of the formulas
sub getformulas {
my $sheet = shift;
return %{$sheet->{'safe'}->varglob('f')};
@@ -1454,31 +1455,19 @@
# 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;
}
@@ -2234,45 +2223,49 @@
&loadrows($newsheet);
&calcsheet($newsheet);
@exportarr=&exportdata($newsheet);
+ ##
+ ## Store now
+ ##
#
- # Store now
+ # load in the old value
#
- my $cid=$newsheet->{'cid'};
- my $current='';
- if ($stype eq 'studentcalc') {
- $current=&Apache::lonnet::reply('get:'.$sheet->{'cdom'}.':'.
- $sheet->{'cnum'}.
- ':nohist_calculatedsheets:'.
- &Apache::lonnet::escape($key),
- $sheet->{'chome'});
- } else {
- $current=&Apache::lonnet::reply('get:'.$sheet->{'udom'}.':'.
- $sheet->{'uname'}.
- ':nohist_calculatedsheets_'.
- $sheet->{'cid'}.':'.
- &Apache::lonnet::escape($key),
- $sheet->{'uhome'});
- }
my %currentlystored=();
- unless ($current=~/^error\:/) {
- foreach (split(/___&\___/,&Apache::lonnet::unescape($current))) {
- my ($name,$value)=split(/___=___/,$_);
- $currentlystored{$name}=$value;
+ if ($stype eq 'studentcalc') {
+ my @tmp = &Apache::lonnet::get('nohist_calculatedsheets',
+ [$key],
+ $sheet->{'cdom'},$sheet->{'cnum'});
+ if ($tmp[0]!~/^error/) {
+ %currentlystored = @tmp;
+ }
+ } else {
+ my @tmp = &Apache::lonnet::get('nohist_calculatedsheets_'.
+ $sheet->{'cid'},[$key],
+ $sheet->{'udom'},$sheet->{'uname'});
+ if ($tmp[0]!~/^error/) {
+ %currentlystored = @tmp;
}
}
+ #
+ # Add the new line
+ #
$currentlystored{$fn}=join('___;___',@exportarr);
#
+ # Stick everything back together
+ #
my $newstore='';
foreach (keys(%currentlystored)) {
if ($newstore) { $newstore.='___&___'; }
$newstore.=$_.'___=___'.$currentlystored{$_};
}
my $now=time;
+ #
+ # Store away the new value
+ #
if ($stype eq 'studentcalc') {
&Apache::lonnet::put('nohist_calculatedsheets',
{ $key => $newstore,
$key.time => $now },
- $sheet->{'cid'},$sheet->{'cnum'});
+ $sheet->{'cdom'},$sheet->{'cnum'});
} else {
&Apache::lonnet::put('nohist_calculatedsheets_'.$sheet->{'cid'},
{ $key => $newstore,