--- loncom/homework/grades.pm 2001/02/13 19:43:44 1.4
+++ loncom/homework/grades.pm 2001/04/16 23:34:11 1.5
@@ -13,20 +13,119 @@ use Apache::Constants qw(:common);
sub moreinfo {
my ($request,$reason) = @_;
$request->print("Unable to process request: $reason");
- $request->print('
');
+ if ( $Apache::grades::viewgrades eq 'F' ) {
+ $request->print('');
+ }
+ return '';
}
#FIXME - needs to be much smarter
sub finduser {
my ($name) = @_;
- return ($name,$ENV{'user.domain'});
+
+ if ( $Apache::grades::viewgrades eq 'F' ) {
+ return ($name,$ENV{'user.domain'});
+ } else {
+ return ($ENV{'user.name'},$ENV{'user.domain'});
+ }
+}
+
+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;
+ }
+ push( @{ $classlist{'allids'} }, $name);
+ }
+ return (%classlist);
+}
+
+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;
+}
+
+sub viewstudentgrade {
+ my ($url,$symb,$courseid,$student,@parts) = @_;
+ my $result ='';
+
+ my ($stuname,$domain) = split(/:/,$student);
+
+ my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname,
+ &Apache::lonnet::homeserver($stuname,$domain));
+
+ $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.=" | \n";
+ } elsif ($type eq 'tries') {
+ my $score=$record{"resource.$part.$type"};
+ $result.=" | \n"
+ } elsif ($type eq 'solved') {
+ my $score=$record{"resource.$part.$type"};
+ $result.=" | \n";
+ }
+ }
+ $result.='
';
+ return $result;
+}
+
+sub setstudentgrade {
+ my ($url,$symb,$courseid,$student,@parts) = @_;
+
+ my $result ='Hi!';
+
+ my ($stuname,$domain) = split(/:/,$student);
+
+ my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname,
+ &Apache::lonnet::homeserver($stuname,$domain));
+ my %newrecord;
+ foreach my $part (@parts) {
+ my ($temp,$part,$type)=split(/_/,$part);
+ my $oldscore=$record{"resource.$part.$type"};
+ my $newscore=$ENV{"GRADE.$stuname.$part.$type"};
+ if ($oldscore != $newscore) {
+ $result.="$stuname:$part:$type:changed from $oldscore to $newscore:
\n";
+ } else {
+ $result.="$stuname:$part:$type:changed same $oldscore to $newscore:
\n";
+ }
+ }
+ return $result;
}
sub submission {
@@ -45,6 +144,75 @@ sub submission {
return $result;
}
+sub viewgrades {
+ my ($request) = @_;
+ my $result='';
+
+ #get resource reference
+ my $url=$ENV{'form.url'};
+ $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
+ my $symb=$ENV{'form.symb'};
+ if (!$symb) { $symb=&Apache::lonnet::symbread($url); }
+ if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
+
+ #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');
+
+
+ #get list of parts for this problem
+ my (@parts) = &getpartlist($url);
+
+ #start the form
+ $result = '';
+
+ return $result;
+}
+
+sub editgrades {
+ my ($request) = @_;
+ my $result='';
+
+ my $symb=$ENV{'form.symb'};
+ 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 $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
+ #print "Found $cdom:$cnum:$chome
";
+ my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
+
+ #get list of parts for this problem
+ my (@parts) = &getpartlist($url);
+
+ $result.='';
+ return $result;
+}
+
sub send_header {
my ($request)= @_;
$request->print(&Apache::lontexconvert::header());
@@ -75,15 +243,20 @@ sub handler {
$request->send_http_header;
return OK if $request->header_only;
my $url=$ENV{'form.url'};
+ my $symb=$ENV{'form.symb'};
my $command=$ENV{'form.command'};
&send_header($request);
- if ($url eq '') {
+ if ($url eq '' && $symb eq '') {
$request->print("Non-Contextual Access Unsupported:$command:$url:");
} else {
- $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$url);
+ $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
if ($command eq 'submission') {
$request->print(&submission($request));
+ } elsif ($command eq 'viewgrades') {
+ $request->print(&viewgrades($request));
+ } elsif ($command eq 'editgrades') {
+ $request->print(&editgrades($request));
} else {
$request->print("Unknown action:$command:");
}