--- loncom/homework/externalresponse.pm 2005/10/18 15:33:55 1.6
+++ loncom/homework/externalresponse.pm 2014/02/26 20:52:11 1.19.10.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# external style responses
#
-# $Id: externalresponse.pm,v 1.6 2005/10/18 15:33:55 albertel Exp $
+# $Id: externalresponse.pm,v 1.19.10.1 2014/02/26 20:52:11 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,24 +26,52 @@
# http://www.lon-capa.org/
#
+
+
package Apache::externalresponse;
use strict;
use HTTP::Request::Common;
use Apache::loncapagrade;
use Apache::lonnet;
+use Apache::lonlocal;
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)
+=pod
+
+=head1 FIXME (start_externalresponse)
+
+send of response params and their current values (form good enough? what parameters to send?)
+Need to get returned message displayed
+
+=cut
+
+
sub start_externalresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
my $id = &Apache::response::start_response($parstack,$safeeval);
+
+ if ($target eq 'edit') {
+ $result .=&Apache::edit::tag_start($target,$token);
+ $result .=&Apache::edit::text_arg('URL:','url',$token,60).'
';
+ $result .=&Apache::edit::text_arg(&mt('Answer:'),'answer',$token);
+ $result .=&Apache::edit::text_arg(&mt('Form:'),'form',$token).'
';
+ $result .=&Apache::edit::text_arg(&mt('Answer display:'),'answerdisplay',$token,80);
+ $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
+ } elsif ($target eq 'modified') {
+ my $constructtag =
+ &Apache::edit::get_new_args($token,$parstack,$safeeval,
+ 'answerdisplay','answer','form','url');
+ if ($constructtag) {
+ $result = &Apache::edit::rebuild_tag($token);
+ }
+ } elsif ($target eq 'meta') {
+ $result=&Apache::response::meta_package_write('externalresponse');
+ }
+
return $result;
}
@@ -74,11 +102,12 @@ sub end_externalresponse {
$part,$id);
%Apache::loncapagrade::results=();
$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
- if ($res->{_rc} != '200') {
+ if ($res->is_error()) {
$Apache::loncapagrade::results{'awarddetail'}='ERROR';
} else {
&Apache::lonxml::register('Apache::loncapagrade',
('loncapagrade'));
+ @Apache::scripttag::parser_env = @_;
my $result=&Apache::scripttag::xmlparse($res->{_content});
&Apache::lonxml::debug("Got a result of :$result:");
}
@@ -86,8 +115,13 @@ sub end_externalresponse {
$Apache::lonhomework::results{"resource.$part.$id.$key"}=
$Apache::loncapagrade::results{$key};
}
+ $Apache::externalresponse::message=$Apache::loncapagrade::results{'message'};
&Apache::response::handle_previous(\%previous,
$Apache::loncapagrade::results{'awarddetail'});
+ if ($Apache::loncapagrade::results{'awarddetail'} eq 'ASSIGNED_SCORE') {
+ $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
+ 1.*$Apache::loncapagrade::results{"awarded"};
+ }
&Apache::lonxml::debug("response of");
&Apache::lonhomework::showhash(%$res);
&Apache::lonxml::debug("capagrade of");
@@ -97,15 +131,67 @@ sub end_externalresponse {
}
}
}
+ if ($target eq 'web') {
+ &Apache::response::setup_prior_tries_hash(\&format_prior_response);
+ if (&Apache::response::show_answer()) {
+ $result.='
'.&mt('Your answer:').' |
---|
'.
+ &HTML::Entities::encode(
+ $Apache::lonhomework::history{"resource.$part.$id.submission"},'"<>&').
+ ' |
'.&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval).
+ '
';
+ }
+ if ($Apache::externalresponse::message) {
+ $result.='
'.$Apache::externalresponse::message.' |
';
+ }
+ $Apache::externalresponse::message='';
+ }
+
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
$target eq 'tex' || $target eq 'analyze') {
- &Apache::lonxml::increment_counter($increment);
+ &Apache::lonxml::increment_counter($increment, "$part.$id");
+
+ if ($target eq 'analyze') {
+ $Apache::lonhomework::analyze{"$part.$id.type"} = 'externalresponse';
+ &Apache::lonhomework::set_bubble_lines();
+ }
}
&Apache::response::end_response();
return $result;
}
+sub format_prior_response {
+ my ($mode,$answer) =@_;
+ return ''.
+ &HTML::Entities::encode($answer,'"<>&').'';
+}
+
1;
__END__
+=pod
+
+=head1 NAME
+
+Apache::externalresponse.pm
+
+=head1 SYNOPSIS
+
+Handler to evaluate externally graded responses.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 SUBROUTINES
+
+=over
+
+=item start_externalresponse()
+
+=item end_externalresponse()
+
+=item format_prior_response()
+
+=back
+
+=cut