--- loncom/interface/Attic/lonspreadsheet.pm 2002/10/22 13:13:15 1.121 +++ loncom/interface/Attic/lonspreadsheet.pm 2002/10/30 15:07:20 1.131 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.121 2002/10/22 13:13:15 matthew Exp $ +# $Id: lonspreadsheet.pm,v 1.131 2002/10/30 15:07:20 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -122,20 +122,17 @@ my $tmpdir; ## sub mask { my ($lower,$upper)=@_; - - $lower=~/([A-Za-z]|\*)(\d+|\*)/; - my $la=$1; - my $ld=$2; - - $upper=~/([A-Za-z]|\*)(\d+|\*)/; - my $ua=$1; - my $ud=$2; + # + my ($la,$ld) = ($lower=~/([A-Za-z]|\*)(\d+|\*)/); + my ($ua,$ud) = ($upper=~/([A-Za-z]|\*)(\d+|\*)/); + # my $alpha=''; my $num=''; - + # if (($la eq '*') || ($ua eq '*')) { $alpha='[A-Za-z]'; } else { + if (($la=~/[A-Z]/) && ($ua=~/[A-Z]/) || ($la=~/[a-z]/) && ($ua=~/[a-z]/)) { $alpha='['.$la.'-'.$ua.']'; @@ -188,8 +185,8 @@ sub mask { } $num.=')'; } else { - if ($lda[$#lda]!=$uda[$#uda]) { - $num.='['.$lda[$#lda].'-'.$uda[$#uda].']'; + if ($lda[-1]!=$uda[-1]) { + $num.='['.$lda[-1].'-'.$uda[-1].']'; } } } @@ -208,7 +205,6 @@ sub initsheet { $safeeval->deny(":base_io"); $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT'); $safehole->wrap(\&Apache::lonspreadsheet::mask,$safeeval,'&mask'); - $safehole->wrap(\&Apache::lonspreadsheet::templaterow,$safeeval,'&templaterow'); $safeeval->share('$@'); my $code=<<'ENDDEFS'; # ---------------------------------------------------- Inside of the safe space @@ -238,8 +234,6 @@ undef %c; # Holds the constants for a sh # sheets, this is the A column. Used in &MINPARM, &MAXPARM, &expandnamed, # &sett, and &setconstants. There is no &getconstants. # &setconstants is called by &loadstudent, &loadcourse, &load assessment, -undef %rowlabel; # Holds the 'prefix' for each row. Set by &setrowlabels. - # &setrowlabels is called by &updateclasssheet, &updatestudentassesssheet, undef @os; # Holds the names of other spreadsheets - this is used to specify # the spreadsheets that are available for the assessment sheet. # Set by &setothersheets. &setothersheets is called by &handler. A @@ -834,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) { @@ -845,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; } @@ -945,19 +943,41 @@ sub calc { return ''; } +# ------------------------------------------- End of "Inside of the safe space" +ENDDEFS + $safeeval->reval($code); + return $safeeval; +} + +# # -# 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]='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); + } + return @cols; +} + + sub outrowassess { # $n is the current row number + my $sheet = shift; my $n=shift; - my $csv = shift; + my $csv = $ENV{'form.showcsv'}; my @cols=(); if ($n) { - my ($usy,$ufn)=split(/__&&&\__/,$f{'A'.$n}); - if ($rowlabel{$usy}) { - $cols[0]=$rowlabel{$usy}; + my ($usy,$ufn)=split(/__&&&\__/,$sheet->{'f'}->{'A'.$n}); + if ($sheet->{'rowlabel'}->{$usy}) { + $cols[0]=&format_rowlabel($sheet->{'rowlabel'}->{$usy}); if (! $csv) { $cols[0].='
'. '