1: # The LearningOnline Network with CAPA
2: # external style responses
3: #
4: # $Id: externalresponse.pm,v 1.14 2008/11/10 13:18:19 jms 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: =pod
30:
31: =head1 NAME
32:
33: Apache::externalresponse.pm
34:
35: =head1 SYNOPSIS
36:
37: Handler to evaluate externally graded responses.
38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
42:
43: =cut
44:
45: package Apache::externalresponse;
46: use strict;
47: use HTTP::Request::Common;
48: use Apache::loncapagrade;
49: use Apache::lonnet;
50:
51: BEGIN {
52: &Apache::lonxml::register('Apache::externalresponse',('externalresponse'));
53: }
54:
55: =pod
56:
57: =head1 FIXME
58:
59: send of response params and their current values (form good enough? what parameters to send?)
60: Need to get returned message displayed
61:
62: =cut
63:
64:
65: sub start_externalresponse {
66: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
67: my $result;
68: my $id = &Apache::response::start_response($parstack,$safeeval);
69:
70: if ($target eq 'edit') {
71: $result .=&Apache::edit::tag_start($target,$token);
72: $result .=&Apache::edit::text_arg('URL:','url',$token,60).'<br />';
73: $result .=&Apache::edit::text_arg('Answer:','answer',$token);
74: $result .=&Apache::edit::text_arg('Form:','form',$token);
75: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
76: } elsif ($target eq 'modified') {
77: my $constructtag =
78: &Apache::edit::get_new_args($token,$parstack,$safeeval,
79: 'answer','form','url');
80: if ($constructtag) {
81: $result = &Apache::edit::rebuild_tag($token);
82: }
83: } elsif ($target eq 'meta') {
84: $result=&Apache::response::meta_package_write('externalresponse');
85: }
86:
87: return $result;
88: }
89:
90: sub end_externalresponse {
91: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
92: my $result;
93: my $part=$Apache::inputtags::part;
94: my $id = $Apache::inputtags::response['-1'];
95: my $increment = 1;
96: if ($target eq 'grade') {
97: if ( &Apache::response::submitted('scantron') ) {
98: my $increment=&Apache::response::scored_response($part,$id);
99: } elsif ( &Apache::response::submitted() ) {
100: my $response = &Apache::response::getresponse();
101: if ( $response =~ /[^\s]/) {
102: my $url = &Apache::lonxml::get_param('url',$parstack,$safeeval);
103: my $answer = &Apache::lonxml::get_param('answer',$parstack,$safeeval);
104: my %form = &Apache::lonxml::get_param_var('form',$parstack,$safeeval);
105: $form{'LONCAPA_student_response'}=$response;
106: $form{'LONCAPA_correct_answer'}=$answer;
107: $form{'LONCAPA_language'}=
108: &Apache::lonnet::metadata($ENV{'REQUEST_URI'},'language');
109: &Apache::lonxml::debug("Asking $url, with:");
110: &Apache::lonhomework::showhash(%form);
111: my $ua = LWP::UserAgent->new;
112: my $res = $ua->request(POST $url, \%form);
113: my %previous = &Apache::response::check_for_previous($response,
114: $part,$id);
115: %Apache::loncapagrade::results=();
116: $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
117: if ($res->is_error()) {
118: $Apache::loncapagrade::results{'awarddetail'}='ERROR';
119: } else {
120: &Apache::lonxml::register('Apache::loncapagrade',
121: ('loncapagrade'));
122: @Apache::scripttag::parser_env = @_;
123: my $result=&Apache::scripttag::xmlparse($res->{_content});
124: &Apache::lonxml::debug("Got a result of :$result:");
125: }
126: foreach my $key (keys(%Apache::loncapagrade::results)) {
127: $Apache::lonhomework::results{"resource.$part.$id.$key"}=
128: $Apache::loncapagrade::results{$key};
129: }
130: &Apache::response::handle_previous(\%previous,
131: $Apache::loncapagrade::results{'awarddetail'});
132: &Apache::lonxml::debug("response of");
133: &Apache::lonhomework::showhash(%$res);
134: &Apache::lonxml::debug("capagrade of");
135: &Apache::lonhomework::showhash(%Apache::loncapagrade::results);
136: &Apache::lonxml::debug("results of");
137: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
138: }
139: }
140: }
141: if ($target eq 'web') {
142: &Apache::response::setup_prior_tries_hash(\&format_prior_response);
143: }
144:
145: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
146: $target eq 'tex' || $target eq 'analyze') {
147: &Apache::lonxml::increment_counter($increment, "$part.$id");
148:
149: if ($target eq 'analyze') {
150: $Apache::lonhomework::analyze{"$part.$id.type"} = 'externalresponse';
151: &Apache::lonhomework::set_bubble_lines();
152: }
153: }
154: &Apache::response::end_response();
155: return $result;
156: }
157:
158: sub format_prior_response {
159: my ($mode,$answer) =@_;
160: return '<span class="LC_prior_external">'.
161: &HTML::Entities::encode($answer,'"<>&').'</span>';
162: }
163:
164: 1;
165: __END__
166:
167:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>