# The LON-CAPA Grading handler # 2/9 Guy Albertelli package Apache::grades; use strict; use Apache::style; use Apache::lonxml; use Apache::lonnet; use Apache::loncommon; use Apache::lonhomework; use Apache::Constants qw(:common); sub moreinfo { my ($request,$reason) = @_; $request->print("Unable to process request: $reason"); $request->print('
'."\n"); $request->print(''."\n"); $request->print(''."\n"); $request->print("Student:".''."
\n"); $request->print("Domain:".''."
\n"); $request->print(''."
\n"); $request->print('
'); } #FIXME - needs to be much smarter sub finduser { my ($name) = @_; return ($name,$ENV{'user.domain'}); } sub submission { my ($request) = @_; my $url=$ENV{'form.url'}; $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=&Apache::lonnet::symbread($url); if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; } my $home=&Apache::lonnet::homeserver($uname,$udom); my $answer=&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,$home, $ENV{'request.course.id'}); my $result="

Submission Record

$uname:$udom for $url".$answer; return $result; } sub send_header { my ($request)= @_; $request->print(&Apache::lontexconvert::header()); $request->print(''); } sub send_footer { my ($request)= @_; $request->print(''); $request->print(&Apache::lontexconvert::footer()); } sub handler { my $request=$_[0]; if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} else {$Apache::lonxml::debug=0;} if ($ENV{'browser.mathml'}) { $request->content_type('text/xml'); } else { $request->content_type('text/html'); } $request->send_http_header; return OK if $request->header_only; my $url=$ENV{'form.url'}; my $command=$ENV{'form.command'}; &send_header($request); if ($url eq '') { $request->print("Non-Contextual Access Unsupported:$command:$url:"); } else { $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$url); if ($command eq 'submission') { $request->print(&submission($request)); } else { $request->print("Unknown action:$command:"); } } &send_footer($request); return OK; } 1; __END__;