--- loncom/interface/Attic/lonspreadsheet.pm 2001/09/01 20:38:52 1.59 +++ loncom/interface/Attic/lonspreadsheet.pm 2001/11/06 11:14:42 1.75 @@ -6,7 +6,8 @@ # 01/01/01,02/01,03/01,19/01,20/01,22/01, # 03/05,03/08,03/10,03/12,03/13,03/15,03/17, # 03/19,03/20,03/21,03/27,04/05,04/09, -# 07/09,07/14,07/21,09/01 Gerd Kortemeyer +# 07/09,07/14,07/21,09/01,09/10,9/11,9/12,9/13,9/14,9/17, +# 10/16,10/17,10/20,11/05 Gerd Kortemeyer package Apache::lonspreadsheet; @@ -670,48 +671,40 @@ sub rown { my ($safeeval,$n)=@_; my $defaultbg; my $rowdata=''; + my $dataflag=0; 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.="\n
". - ''; - map { - $rowdata.=''; - } ('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.=''; + unless ($ENV{'form.showcsv'}) { + $rowdata.="\n"; + } else { + $rowdata.="\n".'"'.$n.'"'; } - $rowdata.="\n"; my $showf=0; my $proc; my $maxred; - if (&gettype($safeeval) eq 'studentcalc') { + my $sheettype=&gettype($safeeval); + if ($sheettype eq 'studentcalc') { $proc='&outrowassess'; $maxred=26; } else { $proc='&outrow'; } - if (&gettype($safeeval) eq 'assesscalc') { + if ($sheettype eq 'assesscalc') { $maxred=1; } else { $maxred=26; } - if ($n eq '-') { $proc='&templaterow'; $n=-1; } + if ($n eq '-') { $proc='&templaterow'; $n=-1; $dataflag=1; } map { my $bgcolor=$defaultbg.((($showf-1)/5==int(($showf-1)/5))?'99':'DD'); my ($fm,$vl)=split(/\_\_\_eq\_\_\_/,$_); + if ((($vl ne '') || ($vl eq '0')) && + (($showf==1) || ($sheettype ne 'studentcalc'))) { $dataflag=1; } if ($showf==0) { $vl=$_; } + unless ($ENV{'form.showcsv'}) { if ($showf<=$maxred) { $bgcolor='#FFDDDD'; } if (($n==0) && ($showf<=26)) { $bgcolor='#CCCCFF'; } if (($showf>$maxred) || ((!$n) && ($showf>0))) { @@ -724,9 +717,16 @@ sub rown { } else { $rowdata.=''; } + } else { + $rowdata.=',"'.$vl.'"'; + } $showf++; } $safeeval->reval($proc.'('.$n.')'); - return $rowdata.''; + if ($ENV{'form.showall'} || ($dataflag)) { + return $rowdata.($ENV{'form.showcsv'}?'':''); + } else { + return ''; + } } # ------------------------------------------------------------- Print out sheet @@ -746,7 +746,9 @@ sub outsheet { $realm='Course'; } my $maxyellow=52-$maxred; - my $tabledata= + my $tabledata; + unless ($ENV{'form.showcsv'}) { + $tabledata= '
 '.$what.''.$_.'
