--- loncom/interface/Attic/lonspreadsheet.pm 2002/10/22 13:09:49 1.120 +++ loncom/interface/Attic/lonspreadsheet.pm 2002/10/22 19:47:13 1.124 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.120 2002/10/22 13:09:49 matthew Exp $ +# $Id: lonspreadsheet.pm,v 1.124 2002/10/22 19:47:13 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -208,7 +208,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 @@ -945,19 +944,42 @@ 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]='<b><font size=+1>Template</font></b>'; + 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]=$sheet->{'rowlabel'}->{$usy}; if (! $csv) { $cols[0].='<br>'. '<select name="sel_'.$n.'" onChange="changesheet('.$n.')">'. @@ -967,7 +989,7 @@ sub outrowassess { $cols[0]=''; } if (! $csv) { - foreach (@os) { + foreach (@{$sheet->{'othersheets'}}) { $cols[0].='<option name="'.$_.'"'; if ($ufn eq $_) { $cols[0].=' selected'; @@ -983,18 +1005,19 @@ sub outrowassess { '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=$f{$_.$n}; + my $fm=$sheet->{'f'}->{$_.$n}; $fm=~s/[\'\"]/\&\#34;/g; - push(@cols,"'$_$n','$fm'".'___eq___'.$sheet_values{$_.$n}); + push(@cols,"'$_$n','$fm'".'___eq___'.$sheet->{'values'}->{$_.$n}); } return @cols; } sub outrow { + my $sheet=shift; my $n=shift; my @cols=(); if ($n) { - $cols[0]=$rowlabel{$f{'A'.$n}}; + $cols[0]=$sheet->{'rowlabel'}->{$sheet->{'f'}->{'A'.$n}}; } else { $cols[0]='<b><font size=+1>Export</font></b>'; } @@ -1002,44 +1025,13 @@ sub outrow { '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=$f{$_.$n}; + my $fm=$sheet->{'f'}->{$_.$n}; $fm=~s/[\'\"]/\&\#34;/g; - push(@cols,"'$_$n','$fm'".'___eq___'.$sheet_values{$_.$n}); + push(@cols,"'$_$n','$fm'".'___eq___'.$sheet->{'values'}->{$_.$n}); } return @cols; } -sub exportrowa { - 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'}); - } - return @exportarray; -} - -sub templaterow { - my @cols=(); - $cols[0]='<b><font size=+1>Template</font></b>'; - 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=$f{'template_'.$_}; - $fm=~s/[\'\"]/\&\#34;/g; - push(@cols,"'template_$_','$fm'".'___eq___'.$fm); - } - return @cols; -} - - -# ------------------------------------------- End of "Inside of the safe space" -ENDDEFS - $safeeval->reval($code); - return $safeeval; -} - - # ------------------------------------------------ Add or change formula values sub setformulas { my ($sheet)=shift; @@ -1049,6 +1041,12 @@ sub setformulas { # ------------------------------------------------ Add or change formula values sub setconstants { my ($sheet)=shift; + my ($constants) = @_; + if (! ref($constants)) { + my %tmp = @_; + $constants = \%tmp; + } + $sheet->{'constants'} = $constants; return %{$sheet->{'safe'}->varglob('c')}=%{$sheet->{'constants'}}; } @@ -1091,10 +1089,14 @@ sub getfa { # ------------------------------------------------------------- Export of A-row sub exportdata { my $sheet=shift; - return $sheet->{'safe'}->reval('&exportrowa()'); + 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'}); + } + return @exportarray; } - # ========================================================== End of Spreadsheet # ============================================================================= @@ -1119,27 +1121,32 @@ sub rown { $rowdata.="\n".'"'.$n.'"'; } my $showf=0; - my $proc; + # + # Determine how many pink (uneditable) cells there are in this sheet. my $maxred=1; my $sheettype=$sheet->{'sheettype'}; if ($sheettype eq 'studentcalc') { - $proc='&outrowassess'; $maxred=26; - } else { - $proc='&outrow'; - } - if ($sheettype eq 'assesscalc') { + } elsif ($sheettype eq 'assesscalc') { $maxred=1; } else { $maxred=26; } - if (&getfa($sheet,$n)=~/^[\~\-]/) { $maxred=1; } + $maxred=1 if (&getfa($sheet,$n)=~/^[\~\-]/); + # + # Get the proper row + my @rowdata; if ($n eq '-') { - $proc='&templaterow'; + @rowdata = &templaterow($sheet); $n=-1; $dataflag=1; + } elsif ($sheettype eq 'studentcalc') { + @rowdata = &outrowassess($sheet,$n); + } else { + @rowdata = &outrow($sheet,$n); } - foreach ($sheet->{'safe'}->reval($proc.'('.$n.','.$ENV{'form.showcsv'}.')')) { + # + 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')) && @@ -1873,9 +1880,8 @@ sub loadstudent { $cachedassess=''; undef %cachedstores; $sheet->{'f'} = \%f; - $sheet->{'constants'} = \%c; &setformulas($sheet); - &setconstants($sheet); + &setconstants($sheet,\%c); } # --------------------------------------------------- Load data for one student @@ -1935,9 +1941,8 @@ ENDPOP } } $sheet->{'f'}=\%f; - $sheet->{'constants'}=\%c; &setformulas($sheet); - &setconstants($sheet); + &setconstants($sheet,\%c); $r->print('<script>popwin.close()</script>'); $r->rflush(); } @@ -2061,8 +2066,7 @@ sub loadassessment { } untie(%parmhash); } - $sheet->{'constants'}=\%c; - &setconstants($sheet); + &setconstants($sheet,\%c); } # --------------------------------------------------------- Various form fields