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

1.1       albertel    1: # The LON-CAPA Grading handler
1.4     ! albertel    2: # 2/9,2/13 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());
1.4     ! albertel   51:   $request->print("
        !            52: <script>
        !            53: remotewindow=open('','homeworkremote');
        !            54: remotewindow.close();
        !            55: </script>"); 
1.2       albertel   56:   $request->print('<body bgcolor="#FFFFFF">');
                     57: }
                     58: 
                     59: sub send_footer {
                     60:   my ($request)= @_;
                     61:   $request->print('</body>');
                     62:   $request->print(&Apache::lontexconvert::footer());
                     63: }
                     64: 
1.1       albertel   65: sub handler {
                     66:   my $request=$_[0];
                     67: 
                     68:   if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} else {$Apache::lonxml::debug=0;}
                     69:   
                     70:   if ($ENV{'browser.mathml'}) {
                     71:     $request->content_type('text/xml');
                     72:   } else {
                     73:     $request->content_type('text/html');
                     74:   }
                     75:   $request->send_http_header;
                     76:   return OK if $request->header_only;
                     77:   my $url=$ENV{'form.url'};
1.2       albertel   78:   my $command=$ENV{'form.command'};
                     79:   
                     80:   &send_header($request);
1.1       albertel   81:   if ($url eq '') {
1.2       albertel   82:     $request->print("Non-Contextual Access Unsupported:$command:$url:");
1.1       albertel   83:   } else {
                     84:     $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$url);
1.2       albertel   85:     if ($command eq 'submission') {
1.3       albertel   86:       $request->print(&submission($request));
1.2       albertel   87:     } else {
                     88:       $request->print("Unknown action:$command:");
                     89:     }
1.1       albertel   90:   }
1.2       albertel   91:   &send_footer($request);
1.1       albertel   92:   return OK;
                     93: }
                     94: 
                     95: 1;
                     96: 
                     97: __END__;

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