--- loncom/homework/imageresponse.pm 2001/02/22 01:13:43 1.3 +++ loncom/homework/imageresponse.pm 2001/05/15 20:48:43 1.6 @@ -14,28 +14,22 @@ sub start_imageresponse { my ($target,$token,$parstack,$parser,$safeeval,$style)=@_; #when in a radiobutton response use these &Apache::lonxml::register('Apache::imageresponse',('foilgroup','foil','text','image','rectangle')); + push (@Apache::lonxml::namespace,'imageresponse'); my $id = &Apache::response::start_response($parstack,$safeeval); return ''; } sub end_imageresponse { &Apache::response::end_response; + pop @Apache::lonxml::namespace; return ''; } %Apache::response::foilgroup={}; sub start_foilgroup { %Apache::response::foilgroup={}; - return ''; -} - -sub setrandomnumber { - my $rndseed=&Apache::lonnet::rndseed(); - $rndseed=unpack("%32i",$rndseed); - $rndseed=$rndseed - +&Apache::lonnet::numval($Apache::inputtags::part) - +&Apache::lonnet::numval($Apache::inputtags::response['-1']); - srand($rndseed); + $Apache::optionresponse::conceptgroup=0; + &Apache::response::setrandomnumber(); return ''; } @@ -52,7 +46,7 @@ sub whichfoils { my ($max)=@_; my @names = @{ $Apache::response::foilgroup{'names'} }; my @whichopt =(); - while ((($#whichopt+1) < $max) && ($#names > -1)) { + while ((($#whichopt) < $max) && ($#names > -1)) { my $aopt=int rand $#names; &Apache::lonxml::debug("From $#names elms, picking $aopt"); $aopt=splice(@names,$aopt,1); @@ -122,7 +116,6 @@ sub end_foilgroup { my $result=''; my @whichopt; if ($target eq 'web' || $target eq 'grade') { - &setrandomnumber(); my ($count,$max) = &getfoilcounts($parstack,$safeeval); if ($count>$max) { $count=$max } &Apache::lonxml::debug("Count is $count from $max"); @@ -140,9 +133,29 @@ sub end_foilgroup { } sub start_conceptgroup { + $Apache::optionresponse::conceptgroup=1; + %Apache::response::conceptgroup={}; + return ''; } sub end_conceptgroup { + my ($target,$token,$parstack,$parser,$safeeval,$style)=@_; + $Apache::optionresponse::conceptgroup=0; + if ($target eq 'web' || $target eq 'grade') { + my @names = @{ $Apache::response::conceptgroup{'names'} }; + my $pick=int rand $#names+1; + my $name=$names[$pick]; + push @{ $Apache::response::foilgroup{'names'} }, $name; + $Apache::response::foilgroup{"$name.text"} = $Apache::response::conceptgroup{"$name.text"}; + $Apache::response::foilgroup{"$name.image"} = $Apache::response::conceptgroup{"$name.image"}; + push(@{ $Apache::response::foilgroup{"$name.area"} }, @{ $Apache::response::conceptgroup{"$name.area"} }); + my $args; + if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } + my $concept = &Apache::run::run("{$args;".'return $concept}',$safeeval); + $Apache::response::foilgroup{"$name.concept"} = $concept; + &Apache::lonxml::debug("Selecting $name in $concept"); + } + return ''; } $Apache::imageresponse::curname='';