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

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.2       albertel   18:   $request->content_type('text/html');
                     19:   $request->send_http_header;
                     20:   &Apache::lonhomework::send_header($request);
1.8       albertel   21:   my $file = "/home/httpd/html".$request->uri;
1.2       albertel   22:   my %mystyle;
1.5       albertel   23:   my $result = '';
1.2       albertel   24:   &Apache::inputtags::initialize_inputtags;
1.13    ! albertel   25: 
        !            26:   my $problem=&Apache::lonnet::getfile($file);
        !            27:   if ($problem == -1) {
        !            28:     &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
        !            29:     $problem='';
        !            30:   }
        !            31:   my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
        !            32:   if ($default == -1) {
        !            33:     &Apache::lonxml::error("<b>Unable to find <i>$file</i></b>");
        !            34:     $default='';
        !            35:   }
        !            36: 
        !            37:   $result = Apache::lonxml::xmlparse($target, $problem,
        !            38: 				     $default.&setup_vars($target),%mystyle);
1.2       albertel   39:   #$request->print("Result follows:");
                     40:   $request->print($result);
                     41:   #$request->print(":Result ends");
                     42:   &Apache::lonhomework::send_footer($request);
1.3       albertel   43: }
                     44: 
1.5       albertel   45: sub get_target {
1.6       albertel   46:   return "web";
1.5       albertel   47: }
                     48: 
1.3       albertel   49: sub setup_vars {
1.5       albertel   50:   my ($target) = @_;
1.11      albertel   51:   return ';'
                     52: #  return ';$external::target='.$target.';';
1.2       albertel   53: }
                     54: 
                     55: sub send_header {
                     56:   my ($request)= @_;
                     57:   $request->print('<html>');
                     58:   $request->print('<form method="POST" action="'.$request->uri.'">');
                     59: }
                     60: 
                     61: sub send_footer {
                     62:   my ($request)= @_;
                     63:   $request->print('</form>');
                     64:   $request->print('</html>');
                     65: }
                     66: 
                     67: sub getfile {
                     68:   my ($filename) = @_;
                     69:   my $a="";
1.8       albertel   70:   if (! -e $filename ) {
                     71:     &Apache::lonnet::subscribe($filename);
                     72:     &Apache::lonnet::repcopy($filename);
                     73:   }
1.1       albertel   74:   {
1.8       albertel   75:     my $fh=Apache::File->new($filename);
1.2       albertel   76: 
                     77:     while (<$fh>) {
                     78:       $a .=$_;
                     79:     }
1.1       albertel   80:   }
1.2       albertel   81:   return $a
1.1       albertel   82: }
                     83: 
                     84: 1;
                     85: __END__

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