--- loncom/homework/optionresponse.pm	2002/11/10 15:51:31	1.59
+++ loncom/homework/optionresponse.pm	2002/11/13 16:53:11	1.63
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.59 2002/11/10 15:51:31 albertel Exp $
+# $Id: optionresponse.pm,v 1.63 2002/11/13 16:53:11 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -318,22 +318,30 @@ sub displayfoils {
   my @whichopt = &whichfoils($max,$randomize);
   my $part=$Apache::inputtags::part;
   my $id=$Apache::inputtags::response[-1];
+  my $break;
   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 />";
+	my $text=$Apache::response::foilgroup{$name.'.text'};
+	if ($text!~/^\s*$/) {
+	    if ($target eq 'tex') {
+		$break='\vskip 0 mm ';
+	    } elsif ($target eq 'web') {
+		$break='<br />';
+	    }
+	}
+	$result.=$break;
+	if ($target eq 'web') {
+	    my $value=$Apache::response::foilgroup{$name.'.value'};
+	    if (!($text=~s|<drawoptionlist\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|<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";
@@ -351,6 +359,14 @@ sub displayfoils {
     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='<br />';
+	  }
+      }
       my $lastopt=$lastresponse{$name};
       my $optionlist="<option></option>\n";
       my $option;
@@ -369,20 +385,23 @@ sub displayfoils {
 	  if (!($text=~s|<drawoptionlist\s*/>|$optionlist|)) {
 	      $text=$optionlist.$text;
 	  }
-	  $result.="<br />".$text."\n";
+	  $result.=$break.$text."\n";
 	  if ($Apache::lonhomework::type eq 'exam') {
 	    $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*\/>/) {
+	          $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\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'};
@@ -399,7 +418,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'}=~/<drawoptionlist\s*\/>/) {
+	          $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\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'};
@@ -411,13 +433,12 @@ sub displayfoils {
 		  $result.=&bubbles(\@alphabet,\@opt);
 	      }
 	  }
-      } 
+      }
     }
-  } 
-  if ($target ne 'tex') {
-      return $result."<br />";
   }
-  else {
+  if ($target ne 'tex') {
+      return $result.$break;
+  } else {
       return $result;
   }
 }