Annotation of loncom/homework/grades.pm, revision 1.3

1.1       albertel    1: # The LON-CAPA Grading handler
1.3     ! albertel    2: # 2/9 Guy Albertelli
1.1       albertel    3: 
                      4: package Apache::grades;
                      5: use strict;
                      6: use Apache::style;
                      7: use Apache::lonxml;
                      8: use Apache::lonnet;
1.3     ! albertel    9: use Apache::loncommon;
1.1       albertel   10: use Apache::lonhomework;
                     11: use Apache::Constants qw(:common);
                     12: 
1.2       albertel   13: sub moreinfo {
                     14:   my ($request,$reason) = @_;
                     15:   $request->print("Unable to process request: $reason");
                     16:   $request->print('<form action="/adm/grades" method="post">'."\n");
                     17:   $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'"></input>'."\n");
                     18:   $request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'"></input>'."\n");
                     19:   $request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'"></input>'."<br />\n");
                     20:   $request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'"></input>'."<br />\n");
                     21:   $request->print('<input type="submit" name="submit" value="ReSubmit"></input>'."<br />\n");
                     22:   $request->print('</form>');
                     23: }
                     24: 
                     25: 
1.3     ! albertel   26: #FIXME - needs to be much smarter
1.2       albertel   27: sub finduser {
                     28:   my ($name) = @_;
1.3     ! albertel   29:   return ($name,$ENV{'user.domain'});
1.2       albertel   30: }
                     31: 
                     32: sub submission {
                     33:   my ($request) = @_;
1.3     ! albertel   34:   my $url=$ENV{'form.url'};
        !            35:   $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.2       albertel   36:   if ($ENV{'form.student'} eq '') { &moreinfo($request,"Need student login id"); return ''; }
                     37:   my ($uname,$udom) = &finduser($ENV{'form.student'});
                     38:   if ($uname eq '') { &moreinfo($request,"Unable to find student"); return ''; }
1.3     ! albertel   39:   my $symb=&Apache::lonnet::symbread($url);
        !            40:   if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
        !            41:   my $home=&Apache::lonnet::homeserver($uname,$udom);
        !            42:   my $answer=&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,$home,
        !            43: 						      $ENV{'request.course.id'});
        !            44:   my $result="<h2> Submission Record </h2>  $uname:$udom for $url".$answer;
        !            45:   return $result;
1.2       albertel   46: }
                     47: 
                     48: sub send_header {
                     49:   my ($request)= @_;
                     50:   $request->print(&Apache::lontexconvert::header());
                     51:   $request->print('<body bgcolor="#FFFFFF">');
                     52: }
                     53: 
                     54: sub send_footer {
                     55:   my ($request)= @_;
                     56:   $request->print('</body>');
                     57:   $request->print(&Apache::lontexconvert::footer());
                     58: }
                     59: 
1.1       albertel   60: sub handler {
                     61:   my $request=$_[0];
                     62: 
                     63:   if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} else {$Apache::lonxml::debug=0;}
                     64:   
                     65:   if ($ENV{'browser.mathml'}) {
                     66:     $request->content_type('text/xml');
                     67:   } else {
                     68:     $request->content_type('text/html');
                     69:   }
                     70:   $request->send_http_header;
                     71:   return OK if $request->header_only;
                     72:   my $url=$ENV{'form.url'};
1.2       albertel   73:   my $command=$ENV{'form.command'};
                     74:   
                     75:   &send_header($request);
1.1       albertel   76:   if ($url eq '') {
1.2       albertel   77:     $request->print("Non-Contextual Access Unsupported:$command:$url:");
1.1       albertel   78:   } else {
                     79:     $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$url);
1.2       albertel   80:     if ($command eq 'submission') {
1.3     ! albertel   81:       $request->print(&submission($request));
1.2       albertel   82:     } else {
                     83:       $request->print("Unknown action:$command:");
                     84:     }
1.1       albertel   85:   }
1.2       albertel   86:   &send_footer($request);
1.1       albertel   87:   return OK;
                     88: }
                     89: 
                     90: 1;
                     91: 
                     92: __END__;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>