--- loncom/homework/optionresponse.pm 2004/03/15 22:09:52 1.104 +++ loncom/homework/optionresponse.pm 2004/04/16 22:25:13 1.106 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: optionresponse.pm,v 1.104 2004/03/15 22:09:52 albertel Exp $ +# $Id: optionresponse.pm,v 1.106 2004/04/16 22:25:13 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -284,6 +284,27 @@ sub displayanswers { return $result; } +sub check_for_invalid { + my ($names,$options) = @_; + my %bad_names; + foreach my $name (@{ $names }) { + my $value=$Apache::response::foilgroup{$name.'.value'}; + my $found=0; + foreach my $option (@{ $options }) { + if ($value eq $option) { $found=1; } + } + if (!$found) { $bad_names{$name}=$value; } + } + if (%bad_names) { + my $error=&mt('The question can not be gotten correct, '. + 'the following foils in the <optionresponse> '. + 'have invalid correct options').'
'. + join('
',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))). + "
"; + &Apache::lonxml::error($error); + } +} + sub displayfoils { my ($target,$max,$randomize,@opt)=@_; if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;} @@ -295,6 +316,7 @@ sub displayfoils { my $displayoptionintex=1; my @alphabet = ('A'..'Z'); my @whichopt = &whichfoils($max,$randomize); + &check_for_invalid(\@whichopt,\@opt); my $part=$Apache::inputtags::part; my $id=$Apache::inputtags::response[-1]; my $break; @@ -530,7 +552,10 @@ sub start_foil { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) { - &Apache::lonxml::startredirection; + &Apache::lonxml::startredirection; + if ($target eq 'analyze') { + &Apache::response::check_if_computed($token,$parstack,$safeeval,'value'); + } } elsif ($target eq 'edit') { $result=&Apache::edit::tag_start($target,$token,"Foil"); my $level='-2';