File:  [LON-CAPA] / loncom / homework / grades.pm
Revision 1.4: download - view: text, annotated - select for diffs
Tue Feb 13 19:43:44 2001 UTC (23 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- closes the home work remote now

# The LON-CAPA Grading handler
# 2/9,2/13 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('<form action="/adm/grades" method="post">'."\n");
  $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'"></input>'."\n");
  $request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'"></input>'."\n");
  $request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'"></input>'."<br />\n");
  $request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'"></input>'."<br />\n");
  $request->print('<input type="submit" name="submit" value="ReSubmit"></input>'."<br />\n");
  $request->print('</form>');
}


#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="<h2> Submission Record </h2>  $uname:$udom for $url".$answer;
  return $result;
}

sub send_header {
  my ($request)= @_;
  $request->print(&Apache::lontexconvert::header());
  $request->print("
<script>
remotewindow=open('','homeworkremote');
remotewindow.close();
</script>"); 
  $request->print('<body bgcolor="#FFFFFF">');
}

sub send_footer {
  my ($request)= @_;
  $request->print('</body>');
  $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__;

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