[LON-CAPA-cvs] cvs: loncom /homework imageresponse.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 18 Apr 2007 01:06:22 -0000
albertel Tue Apr 17 21:06:22 2007 EDT
Modified files:
/loncom/homework imageresponse.pm
Log:
- bug2622 imageresponse
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.81 loncom/homework/imageresponse.pm:1.82
--- loncom/homework/imageresponse.pm:1.81 Wed Feb 21 20:25:31 2007
+++ loncom/homework/imageresponse.pm Tue Apr 17 21:06:22 2007
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# image click response style
#
-# $Id: imageresponse.pm,v 1.81 2007/02/22 01:25:31 albertel Exp $
+# $Id: imageresponse.pm,v 1.82 2007/04/18 01:06:22 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -132,15 +132,24 @@
my ($image,$mode,$name)=@_;
my $part=$Apache::inputtags::part;
my $respid=$Apache::inputtags::response['-1'];
+ my ($x,$y)=split(/:/,$Apache::lonhomework::history{"resource.$part.$respid.submission"});
+ &draw_image($mode,$image,$x,$y,$Apache::response::foilgroup{"$name.area"});
+}
+
+sub draw_image {
+ my ($mode,$image,$x,$y,$areas) = @_;
+
my $id=&Apache::loncommon::get_cgi_id();
+
my (%x,$i);
$x{"cgi.$id.BGIMG"}=&escape($image);
- my ($x,$y)=split(/:/,$Apache::lonhomework::history{"resource.$part.$respid.submission"});
+
#draws 2 xs on the image at the clicked location
#one in white and then one in red on top of the one in white
+
if (defined($x) && $x =~/\S/
&& defined($y) && $y =~/\S/
- && !&Apache::response::show_answer()
+ && ($mode eq 'submission' || !&Apache::response::show_answer())
&& $mode ne 'answeronly') {
my $length = 6;
my $width = 1;
@@ -170,8 +179,7 @@
if ($mode eq 'answer' || $mode eq 'answeronly') {
my $width = 1;
my $extrawidth = 2;
- my @areas = @{ $Apache::response::foilgroup{"$name.area"} };
- foreach my $area (@areas) {
+ foreach my $area (@{ $areas }) {
if ($area=~/^rectangle:/) {
$x{"cgi.$id.OBJTYPE"}.='RECTANGLE:';
$i=$x{"cgi.$id.OBJCOUNT"}++;
@@ -203,6 +211,7 @@
my $result ='';
my $name;
my $temp=1;
+ my @images;
foreach $name (@whichopt) {
$result.=$Apache::response::foilgroup{"$name.text"};
&Apache::lonxml::debug("Text is $result");
@@ -211,7 +220,8 @@
&Apache::lonxml::debug("image is $image");
if ( $target eq 'web' && $image !~ /^http:/ ) {
$image=&clean_up_image($image);
- }
+ }
+ push(@images,$image);
&Apache::lonxml::debug("image is $image");
if ( &Apache::response::show_answer() ) {
if ($target eq 'tex') {
@@ -233,9 +243,24 @@
}
$temp++;
}
+ if ($target eq 'web') {
+ &Apache::response::setup_prior_tries_hash(\&format_prior_response,
+ [\@images]);
+ }
return $result;
}
+sub format_prior_response {
+ my ($mode,$answer,$other_data) = @_;
+ my ($x,$y)=split(/:/,$answer);
+ my $images = $other_data->[0];
+
+ my $token = &draw_image('submission',$images->[0],$x,$y);
+
+ return "<img class=\"LC_prior_image\" src=\"/adm/randomlabel.png?token=$token\" />";
+
+}
+
sub display_answers {
my ($target,$whichopt)=@_;