--- loncom/homework/radiobuttonresponse.pm	2012/02/10 00:26:42	1.155
+++ loncom/homework/radiobuttonresponse.pm	2019/02/03 22:02:21	1.157.2.3
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.155 2012/02/10 00:26:42 foxr Exp $
+# $Id: radiobuttonresponse.pm,v 1.157.2.3 2019/02/03 22:02:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -80,7 +80,8 @@ sub start_radiobuttonresponse {
 	$result=&Apache::response::meta_package_write('radiobuttonresponse');
     } elsif ($target eq 'edit' ) {
 	$result.=&Apache::edit::start_table($token)
-           .'<tr><td>'.&Apache::lonxml::description($token)
+           .'<tr><td>'.&Apache::loncommon::insert_folding_button()
+           .&Apache::lonxml::description($token)
            .&Apache::loncommon::help_open_topic('Radio_Response_Problems')
            .'</td>'
            .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
@@ -90,9 +91,9 @@ sub start_radiobuttonresponse {
            .&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 .
+				      ['yes','no'],$token).
 	    &Apache::edit::select_arg('Display Direction:','direction',
 				      ['vertical','horizontal'],$token).
 				      &Apache::edit::end_row().
@@ -376,24 +377,19 @@ sub get_last_survey_response {
         }
     }
     $showanswer = &Apache::response::show_answer();
-    unless (
-        (
-            (
-                $Apache::lonhomework::history{"resource.$part.type"} eq
-                'anonsurvey'
-            )
-            || ( $Apache::lonhomework::history{"resource.$part.type"} eq
-                'anonsurveycred' )
-        )
-        && ( defined( $env{'form.grade_symb'} ) )
-        || ( $newvariation && !$showanswer )
-      )
-    {
-        $lastresponse =
-          $Apache::lonhomework::history{"resource.$part.$id.submission"};
+    unless ($newvariation && !$showanswer) {
+        if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
+            (($env{'form.grade_username'} eq $env{'user.name'}) &&
+             ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
+            $lastresponse = $Apache::lonhomework::history{"resource.$part.$id.submission"};
+        } else {
+            unless (($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') ||
+                    ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) {
+                $lastresponse = $Apache::lonhomework::history{"resource.$part.$id.submission"};
+            }
+        }
     }
     my %lastresponse = &Apache::lonnet::str2hash($lastresponse);
-   
 
     return \%lastresponse;
 
@@ -829,10 +825,10 @@ sub html_radiobutton {
 
     my $result='<label>';
     
-    $result .= '<input type="radio"
-                onchange="javascript:setSubmittedPart(' . "'$part');\""
-		. 'name="HWVAL_' . $fieldname . '"'
-		. "value='$value'";
+    $result .= '<input type="radio" '
+		. 'onchange="javascript:setSubmittedPart(' . "'$part');\" "
+		. 'name="HWVAL_' . $fieldname . '" '
+		. 'value="'.$value.'"';
 
     if (defined($last_responses->{$name})) {
 	$result .= '  checked="checked" ';
@@ -874,9 +870,21 @@ sub get_last_response {
 	}
     }
     unless ($newvariation) {
-	$lastresponse =
-	    $Apache::lonhomework::history{"resource.$part.$id.submission"};
+        if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
+            (($env{'form.grade_username'} eq $env{'user.name'}) &&
+             ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
+            $lastresponse =
+                $Apache::lonhomework::history{"resource.$part.$id.submission"};
+        } else {
+            unless (($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') ||
+                    ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) {
+                $lastresponse =
+                    $Apache::lonhomework::history{"resource.$part.$id.submission"};
+
+            }
+        }
     }
+
     my %lastresponse = &Apache::lonnet::str2hash($lastresponse);
 
     return \%lastresponse;
@@ -1022,7 +1030,8 @@ sub display_latex_exam {
 		. '} \hspace*{\fill} \\\\';
 	}
 	else {
-	    $result .= '\textbf{' . $Apache::lonxml::counter . '}.';
+	    $result .= '\textbf{' . $Apache::lonxml::counter . '}.'.
+                       '\hspace*{2 mm}';        
 	}
 	
 	# Now output the bubbles themselves:
@@ -1039,7 +1048,15 @@ sub display_latex_exam {
 	    }
 	    my $preindent;
 	    if ($bubble_number > 0) {
-		$preindent = '\hspace*{3 mm}';
+                my $offset = 5;
+                if ($Apache::lonxml::counter) {
+                    if ($identifier) {
+                        $offset += 2 * (length($identifier)-1);
+                    } else {
+                        $offset += 2 * (length($Apache::lonxml::counter)-1);
+                    }
+                }
+                $preindent = '\hspace*{'.$offset.' mm}';
 	    }
 	    my $foiltext = $Apache::response::foilgroup{$name . '.text'};
 	    $foiltext =~ s/\\noindent//; # forgive me for I have sinned..