File:
[LON-CAPA] /
loncom /
homework /
externalresponse.pm
Revision
1.3:
download - view:
text,
annotated -
select for diffs
Tue Apr 8 02:40:56 2003 UTC (21 years, 4 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_X,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
version_1_1_3,
version_1_1_2,
version_1_1_1,
version_1_1_0,
version_1_0_99_3,
version_1_0_99_2,
version_1_0_99_1,
version_1_0_99,
version_1_0_3,
version_1_0_2,
version_1_0_1,
version_1_0_0,
version_0_99_5,
version_0_99_4,
version_0_99_3,
version_0_99_2,
version_0_99_1,
version_0_99_0,
conference_2003,
HEAD
- brining consitancy to the homework input fields
# The LearningOnline Network with CAPA
# external style responses
#
# $Id: externalresponse.pm,v 1.3 2003/04/08 02:40:56 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# 1/26 Guy
package Apache::externalresponse;
use strict;
use HTTP::Request::Common;
use Apache::loncapagrade;
BEGIN {
&Apache::lonxml::register('Apache::externalresponse',('externalresponse'));
}
#FIXME
# send of response params and there current values
# accept a string to be printed out (Where does it get shown?) (.message)
# need to get a correct answer from somewhere (probably here since randomized)
sub start_externalresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
my $id = &Apache::response::start_response($parstack,$safeeval);
return $result;
}
sub end_externalresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
if ($target eq 'grade') {
if ( defined $ENV{'form.submitted'}) {
my $id = $Apache::inputtags::response['-1'];
my $response = $ENV{'form.HWVAL_'.$id};
if ( $response =~ /[^\s]/) {
my $url = &Apache::lonxml::get_param('url',$parstack,$safeeval);
my $answer = &Apache::lonxml::get_param('answer',$parstack,$safeeval);
my %form = &Apache::lonxml::get_param_var('form',$parstack,$safeeval);
$form{'LONCAPA_student_response'}=$response;
$form{'LONCAPA_correct_answer'}=$answer;
$form{'LONCAPA_language'}=
&Apache::lonnet::metadata($ENV{'REQUEST_URI'},'language');
&Apache::lonxml::debug("Asking $url, with:");
&Apache::lonhomework::showhash(%form);
my $ua = LWP::UserAgent->new;
my $res = $ua->request(POST $url, \%form);
my $partid = $Apache::inputtags::part;
my $id = $Apache::inputtags::response['-1'];
my %previous = &Apache::response::check_for_previous($response,
$partid,$id);
%Apache::loncapagrade::results=();
if ($res->{_rc} != '200') {
$Apache::loncapagrade::results{'awardetail'}='ERROR';
} else {
&Apache::lonxml::register('Apache::loncapagrade',('loncapagrade'));
my $result=&Apache::scripttag::xmlparse($res->{_content});
&Apache::lonxml::debug("Got a result of :$result:");
}
foreach my $key (%Apache::loncapagrade::results) {
$Apache::lonhomework::results{"resource.$partid.$id.$key"}=
$Apache::loncapagrade::results{$key};
}
&Apache::response::handle_previous(\%previous,
$Apache::loncapagrade::results{'awarddetail'});
&Apache::lonxml::debug("response of");
&Apache::lonhomework::showhash(%$res);
&Apache::lonhomework::showhash(%Apache::loncapagrade::results);
}
}
}
&Apache::response::end_response;
return $result;
}
1;
__END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>