Annotation of loncom/homework/lonhomework.pm, revision 1.17
1.1 albertel 1: # The LON-CAPA Homework handler
2: # Guy Albertelli
1.17 ! www 3: # 11/30 Gerd Kortemeyer
1.1 albertel 4:
5: package Apache::lonhomework;
6: use strict;
7: use Apache::style;
8: use Apache::lonxml;
1.2 albertel 9: use Apache::lonnet;
10: use Apache::inputtags;
11: use Apache::structuretags;
1.9 albertel 12: use Apache::response;
1.1 albertel 13:
1.16 albertel 14:
1.17 ! www 15: sub subhandler {
! 16: my ($target,$problem)=@_;
1.2 albertel 17: my %mystyle;
1.5 albertel 18: my $result = '';
1.2 albertel 19: &Apache::inputtags::initialize_inputtags;
1.16 albertel 20: %Apache::lonhomework::results=();
21: %Apache::lonhomework::history=&Apache::lonnet::restore;
22: #ignore error conditions
23: my ($temp)=keys %Apache::lonhomework::history ;
24: if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
25:
26: my $resultkey;
27: foreach $resultkey (sort keys %Apache::lonhomework::history) {
28: &Apache::lonxml::debug("$resultkey ---- $Apache::lonhomework::history{$resultkey}");
29: }
30: &Apache::lonxml::debug("\n<br>restored values^</br>\n");
1.13 albertel 31: my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
32: if ($default == -1) {
1.17 ! www 33: &Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
1.13 albertel 34: $default='';
35: }
36:
1.17 ! www 37: return Apache::lonxml::xmlparse($target, $problem,
1.13 albertel 38: $default.&setup_vars($target),%mystyle);
1.3 albertel 39: }
40:
1.5 albertel 41: sub get_target {
1.15 albertel 42: if ( $ENV{'request.state'} eq "published") {
43: return 'web';
44: } elsif ($ENV{'request.state'} eq "construct") {
1.16 albertel 45: if ( defined $ENV{'form.preview'}) {
1.15 albertel 46: return 'web';
47: } else {
48: return 'edit';
49: }
50: }
1.5 albertel 51: }
52:
1.3 albertel 53: sub setup_vars {
1.5 albertel 54: my ($target) = @_;
1.11 albertel 55: return ';'
56: # return ';$external::target='.$target.';';
1.2 albertel 57: }
58:
59: sub send_header {
60: my ($request)= @_;
1.14 albertel 61: $request->print(&Apache::lontexconvert::header());
1.16 albertel 62: $ENV{'request.uri'}=$request->uri;
63: # $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');
1.2 albertel 64: }
65:
66: sub send_footer {
67: my ($request)= @_;
1.16 albertel 68: # $request->print('</form>');
1.14 albertel 69: $request->print(&Apache::lontexconvert::footer());
1.2 albertel 70: }
71:
1.15 albertel 72: sub getfilenothere {
1.2 albertel 73: my ($filename) = @_;
74: my $a="";
1.8 albertel 75: if (! -e $filename ) {
76: &Apache::lonnet::subscribe($filename);
77: &Apache::lonnet::repcopy($filename);
78: }
1.1 albertel 79: {
1.8 albertel 80: my $fh=Apache::File->new($filename);
1.2 albertel 81:
82: while (<$fh>) {
83: $a .=$_;
84: }
1.1 albertel 85: }
1.2 albertel 86: return $a
1.17 ! www 87: }
! 88:
! 89: sub handler {
! 90: my $request=shift;
! 91:
! 92: $Apache::lonxml::debug=1;
! 93: if ($ENV{'browser.mathml'}) {
! 94: $request->content_type('text/xml');
! 95: } else {
! 96: $request->content_type('text/html');
! 97: }
! 98: $request->send_http_header;
! 99: return 'OK' if $request->header_only;
! 100:
! 101: &Apache::lonhomework::send_header($request);
! 102: my $file=&Apache::lonnet::filelocation("",$request->uri);
! 103: my $problem=&Apache::lonnet::getfile($file);
! 104: if ($problem == -1) {
! 105: &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
! 106: $problem='';
! 107: }
! 108:
! 109: my $result=&subhandler(&get_target(),$problem);
! 110:
! 111: #$request->print("Result follows:");
! 112: $request->print($result);
! 113: #$request->print(":Result ends");
! 114:
! 115: my $temp;
! 116: my $resultkey;
! 117: foreach $resultkey (sort keys %Apache::lonhomework::results) {
! 118: &Apache::lonxml::debug("$resultkey ---- $Apache::lonhomework::results{$resultkey}");
! 119: }
! 120: &Apache::lonxml::debug("\n<br>storing values^</br>\n");
! 121:
! 122: &Apache::lonhomework::send_footer($request);
! 123: ($temp) = keys %Apache::lonhomework::results;
! 124: if ( $temp ne '' ) {
! 125: &Apache::lonxml::debug("Store return message:".&Apache::lonnet::cstore(%Apache::lonhomework::results));
! 126: }
! 127: return 'OK';
! 128:
1.1 albertel 129: }
130:
131: 1;
132: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>