File:
[LON-CAPA] /
loncom /
homework /
externalresponse.pm
Revision
1.19.10.1:
download - view:
text,
annotated -
select for diffs
Wed Feb 26 20:52:11 2014 UTC (10 years, 5 months ago) by
raeburn
Branches:
version_2_11_X
CVS tags:
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0
Diff to branchpoint 1.19:
preferred,
unified
- For 2.11
- Backport 1.26.
1: # The LearningOnline Network with CAPA
2: # external style responses
3: #
4: # $Id: externalresponse.pm,v 1.19.10.1 2014/02/26 20:52:11 raeburn 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:
30:
31: package Apache::externalresponse;
32: use strict;
33: use HTTP::Request::Common;
34: use Apache::loncapagrade;
35: use Apache::lonnet;
36: use Apache::lonlocal;
37:
38: BEGIN {
39: &Apache::lonxml::register('Apache::externalresponse',('externalresponse'));
40: }
41:
42: =pod
43:
44: =head1 FIXME (start_externalresponse)
45:
46: send of response params and their current values (form good enough? what parameters to send?)
47: Need to get returned message displayed
48:
49: =cut
50:
51:
52: sub start_externalresponse {
53: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
54: my $result;
55: my $id = &Apache::response::start_response($parstack,$safeeval);
56:
57: if ($target eq 'edit') {
58: $result .=&Apache::edit::tag_start($target,$token);
59: $result .=&Apache::edit::text_arg('URL:','url',$token,60).'<br />';
60: $result .=&Apache::edit::text_arg(&mt('Answer:'),'answer',$token);
61: $result .=&Apache::edit::text_arg(&mt('Form:'),'form',$token).'<br />';
62: $result .=&Apache::edit::text_arg(&mt('Answer display:'),'answerdisplay',$token,80);
63: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
64: } elsif ($target eq 'modified') {
65: my $constructtag =
66: &Apache::edit::get_new_args($token,$parstack,$safeeval,
67: 'answerdisplay','answer','form','url');
68: if ($constructtag) {
69: $result = &Apache::edit::rebuild_tag($token);
70: }
71: } elsif ($target eq 'meta') {
72: $result=&Apache::response::meta_package_write('externalresponse');
73: }
74:
75: return $result;
76: }
77:
78: sub end_externalresponse {
79: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
80: my $result;
81: my $part=$Apache::inputtags::part;
82: my $id = $Apache::inputtags::response['-1'];
83: my $increment = 1;
84: if ($target eq 'grade') {
85: if ( &Apache::response::submitted('scantron') ) {
86: my $increment=&Apache::response::scored_response($part,$id);
87: } elsif ( &Apache::response::submitted() ) {
88: my $response = &Apache::response::getresponse();
89: if ( $response =~ /[^\s]/) {
90: my $url = &Apache::lonxml::get_param('url',$parstack,$safeeval);
91: my $answer = &Apache::lonxml::get_param('answer',$parstack,$safeeval);
92: my %form = &Apache::lonxml::get_param_var('form',$parstack,$safeeval);
93: $form{'LONCAPA_student_response'}=$response;
94: $form{'LONCAPA_correct_answer'}=$answer;
95: $form{'LONCAPA_language'}=
96: &Apache::lonnet::metadata($ENV{'REQUEST_URI'},'language');
97: &Apache::lonxml::debug("Asking $url, with:");
98: &Apache::lonhomework::showhash(%form);
99: my $ua = LWP::UserAgent->new;
100: my $res = $ua->request(POST $url, \%form);
101: my %previous = &Apache::response::check_for_previous($response,
102: $part,$id);
103: %Apache::loncapagrade::results=();
104: $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
105: if ($res->is_error()) {
106: $Apache::loncapagrade::results{'awarddetail'}='ERROR';
107: } else {
108: &Apache::lonxml::register('Apache::loncapagrade',
109: ('loncapagrade'));
110: @Apache::scripttag::parser_env = @_;
111: my $result=&Apache::scripttag::xmlparse($res->{_content});
112: &Apache::lonxml::debug("Got a result of :$result:");
113: }
114: foreach my $key (keys(%Apache::loncapagrade::results)) {
115: $Apache::lonhomework::results{"resource.$part.$id.$key"}=
116: $Apache::loncapagrade::results{$key};
117: }
118: $Apache::externalresponse::message=$Apache::loncapagrade::results{'message'};
119: &Apache::response::handle_previous(\%previous,
120: $Apache::loncapagrade::results{'awarddetail'});
121: if ($Apache::loncapagrade::results{'awarddetail'} eq 'ASSIGNED_SCORE') {
122: $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
123: 1.*$Apache::loncapagrade::results{"awarded"};
124: }
125: &Apache::lonxml::debug("response of");
126: &Apache::lonhomework::showhash(%$res);
127: &Apache::lonxml::debug("capagrade of");
128: &Apache::lonhomework::showhash(%Apache::loncapagrade::results);
129: &Apache::lonxml::debug("results of");
130: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
131: }
132: }
133: }
134: if ($target eq 'web') {
135: &Apache::response::setup_prior_tries_hash(\&format_prior_response);
136: if (&Apache::response::show_answer()) {
137: $result.='<table border="1"><tr><th>'.&mt('Your answer:').'</th></tr><tr><td><pre>'.
138: &HTML::Entities::encode(
139: $Apache::lonhomework::history{"resource.$part.$id.submission"},'"<>&').
140: '</pre></td></table><br />'.&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval).
141: '<br />';
142: }
143: if ($Apache::externalresponse::message) {
144: $result.='<br /><table><tr><td bgcolor="#FFFFAA">'.$Apache::externalresponse::message.'</td></tr></table><br />';
145: }
146: $Apache::externalresponse::message='';
147: }
148:
149: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
150: $target eq 'tex' || $target eq 'analyze') {
151: &Apache::lonxml::increment_counter($increment, "$part.$id");
152:
153: if ($target eq 'analyze') {
154: $Apache::lonhomework::analyze{"$part.$id.type"} = 'externalresponse';
155: &Apache::lonhomework::set_bubble_lines();
156: }
157: }
158: &Apache::response::end_response();
159: return $result;
160: }
161:
162: sub format_prior_response {
163: my ($mode,$answer) =@_;
164: return '<span class="LC_prior_external">'.
165: &HTML::Entities::encode($answer,'"<>&').'</span>';
166: }
167:
168: 1;
169: __END__
170:
171:
172: =pod
173:
174: =head1 NAME
175:
176: Apache::externalresponse.pm
177:
178: =head1 SYNOPSIS
179:
180: Handler to evaluate externally graded responses.
181:
182: This is part of the LearningOnline Network with CAPA project
183: described at http://www.lon-capa.org.
184:
185: =head1 SUBROUTINES
186:
187: =over
188:
189: =item start_externalresponse()
190:
191: =item end_externalresponse()
192:
193: =item format_prior_response()
194:
195: =back
196:
197: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>