--- loncom/homework/grades.pm 2002/06/27 21:34:18 1.33
+++ loncom/homework/grades.pm 2002/07/08 21:18:54 1.37
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.33 2002/06/27 21:34:18 ng Exp $
+# $Id: grades.pm,v 1.37 2002/07/08 21:18:54 ng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,7 +30,7 @@
# 7/26 H.K. Ng
# 8/20 Gerd Kortemeyer
# Year 2002
-# June 2002 H.K. Ng
+# June, July 2002 H.K. Ng
#
package Apache::grades;
@@ -53,6 +53,7 @@ sub moreinfo {
if ($ENV{'form.symb'}) {
$request->print(''."\n");
}
+# $request->print(''."\n");
$request->print(''."\n");
$request->print("Student:".''."
\n");
$request->print("Domain:".''."
\n");
@@ -65,8 +66,8 @@ sub moreinfo {
sub verifyreceipt {
my $request=shift;
my $courseid=$ENV{'request.course.id'};
- my $cdom=$ENV{"course.$courseid.domain"};
- my $cnum=$ENV{"course.$courseid.num"};
+# my $cdom=$ENV{"course.$courseid.domain"};
+# my $cnum=$ENV{"course.$courseid.num"};
my $receipt=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
$ENV{'form.receipt'};
$receipt=~s/[^\-\d]//g;
@@ -77,8 +78,8 @@ sub verifyreceipt {
if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
$request->print('
-
LON-CAPA User Error'."\n"); + $request->print('Reason: '.$reason.' '."\n"); + $request->print('Step: '.($step ne '' ? $step : 'Use your browser back button to correct') + .' '."\n"); + return ''; +} #FIXME - needs to handle multiple matches sub finduser { my ($name) = @_; my $domain = ''; - if ( $Apache::grades::viewgrades eq 'F' ) { - #get classlist - my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'}); - #print "Found $cdom:$cnum "; - my (%classlist) = &getclasslist($cdom,$cnum,'0'); - foreach my $student ( sort(@{ $classlist{'allids'} }) ) { - my ($posname,$posdomain) = split(/:/,$student); + my ($classlist) = &getclasslist('all','0'); + foreach ( sort(@{ $$classlist{'all'} }) ) { + my ($posname,$posdomain) = split(/:/); if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; } } return ($name,$domain); @@ -220,20 +228,28 @@ sub finduser { } sub getclasslist { - my ($coursedomain,$coursenum,$hideexpired) = @_; + my ($getsec,$hideexpired) = @_; + my ($coursedomain,$coursenum) = split(/_/,$ENV{'request.course.id'}); my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum); my $now = time; + my (@holdsec,@sections); foreach my $student (keys(%classlist)) { my ($end,$start)=split(/:/,$classlist{$student}); # still a student? if (($hideexpired) && ($end) && ($end < $now)) { - #print "Skipping:$name:$end:$now \n"; next; } - #print "record=$record "; - push( @{ $classlist{'allids'} }, $student); + my ($unam,$udom) = split(/:/,$student,2); + my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'}); + $section = ($section ne '-1' ? $section : 'no'); + push @holdsec,$section; + push (@{ $classlist{$getsec} }, $student) if ($getsec eq 'all' || $getsec eq $section); + } + my %seen = (); + foreach my $item (@holdsec) { + push (@sections, $item) unless $seen{$item}++; } - return (%classlist); + return (\%classlist,\@sections); } sub getpartlist { @@ -254,14 +270,9 @@ sub viewstudentgrade { my $cellclr = '"#ffffdd"'; my ($username,$domain) = split(/:/,$student); - my (@requests) = ('lastname','firstname','middlename','generation'); - my (%name) = &Apache::lonnet::get('environment',\@requests,$domain,$username); + my $fullname = &get_fullname($username,$domain); my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$username); - my $fullname=$name{'lastname'}.$name{'generation'}; - if ($fullname =~ /[^\s]+/) { $fullname.=', '; } - $fullname.=$name{'firstname'}.' '.$name{'middlename'}; - $result.=" | |||||||||||||||||||||||||||||||||||||
$username | $fullname | $domain | \n"; foreach my $part (@parts) { my ($temp,$part,$type)=split(/_/,$part); @@ -288,7 +299,7 @@ sub viewstudentgrade { #interface based on that, also do that to above function. sub setstudentgrade { my ($url,$symb,$courseid,$student,@parts) = @_; - + print "set student grade parts=@parts
Username: '.$uname. - ' | Fullname: '.$ENV{'form.fullname'}.' | Domain: '.$udom.' |
Resource: '.$url.' |
';
+ my $result.='
'; + $request->print($result); } - my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : ''); - my $answer=&Apache::loncommon::get_previous_attempt($symb,$uname,$udom, - $ENV{'request.course.id'},$last); - $result.=$answer; - my $wgt = &Apache::lonnet::EXT('resource.partid.weight',$symb,$udom,$uname); - my %record= &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname); - my $score = $record{'resource.0.awarded'}*$wgt; + # beginning of form + if ($counter == 0) { + my %keyhash = &Apache::lonnet::dump('nohist_handgrade', + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + + my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'}; + # if the handgrade db has never being initialized then set some default values + if ($keyhash{$symb.'_handgrade'} eq '') { + $keyhash{$symb.'_keywords'} = ''; + $keyhash{$symb.'_subject'} = &Apache::lonnet::metadata($url,'title'); + $keyhash{$loginuser.'_kwclr'} = $keyhash{$loginuser.'_kwclr'} eq '' ? 'red' : $keyhash{$loginuser.'_kwclr'}; + $keyhash{$loginuser.'_kwsize'} = $keyhash{$loginuser.'_kwsize'} eq '' ? '0' : $keyhash{$loginuser.'_kwsize'}; + $keyhash{$loginuser.'_kwstyle'} = $keyhash{$loginuser.'_kwstyle'} eq '' ? '' : $keyhash{$loginuser.'_kwstyle'}; + $keyhash{$symb.'_savemsgN'} = '0'; + } + $request->print(''; + $request->print($endform); + } + return ''; +} + +sub get_last_submission { + my ($symb,$username,$domain,$course)=@_; + if ($symb) { + my ($string,$timestamp); + my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username); + if ($returnhash{'version'}) { + my %lasthash=(); + my ($version); + for ($version=1;$version<=$returnhash{'version'};$version++) { + foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) { + $lasthash{$_}=$returnhash{$version.':'.$_}; + } + } + foreach ((keys %lasthash)) { + if ($_ =~ /\.submission$/) {$string = $lasthash{$_}} + if ($_ =~ /timestamp/) {$timestamp=scalar(localtime($lasthash{$_}))}; + } } + $string = $string eq '' ? 'Nothing submitted - no attempts.' : $string; + return $string,$timestamp; } +} - $result.=' | |||||
'; - my $ntstu =''."\n"; - my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1'); - $ntstu =~ s/ | |||||
Resource: | '. + ''.$url.' |
Type: | '. + ''.$responsetype.' Handgrade: '.$handgrade.' |
'."\n";
- $result.='
"; - my (%classlist) = &getclasslist($cdom,$cnum,'0'); + my ($classlist) = &getclasslist('all','0'); my $headerclr = '"#ccffff"'; my $cellclr = '"#ffffcc"'; @@ -691,12 +1209,11 @@ sub viewgrades { foreach my $part (@parts) { my $display=&Apache::lonnet::metadata($url,$part.'.display'); if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); } - print "Manual grading:$url:$part:$display: "; $result.=' '.$display.' | '."\n";
}
$result.='';
#get info for each student
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
+ foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
# print "ID=$ENV{'request.course.id'}:STU=$student:DIS=$display:\n"; $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts); @@ -715,9 +1232,9 @@ sub editgrades { if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; } my $url=$ENV{'form.url'}; #get classlist - my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'}); +# my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'}); #print "Found $cdom:$cnum "; - my (%classlist) = &getclasslist($cdom,$cnum,'0'); + my ($classlist) = &getclasslist('all','0'); #get list of parts for this problem my (@parts) = &getpartlist($url); @@ -728,7 +1245,7 @@ sub editgrades { ''."\n". ' '."\n"; - foreach my $student ( sort(@{ $classlist{'allids'} }) ) { + foreach my $student ( sort(@{ $$classlist{'all'} }) ) { $result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts); } @@ -736,25 +1253,6 @@ sub editgrades { return $result; } -sub csvupload { - my ($request)= @_; - my $result; - my ($symb,$url)=&get_symb_and_url($request); - if (!$symb) {return '';} - my $upfile_select=&Apache::loncommon::upfile_select_html(); - $result.=< - Specify a file containing the class grades for resource $url-$upfile_select -
-ENDUPFORM
- return $result;
-}
-
sub csvupload_javascript_reverse_associate {
return(< |