Diff for /loncom/homework/lonhomework.pm between versions 1.2 and 1.18

version 1.2, 2000/07/25 21:27:30 version 1.18, 2000/12/04 22:08:57
Line 1 Line 1
 # The LON-CAPA Homework handler  # The LON-CAPA Homework handler
 # Guy Albertelli  # Guy Albertelli
   # 11/30 Gerd Kortemeyer
   
 package Apache::lonhomework;  package Apache::lonhomework;
 use strict;  use strict;
Line 8  use Apache::lonxml; Line 9  use Apache::lonxml;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::inputtags;  use Apache::inputtags;
 use Apache::structuretags;  use Apache::structuretags;
   use Apache::response;
   
 sub handler {  
   my $request=shift;  
   
   $request->content_type('text/html');  sub get_target {
   $request->send_http_header;    if ( $ENV{'request.state'} eq "published") {
   &Apache::lonhomework::send_header($request);      if ( defined $ENV{'form.submit'}) {
   my $file = "/home/httpd/html".$request->uri;        return ('grade', 'web');
   my %mystyle;      } else {
   &Apache::inputtags::initialize_inputtags;        return ('web');
   my $result = Apache::lonxml::xmlparse("web",'<scriptlib>/home/httpd/html/res/103/albertel/default_homework</scriptlib>'.&getfile($file),%mystyle);      }
   #$request->print("Result follows:");    } elsif ($ENV{'request.state'} eq "construct") {
   $request->print($result);      if ( defined $ENV{'form.preview'}) {
   #$request->print(":Result ends");        if ( defined $ENV{'form.submit'}) {
   &Apache::lonhomework::send_footer($request);   return ('grade', 'web');
         } else {
    return ('web');
         }
       } else {
         return ('edit');
       }
     }
     return ();
   }
   
   sub setup_vars {
     my ($target) = @_;
     return ';'
   #  return ';$external::target='.$target.';';
 }  }
   
 sub send_header {  sub send_header {
   my ($request)= @_;    my ($request)= @_;
   $request->print('<html>');    $request->print(&Apache::lontexconvert::header());
   $request->print('<form method="POST" action="'.$request->uri.'">');    $ENV{'request.uri'}=$request->uri;
   #  $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');
 }  }
   
 sub send_footer {  sub send_footer {
   my ($request)= @_;    my ($request)= @_;
   $request->print('</form>');  #  $request->print('</form>');
   $request->print('</html>');    $request->print(&Apache::lontexconvert::footer());
 }  }
   
 sub getfile {  sub handler {
   my ($filename) = @_;    my $request=$_[0];
   my $a="";  
   &Apache::lonnet::repcopy($filename);  
   {  
     my $fh=Apache::File->new($filename);  
   
     while (<$fh>) {    $Apache::lonxml::debug=1;
       $a .=$_;    
     my (@targets) = &get_target();
   
     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;
     
     &Apache::lonhomework::send_header($request);
     
     foreach my $target (@targets) {
       my $file=&Apache::lonnet::filelocation("",$request->uri);
       my $problem=&Apache::lonnet::getfile($file);
       if ($problem == -1) {
         &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
         $problem='';
       }
       
       my %mystyle;
       my $result = '';
       &Apache::inputtags::initialize_inputtags;
       %Apache::lonhomework::results=();
       %Apache::lonhomework::history=&Apache::lonnet::restore;
       #ignore error conditions
       my ($temp)=keys %Apache::lonhomework::history ;
       if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); } 
       
       if ($target eq 'grade') {
         my $resultkey;
         foreach $resultkey (sort keys %Apache::lonhomework::history) {
    &Apache::lonxml::debug("$resultkey ---- $Apache::lonhomework::history{$resultkey}");
         }
         &Apache::lonxml::debug("\n<br>restored values^</br>\n");
       }
       my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
       if ($default == -1) {
         &Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
         $default='';
       }
       if ( $target eq 'grade') { 
         $Apache::lonxml::textredirection = 0; 
       } else {
         $Apache::lonxml::textredirection = 1; 
       }
       $result = &Apache::lonxml::xmlparse($target, $problem,
    $default.&setup_vars($target),%mystyle);
   
       #$request->print("Result follows:");
       $request->print($result);
       #$request->print(":Result ends");
       if ($target eq 'grade') {
         my $resultkey;
         foreach $resultkey (sort keys %Apache::lonhomework::results) {
    &Apache::lonxml::debug("$resultkey ---- $Apache::lonhomework::results{$resultkey}");
         }
         &Apache::lonxml::debug("\n<br>storing values^</br>\n");
       }
       
       my ($temp) = keys %Apache::lonhomework::results;
       if ( $temp ne '' ) {
         &Apache::lonxml::debug("Store return message:".&Apache::lonnet::cstore(%Apache::lonhomework::results));
     }      }
   }    }
   return $a    &Apache::lonhomework::send_footer($request);
     
     return 'OK';
   
 }  }
   
 1;  1;

Removed from v.1.2  
changed lines
  Added in v.1.18


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