--- loncom/homework/optionresponse.pm	2012/06/25 10:36:00	1.186
+++ loncom/homework/optionresponse.pm	2013/07/19 18:24:21	1.191
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.186 2012/06/25 10:36:00 foxr Exp $
+# $Id: optionresponse.pm,v 1.191 2013/07/19 18:24:21 bisitz Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -108,7 +108,11 @@ sub start_foilgroup {
     my $optionlist="<option></option>\n";
     my $option;
     my @opt;
-    eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval);
+    my @raw_options = &Apache::lonxml::get_param('options', $parstack, $safeeval, 0,  0, 1);
+
+
+    eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval, 0, 0, 1);
+
     my $count=1;
     foreach $option (@opt) {
       $optionlist.="<option value=\"$count\">$option</option>\n";
@@ -148,7 +152,10 @@ ENDTABLE
   if ($target eq 'modified') {
     my @options;
     my $optchanged=0;
-    eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
+
+
+    eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval, 0, 0, 1);
+
     if ($env{"form.$Apache::lonxml::curdepth.deleteopt"}) {
       my $delopt=$env{"form.$Apache::lonxml::curdepth.deleteopt"};
       &Apache::lonxml::debug("Deleting :$delopt:");
@@ -427,8 +434,11 @@ sub whichfoils {
 
 sub displayanswers {
     my ($max,$randomize,@opt)=@_;
-    if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
-    my @names = @{ $Apache::response::foilgroup{'names'} };
+    my @names;
+    if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
+        @names = @{ $Apache::response::foilgroup{'names'} };
+    }
+    return if (!@names);
     my @whichopt = &whichfoils($max,$randomize);
     my $result;
     if ($Apache::lonhomework::type eq 'exam') {
@@ -489,8 +499,11 @@ sub check_for_invalid {
 sub displayfoils {
   my ($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,
       $tex_option_switch, $no_tfprompt, @opt)=@_;
-  if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
-  my @names = @{ $Apache::response::foilgroup{'names'} };
+  my @names; 
+  if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
+      @names = @{ $Apache::response::foilgroup{'names'} };
+  }
+  unless (@names > 0) { return;}
   my @truelist;
   my @falselist;
   my $result;  
@@ -510,8 +523,15 @@ sub displayfoils {
     foreach $name (@whichopt) {
 	my $text=$Apache::response::foilgroup{$name.'.text'};
         my $lastresp;
-        unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) {
+        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'}))) {
             $lastresp = $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')) {
+                $lastresp = $Apache::lonhomework::history{"resource.$part.$id.submission"};
+            }
         }
 	my %lastresponse=&Apache::lonnet::str2hash($lastresp);
 	my $lastopt=$lastresponse{$name};
@@ -550,14 +570,25 @@ sub displayfoils {
         }
     }
     unless ($newvariation) {
-        %lastresponse=&Apache::lonnet::str2hash($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::lonnet::str2hash($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::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
+            }
+        }
     }
     my $internal_counter=$Apache::lonxml::counter;
     my $checkboxopt=&check_box_opt($target,$checkboxvalue,@opt);
     if ($checkboxopt && (!$no_tfprompt)) {
        $result.='<br />'.
                 ($checkboxchoices?&mt('Choices: ').'<b>'.$opt[0].','.$opt[1].'</b>. ':'').
-                 &mt('Select all that are <b>[_1]</b>.',$checkboxopt);
+                 &mt('Select all that are [_1].','<b>'.$checkboxopt.'</b>');
     }
     foreach $name (@whichopt) {
       my $text=$Apache::response::foilgroup{$name.'.text'};