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

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.1       albertel   11: 
                     12: sub handler {
                     13:   my $request=shift;
                     14: 
1.5     ! albertel   15:   my $target=&get_target();
1.2       albertel   16:   $request->content_type('text/html');
                     17:   $request->send_http_header;
                     18:   &Apache::lonhomework::send_header($request);
                     19:   my $file = "/home/httpd/html".$request->uri;
                     20:   my %mystyle;
1.5     ! albertel   21:   my $result = '';
1.2       albertel   22:   &Apache::inputtags::initialize_inputtags;
1.5     ! albertel   23:   if ($target eq "web") {
        !            24:     $result = Apache::lonxml::xmlparse($target,'<scriptlib>/res/103/albertel/default_homework</scriptlib>'.&setup_vars($target).&getfile($file),%mystyle);
        !            25:   } else {
        !            26:     $result = Apache::lonxml::xmlparse($target,&getfile($file),%mystyle);
        !            27:   }
1.2       albertel   28:   #$request->print("Result follows:");
                     29:   $request->print($result);
                     30:   #$request->print(":Result ends");
                     31:   &Apache::lonhomework::send_footer($request);
1.3       albertel   32: }
                     33: 
1.5     ! albertel   34: sub get_target {
        !            35:   return "edit";
        !            36: }
        !            37: 
1.3       albertel   38: sub setup_vars {
1.5     ! albertel   39:   my ($target) = @_;
        !            40:   $Apache::lonhomework::target=$target;
        !            41:   return '<script>$external::target='.$target.';</script>';
1.2       albertel   42: }
                     43: 
                     44: sub send_header {
                     45:   my ($request)= @_;
                     46:   $request->print('<html>');
                     47:   $request->print('<form method="POST" action="'.$request->uri.'">');
                     48: }
                     49: 
                     50: sub send_footer {
                     51:   my ($request)= @_;
                     52:   $request->print('</form>');
                     53:   $request->print('</html>');
                     54: }
                     55: 
                     56: sub getfile {
                     57:   my ($filename) = @_;
                     58:   my $a="";
                     59:   &Apache::lonnet::repcopy($filename);
1.1       albertel   60:   {
1.2       albertel   61:     my $fh=Apache::File->new($filename);
                     62: 
                     63:     while (<$fh>) {
                     64:       $a .=$_;
                     65:     }
1.1       albertel   66:   }
1.2       albertel   67:   return $a
1.1       albertel   68: }
                     69: 
                     70: 1;
                     71: __END__

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