[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Tue, 22 Oct 2002 13:29:57 -0000
matthew Tue Oct 22 09:29:57 2002 EDT
Modified files:
/loncom/interface lonspreadsheet.pm
Log:
Moved &templaterow, &outrow, and &outrowassess outside the safe space.
Rewrote part of &rown to make this work. Changed the calling structure of
&setconstants to something a little more (Perl) object-like.
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.121 loncom/interface/lonspreadsheet.pm:1.122
--- loncom/interface/lonspreadsheet.pm:1.121 Tue Oct 22 09:13:15 2002
+++ loncom/interface/lonspreadsheet.pm Tue Oct 22 09:29:57 2002
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.121 2002/10/22 13:13:15 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.122 2002/10/22 13:29:57 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -208,7 +208,6 @@
$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 @@
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 @@
$cols[0]='';
}
if (! $csv) {
- foreach (@os) {
+ foreach (@{$sheet->{'othersheets'}}) {
$cols[0].='<option name="'.$_.'"';
if ($ufn eq $_) {
$cols[0].=' selected';
@@ -983,18 +1005,19 @@
'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,35 +1025,13 @@
'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};
- $fm=~s/[\'\"]/\&\#34;/g;
- push(@cols,"'$_$n','$fm'".'___eq___'.$sheet_values{$_.$n});
- }
- return @cols;
-}
-
-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_'.$_};
+ my $fm=$sheet->{'f'}->{$_.$n};
$fm=~s/[\'\"]/\&\#34;/g;
- push(@cols,"'template_$_','$fm'".'___eq___'.$fm);
+ push(@cols,"'$_$n','$fm'".'___eq___'.$sheet->{'values'}->{$_.$n});
}
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;
@@ -1040,6 +1041,12 @@
# ------------------------------------------------ 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'}};
}
@@ -1114,27 +1121,32 @@
$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')) &&
@@ -1868,9 +1880,8 @@
$cachedassess='';
undef %cachedstores;
$sheet->{'f'} = \%f;
- $sheet->{'constants'} = \%c;
&setformulas($sheet);
- &setconstants($sheet);
+ &setconstants($sheet,\%c);
}
# --------------------------------------------------- Load data for one student
@@ -1930,9 +1941,8 @@
}
}
$sheet->{'f'}=\%f;
- $sheet->{'constants'}=\%c;
&setformulas($sheet);
- &setconstants($sheet);
+ &setconstants($sheet,\%c);
$r->print('<script>popwin.close()</script>');
$r->rflush();
}
@@ -2056,8 +2066,7 @@
}
untie(%parmhash);
}
- $sheet->{'constants'}=\%c;
- &setconstants($sheet);
+ &setconstants($sheet,\%c);
}
# --------------------------------------------------------- Various form fields