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

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;
1.15    ! albertel   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.15    ! albertel   27:   my $file = &Apache::lonnet::filelocation("",$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.15    ! albertel   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:   }
1.5       albertel   62: }
                     63: 
1.3       albertel   64: sub setup_vars {
1.5       albertel   65:   my ($target) = @_;
1.11      albertel   66:   return ';'
                     67: #  return ';$external::target='.$target.';';
1.2       albertel   68: }
                     69: 
                     70: sub send_header {
                     71:   my ($request)= @_;
1.14      albertel   72:   $request->print(&Apache::lontexconvert::header());
                     73:   $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');
1.2       albertel   74: }
                     75: 
                     76: sub send_footer {
                     77:   my ($request)= @_;
                     78:   $request->print('</form>');
1.14      albertel   79:   $request->print(&Apache::lontexconvert::footer());
1.2       albertel   80: }
                     81: 
1.15    ! albertel   82: sub getfilenothere {
1.2       albertel   83:   my ($filename) = @_;
                     84:   my $a="";
1.8       albertel   85:   if (! -e $filename ) {
                     86:     &Apache::lonnet::subscribe($filename);
                     87:     &Apache::lonnet::repcopy($filename);
                     88:   }
1.1       albertel   89:   {
1.8       albertel   90:     my $fh=Apache::File->new($filename);
1.2       albertel   91: 
                     92:     while (<$fh>) {
                     93:       $a .=$_;
                     94:     }
1.1       albertel   95:   }
1.2       albertel   96:   return $a
1.1       albertel   97: }
                     98: 
                     99: 1;
                    100: __END__

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