--- loncom/homework/optionresponse.pm 2002/11/11 15:58:51 1.60
+++ loncom/homework/optionresponse.pm 2003/01/19 08:10:22 1.67
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.60 2002/11/11 15:58:51 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.67 2003/01/19 08:10:22 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -248,6 +248,7 @@ sub whichfoils {
my ($max,$randomize)=@_;
$max = &getfoilcounts($max);
&Apache::lonxml::debug("randomize $randomize");
+ if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
my @names = @{ $Apache::response::foilgroup{'names'} };
my @whichopt =();
my (%top,@toplist,%bottom,@bottomlist);
@@ -294,6 +295,7 @@ sub whichfoils {
sub displayanswers {
my ($max,$randomize,@opt)=@_;
+ if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
my @names = @{ $Apache::response::foilgroup{'names'} };
my @whichopt = &whichfoils($max,$randomize);
my $result=&Apache::response::answer_header('optionresponse');
@@ -307,6 +309,7 @@ sub displayanswers {
sub displayfoils {
my ($target,$max,$randomize,@opt)=@_;
+ if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
my @names = @{ $Apache::response::foilgroup{'names'} };
my @truelist;
my @falselist;
@@ -318,22 +321,33 @@ sub displayfoils {
my @whichopt = &whichfoils($max,$randomize);
my $part=$Apache::inputtags::part;
my $id=$Apache::inputtags::response[-1];
- if (($Apache::lonhomework::history{"resource.$part.solved"} =~ /^correct/) || ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER')) {
- my $temp=1; ####
+ my $break;
+ my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
+ my $status=$Apache::inputtags::status[-1];
+ if (
+ ($target ne 'tex') &&
+ (($solved =~ /^correct/) || ($status eq 'SHOW_ANSWER')) ) {
foreach $name (@whichopt) {
- if ($target eq 'web') {
- $result.="
";
+ my $text=$Apache::response::foilgroup{$name.'.text'};
+ if ($text!~/^\s*$/) {
+ if ($target eq 'tex') {
+ $break='\vskip 0 mm ';
+ } elsif ($target eq 'web') {
+ $break='
';
+ }
+ }
+ $result.=$break;
+ if ($target eq 'web') {
+ my $value=$Apache::response::foilgroup{$name.'.value'};
+ if (!($text=~s||$value|)) {
+ if ($text=~/^\s*$/) {
+ $text=$value.$text;
+ } else {
+ $text=$value.': '.$text;
+ }
+ }
+ $result.=$text."\n";
} elsif ($target eq 'tex') {
- $result.='\vskip 0 mm ';
- }
- if ($target ne 'tex') {
- my $text=$Apache::response::foilgroup{$name.'.text'};
- my $value=$Apache::response::foilgroup{$name.'.value'};
- if (!($text=~s||$value|)) {
- $text=$value.': '.$text;
- }
- $result.=$text."\n";
- } else {
$Apache::response::foilgroup{$name.'.text'}=~s/\\item//;
$result .='\item \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'.
":".$Apache::response::foilgroup{$name.'.text'}."\n";
@@ -345,12 +359,19 @@ sub displayfoils {
$result.=&bubbles(\@alphabet,\@opt);
}
}
- $temp++;
}
} else {
my $temp=1;
my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
foreach $name (@whichopt) {
+ my $text=$Apache::response::foilgroup{$name.'.text'};
+ if ($text!~/^\s*$/) {
+ if ($target eq 'tex') {
+ $break='\vskip 0 mm ';
+ } elsif ($target eq 'web') {
+ $break='
';
+ }
+ }
my $lastopt=$lastresponse{$name};
my $optionlist="\n";
my $option;
@@ -369,7 +390,7 @@ sub displayfoils {
if (!($text=~s||$optionlist|)) {
$text=$optionlist.$text;
}
- $result.="
".$text."\n";
+ $result.=$break.$text."\n";
if ($Apache::lonhomework::type eq 'exam') {
$result.=&webbubbles(\@opt,\@alphabet);
}
@@ -383,12 +404,9 @@ sub displayfoils {
$Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\item[\\textbf{$Apache::lonxml::counter}\.]/;
}
if ($Apache::response::foilgroup{$name.'.text'}=~//) {
- $texoptionlist = &texoptionlist_correction($texoptionlist);
- $Apache::response::foilgroup{$name.'.text'}=~s||$texoptionlist|;
- $result.= $Apache::response::foilgroup{$name.'.text'};
- } else {
- $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'};
+ $Apache::response::foilgroup{$name.'.text'}=~s|| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
}
+ $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'};
} else {
if ($Apache::lonhomework::type eq 'exam') {
$result.= $texoptionlist.'\vspace*{-2 mm}\item[\textbf{'.$Apache::lonxml::counter.'}.]'.$Apache::response::foilgroup{$name.'.text'};
@@ -398,6 +416,7 @@ sub displayfoils {
}
if ($Apache::lonhomework::type eq 'exam') {
$result.=&bubbles(\@alphabet,\@opt);
+ $result.='\vskip 2 mm ';
}
$displayoptionintex=1;
} else {
@@ -406,8 +425,7 @@ sub displayfoils {
$Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\item[\\textbf{$Apache::lonxml::counter}\.]/;
}
if ($Apache::response::foilgroup{$name.'.text'}=~//) {
- $texoptionlist = &texoptionlist_correction($texoptionlist);
- $Apache::response::foilgroup{$name.'.text'}=~s||$texoptionlist|;
+ $Apache::response::foilgroup{$name.'.text'}=~s|| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
}
$result.= $Apache::response::foilgroup{$name.'.text'};
} else {
@@ -419,15 +437,15 @@ sub displayfoils {
}
if ($Apache::lonhomework::type eq 'exam') {
$result.=&bubbles(\@alphabet,\@opt);
+ $result.='\vskip 2 mm ';
}
}
- }
+ }
}
- }
- if ($target ne 'tex') {
- return $result."
";
}
- else {
+ if ($target ne 'tex') {
+ return $result.$break;
+ } else {
return $result;
}
}
@@ -444,14 +462,7 @@ sub optionlist_correction {
$texoptionlist =~ s/>/\$>\$/g;
$texoptionlist =~ s/\$<\$/g;
$texoptionlist =~ s/=/\$=\$/g;
- return $texoptionlist;
-}
-
-
-sub texoptionlist_correction {
- my $texoptionlist = shift;
- $texoptionlist =~ s/\\item \[\] Possible answers are:\s*/\\fbox\{/;
- $texoptionlist =~ s/\.$/}/;
+ $texoptionlist =~ s/\^(\d+)/\$$1\$<\/m>/g;
return $texoptionlist;
}