version 1.13, 2000/12/11 18:33:24
|
version 1.18, 2000/12/18 17:14:49
|
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,12/08,12/09,12/11 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 Gerd Kortemeyer |
|
|
package Apache::lonspreadsheet; |
package Apache::lonspreadsheet; |
|
|
Line 259 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 { |
map { |
if ($f{$_}) { |
if ($f{$_}) { |
if ($_=~/^A/) { |
if ($_=~/^$pattern/) { |
unless ($f{$_}=~/^\!/) { |
unless ($f{$_}=~/^\!/) { |
$t{$_}=$c{$_}; |
$t{$_}=$c{$_}; |
} |
} |
Line 272 sub sett {
|
Line 279 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 299 sub calc {
|
Line 309 sub calc {
|
return ''; |
return ''; |
} |
} |
|
|
sub outrow { |
sub outrowassess { |
my $n=shift; |
my $n=shift; |
my @cols=(); |
my @cols=(); |
if ($n) { |
if ($n) { |
Line 318 sub outrow {
|
Line 328 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 406 sub getfilename {
|
Line 445 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 418 sub rown {
|
Line 464 sub rown {
|
my $defaultbg=((($n-1)/5)==int(($n-1)/5))?'#E0E0':'#FFFF'; |
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 $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) { $bgcolor='#FFDDDD'; } |
if ($showf<=$maxred) { $bgcolor='#FFDDDD'; } |
if (($n==0) && ($showf<=26)) { $bgcolor='#CCCCFF'; } |
if (($n==0) && ($showf<=26)) { $bgcolor='#CCCCFF'; } |
if ($showf>1) { |
if (($showf>$maxred) || ((!$n) && ($showf>0))) { |
if ($vl eq '') { |
if ($vl eq '') { |
$vl='<font size=+2 color='.$bgcolor.'>#</font>'; |
$vl='<font size=+2 color='.$bgcolor.'>#</font>'; |
} |
} |
Line 435 sub rown {
|
Line 490 sub rown {
|
$rowdata.='<td bgcolor='.$bgcolor.'> '.$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 443 sub rown {
|
Line 498 sub rown {
|
|
|
sub outsheet { |
sub outsheet { |
my $safeeval=shift; |
my $safeeval=shift; |
my $tabledata='<table border=2><tr><td colspan=2> </td>'. |
my $maxred; |
'<td bgcolor=#FFDDDD><b>A Import</b></td>'; |
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++; |
} ('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 704 sub updaterows {
|
Line 783 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 731 sub updaterows {
|
Line 810 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 { |
Line 741 sub rowaassess {
|
Line 854 sub rowaassess {
|
|
|
# ----------------------------------------------------------- Get stored values |
# ----------------------------------------------------------- Get stored values |
my $answer=&Apache::lonnet::reply( |
my $answer=&Apache::lonnet::reply( |
"restore:$udom:$uname:$namespace:$symb",$uhome); |
"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(/\=/,$_); |
Line 791 sub rowaassess {
|
Line 906 sub rowaassess {
|
map { |
map { |
my ($name,$value)=split(/\=/,$_); |
my ($name,$value)=split(/\=/,$_); |
$useropt{&Apache::lonnet::unescape($name)}= |
$useropt{&Apache::lonnet::unescape($name)}= |
&Apache::lonnet::unescape($value); |
&Apache::lonnet::unescape($value); |
} split(/\&/,$userrdatas{$uname.'___'.$udom}); |
} split(/\&/,$userrdatas{$uname.'___'.$udom}); |
} |
} |
# -- now courseopt, useropt initialized for this user and course (used parmval) |
# -- now courseopt, useropt initialized for this user and course (used parmval) |
Line 804 sub rowaassess {
|
Line 919 sub rowaassess {
|
if ($f{$_}=~/^parameter/) { |
if ($f{$_}=~/^parameter/) { |
$c{$_}=&parmval($f{$_},$symb); |
$c{$_}=&parmval($f{$_},$symb); |
} else { |
} else { |
$c{$_}=$returnhash{$f{$_}}; |
my $key=$f{$_}; |
|
$key=~s/^stores\_/resource\./; |
|
$key=~s/\_/\./; |
|
$c{$_}=$returnhash{$key}; |
} |
} |
} |
} |
} |
} |
Line 837 sub selectbox {
|
Line 955 sub selectbox {
|
return $selout.'</select>'; |
return $selout.'</select>'; |
} |
} |
|
|
# ==================================== Sub handler to get export of assessments |
|
|
|
# ================================================================ Main handler |
# ================================================================ Main handler |
|
|
sub handler { |
sub handler { |
Line 860 sub handler {
|
Line 976 sub handler {
|
($ENV{'request.state'} eq 'construct')) { |
($ENV{'request.state'} eq 'construct')) { |
|
|
# --------------------------- Get query string for limited number of parameters |
# --------------------------- Get query string for limited number of parameters |
|
|
map { |
map { |
my ($name, $value) = split(/=/,$_); |
my ($name, $value) = split(/=/,$_); |
$value =~ tr/+/ /; |
$value =~ tr/+/ /; |
Line 880 sub handler {
|
Line 997 sub handler {
|
$uname=$ENV{'form.uname'}; |
$uname=$ENV{'form.uname'}; |
$udom=$ENV{'form.udom'}; |
$udom=$ENV{'form.udom'}; |
} |
} |
|
# ----------------------------------------------------------- Change of target? |
|
|
|
my $reroute=($ENV{'form.utarget'} eq 'export'); |
|
|
# ------------------------------------------------------------------- Open page |
# ------------------------------------------------------------------- Open page |
|
|
$r->content_type('text/html'); |
$r->content_type('text/html'); |
Line 887 sub handler {
|
Line 1008 sub handler {
|
$r->header_out('Pragma','no-cache'); |
$r->header_out('Pragma','no-cache'); |
$r->send_http_header; |
$r->send_http_header; |
|
|
|
# --------------------------------------------------------------- Screen output |
|
|
|
unless ($reroute) { |
$r->print('<html><head><title>LON-CAPA Spreadsheet</title>'); |
$r->print('<html><head><title>LON-CAPA Spreadsheet</title>'); |
$r->print(<<ENDSCRIPT); |
$r->print(<<ENDSCRIPT); |
<script language="JavaScript"> |
<script language="JavaScript"> |
Line 909 ENDSCRIPT
|
Line 1033 ENDSCRIPT
|
&hiddenfield('usymb',$ENV{'form.usymb'}). |
&hiddenfield('usymb',$ENV{'form.usymb'}). |
&hiddenfield('unewfield',''). |
&hiddenfield('unewfield',''). |
&hiddenfield('unewformula','')); |
&hiddenfield('unewformula','')); |
|
} |
|
|
|
# ---------------------------------------- Read new sheet or modified worksheet |
|
|
my $sheetone=initsheet(); |
my $sheetone=initsheet(); |
if ($ENV{'form.unewfield'}) { |
if ($ENV{'form.unewfield'}) { |
$r->print('<h2>Modified Workcopy</h2>'); |
$r->print('<h2>Modified Workcopy</h2>'); |
$ENV{'form.unewformula'}=~s/\'/\"/g; |
$ENV{'form.unewformula'}=~s/\'/\"/g; |
$r->print('New formula: '.$ENV{'form.unewfield'}.'='. |
$r->print('New formula: '.$ENV{'form.unewfield'}.'='. |
$ENV{'form.unewformula'}.'<br>'); |
$ENV{'form.unewformula'}.'<br>'); |
&tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
|
$ENV{'form.usymb'}, |
|
$ENV{'form.unewfield'},$ENV{'form.unewformula'}); |
|
&setfilename($sheetone,$r->filename); |
&setfilename($sheetone,$r->filename); |
$r->filename=~/\.(\w+)/; |
$r->filename=~/\.(\w+)/; |
&settype($sheetone,$1); |
&settype($sheetone,$1); |
|
&tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
|
$ENV{'form.usymb'}, |
|
$ENV{'form.unewfield'},$ENV{'form.unewformula'}); |
} else { |
} else { |
&readsheet($sheetone,$r->filename); |
&readsheet($sheetone,$r->filename); |
} |
} |
|
|
|
# --------------------------------------------- See if all import rows uptodate |
|
|
if (tie(%parmhash,'GDBM_File', |
if (tie(%parmhash,'GDBM_File', |
$ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640)) { |
$ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640)) { |
$csec=&Apache::lonnet::usection($udom,$uname,$ENV{'request.course.id'}); |
$csec=&Apache::lonnet::usection($udom,$uname,$ENV{'request.course.id'}); |
Line 937 ENDSCRIPT
|
Line 1068 ENDSCRIPT
|
$r->print('<h3><font color=red>'. |
$r->print('<h3><font color=red>'. |
'Could not initialize import fields (not in a course)</font></h3>'); |
'Could not initialize import fields (not in a course)</font></h3>'); |
} |
} |
|
|
|
# ------------------------------------------------ Write the modified worksheet |
|
|
&tmpwrite($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
&tmpwrite($sheetone,$r->dir_config('lonDaemons').'/tmp/', |
$ENV{'form.usymb'}); |
$ENV{'form.usymb'}); |
|
|
|
# ----------------------------------------------------- Print user, course, etc |
|
unless ($reroute) { |
$r->print("<b>User '$uname' at domain '$udom' for '". |
$r->print("<b>User '$uname' at domain '$udom' for '". |
$ENV{'course.'.$ENV{'request.course.id'}.'.description'}."'"); |
$ENV{'course.'.$ENV{'request.course.id'}.'.description'}."'"); |
if ($csec) { |
if ($csec) { |
$r->print(", group/section '$csec'"); |
$r->print(", group/section '$csec'"); |
} |
} |
$r->print("</b>\n"); |
$r->print("</b>\n"); |
|
} |
|
# -------------------------------------------------------- Import and calculate |
|
|
if (&gettype($sheetone) eq 'assesscalc') { |
if (&gettype($sheetone) eq 'assesscalc') { |
&rowaassess($sheetone,$ENV{'form.usymb'}); |
&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>'); |
} |
} |
&calcsheet($sheetone); |
|
|
# ------------------------------------------------------- Print or export sheet |
|
unless ($reroute) { |
$r->print(&outsheet($sheetone)); |
$r->print(&outsheet($sheetone)); |
|
|
$r->print('</form></body></html>'); |
$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'}= |