--- loncom/homework/radiobuttonresponse.pm	2008/12/11 03:29:30	1.134.2.1
+++ loncom/homework/radiobuttonresponse.pm	2008/11/20 15:19:15	1.139
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.134.2.1 2008/12/11 03:29:30 raeburn Exp $
+# $Id: radiobuttonresponse.pm,v 1.139 2008/11/20 15:19:15 jms Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -25,6 +25,8 @@
 # http://www.lon-capa.org/
 #
 
+
+
 package Apache::radiobuttonresponse;
 use strict;
 use HTML::Entities();
@@ -65,21 +67,21 @@ sub start_radiobuttonresponse {
     if ($target eq 'meta') {
 	$result=&Apache::response::meta_package_write('radiobuttonresponse');
     } elsif ($target eq 'edit' ) {
-        $result.=&Apache::edit::start_table($token)
+	$result.=&Apache::edit::start_table($token)
            .'<tr><td>'.&Apache::lonxml::description($token)
            .&Apache::loncommon::help_open_topic('Radio_Response_Problems')
            .'</td>'
            .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
            .&Apache::edit::deletelist($target,$token)
            .'</span></td>'
-           .'<td>&nbsp;'.&Apache::edit::end_row()
+           .'<td>&nbsp'.&Apache::edit::end_row()
            .&Apache::edit::start_spanning_row();
 	$result.=
 	    &Apache::edit::text_arg('Max Number Of Shown Foils:','max',
-				    $token,'4').'&nbsp;'x 3 .
+				    $token,'4').
 	    &Apache::edit::select_arg('Randomize Foil Order:','randomize',
-				      ['yes','no'],$token).'&nbsp;'x 3 .
-	    &Apache::edit::select_arg('Display Direction:','direction',
+				      ['yes','no'],$token).
+	    &Apache::edit::select_arg('Display Direction','direction',
 				      ['vertical','horizontal'],$token).
 				      &Apache::edit::end_row().
 				      &Apache::edit::start_spanning_row()."\n";
@@ -102,7 +104,12 @@ sub start_radiobuttonresponse {
 	} else {
 	    $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
 	}
-	$result .= '\begin{enumerate}';
+        if($env{'form.pdfFormFields'} eq 'yes') {
+            $result .= &Apache::lonxml::print_pdf_hiddenfield('meta', $env{'user.name'}, $env{'user.domain'});
+            $result .= "\n\\\\\n\\\\\n";
+        } else {
+            $result .= '\begin{enumerate}';
+        }
     } elsif ($target eq 'analyze') {
 	my $part_id="$Apache::inputtags::part.$id";
         $Apache::lonhomework::analyze{"$part_id.type"} = 'radiobuttonresponse';
@@ -115,7 +122,9 @@ sub end_radiobuttonresponse {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;
     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
-    if ($target eq 'tex') { $result .= '\end{enumerate}'; }
+    if ($target eq 'tex' and $env{'form.pdfFormFields'} ne 'yes') { 
+        $result .= '\end{enumerate}'; 
+    }
     &Apache::response::end_response;
     pop @Apache::lonxml::namespace;
     &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
@@ -349,13 +358,27 @@ sub displayallfoils {
 		    $result.="<td>";
 		} else {
 		    if ($target eq 'tex') {
-			$result .= '\item \vskip -2mm ';
-		    } else {
+		        if($env{'form.pdfFormFields'} eq 'yes') {
+                            my $fieldname = $env{'request.symb'}.
+                                           '&part_'. $Apache::inputtags::part.
+                                           '&radiobuttonresponse'.
+                                           '&HWVAL_' . $Apache::inputtags::response['-1'];
+                            my $value = $temp;
+                            my $text = $Apache::response::foilgroup{$name.'.text'};
+                            $result .= &Apache::lonxml::print_pdf_radiobutton($fieldname,
+                                                                             $value,
+                                                                             $text)."\n";
+                        } else {
+                            $result .= '\item \vskip -2mm ';
+                        }
+                    } else {
 			$result.="<br />";
 		    }
 		}
 		if ($target eq 'tex') {
-		    $result .= '$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs
+		    if($env{'form.pdfFormFields'} ne 'yes') {
+                        $result .= '$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs
+                    }
 		    $i++;
 		} else {
 		    $result .= '<label>';
@@ -382,33 +405,6 @@ sub displayallfoils {
     return $result;
 }
 
-=pod
-
-=item &whichfoils($max,$randomize)
-
-Randomizes the list of foils.
-Respects
-  - each foils desire to be randomized
-  - the existance of Concept groups of foils (select 1 foil from each)
-  - and selects a single correct statement from all possilble true statments
-  - and limits it to a toal of $max foils
-
-WARNING: this routine uses the random number generator, it should only
-be called once per target, otherwise it can cause randomness changes in
-homework problems.
-
-Arguments
-  $max - maximum number of foils to select (including the true one)
-         (so a max of 5 is: 1 true, 4 false)
-
-  $randomize - whether to randomize the listing of foils, by default
-               will randomize, only if randomize is 'no' will it not
-
-Returns
-  $answer - location in the array of the correct answer
-  @foils  - array of foil names in to display order
-
-=cut
 
 sub whichfoils {
     my ($max,$randomize)=@_;
@@ -634,8 +630,19 @@ sub displayfoils {
 		    $i++;
 		    $bubble_number++;
 		} else {
-		    $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
-		}
+		      if($env{'form.pdfFormFields'} eq 'yes') {
+
+                         my $fieldname = $env{'request.symb'}.
+                                         '&part_'. $Apache::inputtags::part.
+                                         '&radiobuttonresponse'.
+                                         '&HWVAL_' . $Apache::inputtags::response['-1'];
+                         my $value = $temp;
+                         my $text = $Apache::response::foilgroup{$name.'.text'};
+                         $result .= &Apache::lonxml::print_pdf_radiobutton($fieldname, $value, $text).'\newline'."\n";
+                     } else { 
+                         $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
+                     }
+                }
 	    }
 	    if ($target ne 'tex' && $direction eq 'horizontal') {
 		$result.="</td>"; 
@@ -801,4 +808,87 @@ sub insert_foil {
 }
 1;
 __END__
+
+
+
+=head1 NAME
+
+Apache::radiobuttonresponse
+
+=head1 SYNOPSIS
+
+Handles multiple-choice style responses.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 SUBROUTINES
+
+=over
+
+=item start_radiobuttonresponse()
+
+=item bubble_line_count()
+
+=item end_radiobuttonresponse()
+
+=item start_foilgroup()
+
+=item storesurvey()
+
+=item grade_response()
+
+=item end_foilgroup()
+
+=item getfoilcounts()
+
+=item format_prior_answer()
+
+=item displayallfoils()
+
+=item &whichfoils($max,$randomize)
+
+Randomizes the list of foils.
+Respects
+  - each foils desire to be randomized
+  - the existance of Concept groups of foils (select 1 foil from each)
+  - and selects a single correct statement from all possilble true statments
+  - and limits it to a toal of $max foils
+
+WARNING: this routine uses the random number generator, it should only
+be called once per target, otherwise it can cause randomness changes in
+homework problems.
+
+Arguments
+  $max - maximum number of foils to select (including the true one)
+         (so a max of 5 is: 1 true, 4 false)
+
+  $randomize - whether to randomize the listing of foils, by default
+               will randomize, only if randomize is 'no' will it not
+
+Returns
+  $answer - location in the array of the correct answer
+  @foils  - array of foil names in to display order
+
+=item displayfoils()
+
+=item displayallanswers()
+
+=item displayanswers()
+
+=item start_conceptgroup()
+
+=item end_conceptgroup()
+
+=item insert_conceptgroup()
+
+=item start_foil()
+
+=item end_foil()
+
+=item insert_foil()
+
+=back
+
+=cut