$n
$n '.$vl.' 
'. '
'. $realm.'print($tabledata); + my $row; my $maxrow=&getmaxrow($safeeval); - $tabledata.=&rown($safeeval,'-'); - $r->print($tabledata); - for ($row=0;$row<=$maxrow;$row++) { - $r->print(&rown($safeeval,$row)); + + my @sortby=(); + my @sortidx=(); + for ($row=1;$row<=$maxrow;$row++) { + $sortby[$row-1]=$safeeval->reval('$f{"A'.$row.'"}'); + $sortidx[$row-1]=$row-1; } - $r->print('
'); + @sortidx=sort { $sortby[$a] cmp $sortby[$b]; } @sortidx; + + my $what='Student'; + if (&gettype($safeeval) eq 'assesscalc') { + $what='Item'; + } elsif (&gettype($safeeval) eq 'studentcalc') { + $what='Assessment'; + } + + my $n=0; + for ($row=0;$row<$maxrow;$row++) { + my $thisrow=&rown($safeeval,$sortidx[$row]+1); + if ($thisrow) { + if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) { + $r->print("\n
\n"); + $r->rflush(); + $r->print(''); + map { + $r->print(''); + } ('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'); + $r->print(''); + } + $n++; + $r->print($thisrow); + } + } + $r->print($ENV{'form.showcsv'}?'':'
 '.$what.''.$_.'
'); } # @@ -843,10 +880,13 @@ sub readsheet { my $sheetxml=''; { my $fh; - if ($fh=Apache::File->new($includedir. - '/default.'.&gettype($safeeval))) { + my $dfn=$fn; + $dfn=~s/\_/\./g; + if ($fh=Apache::File->new($includedir.'/'.$dfn)) { $sheetxml=join('',<$fh>); - } + } else { + $sheetxml='"Error"'; + } } my $parser=HTML::TokeParser->new(\$sheetxml); my $token; @@ -1025,7 +1065,7 @@ sub parmval { # ----------------------------------------------------- Cascading lookup scheme my $rwhat=$what; $what=~s/^parameter\_//; - $what=~s/\_/\./; + $what=~s/\_([^\_]+)$/\.$1/; my $symbparm=$symb.'.'.$what; my $mapparm=$mapname.'___(all).'.$what; @@ -1116,13 +1156,19 @@ sub updateclasssheet { my ($sname,$sdom)=split(/\:/,$name); my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid); if ($ssec==-1) { + unless ($ENV{'form.showcsv'}) { $rowlabel='Data not available: '.$name. ''; + } else { + $rowlabel='ERROR","'.$name. + '","Data not available","","","'; + } } else { my %reply=&Apache::lonnet::idrget($sdom,$sname); my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname. ':environment:firstname&middlename&lastname&generation', &Apache::lonnet::homeserver($sname,$sdom)); + unless ($ENV{'form.showcsv'}) { $rowlabel=''. $ssec.' '.$reply{$sname}.'
'; @@ -1130,6 +1176,16 @@ sub updateclasssheet { $rowlabel.=&Apache::lonnet::unescape($_).' '; } split(/\&/,$reply); $rowlabel.='
'; + } else { + $rowlabel=$ssec.'","'.$reply{$sname}.'"'; + my $ncount=0; + map { + $rowlabel.=',"'.&Apache::lonnet::unescape($_).'"'; + $ncount++; + } split(/\&/,$reply); + unless ($ncount==4) { $rowlabel.=',""'; } + $rowlabel=~s/\"$//; + } } $currentlist{&Apache::lonnet::unescape($name)}=$rowlabel; } @@ -1189,8 +1245,13 @@ sub updatestudentassesssheet { # --------------------------------------------------------- Get all assessments my %allkeys=('timestamp' => - 'Timestamp of Last Transaction
timestamp'); - my %allassess=(); + 'Timestamp of Last Transaction
timestamp', + 'subnumber' => + 'Number of Submissions
subnumber', + 'tutornumber' => + 'Number of Tutor Responses
tutornumber', + 'totalpoints' => + 'Total Points Granted
totalpoints'); my $adduserstr=''; if ((&getuname($safeeval) ne $ENV{'user.name'}) || @@ -1199,6 +1260,20 @@ sub updatestudentassesssheet { '&udom='.&getudom($safeeval); } + my %allassess=('_feedback' => + 'Feedback', + '_evaluation' => + 'Evaluation', + '_tutoring' => + 'Tutoring', + '_discussion' => + 'Discussion' + ); + map { if ($_=~/^src\_(\d+)\.(\d+)$/) { my $mapid=$1; @@ -1513,6 +1588,18 @@ sub loadassessment { # ----------------- now courseopt, useropt initialized for this user and course # (used by parmval) +# +# Load keys for this assessment only +# + my %thisassess=(); + my ($symap,$syid,$srcf)=split(/\_\_\_/,$symb); + + map { + $thisassess{$_}=1; + } split(/\,/,&Apache::lonnet::metadata($srcf,'keys')); +# +# Load parameters +# my %c=(); if (tie(%parmhash,'GDBM_File', @@ -1522,14 +1609,16 @@ sub loadassessment { if ($_=~/^A/) { unless ($f{$_}=~/^\!/) { if ($f{$_}=~/^parameter/) { + if ($thisassess{$f{$_}}) { my $val=&parmval($f{$_},$safeeval); $c{$_}=$val; $c{$f{$_}}=$val; + } } else { my $key=$f{$_}; my $ckey=$key; $key=~s/^stores\_/resource\./; - $key=~s/\_/\./; + $key=~s/\_/\./g; $c{$_}=$returnhash{$key}; $c{$ckey}=$returnhash{$key}; } @@ -1636,6 +1725,11 @@ sub forcedrecalc { sub exportsheet { my ($uname,$udom,$stype,$usymb,$fn)=@_; my @exportarr=(); + + if (($usymb=~/^\_(\w+)/) && (!$fn)) { + $fn='default_'.$1; + } + # # Check if cached # @@ -1860,6 +1954,10 @@ $tmpdir=$r->dir_config('lonDaemons').'/t } } (split(/&/,$ENV{'QUERY_STRING'})); + if (($ENV{'form.usymb'}=~/^\_(\w+)/) && (!$ENV{'form.ufn'})) { + $ENV{'form.ufn'}='default_'.$1; + } + # -------------------------------------- Interactive loading of specific sheet? if (($ENV{'form.load'}) && ($ENV{'form.loadthissheet'} ne 'Default')) { $ENV{'form.ufn'}=$ENV{'form.loadthissheet'}; @@ -1973,7 +2071,8 @@ ENDSCRIPT # ---------------------------------------------------------------- Course title $r->print('

'. - $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.'

'); + $ENV{'course.'.$ENV{'request.course.id'}.'.description'}. + '

'.localtime().'

'); # ---------------------------------------------------- See if user can see this @@ -2096,6 +2195,20 @@ ENDSCRIPT &tmpwrite($asheet); + if (&gettype($asheet) eq 'studentcalc') { + $r->print('
Show rows with empty A column: '); + } else { + $r->print('
Show empty rows: '); + } + $r->print('print(' checked'); } + $r->print('>'); + if (&gettype($asheet) eq 'classcalc') { + $r->print( + ' Output CSV format: print(' checked'); } + $r->print('>'); + } # ------------------------------------------------------------- Print out sheet &outsheet($r,$asheet);