--- loncom/homework/grades.pm	2014/12/07 19:45:08	1.729
+++ loncom/homework/grades.pm	2015/02/22 01:34:48	1.732
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.729 2014/12/07 19:45:08 raeburn Exp $
+# $Id: grades.pm,v 1.732 2015/02/22 01:34:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -406,7 +406,7 @@ sub cleanRecord {
 	    $env{'form.kwstyle'}  = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
 	    $env{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
 	}
-	return '<br /><br /><blockquote><tt>'.&keywords_highlight(&HTML::Entities::encode($answer, '"<>&')).'</tt></blockquote>';
+	return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
 
     } elsif ( $response eq 'organic') {
         my $result=&mt('Smile representation: [_1]',
@@ -2231,7 +2231,11 @@ sub submission {
                 if ($hide eq 'rand') {
                     $type = 'randomizetry';
                     $trial = $record{"resource.$partid.tries"};
-                    $rndseed = $record{"resource.$partid.rndseed"};
+                    if (exists($record{"resource.$partid.rawrndseed"})) {
+                        $rndseed = $record{"resource.$partid.rawrndseed"};
+                    } else {
+                        $rndseed = $record{"resource.$partid.rndseed"};
+                    }
                 }
 	        if ($env{'form.checkPlag'}) {
     		    my ($oname,$odom,$ocrsid,$oessay,$osim)=
@@ -2543,7 +2547,7 @@ sub get_last_submission {
             }
             unless ($hide) {
                 if (@randomize) {
-                    foreach my $id (@hidden) {
+                    foreach my $id (@randomize) {
                         if ($key =~ /^\Q$id\E/) {
                             $hide = 'rand';
                             last;
@@ -4857,7 +4861,11 @@ sub displaySubByDates {
                         my ($trial,$rndseed,$newvariation);
                         if ($type eq 'randomizetry') {
                             $trial = $$record{"$where.$partid.tries"};
-                            $rndseed = $$record{"$where.$partid.rndseed"};
+                            if (exists($$record{"$where.$partid.rawrndseed"})) {
+                                $rndseed = $$record{"$where.$partid.rawrndseed"};
+                            } else {
+                                $rndseed = $$record{"$where.$partid.rndseed"};
+                            }
                         }
 		        if ($$record{"$where.$partid.tries"} eq '') {
 			    $displaySub[0].=&mt('Trial not counted');
@@ -5714,7 +5722,9 @@ sub get_scantron_config {
 =item username_to_idmap
 
     creates a hash keyed by student/employee ID with values of the corresponding
-    student username:domain.
+    student username:domain. If a single ID occurs for more than one student,
+    the status of the student is checked, and if Active, the value in the hash
+    will be set to the Active student.
 
   Arguments:
 
@@ -5732,8 +5742,17 @@ sub username_to_idmap {
     my ($classlist)= @_;
     my %idmap;
     foreach my $student (keys(%$classlist)) {
-	$idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
-	    $student;
+        my $id = $classlist->{$student}->[&Apache::loncoursedata::CL_ID];
+        unless ($id eq '') {
+            if (!exists($idmap{$id})) {
+                $idmap{$id} = $student;
+            } else {
+                my $status = $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS];
+                if ($status eq 'Active') {
+                    $idmap{$id} = $student;
+                }
+            }
+        }
     }
     return %idmap;
 }