version 1.8, 2000/12/07 22:51:29
|
version 1.20, 2000/12/30 17:13:54
|
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,12/05,12/06,12/07 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 Gerd Kortemeyer |
|
|
package Apache::lonspreadsheet; |
package Apache::lonspreadsheet; |
|
|
Line 11 use Safe::Hole;
|
Line 12 use Safe::Hole;
|
use Opcode; |
use Opcode; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::Constants qw(:common :http); |
use Apache::Constants qw(:common :http); |
use HTML::TokeParser; |
|
use GDBM_File; |
use GDBM_File; |
|
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 |
# ===================================== Implements an instance of a spreadsheet |
Line 243 sub SUMMIN {
|
Line 260 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\_/)) { |
if ($_=~/^A/) { |
if ($_=~/^$pattern/) { |
unless ($f{$_}=~/^\!/) { |
unless ($f{$_}=~/^\!/) { |
$t{$_}=$c{$_}; |
$t{$_}=$c{$_}; |
} |
} |
Line 256 sub sett {
|
Line 298 sub sett {
|
} |
} |
} |
} |
} 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 283 sub calc {
|
Line 328 sub calc {
|
return ''; |
return ''; |
} |
} |
|
|
sub outrow { |
sub outrowassess { |
my $n=shift; |
my $n=shift; |
my @cols=(); |
my @cols=(); |
if ($n) { |
if ($n) { |
Line 302 sub outrow {
|
Line 347 sub outrow {
|
return @cols; |
return @cols; |
} |
} |
|
|
|
sub outrow { |
|
my $n=shift; |
|
my @cols=(); |
|
if ($n) { |
|
$cols[0]=$rl{$f{'A'.$n}}.' stuff'; |
|
} 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 354 sub getformulas {
|
Line 428 sub getformulas {
|
|
|
sub settype { |
sub settype { |
my ($safeeval,$type)=@_; |
my ($safeeval,$type)=@_; |
$safeeval->reval('$sheettype='.$type.';'); |
$safeeval->reval('$sheettype="'.$type.'";'); |
} |
} |
|
|
# -------------------------------------------------------------------- Get type |
# -------------------------------------------------------------------- Get type |
Line 381 sub getmaxrow {
|
Line 455 sub getmaxrow {
|
|
|
sub setfilename { |
sub setfilename { |
my ($safeeval,$fn)=@_; |
my ($safeeval,$fn)=@_; |
$safeeval->reval('$filename='.$fn.';'); |
$safeeval->reval('$filename="'.$fn.'";'); |
} |
} |
|
|
# ---------------------------------------------------------------- Get filename |
# ---------------------------------------------------------------- Get filename |
Line 390 sub getfilename {
|
Line 464 sub getfilename {
|
my $safeeval=shift; |
my $safeeval=shift; |
return $safeeval->reval('$filename'); |
return $safeeval->reval('$filename'); |
} |
} |
|
|
|
# ------------------------------------------------------------- Export of A-row |
|
|
|
sub exportrow { |
|
my $safeeval=shift; |
|
return $safeeval->reval('&exportrowa()'); |
|
} |
|
|
# ========================================================== End of Spreadsheet |
# ========================================================== End of Spreadsheet |
# ============================================================================= |
# ============================================================================= |
|
|
Line 399 sub getfilename {
|
Line 480 sub getfilename {
|
|
|
sub rown { |
sub rown { |
my ($safeeval,$n)=@_; |
my ($safeeval,$n)=@_; |
|
my $defaultbg=((($n-1)/5)==int(($n-1)/5))?'#E0E0':'#FFFF'; |
my $rowdata="\n<tr><td><b><font size=+1>$n</font></b></td>"; |
my $rowdata="\n<tr><td><b><font size=+1>$n</font></b></td>"; |
my $showf=0; |
my $showf=0; |
|
my $proc; |
|
my $maxred; |
|
if (&gettype($safeeval) eq 'assesscalc') { |
|
$proc='&outrowassess'; |
|
$maxred=1; |
|
} else { |
|
$proc='&outrow'; |
|
$maxred=26; |
|
} |
map { |
map { |
|
my $bgcolor=$defaultbg.((($showf-1)/5==int(($showf-1)/5))?'99':'DD'); |
my ($fm,$vl)=split(/\_\_\_eq\_\_\_/,$_); |
my ($fm,$vl)=split(/\_\_\_eq\_\_\_/,$_); |
if ($showf==0) { $vl=$_; } |
if ($showf==0) { $vl=$_; } |
if ($showf>1) { |
if ($showf<=$maxred) { $bgcolor='#FFDDDD'; } |
|
if (($n==0) && ($showf<=26)) { $bgcolor='#CCCCFF'; } |
|
if (($showf>$maxred) || ((!$n) && ($showf>0))) { |
if ($vl eq '') { |
if ($vl eq '') { |
$vl='<font size=+2 color=white>#</font>'; |
$vl='<font size=+2 color='.$bgcolor.'>#</font>'; |
} |
} |
$rowdata.= |
$rowdata.= |
'<td><a href="javascript:prompt('.$fm.');">'.$vl. |
'<td bgcolor='.$bgcolor.'><a href="javascript:celledit('.$fm.');">'.$vl. |
'</a></td>'; |
'</a></td>'; |
} else { |
} else { |
$rowdata.='<td> '.$vl.' </td>'; |
$rowdata.='<td bgcolor='.$bgcolor.'> '.$vl.' </td>'; |
} |
} |
$showf++; |
$showf++; |
} $safeeval->reval('&outrow('.$n.')'); |
} $safeeval->reval($proc.'('.$n.')'); |
return $rowdata.'</tr>'; |
return $rowdata.'</tr>'; |
} |
} |
|
|
Line 423 sub rown {
|
Line 517 sub rown {
|
|
|
sub outsheet { |
sub outsheet { |
my $safeeval=shift; |
my $safeeval=shift; |
my $tabledata='<table border=2><tr><td colspan=2> </td>'; |
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 { |
map { |
$tabledata.="<td><b><font size=+1>$_</font></b></td>"; |
$showf++; |
} ('A<br>Import','B','C','D','E','F','G','H','I','J','K','L','M', |
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', |
'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', |
'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'); |
'n','o','p','q','r','s','t','u','v','w','x','y','z'); |
Line 441 sub outsheet {
|
Line 560 sub outsheet {
|
|
|
|
|
|
|
# --------------------------------------- Read spreadsheet formulas from a file |
# ------------------------------------- Read spreadsheet formulas from a course |
|
|
sub readsheet { |
sub readsheet { |
my ($safeeval,$fn)=@_; |
my ($safeeval,$fn,$r)=@_; |
&setfilename($safeeval,$fn); |
|
$fn=~/\.(\w+)/; |
|
&settype($safeeval,$1); |
|
my %f=(); |
my %f=(); |
my $content=''; |
unless ($fn) { |
{ |
my $sheetxml=''; |
my $fh; |
{ |
if ($fh=Apache::File->new($fn)) { |
my $fh; |
$content=join('',<$fh>); |
if ($fh=Apache::File->new($r->dir_config('lonIncludes'). |
} |
'/default.'.&gettype($safeeval))) { |
} |
$sheetxml=join('',<$fh>); |
{ |
} |
my $parser=HTML::TokeParser->new(\$content); |
} |
my $token; |
my $parser=HTML::TokeParser->new(\$sheetxml); |
while ($token=$parser->get_token) { |
my $token; |
if ($token->[0] eq 'S') { |
while ($token=$parser->get_token) { |
if ($token->[1] eq 'field') { |
if ($token->[0] eq 'S') { |
$f{$token->[2]->{'col'}.$token->[2]->{'row'}}= |
if ($token->[1] eq 'field') { |
$parser->get_text('/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}); |
} |
} |
|
|
&setformulas($safeeval,%f); |
&setformulas($safeeval,%f); |
} |
} |
|
|
|
# ------------------------------------------------------------ Save spreadsheet |
|
|
|
sub writesheet { |
|
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'}); |
|
} |
|
} |
|
|
|
# ----------------------------------------------- Make a temp copy of the sheet |
|
|
|
sub tmpwrite { |
|
my ($safeeval,$tmpdir,$symb)=@_; |
|
my $fn=$uname.'_'.$udom.'_spreadsheet_'.&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_'.&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; |
|
} |
|
} |
|
$fo{$nfield}=$nform; |
|
&setformulas($safeeval,%fo); |
|
} |
|
|
# --------------------------------------------------------------- Read metadata |
# --------------------------------------------------------------- Read metadata |
|
|
sub readmeta { |
sub readmeta { |
Line 498 sub readmeta {
|
Line 694 sub readmeta {
|
return %returnhash; |
return %returnhash; |
} |
} |
|
|
|
# ================================================================== Parameters |
|
# -------------------------------------------- Figure out a cascading parameter |
|
|
|
sub parmval { |
|
my ($what,$symb)=@_; |
|
|
|
unless ($symb) { return ''; } |
|
my $result=''; |
|
|
|
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}; } |
|
|
|
} |
|
|
|
# --------------------------------------------------------- third, check course |
|
|
|
if ($csec) { |
|
|
|
if ($courseopt{$seclevelr}) { return $courseopt{$seclevelr}; } |
|
|
|
if ($courseopt{$seclevelm}) { return $courseopt{$seclevelm}; } |
|
|
|
if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; } |
|
|
|
} |
|
|
|
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 |
# ----------------------------------------------------------------- Update rows |
|
|
sub updaterows { |
sub updaterows { |
Line 528 sub updaterows {
|
Line 801 sub updaterows {
|
|
|
if ($stype eq 'assesscalc') { |
if ($stype eq 'assesscalc') { |
map { |
map { |
if ($_=~/^stores\_(.*)/) { |
if (($_=~/^stores\_(.*)/) || ($_=~/^parameter\_(.*)/)) { |
my $key=$_; |
my $key=$_; |
my $display= |
my $display= |
&Apache::lonnet::metadata($srcf,$key.'.display'); |
&Apache::lonnet::metadata($srcf,$key.'.display'); |
Line 536 sub updaterows {
|
Line 809 sub updaterows {
|
$display= |
$display= |
&Apache::lonnet::metadata($srcf,$key.'.name'); |
&Apache::lonnet::metadata($srcf,$key.'.name'); |
} |
} |
|
|
|
|
$allkeys{$key}=$display; |
$allkeys{$key}=$display; |
} |
} |
} split(/\,/,&Apache::lonnet::metadata($srcf,'keys')); |
} split(/\,/,&Apache::lonnet::metadata($srcf,'keys')); |
Line 548 sub updaterows {
|
Line 819 sub updaterows {
|
untie(%bighash); |
untie(%bighash); |
|
|
# |
# |
# %allkeys has a list of storage displays by unikey |
# %allkeys has a list of storage and parameter displays by unikey |
# %allassess has a list of all resource displays by symb |
# %allassess has a list of all resource displays by symb |
# |
# |
# -------------------- Find discrepancies between the course row table and this |
# -------------------- Find discrepancies between the course row table and this |
Line 571 sub updaterows {
|
Line 842 sub updaterows {
|
if ($_=~/^A(\d+)/) { |
if ($_=~/^A(\d+)/) { |
$maxrow=($1>$maxrow)?$1:$maxrow; |
$maxrow=($1>$maxrow)?$1:$maxrow; |
$existing{$f{$_}}=1; |
$existing{$f{$_}}=1; |
unless (defined($current{$f{$_}})) { |
unless ((defined($current{$f{$_}})) || (!$1)) { |
$f{$_}='!!! Obsolete'; |
$f{$_}='!!! Obsolete'; |
$changed=1; |
$changed=1; |
} |
} |
Line 598 sub updaterows {
|
Line 869 sub updaterows {
|
} |
} |
} |
} |
|
|
|
# --------------------------------------------------- Load data for one student |
|
|
|
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( |
|
'/res/msu/korte/junk.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 assessment |
# ------------------------------------------------ Load data for one assessment |
|
|
sub rowaassess { |
sub rowaassess { |
my ($safeeval,$uname,$udom,$symb)=@_; |
my ($safeeval,$symb)=@_; |
my $uhome=&Apache::lonnet::homeserver($uname,$udom); |
my $uhome=&Apache::lonnet::homeserver($uname,$udom); |
my $namespace; |
my $namespace; |
unless ($namespace=$ENV{'request.course.id'}) { return ''; } |
unless ($namespace=$ENV{'request.course.id'}) { return ''; } |
my $answer=reply("restore:$udom:$uname:$namespace:$symb",$uhome); |
|
|
# ----------------------------------------------------------- Get stored values |
|
my $answer=&Apache::lonnet::reply( |
|
"restore:$udom:$uname:". |
|
&Apache::lonnet::escape($namespace).":". |
|
&Apache::lonnet::escape($symb),$uhome); |
my %returnhash=(); |
my %returnhash=(); |
map { |
map { |
my ($name,$value)=split(/\=/,$_); |
my ($name,$value)=split(/\=/,$_); |
$returnhash{&unescape($name)}=&unescape($value); |
$returnhash{&Apache::lonnet::unescape($name)}= |
|
&Apache::lonnet::unescape($value); |
} split(/\&/,$answer); |
} split(/\&/,$answer); |
my $version; |
my $version; |
for ($version=1;$version<=$returnhash{'version'};$version++) { |
for ($version=1;$version<=$returnhash{'version'};$version++) { |
Line 617 sub rowaassess {
|
Line 928 sub rowaassess {
|
$returnhash{$_}=$returnhash{$version.':'.$_}; |
$returnhash{$_}=$returnhash{$version.':'.$_}; |
} split(/\:/,$returnhash{$version.':keys'}); |
} 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 %c=(); |
my %f=&getformulas($safeeval); |
my %f=&getformulas($safeeval); |
map { |
map { |
if ($_=~/^A/) { |
if ($_=~/^A/) { |
unless ($f{$_}=~/^\!/) { |
unless ($f{$_}=~/^\!/) { |
$c{$_}=$returnhash{$f{$_}}; |
if ($f{$_}=~/^parameter/) { |
} |
$c{$_}=&parmval($f{$_},$symb); |
|
} else { |
|
my $key=$f{$_}; |
|
$key=~s/^stores\_/resource\./; |
|
$key=~s/\_/\./; |
|
$c{$_}=$returnhash{$key}; |
|
} |
|
} |
} |
} |
} keys %f; |
} keys %f; |
|
|
&setconstants($safeeval,%c); |
&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 { |
sub handler { |
my $r=shift; |
my $r=shift; |
|
|
|
$uname=''; |
|
$udom=''; |
|
$csec=''; |
|
|
if ($r->header_only) { |
if ($r->header_only) { |
$r->content_type('text/html'); |
$r->content_type('text/html'); |
$r->send_http_header; |
$r->send_http_header; |
Line 644 sub handler {
|
Line 1033 sub handler {
|
|
|
if (($ENV{'request.course.fn'}) || |
if (($ENV{'request.course.fn'}) || |
($ENV{'request.state'} eq 'construct')) { |
($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->content_type('text/html'); |
|
$r->header_out('Cache-control','no-cache'); |
|
$r->header_out('Pragma','no-cache'); |
$r->send_http_header; |
$r->send_http_header; |
|
|
$r->print('<html><head><title>LON-CAPA Spreadsheet</title></head>'); |
# --------------------------------------------------------------- Screen output |
$r->print('<body bgcolor="#FFFFFF">'); |
|
|
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">'. |
|
'<form action="'.$r->uri.'" name=sheet method=post>'. |
|
&hiddenfield('uname',$ENV{'form.uname'}). |
|
&hiddenfield('udom',$ENV{'form.udom'}). |
|
&hiddenfield('usymb',$ENV{'form.usymb'}). |
|
&hiddenfield('ufn',$ENV{'form.ufn'}). |
|
&hiddenfield('unewfield',''). |
|
&hiddenfield('unewformula','')); |
|
} |
|
|
|
# ---------------------------------------- Read new sheet or modified worksheet |
|
|
my $sheetone=initsheet(); |
my $sheetone=initsheet(); |
&readsheet($sheetone,$r->filename); |
$r->uri=~/\/(\w+)$/; |
&updaterows($sheetone); |
&settype($sheetone,$1); |
&calcsheet($sheetone); |
if ($ENV{'form.unewfield'}) { |
$r->print(&outsheet($sheetone)); |
$r->print('<h2>Modified Workcopy</h2>'); |
|
$ENV{'form.unewformula'}=~s/\'/\"/g; |
|
$r->print('New formula: '.$ENV{'form.unewfield'}.'='. |
|
$ENV{'form.unewformula'}.'<br>'); |
|
&setfilename($sheetone,$ENV{'form.ufn'}); |
|
&tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
|
$ENV{'form.usymb'}, |
|
$ENV{'form.unewfield'},$ENV{'form.unewformula'}); |
|
} else { |
|
&readsheet($sheetone,$ENV{'form.ufn'},$r); |
|
} |
|
|
|
# --------------------------------------------- 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>'); |
|
} |
|
|
|
# ------------------------------------------------ Write the modified worksheet |
|
|
$r->print('</body></html>'); |
&tmpwrite($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
|
$ENV{'form.usymb'}); |
|
|
|
# ----------------------------------------------------- Print user, course, etc |
|
unless ($reroute) { |
|
$r->print("<b>User '$uname' at domain '$udom' for '". |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.description'}."'"); |
|
if ($csec) { |
|
$r->print(", group/section '$csec'"); |
|
} |
|
$r->print("</b>\n"); |
|
} |
|
# -------------------------------------------------------- Import and calculate |
|
|
|
if (&gettype($sheetone) eq 'assesscalc') { |
|
&rowaassess($sheetone,$ENV{'form.usymb'}); |
|
} elsif (&gettype($sheetone) eq 'studentcalc') { |
|
&rowazstudent($sheetone); |
|
} |
|
my $calcoutput=&calcsheet($sheetone); |
|
unless ($reroute) { |
|
$r->print('<h3><font color=red>'.$calcoutput.'</h3></font>'); |
|
} |
|
|
|
# ------------------------------------------------------- Print or export sheet |
|
unless ($reroute) { |
|
$r->print(&outsheet($sheetone)); |
|
|
|
$r->print('</form></body></html>'); |
|
} else { |
|
$r->print(&exportrow($sheetone)); |
|
} |
|
# ------------------------------------------------------------------------ Done |
} else { |
} else { |
# ----------------------------- Not in a course, or not allowed to modify parms |
# ----------------------------- Not in a course, or not allowed to modify parms |
$ENV{'user.error.msg'}= |
$ENV{'user.error.msg'}= |