--- loncom/homework/optionresponse.pm 2002/10/28 23:31:48 1.57
+++ 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.57 2002/10/28 23:31:48 albertel 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,26 +321,57 @@ 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 $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') {
- $result .=$Apache::response::foilgroup{$name.'.value'}.
- ":".$Apache::response::foilgroup{$name.'.text'}."\n";
- } else {
$Apache::response::foilgroup{$name.'.text'}=~s/\\item//;
$result .='\item \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'.
":".$Apache::response::foilgroup{$name.'.text'}."\n";
}
+ if ($Apache::lonhomework::type eq 'exam') {
+ if ($target ne 'tex') {
+ $result.=&webbubbles(\@opt,\@alphabet);
+ } else {
+ $result.=&bubbles(\@alphabet,\@opt);
+ }
+ }
}
} 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;
@@ -349,27 +383,30 @@ sub displayfoils {
}
}
if ($target ne 'tex') {
- $result.="
\n".$Apache::response::foilgroup{$name.'.text'}."\n";
+ $optionlist='\n";
+ my $text=$Apache::response::foilgroup{$name.'.text'};
+ if (!($text=~s||$optionlist|)) {
+ $text=$optionlist.$text;
+ }
+ $result.=$break.$text."\n";
if ($Apache::lonhomework::type eq 'exam') {
- my $number_of_bubbles = $#opt + 1;
- $result.= '
';
- for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
- $result.=''.$alphabet[$ind].': '.$opt[$ind].' | ';
- }
- $result.='
';
+ $result.=&webbubbles(\@opt,\@alphabet);
}
$temp++;
} else {
+ my $texoptionlist = &optionlist_correction($optionlist);
if ($displayoptionintex == 0) {
- my $texoptionlist = &optionlist_correction($optionlist);
- if ($Apache::lonhomework::type eq 'exam') {$texoptionlist='';}
+ if ($Apache::lonhomework::type eq 'exam') {$texoptionlist='';} #if exam we do not need to show optionlist
if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
- if ($Apache::lonhomework::type eq 'exam') {
- $Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\item[\\textbf{$Apache::lonxml::counter}\.]/;
- }
- $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'};
+ if ($Apache::lonhomework::type eq 'exam') {
+ $Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\item[\\textbf{$Apache::lonxml::counter}\.]/;
+ }
+ if ($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'};
@@ -379,6 +416,7 @@ sub displayfoils {
}
if ($Apache::lonhomework::type eq 'exam') {
$result.=&bubbles(\@alphabet,\@opt);
+ $result.='\vskip 2 mm ';
}
$displayoptionintex=1;
} else {
@@ -386,7 +424,10 @@ sub displayfoils {
if ($Apache::lonhomework::type eq 'exam') {
$Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\item[\\textbf{$Apache::lonxml::counter}\.]/;
}
- $result.= $Apache::response::foilgroup{$name.'.text'};
+ if ($Apache::response::foilgroup{$name.'.text'}=~//) {
+ $Apache::response::foilgroup{$name.'.text'}=~s|| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
+ }
+ $result.= $Apache::response::foilgroup{$name.'.text'};
} else {
if ($Apache::lonhomework::type eq 'exam') {
$result.= '\item[\textbf{'.$Apache::lonxml::counter.'}.]'.$Apache::response::foilgroup{$name.'.text'};
@@ -396,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;
}
}
@@ -421,10 +462,27 @@ sub optionlist_correction {
$texoptionlist =~ s/>/\$>\$/g;
$texoptionlist =~ s/\$<\$/g;
$texoptionlist =~ s/=/\$=\$/g;
+ $texoptionlist =~ s/\^(\d+)/\$$1\$<\/m>/g;
return $texoptionlist;
}
+sub webbubbles {
+
+ my ($ropt,$ralphabet)=@_;
+ my @opt=@$ropt;
+ my @alphabet=@$ralphabet;
+ my $result='';
+ my $number_of_bubbles = $#opt + 1;
+ $result.= '';
+ for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
+ $result.=''.$alphabet[$ind].': '.$opt[$ind].' | ';
+ }
+ $result.='
';
+ return $result;
+}
+
+
sub bubbles {
my ($ralphabit,$ropt) = @_;