--- loncom/homework/randomlylabel.pm 2006/05/30 12:45:37 1.28 +++ loncom/homework/randomlylabel.pm 2007/09/25 23:16:13 1.30 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # randomlabel.png: composite together text and images into 1 image # -# $Id: randomlylabel.pm,v 1.28 2006/05/30 12:45:37 www Exp $ +# $Id: randomlylabel.pm,v 1.30 2007/09/25 23:16:13 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -267,24 +267,45 @@ sub get_color_from_hexstring { return $imcolor; } +sub add_click { + my ($image) = @_; + + my $length=6; + my $bgcolor=&get_color_from_hexstring($image,'FFFFFF'); + my $fgcolor=&get_color_from_hexstring($image,'009999'); + + my ($x,$y) = split(':',$env{'form.clickdata'}); + + $image->setThickness(3); + $image->line($x-$length,$y, $x+$length,$y, $bgcolor); + $image->line($x, $y-$length,$x, $y+$length,$bgcolor); + $image->setThickness(1); + $image->line($x-$length,$y, $x+$length,$y, $fgcolor); + $image->line($x, $y-$length,$x, $y+$length,$fgcolor); +} + sub handler { my $r = shift; $r->content_type('image/png'); $r->send_http_header; - my (undef,$id) = split(/=/,$ENV{'QUERY_STRING'}); - my $image; - my $prefix="cgi.$id."; + + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + + my $prefix; if ($ENV{'QUERY_STRING'}=~/OBJCOUNT\=/) { - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); $prefix='form.'; + } else { + $prefix="cgi.$env{'form.token'}."; } + + my $image; if (defined($env{$prefix."BGIMG"})) { my $bgimg=&unescape($env{$prefix."BGIMG"}); #&Apache::lonnet::logthis("BGIMG is ".$bgimg); $image=&get_image($bgimg,0); if (! defined($image)) { &Apache::lonnet::logthis('Unable to create image object for -'. - $id.'-'.$bgimg); + $env{'form.token'}.'-'.$bgimg); return OK; } } elsif (defined($env{$prefix."SIZE"})) { @@ -301,7 +322,7 @@ sub handler { $image->transparent($bgcolor); } } else { - &Apache::lonnet::logthis('Unable to create image object, no info'); + &Apache::lonnet::logthis('Unable to create image object, no info '.$prefix); return OK; } #binmode(STDOUT); @@ -425,6 +446,7 @@ sub handler { &Apache::lonnet::logthis("randomlylabel unable to handle object of type $type"); } } + if (exists($env{'form.clickdata'})) { &add_click($image); } $image->setThickness(1); $r->print($image->png); return OK;