[LON-CAPA-cvs] cvs: loncom /homework optionresponse.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 16 Apr 2004 22:25:14 -0000
albertel Fri Apr 16 18:25:14 2004 EDT
Modified files:
/loncom/homework optionresponse.pm
Log:
- BUG#2284, optionresponse now complains if the correct option for a question isn't available for selection for the student to choose
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.105 loncom/homework/optionresponse.pm:1.106
--- loncom/homework/optionresponse.pm:1.105 Thu Mar 25 11:55:16 2004
+++ loncom/homework/optionresponse.pm Fri Apr 16 18:25:13 2004
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.105 2004/03/25 16:55:16 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 @@
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').' <br /><tt>'.
+ join('<br />',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))).
+ "</tt>";
+ &Apache::lonxml::error($error);
+ }
+}
+
sub displayfoils {
my ($target,$max,$randomize,@opt)=@_;
if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
@@ -295,6 +316,7 @@
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;