--- loncom/homework/grades.pm 2001/02/13 18:41:00 1.3
+++ loncom/homework/grades.pm 2001/08/06 16:37:58 1.12
@@ -1,5 +1,14 @@
-# The LON-CAPA Grading handler
-# 2/9 Guy Albertelli
+# The LON-CAPA grading handler.
+#
+# Handles the viewing of grades.
+#
+# YEAR=2001
+# 2/7,2/9,2/13,4/16,4/17,5/1 Guy Albertelli
+# 6/8 Gerd Kortemeyer
+# 7/26 Guy Albertelli
+# 7/27 H.K. Ng
+# 7/30 Guy Albertelli
+# 8/6 Scott Harrison
package Apache::grades;
use strict;
@@ -10,83 +19,413 @@ use Apache::loncommon;
use Apache::lonhomework;
use Apache::Constants qw(:common);
+# ======================================================== Get more information
sub moreinfo {
- my ($request,$reason) = @_;
- $request->print("Unable to process request: $reason");
- $request->print('
');
+ 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 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]);
+ if ( $Apache::grades::viewgrades eq 'F' ) {
+ $request->print('');
+ }
+ }
+}
-#FIXME - needs to be much smarter
+# ========== Finds a user based on a name substring (returns a 2 element array)
+#FIXME - needs to handle multiple matches
sub finduser {
- my ($name) = @_;
- return ($name,$ENV{'user.domain'});
+ 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;
+ }
+ }
+ return ($name,$domain);
+ } else {
+ return ($ENV{'user.name'},$ENV{'user.domain'});
+ }
+}
+
+# ===================================== 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 $now = time;
+ foreach my $record (split /&/, $classlist) {
+ my ($name,$value)=split(/=/,&Apache::lonnet::unescape($record));
+ my ($end,$start)=split(/:/,$value);
+ # still a student?
+ if (($hideexpired) && ($end) && ($end < $now)) {
+ print "Skipping:$name:$end:$now \n";
+ next;
+ }
+ print "record=$record ";
+ push( @{ $classlist{'allids'} }, $name);
+ }
+ return (%classlist);
+}
+
+# ============================== 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]+)_.*/ ) {
+ 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 .= "
$stuname
$domain
\n";
+ foreach my $part (@parts) {
+ my ($temp,$part,$type)=split(/_/,$part);
+ #print "resource.$part.$type = ".$record{"resource.$part.$type"}." \n";
+ if ($type eq 'awarded') {
+ my $score = $record{"resource.$part.$type"};
+ $result .= "