[LON-CAPA-cvs] cvs: loncom /homework radiobuttonresponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 24 Aug 2004 23:32:13 -0000


albertel		Tue Aug 24 19:32:13 2004 EDT

  Modified files:              
    /loncom/homework	radiobuttonresponse.pm 
  Log:
   - BUG#3194, radiobutton can be marked as horizontal now
  
  
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.89 loncom/homework/radiobuttonresponse.pm:1.90
--- loncom/homework/radiobuttonresponse.pm:1.89	Thu May 27 00:25:13 2004
+++ loncom/homework/radiobuttonresponse.pm	Tue Aug 24 19:32:13 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.89 2004/05/27 04:25:13 albertel Exp $
+# $Id: radiobuttonresponse.pm,v 1.90 2004/08/24 23:32:13 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -181,8 +181,11 @@
 						 '-2');
 	    my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
 						       $safeeval,'-2');
+	    my $direction = &Apache::lonxml::get_param('direction',$parstack,
+						       $safeeval,'-2');
+	    &Apache::lonxml::debug("direction is $direction");
 	    if ($target eq 'web' || $target eq 'tex') {
-		$result=&displayfoils($target,$max,$randomize);
+		$result=&displayfoils($target,$max,$randomize,$direction);
 	    } elsif ($target eq 'answer' ) {
 		$result=&displayanswers($max,$randomize);
 	    } elsif ( $target eq 'grade') {
@@ -390,7 +393,7 @@
 }
 
 sub displayfoils {
-    my ($target,$max,$randomize)=@_;
+    my ($target,$max,$randomize,$direction)=@_;
     my $result;
 
     my ($answer,@whichfoils)=&whichfoils($max,$randomize);
@@ -398,7 +401,15 @@
     my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
     if ( ($target ne 'tex') &&
 	 &Apache::response::show_answer() ) {
+	if ($direction eq 'horizontal') {
+	    if ($target ne 'tex') {
+		$result.='<table><tr>';
+	    }
+	}
 	foreach my $name (@whichfoils) {
+	    if ($direction eq 'horizontal') {
+		if ($target ne 'tex') { $result.='<td>'; }
+	    }
 	    if ($target ne 'tex') {
 		$result.="<br />";
 	    } else {
@@ -409,14 +420,19 @@
 	    } else {
 		$result.='Incorrect:';
 	    }
-	    if ($target ne 'tex') {
-		$result.=$Apache::response::foilgroup{$name.'.text'}."</input>\n";
-	    } else {
-		$result.=$Apache::response::foilgroup{$name.'.text'};
-	    }
+	    $result.=$Apache::response::foilgroup{$name.'.text'};
+	    if ($target eq 'web') { $result.="</input>\n"; }
 	    if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
 		if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
 	    }
+	    if ($direction eq 'horizontal') {
+		if ($target ne 'tex') { $result.='</td>'; }
+	    }
+	}
+	if ($direction eq 'horizontal') {
+	    if ($target ne 'tex') {
+		$result.='</tr></table>';
+	    }
 	}
     } else {
 	my @alphabet = ('A'..'Z');
@@ -426,9 +442,19 @@
 	my $part=$Apache::inputtags::part;
 	my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
 	my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
+	if ($target ne 'tex' && $direction eq 'horizontal') {
+	    $result.="<table><tr>";
+	}
 	foreach my $name (@whichfoils) {
 	    if ($target ne 'tex') {
-		$result.="<br /><input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
+		if ($direction eq 'horizontal') {
+		    $result.="<td>"; 
+		} else { 
+		    $result.="<br />";
+		} 
+	    }
+	    if ($target ne 'tex') { 
+		$result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
 		if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
 		$result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
 	    } else {
@@ -439,8 +465,14 @@
 		    $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
 		}
 	    }
+	    if ($target ne 'tex' && $direction eq 'horizontal') {
+		$result.="</td>"; 
+	    }
 	    $temp++;
 	}
+	if ($target ne 'tex' && $direction eq 'horizontal') {
+	    $result.="</tr></table>";
+	}
     }
     if ($target ne 'tex') { $result.="<br />"; } else { $result.='\vskip 0 mm '; }
     return $result;