"; }
+ if ($target ne 'tex') {
+ if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.=""; }
+ } else {
+ $result.='\vskip 0 mm ';
+ }
}
}
}
- if ($direction eq 'horizontal') { $result.=''; }
+
+ if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.=''; }
return $result;
}
+=pod
+
+=item &whichfoils($max,$randomize)
+
+Randomizes the list of foils.
+Respects
+ - each foils desire to be randomized
+ - the existance of Concept groups of foils (select 1 foil from each)
+ - and selects a single correct statement from all possilble true statments
+ - and limits it to a toal of $max foils
+
+WARNING: this routine uses the random number generator, it should only
+be called once per target, otherwise it can cause randomness changes in
+homework problems.
+
+Arguments
+ $max - maximum number of foils to select (including the true one)
+ (so a max of 5 is: 1 true, 4 false)
+
+ $randomize - whether to randomize the listing of foils, by default
+ will randomize, only if randomize is 'no' will it not
+
+Returns
+ $answer - location in the array of the correct answer
+ @foils - array of foil names in to display order
+
+=cut
+
sub whichfoils {
my ($max,$randomize)=@_;
@@ -289,7 +417,7 @@ sub whichfoils {
my ($truecnt,$falsecnt) = &getfoilcounts();
my $count=0;
# we will add in 1 of the true statements
- if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
+ if ( $max>0 && ($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; $max=$count; }
my $answer=int(&Math::Random::random_uniform() * ($count));
&Apache::lonxml::debug("Count is $count, $answer is $answer");
my @names;
@@ -314,7 +442,7 @@ sub whichfoils {
}
}
if (!$havetrue && $Apache::lonhomework::type ne 'survey') {
- &Apache::lonxml::error("There are no true statements available. ");
+ &Apache::lonxml::error(&mt('There are no true statements available.').' ');
}
} else {
my $current=0;
@@ -375,7 +503,7 @@ sub whichfoils {
my $dosplice=1;
if ($notrue && $Apache::lonhomework::type ne 'survey') {
$dosplice=0;
- &Apache::lonxml::error("There are no true statements available. ");
+ &Apache::lonxml::error(&mt('There are no true statements available.').' ');
}
#insert the true statement, keeping track of where it wants to be
if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
@@ -417,10 +545,9 @@ sub whichfoils {
}
sub displayfoils {
- my ($target,$max,$randomize,$direction)=@_;
+ my ($target,$answer,$whichfoils,$direction, $bubbles_per_line)=@_;
my $result;
- my ($answer,@whichfoils)=&whichfoils($max,$randomize);
my $part=$Apache::inputtags::part;
my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
if ( ($target ne 'tex') &&
@@ -430,7 +557,7 @@ sub displayfoils {
$result.='
';
}
}
- foreach my $name (@whichfoils) {
+ foreach my $name (@{ $whichfoils }) {
if ($direction eq 'horizontal') {
if ($target ne 'tex') { $result.='
'; }
}
@@ -440,9 +567,13 @@ sub displayfoils {
$result.='\item \vskip -2 mm ';
}
if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
- if ($target ne 'tex') { $result.='Correct:'; } else { $result.='Correct: \textbf{';}
+ if ($target ne 'tex') {
+ $result.=&mt('Correct:').'';
+ } else {
+ $result.=&mt('Correct:').' \textbf{';
+ }
} else {
- $result.='Incorrect:';
+ $result.=&mt('Incorrect:');
}
if ($target eq 'web') { $result.=""; }
$result.=$Apache::response::foilgroup{$name.'.text'};
@@ -462,6 +593,8 @@ sub displayfoils {
} else {
my @alphabet = ('A'..'Z');
my $i = 0;
+ my $bubble_number = 0;
+ my $line = 0;
my $temp=0;
my $id=$Apache::inputtags::response['-1'];
my $part=$Apache::inputtags::part;
@@ -470,7 +603,7 @@ sub displayfoils {
if ($target ne 'tex' && $direction eq 'horizontal') {
$result.="
";
}
- foreach my $name (@whichfoils) {
+ foreach my $name (@{ $whichfoils }) {
if ($target ne 'tex') {
if ($direction eq 'horizontal') {
$result.="
";
@@ -480,13 +613,24 @@ sub displayfoils {
}
if ($target ne 'tex') {
$result.= '';
- $result.="";
+ $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}."";
} else {
if ($Apache::lonhomework::type eq 'exam') {
+ if($bubble_number >= $bubbles_per_line) {
+ $line++;
+ $i = 0;
+ $bubble_number = 0;
+ $result.='\item[\textbf{'.($Apache::lonxml::counter+$line).'}.]';
+ }
$result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
$i++;
+ $bubble_number++;
} else {
$result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
}
@@ -505,8 +649,10 @@ sub displayfoils {
}
sub displayallanswers {
- my @names = @{ $Apache::response::foilgroup{'names'} };
-
+ my @names;
+ if ( $Apache::response::foilgroup{'names'} ) {
+ @names= @{ $Apache::response::foilgroup{'names'} };
+ }
my $result=&Apache::response::answer_header('radiobuttonresponse');
foreach my $name (@names) {
$result.=&Apache::response::answer_part('radiobuttonresponse',
@@ -517,13 +663,23 @@ sub displayallanswers {
}
sub displayanswers {
- my ($max,$randomize)=@_;
- my ($answer,@whichopt) = &whichfoils($max,$randomize);
- my $result=&Apache::response::answer_header('radiobuttonresponse');
- foreach my $name (@whichopt) {
+ my ($answer, $whichopt, $bubbles_per_line)=@_;
+ my $result;
+
+ if ($Apache::lonhomework::type eq 'exam') {
+ my $line = int($answer/$bubbles_per_line);
+ my $correct = ('A'..'Z')[$answer%$bubbles_per_line];
+ $result .= &Apache::response::answer_header('radiobuttonresponse',
+ $line);
+ $result .= &Apache::response::answer_part('radiobuttonresponse',
+ $correct);
+ } else {
+ $result .= &Apache::response::answer_header('radiobuttonresponse');
+ }
+ foreach my $name (@{ $whichopt }) {
$result.=&Apache::response::answer_part('radiobuttonresponse',
- $Apache::response::foilgroup{$name.'.value'})
- }
+ $Apache::response::foilgroup{$name.'.value'});
+ }
$result.=&Apache::response::answer_footer('radiobuttonresponse');
return $result;
}
@@ -608,11 +764,11 @@ sub end_foil {
if ($value ne 'unused') {
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
if ($name eq "") {
- &Apache::lonxml::warning("Foils without names exist. This can cause problems to malfunction.");
+ &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
$name=$Apache::lonxml::curdepth;
}
if (defined($Apache::response::foilnames{$name})) {
- &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",$name));
+ &Apache::lonxml::error(&mt('Foil name [_1] appears more than once. Foil names need to be unique.',''.$name.''));
}
$Apache::response::foilnames{$name}++;
my $location =&Apache::lonxml::get_param('location',$parstack,