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