--- loncom/homework/optionresponse.pm 2002/10/01 14:39:45 1.49
+++ loncom/homework/optionresponse.pm 2003/03/26 22:59:09 1.70
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.49 2002/10/01 14:39:45 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.70 2003/03/26 22:59:09 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,6 +42,7 @@ sub start_optionresponse {
&Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
push (@Apache::lonxml::namespace,'optionresponse');
my $id = &Apache::response::start_response($parstack,$safeeval);
+ %Apache::hint::option=();
if ($target eq 'edit') {
$result.=&Apache::edit::start_table($token).
"
Multiple Option Response Question | Delete:".
@@ -140,7 +141,7 @@ ENDTABLE
$result.=')">';
} # else nothing changed so just use the default mechanism
}
- if ($target eq 'tex') {
+ if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
$result .= ' \begin{enumerate} ';
}
return $result;
@@ -179,6 +180,7 @@ sub end_foilgroup {
my @whichopt = &whichfoils($max,$randomize);
my $temp=1;my $name;
my %responsehash;
+ my %grade;
my $right=0;
my $wrong=0;
my $ignored=0;
@@ -188,7 +190,11 @@ sub end_foilgroup {
if ( $response =~ /[^\s]/) {
my $value=$Apache::response::foilgroup{$name.'.value'};
&Apache::lonxml::debug("submitted a $response for $value \n");
- if ($value eq $response) {$right++;} else {$wrong++;}
+ if ($value eq $response) {
+ $grade{$name}='1'; $right++;
+ } else {
+ $grade{$name}='0'; $wrong++;
+ }
} else {
$ignored++;
}
@@ -197,6 +203,7 @@ sub end_foilgroup {
my $part=$Apache::inputtags::part;
my $id = $Apache::inputtags::response['-1'];
my $responsestr=&Apache::lonnet::hash2str(%responsehash);
+ my $gradestr =&Apache::lonnet::hash2str(%grade);
my %previous=&Apache::response::check_for_previous($responsestr,
$part,$id);
&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
@@ -214,6 +221,7 @@ sub end_foilgroup {
}
$Apache::lonhomework::results{"resource.$part.$id.submission"}=
$responsestr;
+ $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
$ad;
&Apache::response::handle_previous(\%previous,$ad);
@@ -222,7 +230,7 @@ sub end_foilgroup {
} elsif ($target eq 'edit') {
$result.=&Apache::edit::end_table();
}
- if ($target eq 'tex') {$result .= '\end{enumerate}';}
+ if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {$result .= '\end{enumerate}';}
return $result;
}
@@ -240,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);
@@ -286,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');
@@ -299,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;
@@ -310,25 +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 {
- $result .='\item '.$Apache::response::foilgroup{$name.'.value'}.
+ $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;
@@ -340,80 +383,131 @@ 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;
- $texoptionlist =~ s/ |