File:
[LON-CAPA] /
loncom /
homework /
externalresponse.pm
Revision
1.7:
download - view:
text,
annotated -
select for diffs
Wed Apr 18 00:19:37 2007 UTC (17 years, 5 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_5_X,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_99_0,
HEAD
- 2622 for math, external, custom
1: # The LearningOnline Network with CAPA
2: # external style responses
3: #
4: # $Id: externalresponse.pm,v 1.7 2007/04/18 00:19:37 albertel Exp $
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:
29: package Apache::externalresponse;
30: use strict;
31: use HTTP::Request::Common;
32: use Apache::loncapagrade;
33: use Apache::lonnet;
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: my $part=$Apache::inputtags::part;
54: my $id = $Apache::inputtags::response['-1'];
55: my $increment = 1;
56: if ($target eq 'grade') {
57: if ( &Apache::response::submitted('scantron') ) {
58: my $increment=&Apache::response::scored_response($part,$id);
59: } elsif ( &Apache::response::submitted() ) {
60: my $response = &Apache::response::getresponse();
61: if ( $response =~ /[^\s]/) {
62: my $url = &Apache::lonxml::get_param('url',$parstack,$safeeval);
63: my $answer = &Apache::lonxml::get_param('answer',$parstack,$safeeval);
64: my %form = &Apache::lonxml::get_param_var('form',$parstack,$safeeval);
65: $form{'LONCAPA_student_response'}=$response;
66: $form{'LONCAPA_correct_answer'}=$answer;
67: $form{'LONCAPA_language'}=
68: &Apache::lonnet::metadata($ENV{'REQUEST_URI'},'language');
69: &Apache::lonxml::debug("Asking $url, with:");
70: &Apache::lonhomework::showhash(%form);
71: my $ua = LWP::UserAgent->new;
72: my $res = $ua->request(POST $url, \%form);
73: my %previous = &Apache::response::check_for_previous($response,
74: $part,$id);
75: %Apache::loncapagrade::results=();
76: $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
77: if ($res->{_rc} != '200') {
78: $Apache::loncapagrade::results{'awarddetail'}='ERROR';
79: } else {
80: &Apache::lonxml::register('Apache::loncapagrade',
81: ('loncapagrade'));
82: my $result=&Apache::scripttag::xmlparse($res->{_content});
83: &Apache::lonxml::debug("Got a result of :$result:");
84: }
85: foreach my $key (keys(%Apache::loncapagrade::results)) {
86: $Apache::lonhomework::results{"resource.$part.$id.$key"}=
87: $Apache::loncapagrade::results{$key};
88: }
89: &Apache::response::handle_previous(\%previous,
90: $Apache::loncapagrade::results{'awarddetail'});
91: &Apache::lonxml::debug("response of");
92: &Apache::lonhomework::showhash(%$res);
93: &Apache::lonxml::debug("capagrade of");
94: &Apache::lonhomework::showhash(%Apache::loncapagrade::results);
95: &Apache::lonxml::debug("results of");
96: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
97: }
98: }
99: }
100: if ($target eq 'web') {
101: &Apache::response::setup_prior_tries_hash(\&format_prior_response);
102: }
103:
104: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
105: $target eq 'tex' || $target eq 'analyze') {
106: &Apache::lonxml::increment_counter($increment);
107: }
108: &Apache::response::end_response();
109: return $result;
110: }
111:
112: sub format_prior_response {
113: my ($mode,$answer) =@_;
114: return '<span class="LC_prior_external">'.
115: &HTML::Entities::encode($answer,'"<>&').'</span>';
116: }
117:
118: 1;
119: __END__
120:
121:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>