--- loncom/homework/grades.pm	2003/07/25 20:35:40	1.125
+++ loncom/homework/grades.pm	2003/10/21 21:46:15	1.144
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.125 2003/07/25 20:35:40 ng Exp $
+# $Id: grades.pm,v 1.144 2003/10/21 21:46:15 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -96,6 +96,18 @@ sub get_fullname {
     return $fullname;
 }
 
+#--- Format fullname, username:domain if different for display
+#--- Use anywhere where the student names are listed
+sub nameUserString {
+    my ($type,$fullname,$uname,$udom) = @_;
+    if ($type eq 'header') {
+	return '<b>&nbsp;Fullname&nbsp;</b><font color="#999999">(Username)</font>&nbsp;';
+    } else {
+	return '&nbsp;'.$fullname.'<font color="#999999">&nbsp;('.$uname.
+	    ($ENV{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</font>';
+    }
+}
+
 #--- Get the partlist and the response type for a given problem. ---
 #--- Indicate if a response type is coded handgraded or not. ---
 sub response_type {
@@ -109,9 +121,8 @@ sub response_type {
 	    my ($responsetype,$part) = split(/_/,$_,2);
 	    my ($partid,$respid) = split(/_/,$part);
 	    $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
-#	    my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
-#	    $handgrade{$part} = $responsetype.':'.($value eq 'yes' ? 'yes' : 'no'); #a bug $value is 'yes' regardless
-	    $handgrade{$part} = $responsetype.':'.(($allkeys =~ /parameter_$part\_handgrade/) ? 'yes' : 'no');
+	    my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
+	    $handgrade{$part} = $responsetype.':'.($value eq 'yes' ? 'yes' : 'no'); 
 	    next if ($seen{$partid} > 0);
 	    $seen{$partid}++;
 	    push @partlist,$partid;
@@ -127,7 +138,7 @@ sub showResourceInfo {
     my $result ='<table border="0">'.
 	'<tr><td colspan=3><font size=+1><b>Current Resource: </b>'.$probTitle.'</font></td></tr>'."\n";
     my ($partlist,$handgrade) = &response_type($url);
-    my %resptype = (); #,$hdgrade)=('','no');
+    my %resptype = ();
     my $hdgrade='no';
     for (sort keys(%$handgrade)) {
 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
@@ -154,12 +165,12 @@ sub cleanRecord {
 	    push @ans,$ans;
 	}
 	my $grayFont = '<font color="#999999">';
-	return '<table border="1">'.
+	return '<blockquote><table border="1">'.
 	    '<tr valign="top"><td>Answer</td><td>'.
 	    (join '</td><td>',@ans).'</td></tr>'.
 	    '<tr valign="top"><td>'.$grayFont.'Option ID</font></td><td>'.$grayFont.
 	    (join '</td><td>'.$grayFont,@IDs).'</font></td></tr>'.
-	    '</table>';
+	    '</table></blockquote>';
     }
     if ($response eq 'essay') {
 	if (! exists ($ENV{'form.'.$symb})) {
@@ -174,7 +185,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 &keywords_highlight($answer);
+	return '<br /><br /><blockquote><pre>'.&keywords_highlight($answer).'</pre></blockquote>';
     }
     return $answer;
 }
@@ -207,7 +218,8 @@ sub commonJSfunctions {
 		}
 	    }
 	} else {
-	    if (selectOne.selected) return selectOne.value;
+            // only one value it must be the selected one
+	    return selectOne.value;
 	}
     }
 </script>
@@ -299,7 +311,7 @@ sub student_gradeStatus {
     my %record     = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
     my %partstatus = ();
     foreach (@$partlist) {
-	my ($status,$foo)    = split(/_/,$record{"resource.$_.solved"},2);
+	my ($status,undef)   = split(/_/,$record{"resource.$_.solved"},2);
 	$status              = 'nothing' if ($status eq '');
 	$partstatus{$_}      = $status;
 	my $subkey           = "resource.$_.submitted_by";
@@ -475,7 +487,7 @@ sub listStudents {
 	    sense = "the student";
 	}
 	if (ctr == 0) {
-	    alert("Please select "+sense+" before clicking on the $viewgrade button.");
+	    alert("Please select "+sense+" before clicking on the Next button.");
 	    return false;
 	}
 	document.gradesub.submit();
@@ -495,9 +507,12 @@ LISTJAVASCRIPT
     my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
     my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
     my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'."\n".
-	'&nbsp;<b>View Problem Text: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
+	'&nbsp;<b>View Problem Text: </b><input type="radio" name="vProb" value="no" checked="on" /> no '."\n".
 	'<input type="radio" name="vProb" value="yes" /> one student '."\n".
 	'<input type="radio" name="vProb" value="all" /> all students <br />'."\n".
+	'&nbsp;<b>View Answer: </b><input type="radio" name="vAns" value="no"  /> no '."\n".
+	'<input type="radio" name="vAns" value="yes" /> one student '."\n".
+	'<input type="radio" name="vAns" value="all" checked="on" /> all students <br />'."\n".
 	'&nbsp;<b>Submissions: </b>'."\n";
     if ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
 	$gradeTable.='<input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> essay part only'."\n";
@@ -506,8 +521,8 @@ LISTJAVASCRIPT
     my $saveStatus = $ENV{'form.Status'} eq '' ? 'Active' : $ENV{'form.Status'};
     $ENV{'form.Status'} = $saveStatus;
 
-    $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last sub only'."\n".
-	'<input type="radio" name="lastSub" value="last" /> last sub & parts info'."\n".
+    $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only'."\n".
+	'<input type="radio" name="lastSub" value="last" /> last submission & parts info'."\n".
 	'<input type="radio" name="lastSub" value="datesub" /> by dates and submissions'."\n".
 	'<input type="radio" name="lastSub" value="all" /> all details'."\n".
 	'<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
@@ -527,27 +542,27 @@ LISTJAVASCRIPT
 	    &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'<br />';
     }
 
-    $gradeTable.='To '.lc($viewgrade).' a submission, click on the check box next to the student\'s name. Then '."\n".
-	'click on the '.$viewgrade.' button. To view the submissions for a group of students, click'."\n".
-	' on the check boxes for the group of students.<br />'."\n".
+    $gradeTable.='To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '.
+	'next to the student\'s name(s). Then click on the Next button.<br />'."\n".
 	'<input type="hidden" name="command" value="processGroup" />'."\n";
     $gradeTable.='<input type="button" '."\n".
 	'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
-	'value="'.$viewgrade.'" />'."\n";
-
+	'value="Next->" />'."\n";
+    $gradeTable.='<input type="checkbox" name="checkPlag" checked="on">Check For Plagiarism</input>';
     my (undef, undef, $fullname) = &getclasslist($getsec,'1');  
     $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
 	'<table border="0"><tr bgcolor="#e6ffff">';
     my $loop = 0;
     while ($loop < 2) {
-	$gradeTable.='<td><b>&nbsp;Select&nbsp;</b></td><td><b>&nbsp;Fullname&nbsp;</b>'.
-	    '<font color="#999999">(Username)</font>&nbsp;</td>';
+	$gradeTable.='<td><b>&nbsp;No.</b>&nbsp;</td><td><b>&nbsp;Select&nbsp;</b></td>'.
+	    '<td>'.&nameUserString('header').'</td>';
 	if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
 	    foreach (sort(@$partlist)) {
 		$gradeTable.='<td><b>&nbsp;Part '.(split(/_/))[0].' Status&nbsp;</b></td>';
 	    }
 	}
 	$loop++;
+#	$gradeTable.='<td></td>' if ($loop%2 ==1);
     }
     $gradeTable.='</tr>'."\n";
 
@@ -574,10 +589,10 @@ LISTJAVASCRIPT
 	$ctr++;
 	if ( $perm{'vgr'} eq 'F' ) {
 	    $gradeTable.='<tr bgcolor="#ffffe6">' if ($ctr%2 ==1);
-	    $gradeTable.='<td align="center"><input type=checkbox name="stuinfo" value="'.
+	    $gradeTable.='<td align="right">'.$ctr.'&nbsp;</td>'.
+		'<td align="center"><input type=checkbox name="stuinfo" value="'.
 		$student.':'.$$fullname{$student}.'&nbsp;"></td>'."\n".
-		'<td>&nbsp;'.$$fullname{$student}.'&nbsp;'."\n".
-		'<font color="#999999">('.$uname.')</font></td>'."\n";
+		'<td>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).'</td>'."\n";
 
 	    if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
 		foreach (sort keys(%status)) {
@@ -585,11 +600,12 @@ LISTJAVASCRIPT
 		    $gradeTable.='<td align="middle">&nbsp;'.$status{$_}.'&nbsp;</td>'."\n";
 		}
 	    }
+#	    $gradeTable.='<td></td>' if ($ctr%2 ==1);
 	    $gradeTable.='</tr>'."\n" if ($ctr%2 ==0);
 	}
     }
     if ($ctr%2 ==1) {
-	$gradeTable.='<td>&nbsp;</td><td>&nbsp;</td>';
+	$gradeTable.='<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';
 	    if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
 		foreach (@$partlist) {
 		    $gradeTable.='<td>&nbsp;</td>';
@@ -601,7 +617,7 @@ LISTJAVASCRIPT
     $gradeTable.='</table></td></tr></table>'.
 	'<input type="button" '.
 	'onClick="javascript:checkSelect(this.form.stuinfo);" '.
-	'value="'.$viewgrade.'" /></form>'."\n";
+	'value="Next->" /></form>'."\n";
     if ($ctr == 0) {
 	my $num_students=(scalar(keys(%$fullname)));
 	if ($num_students eq 0) {
@@ -752,12 +768,13 @@ sub sub_page_js {
 	    for (i=0;i<=total;i++) {
 		for (j=0;j<parttot;j++) {
 		    var partid = formname["partid"+i+"_"+j].value;
-		    var selopt = formname["GD_SEL"+i+"_"+partid];
-		    if (selopt[0].selected) {
+		    if (formname["GD_SEL"+i+"_"+partid][0].selected) {
 			var points = formname["GD_BOX"+i+"_"+partid].value;
 			if (points == "") {
 			    var name = formname["name"+i].value;
-			    var resp = confirm("You did not assign a score for "+name+", part "+partid+". Continue?");
+			    var studentID = (name != '' ? name : formname["unamedom"+i].value);
+			    var resp = confirm("You did not assign a score for "+studentID+
+					       ", part "+partid+". Continue?");
 			    if (resp == false) {
 				formname["GD_BOX"+i+"_"+partid].focus();
 				return false;
@@ -785,8 +802,7 @@ sub sub_page_js {
 	var ptr = 0;
 	for (i=1;i<total;i++) {
 	    var partid = formname["q_"+i].value;
-	    var selopt = formname["GD_SEL"+i+"_"+partid];
-	    if (selopt[0].selected) {
+	    if (formname["GD_SEL"+i+"_"+partid][0].selected) {
 		var points = formname["GD_BOX"+i+"_"+partid].value;
 		var status = formname["solved"+i+"_"+partid].value;
 		if (points == "" && status != "correct_by_student") {
@@ -834,8 +850,8 @@ sub sub_page_kw_js {
     if (nret==null) return;
     formname.keywords.value = nret;
 
-    formname.refresh.value = "on";
     if (formname.keywords.value != "") {
+	formname.refresh.value = "on";
 	formname.submit();
     }
     return;
@@ -862,10 +878,9 @@ sub sub_page_kw_js {
     }
     var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
     if (nret==null) return;
-    var curlist = document.SCORE.keywords.value;
-    document.SCORE.keywords.value = curlist+" "+nret;
-    document.SCORE.refresh.value = "on";
+    document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
     if (document.SCORE.keywords.value != "") {
+	document.SCORE.refresh.value = "on";
 	document.SCORE.submit();
     }
     return;
@@ -882,8 +897,7 @@ sub sub_page_kw_js {
     var Nmsg  = msgform.savemsgN.value;
     savedMsgHeader(Nmsg,usrctr,fullname);
     var subject = msgform.msgsub.value;
-    var rtrchk  = document.SCORE["includemsg"+usrctr];
-    var msgchk = rtrchk.value;
+    var msgchk = document.SCORE["includemsg"+usrctr].value;
     re = /msgsub/;
     var shwsel = "";
     if (re.test(msgchk)) { shwsel = "checked" }
@@ -895,8 +909,7 @@ sub sub_page_kw_js {
 	shwsel = "";
 	if (re.test(msgchk)) { shwsel = "checked" }
 	var message = document.SCORE["savemsg"+i].value;
-	var shownOnce = document.SCORE["shownOnce"+i].value;
-	message = (shownOnce == 0 ? checkEntities(message) : message);
+	message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
 	displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
 	                                   //any &lt; is already converted to <, etc. However, only once!!
     }
@@ -932,7 +945,6 @@ sub sub_page_kw_js {
 	height = 600;
 	scrollbar = "yes";
     }
-//    if (window.pWin) {window.pWin.close(); window.pWin=null}
     var xpos = (screen.width-600)/2;
     xpos = (xpos < 0) ? '0' : xpos;
     var ypos = (screen.height-height)/2-30;
@@ -941,6 +953,7 @@ sub sub_page_kw_js {
     pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
     pWin.focus();
     pDoc = pWin.document;
+    pDoc.open('text/html','replace');
     pDoc.write("<html><head>");
     pDoc.write("<title>Message Central</title>");
 
@@ -1027,6 +1040,7 @@ sub sub_page_kw_js {
     pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
     pDoc.write("</form>");
     pDoc.write("</body></html>");
+    pDoc.close();
 }
 
 //====================== Script for keyword highlight options ==============
@@ -1070,6 +1084,7 @@ sub sub_page_kw_js {
     hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
     hwdWin.focus();
     var hDoc = hwdWin.document;
+    hDoc.open('text/html','replace');
     hDoc.write("<html><head>");
     hDoc.write("<title>Highlight Central</title>");
 
@@ -1118,6 +1133,7 @@ sub sub_page_kw_js {
     hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
     hDoc.write("</form>");
     hDoc.write("</body></html>");
+    hDoc.close();
   }
 
 </script>
@@ -1183,27 +1199,46 @@ sub gradeBox {
 }
 
 sub show_problem {
-    my ($request,$symb,$uname,$udom,$removeform,$viewon) = @_;
-    my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
-						      $ENV{'request.course.id'});
+    my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode) = @_;
+    my $rendered;
+    if ($mode eq 'both' or $mode eq 'text') {
+	$rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
+					     $ENV{'request.course.id'});
+    }
     if ($removeform) {
 	$rendered=~s|<form(.*?)>||g;
 	$rendered=~s|</form>||g;
 	$rendered=~s|name="submit"|name="would_have_been_submit"|g;
     }
-    my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
-							   $ENV{'request.course.id'});
+    my $companswer;
+    if ($mode eq 'both' or $mode eq 'answer') {
+	$companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
+						    $ENV{'request.course.id'});
+    }
     if ($removeform) {
 	$companswer=~s|<form(.*?)>||g;
 	$companswer=~s|</form>||g;
-	$rendered=~s|name="submit"|name="would_have_been_submit"|g;
+	$companswer=~s|name="submit"|name="would_have_been_submit"|g;
     }
     my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
     $result.='<table border="0" width="100%">';
-    $result.='<tr><td bgcolor="#e6ffff"><b> View of the problem - '.$ENV{'form.fullname'}.
-	'</b></td></tr>' if ($viewon);
-    $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
-    $result.='<b>Correct answer:</b><br />'.$companswer;
+    if ($viewon) {
+	$result.='<tr><td bgcolor="#e6ffff"><b> ';
+	if ($mode eq 'both' or $mode eq 'text') {
+	    $result.='View of the problem - ';
+	} else {
+	    $result.='Correct answer: ';
+	}
+	$result.=$ENV{'form.fullname'}.'</b></td></tr>';
+    }
+    if ($mode eq 'both') {
+	$result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
+	$result.='<b>Correct answer:</b><br />'.$companswer;
+    } elsif ($mode eq 'text') {
+	$result.='<tr><td bgcolor="#ffffff">'.$rendered;
+    } elsif ($mode eq 'answer') {
+	$result.='<tr><td bgcolor="#ffffff">'.$companswer;
+    }
     $result.='</td></tr></table>';
     $result.='</td></tr></table><br />';
     return $result;
@@ -1252,8 +1287,16 @@ sub submission {
 
 	# option to display problem, only once else it cause problems 
         # with the form later since the problem has a form.
-	if ($ENV{'form.vProb'} eq 'yes' or !$ENV{'form.vProb'}) {
-	    $request->print(&show_problem($request,$symb,$uname,$udom,0,1));
+	if ($ENV{'form.vProb'} eq 'yes' or $ENV{'form.vAns'} eq 'yes') {
+	    my $mode;
+	    if ($ENV{'form.vProb'} eq 'yes' && $ENV{'form.vAns'} eq 'yes') {
+		$mode='both';
+	    } elsif ($ENV{'form.vProb'} eq 'yes') {
+		$mode='text';
+	    } elsif ($ENV{'form.vAns'} eq 'yes') {
+		$mode='answer';
+	    }
+	    $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
 	}
 	
 	# kwclr is the only variable that is guaranteed to be non blank 
@@ -1288,6 +1331,7 @@ sub submission {
 			'<input type="hidden" name="url"        value="'.$url.'" />'."\n".
 			'<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
 			'<input type="hidden" name="vProb"      value="'.$ENV{'form.vProb'}.'" />'."\n".
+			'<input type="hidden" name="vAns"       value="'.$ENV{'form.vAns'}.'" />'."\n".
 			'<input type="hidden" name="lastSub"    value="'.$ENV{'form.lastSub'}.'" />'."\n".
 			'<input type="hidden" name="section"    value="'.$ENV{'form.section'}.'">'."\n".
 			'<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
@@ -1338,10 +1382,19 @@ KEYWORDS
         }
     }
 
-    if ($ENV{'form.vProb'} eq 'all') {
+    if ($ENV{'form.vProb'} eq 'all' or $ENV{'form.vAns'} eq 'all') {
 	$request->print('<br /><br /><br />') if ($counter > 0);
-	$request->print(&show_problem($request,$symb,$uname,$udom,1,1));
+	my $mode;
+	if ($ENV{'form.vProb'} eq 'all' && $ENV{'form.vAns'} eq 'all') {
+	    $mode='both';
+	} elsif ($ENV{'form.vProb'} eq 'all' ) {
+	    $mode='text';
+	} elsif ($ENV{'form.vAns'} eq 'all') {
+	    $mode='answer';
+	}
+	$request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
     }
+
     my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
 
     my ($partlist,$handgrade) = &response_type($url,$symb);
@@ -1351,9 +1404,7 @@ KEYWORDS
     my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
 	'<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
 
-    $result.='<b>Fullname: </b>'.$ENV{'form.fullname'}.
-	'<font color="#999999">&nbsp; &nbsp;Username: '.$uname.
-	($ENV{'user.domain'} eq $udom ? '' : ' ('.$udom.')').'</font><br />'."\n";
+    $result.='<b>Fullname: </b>'.&nameUserString(undef,$ENV{'form.fullname'},$uname,$udom).'<br />'."\n";
     $result.='<input type="hidden" name="name'.$counter.
 	'" value="'.$ENV{'form.fullname'}.'" />'."\n";
 
@@ -1451,13 +1502,20 @@ KEYWORDS
 				my ($ressub,$subval) = split(/:/,$_,2);
                             # Similarity check
 				my $similar='';
-				my ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval);
-				if ($osim) {
-				    $osim=int($osim*100.0);
-				    $similar='<hr /><h3><font color="#FF0000">Essay is '.$osim.
-					'% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom).
-					'</font></h3><blockquote><i>'.
-					&keywords_highlight($oessay).'</i></blockquote><hr />';
+				my $oname;
+				my $odom;
+				my $ocrsid;
+				my $oessay;
+				my $osim;
+				if($ENV{'form.checkPlag'}){
+				    ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval);
+				    if ($osim) {
+					$osim=int($osim*100.0);
+					$similar='<hr /><h3><font color="#FF0000">Essay is '.$osim.
+					    '% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom).
+					    '</font></h3><blockquote><i>'.
+					    &keywords_highlight($oessay).'</i></blockquote><hr />';
+				    }
 				}
 				$lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
 				    $partid.'</b> <font color="#999999">( ID '.$respid.
@@ -1468,11 +1526,9 @@ KEYWORDS
 				     '"><img src="/adm/lonIcons/unknown.gif" border=0"> File uploaded by student</a> '.
 				     '<font color="red" size="1">Like all files provided by users, '.
 				     'this file may contain virusses</font><br />':'').
-				     '<b>Submitted Answer: </b>'.($responsetype =~ /^(essay|option)$/ ? 
-								  '<blockquote>' : '').
+				     '<b>Submitted Answer: </b>'.
 				     &cleanRecord($subval,$responsetype,$symb).
-				     ($responsetype =~ /^(essay|option)$/ ? '</blockquote><br />' : 
-				      '<br /><br />').$similar."\n"
+				     '<br /><br />'.$similar."\n"
 				     if ($ENV{'form.lastSub'} eq 'lastonly' || 
 					 ($ENV{'form.lastSub'} eq 'hdgrade' && 
 					  $$handgrade{$part} =~ /:yes$/));
@@ -1519,7 +1575,6 @@ KEYWORDS
 	    $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
 	}
 	$msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
-#	$result.='<tr><td bgcolor="#ffffff">'."\n".
 	$result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
 	    '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
 	$result.='&nbsp;<a href="javascript:msgCenter(document.SCORE,'.$counter.
@@ -1534,17 +1589,21 @@ KEYWORDS
 
     my %seen = ();
     my @partlist;
+    my @gradePartRespid;
     for (sort keys(%$handgrade)) {
 	my ($partid,$respid) = split(/_/);
 	next if ($seen{$partid} > 0);
 	$seen{$partid}++;
 	next if ($$handgrade{$_} =~ /:no$/ && $ENV{'form.lastSub'} =~ /^(hdgrade)$/);
 	push @partlist,$partid;
+	push @gradePartRespid,$partid.'.'.$respid;
 
 	$request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
     }
     $result='<input type="hidden" name="partlist'.$counter.
 	'" value="'.(join ":",@partlist).'" />'."\n";
+    $result.='<input type="hidden" name="gradePartRespid'.
+	'" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
     my $ctr = 0;
     while ($ctr < scalar(@partlist)) {
 	$result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
@@ -1566,11 +1625,11 @@ KEYWORDS
 	my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
 	$ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
 	$endform.=$ntstu.'student(s) &nbsp;&nbsp;';
-	$endform.='<input type="button" value="Next" '.
-	    'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> &nbsp;'."\n".
-	    '<input type="button" value="Previous" '.
-	    'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> &nbsp;';
-	$endform.='(Next and Previous do not save the scores.)'."\n" ;
+	$endform.='<input type="button" value="Previous" '.
+	    'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> &nbsp;'."\n".
+	    '<input type="button" value="Next" '.
+	    'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> &nbsp;';
+	$endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
 	$endform.='</td><tr></table></form>';
 	$endform.=&show_grading_menu_form($symb,$url);
 	$request->print($endform);
@@ -1770,21 +1829,19 @@ sub processHandGrade {
 	}
     }
     $ctr = 0;
-    my ($partlist,$handgrade) = &response_type($ENV{'form.url'},$symb);
     @parsedlist = reverse @parsedlist if ($button eq 'Previous');
     foreach my $student (@parsedlist) {
 	my ($uname,$udom) = split(/:/,$student);
 	if ($ENV{'form.submitonly'} eq 'yes') {
-	    my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ;
+	    my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
 	    my $statusflg = '';
-	    foreach (keys(%status)) {
-		$statusflg = 1 if ($status{$_} ne 'nothing');
-		my ($foo,$partid,$foo1) = split(/\./);
-		$statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
+	    foreach (split(/:/,$ENV{'form.gradePartRespid'})){
+		$statusflg = 1 if (exists ($record{'resource.'.$_.'.submission'}));
 	    }
 	    next if ($statusflg eq '');
 	}
 	push @nextlist,$student if ($ctr < $ntstu);
+	last if ($ctr == $ntstu);
 	$ctr++;
     }
 
@@ -2059,14 +2116,15 @@ sub viewgrades {
 	'<input type="hidden" name="Status" value="'.$ENV{'form.Status'}.'" />'."\n".
 	'<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
 
-    $result.='<h3>Assign Common Grade To ';
+    my $sectionClass;
     if ($ENV{'form.section'} eq 'all') {
-	$result.='Class </h3>';
+	$sectionClass='Class </h3>';
     } elsif ($ENV{'form.section'} eq 'no') {
-	$result.='Students in no Section </h3>';
+	$sectionClass='Students in no Section </h3>';
     } else {
-	$result.='Students in Section '.$ENV{'form.section'}.'</h3>';
+	$sectionClass='Students in Section '.$ENV{'form.section'}.'</h3>';
     }
+    $result.='<h3>Assign Common Grade To '.$sectionClass;
     $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
 	'<table border=0><tr bgcolor="#ffffdd"><td>';
     #radio buttons/text box for assigning points for a section or class.
@@ -2107,7 +2165,6 @@ sub viewgrades {
 	    'onChange="javascript:writeRadText(\''.$partid.'\','.
 		$weight{$partid}.')"> '.
 	    '<option selected="on"> </option>'.
-#	    '<option>excused</option></select></td></tr>'."\n";
 	    '<option>excused</option>'.
 	    '<option>reset status</option></select></td></tr>'."\n";
 	$ctsparts++;
@@ -2119,21 +2176,14 @@ sub viewgrades {
 
     #table listing all the students in a section/class
     #header of table
-    $result.= '<h3>Assign Grade to Specific Students in ';
-    if ($ENV{'form.section'} eq 'all') {
-	$result.='the Class </h3>';
-    } elsif ($ENV{'form.section'} eq 'no') {
-	$result.='no Section </h3>';
-    } else {
-	$result.='Section '.$ENV{'form.section'}.'</h3>';
-    }
+    $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
     $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
-	'<table border=0><tr bgcolor="#deffff">'.
-	'<td><b>Fullname</b> <font color="#999999">(Username)</font></td>'."\n";
+	'<table border=0><tr bgcolor="#deffff"><td>&nbsp;<b>No.</b>&nbsp;</td>'.
+	'<td>'.&nameUserString('header')."</td>\n";
     my (@parts) = sort(&getpartlist($url));
     foreach my $part (@parts) {
 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
-	$display =~ s/^Number of Attempts/Tries/; # makes the column narrower
+	$display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
 	if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
 	if ($display =~ /^Partial Credit Factor/) {
 	    my ($partid) = &split_part_type($part);
@@ -2154,13 +2204,13 @@ sub viewgrades {
 	my $uname = $_;
 	$uname=~s/:/_/;
 	$result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$uname.'" />'."\n";
-	$result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
-				   $_,$$fullname{$_},\@parts,\%weight);
 	$ctr++;
+	$result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
+				   $_,$$fullname{$_},\@parts,\%weight,$ctr);
     }
     $result.='</table></td></tr></table>';
     $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
-    $result.='<input type="button" value="Submit Changes" '.
+    $result.='<input type="button" value="Save" '.
 	'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
     if (scalar(%$fullname) eq 0) {
 	my $colspan=3+scalar(@parts);
@@ -2173,11 +2223,11 @@ sub viewgrades {
 
 #--- call by previous routine to display each student
 sub viewstudentgrade {
-    my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
+    my ($url,$symb,$courseid,$student,$fullname,$parts,$weight,$ctr) = @_;
     my ($uname,$udom) = split(/:/,$student);
     $student=~s/:/_/;
     my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
-    my $result='<tr bgcolor="#ffffdd"><td>'.
+    my $result='<tr bgcolor="#ffffdd"><td align="right">'.$ctr.'&nbsp;</td><td>&nbsp;'.
 	'<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
 	'\')"; TARGET=_self>'.$fullname.'</a> '.
 	'<font color="#999999">('.$uname.($ENV{'user.domain'} eq $udom ? '' : ':'.$udom).')</font></td>'."\n";
@@ -2197,17 +2247,13 @@ sub viewstudentgrade {
 	    $status = 'nothing' if ($status eq '');
 	    $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
 		$part.'_solved_s" value="'.$status.'" />'."\n";
-	    $result.='<td align="middle"><select name="'.
+	    $result.='<td align="middle">&nbsp;<select name="'.
 		'GD_'.$student.'_'.$part.'_solved" '.
 		'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
-#	    my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
-#	    $optsel = '<option> </option><option selected="on">excused</option>'."\n"
-#		if ($status eq 'excused');
-#	    $result.=$optsel;
 	    $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>' 
 		: '<option selected="on"> </option><option>excused</option>')."\n";
 	    $result.='<option>reset status</option>';
-	    $result.="</select></td>\n";
+	    $result.="</select>&nbsp;</td>\n";
 	} else {
 	    $result.='<input type="hidden" name="'.
 		'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
@@ -2231,9 +2277,11 @@ sub editgrades {
     my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
     $title.='<font size=+1><b>Current Resource: </b>'.$ENV{'form.probTitle'}.'</font><br />'."\n";
     $title.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
+
     my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
     $result.= '<table border="0"><tr bgcolor="#deffff">'.
-	'<td rowspan=2><b>Username</b></td><td rowspan=2><b>Domain</b></td><td rowspan=2><b>Fullname</b></td>'."\n";
+	'<td rowspan=2 valign="center">&nbsp;<b>No.</b>&nbsp;</td>'.
+	'<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
 
     my %scoreptr = (
 		    'correct'  =>'correct_by_override',
@@ -2283,6 +2331,7 @@ sub editgrades {
     $result .= $header;
     $result .= '</tr>'."\n";
     my $noupdate;
+    my ($updateCtr,$noupdateCtr) = (1,1);
     for ($i=0; $i<$ENV{'form.total'}; $i++) {
 	my $line;
 	my $user = $ENV{'form.ctr'.$i};
@@ -2291,12 +2340,10 @@ sub editgrades {
 	my ($uname,$udom)=split(/_/,$user);
 	my %newrecord;
 	my $updateflag = 0;
-	$line .= '<tr bgcolor="#ffffde"><td>'.$uname.'&nbsp;</td><td>'.
-	    $udom.'&nbsp;</td><td>'.
-		$$fullname{$usercolon}.'&nbsp;</td>';
+	$line .= '<td>'.&nameUserString(undef,$$fullname{$usercolon},$uname,$udom).'</td>';
 	my $usec=$classlist->{"$uname:$udom"}[5];
 	if (!&canmodify($usec)) {
-	    my $numcols=scalar(@partid)*(scalar(@parts)-1)*2;
+	    my $numcols=scalar(@partid)*4+2;
 	    $noupdate.=$line."<td colspan=\"$numcols\"><font color=\"red\">Not allowed to modify student</font></td></tr>";
 	    next;
 	}
@@ -2322,25 +2369,23 @@ sub editgrades {
 
 	    if ($dropMenu eq 'reset status' &&
 		$old_score ne '') { # ignore if no previous attempts => nothing to reset
-		print "reset status<br>";
 		$newrecord{'resource.'.$_.'.tries'} = 0;
 		$newrecord{'resource.'.$_.'.solved'} = '';
 		$newrecord{'resource.'.$_.'.award'} = '';
 		$newrecord{'resource.'.$_.'.awarded'} = 0;
 		$newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
 		$updateflag = 1;
+	    } elsif (!($old_part eq $partial && $old_score eq $score)) {
+		$updateflag = 1;
+		$newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
+		$newrecord{'resource.'.$_.'.solved'}   = $score;
+		$rec_update++;
 	    }
 
 	    $line .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
 		'<td align="center">'.$awarded.
 		($score eq 'excused' ? $score : '').'&nbsp;</td>';
 
-	    if (!($old_part eq $partial && $old_score eq $score)) {
-		$updateflag = 1;
-		$newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
-		$newrecord{'resource.'.$_.'.solved'}   = $score;
-		$rec_update++;
-	    }
 
 	    my $partid=$_;
 	    foreach my $stores (@parts) {
@@ -2363,14 +2408,17 @@ sub editgrades {
 	    $count++;
 	    &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
 				    $udom,$uname);
-	    $result.=$line;
+	    $result.='<tr bgcolor="#ffffde"><td align="right">&nbsp;'.$updateCtr.'&nbsp;</td>'.$line;
+	    $updateCtr++;
 	} else {
-	    $noupdate.=$line;
+	    $noupdate.='<tr bgcolor="#ffffde"><td align="right">&nbsp;'.$noupdateCtr.'&nbsp;</td>'.$line;
+	    $noupdateCtr++;
 	}
     }
     if ($noupdate) {
-	my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
-	$result .= '<tr bgcolor="#ffffff"><td align="center" colspan="'.$numcols.'">No Changes Occured For the Students Below</td></tr>'.$noupdate;
+#	my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
+	my $numcols=scalar(@partid)*4+2;
+	$result .= '<tr bgcolor="#ffffff"><td align="center" colspan="'.$numcols.'">No Changes Occurred For the Students Below</td></tr>'.$noupdate;
     }
     $result .= '</table></td></tr></table>'."\n".
 	&show_grading_menu_form ($symb,$url);
@@ -2509,7 +2557,6 @@ to this page if the data selected is ins
 $javascript
 </script>
 ENDPICK
-    $request->print(&show_grading_menu_form($symb,$url));
     return '';
 
 }
@@ -2726,7 +2773,9 @@ LISTJAVASCRIPT
     $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
     $result.='&nbsp;<b>Problems from:</b> <select name="selectpage">'."\n";
     my ($titles,$symbx) = &getSymbMap($request);
-    my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/); 
+    my ($curpage) =&Apache::lonnet::decode_symb($symb); 
+#    my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb); 
+#    my $type=($curpage =~ /\.(page|sequence)/);
     my $ctr=0;
     foreach (@$titles) {
 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
@@ -2746,7 +2795,7 @@ LISTJAVASCRIPT
     $result.='<input type="hidden" name="page" />'."\n".
 	'<input type="hidden" name="title" />'."\n";
 
-    $result.='&nbsp;<b>View Problems Text: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
+    $result.='&nbsp;<b>View Problems Text: </b><input type="radio" name="vProb" value="no" checked="on" /> no '."\n".
 	'<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
 
     $result.='&nbsp;<b>Submission Details: </b>'.
@@ -2762,34 +2811,33 @@ LISTJAVASCRIPT
 	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."<br />\n";
 
     $result.='&nbsp;<input type="button" '.
-	'onClick="javascript:checkPickOne(this.form);"value="Submit" /><br />'."\n";
+	'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
 
     $request->print($result);
 
-    my $studentTable.='&nbsp;<b>Select a student you wish to grade</b><br>'.
+    my $studentTable.='&nbsp;<b>Select a student you wish to grade and then click on the Next button.</b><br>'.
 	'<table border="0"><tr><td bgcolor="#777777">'.
 	'<table border="0"><tr bgcolor="#e6ffff">'.
-	'<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td>'.
-	'<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td>'.
-	'<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td>'.
-	'<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td></tr>';
+	'<td align="right">&nbsp;<b>No.</b></td>'.
+	'<td>'.&nameUserString('header').'</td>'.
+	'<td align="right">&nbsp;<b>No.</b></td>'.
+	'<td>'.&nameUserString('header').'</td></tr>';
  
     my (undef,undef,$fullname) = &getclasslist($getsec,'1');
     my $ptr = 1;
     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
 	my ($uname,$udom) = split(/:/,$student);
-	$studentTable.=($ptr%4 == 1 ? '<tr bgcolor="#ffffe6"><td>' : '</td><td>');
-	$studentTable.='<input type="radio" name="student" value="'.$student.'" /> '.$$fullname{$student}.
-	    '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font>'."\n";
-	$studentTable.=($ptr%4 == 0 ? '</td></tr>' : '');
+	$studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
+	$studentTable.='<td align="right">'.$ptr.'&nbsp;</td>';
+	$studentTable.='<td>&nbsp;<input type="radio" name="student" value="'.$student.'" /> '
+	    .&nameUserString(undef,$$fullname{$student},$uname,$udom)."\n";
+	$studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
 	$ptr++;
     }
-    $studentTable.='</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;' if ($ptr%4 == 2);
-    $studentTable.='</td><td>&nbsp;</td><td>&nbsp;' if ($ptr%4 == 3);
-    $studentTable.='</td><td>&nbsp;' if ($ptr%4 == 0);
+    $studentTable.='</td><td>&nbsp;</td><td>&nbsp;' if ($ptr%2 == 0);
     $studentTable.='</td></tr></table></td></tr></table>'."\n";
-    $studentTable.='<br /><input type="button" '.
-	'onClick="javascript:checkPickOne(this.form);"value="Submit" /></form>'."\n";
+    $studentTable.='<input type="button" '.
+	'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
 
     $studentTable.=&show_grading_menu_form($symb,$url);
     $request->print($studentTable);
@@ -2799,9 +2847,7 @@ LISTJAVASCRIPT
 
 sub getSymbMap {
     my ($request) = @_;
-    my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
-						  $ENV{'request.course.fn'}.'_parms.db');
-    $navmap->init();
+    my $navmap = Apache::lonnavmaps::navmap->new();
 
     my %symbx = ();
     my @titles = ();
@@ -2841,15 +2887,13 @@ sub displayPage {
 	return;
     }
     my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
-    $result.='<h3>&nbsp;Student: '.$$fullname{$ENV{'form.student'}}.
-	'<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
-
+    $result.='<h3>&nbsp;Student: '.&nameUserString(undef,$$fullname{$ENV{'form.student'}},$uname,$udom).
+	'</h3>'."\n";
     &sub_page_js($request);
     $request->print($result);
 
-    my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
-						  $ENV{'request.course.fn'}.'_parms.db',1, 1);
-    my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
+    my $navmap = Apache::lonnavmaps::navmap->new();
+    my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($ENV{'form.page'});
     my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
 
     my $iterator = $navmap->getIterator($map->map_start(),
@@ -2883,7 +2927,6 @@ sub displayPage {
         if($curRes == $iterator->BEGIN_MAP) { $depth++; }
         if($curRes == $iterator->END_MAP) { $depth--; }
 
-#        if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
         if (ref($curRes) && $curRes->is_problem()) {
 	    my $parts = $curRes->parts();
             my $title = $curRes->compTitle();
@@ -2891,8 +2934,9 @@ sub displayPage {
 	    $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
 		(scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).'&nbsp;parts)').'</td>';
 	    $studentTable.='<td valign="top">';
-	    if ($ENV{'form.vProb'} eq 'yes') {
-		$studentTable.=&show_problem($request,$symbx,$uname,$udom,1);
+	    if ($ENV{'form.vProb'} eq 'yes' ) {
+		$studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
+					     undef,'both');
 	    } else {
 		my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$ENV{'request.course.id'});
 		$companswer =~ s|<form(.*?)>||g;
@@ -2982,7 +3026,7 @@ sub displaySubByDates {
 		$$record{"$version:resource.$partid.regrader"}.' (<b>Part:</b> '.$partid.')' : '';
 	}
 	$displaySub[2].=(exists $$record{"$version:resource.regrader"}) ?
-	    $$record{"$version:resource.regrader"} : '';
+	    $$record{"$version:resource.regrader"} : ''; # needed because old essay regrader has not parts info
 	$studentTable.='<td>'.$displaySub[0].'&nbsp;</td><td>'.$displaySub[1].
 	    ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).'&nbsp;</td></tr>';
     }
@@ -3006,14 +3050,13 @@ sub updateGradeByPage {
 	return;
     }
     my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
-    $result.='<h3>&nbsp;Student: '.$ENV{'form.fullname'}.
-	'<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
+    $result.='<h3>&nbsp;Student: '.&nameUserString(undef,$ENV{'form.fullname'},$uname,$udom).
+	'</h3>'."\n";
 
     $request->print($result);
 
-    my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
-						  $ENV{'request.course.fn'}.'_parms.db',1, 1);
-    my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
+    my $navmap = Apache::lonnavmaps::navmap->new();
+    my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $ENV{'form.page'});
     my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
 
     my $iterator = $navmap->getIterator($map->map_start(),
@@ -3062,7 +3105,6 @@ sub updateGradeByPage {
 		    $score = 'excused';
 		} elsif ($dropMenu eq 'reset status'
 			 && $ENV{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
-		    print "got to reset = $ENV{'form.solved'.$question.'_'.$partid}:<br>";
 		    $newrecord{'resource.'.$partid.'.tries'} = 0;
 		    $newrecord{'resource.'.$partid.'.solved'} = '';
 		    $newrecord{'resource.'.$partid.'.award'} = '';
@@ -3136,7 +3178,7 @@ sub getSequenceDropDown {
     my ($request,$symb)=@_;
     my $result='<select name="selectpage">'."\n";
     my ($titles,$symbx) = &getSymbMap($request);
-    my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/); 
+    my ($curpage)=&Apache::lonnet::decode_symb($symb); 
     my $ctr=0;
     foreach (@$titles) {
 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
@@ -3188,7 +3230,7 @@ sub scantron_selectphase {
     my $result;
     $result.= <<SCANTRONFORM;
 <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
-  <input type="hidden" name="command" value="scantron_process" />
+  <input type="hidden" name="command" value="scantron_validate" />
   $default_form_data
   <table width="100%" border="0">
     <tr>
@@ -3218,7 +3260,7 @@ sub scantron_selectphase {
       </td>
     </tr>
   </table>
-  <input type="submit" value="Submit" />
+  <input type="submit" value="Validate Scantron Records" />
 </form>
 $grading_menu_button
 SCANTRONFORM
@@ -3300,14 +3342,23 @@ sub scantron_parse_scanline {
 }
 
 sub scantron_add_delay {
+    my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
+    Apache->request->print('add_delay_error '.$_[2] );
+    push(@$delayqueue,
+	 {'line' => $scanline, 'emsg' => $errormessage,
+	  'ecode' => $errorcode }
+	 );
 }
 
 sub scantron_find_student {
     my ($scantron_record,$idmap)=@_;
     my $scanID=$$scantron_record{'scantron.ID'};
     foreach my $id (keys(%$idmap)) {
-	Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
-	if (lc($id) eq lc($scanID)) { Apache->request->print('success');return $$idmap{$id}; }
+	#Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
+	if (lc($id) eq lc($scanID)) {
+	    #Apache->request->print('success');
+	    return $$idmap{$id};
+	}
     }
     return undef;
 }
@@ -3320,9 +3371,21 @@ sub scantron_filter {
     return 0;
 }
 
+#FIXME I think I am doing this in the wrong order, I think it would be
+#better to make a several passes analyzing all of the lines in the
+#file for common errors wrong/invalid PID/username duplicated
+#PID/username, missing bubbles, double bubbles, missing/invalid CODE
+#and then get the instructor to fix all of these errors, then grade
+#the corrected one, I'll still need to catch error conditions, but
+#maybe most will taken care even before we start
+
+sub scantron_validate_file {
+    my ($r) = @_;
+}
+
 sub scantron_process_students {
     my ($r) = @_;
-    my (undef,undef,$sequence)=split(/___/,$ENV{'form.selectpage'});
+    my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($ENV{'form.selectpage'});
     my ($symb,$url)=&get_symb_and_url($r);
     if (!$symb) {return '';}
     my $default_form_data=&defaultFormData($symb,$url);
@@ -3332,10 +3395,10 @@ sub scantron_process_students {
     my @scanlines=<$scanlines>;
     my $classlist=&Apache::loncoursedata::get_classlist();
     my %idmap=&username_to_idmap($classlist);
-    my $navmap=Apache::lonnavmaps::navmap->new($ENV{'request.course.fn'}.'.db',$ENV{'request.course.fn'}.'_parms.db',1, 1);
+    my $navmap=Apache::lonnavmaps::navmap->new();
     my $map=$navmap->getResourceByUrl($sequence);
     my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
-    $r->print("geto ".scalar(@resources)."<br />");
+#    $r->print("geto ".scalar(@resources)."<br />");
     my $result= <<SCANTRONFORM;
 <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
   <input type="hidden" name="command" value="scantron_configphase" />
@@ -3344,29 +3407,36 @@ SCANTRONFORM
     $r->print($result);
 
     my @delayqueue;
-    my $totalcorrect;
-    my $totalincorrect;
-
+    my %completedstudents;
+    
     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
 	           'Scantron Status','Scantron Progress',scalar(@scanlines));
+    &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
+					  'Processing first student');
+    my $start=&Time::HiRes::time();
     foreach my $line (@scanlines) {
-	my $studentcorrect;
-	my $studentincorrect;
+	$r->print('<pre>line is'.$line.'</pre>');
 
 	chomp($line);
 	my $scan_record=&scantron_parse_scanline($line,\%scantron_config);
 	my ($uname,$udom);
-	if ($uname=&scantron_find_student($scan_record,\%idmap)) {
+	unless ($uname=&scantron_find_student($scan_record,\%idmap)) {
 	    &scantron_add_delay(\@delayqueue,$line,
-				'Unable to find a student that matches');
+				'Unable to find a student that matches',1);
+	    next;
+	}
+	if (exists $completedstudents{$uname}) {
+	    &scantron_add_delay(\@delayqueue,$line,
+				'Student '.$uname.' has multiple sheets',2);
+	    next;
 	}
 	$r->print('<pre>doing studnet'.$uname.'</pre>');
 	($uname,$udom)=split(/:/,$uname);
 	&Apache::lonnet::delenv('form.counter');
 	&Apache::lonnet::appenv(%$scan_record);
 #    &Apache::lonhomework::showhash(%ENV);
-    $Apache::lonxml::debug=1;
-	&Apache::lonxml::debug("line is $line");
+#    $Apache::lonxml::debug=1;
+#	&Apache::lonxml::debug("line is $line");
 	
 	    my $i=0;
 	foreach my $resource (@resources) {
@@ -3378,31 +3448,31 @@ SCANTRONFORM
 				  'grade_domain'  =>$udom,
 				  'grade_courseid'=>$ENV{'request.course.id'},
 				  'grade_symb'    =>$resource->symb()));
-	    my %score=&Apache::lonnet::restore($resource->symb(),
-					       $ENV{'request.course.id'},
-					       $udom,$uname);
-	    foreach my $part ($resource->{PARTS}) {
-		if ($score{'resource.'.$part.'.solved'} =~ /^correct/) {
-		    $studentcorrect++;
-		    $totalcorrect++;
-		} else {
-		    $studentincorrect++;
-		    $totalincorrect++;
-		}
-	    }
-	    $r->print('<pre>'.
-		      $resource->symb().'-'.
-		      $resource->src().'-'.'</pre>result is'.$result);
-	    &Apache::lonhomework::showhash(%score);
+#	    my %score=&Apache::lonnet::restore($resource->symb(),
+#					       $ENV{'request.course.id'},
+#					       $udom,$uname);
+#	    foreach my $part ($resource->{PARTS}) {
+#		if ($score{'resource.'.$part.'.solved'} =~ /^correct/) {
+#		    $studentcorrect++;
+#		    $totalcorrect++;
+#		} else {
+#		    $studentincorrect++;
+#		    $totalincorrect++;
+#		}
+#	    }
+#	    $r->print('<pre>'.
+#		      $resource->symb().'-'.
+#		      $resource->src().'-'.'</pre>result is'.$result);
+#	    &Apache::lonhomework::showhash(%score);
 	#    if ($i eq 3) {last;}
 	}
+	$completedstudents{$uname}={'line'=>$line};
+    } continue {
 	&Apache::lonnet::delenv('form.counter');
 	&Apache::lonnet::delenv('scantron\.');
 	&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
-             'last student Who got a '.$studentcorrect.' correct and '.
-	     $studentincorrect.' incorrect. The class has gotten '.
-             $totalcorrect.' correct and '.$totalincorrect.' incorrect');
-	last;
+						 'last student');
+	#last;
 	#FIXME
 	#get iterator for $sequence
 	#foreach question 'submit' the students answer to the server
@@ -3410,7 +3480,11 @@ SCANTRONFORM
 	#   generate data to pass back that includes grade recevied
 	#}
     }
-    $Apache::lonxml::debug=0;
+    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+    my $lasttime = &Time::HiRes::time()-$start;
+    $r->print("<p>took $lasttime</p>");
+
+    #$Apache::lonxml::debug=0;
     foreach my $delay (@delayqueue) {
 	#FIXME
 	#print out each delayed student with interface to select how
@@ -3563,7 +3637,7 @@ GRADINGMENUJS
 	'The <b>complete</b> set/page/sequence: For one student</td></tr>'."\n";
 
     $result.='<tr bgcolor="#ffffe6"><td><br />'.
-	'<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="View/Grade/Regrade" />'.
+	'<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
 	'</td></tr></table>'."\n";
 
     $result.='</td><td valign="top">';
@@ -3596,9 +3670,9 @@ sub handler {
 
     undef(%perm);
     if ($ENV{'browser.mathml'}) {
-	$request->content_type('text/xml');
+	&Apache::loncommon::content_type($request,'text/xml');
     } else {
-	$request->content_type('text/html');
+	&Apache::loncommon::content_type($request,'text/html');
     }
     $request->send_http_header;
     return '' if $request->header_only;
@@ -3608,7 +3682,7 @@ sub handler {
     my $command=$ENV{'form.command'};
     if (!$url) {
 	my ($temp1,$temp2);
-	($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
+	($temp1,$temp2,$ENV{'form.url'})=&Apache::lonnet::decode_symb($symb);
 	$url = $ENV{'form.url'};
     }
     &send_header($request);
@@ -3621,7 +3695,7 @@ sub handler {
 		my ($tsymb,$tuname,$tudom,$tcrsid)=
 		    &Apache::lonnet::checkin($token);
 		if ($tsymb) {
-		    my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
+		    my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
 		    if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
 			$request->print(&Apache::lonnet::ssi_body('/res/'.$url,
 					  ('grade_username' => $tuname,
@@ -3693,6 +3767,8 @@ sub handler {
 	    }
 	} elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
 	    $request->print(&scantron_selectphase($request));
+	} elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
+	    $request->print(&scantron_validate_file($request));
 	} elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
 	    $request->print(&scantron_process_students($request));
 	} elsif ($command) {