--- loncom/homework/optionresponse.pm 2001/02/07 00:28:33 1.2 +++ loncom/homework/optionresponse.pm 2001/03/01 00:59:33 1.5 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # option list style responses - +# 2/21 Guy package Apache::optionresponse; use strict; @@ -24,6 +24,8 @@ sub end_optionresponse { %Apache::response::foilgroup={}; sub start_foilgroup { %Apache::response::foilgroup={}; + $Apache::optionresponse::conceptgroup=0; + &setrandomnumber(); return ''; } @@ -34,6 +36,7 @@ sub setrandomnumber { +&Apache::lonnet::numval($Apache::inputtags::part) +&Apache::lonnet::numval($Apache::inputtags::response['-1']); srand($rndseed); + &Apache::lonxml::debug("randseed $rndseed"); return ''; } @@ -43,7 +46,6 @@ sub end_foilgroup { my $result; if ($target ne 'meta') { my $name; - &setrandomnumber(); my ($count,$max) = &getfoilcounts($parstack,$safeeval); if ($count>$max) { $count=$max } &Apache::lonxml::debug("Count is $count from $max"); @@ -64,7 +66,7 @@ sub end_foilgroup { my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1'].":$temp"}; $allresponse.="$response:"; if ( $response =~ /[^\s]/) { - &Apache::lonxml::debug("submitted a $response
\n"); + &Apache::lonxml::debug("submitted a $response
\n"); my $value=$Apache::response::foilgroup{$name.'.value'}; if ($value eq $response) {$right++;} else {$wrong++;} } @@ -137,37 +139,57 @@ sub displayfoils { return $result."
"; } + 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.value"} = $Apache::response::conceptgroup{"$name.value"}; + $Apache::response::foilgroup{"$name.text"} = $Apache::response::conceptgroup{"$name.text"}; + 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 ''; } sub start_foil { my ($target,$token,$parstack,$parser,$safeeval,$style)=@_; - if ($target eq 'web') { - $Apache::lonxml::redirection--; - } + if ($target eq 'web') { &Apache::lonxml::startredirection; } return ''; } sub end_foil { my ($target,$token,$parstack,$parser,$safeeval,$style)=@_; + my $text =''; + if ($target eq 'web') { $text=&Apache::lonxml::endredirection; } if ($target eq 'web' || $target eq 'grade') { my $args =''; if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } my $value = &Apache::run::run("{$args;".'return $value}',$safeeval); if ($value ne 'unused') { my $name = &Apache::run::run("{$args;".'return $name}',$safeeval); - push @{ $Apache::response::foilgroup{'names'} }, $name; - $Apache::response::foilgroup{"$name.value"} = $value; - $Apache::response::foilgroup{"$name.text"} = $Apache::lonxml::outputstack; - } - } - if ($target eq 'web' ) { - $Apache::lonxml::redirection++; - if ($Apache::lonxml::redirection == 1) { - $Apache::lonxml::outputstack=''; + if ( $Apache::optionresponse::conceptgroup ) { + push @{ $Apache::response::conceptgroup{'names'} }, $name; + $Apache::response::conceptgroup{"$name.value"} = $value; + $Apache::response::conceptgroup{"$name.text"} = $text; + } else { + push @{ $Apache::response::foilgroup{'names'} }, $name; + $Apache::response::foilgroup{"$name.value"} = $value; + $Apache::response::foilgroup{"$name.text"} = $text; + } } } return '';