Annotation of loncom/homework/lonhomework.pm, revision 1.14

1.1       albertel    1: # The LON-CAPA Homework handler
                      2: # Guy Albertelli
                      3: 
                      4: package Apache::lonhomework;
                      5: use strict;
                      6: use Apache::style;
                      7: use Apache::lonxml;
1.2       albertel    8: use Apache::lonnet;
                      9: use Apache::inputtags;
                     10: use Apache::structuretags;
1.9       albertel   11: use Apache::response;
1.1       albertel   12: 
                     13: sub handler {
                     14:   my $request=shift;
                     15: 
1.5       albertel   16:   my $target=&get_target();
1.12      albertel   17:   $Apache::lonxml::debug=1;
1.14    ! albertel   18:   if ($ENV{'browser.mathml'}) {
        !            19:     $request->content_type('text/xml');
        !            20:   } else {
        !            21:     $request->content_type('text/html');
        !            22:   }
1.2       albertel   23:   $request->send_http_header;
1.14    ! albertel   24:   return 'OK' if $request->header_only;
        !            25: 
1.2       albertel   26:   &Apache::lonhomework::send_header($request);
1.8       albertel   27:   my $file = "/home/httpd/html".$request->uri;
1.2       albertel   28:   my %mystyle;
1.5       albertel   29:   my $result = '';
1.2       albertel   30:   &Apache::inputtags::initialize_inputtags;
1.13      albertel   31: 
                     32:   my $problem=&Apache::lonnet::getfile($file);
                     33:   if ($problem == -1) {
                     34:     &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
                     35:     $problem='';
                     36:   }
                     37:   my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
                     38:   if ($default == -1) {
                     39:     &Apache::lonxml::error("<b>Unable to find <i>$file</i></b>");
                     40:     $default='';
                     41:   }
                     42: 
                     43:   $result = Apache::lonxml::xmlparse($target, $problem,
                     44: 				     $default.&setup_vars($target),%mystyle);
1.2       albertel   45:   #$request->print("Result follows:");
                     46:   $request->print($result);
                     47:   #$request->print(":Result ends");
                     48:   &Apache::lonhomework::send_footer($request);
1.14    ! albertel   49:   return 'OK';
1.3       albertel   50: }
                     51: 
1.5       albertel   52: sub get_target {
1.6       albertel   53:   return "web";
1.5       albertel   54: }
                     55: 
1.3       albertel   56: sub setup_vars {
1.5       albertel   57:   my ($target) = @_;
1.11      albertel   58:   return ';'
                     59: #  return ';$external::target='.$target.';';
1.2       albertel   60: }
                     61: 
                     62: sub send_header {
                     63:   my ($request)= @_;
1.14    ! albertel   64:   $request->print(&Apache::lontexconvert::header());
        !            65:   $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');
1.2       albertel   66: }
                     67: 
                     68: sub send_footer {
                     69:   my ($request)= @_;
                     70:   $request->print('</form>');
1.14    ! albertel   71:   $request->print(&Apache::lontexconvert::footer());
1.2       albertel   72: }
                     73: 
                     74: sub getfile {
                     75:   my ($filename) = @_;
                     76:   my $a="";
1.8       albertel   77:   if (! -e $filename ) {
                     78:     &Apache::lonnet::subscribe($filename);
                     79:     &Apache::lonnet::repcopy($filename);
                     80:   }
1.1       albertel   81:   {
1.8       albertel   82:     my $fh=Apache::File->new($filename);
1.2       albertel   83: 
                     84:     while (<$fh>) {
                     85:       $a .=$_;
                     86:     }
1.1       albertel   87:   }
1.2       albertel   88:   return $a
1.1       albertel   89: }
                     90: 
                     91: 1;
                     92: __END__

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