File:  [LON-CAPA] / loncom / homework / lonhomework.pm
Revision 1.15: download - view: text, annotated - select for diffs
Tue Nov 7 17:21:18 2000 UTC (23 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- now uses lonnet::filelocation to figure where to get main file
- sets the target to be edit, if pulled from a /~user/ location

    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:   if ($ENV{'browser.mathml'}) {
   19:     $request->content_type('text/xml');
   20:   } else {
   21:     $request->content_type('text/html');
   22:   }
   23:   $request->send_http_header;
   24:   return 'OK' if $request->header_only;
   25: 
   26:   &Apache::lonhomework::send_header($request);
   27:   my $file = &Apache::lonnet::filelocation("",$request->uri);
   28:   my %mystyle;
   29:   my $result = '';
   30:   &Apache::inputtags::initialize_inputtags;
   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);
   45:   #$request->print("Result follows:");
   46:   $request->print($result);
   47:   #$request->print(":Result ends");
   48:   &Apache::lonhomework::send_footer($request);
   49:   return 'OK';
   50: }
   51: 
   52: sub get_target {
   53:   if ( $ENV{'request.state'} eq "published") {
   54:     return 'web';
   55:   } elsif ($ENV{'request.state'} eq "construct") {
   56:     if ( defined $ENV{'form.'.$ENV{'form.request.prefix'}.'preview'}) {
   57:       return 'web';
   58:     } else {
   59:       return 'edit';
   60:     }
   61:   }
   62: }
   63: 
   64: sub setup_vars {
   65:   my ($target) = @_;
   66:   return ';'
   67: #  return ';$external::target='.$target.';';
   68: }
   69: 
   70: sub send_header {
   71:   my ($request)= @_;
   72:   $request->print(&Apache::lontexconvert::header());
   73:   $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');
   74: }
   75: 
   76: sub send_footer {
   77:   my ($request)= @_;
   78:   $request->print('</form>');
   79:   $request->print(&Apache::lontexconvert::footer());
   80: }
   81: 
   82: sub getfilenothere {
   83:   my ($filename) = @_;
   84:   my $a="";
   85:   if (! -e $filename ) {
   86:     &Apache::lonnet::subscribe($filename);
   87:     &Apache::lonnet::repcopy($filename);
   88:   }
   89:   {
   90:     my $fh=Apache::File->new($filename);
   91: 
   92:     while (<$fh>) {
   93:       $a .=$_;
   94:     }
   95:   }
   96:   return $a
   97: }
   98: 
   99: 1;
  100: __END__

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