Annotation of loncom/homework/externalresponse.pm, revision 1.4
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # external style responses
3: #
1.4 ! albertel 4: # $Id: externalresponse.pm,v 1.3 2003/04/08 02:40:56 albertel Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # 1/26 Guy
29: package Apache::externalresponse;
30: use strict;
31: use HTTP::Request::Common;
32: use Apache::loncapagrade;
1.4 ! albertel 33: use Apache::lonnet;
1.1 albertel 34:
35: BEGIN {
36: &Apache::lonxml::register('Apache::externalresponse',('externalresponse'));
37: }
38:
39: #FIXME
40: # send of response params and there current values
41: # accept a string to be printed out (Where does it get shown?) (.message)
42: # need to get a correct answer from somewhere (probably here since randomized)
43: sub start_externalresponse {
44: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
45: my $result;
46: my $id = &Apache::response::start_response($parstack,$safeeval);
47: return $result;
48: }
49:
50: sub end_externalresponse {
51: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
52: my $result;
53: if ($target eq 'grade') {
1.4 ! albertel 54: if ( defined $env{'form.submitted'}) {
1.1 albertel 55: my $id = $Apache::inputtags::response['-1'];
1.4 ! albertel 56: my $response = $env{'form.HWVAL_'.$id};
1.1 albertel 57: if ( $response =~ /[^\s]/) {
58: my $url = &Apache::lonxml::get_param('url',$parstack,$safeeval);
59: my $answer = &Apache::lonxml::get_param('answer',$parstack,$safeeval);
60: my %form = &Apache::lonxml::get_param_var('form',$parstack,$safeeval);
61: $form{'LONCAPA_student_response'}=$response;
62: $form{'LONCAPA_correct_answer'}=$answer;
63: $form{'LONCAPA_language'}=
1.2 albertel 64: &Apache::lonnet::metadata($ENV{'REQUEST_URI'},'language');
1.1 albertel 65: &Apache::lonxml::debug("Asking $url, with:");
66: &Apache::lonhomework::showhash(%form);
67: my $ua = LWP::UserAgent->new;
68: my $res = $ua->request(POST $url, \%form);
69: my $partid = $Apache::inputtags::part;
70: my $id = $Apache::inputtags::response['-1'];
71: my %previous = &Apache::response::check_for_previous($response,
72: $partid,$id);
73: %Apache::loncapagrade::results=();
74: if ($res->{_rc} != '200') {
75: $Apache::loncapagrade::results{'awardetail'}='ERROR';
76: } else {
77: &Apache::lonxml::register('Apache::loncapagrade',('loncapagrade'));
78: my $result=&Apache::scripttag::xmlparse($res->{_content});
79: &Apache::lonxml::debug("Got a result of :$result:");
80: }
81: foreach my $key (%Apache::loncapagrade::results) {
82: $Apache::lonhomework::results{"resource.$partid.$id.$key"}=
83: $Apache::loncapagrade::results{$key};
84: }
85: &Apache::response::handle_previous(\%previous,
86: $Apache::loncapagrade::results{'awarddetail'});
87: &Apache::lonxml::debug("response of");
88: &Apache::lonhomework::showhash(%$res);
89: &Apache::lonhomework::showhash(%Apache::loncapagrade::results);
90: }
91: }
92: }
93: &Apache::response::end_response;
94: return $result;
95: }
96:
97: 1;
98: __END__
99:
100:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>