version 1.14, 2001/12/04 15:17:56
|
version 1.18, 2002/05/03 20:44:46
|
Line 31
|
Line 31
|
package Apache::imageresponse; |
package Apache::imageresponse; |
use strict; |
use strict; |
|
|
sub BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::imageresponse',('imageresponse')); |
&Apache::lonxml::register('Apache::imageresponse',('imageresponse')); |
} |
} |
|
|
Line 51 sub start_imageresponse {
|
Line 51 sub start_imageresponse {
|
sub end_imageresponse { |
sub end_imageresponse { |
&Apache::response::end_response; |
&Apache::response::end_response; |
pop @Apache::lonxml::namespace; |
pop @Apache::lonxml::namespace; |
|
&Apache::lonxml::deregister('Apache::imageresponse',('foilgroup','foil','text','image','rectangle','conceptgroup')); |
return ''; |
return ''; |
} |
} |
|
|
Line 68 sub getfoilcounts {
|
Line 69 sub getfoilcounts {
|
my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2'); |
my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2'); |
# +1 since instructors will count from 1 |
# +1 since instructors will count from 1 |
my $count = $#{ $Apache::response::foilgroup{'names'} }+1; |
my $count = $#{ $Apache::response::foilgroup{'names'} }+1; |
|
if (&Apache::response::showallfoils()) { $max=$count; } |
return ($count,$max); |
return ($count,$max); |
} |
} |
|
|
Line 78 sub whichfoils {
|
Line 80 sub whichfoils {
|
my @whichopt =(); |
my @whichopt =(); |
while ((($#whichopt+1) < $max) && ($#names > -1)) { |
while ((($#whichopt+1) < $max) && ($#names > -1)) { |
&Apache::lonxml::debug("Have $#whichopt max is $max"); |
&Apache::lonxml::debug("Have $#whichopt max is $max"); |
my $aopt=int(rand($#names+1)); |
my $aopt; |
|
if (&Apache::response::showallfoils()) { |
|
$aopt=0; |
|
} else { |
|
$aopt=int(rand($#names+1)); |
|
} |
&Apache::lonxml::debug("From $#names elms, picking $aopt"); |
&Apache::lonxml::debug("From $#names elms, picking $aopt"); |
$aopt=splice(@names,$aopt,1); |
$aopt=splice(@names,$aopt,1); |
&Apache::lonxml::debug("Picked $aopt"); |
&Apache::lonxml::debug("Picked $aopt"); |
Line 199 sub start_foil {
|
Line 206 sub start_foil {
|
if ($target eq 'web' || $target eq 'grade') { |
if ($target eq 'web' || $target eq 'grade') { |
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); |
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); |
if ($name eq '') { $name=$Apache::lonxml::curdepth; } |
if ($name eq '') { $name=$Apache::lonxml::curdepth; } |
if ( $Apache::imageresponse::conceptgroup ) { |
if ( $Apache::imageresponse::conceptgroup |
|
&& !&Apache::response::showallfoils()) { |
push(@{ $Apache::response::conceptgroup{'names'} }, $name); |
push(@{ $Apache::response::conceptgroup{'names'} }, $name); |
} else { |
} else { |
push(@{ $Apache::response::foilgroup{'names'} }, $name); |
push(@{ $Apache::response::foilgroup{'names'} }, $name); |
Line 224 sub end_text {
|
Line 232 sub end_text {
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
if ($target eq 'web') { |
if ($target eq 'web') { |
my $name = $Apache::imageresponse::curname; |
my $name = $Apache::imageresponse::curname; |
if ( $Apache::imageresponse::conceptgroup ) { |
if ( $Apache::imageresponse::conceptgroup |
|
&& !&Apache::response::showallfoils() ) { |
$Apache::response::conceptgroup{"$name.text"} = &Apache::lonxml::endredirection; |
$Apache::response::conceptgroup{"$name.text"} = &Apache::lonxml::endredirection; |
} else { |
} else { |
$Apache::response::foilgroup{"$name.text"} = &Apache::lonxml::endredirection; |
$Apache::response::foilgroup{"$name.text"} = &Apache::lonxml::endredirection; |
Line 245 sub end_image {
|
Line 254 sub end_image {
|
my $name = $Apache::imageresponse::curname; |
my $name = $Apache::imageresponse::curname; |
my $image = &Apache::lonxml::endredirection; |
my $image = &Apache::lonxml::endredirection; |
&Apache::lonxml::debug("out is $image"); |
&Apache::lonxml::debug("out is $image"); |
if ( $Apache::imageresponse::conceptgroup ) { |
if ( $Apache::imageresponse::conceptgroup |
|
&& !&Apache::response::showallfoils()) { |
$Apache::response::conceptgroup{"$name.image"} = $image; |
$Apache::response::conceptgroup{"$name.image"} = $image; |
} else { |
} else { |
$Apache::response::foilgroup{"$name.image"} = $image; |
$Apache::response::foilgroup{"$name.image"} = $image; |
Line 271 sub grade_rectangle {
|
Line 281 sub grade_rectangle {
|
&Apache::lonxml::debug("Point $x1,$y1,$x2,$y2"); |
&Apache::lonxml::debug("Point $x1,$y1,$x2,$y2"); |
if ($x1 > $x2) { my $temp=$x1;$x1=$x2;$x2=$temp; } |
if ($x1 > $x2) { my $temp=$x1;$x1=$x2;$x2=$temp; } |
if ($y1 > $y2) { my $temp=$y1;$y1=$y2;$y2=$temp; } |
if ($y1 > $y2) { my $temp=$y1;$y1=$y2;$y2=$temp; } |
if ($x => $x1) { if ($x <= $x2) { if ($y => $y1) { if ($y <= $y2) { return 'APPROX_ANS'; } } } } |
if (($x >= $x1) && ($x <= $x2) && ($y >= $y1) && ($y <= $y2)) { |
|
return 'APPROX_ANS'; |
|
} |
return 'INCORRECT'; |
return 'INCORRECT'; |
} |
} |
|
|
Line 281 sub end_rectangle {
|
Line 293 sub end_rectangle {
|
my $name = $Apache::imageresponse::curname; |
my $name = $Apache::imageresponse::curname; |
my $area = &Apache::lonxml::endredirection; |
my $area = &Apache::lonxml::endredirection; |
&Apache::lonxml::debug("out is $area for $name"); |
&Apache::lonxml::debug("out is $area for $name"); |
if ( $Apache::imageresponse::conceptgroup ) { |
if ( $Apache::imageresponse::conceptgroup |
|
&& !&Apache::response::showallfoils()) { |
push @{ $Apache::response::conceptgroup{"$name.area"} },"rectangle:$area"; |
push @{ $Apache::response::conceptgroup{"$name.area"} },"rectangle:$area"; |
} else { |
} else { |
push @{ $Apache::response::foilgroup{"$name.area"} },"rectangle:$area"; |
push @{ $Apache::response::foilgroup{"$name.area"} },"rectangle:$area"; |