--- loncom/homework/grades.pm 2002/08/05 20:49:54 1.45
+++ loncom/homework/grades.pm 2003/03/28 23:44:31 1.81
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.45 2002/08/05 20:49:54 ng Exp $
+# $Id: grades.pm,v 1.81 2003/03/28 23:44:31 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,6 +31,8 @@
# 8/20 Gerd Kortemeyer
# Year 2002
# June-August H.K. Ng
+# Year 2003
+# February, March H.K. Ng
#
package Apache::grades;
@@ -39,30 +41,21 @@ use Apache::style;
use Apache::lonxml;
use Apache::lonnet;
use Apache::loncommon;
+use Apache::lonnavmaps;
use Apache::lonhomework;
+use Apache::loncoursedata;
use Apache::lonmsg qw(:user_normal_msg);
use Apache::Constants qw(:common);
-# ----- These first few routines are general use routines.-----
+# ----- These first few routines are general use routines.----
#
-
-sub print_hash {
- my ($request, $hash) = @_;
- $request->print('
Key
Value
');
- for (sort keys (%$hash)) {
- $request->print('
'.$_.'
'.$$hash{$_}.'
');
- }
- $request->print('
');
- return '';
-}
-
# --- Retrieve the parts that matches stores_\d+ from the metadata file.---
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_(\w+)_.*/) {
push(@parts,$key);
}
}
@@ -83,13 +76,16 @@ sub get_symb_and_url {
sub get_fullname {
my ($uname,$udom) = @_;
my %name=&Apache::lonnet::get('environment', ['lastname','generation',
- 'firstname','middlename'],$udom,$uname);
+ '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'};
+ $fullname = &Apache::loncoursedata::ProcessFullName
+ (@name{qw/lastname generation firstname middlename/});
+ } else {
+ &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
+ '@'.$udom.':'.$tmp);
}
return $fullname;
}
@@ -102,7 +98,7 @@ sub response_type {
my %seen = ();
my (@partlist,%handgrade);
foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
- if (/^\w+response_\d+.*/) {
+ if (/^\w+response_\w+.*/) {
my ($responsetype,$part) = split(/_/,$_,2);
my ($partid,$respid) = split(/_/,$part);
$handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
@@ -114,73 +110,38 @@ sub response_type {
return \@partlist,\%handgrade;
}
-#--- Prints a message on screen if a user did something wrong
-#--- Operator error ---
-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 '';
-}
-
#--- Dumps the class list with usernames,list of sections,
#--- section, ids and fullnames for each user.
sub getclasslist {
- my ($getsec,$hideexpired) = @_;
- my $now = time;
- my %classlist=&Apache::lonnet::dump('classlist',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
- # codes to check for fields in the classlist
- # should contain end:start:id:section:fullname
- for (keys %classlist) {
- my (@fields) = split(/:/,$classlist{$_});
- %classlist = &reformat_classlist(\%classlist) if (scalar(@fields) <= 2);
- last;
- }
-
- 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)) {
- next;
+ my ($getsec,$filterlist) = @_;
+ my $classlist=&Apache::loncoursedata::get_classlist();
+ # Bail out if we were unable to get the classlist
+ return if (! defined($classlist));
+ #
+ my %sections;
+ my %fullnames;
+ foreach (keys(%$classlist)) {
+ # the following undefs are for 'domain', and 'username' respectively.
+ my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
+ @{$classlist->{$_}};
+ # filter students according to status selected
+ if ($filterlist && $ENV{'form.status'} ne 'Any') {
+ if ($ENV{'form.status'} ne $status) {
+ delete ($classlist->{$_});
+ next;
+ }
}
$section = ($section ne '' ? $section : 'no');
- push @holdsec,$section;
if ($getsec eq 'all' || $getsec eq $section) {
- push (@{ $classlist{$getsec} }, $_);
- $allids{$_} =$id;
- $stusec{$_} =$section;
- $fullname{$_}=$fullname;
- }
+ $sections{$section}++;
+ $fullnames{$_}=$fullname;
+ } else {
+ delete($classlist->{$_});
+ }
}
my %seen = ();
- foreach my $item (@holdsec) {
- push (@sections, $item) unless $seen{$item}++;
- }
- return (\%classlist,\@sections,\%allids,\%stusec,\%fullname);
-}
-
-# add id, section and fullname to the classlist.db
-# done to maintain backward compatibility with older versions
-sub reformat_classlist {
- my ($classlist) = shift;
- foreach (sort keys(%$classlist)) {
- my ($unam,$udom) = split(/:/);
- my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
- my $fullname = &get_fullname ($unam,$udom);
- my %userid = &Apache::lonnet::idrget($udom,($unam));
- $$classlist{$_} = $$classlist{$_}.':'.$userid{$unam}.':'.$section.':'.$fullname;
- }
- my $putresult = &Apache::lonnet::put
- ('classlist',\%$classlist,
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-
- return %$classlist;
+ my @sections = sort(keys(%sections));
+ return ($classlist,\@sections,\%fullnames);
}
#find user domain
@@ -250,6 +211,8 @@ sub jscriptNform {
$jscript.= '