Diff for /loncom/homework/lonhomework.pm between versions 1.6 and 1.17

version 1.6, 2000/08/11 14:25:24 version 1.17, 2000/11/30 16:20:49
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;  
   
   my $target=&get_target();  sub subhandler {
   $request->content_type('text/html');    my ($target,$problem)=@_;
   $request->send_http_header;  
   &Apache::lonhomework::send_header($request);  
   my $file = "/home/httpd/html".$request->uri;  
   my %mystyle;    my %mystyle;
   my $result = '';    my $result = '';
   &Apache::inputtags::initialize_inputtags;    &Apache::inputtags::initialize_inputtags;
   $result = Apache::lonxml::xmlparse($target, &getfile($file),    %Apache::lonhomework::results=();
  &getfile('/home/httpd/html/res/103/albertel/default_homework').&setup_vars($target),%mystyle);    %Apache::lonhomework::history=&Apache::lonnet::restore;
   #$request->print("Result follows:");    #ignore error conditions
   $request->print($result);    my ($temp)=keys %Apache::lonhomework::history ;
   #$request->print(":Result ends");    if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); } 
   &Apache::lonhomework::send_footer($request);  
     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='';
     }
   
     return Apache::lonxml::xmlparse($target, $problem,
        $default.&setup_vars($target),%mystyle);
 }  }
   
 sub get_target {  sub get_target {
   return "web";    if ( $ENV{'request.state'} eq "published") {
       return 'web';
     } elsif ($ENV{'request.state'} eq "construct") {
       if ( defined $ENV{'form.preview'}) {
         return 'web';
       } else {
         return 'edit';
       }
     }
 }  }
   
 sub setup_vars {  sub setup_vars {
   my ($target) = @_;    my ($target) = @_;
   return ';$external::target='.$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 getfilenothere {
   my ($filename) = @_;    my ($filename) = @_;
   my $a="";    my $a="";
   &Apache::lonnet::repcopy($filename);    if (! -e $filename ) {
       &Apache::lonnet::subscribe($filename);
       &Apache::lonnet::repcopy($filename);
     }
   {    {
     my $fh=Apache::File->new($filename);      my $fh=Apache::File->new($filename);
   
Line 63  sub getfile { Line 86  sub getfile {
   return $a    return $a
 }  }
   
   sub handler {
     my $request=shift;
   
     $Apache::lonxml::debug=1;
     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);
     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 $result=&subhandler(&get_target(),$problem);
   
     #$request->print("Result follows:");
     $request->print($result);
     #$request->print(":Result ends");
   
     my $temp;
     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");
   
     &Apache::lonhomework::send_footer($request);
     ($temp) = keys %Apache::lonhomework::results;
     if ( $temp ne '' ) {
       &Apache::lonxml::debug("Store return message:".&Apache::lonnet::cstore(%Apache::lonhomework::results));
     }
     return 'OK';
   
   }
   
 1;  1;
 __END__  __END__

Removed from v.1.6  
changed lines
  Added in v.1.17


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