--- loncom/homework/optionresponse.pm	2002/10/28 23:31:48	1.57
+++ loncom/homework/optionresponse.pm	2002/11/11 15:58:51	1.60
@@ -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.60 2002/11/11 15:58:51 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -318,7 +318,8 @@ 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')) {
+  if (($Apache::lonhomework::history{"resource.$part.solved"} =~ /^correct/)  || ($Apache::inputtags::status[-1] eq  'SHOW_ANSWER')) {    
+    my $temp=1; ####
     foreach $name (@whichopt) {
       if ($target eq 'web') {
 	  $result.="<br />";
@@ -326,13 +327,25 @@ sub displayfoils {
 	  $result.='\vskip 0 mm ';
       }
       if ($target ne 'tex') {
-	  $result .=$Apache::response::foilgroup{$name.'.value'}.
-	      ":".$Apache::response::foilgroup{$name.'.text'}."\n";
+	  my $text=$Apache::response::foilgroup{$name.'.text'};
+	  my $value=$Apache::response::foilgroup{$name.'.value'};
+	  if (!($text=~s|<drawoptionlist\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";
       }
+      if ($Apache::lonhomework::type eq 'exam') {
+	if ($target ne 'tex') {
+	  $result.=&webbubbles(\@opt,\@alphabet);
+        } else {
+	  $result.=&bubbles(\@alphabet,\@opt);
+        }
+      }
+    $temp++;
     }
   } else {
     my $temp=1;
@@ -349,27 +362,33 @@ sub displayfoils {
 	}
       }
       if ($target ne 'tex') {
-	  $result.="<br /><select name=\"HWVAL_$Apache::inputtags::response['-1']:$temp\">"
-	      .$optionlist
-		  ."</select>\n".$Apache::response::foilgroup{$name.'.text'}."\n";
+	  $optionlist='<select name="HWVAL_'.
+	      $Apache::inputtags::response['-1'].':'.$temp.'">'.
+		  $optionlist."</select>\n";
+	  my $text=$Apache::response::foilgroup{$name.'.text'};
+	  if (!($text=~s|<drawoptionlist\s*/>|$optionlist|)) {
+	      $text=$optionlist.$text;
+	  }
+	  $result.="<br />".$text."\n";
 	  if ($Apache::lonhomework::type eq 'exam') {
-		  my $number_of_bubbles = $#opt + 1;
-		  $result.= '<table border="1"><tr>';
-		  for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
-		      $result.='<td>'.$alphabet[$ind].': '.$opt[$ind].'</td>';
-		  }
-		  $result.='</tr></table>';
+	    $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'}=~/<drawoptionlist\s*\/>/) {
+		  $texoptionlist = &texoptionlist_correction($texoptionlist);
+	          $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\s*/>|$texoptionlist|;
+	          $result.= $Apache::response::foilgroup{$name.'.text'};
+	        } else {
+	          $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'};
@@ -386,7 +405,11 @@ 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'}=~/<drawoptionlist\s*\/>/) {
+		  $texoptionlist = &texoptionlist_correction($texoptionlist);
+	          $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\s*/>|$texoptionlist|;
+	        }
+		$result.= $Apache::response::foilgroup{$name.'.text'};
 	      } else {
 		  if ($Apache::lonhomework::type eq 'exam') {
 		      $result.= '\item[\textbf{'.$Apache::lonxml::counter.'}.]'.$Apache::response::foilgroup{$name.'.text'};
@@ -425,6 +448,30 @@ sub optionlist_correction {
 }
 
 
+sub texoptionlist_correction {
+    my $texoptionlist = shift;
+    $texoptionlist =~ s/\\item \[\] Possible answers are:\s*/\\fbox\{/;
+    $texoptionlist =~ s/\.$/}/;
+    return $texoptionlist;
+}
+
+
+sub webbubbles {
+
+    my ($ropt,$ralphabet)=@_;
+    my @opt=@$ropt; 
+    my @alphabet=@$ralphabet;
+    my $result='';
+	my $number_of_bubbles = $#opt + 1;
+	$result.= '<table border="1"><tr>';
+	for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
+	   $result.='<td>'.$alphabet[$ind].': '.$opt[$ind].'</td>';
+	}
+	$result.='</tr></table>';
+	return $result;
+}
+
+
 sub bubbles {
 
     my ($ralphabit,$ropt) = @_;