--- loncom/homework/radiobuttonresponse.pm	2008/11/18 19:14:28	1.138
+++ loncom/homework/radiobuttonresponse.pm	2010/02/28 23:42:24	1.144
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.138 2008/11/18 19:14:28 jms Exp $
+# $Id: radiobuttonresponse.pm,v 1.144 2010/02/28 23:42:24 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -26,86 +26,6 @@
 #
 
 
-=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
 
 package Apache::radiobuttonresponse;
 use strict;
@@ -154,14 +74,14 @@ sub start_radiobuttonresponse {
            .'<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').
+				    $token,'4').'&nbsp;'x 3 .
 	    &Apache::edit::select_arg('Randomize Foil Order:','randomize',
-				      ['yes','no'],$token).
-	    &Apache::edit::select_arg('Display Direction','direction',
+				      ['yes','no'],$token).'&nbsp;'x 3 .
+	    &Apache::edit::select_arg('Display Direction:','direction',
 				      ['vertical','horizontal'],$token).
 				      &Apache::edit::end_row().
 				      &Apache::edit::start_spanning_row()."\n";
@@ -184,7 +104,7 @@ sub start_radiobuttonresponse {
 	} else {
 	    $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
 	}
-        if($env{'form.pdfFormFields'} eq 'yes') {
+        if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
             $result .= &Apache::lonxml::print_pdf_hiddenfield('meta', $env{'user.name'}, $env{'user.domain'});
             $result .= "\n\\\\\n\\\\\n";
         } else {
@@ -202,7 +122,7 @@ 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' and $env{'form.pdfFormFields'} ne 'yes') { 
+    if ($target eq 'tex' and ($env{'form.pdfFormFields'} ne 'yes' or $Apache::inputtags::status[-1] ne 'CAN_ANSWER')) {
         $result .= '\end{enumerate}'; 
     }
     &Apache::response::end_response;
@@ -226,6 +146,7 @@ sub start_foilgroup {
 }
 
 sub storesurvey {
+    my ($style) = @_;
     if ( !&Apache::response::submitted() ) { return ''; }
     my $response = $env{'form.HWVAL_'.$Apache::inputtags::response['-1']};
     &Apache::lonxml::debug("Here I am!:$response:");
@@ -239,7 +160,16 @@ sub storesurvey {
     $Apache::lonhomework::results{"resource.$part.$id.submission"}=
 	$responsestr;
     my %previous=&Apache::response::check_for_previous($responsestr,$part,$id);
-    my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
+    my $ad;
+    if ($style eq 'anonsurvey') {
+        $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
+    } elsif ($style eq 'anonsurveycred') {
+        $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CRED';
+    } elsif ($style eq 'surveycred') {
+        $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
+    } else {
+        $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
+    }
     &Apache::response::handle_previous(\%previous,$ad);
     &Apache::lonxml::debug("submitted a $response<br />\n");
     return '';
@@ -304,13 +234,15 @@ sub end_foilgroup {
 	my $style = $Apache::lonhomework::type;
 	my $direction = &Apache::lonxml::get_param('direction',$parstack,
 						   $safeeval,'-2');
-	if ( $style eq 'survey'  && $target ne 'analyze') {
+	if ( (($style eq 'survey') || ($style eq 'surveycred') || 
+              ($style eq 'anonsurvey') || ($style eq 'anonsurveycred')) 
+             && ($target ne 'analyze')) {
 	    if ($target eq 'web' || $target eq 'tex') {
 		$result=&displayallfoils($direction, $target);
 	    } elsif ( $target eq 'answer' ) {
 		$result=&displayallanswers();
 	    } elsif ( $target eq 'grade' ) {
-		$result=&storesurvey();
+		$result=&storesurvey($style);
 	    }
 	    $answer_count = scalar(@{$Apache::response::foilgroup{'names'}});
 
@@ -401,8 +333,11 @@ sub displayallfoils {
     my $i   =0;
     my $id=$Apache::inputtags::response['-1'];
     my $part=$Apache::inputtags::part;
-    my $lastresponse=
-	$Apache::lonhomework::history{"resource.$part.$id.submission"};
+    my $lastresponse;
+    unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) {
+        $lastresponse = 
+	    $Apache::lonhomework::history{"resource.$part.$id.submission"};
+    }
     if ($direction eq 'horizontal') { $result.='<table><tr>'; }
     my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
     if (&Apache::response::show_answer() ) {
@@ -438,7 +373,7 @@ sub displayallfoils {
 		    $result.="<td>";
 		} else {
 		    if ($target eq 'tex') {
-		        if($env{'form.pdfFormFields'} eq 'yes') {
+		        if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                             my $fieldname = $env{'request.symb'}.
                                            '&part_'. $Apache::inputtags::part.
                                            '&radiobuttonresponse'.
@@ -456,7 +391,7 @@ sub displayallfoils {
 		    }
 		}
 		if ($target eq 'tex') {
-		    if($env{'form.pdfFormFields'} ne 'yes') {
+		    if($env{'form.pdfFormFields'} ne 'yes' or $Apache::inputtags::status[-1] ne 'CAN_ANSWER') {
                         $result .= '$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs
                     }
 		    $i++;
@@ -466,8 +401,8 @@ sub displayallfoils {
                        onchange=\"javascript:setSubmittedPart('$part');\"
                        type=\"radio\"
                        name=\"HWVAL_$Apache::inputtags::response['-1']\"
-                       value=\"$temp\" ";
-		    if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
+                       value=\"$temp\"";
+		    if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
 		    $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.
 			'</label>';
 		}
@@ -519,7 +454,11 @@ sub whichfoils {
 		&Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
 	    }
 	}
-	if (!$havetrue && $Apache::lonhomework::type ne 'survey') {
+	if ((!$havetrue) && 
+            ($Apache::lonhomework::type ne 'survey') && 
+            ($Apache::lonhomework::type ne 'surveycred') &&
+            ($Apache::lonhomework::type ne 'anonsurvey') &&
+            ($Apache::lonhomework::type ne 'anonsurveycred')) {
 	    &Apache::lonxml::error(&mt('There are no true statements available.').'<br />');
 	}
     } else {
@@ -579,7 +518,11 @@ sub whichfoils {
 	&Apache::lonxml::debug("Answer wants $answer");
 	my $truename=$truelist[$whichtrue];
 	my $dosplice=1;
-	if ($notrue && $Apache::lonhomework::type ne 'survey') {
+	if (($notrue) && 
+            ($Apache::lonhomework::type ne 'survey') &&
+            ($Apache::lonhomework::type ne 'surveycred') &&
+            ($Apache::lonhomework::type ne 'anonsurvey') &&
+            ($Apache::lonhomework::type ne 'anonsurveycred')) {
 	    $dosplice=0;
 	    &Apache::lonxml::error(&mt('There are no true statements available.').'<br />');
 	}
@@ -695,8 +638,8 @@ sub displayfoils {
 		    "<input type=\"radio\"
                             onchange=\"javascript:setSubmittedPart('$part');\"
                             name=\"HWVAL_$Apache::inputtags::response['-1']\"
-                            value=\"$temp\" ";
-		if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
+                            value=\"$temp\"";
+		if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
 		$result .= ' />'.$Apache::response::foilgroup{$name.'.text'}."</label>";
 	    } else {
 		if ($Apache::lonhomework::type eq 'exam') {
@@ -710,7 +653,7 @@ sub displayfoils {
 		    $i++;
 		    $bubble_number++;
 		} else {
-		      if($env{'form.pdfFormFields'} eq 'yes') {
+		      if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
 
                          my $fieldname = $env{'request.symb'}.
                                          '&part_'. $Apache::inputtags::part.
@@ -888,4 +831,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