--- loncom/homework/grades.pm 2001/08/06 16:37:58 1.12
+++ loncom/homework/grades.pm 2002/07/26 20:28:42 1.42
@@ -1,14 +1,37 @@
-# The LON-CAPA grading handler.
+# The LearningOnline Network with CAPA
+# The LON-CAPA Grading handler
#
-# Handles the viewing of grades.
+# $Id: grades.pm,v 1.42 2002/07/26 20:28:42 ng Exp $
#
-# YEAR=2001
-# 2/7,2/9,2/13,4/16,4/17,5/1 Guy Albertelli
+# Copyright Michigan State University Board of Trustees
+#
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+# 2/9,2/13 Guy Albertelli
# 6/8 Gerd Kortemeyer
-# 7/26 Guy Albertelli
-# 7/27 H.K. Ng
-# 7/30 Guy Albertelli
-# 8/6 Scott Harrison
+# 7/26 H.K. Ng
+# 8/20 Gerd Kortemeyer
+# Year 2002
+# June, July 2002 H.K. Ng
+#
package Apache::grades;
use strict;
@@ -17,82 +40,239 @@ use Apache::lonxml;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonhomework;
+use Apache::lonmsg qw(:user_normal_msg);
use Apache::Constants qw(:common);
+#use Time::HiRes qw( gettimeofday tv_interval );
-# ======================================================== Get more information
sub moreinfo {
my ($request,$reason) = @_;
$request->print("Unable to process request: $reason");
if ( $Apache::grades::viewgrades eq 'F' ) {
$request->print('
');
}
return '';
}
-# ========================================= Displays the class list of students
+sub verifyreceipt {
+ my $request=shift;
+ my $courseid=$ENV{'request.course.id'};
+# 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;
+ my $symb=$ENV{'form.symb'};
+ unless ($symb) {
+ $symb=&Apache::lonnet::symbread($ENV{'form.url'});
+ }
+ if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
+ $request->print('
Verifying Submission Receipt '.$receipt.'
');
+ my $matches=0;
+ my ($classlist) = &getclasslist('all','0');
+ foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
+ my ($uname,$udom)=split(/\:/,$student);
+ if ($receipt eq
+ &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
+ $request->print('Matching '.$student.' ');
+ $matches++;
+ }
+ }
+ $request->printf('
'.$matches." match%s
",$matches <= 1 ? '' : 'es');
+# needs to print who is matched
+ }
+ return '';
+}
+
+sub student_gradeStatus {
+ my ($url,$udom,$uname,$partlist) = @_;
+ my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
+ my %record= &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
+ my %partstatus = ();
+ foreach (@$partlist) {
+ my ($status,$foo)=split(/_/,$record{"resource.$_.solved"},2);
+ $status = 'nothing' if ($status eq '');
+ $partstatus{$_} = $status;
+ $partstatus{"resource.$_.submitted_by"} = $record{"resource.$_.submitted_by"}
+ if ($record{"resource.$_.submitted_by"} ne '');
+ }
+ return %partstatus;
+}
+
+sub get_fullname {
+ my ($uname,$udom) = @_;
+ my %name=&Apache::lonnet::get('environment', ['lastname','generation',
+ 'firstname','middlename'],$udom,$uname);
+ my $fullname;
+ my ($tmp) = keys(%name);
+ if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
+ $fullname=$name{'lastname'}.$name{'generation'};
+ if ($fullname =~ /[^\s]+/) { $fullname.=', '; }
+ $fullname.=$name{'firstname'}.' '.$name{'middlename'};
+ }
+ return $fullname;
+}
+
+sub response_type {
+ my ($url) = shift;
+ my $allkeys = &Apache::lonnet::metadata($url,'keys');
+# print "allkeys=>$allkeys ";
+ my %seen = ();
+ my (@partlist,%handgrade);
+ foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
+ if (/^\w+response_\d{1,2}.*/) {
+ my ($responsetype,$part) = split(/_/,$_,2);
+ my ($partid,$respid) = split(/_/,$part);
+ $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
+ next if ($seen{$partid} > 0);
+ $seen{$partid}++;
+ push @partlist,$partid;
+ }
+ }
+ return \@partlist,\%handgrade;
+}
+
+
sub listStudents {
my ($request) = shift;
- my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
- my $chome = $ENV{"course.$ENV{'request.course.id'}.home"};
- $request->print ("Found $cdom:$cnum:$chome ");
- my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
- my ($sname,$sdom) = split(/:/,$student);
- my $reply = &Apache::lonnet::reply('get:'.$sdom.':'.$sname.
- ':environment:lastname&generation&firstname&middle'.
- 'name',&Apache::lonnet::homeserver($sname,$sdom));
- print "reply=$reply ";
- my (@nameparts) = split /&/,$reply;
-# my $sfullname = $Apache::lonnet::unescape($nameparts[0]);
+ my $cdom =$ENV{"course.$ENV{'request.course.id'}.domain"};
+ my $cnum =$ENV{"course.$ENV{'request.course.id'}.num"};
+ my $getsec =$ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
+ my $submitonly=$ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
+
+ my $result='
View Submissions for a Student or a Group of Students
';
+ $result.='
';
+ $result.='
Resource: '.$ENV{'form.url'}.'
';
+ my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
+ for (sort keys(%$handgrade)) {
+ my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
+ $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes');
+ $result.='
Part id: '.$_.'
'.
+ '
Type: '.$responsetype.'
'.
+ '
Handgrade: '.$handgrade.'
';
+ }
+ $result.='
';
+ $request->print($result);
+
+ $request->print(<
+ View Problem: no
+ yes
+ Submissions:
+ handgrade only
+ last sub only
+ last sub & parts info
+ all details
+
+
+
+
+
+
+ENDTABLEST
+ if ($ENV{'form.url'}) {
+ $request->print(''."\n");
+ }
+ if ($ENV{'form.symb'}) {
+ $request->print(''."\n");
+ }
+ $request->print(''."\n");
+
+ my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0');
+
+ $result='
'.
+ '
'.
+ '
Select
Username
'.
+ '
Fullname
Domain
';
+ foreach (sort(@$partlist)) {
+ $result.='
Part ID '.$_.' Status
';
+ }
+ $request->print($result.'
'."\n");
+
+ foreach my $student (sort(@{ $$classlist{$getsec} }) ) {
+ my ($uname,$udom) = split(/:/,$student);
+ my (%status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname,$partlist);
+ my $statusflg = '';
+ foreach (keys(%status)) {
+ $statusflg = 1 if ($status{$_} ne 'nothing');
+ my ($foo,$partid,$foo) = split(/\./,$_);
+ if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
+ $statusflg = '';
+ $request->print('');
+ }
+ }
+ next if ($statusflg eq '' && $submitonly eq 'yes');
+
if ( $Apache::grades::viewgrades eq 'F' ) {
- $request->print('');
+ $result='
'.
+ '
'."\n".
+ '
'.$uname.'
'."\n".
+ '
'.$$fullname{$student}.'
'."\n".
+ '
'.$udom.'
'."\n";
+
+ foreach (sort keys(%status)) {
+ next if (/^resource.*?submitted_by$/);
+ $result.='
'.$status{$_}.'
'."\n";
+ }
+ $request->print($result.'
'."\n");
}
}
+ $request->print('
');
+ $request->print('');
+}
+
+sub processGroup {
+ my ($request) = shift;
+ my $ctr = 0;
+ my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
+ : ($ENV{'form.stuinfo'}));
+ my $total = scalar(@stuchecked)-1;
+ if ($stuchecked[0] eq '') {
+ &userError($request,'No student was selected for viewing/grading.');
+ return;
+ }
+ foreach (@stuchecked) {
+ my ($uname,$udom,$fullname) = split(/:/);
+ $ENV{'form.student'} = $uname;
+ $ENV{'form.fullname'} = $fullname;
+ &submission($request,$ctr,$total);
+ $ctr++;
+ }
+ return '';
+}
+
+sub userError {
+ my ($request, $reason, $step) = @_;
+ $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 '';
}
-# ========== Finds a user based on a name substring (returns a 2 element array)
#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'});
- my $chome = $ENV{"course.$ENV{'request.course.id'}.home"};
- #print "Found $cdom:$cnum:$chome ";
- my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
- my ($posname,$posdomain) = split(/:/,$student);
- if ($posname =~ $name) {
- $name = $posname;
- $domain = $posdomain;
- last;
- }
+ my ($classlist) = &getclasslist('all','0');
+ foreach ( sort(@{ $$classlist{'all'} }) ) {
+ my ($posname,$posdomain) = split(/:/);
+ if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
}
return ($name,$domain);
} else {
@@ -100,103 +280,1044 @@ sub finduser {
}
}
-# ===================================== Gets a class list (returns a hash list)
sub getclasslist {
- my ($coursedomain,$coursenum,$coursehome,$hideexpired) = @_;
- my $classlist = &Apache::lonnet::reply('dump:'.$coursedomain.':'.
- $coursenum.':classlist',$coursehome);
- my %classlist = ();
+ my ($getsec,$hideexpired) = @_;
my $now = time;
- foreach my $record (split /&/, $classlist) {
- my ($name,$value)=split(/=/,&Apache::lonnet::unescape($record));
- my ($end,$start)=split(/:/,$value);
- # still a student?
+ my %classlist=&Apache::lonnet::dump('classlist',
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ my (@holdsec,@sections,%allids,%stusec,%fullname);
+ foreach (keys(%classlist)) {
+ my ($end,$start,$id,$section,$fullname)=split(/:/,$classlist{$_});
+ # still a student?
if (($hideexpired) && ($end) && ($end < $now)) {
- print "Skipping:$name:$end:$now \n";
next;
}
- print "record=$record ";
- push( @{ $classlist{'allids'} }, $name);
+ $section = ($section ne '' ? $section : 'no');
+ push @holdsec,$section;
+ if ($getsec eq 'all' || $getsec eq $section) {
+ push (@{ $classlist{$getsec} }, $_);
+ $allids{$_}=$id;
+ $stusec{$_}=$section;
+ $fullname{$_}=$fullname;
+ }
+ }
+ my %seen = ();
+ foreach my $item (@holdsec) {
+ push (@sections, $item) unless $seen{$item}++;
}
- return (%classlist);
+ return (\%classlist,\@sections,\%allids,\%stusec,\%fullname);
}
-# ============================== Get parts of a stored value (returns an array)
sub getpartlist {
my ($url) = @_;
my @parts =();
my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
foreach my $key (@metakeys) {
- if ( $key =~ m/stores_([0-9]+)_.*/ ) {
+ if ( $key =~ m/stores_([0-9]+)_.*/) {
push(@parts,$key);
}
}
return @parts;
}
-# =================================== Displays student grade (returns a string)
-sub viewstudentgrade {
- my ($url,$symb,$courseid,$student,@parts) = @_;
- my $result = '';
- my $cellclr = '"#ffffdd"';
- my ($stuname,$domain) = split(/:/,$student);
- my %record = &Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
- $result .= "
');
+ for (sort keys (%$hash)) {
+ $request->print('
'.$_.'
'.$$hash{$_}.'
');
+ }
+ $request->print('
');
+ return '';
+}
+#
+# --------------------------- show submissions of a student, option to grade --------
+sub submission {
+ my ($request,$counter,$total) = @_;
+
+ (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
+ if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
+ my ($uname,$udom) = &finduser($ENV{'form.student'});
+ if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
+
+ my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
+ if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
+ my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
+ $ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes';
+ my ($classlist,$seclist,$ids,$stusec,$fullname);
+
+ # header info
+ if ($counter == 0) {
+ &sub_page_js($request);
+ $request->print('
Submission Record
'.
+ ' Resource: '.$url.'');
+
+ # option to display problem, only once else it cause problems with the form later
+ # since the problem has a form.
+ if ($ENV{'form.vProb'} eq 'yes') {
+ my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
+ $ENV{'request.course.id'});
+ my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
+ $ENV{'request.course.id'});
+ my $result.='