--- loncom/interface/Attic/lonspreadsheet.pm 2002/10/25 15:58:35 1.128 +++ loncom/interface/Attic/lonspreadsheet.pm 2002/11/04 22:35:45 1.132 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.128 2002/10/25 15:58:35 matthew Exp $ +# $Id: lonspreadsheet.pm,v 1.132 2002/11/04 22:35:45 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -122,6 +122,7 @@ my $tmpdir; ## sub mask { my ($lower,$upper)=@_; + $upper = $lower if (! defined($upper)); # my ($la,$ld) = ($lower=~/([A-Za-z]|\*)(\d+|\*)/); my ($ua,$ud) = ($upper=~/([A-Za-z]|\*)(\d+|\*)/); @@ -130,9 +131,8 @@ sub mask { my $num=''; # if (($la eq '*') || ($ua eq '*')) { - $alpha='[A-Za-z]'; + $alpha='[A-Za-z]'; } else { - if (($la=~/[A-Z]/) && ($ua=~/[A-Z]/) || ($la=~/[a-z]/) && ($ua=~/[a-z]/)) { $alpha='['.$la.'-'.$ua.']'; @@ -194,8 +194,6 @@ sub mask { return '^'.$alpha.$num."\$"; } - - sub initsheet { my $safeeval = new Safe(shift); my $safehole = new Safe::Hole; @@ -238,6 +236,7 @@ undef @os; # Holds the names of other s # the spreadsheets that are available for the assessment sheet. # Set by &setothersheets. &setothersheets is called by &handler. A # related subroutine is &othersheets. +#$errorlog = ''; $maxrow = 0; $sheettype = ''; @@ -591,7 +590,8 @@ compute the average of the items in the #------------------------------------------------------- sub MEAN { my $mask=mask(@_); - my $sum=0; my $num=0; + my $sum=0; + my $num=0; foreach (grep /$mask/,keys(%sheet_values)) { $sum+=$sheet_values{$_}; $num++; @@ -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; } @@ -922,6 +926,7 @@ sub calc { while ($notfinished) { $notfinished=0; foreach (keys(%t)) { + #$errorlog .= "$_:".$t{$_}; my $old=$sheet_values{$_}; $sheet_values{$_}=eval $t{$_}; if ($@) { @@ -929,6 +934,7 @@ sub calc { return $_.': '.$@; } if ($sheet_values{$_} ne $old) { $notfinished=1; $lastcalc=$_; } + #$errorlog .= ":".$sheet_values{$_}."\n"; } $depth++; if ($depth>100) { @@ -946,55 +952,39 @@ 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; my @cols=(); - $cols[0]='<b><font size=+1>Template</font></b>'; + my $rowlabel = 'Template'; 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', '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') { my $fm=$sheet->{'f'}->{'template_'.$_}; $fm=~s/[\'\"]/\&\#34;/g; - push(@cols,"'template_$_','$fm'".'___eq___'.$fm); + push(@cols,{ name => 'template_'.$_, + formula => $fm, + value => $fm }); } - return @cols; + return ($rowlabel,@cols); } - sub outrowassess { # $n is the current row number - my $sheet = shift; - my $n=shift; - my $csv = $ENV{'form.showcsv'}; + my ($sheet,$n) = @_; my @cols=(); + my $rowlabel=''; if ($n) { my ($usy,$ufn)=split(/__&&&\__/,$sheet->{'f'}->{'A'.$n}); - if ($sheet->{'rowlabel'}->{$usy}) { - $cols[0]=&format_rowlabel($sheet->{'rowlabel'}->{$usy}); - if (! $csv) { - $cols[0].='<br>'. - '<select name="sel_'.$n.'" onChange="changesheet('.$n.')">'. - '<option name="default">Default</option>'; - } + if (exists($sheet->{'rowlabel'}->{$usy})) { + $rowlabel = $sheet->{'rowlabel'}->{$usy}; } else { - $cols[0]=''; - } - if (! $csv) { - foreach (@{$sheet->{'othersheets'}}) { - $cols[0].='<option name="'.$_.'"'; - if ($ufn eq $_) { - $cols[0].=' selected'; - } - $cols[0].='>'.$_.'</option>'; - } - $cols[0].='</select>'; + $rowlabel = ''; } } else { - $cols[0]='<b><font size=+1>Export</font></b>'; + $rowlabel = 'Export'; } 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', @@ -1002,19 +992,25 @@ sub outrowassess { 'n','o','p','q','r','s','t','u','v','w','x','y','z') { my $fm=$sheet->{'f'}->{$_.$n}; $fm=~s/[\'\"]/\&\#34;/g; - push(@cols,"'$_$n','$fm'".'___eq___'.$sheet->{'values'}->{$_.$n}); + push(@cols,{ name => $_.$n, + formula => $fm, + value => $sheet->{'values'}->{$_.$n}}); } - return @cols; + return ($rowlabel,@cols); } sub outrow { - my $sheet=shift; - my $n=shift; + my ($sheet,$n)=@_; my @cols=(); + my $rowlabel; if ($n) { - $cols[0]=&format_rowlabel($sheet->{'rowlabel'}->{$sheet->{'f'}->{'A'.$n}}); + $rowlabel = $sheet->{'rowlabel'}->{$sheet->{'f'}->{'A'.$n}}; } else { - $cols[0]='<b><font size=+1>Export</font></b>'; + if ($sheet->{'sheettype'} eq 'classcalc') { + $rowlabel = 'Summary'; + } else { + $rowlabel = 'Export'; + } } 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', @@ -1022,9 +1018,11 @@ sub outrow { 'n','o','p','q','r','s','t','u','v','w','x','y','z') { my $fm=$sheet->{'f'}->{$_.$n}; $fm=~s/[\'\"]/\&\#34;/g; - push(@cols,"'$_$n','$fm'".'___eq___'.$sheet->{'values'}->{$_.$n}); + push(@cols,{ name => $_.$n, + formula => $fm, + value => $sheet->{'values'}->{$_.$n}}); } - return @cols; + return ($rowlabel,@cols); } # ------------------------------------------------ Add or change formula values @@ -1074,11 +1072,17 @@ sub calcsheet { } # ---------------------------------------------------------------- Get formulas +# Return a copy of the formulas sub getformulas { my $sheet = shift; return %{$sheet->{'safe'}->varglob('f')}; } +sub geterrorlog { + my $sheet = shift; + return ${$sheet->{'safe'}->varglob('errorlog')}; +} + # ----------------------------------------------------- Get value of $f{'A'.$n} sub getfa { my $sheet = shift; @@ -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; } @@ -1105,176 +1113,273 @@ sub exportdata { # # --------------------------------------------- Produce output row n from sheet -sub rown { - my ($sheet,$n)=@_; - my $defaultbg; - my $rowdata=''; - my $dataflag=0; - unless ($n eq '-') { - $defaultbg=((($n-1)/5)==int(($n-1)/5))?'#E0E0':'#FFFF'; - } else { - $defaultbg='#E0FF'; - } - unless ($ENV{'form.showcsv'}) { - $rowdata.="\n<tr><td><b><font size=+1>$n</font></b></td>"; - } else { - $rowdata.="\n".'"'.$n.'"'; - } - my $showf=0; - # - # Determine how many pink (uneditable) cells there are in this sheet. - my $maxred=1; - my $sheettype=$sheet->{'sheettype'}; - if ($sheettype eq 'studentcalc') { - $maxred=26; - } elsif ($sheettype eq 'assesscalc') { - $maxred=1; - } else { - $maxred=26; - } - $maxred=1 if (&getfa($sheet,$n)=~/^[\~\-]/); - # - # Get the proper row - my @rowdata; +sub get_row { + my ($sheet,$n) = @_; + my ($rowlabel,@rowdata); if ($n eq '-') { - @rowdata = &templaterow($sheet); - $n=-1; - $dataflag=1; - } elsif ($sheettype eq 'studentcalc') { - @rowdata = &outrowassess($sheet,$n); - } else { - @rowdata = &outrow($sheet,$n); - } - # - foreach (@rowdata) { - my $bgcolor=$defaultbg.((($showf-1)/5==int(($showf-1)/5))?'99':'DD'); - my ($fm,$vl)=split(/\_\_\_eq\_\_\_/,$_); - if ((($vl ne '') || ($vl eq '0')) && - (($showf==1) || ($sheettype ne 'studentcalc'))) { $dataflag=1; } - if ($showf==0) { $vl=$_; } - unless ($ENV{'form.showcsv'}) { - if ($showf<=$maxred) { $bgcolor='#FFDDDD'; } - if (($n==0) && ($showf<=26)) { $bgcolor='#CCCCFF'; } - if (($showf>$maxred) || ((!$n) && ($showf>0))) { - if ($vl eq '') { - $vl='<font size=+2 color='.$bgcolor.'>#</font>'; - } - $rowdata.='<td bgcolor='.$bgcolor.'>'; - if ($ENV{'request.role'} =~ /^st\./) { - $rowdata.=$vl; - } else { - $rowdata.='<a href="javascript:celledit('.$fm.');">'. - $vl.'</a>'; - } - $rowdata.='</td>'; - } else { - $rowdata.='<td bgcolor='.$bgcolor.'> '.$vl.' </td>'; - } - } else { - $rowdata.=',"'.$vl.'"'; - } - $showf++; - } # End of foreach($safeval...) - if ($ENV{'form.showall'} || ($dataflag)) { - return $rowdata.($ENV{'form.showcsv'}?'':'</tr>'); + ($rowlabel,@rowdata) = &templaterow($sheet); + } elsif ($sheet->{'sheettype'} eq 'studentcalc') { + ($rowlabel,@rowdata) = &outrowassess($sheet,$n); } else { - return ''; + ($rowlabel,@rowdata) = &outrow($sheet,$n); } + return ($rowlabel,@rowdata); } -# ------------------------------------------------------------- Print out sheet - -sub outsheet { - my ($r,$sheet)=@_; - my $maxred = 26; # The maximum number of cells to show as - # red (uneditable) - # To make student sheets uneditable could we - # set $maxred = 52? - # - my $realm='Course'; # 'assessment', 'user', or 'course' sheet - if ($sheet->{'sheettype'} eq 'assesscalc') { - $maxred=1; - $realm='Assessment'; - } elsif ($sheet->{'sheettype'} eq 'studentcalc') { - $maxred=26; - $realm='User'; - } - # - # Column label - my $tabledata; - if ($ENV{'form.showcsv'}) { - $tabledata='<pre>'; - } else { - $tabledata='<table border=2><tr><th colspan=2 rowspan=2>'. - '<font size=+2>'.$realm.'</font></th>'. - '<td bgcolor=#FFDDDD colspan='.$maxred. - '><b><font size=+1>Import</font></b></td>'. - '<td colspan='.(52-$maxred). - '><b><font size=+1>Calculations</font></b></td></tr><tr>'; - my $showf=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', - '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') { - $showf++; - if ($showf<=$maxred) { - $tabledata.='<td bgcolor="#FFDDDD">'; - } else { - $tabledata.='<td>'; - } - $tabledata.="<b><font size=+1>$_</font></b></td>"; - } - $tabledata.='</tr>'.&rown($sheet,'-'). - &rown($sheet,0); - } - $r->print($tabledata); - # - # Prepare to output rows - my $row; +######################################################################## +######################################################################## +sub sort_indicies { + my $sheet = shift; # # Sort the rows in some manner # my @sortby=(); my @sortidx=(); - for ($row=1;$row<=$sheet->{'maxrow'};$row++) { + for (my $row=1;$row<=$sheet->{'maxrow'};$row++) { push (@sortby, $sheet->{'safe'}->reval('$f{"A'.$row.'"}')); - push (@sortidx, $row-1); + push (@sortidx, $row); } @sortidx=sort { lc($sortby[$a]) cmp lc($sortby[$b]); } @sortidx; + return @sortidx; +} + +######################################################################## +######################################################################## + +sub html_editable_cell { + my ($cell,$bgcolor) = @_; + my $result; +# if (defined($cell)) { +# &Apache::lonnet::logthis("cell ".$cell->{'name'}. +# " = ".$cell->{'value'}. +# " : ".$cell->{'formula'}); +# } + my ($name,$formula,$value); + if (defined($cell)) { + $name = $cell->{'name'}; + $formula = $cell->{'formula'}; + $value = $cell->{'value'}; + } + $name = '' if (! defined($name)); + $formula = '' if (! defined($formula)); + if (! defined($value)) { + $value = '<font color="'.$bgcolor.'">#</font>'; + if ($formula ne '') { + $value = '<i>undefined value</i>'; + } + } # - # Determine the type of child spreadsheets - my $what='Student'; + $result .= '<a href="javascript:celledit(\''. + $name.'\',\''.$formula.'\');">'.$value.'</a>'; + return $result; +} + +sub html_uneditable_cell { + my ($cell,$bgcolor) = @_; + my $value = (defined($cell) ? $cell->{'value'} : ''); + return ' '.$value.' '; +} + +######################################################################## +######################################################################## + +sub outsheet_html { + my ($sheet,$r) = @_; + my ($num_uneditable,$realm,$row_type); if ($sheet->{'sheettype'} eq 'assesscalc') { - $what='Item'; + $num_uneditable = 1; + $realm = 'Assessment'; + $row_type = 'Item'; } elsif ($sheet->{'sheettype'} eq 'studentcalc') { - $what='Assessment'; + $num_uneditable = 26; + $realm = 'User'; + $row_type = 'Assessment'; + } elsif ($sheet->{'sheettype'} eq 'classcalc') { + $num_uneditable = 26; + $realm = 'Course'; + $row_type = 'Student'; + } else { + return; # error + } + #################################### + # Print out header table + #################################### + my $num_left = 52-$num_uneditable; + my $tabledata =<<"END"; +<table border="2"> +<tr> + <th colspan="1" rowspan="2"><font size="+2">$realm</font></th> + <td bgcolor="#FFDDDD" colspan="$num_uneditable"> + <b><font size="+1">Import</font></b></td> + <td colspan="$num_left"> + <b><font size="+1">Calculations</font></b></td> +</tr><tr> +END + my $label_num = 0; + foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ + if ($label_num<$num_uneditable) { + $tabledata.='<td bgcolor="#FFDDDD">'; + } else { + $tabledata.='<td>'; + } + $tabledata.="<b><font size=+1>$_</font></b></td>"; + $label_num++; } + $tabledata.="</tr>\n"; + $r->print($tabledata); + #################################### + # Print out template row + #################################### + my ($rowlabel,@rowdata) = &get_row($sheet,'-'); + my $row_html = '<tr><td>'.&format_rowlabel($rowlabel).'</td>'; + my $num_cols_output = 0; + foreach my $cell (@rowdata) { + if ($num_cols_output++ < $num_uneditable) { + $row_html .= '<td bgcolor="#FFDDDD">'; + $row_html .= &html_uneditable_cell($cell,'#FFDDDD'); + } else { + $row_html .= '<td bgcolor="#EOFFDD">'; + $row_html .= &html_editable_cell($cell,'#E0FFDD'); + } + $row_html .= '</td>'; + } + $row_html.= "</tr>\n"; + $r->print($row_html); + #################################### + # Print out summary/export row + #################################### + my ($rowlabel,@rowdata) = &get_row($sheet,'0'); + my $rowcount = 0; + $row_html = '<tr><td>'.&format_rowlabel($rowlabel).'</td>'; + $num_cols_output = 0; + foreach my $cell (@rowdata) { + if ($num_cols_output++ < 26) { + $row_html .= '<td bgcolor="#CCCCFF">'; + $row_html .= &html_editable_cell($cell,'#CCCCFF'); + } else { + $row_html .= '<td bgcolor="#DDCCFF">'; + $row_html .= &html_uneditable_cell(undef,'#CCCCFF'); + } + $row_html .= '</td>'; + } + $row_html.= "</tr>\n"; + $r->print($row_html); + $r->print('</table>'); + #################################### + # Prepare to output rows + #################################### + my @Rows = &sort_indicies($sheet); # # Loop through the rows and output them one at a time - my $n=0; - for ($row=0;$row<$sheet->{'maxrow'};$row++) { - my $thisrow=&rown($sheet,$sortidx[$row]+1); - if ($thisrow) { - if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) { + my $rows_output=0; + foreach my $rownum (@Rows) { + my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); + # + my $defaultbg='#E0FF'; + # + my $row_html ="\n".'<tr><td><b><font size=+1>'.$rownum. + '</font></b></td>'; + # + if ($sheet->{'sheettype'} eq 'classcalc') { + $row_html.='<td>'.&format_rowlabel($rowlabel).'</td>'; + # Output links for each student? + # Nope, that is already done for us in format_rowlabel (for now) + } elsif ($sheet->{'sheettype'} eq 'studentcalc') { + $row_html.='<td>'.&format_rowlabel($rowlabel); + $row_html.= '<br>'. + '<select name="sel_'.$rownum.'" '. + 'onChange="changesheet('.$rownum.')">'. + '<option name="default">Default</option>'; + foreach (@{$sheet->{'othersheets'}}) { + $row_html.='<option name="'.$_.'"'; + #if ($ufn eq $_) { + # $row_html.=' selected'; + #} + $row_html.='>'.$_.'</option>'; + } + $row_html.='</select></td>'; + } elsif ($sheet->{'sheettype'} eq 'assesscalc') { + $row_html.='<td>'.&format_rowlabel($rowlabel).'</td>'; + } + # + my $shown_cells = 0; + foreach my $cell (@rowdata) { + my $value = $cell->{'value'}; + my $formula = $cell->{'formula'}; + my $cellname = $cell->{'name'}; + # + my $bgcolor; + if ($shown_cells && ($shown_cells/5 == int($shown_cells/5))) { + $bgcolor = $defaultbg.'99'; + } else { + $bgcolor = $defaultbg.'DD'; + } + $bgcolor='#FFDDDD' if ($shown_cells < $num_uneditable); + # + $row_html.='<td bgcolor='.$bgcolor.'>'; + if ($shown_cells < $num_uneditable) { + $row_html .= &html_uneditable_cell($cell,$bgcolor); + } else { + $row_html .= &html_editable_cell($cell,$bgcolor); + } + $row_html.='</td>'; + $shown_cells++; + } + if ($row_html) { + if ($rows_output % 25 == 0) { $r->print("</table>\n<br>\n"); $r->rflush(); - $r->print('<table border=2><tr><td> <td>'.$what.'</td>'); - $r->print('<td>'. + $r->print('<table border=2>'. + '<tr><td> <td>'.$row_type.'</td>'. + '<td>'. join('</td><td>', (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. 'abcdefghijklmnopqrstuvwxyz'))). "</td></tr>\n"); } - $n++; - $r->print($thisrow); + $rows_output++; + $r->print($row_html); } } - $r->print($ENV{'form.showcsv'}?'</pre>':'</table>'); + # + $r->print('</table>'); + # + # Debugging code (be sure to uncomment errorlog code in safe space): + # + # $r->print("\n<pre>"); + # $r->print(&geterrorlog($sheet)); + # $r->print("\n</pre>"); + return 1; } -# -# ----------------------------------------------- Read list of available sheets -# +sub outsheet_csv { + my ($sheet,$r) = @_; +} + +sub outsheet_excel { + my ($sheet,$r) = @_; +} + +sub outsheet_xml { + my ($sheet,$r) = @_; +} + +sub outsheet { + my ($r,$sheet)=@_; + &outsheet_html($sheet,$r); +# if (exists($ENV{'form.csv'})) { +# &outsheet_csv($sheet,$r); +# } elsif (exists($ENV{'form.excel'})) { +# &outsheet_excel($sheet,$r); +# } elsif (exists($ENV{'form.xml'})) { +# &outsheet_xml($sheet,$r); +# } else { +# &outsheet_html($sheet,$r); +# } +} + +######################################################################## +######################################################################## sub othersheets { my ($sheet,$stype)=@_; $stype = $sheet->{'sheettype'} if (! defined($stype)); @@ -1292,7 +1397,6 @@ sub othersheets { return @alternatives; } - # # -------------------------------------- Parse a spreadsheet # @@ -1447,31 +1551,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; } @@ -1620,6 +1712,7 @@ sub parmval { sub format_rowlabel { my $rowlabel = shift; + return '' if ($rowlabel eq ''); my ($type,$labeldata) = split(':',$rowlabel,2); my $result = ''; if ($type eq 'symb') { @@ -1647,7 +1740,11 @@ sub format_rowlabel { } $result = $labeldata; } else { - &Apache::lonnet::logthis("lonspreadsheet:bogus rowlabel type: $type"); + if ($ENV{'form.showcsv'}) { + $result = $rowlabel; + } else { + $result = '<b><font size=+1>'.$rowlabel.'</font></b>'; + } } return $result; } @@ -1924,8 +2021,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('<script>popwin.document.popremain.remaining.value="'. @@ -1936,7 +2033,7 @@ ENDPOP 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]) { + if (defined($studentdata[$index])) { my $col=$_; if ($studentdata[$index]=~/\D/) { $c{$col.$row}="'".$studentdata[$index]."'"; @@ -1946,8 +2043,8 @@ ENDPOP unless ($col eq 'A') { $f{$col.$row}='import'; } - $index++; - } + } + $index++; } } $sheet->{'f'}=\%f; @@ -2177,7 +2274,8 @@ sub exportsheet { $udom = $udom || $sheet->{'udom'}; $stype = $stype || $sheet->{'sheettype'}; my @exportarr=(); - if (defined($usymb) && ($usymb=~/^\_(\w+)/) && (!$fn)) { + if (defined($usymb) && ($usymb=~/^\_(\w+)/) && + (!defined($fn) || $fn eq '')) { $fn='default_'.$1; } # @@ -2228,45 +2326,49 @@ sub exportsheet { &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,