File:  [LON-CAPA] / loncom / homework / lonhomework.pm
Revision 1.13: download - view: text, annotated - select for diffs
Thu Oct 5 19:25:38 2000 UTC (23 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- uses the new lonnet getfile routine

    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;
    8: use Apache::lonnet;
    9: use Apache::inputtags;
   10: use Apache::structuretags;
   11: use Apache::response;
   12: 
   13: sub handler {
   14:   my $request=shift;
   15: 
   16:   my $target=&get_target();
   17:   $Apache::lonxml::debug=1;
   18:   $request->content_type('text/html');
   19:   $request->send_http_header;
   20:   &Apache::lonhomework::send_header($request);
   21:   my $file = "/home/httpd/html".$request->uri;
   22:   my %mystyle;
   23:   my $result = '';
   24:   &Apache::inputtags::initialize_inputtags;
   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);
   39:   #$request->print("Result follows:");
   40:   $request->print($result);
   41:   #$request->print(":Result ends");
   42:   &Apache::lonhomework::send_footer($request);
   43: }
   44: 
   45: sub get_target {
   46:   return "web";
   47: }
   48: 
   49: sub setup_vars {
   50:   my ($target) = @_;
   51:   return ';'
   52: #  return ';$external::target='.$target.';';
   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="";
   70:   if (! -e $filename ) {
   71:     &Apache::lonnet::subscribe($filename);
   72:     &Apache::lonnet::repcopy($filename);
   73:   }
   74:   {
   75:     my $fh=Apache::File->new($filename);
   76: 
   77:     while (<$fh>) {
   78:       $a .=$_;
   79:     }
   80:   }
   81:   return $a
   82: }
   83: 
   84: 1;
   85: __END__

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