--- loncom/interface/Attic/lonspreadsheet.pm 2002/10/25 15:58:35 1.128 +++ loncom/interface/Attic/lonspreadsheet.pm 2002/10/30 15:07:20 1.131 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.128 2002/10/25 15:58:35 matthew Exp $ +# $Id: lonspreadsheet.pm,v 1.131 2002/10/30 15:07:20 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -828,8 +828,8 @@ sub expandnamed { foreach $parameter (keys(%c)) { push @matches,$parameter if ($parameter =~ /$expression/); } - if (scalar(@matches )== 0) { - return; + if (scalar(@matches) == 0) { + $returnvalue = 'unmatched parameter: '.$parameter; } elsif (scalar(@matches) == 1) { $returnvalue = '$c{\''.$matches[0].'\'}'; } elsif (scalar(@matches) > 0) { @@ -840,6 +840,10 @@ sub expandnamed { $returnvalue = '$c{\''.$_.'\'}'; } } + } else { + # 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; } @@ -1447,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; } @@ -1924,8 +1920,8 @@ ENDPOP next if ($_!~/^A(\d+)/); my $row=$1; next if (($f{$_}=~/^[\!\~\-]/) || ($row==0)); - my @studentdata=&exportsheet($sheet,split(/\:/,$f{$_}), - 'studentcalc'); + my ($sname,$sdom) = split(':',$f{$_}); + my @studentdata=&exportsheet($sheet,$sname,$sdom,'studentcalc'); undef %userrdatas; $now++; $r->print('