--- loncom/homework/radiobuttonresponse.pm	2012/02/10 00:26:42	1.155
+++ loncom/homework/radiobuttonresponse.pm	2016/01/22 22:42:51	1.160
@@ -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.160 2016/01/22 22:42:51 damieng 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;
 
@@ -596,7 +592,7 @@ sub html_direction_fragments {
     if ($direction eq 'horizontal') {
 	return ('<table><tr>', '</tr></table>', '<td>', '</td>');
     } else {
-	return ('', '<br />', '<br />', '');
+	return ('', '', '<div class="LC_radiofoil">', '</div>');
     }
 }
 
@@ -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;