version 1.4, 2000/12/04 22:09:39
|
version 1.26, 2001/01/01 20:52:10
|
Line 1
|
Line 1
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# Spreadsheet/Grades Display Handler |
# Spreadsheet/Grades Display Handler |
# |
# |
# 11/11,11/15,11/27,12/04 Gerd Kortemeyer |
# 11/11,11/15,11/27,12/04,12/05,12/06,12/07, |
|
# 12/08,12/09,12/11,12/12,12/15,12/16,12/18,12/19,12/30, |
|
# 01/01/01 Gerd Kortemeyer |
|
|
package Apache::lonspreadsheet; |
package Apache::lonspreadsheet; |
|
|
Line 10 use Safe;
|
Line 12 use Safe;
|
use Safe::Hole; |
use Safe::Hole; |
use Opcode; |
use Opcode; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common :http); |
|
use GDBM_File; |
use HTML::TokeParser; |
use HTML::TokeParser; |
|
|
|
# |
|
# These cache hashes need to be independent of user, resource and course |
|
# (user and course are in the keys) |
|
# |
|
use vars qw(%spreadsheets %courserdatas %userrdatas); |
|
# |
|
# These global hashes are dependent on user, course and resource, |
|
# and need to be initialized every time when a sheet is calculated |
|
# |
|
my %courseopt; |
|
my %useropt; |
|
my %parmhash; |
|
my $csec; |
|
my $uname; |
|
my $udom; |
|
|
|
# ============================================================================= |
|
# ===================================== Implements an instance of a spreadsheet |
|
|
sub initsheet { |
sub initsheet { |
my $safeeval = new Safe; |
my $safeeval = new Safe; |
Line 30 sub initsheet {
|
Line 50 sub initsheet {
|
# f: formulas |
# f: formulas |
# t: intermediate format (variable references expanded) |
# t: intermediate format (variable references expanded) |
# v: output values |
# v: output values |
# |
# c: preloaded constants (A-column) |
|
# rl: row label |
|
|
%v=(); |
%v=(); |
%t=(); |
%t=(); |
%f=(); |
%f=(); |
|
%c=(); |
|
%rl=(); |
|
|
|
$maxrow=0; |
|
$sheettype=''; |
|
$filename=''; |
|
|
sub mask { |
sub mask { |
my ($lower,$upper)=@_; |
my ($lower,$upper)=@_; |
|
|
$lower=~/([A-Z]|\*)(\d+|\*)/; |
$lower=~/([A-Za-z]|\*)(\d+|\*)/; |
my $la=$1; |
my $la=$1; |
my $ld=$2; |
my $ld=$2; |
|
|
$upper=~/([A-Z]|\*)(\d+|\*)/; |
$upper=~/([A-Za-z]|\*)(\d+|\*)/; |
my $ua=$1; |
my $ua=$1; |
my $ud=$2; |
my $ud=$2; |
my $alpha=''; |
my $alpha=''; |
my $num=''; |
my $num=''; |
|
|
if (($la eq '*') || ($ua eq '*')) { |
if (($la eq '*') || ($ua eq '*')) { |
$alpha='[A-Z]'; |
$alpha='[A-Za-z]'; |
} else { |
} else { |
$alpha='['.$la.'-'.$ua.']'; |
if (($la=~/[A-Z]/) && ($ua=~/[A-Z]/) || |
|
($la=~/[a-z]/) && ($ua=~/[a-z]/)) { |
|
$alpha='['.$la.'-'.$ua.']'; |
|
} else { |
|
$alpha='['.$la.'-Za-'.$ua.']'; |
|
} |
} |
} |
|
|
if (($ld eq '*') || ($ud eq '*')) { |
if (($ld eq '*') || ($ud eq '*')) { |
Line 74 sub mask {
|
Line 106 sub mask {
|
} else { |
} else { |
my @lda=($ld=~m/\d/g); |
my @lda=($ld=~m/\d/g); |
my @uda=($ud=~m/\d/g); |
my @uda=($ud=~m/\d/g); |
my $i; $j=0; |
my $i; $j=0; $notdone=1; |
for ($i=0;$i<=$#lda;$i++) { |
for ($i=0;($i<=$#lda)&&($notdone);$i++) { |
if ($lda[$i]==$uda[$i]) { |
if ($lda[$i]==$uda[$i]) { |
$num.=$lda[$i]; |
$num.=$lda[$i]; |
$j=$i; |
$j=$i; |
|
} else { |
|
$notdone=0; |
} |
} |
} |
} |
if ($j<$#lda-1) { |
if ($j<$#lda-1) { |
Line 96 sub mask {
|
Line 130 sub mask {
|
} |
} |
$num.=')'; |
$num.=')'; |
} else { |
} else { |
$num.='['.$lda[$#lda].'-'.$uda[$#uda].']'; |
if ($lda[$#lda]!=$uda[$#uda]) { |
|
$num.='['.$lda[$#lda].'-'.$uda[$#uda].']'; |
|
} |
} |
} |
} |
} |
} |
} |
Line 225 sub SUMMIN {
|
Line 261 sub SUMMIN {
|
|
|
sub sett { |
sub sett { |
%t=(); |
%t=(); |
|
my $pattern=''; |
|
if ($sheettype eq 'assesscalc') { |
|
$pattern='A'; |
|
} else { |
|
$pattern='[A-Z]'; |
|
} |
|
map { |
|
if ($_=~/template\_(\w)/) { |
|
my $col=$1; |
|
unless ($col=~/^$pattern/) { |
|
map { |
|
if ($_=~/A(\d+)/) { |
|
my $trow=$1; |
|
if ($trow) { |
|
my $lb=$col.$trow; |
|
$t{$lb}=$f{'template_'.$col}; |
|
$t{$lb}=~s/\#/$trow/g; |
|
$t{$lb}=~s/\.\.+/\,/g; |
|
$t{$lb}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$v\{\'$2\'\}/g; |
|
} |
|
} |
|
} keys %f; |
|
} |
|
} |
|
} keys %f; |
map { |
map { |
if ($f{$_}) { |
if (($f{$_}) && ($_!~/template\_/)) { |
$t{$_}=$f{$_}; |
if ($_=~/^$pattern/) { |
$t{$_}=~s/\.+/\,/g; |
unless ($f{$_}=~/^\!/) { |
$t{$_}=~s/(^|[^\"\'])([A-Z]\d+)/$1\$v\{\'$2\'\}/g; |
$t{$_}=$c{$_}; |
|
} |
|
} else { |
|
$t{$_}=$f{$_}; |
|
$t{$_}=~s/\.\.+/\,/g; |
|
$t{$_}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$v\{\'$2\'\}/g; |
|
} |
} |
} |
} keys %f; |
} keys %f; |
|
$t{'A0'}=$f{'A0'}; |
|
$t{'A0'}=~s/\.\.+/\,/g; |
|
$t{'A0'}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$v\{\'$2\'\}/g; |
} |
} |
|
|
sub calc { |
sub calc { |
Line 259 sub calc {
|
Line 329 sub calc {
|
return ''; |
return ''; |
} |
} |
|
|
|
sub templaterow { |
|
my @cols=(); |
|
$cols[0]='<b><font size=+1>Template</font></b>'; |
|
map { |
|
my $fm=$f{'template_'.$_}; |
|
$fm=~s/[\'\"]/\&\#34;/g; |
|
$cols[$#cols+1]="'template_$_','$fm'".'___eq___'.$fm; |
|
} ('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'); |
|
return @cols; |
|
} |
|
|
|
sub outrowassess { |
|
my $n=shift; |
|
my @cols=(); |
|
if ($n) { |
|
$cols[0]=$rl{$f{'A'.$n}}; |
|
} else { |
|
$cols[0]='<b><font size=+1>Export</font></b>'; |
|
} |
|
map { |
|
my $fm=$f{$_.$n}; |
|
$fm=~s/[\'\"]/\&\#34;/g; |
|
$cols[$#cols+1]="'$_$n','$fm'".'___eq___'.$v{$_.$n}; |
|
} ('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'); |
|
return @cols; |
|
} |
|
|
|
sub outrow { |
|
my $n=shift; |
|
my @cols=(); |
|
if ($n) { |
|
$cols[0]=$rl{$f{'A'.$n}}; |
|
} else { |
|
$cols[0]='<b><font size=+1>Export</font></b>'; |
|
} |
|
map { |
|
my $fm=$f{$_.$n}; |
|
$fm=~s/[\'\"]/\&\#34;/g; |
|
$cols[$#cols+1]="'$_$n','$fm'".'___eq___'.$v{$_.$n}; |
|
} ('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'); |
|
return @cols; |
|
} |
|
|
|
sub exportrowa { |
|
my $rowa=''; |
|
map { |
|
$rowa.=$v{$_.'0'}."___;___"; |
|
} ('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'); |
|
$rowa=~s/\_\_\_\;\_\_\_$//; |
|
return $rowa; |
|
} |
|
|
# ------------------------------------------- End of "Inside of the safe space" |
# ------------------------------------------- End of "Inside of the safe space" |
ENDDEFS |
ENDDEFS |
$safeeval->reval($code); |
$safeeval->reval($code); |
Line 269 ENDDEFS
|
Line 401 ENDDEFS
|
|
|
sub setformulas { |
sub setformulas { |
my ($safeeval,@f)=@_; |
my ($safeeval,@f)=@_; |
$safeeval->reval('%f=(%f,'."('".join("','",@f)."'));"); |
$safeeval->reval('%f='."('".join("','",@f)."');"); |
|
} |
|
|
|
# ------------------------------------------------ Add or change formula values |
|
|
|
sub setconstants { |
|
my ($safeeval,@c)=@_; |
|
$safeeval->reval('%c='."('".join("','",@c)."');"); |
|
} |
|
|
|
# ------------------------------------------------ Add or change formula values |
|
|
|
sub setrowlabels { |
|
my ($safeeval,@rl)=@_; |
|
$safeeval->reval('%rl='."('".join("','",@rl)."');"); |
} |
} |
|
|
# ------------------------------------------------------- Calculate spreadsheet |
# ------------------------------------------------------- Calculate spreadsheet |
Line 293 sub getformulas {
|
Line 439 sub getformulas {
|
return $safeeval->reval('%f'); |
return $safeeval->reval('%f'); |
} |
} |
|
|
# ------------------------------------------------------------ Read spreadsheet |
# -------------------------------------------------------------------- Set type |
|
|
sub readf { |
sub settype { |
my $fn=shift; |
my ($safeeval,$type)=@_; |
|
$safeeval->reval('$sheettype="'.$type.'";'); |
|
} |
|
|
|
# -------------------------------------------------------------------- Get type |
|
|
|
sub gettype { |
|
my $safeeval=shift; |
|
return $safeeval->reval('$sheettype'); |
|
} |
|
# ------------------------------------------------------------------ Set maxrow |
|
|
|
sub setmaxrow { |
|
my ($safeeval,$row)=@_; |
|
$safeeval->reval('$maxrow='.$row.';'); |
|
} |
|
|
|
# ------------------------------------------------------------------ Get maxrow |
|
|
|
sub getmaxrow { |
|
my $safeeval=shift; |
|
return $safeeval->reval('$maxrow'); |
|
} |
|
|
|
# ---------------------------------------------------------------- Set filename |
|
|
|
sub setfilename { |
|
my ($safeeval,$fn)=@_; |
|
$safeeval->reval('$filename="'.$fn.'";'); |
|
} |
|
|
|
# ---------------------------------------------------------------- Get filename |
|
|
|
sub getfilename { |
|
my $safeeval=shift; |
|
return $safeeval->reval('$filename'); |
|
} |
|
|
|
# ------------------------------------------------------------- Export of A-row |
|
|
|
sub exportrow { |
|
my $safeeval=shift; |
|
return $safeeval->reval('&exportrowa()'); |
|
} |
|
|
|
# ========================================================== End of Spreadsheet |
|
# ============================================================================= |
|
|
|
|
|
# --------------------------------------------- Produce output row n from sheet |
|
|
|
sub rown { |
|
my ($safeeval,$n)=@_; |
|
my $defaultbg; |
|
my $rowdata=''; |
|
unless ($n eq '-') { |
|
$defaultbg=((($n-1)/5)==int(($n-1)/5))?'#E0E0':'#FFFF'; |
|
} else { |
|
$defaultbg='#E0FF'; |
|
} |
|
if ((($n-1)/25)==int(($n-1)/25)) { |
|
my $what='Student'; |
|
if (&gettype($safeeval) eq 'assesscalc') { |
|
$what='Item'; |
|
} elsif (&gettype($safeeval) eq 'studentcalc') { |
|
$what='Assessment'; |
|
} |
|
$rowdata.="</table>\n<br><table border=2>". |
|
'<tr><td> <td>'.$what.'</td>'; |
|
map { |
|
$rowdata.='<td>'.$_.'</td>'; |
|
} ('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'); |
|
$rowdata.='</tr>'; |
|
} |
|
$rowdata.="\n<tr><td><b><font size=+1>$n</font></b></td>"; |
|
my $showf=0; |
|
my $proc; |
|
my $maxred; |
|
if (&gettype($safeeval) eq 'assesscalc') { |
|
$proc='&outrowassess'; |
|
$maxred=1; |
|
} else { |
|
$proc='&outrow'; |
|
$maxred=26; |
|
} |
|
if ($n eq '-') { $proc='&templaterow'; $n=-1; } |
|
map { |
|
my $bgcolor=$defaultbg.((($showf-1)/5==int(($showf-1)/5))?'99':'DD'); |
|
my ($fm,$vl)=split(/\_\_\_eq\_\_\_/,$_); |
|
if ($showf==0) { $vl=$_; } |
|
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.'><a href="javascript:celledit('.$fm.');">'.$vl. |
|
'</a></td>'; |
|
} else { |
|
$rowdata.='<td bgcolor='.$bgcolor.'> '.$vl.' </td>'; |
|
} |
|
$showf++; |
|
} $safeeval->reval($proc.'('.$n.')'); |
|
return $rowdata.'</tr>'; |
|
} |
|
|
|
# ------------------------------------------------------------- Print out sheet |
|
|
|
sub outsheet { |
|
my ($r,$safeeval)=@_; |
|
my $maxred; |
|
my $realm; |
|
if (&gettype($safeeval) eq 'assesscalc') { |
|
$maxred=1; |
|
$realm='Assessment'; |
|
} elsif (&gettype($safeeval) eq 'studentcalc') { |
|
$maxred=26; |
|
$realm='User'; |
|
} else { |
|
$maxred=26; |
|
$realm='Course'; |
|
} |
|
my $maxyellow=52-$maxred; |
|
my $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='.$maxyellow. |
|
'><b><font size=+1>Calculations</font></b></td></tr><tr>'; |
|
my $showf=0; |
|
map { |
|
$showf++; |
|
if ($showf<=$maxred) { |
|
$tabledata.='<td bgcolor="#FFDDDD">'; |
|
} else { |
|
$tabledata.='<td>'; |
|
} |
|
$tabledata.="<b><font size=+1>$_</font></b></td>"; |
|
} ('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'); |
|
$tabledata.='</tr>'; |
|
my $row; |
|
my $maxrow=&getmaxrow($safeeval); |
|
$tabledata.=&rown($safeeval,'-'); |
|
$r->print($tabledata); |
|
for ($row=0;$row<=$maxrow;$row++) { |
|
$r->print(&rown($safeeval,$row)); |
|
} |
|
$r->print('</table>'); |
|
} |
|
|
|
|
|
|
|
# ------------------------------------- Read spreadsheet formulas from a course |
|
|
|
sub readsheet { |
|
my ($safeeval,$fn,$r)=@_; |
my %f=(); |
my %f=(); |
my $content; |
if (($fn eq '') || ($fn=~/^default\_/)) { |
{ |
my $sheetxml=''; |
my $fh=Apache::File->new($fn); |
{ |
$content=join('',<$fh>); |
my $fh; |
|
if ($fh=Apache::File->new($r->dir_config('lonIncludes'). |
|
'/default.'.&gettype($safeeval))) { |
|
$sheetxml=join('',<$fh>); |
|
} |
|
} |
|
my $parser=HTML::TokeParser->new(\$sheetxml); |
|
my $token; |
|
while ($token=$parser->get_token) { |
|
if ($token->[0] eq 'S') { |
|
if ($token->[1] eq 'field') { |
|
$f{$token->[2]->{'col'}.$token->[2]->{'row'}}= |
|
$parser->get_text('/field'); |
|
} |
|
if ($token->[1] eq 'template') { |
|
$f{'template_'.$token->[2]->{'col'}}= |
|
$parser->get_text('/template'); |
|
} |
|
} |
|
} |
|
&setfilename($safeeval,'default_'.&gettype($safeeval)); |
|
} else { |
|
&setfilename($safeeval,$fn); |
|
unless ($spreadsheets{$fn}) { |
|
$spreadsheets{$fn}=''; |
|
my $reply=&Apache::lonnet::reply('dump:'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':'.$fn, |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
|
unless ($reply=~/^error\:/) { |
|
$spreadsheets{$fn}=$reply; |
|
} |
|
} |
|
map { |
|
my ($name,$value)=split(/\=/,$_); |
|
$f{&Apache::lonnet::unescape($name)}= |
|
&Apache::lonnet::unescape($value); |
|
} split(/\&/,$spreadsheets{$fn}); |
} |
} |
{ |
|
my $parser=HTML::TokeParser->new(\$content); |
&setformulas($safeeval,%f); |
my $token; |
} |
while ($token=$parser->get_token) { |
|
if ($token->[0] eq 'S') { |
# ------------------------------------------------------------ Save spreadsheet |
if ($token->[1] eq 'field') { |
|
$f{$token->[2]->{'col'}.$token->[2]->{'row'}}= |
sub writesheet { |
$parser->get_text('/field'); |
my $safeeval=shift; |
} |
if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) { |
} |
my %f=&getformulas($safeeval); |
|
my $sheetdata=''; |
|
map { |
|
$sheetdata.=&Apache::lonnet::escape($_).'='. |
|
&Apache::lonnet::escape($f{$_}).'&'; |
|
} keys %f; |
|
$sheetdata=~s/\&$//; |
|
my $reply=&Apache::lonnet::reply('put:'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':'. |
|
&getfilename($safeeval).':'. |
|
$sheetdata, |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
|
if ($reply eq 'ok') { |
|
return &Apache::lonnet::reply('put:'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':'. |
|
&gettype($safeeval).'_spreadsheets:'. |
|
&Apache::lonnet::escape(&getfilename($safeeval)).'='. |
|
$ENV{'user.name'}, |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
|
} else { |
|
return $reply; |
} |
} |
|
} |
|
return 'unauthorized'; |
|
} |
|
|
|
# ----------------------------------------------- Make a temp copy of the sheet |
|
|
|
sub tmpwrite { |
|
my ($safeeval,$tmpdir,$symb)=@_; |
|
my $fn=$uname.'_'.$udom.'_spreadsheet_'.$symb.'_'.&getfilename($safeeval); |
|
$fn=~s/\W/\_/g; |
|
$fn=$tmpdir.$fn.'.tmp'; |
|
my $fh; |
|
if ($fh=Apache::File->new('>'.$fn)) { |
|
print $fh join("\n",&getformulas($safeeval)); |
|
} |
|
} |
|
|
|
# ---------------------------------------------------------- Read the temp copy |
|
|
|
sub tmpread { |
|
my ($safeeval,$tmpdir,$symb,$nfield,$nform)=@_; |
|
my $fn=$uname.'_'.$udom.'_spreadsheet_'.$symb.'_'.&getfilename($safeeval); |
|
$fn=~s/\W/\_/g; |
|
$fn=$tmpdir.$fn.'.tmp'; |
|
my $fh; |
|
my %fo=(); |
|
if ($fh=Apache::File->new($fn)) { |
|
my $name; |
|
while ($name=<$fh>) { |
|
chomp($name); |
|
my $value=<$fh>; |
|
chomp($value); |
|
$fo{$name}=$value; |
|
} |
} |
} |
|
if ($nfield) { $fo{$nfield}=$nform; } |
|
&setformulas($safeeval,%fo); |
} |
} |
|
|
# --------------------------------------------------------------- Read metadata |
# --------------------------------------------------------------- Read metadata |
Line 344 sub readmeta {
|
Line 748 sub readmeta {
|
return %returnhash; |
return %returnhash; |
} |
} |
|
|
|
# ================================================================== Parameters |
|
# -------------------------------------------- Figure out a cascading parameter |
|
|
# ----------------------------------------------------------------------------- |
sub parmval { |
|
my ($what,$symb)=@_; |
|
|
sub handler { |
unless ($symb) { return ''; } |
|
my $result=''; |
|
|
my $r=shift; |
my ($mapname,$id,$fn)=split(/\_\_\_/,$symb); |
|
# ----------------------------------------------------- Cascading lookup scheme |
|
my $rwhat=$what; |
|
$what=~s/^parameter\_//; |
|
$what=~s/\_/\./; |
|
|
|
my $symbparm=$symb.'.'.$what; |
|
my $mapparm=$mapname.'___(all).'.$what; |
|
|
|
my $seclevel= |
|
$ENV{'request.course.id'}.'.['. |
|
$csec.'].'.$what; |
|
my $seclevelr= |
|
$ENV{'request.course.id'}.'.['. |
|
$csec.'].'.$symbparm; |
|
my $seclevelm= |
|
$ENV{'request.course.id'}.'.['. |
|
$csec.'].'.$mapparm; |
|
|
|
my $courselevel= |
|
$ENV{'request.course.id'}.'.'.$what; |
|
my $courselevelr= |
|
$ENV{'request.course.id'}.'.'.$symbparm; |
|
my $courselevelm= |
|
$ENV{'request.course.id'}.'.'.$mapparm; |
|
|
|
# ---------------------------------------------------------- fourth, check user |
|
|
|
if ($uname) { |
|
|
|
if ($useropt{$courselevelr}) { return $useropt{$courselevelr}; } |
|
|
|
if ($useropt{$courselevelm}) { return $useropt{$courselevelm}; } |
|
|
|
if ($useropt{$courselevel}) { return $useropt{$courselevel}; } |
|
|
$r->content_type('text/html'); |
} |
$r->send_http_header; |
|
|
|
$r->print('<html><head><title>LON-CAPA Spreadsheet</title></head>'); |
# --------------------------------------------------------- third, check course |
$r->print('<body bgcolor="#FFFFFF">'); |
|
|
if ($csec) { |
|
|
my $sheetone=initsheet(); |
if ($courseopt{$seclevelr}) { return $courseopt{$seclevelr}; } |
|
|
&setformulas($sheetone,('A1' => '5', 'B2' => '6', 'C4' => 'A1+B2')); |
if ($courseopt{$seclevelm}) { return $courseopt{$seclevelm}; } |
$r->print(&calcsheet($sheetone)); |
|
my %output=&getformulas($sheetone); |
if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; } |
|
|
$r->print('FORM:'.$output{'A1'}.' '.$output{'B2'}.' '.$output{'C4'}); |
} |
|
|
|
if ($courseopt{$courselevelr}) { return $courseopt{$courselevelr}; } |
|
|
|
if ($courseopt{$courselevelm}) { return $courseopt{$courselevelm}; } |
|
|
|
if ($courseopt{$courselevel}) { return $courseopt{$courselevel}; } |
|
|
|
# ----------------------------------------------------- second, check map parms |
|
|
|
my $thisparm=$parmhash{$symbparm}; |
|
if ($thisparm) { return $thisparm; } |
|
|
|
# -------------------------------------------------------- first, check default |
|
|
|
return &Apache::lonnet::metadata($fn,$rwhat.'.default'); |
|
|
|
} |
|
|
|
# ---------------------------------------------- Update rows for course listing |
|
|
|
sub updatestudentrows { |
|
my $safeeval=shift; |
|
my $cid=$ENV{'request.course.id'}; |
|
my $classlst=&Apache::lonnet::reply |
|
('dump:'.$ENV{'course.'.$cid.'.domain'}.':'. |
|
$ENV{'course.'.$cid.'.num'}.':classlist', |
|
$ENV{'course.'.$cid.'.home'}); |
|
my %currentlist=(); |
|
my $now=time; |
|
unless ($classlst=~/^error\:/) { |
|
map { |
|
my ($name,$value)=split(/\=/,$_); |
|
my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value)); |
|
my $active=1; |
|
if (($end) && ($now>$end)) { $active=0; } |
|
if ($active) { |
|
my $rowlabel=''; |
|
$name=&Apache::lonnet::unescape($name); |
|
my ($cname,$cdom)=split(/\:/,$name); |
|
my $csec= |
|
&Apache::lonnet::usection($cdom,$cname,$ENV{'request.course.id'}); |
|
if ($csec==-1) { |
|
$rowlabel='<font color=red>Data not available: '.$name. |
|
'</font>'; |
|
} else { |
|
my %reply=&Apache::lonnet::idrget($cdom,$cname); |
|
my $reply=&Apache::lonnet::reply('get:'.$cdom.':'.$cname. |
|
':environment:firstname&middlename&lastname&generation', |
|
&Apache::lonnet::homeserver($cname,$cdom)); |
|
$rowlabel=$csec.' '.$reply{$cname}.'<br>'; |
|
map { |
|
$rowlabel.=&Apache::lonnet::unescape($_).' '; |
|
} split(/\&/,$reply); |
|
} |
|
|
|
$currentlist{&Apache::lonnet::unescape($name)}=$rowlabel; |
|
} |
|
} split(/\&/,$classlst); |
|
# |
|
# -------------------- Find discrepancies between the course row table and this |
|
# |
|
my %f=&getformulas($safeeval); |
|
my $changed=0; |
|
|
|
my $maxrow=0; |
|
my %existing=(); |
|
|
|
# ----------------------------------------------------------- Now obsolete rows |
|
map { |
|
if ($_=~/^A(\d+)/) { |
|
$maxrow=($1>$maxrow)?$1:$maxrow; |
|
$existing{$f{$_}}=1; |
|
unless ((defined($currentlist{$f{$_}})) || (!$1)) { |
|
$f{$_}='!!! Obsolete'; |
|
$changed=1; |
|
} |
|
} |
|
} keys %f; |
|
|
|
# -------------------------------------------------------- New and unknown keys |
|
|
|
map { |
|
unless ($existing{$_}) { |
|
$changed=1; |
|
$maxrow++; |
|
$f{'A'.$maxrow}=$_; |
|
} |
|
} sort keys %currentlist; |
|
|
|
if ($changed) { &setformulas($safeeval,%f); } |
|
|
|
&setmaxrow($safeeval,$maxrow); |
|
&setrowlabels($safeeval,%currentlist); |
|
|
|
} else { |
|
return 'Could not access course data'; |
|
} |
|
} |
|
# ----------------------------------------------------------------- Update rows |
|
|
|
sub updaterows { |
|
my $safeeval=shift; |
|
my %bighash; |
|
# -------------------------------------------------------------------- Tie hash |
|
if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db', |
|
&GDBM_READER,0640)) { |
|
# --------------------------------------------------------- Get all assessments |
|
|
|
my %allkeys=(); |
|
my %allassess=(); |
|
|
my %output=&getvalues($sheetone); |
my $stype=&gettype($safeeval); |
|
|
|
map { |
|
if ($_=~/^src\_(\d+)\.(\d+)$/) { |
|
my $mapid=$1; |
|
my $resid=$2; |
|
my $id=$mapid.'.'.$resid; |
|
my $srcf=$bighash{$_}; |
|
if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) { |
|
my $symb= |
|
&Apache::lonnet::declutter($bighash{'map_id_'.$mapid}). |
|
'___'.$resid.'___'. |
|
&Apache::lonnet::declutter($srcf); |
|
$allassess{$symb}=$bighash{'title_'.$id}; |
|
|
|
if ($stype eq 'assesscalc') { |
|
map { |
|
if (($_=~/^stores\_(.*)/) || ($_=~/^parameter\_(.*)/)) { |
|
my $key=$_; |
|
my $display= |
|
&Apache::lonnet::metadata($srcf,$key.'.display'); |
|
unless ($display) { |
|
$display= |
|
&Apache::lonnet::metadata($srcf,$key.'.name'); |
|
} |
|
$allkeys{$key}=$display; |
|
} |
|
} split(/\,/,&Apache::lonnet::metadata($srcf,'keys')); |
|
} |
|
} |
|
} |
|
} keys %bighash; |
|
untie(%bighash); |
|
|
$r->print('<br>OUT:'.$output{'A1'}.' '.$output{'B2'}.' '.$output{'C4'}); |
# |
|
# %allkeys has a list of storage and parameter displays by unikey |
|
# %allassess has a list of all resource displays by symb |
|
# |
|
# -------------------- Find discrepancies between the course row table and this |
|
# |
|
my %f=&getformulas($safeeval); |
|
my $changed=0; |
|
|
|
my %current=(); |
|
if ($stype eq 'assesscalc') { |
|
%current=%allkeys; |
|
} elsif ($stype eq 'studentcalc') { |
|
%current=%allassess; |
|
} |
|
|
|
my $maxrow=0; |
|
my %existing=(); |
|
|
|
# ----------------------------------------------------------- Now obsolete rows |
|
map { |
|
if ($_=~/^A(\d+)/) { |
|
$maxrow=($1>$maxrow)?$1:$maxrow; |
|
$existing{$f{$_}}=1; |
|
unless ((defined($current{$f{$_}})) || (!$1)) { |
|
$f{$_}='!!! Obsolete'; |
|
$changed=1; |
|
} |
|
} |
|
} keys %f; |
|
|
|
# -------------------------------------------------------- New and unknown keys |
|
|
|
map { |
|
unless ($existing{$_}) { |
|
$changed=1; |
|
$maxrow++; |
|
$f{'A'.$maxrow}=$_; |
|
} |
|
} keys %current; |
|
|
|
if ($changed) { &setformulas($safeeval,%f); } |
|
|
|
&setmaxrow($safeeval,$maxrow); |
|
&setrowlabels($safeeval,%current); |
|
|
|
} else { |
|
return 'Could not access course data'; |
|
} |
|
} |
|
|
|
# ------------------------------------------------ Load data for one assessment |
|
|
|
sub rowazstudent { |
|
my $safeeval=shift; |
|
my %c=(); |
|
my %f=&getformulas($safeeval); |
|
map { |
|
if ($_=~/^A(\d+)/) { |
|
my $row=$1; |
|
unless ($f{$_}=~/^\!/) { |
|
my @assessdata=split(/\_\_\_\;\_\_\_/, |
|
&Apache::lonnet::ssi( |
|
'/adm/assesscalc',('utarget' => 'export', |
|
'uname' => $uname, |
|
'udom' => $udom, |
|
'usymb' => $f{$_}))); |
|
my $index=0; |
|
map { |
|
if ($assessdata[$index]) { |
|
$c{$_.$row}=$assessdata[$index]; |
|
unless ($_ eq 'A') { |
|
$f{$_.$row}='import'; |
|
} |
|
} |
|
$index++; |
|
} ('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'); |
|
} |
|
} |
|
} keys %f; |
|
&setformulas($safeeval,%f); |
|
&setconstants($safeeval,%c); |
|
} |
|
|
|
# --------------------------------------------------- Load data for one student |
|
|
|
sub rowazclass { |
|
my $safeeval=shift; |
|
my %c=(); |
|
my %f=&getformulas($safeeval); |
|
map { |
|
if ($_=~/^A(\d+)/) { |
|
my $row=$1; |
|
unless ($f{$_}=~/^\!/) { |
|
my ($tname,$tdom)=split(/\:/,$_); |
|
my @assessdata=split(/\_\_\_\;\_\_\_/, |
|
&Apache::lonnet::ssi( |
|
'/adm/studentcalc',('utarget' => 'export', |
|
'uname' => $tname, |
|
'udom' => $tdom))); |
|
my $index=0; |
|
map { |
|
if ($assessdata[$index]) { |
|
$c{$_.$row}=$assessdata[$index]; |
|
unless ($_ eq 'A') { |
|
$f{$_.$row}='import'; |
|
} |
|
} |
|
$index++; |
|
} ('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'); |
|
} |
|
} |
|
} keys %f; |
|
&setformulas($safeeval,%f); |
|
&setconstants($safeeval,%c); |
|
} |
|
|
|
# ------------------------------------------------ Load data for one assessment |
|
|
|
sub rowaassess { |
|
my ($safeeval,$symb)=@_; |
|
my $uhome=&Apache::lonnet::homeserver($uname,$udom); |
|
my $namespace; |
|
unless ($namespace=$ENV{'request.course.id'}) { return ''; } |
|
|
|
# ----------------------------------------------------------- Get stored values |
|
my $answer=&Apache::lonnet::reply( |
|
"restore:$udom:$uname:". |
|
&Apache::lonnet::escape($namespace).":". |
|
&Apache::lonnet::escape($symb),$uhome); |
|
my %returnhash=(); |
|
map { |
|
my ($name,$value)=split(/\=/,$_); |
|
$returnhash{&Apache::lonnet::unescape($name)}= |
|
&Apache::lonnet::unescape($value); |
|
} split(/\&/,$answer); |
|
my $version; |
|
for ($version=1;$version<=$returnhash{'version'};$version++) { |
|
map { |
|
$returnhash{$_}=$returnhash{$version.':'.$_}; |
|
} split(/\:/,$returnhash{$version.':keys'}); |
|
} |
|
# ----------------------------- returnhash now has all stores for this resource |
|
|
|
# ---------------------------- initialize coursedata and userdata for this user |
|
%courseopt=(); |
|
%useropt=(); |
|
my $uhome=&Apache::lonnet::homeserver($uname,$udom); |
|
unless ($uhome eq 'no_host') { |
|
# -------------------------------------------------------------- Get coursedata |
|
unless |
|
((time-$courserdatas{$ENV{'request.course.id'}.'.last_cache'})<120) { |
|
my $reply=&Apache::lonnet::reply('dump:'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata', |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
|
if ($reply!~/^error\:/) { |
|
$courserdatas{$ENV{'request.course.id'}}=$reply; |
|
$courserdatas{$ENV{'request.course.id'}.'.last_cache'}=time; |
|
} |
|
} |
|
map { |
|
my ($name,$value)=split(/\=/,$_); |
|
$courseopt{&Apache::lonnet::unescape($name)}= |
|
&Apache::lonnet::unescape($value); |
|
} split(/\&/,$courserdatas{$ENV{'request.course.id'}}); |
|
# --------------------------------------------------- Get userdata (if present) |
|
unless |
|
((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<120) { |
|
my $reply= |
|
&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome); |
|
if ($reply!~/^error\:/) { |
|
$userrdatas{$uname.'___'.$udom}=$reply; |
|
$userrdatas{$uname.'___'.$udom.'.last_cache'}=time; |
|
} |
|
} |
|
map { |
|
my ($name,$value)=split(/\=/,$_); |
|
$useropt{&Apache::lonnet::unescape($name)}= |
|
&Apache::lonnet::unescape($value); |
|
} split(/\&/,$userrdatas{$uname.'___'.$udom}); |
|
} |
|
# -- now courseopt, useropt initialized for this user and course (used parmval) |
|
|
|
my %c=(); |
|
my %f=&getformulas($safeeval); |
|
map { |
|
if ($_=~/^A/) { |
|
unless ($f{$_}=~/^\!/) { |
|
if ($f{$_}=~/^parameter/) { |
|
$c{$_}=&parmval($f{$_},$symb); |
|
} else { |
|
my $key=$f{$_}; |
|
$key=~s/^stores\_/resource\./; |
|
$key=~s/\_/\./; |
|
$c{$_}=$returnhash{$key}; |
|
} |
|
} |
|
} |
|
} keys %f; |
|
|
|
&setconstants($safeeval,%c); |
|
} |
|
|
|
# --------------------------------------------------------- Various form fields |
|
|
|
sub textfield { |
|
my ($title,$name,$value)=@_; |
|
return "\n<p><b>$title:</b><br>". |
|
'<input type=text name="'.$name.'" size=80 value="'.$value.'">'; |
|
} |
|
|
|
sub hiddenfield { |
|
my ($name,$value)=@_; |
|
return "\n".'<input type=hidden name="'.$name.'" value="'.$value.'">'; |
|
} |
|
|
|
sub selectbox { |
|
my ($title,$name,$value,%options)=@_; |
|
my $selout="\n<p><b>$title:</b><br>".'<select name="'.$name.'">'; |
|
map { |
|
$selout.='<option value="'.$_.'"'; |
|
if ($_ eq $value) { $selout.=' selected'; } |
|
$selout.='>'.$options{$_}.'</option>'; |
|
} sort keys %options; |
|
return $selout.'</select>'; |
|
} |
|
|
|
# ================================================================ Main handler |
|
|
|
sub handler { |
|
my $r=shift; |
|
|
|
$uname=''; |
|
$udom=''; |
|
$csec=''; |
|
|
|
if ($r->header_only) { |
|
$r->content_type('text/html'); |
|
$r->send_http_header; |
|
return OK; |
|
} |
|
|
|
# ----------------------------------------------------- Needs to be in a course |
|
|
|
if (($ENV{'request.course.fn'}) || |
|
($ENV{'request.state'} eq 'construct')) { |
|
|
|
# --------------------------- Get query string for limited number of parameters |
|
|
|
map { |
|
my ($name, $value) = split(/=/,$_); |
|
$value =~ tr/+/ /; |
|
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; |
|
if (($name eq 'uname') || ($name eq 'udom') || |
|
($name eq 'usymb') || ($name eq 'ufn')) { |
|
unless ($ENV{'form.'.$name}) { |
|
$ENV{'form.'.$name}=$value; |
|
} |
|
} |
|
} (split(/&/,$ENV{'QUERY_STRING'})); |
|
|
|
# ------------------------------------------- Nothing there? Must be login user |
|
unless ($ENV{'form.uname'}) { |
|
$uname=$ENV{'user.name'}; |
|
$udom=$ENV{'user.domain'}; |
|
} else { |
|
$uname=$ENV{'form.uname'}; |
|
$udom=$ENV{'form.udom'}; |
|
} |
|
# ----------------------------------------------------------- Change of target? |
|
|
|
my $reroute=($ENV{'form.utarget'} eq 'export'); |
|
|
|
# ------------------------------------------------------------------- Open page |
|
|
|
$r->content_type('text/html'); |
|
$r->header_out('Cache-control','no-cache'); |
|
$r->header_out('Pragma','no-cache'); |
|
$r->send_http_header; |
|
|
|
# --------------------------------------------------------------- Screen output |
|
|
|
unless ($reroute) { |
|
$r->print('<html><head><title>LON-CAPA Spreadsheet</title>'); |
|
$r->print(<<ENDSCRIPT); |
|
<script language="JavaScript"> |
|
|
|
function celledit(cn,cf) { |
|
var cnf=prompt(cn,cf); |
|
if (cnf!=null) { |
|
document.sheet.unewfield.value=cn; |
|
document.sheet.unewformula.value=cnf; |
|
document.sheet.submit(); |
|
} |
|
} |
|
|
|
</script> |
|
ENDSCRIPT |
|
$r->print('</head><body bgcolor="#FFFFFF">'. |
|
'<img align=right src=/adm/lonIcons/lonlogos.gif>'. |
|
'<h1>LON-CAPA Spreadsheet</h1>'. |
|
'<form action="'.$r->uri.'" name=sheet method=post>'. |
|
&hiddenfield('uname',$ENV{'form.uname'}). |
|
&hiddenfield('udom',$ENV{'form.udom'}). |
|
&hiddenfield('usymb',$ENV{'form.usymb'}). |
|
&hiddenfield('unewfield',''). |
|
&hiddenfield('unewformula','')); |
|
} |
|
$r->rflush(); |
|
# ---------------------------------------- Read new sheet or modified worksheet |
|
|
|
my $sheetone=initsheet(); |
|
$r->uri=~/\/(\w+)$/; |
|
&settype($sheetone,$1); |
|
if ($ENV{'form.unewfield'}) { |
|
$r->print('<h2>Modified Workcopy</h2>'); |
|
$ENV{'form.unewformula'}=~s/\'/\"/g; |
|
$r->print('<p>New formula: '.$ENV{'form.unewfield'}.'='. |
|
$ENV{'form.unewformula'}.'<p>'); |
|
&setfilename($sheetone,$ENV{'form.ufn'}); |
|
&tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
|
$ENV{'form.usymb'}, |
|
$ENV{'form.unewfield'},$ENV{'form.unewformula'}); |
|
} elsif ($ENV{'form.saveas'}) { |
|
&setfilename($sheetone,$ENV{'form.ufn'}); |
|
&tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
|
$ENV{'form.usymb'}); |
|
} else { |
|
unless ($ENV{'form.ufn'}) { |
|
my $reply=&Apache::lonnet::reply('get:'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.num'}. |
|
':environment:spreadsheet_default_'. |
|
&gettype($sheetone), |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
|
unless (($reply=~/^error\:/) || ($reply eq '')) { |
|
$ENV{'form.ufn'}=$reply; |
|
unless ($reroute) { |
|
$r->print('<p>Using customized default spreadsheet<p>'); |
|
} |
|
} |
|
} |
|
&readsheet($sheetone,$ENV{'form.ufn'},$r); |
|
$ENV{'form.ufn'}=&getfilename($sheetone); |
|
} |
|
|
|
if (&gettype($sheetone) eq 'classcalc') { |
|
# ---------------------------------- For course view: get courselist and update |
|
&updatestudentrows($sheetone); |
|
} else { |
|
# ----------------- For assessment and student: See if all import rows uptodate |
|
|
|
if (tie(%parmhash,'GDBM_File', |
|
$ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640)) { |
|
$csec=&Apache::lonnet::usection($udom,$uname,$ENV{'request.course.id'}); |
|
if ($csec eq '-1') { |
|
$r->print('<h3><font color=red>'. |
|
"User '$uname' at domain '$udom' not a student in this course</font></h3>"); |
|
} |
|
&updaterows($sheetone); |
|
untie(%parmhash); |
|
} else { |
|
$r->print('<h3><font color=red>'. |
|
'Could not initialize import fields (not in a course)</font></h3>'); |
|
} |
|
} |
|
# ---------------------------------------------------- See if something to save |
|
if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) { |
|
my $fname=''; |
|
if ($ENV{'form.saveas'} && ($fname=$ENV{'form.newfn'})) { |
|
$fname=~s/\W/\_/g; |
|
if ($fname eq 'default') { $fname='course_default'; } |
|
$fname.='_'.&gettype($sheetone); |
|
&setfilename($sheetone,$fname); |
|
$ENV{'form.ufn'}=$fname; |
|
my $reply=&writesheet($sheetone); |
|
unless ($reroute) { |
|
$r->print('<p>Saving spreadsheet: '.$reply.'<p>'); |
|
} |
|
if ($ENV{'form.makedefufn'}) { |
|
my $reply=&Apache::lonnet::reply('put:'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.num'}. |
|
':environment:spreadsheet_default_'. |
|
&gettype($sheetone).'='. |
|
&Apache::lonnet::escape($fname), |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
|
unless ($reroute) { |
|
$r->print('<p>Making default spreadsheet: '.$reply.'<p>'); |
|
} |
|
} |
|
} |
|
} |
|
# ------------------------------------------------ Write the modified worksheet |
|
|
|
&tmpwrite($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
|
$ENV{'form.usymb'}); |
|
|
|
# ----------------------------------------------------- Print user, course, etc |
|
unless ($reroute) { |
|
if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) { |
|
my $fname=$ENV{'form.ufn'}; |
|
$fname=~s/\_[^\_]+$//; |
|
if ($fname eq 'default') { $fname='course_default'; } |
|
$r->print('<input type=submit name=saveas value="Save as ...">'. |
|
'<input type=text size=20 name=newfn value="'.$fname. |
|
'"> (make default: <input type=checkbox name="makedefufn">)<p>'); |
|
} |
|
$r->print(&hiddenfield('ufn',$ENV{'form.ufn'})); |
|
unless (&gettype($sheetone) eq 'classcalc') { |
|
$r->print('<br><b>User:</b> '.$uname.'<br><b>Domain:</b> '.$udom); |
|
} |
|
$r->print('<h1>'. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.'</h1>'); |
|
if ($csec) { |
|
$r->print('<h3>Group/Section: '.$csec.'</h3>'); |
|
} |
|
} |
|
# -------------------------------------------------------- Import and calculate |
|
|
|
if (&gettype($sheetone) eq 'assesscalc') { |
|
&rowaassess($sheetone,$ENV{'form.usymb'}); |
|
} elsif (&gettype($sheetone) eq 'studentcalc') { |
|
&rowazstudent($sheetone); |
|
} else { |
|
&rowazclass($sheetone); |
|
} |
|
my $calcoutput=&calcsheet($sheetone); |
|
unless ($reroute) { |
|
$r->print('<h3><font color=red>'.$calcoutput.'</h3></font>'); |
|
} |
|
|
$r->print('</body></html>'); |
# ------------------------------------------------------- Print or export sheet |
|
unless ($reroute) { |
|
&outsheet($r,$sheetone); |
|
|
|
$r->print('</form></body></html>'); |
|
} else { |
|
$r->print(&exportrow($sheetone)); |
|
} |
|
# ------------------------------------------------------------------------ Done |
|
} else { |
|
# ----------------------------- Not in a course, or not allowed to modify parms |
|
$ENV{'user.error.msg'}= |
|
$r->uri.":opa:0:0:Cannot modify spreadsheet"; |
|
return HTTP_NOT_ACCEPTABLE; |
|
} |
return OK; |
return OK; |
} |
} |
|
|