version 1.4, 2001/02/13 19:43:44
|
version 1.5, 2001/04/16 23:34:11
|
Line 13 use Apache::Constants qw(:common);
|
Line 13 use Apache::Constants qw(:common);
|
sub moreinfo { |
sub moreinfo { |
my ($request,$reason) = @_; |
my ($request,$reason) = @_; |
$request->print("Unable to process request: $reason"); |
$request->print("Unable to process request: $reason"); |
$request->print('<form action="/adm/grades" method="post">'."\n"); |
if ( $Apache::grades::viewgrades eq 'F' ) { |
$request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'"></input>'."\n"); |
$request->print('<form action="/adm/grades" method="post">'."\n"); |
$request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'"></input>'."\n"); |
$request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'"></input>'."\n"); |
$request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'"></input>'."<br />\n"); |
$request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'"></input>'."\n"); |
$request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'"></input>'."<br />\n"); |
$request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'"></input>'."<br />\n"); |
$request->print('<input type="submit" name="submit" value="ReSubmit"></input>'."<br />\n"); |
$request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'"></input>'."<br />\n"); |
$request->print('</form>'); |
$request->print('<input type="submit" name="submit" value="ReSubmit"></input>'."<br />\n"); |
|
$request->print('</form>'); |
|
} |
|
return ''; |
} |
} |
|
|
|
|
#FIXME - needs to be much smarter |
#FIXME - needs to be much smarter |
sub finduser { |
sub finduser { |
my ($name) = @_; |
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<br />\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.="<tr><td>$stuname</td><td>$domain</td>\n"; |
|
foreach my $part (@parts) { |
|
my ($temp,$part,$type)=split(/_/,$part); |
|
#print "resource.$part.$type = ".$record{"resource.$part.$type"}." <br />\n"; |
|
if ($type eq 'awarded') { |
|
my $score=$record{"resource.$part.$type"}; |
|
$result.="<td><input type=\"text\" name=\"GRADE.$stuname.$part.$type\" value=\"$score\" size=\"4\" /></td>\n"; |
|
} elsif ($type eq 'tries') { |
|
my $score=$record{"resource.$part.$type"}; |
|
$result.="<td><input type=\"text\" name=\"GRADE.$stuname.$part.$type\" value=\"$score\" size=\"4\" /></td>\n" |
|
} elsif ($type eq 'solved') { |
|
my $score=$record{"resource.$part.$type"}; |
|
$result.="<td><select name=\"GRADE.$stuname.$part.$type\">\n"; |
|
if ($score =~ /^correct/) { |
|
$result.="<option selected=\"on\">Correct</option>\n<option>Incorrect</option>\n<option>Excused</option>\n<option>Attempted</option>\n<option>Nothing</option>\n"; |
|
} elsif ($score =~ /^incorrect/) { |
|
$result.="<option>Correct</option>\n<option selected=\"on\">Incorrect</option>\n<option>Excused</option>\n<option>Attempted</option>\n<option>Nothing</option>\n"; |
|
} elsif ($score eq '') { |
|
$result.="<option>Correct</option>\n<option>Incorrect</option>\n<option>Excused</option>\n<option>Attempted</option>\n<option selected=\"on\">Nothing</option>\n"; |
|
} elsif ($score =~ /^excused/) { |
|
$result.="<option>Correct</option>\n<option>Incorrect</option>\n<option selected=\"on\">Excused</option>\n<option>Attempted</option>\n<option>Nothing</option>\n"; |
|
} elsif ($score =~ /^ungraded/) { |
|
$result.="<option>Correct</option>\n<option>Incorrect</option>\n<option>Excused</option>\n<option selected=\"on\">Attempted</option>\n<option>Nothing</option>\n"; |
|
} |
|
$result.="</select></td>\n"; |
|
} |
|
} |
|
$result.='</tr>'; |
|
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:<br />\n"; |
|
} else { |
|
$result.="$stuname:$part:$type:changed same $oldscore to $newscore:<br />\n"; |
|
} |
|
} |
|
return $result; |
} |
} |
|
|
sub submission { |
sub submission { |
Line 45 sub submission {
|
Line 144 sub submission {
|
return $result; |
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<br />"; |
|
my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0'); |
|
|
|
|
|
#get list of parts for this problem |
|
my (@parts) = &getpartlist($url); |
|
|
|
#start the form |
|
$result = '<form action="/adm/grades" method="post">'."\n". |
|
'<input type="hidden" name="symb" value="'.$symb.' "/>'."\n". |
|
'<input type="hidden" name="url" value="'.$url.' "/>'."\n". |
|
'<input type="hidden" name="command" value="editgrades" />'."\n". |
|
'<input type="submit" name="submit" value="Submit Changes" />'."\n". |
|
'<table>'."\n". |
|
'<tr><td>UserId</td><td>Domain</td><td>Portion Correct</td><td>Status</td><td>Tries</td></tr>'."\n"; |
|
#get info for each student |
|
foreach my $student ( sort(@{ $classlist{'allids'} }) ) { |
|
$result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts); |
|
} |
|
$result.='</table><input type="submit" name="submit" value="Submit Changes" /></form>'; |
|
|
|
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<br />"; |
|
my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0'); |
|
|
|
#get list of parts for this problem |
|
my (@parts) = &getpartlist($url); |
|
|
|
$result.='<form action="/adm/grades" method="post">'."\n". |
|
'<input type="hidden" name="symb" value="'.$symb.'" />'."\n". |
|
'<input type="hidden" name="url" value="'.$url.'" />'."\n". |
|
'<input type="hidden" name="command" value="viewgrades" />'."\n". |
|
'<input type="submit" name="submit" value="See Grades" />'."\n"; |
|
|
|
foreach my $student ( sort(@{ $classlist{'allids'} }) ) { |
|
$result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts); |
|
} |
|
|
|
$result.='<input type="submit" name="submit" value="See Grades" /></table></form>'; |
|
return $result; |
|
} |
|
|
sub send_header { |
sub send_header { |
my ($request)= @_; |
my ($request)= @_; |
$request->print(&Apache::lontexconvert::header()); |
$request->print(&Apache::lontexconvert::header()); |
Line 75 sub handler {
|
Line 243 sub handler {
|
$request->send_http_header; |
$request->send_http_header; |
return OK if $request->header_only; |
return OK if $request->header_only; |
my $url=$ENV{'form.url'}; |
my $url=$ENV{'form.url'}; |
|
my $symb=$ENV{'form.symb'}; |
my $command=$ENV{'form.command'}; |
my $command=$ENV{'form.command'}; |
|
|
&send_header($request); |
&send_header($request); |
if ($url eq '') { |
if ($url eq '' && $symb eq '') { |
$request->print("Non-Contextual Access Unsupported:$command:$url:"); |
$request->print("Non-Contextual Access Unsupported:$command:$url:"); |
} else { |
} else { |
$Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$url); |
$Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); |
if ($command eq 'submission') { |
if ($command eq 'submission') { |
$request->print(&submission($request)); |
$request->print(&submission($request)); |
|
} elsif ($command eq 'viewgrades') { |
|
$request->print(&viewgrades($request)); |
|
} elsif ($command eq 'editgrades') { |
|
$request->print(&editgrades($request)); |
} else { |
} else { |
$request->print("Unknown action:$command:"); |
$request->print("Unknown action:$command:"); |
} |
} |