File:  [LON-CAPA] / loncom / homework / lonhomework.pm
Revision 1.14: download - view: text, annotated - select for diffs
Wed Oct 11 21:02:13 2000 UTC (23 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- generates a new tth compliant header

# The LON-CAPA Homework handler
# Guy Albertelli

package Apache::lonhomework;
use strict;
use Apache::style;
use Apache::lonxml;
use Apache::lonnet;
use Apache::inputtags;
use Apache::structuretags;
use Apache::response;

sub handler {
  my $request=shift;

  my $target=&get_target();
  $Apache::lonxml::debug=1;
  if ($ENV{'browser.mathml'}) {
    $request->content_type('text/xml');
  } else {
    $request->content_type('text/html');
  }
  $request->send_http_header;
  return 'OK' if $request->header_only;

  &Apache::lonhomework::send_header($request);
  my $file = "/home/httpd/html".$request->uri;
  my %mystyle;
  my $result = '';
  &Apache::inputtags::initialize_inputtags;

  my $problem=&Apache::lonnet::getfile($file);
  if ($problem == -1) {
    &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
    $problem='';
  }
  my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
  if ($default == -1) {
    &Apache::lonxml::error("<b>Unable to find <i>$file</i></b>");
    $default='';
  }

  $result = Apache::lonxml::xmlparse($target, $problem,
				     $default.&setup_vars($target),%mystyle);
  #$request->print("Result follows:");
  $request->print($result);
  #$request->print(":Result ends");
  &Apache::lonhomework::send_footer($request);
  return 'OK';
}

sub get_target {
  return "web";
}

sub setup_vars {
  my ($target) = @_;
  return ';'
#  return ';$external::target='.$target.';';
}

sub send_header {
  my ($request)= @_;
  $request->print(&Apache::lontexconvert::header());
  $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');
}

sub send_footer {
  my ($request)= @_;
  $request->print('</form>');
  $request->print(&Apache::lontexconvert::footer());
}

sub getfile {
  my ($filename) = @_;
  my $a="";
  if (! -e $filename ) {
    &Apache::lonnet::subscribe($filename);
    &Apache::lonnet::repcopy($filename);
  }
  {
    my $fh=Apache::File->new($filename);

    while (<$fh>) {
      $a .=$_;
    }
  }
  return $a
}

1;
__END__

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