--- loncom/homework/grades.pm	2003/03/23 07:22:58	1.74
+++ loncom/homework/grades.pm	2003/03/28 18:15:24	1.79
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.74 2003/03/23 07:22:58 albertel Exp $
+# $Id: grades.pm,v 1.79 2003/03/28 18:15:24 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -113,7 +113,7 @@ sub response_type {
 #--- Dumps the class list with usernames,list of sections,
 #--- section, ids and fullnames for each user.
 sub getclasslist {
-    my ($getsec,$hideexpired) = @_;
+    my ($getsec,$filterlist) = @_;
     my $classlist=&Apache::loncoursedata::get_classlist();
     # Bail out if we were unable to get the classlist
     return if (! defined($classlist));
@@ -124,11 +124,13 @@ sub getclasslist {
         # the following undefs are for 'domain', and 'username' respectively.
 	my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
             @{$classlist->{$_}};
-	# still a student?
-	if (($hideexpired) && ($status ne 'Active')) {
-            delete ($classlist->{$_});
-            next;
-        }
+	# filter students according to status selected
+	if ($filterlist && $ENV{'form.status'} ne 'Any') {
+	    if ($ENV{'form.status'} ne $status) {
+		delete ($classlist->{$_});
+		next;
+	    }
+	}
 	$section = ($section ne '' ? $section : 'no');
 	if ($getsec eq 'all' || $getsec eq $section) {
             $sections{$section}++;
@@ -209,8 +211,7 @@ sub jscriptNform {
     $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
-	'<input type="hidden" name="lastCmd" value="'.$ENV{'form.lastCmd'}.'" />'."\n".
-	'<input type="hidden" name="lastSec" value="'.$ENV{'form.lastSec'}.'" />'."\n".
+	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
 	'<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
 	'<input type="hidden" name="command" value="submission" />'."\n".
 	'<input type="hidden" name="student" value="" />'."\n".
@@ -297,9 +298,11 @@ sub listStudents {
 	    '<td><b>Type: </b>'.$responsetype.'</td>'.
 	    '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
     }
-    $result.='</table>';
+    $result.='</table>'."\n";
 
     my $viewgrade = $ENV{'form.handgrade'} eq 'yes' ? 'View/Grade' : 'View';
+    $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ? 
+	&Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
 
     $result='<h3><font color="#339933">&nbsp;'.
 	$viewgrade.
@@ -355,8 +358,7 @@ LISTJAVASCRIPT
 	'<input type="hidden" name="response"    value="'.$ENV{'form.response'}.'" />'."\n".
 	'<input type="hidden" name="handgrade"   value="'.$ENV{'form.handgrade'}.'" /><br />'."\n".
 	'<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" /><br />'."\n".
-	'<input type="hidden" name="lastCmd"     value="'.$ENV{'form.lastCmd'}.'" />'."\n".
-	'<input type="hidden" name="lastSec"     value="'.$ENV{'form.lastSec'}.'" />'."\n".
+	'<input type="hidden" name="saveState"   value="'.$ENV{'form.saveState'}.'" />'."\n".
 	'<input type="hidden" name="probTitle"   value="'.$ENV{'form.probTitle'}.'" />'."\n".
 	'<input type="hidden" name="url"  value="'.$url.'" />'."\n".
 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
@@ -368,7 +370,7 @@ LISTJAVASCRIPT
 	'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
 	'value="'.$viewgrade.'" />'."\n";
  
-    my (undef,undef,$fullname) = &getclasslist($getsec,'0');
+    my (undef,undef,$fullname) = &getclasslist($getsec,$ENV{'form.showgrading'} eq 'yes' ? '1' : '0');
     
     $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
 	'<table border="0"><tr bgcolor="#e6ffff">'.
@@ -631,8 +633,7 @@ sub sub_page_kw_js {
 
 //===================== Show list of keywords ====================
   function keywords(keyform) {
-    var keywds = keyform.value;
-    var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
+    var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keyform.value);
     if (nret==null) return;
     keyform.value = nret;
 
@@ -701,91 +702,97 @@ sub sub_page_kw_js {
     return;
   }
 
+//  var pWin = null;
   function savedMsgHeader(Nmsg,usrctr,fullname) {
-    var height = 50*Nmsg+250;
+    var height = 70*Nmsg+250;
     var scrollbar = "no";
     if (height > 600) {
 	height = 600;
 	scrollbar = "yes";
     }
-/*    if (window.pWin)
-	window.pWin.close(); */
+//    if (window.pWin) window.pWin.close();
     pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
-    pWin.document.write("<html><head>");
-    pWin.document.write("<title>Message Central</title>");
-
-    pWin.document.write("<script language=javascript>");
-    pWin.document.write("function checkInput() {");
-    pWin.document.write("  opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
-    pWin.document.write("  var nmsg   = opener.document.SCORE.savemsgN.value;");
-    pWin.document.write("  var usrctr = document.msgcenter.usrctr.value;");
-    pWin.document.write("  var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
-    pWin.document.write("  newval.value = document.msgcenter.newmsg.value;");
-
-    pWin.document.write("  var msgchk = \\"\\";");
-    pWin.document.write("  if (document.msgcenter.subchk.checked) {");
-    pWin.document.write("     msgchk = \\"msgsub,\\";");
-    pWin.document.write("  }");
-    pWin.document.write(   "for (var i=1; i<=nmsg; i++) {");
-    pWin.document.write("      var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
-    pWin.document.write("      var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
-    pWin.document.write("      opnmsg.value = frmmsg.value;");
-    pWin.document.write("      var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
-    pWin.document.write("      if (chkbox.checked) {");
-    pWin.document.write("         msgchk += \\"savemsg\\"+i+\\",\\";");
-    pWin.document.write("      }");
-    pWin.document.write("  }");
-    pWin.document.write("  if (document.msgcenter.newmsgchk.checked) {");
-    pWin.document.write("     msgchk += \\"newmsg\\"+usrctr;");
-    pWin.document.write("  }");
-    pWin.document.write("  var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
-    pWin.document.write("  includemsg.value = msgchk;");
-
-    pWin.document.write("  self.close()");
-
-    pWin.document.write("}");
-
-    pWin.document.write("<");
-    pWin.document.write("/script>");
-
-    pWin.document.write("</head><body bgcolor=white>");
-
-    pWin.document.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
-    pWin.document.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
-    pWin.document.write("<font color=\\"green\\" size=+1>&nbsp;Compose Message for \"+fullname+\"</font><br><br>");
-
-    pWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
-    pWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
-    pWin.document.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
+    pWin.focus();
+    pDoc = pWin.document;
+    pDoc.write("<html><head>");
+    pDoc.write("<title>Message Central</title>");
+
+    pDoc.write("<script language=javascript>");
+    pDoc.write("function checkInput() {");
+    pDoc.write("  opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
+    pDoc.write("  var nmsg   = opener.document.SCORE.savemsgN.value;");
+    pDoc.write("  var usrctr = document.msgcenter.usrctr.value;");
+    pDoc.write("  var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
+    pDoc.write("  newval.value = document.msgcenter.newmsg.value;");
+
+    pDoc.write("  var msgchk = \\"\\";");
+    pDoc.write("  if (document.msgcenter.subchk.checked) {");
+    pDoc.write("     msgchk = \\"msgsub,\\";");
+    pDoc.write("  }");
+    pDoc.write(   "for (var i=1; i<=nmsg; i++) {");
+    pDoc.write("      var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
+    pDoc.write("      var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
+    pDoc.write("      opnmsg.value = frmmsg.value;");
+    pDoc.write("      var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
+    pDoc.write("      if (chkbox.checked) {");
+    pDoc.write("         msgchk += \\"savemsg\\"+i+\\",\\";");
+    pDoc.write("      }");
+    pDoc.write("  }");
+    pDoc.write("  if (document.msgcenter.newmsgchk.checked) {");
+    pDoc.write("     msgchk += \\"newmsg\\"+usrctr;");
+    pDoc.write("  }");
+    pDoc.write("  var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
+    pDoc.write("  includemsg.value = msgchk;");
+
+    pDoc.write("  self.close()");
+
+    pDoc.write("}");
+
+    pDoc.write("<");
+    pDoc.write("/script>");
+
+    pDoc.write("</head><body bgcolor=white>");
+
+    pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
+    pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
+    pDoc.write("<font color=\\"green\\" size=+1>&nbsp;Compose Message for \"+fullname+\"</font><br><br>");
+
+    pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
+    pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
+    pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
 }
     function displaySubject(msg,shwsel) {
-    pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
-    pWin.document.write("<td>Subject</td>");
-    pWin.document.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
-    pWin.document.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
+    pDoc = pWin.document;
+    pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
+    pDoc.write("<td>Subject</td>");
+    pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
+    pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
 }
 
   function displaySavedMsg(ctr,msg,shwsel) {
-    pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
-    pWin.document.write("<td align=\\"center\\">"+ctr+"</td>");
-    pWin.document.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
-    pWin.document.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
+    pDoc = pWin.document;
+    pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
+    pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
+    pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
+    pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
 }
 
   function newMsg(newmsg,shwsel) {
-    pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
-    pWin.document.write("<td align=\\"center\\">New</td>");
-    pWin.document.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
-    pWin.document.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
+    pDoc = pWin.document;
+    pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
+    pDoc.write("<td align=\\"center\\">New</td>");
+    pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
+    pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
 }
 
   function msgTail() {
-    pWin.document.write("</table>");
-    pWin.document.write("</td></tr></table>&nbsp;");
-    pWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\">&nbsp;&nbsp;");
-    pWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
-    pWin.document.write("</form>");
-    pWin.document.write("</body></html>");
+    pDoc = pWin.document;
+    pDoc.write("</table>");
+    pDoc.write("</td></tr></table>&nbsp;");
+    pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\">&nbsp;&nbsp;");
+    pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
+    pDoc.write("</form>");
+    pDoc.write("</body></html>");
 }
 
 //====================== Script for keyword highlight options ==============
@@ -819,65 +826,70 @@ sub sub_page_kw_js {
     return;
   }
 
-
+//  var hwdWin = null;
   function highlightCentral() {
+//    if (window.hwdWin) window.hwdWin.close();
     hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx=100,screeny=75');
-    hwdWin.document.write("<html><head>");
-    hwdWin.document.write("<title>Highlight Central</title>");
-
-    hwdWin.document.write("<script language=javascript>");
-    hwdWin.document.write("function updateChoice(flag) {");
-    hwdWin.document.write("  opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
-    hwdWin.document.write("  opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
-    hwdWin.document.write("  opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
-    hwdWin.document.write("  opener.document.SCORE.refresh.value = \\"on\\";");
-    hwdWin.document.write("  if (opener.document.SCORE.keywords.value!=\\"\\"){");
-    hwdWin.document.write("     opener.document.SCORE.submit();");
-    hwdWin.document.write("  }");
-    hwdWin.document.write("  self.close()");
-    hwdWin.document.write("}");
-
-    hwdWin.document.write("function radioSelection(radioButton) {");
-    hwdWin.document.write("    var selection=null;");
-    hwdWin.document.write("    for (var i=0; i<radioButton.length; i++) {");
-    hwdWin.document.write("        if (radioButton[i].checked) {");
-    hwdWin.document.write("            selection=radioButton[i].value;");
-    hwdWin.document.write("            return selection;");
-    hwdWin.document.write("        }");
-    hwdWin.document.write("    }");
-    hwdWin.document.write("}");
-
-    hwdWin.document.write("<");
-    hwdWin.document.write("/script>");
-
-    hwdWin.document.write("</head><body bgcolor=white>");
-
-    hwdWin.document.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
-    hwdWin.document.write("<font color=\\"green\\" size=+1>&nbsp;Keyword Highlight Options</font><br><br>");
-
-    hwdWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
-    hwdWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
-    hwdWin.document.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
+    hwdWin.focus();
+    var hDoc = hwdWin.document;
+    hDoc.write("<html><head>");
+    hDoc.write("<title>Highlight Central</title>");
+
+    hDoc.write("<script language=javascript>");
+    hDoc.write("function updateChoice(flag) {");
+    hDoc.write("  opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
+    hDoc.write("  opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
+    hDoc.write("  opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
+    hDoc.write("  opener.document.SCORE.refresh.value = \\"on\\";");
+    hDoc.write("  if (opener.document.SCORE.keywords.value!=\\"\\"){");
+    hDoc.write("     opener.document.SCORE.submit();");
+    hDoc.write("  }");
+    hDoc.write("  self.close()");
+    hDoc.write("}");
+
+    hDoc.write("function radioSelection(radioButton) {");
+    hDoc.write("    var selection=null;");
+    hDoc.write("    for (var i=0; i<radioButton.length; i++) {");
+    hDoc.write("        if (radioButton[i].checked) {");
+    hDoc.write("            selection=radioButton[i].value;");
+    hDoc.write("            return selection;");
+    hDoc.write("        }");
+    hDoc.write("    }");
+    hDoc.write("}");
+
+    hDoc.write("<");
+    hDoc.write("/script>");
+
+    hDoc.write("</head><body bgcolor=white>");
+
+    hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
+    hDoc.write("<font color=\\"green\\" size=+1>&nbsp;Keyword Highlight Options</font><br><br>");
+
+    hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
+    hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
+    hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
   }
 
   function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) { 
-    hwdWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
-    hwdWin.document.write("<td align=\\"left\\">");
-    hwdWin.document.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+">&nbsp;"+clrtxt+"</td>");
-    hwdWin.document.write("<td align=\\"left\\">");
-    hwdWin.document.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+">&nbsp;"+sztxt+"</td>");
-    hwdWin.document.write("<td align=\\"left\\">");
-    hwdWin.document.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+">&nbsp;"+sytxt+"</td>");
-    hwdWin.document.write("</tr>");
+    var hDoc = hwdWin.document;
+    hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
+    hDoc.write("<td align=\\"left\\">");
+    hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+">&nbsp;"+clrtxt+"</td>");
+    hDoc.write("<td align=\\"left\\">");
+    hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+">&nbsp;"+sztxt+"</td>");
+    hDoc.write("<td align=\\"left\\">");
+    hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+">&nbsp;"+sytxt+"</td>");
+    hDoc.write("</tr>");
   }
 
   function highlightend() { 
-    hwdWin.document.write("</table>");
-    hwdWin.document.write("</td></tr></table>&nbsp;");
-    hwdWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\">&nbsp;&nbsp;");
-    hwdWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
-    hwdWin.document.write("</form>");
-    hwdWin.document.write("</body></html>");
+    var hDoc = hwdWin.document;
+    hDoc.write("</table>");
+    hDoc.write("</td></tr></table>&nbsp;");
+    hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\">&nbsp;&nbsp;");
+    hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
+    hDoc.write("</form>");
+    hDoc.write("</body></html>");
   }
 
 </script>
@@ -985,6 +997,9 @@ sub submission {
     if ($counter == 0) {
 	&sub_page_js($request);
 	&sub_page_kw_js($request);
+	$ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ? 
+	    &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
+
 	$request->print('<h3>&nbsp;<font color="#339933">Submission Record</font></h3>'."\n".
 			'<font size=+1>&nbsp;<b>Problem: </b>'.$ENV{'form.probTitle'}.'</font>'."\n");
 
@@ -1015,8 +1030,7 @@ sub submission {
 
 	$request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
 			'<input type="hidden" name="command"    value="handgrade" />'."\n".
-			'<input type="hidden" name="lastCmd"    value="'.$ENV{'form.lastCmd'}.'" />'."\n".
-			'<input type="hidden" name="lastSec"    value="'.$ENV{'form.lastSec'}.'" />'."\n".
+			'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
 			'<input type="hidden" name="probTitle"  value="'.$ENV{'form.probTitle'}.'" />'."\n".
 			'<input type="hidden" name="refresh"    value="off" />'."\n".
 			'<input type="hidden" name="symb"       value="'.$symb.'" />'."\n".
@@ -1081,7 +1095,7 @@ KEYWORDS
     my ($classlist,$fullname);
     if ($ENV{'form.handgrade'} eq 'yes') {
 	my @col_list;
-	($classlist,undef,$fullname) = &getclasslist('all','0');
+	($classlist,undef,$fullname) = &getclasslist('all',$ENV{'form.showgrading'} eq 'yes' ? '1' : '0');
 	for (keys (%$handgrade)) {
 	    my $ncol = &Apache::lonnet::EXT('resource.'.$_.
 					    '.maxcollaborators',
@@ -1122,11 +1136,11 @@ KEYWORDS
                         $result .= 'invalid collaborators';
                     }
                     $result .= ': '.join(', ',@badcollaborators);
-                    
+		    $result .= '</td></tr></table>';                 
                 }
                 if (scalar(@collaborators > $ncol)) {
                     $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
-                    $result .= 'This student has sumbitted too many '.
+                    $result .= 'This student has submitted too many '.
                         'collaborators.  Maximum is '.$ncol;
                     $result .= '</td></tr></table>';
                 }
@@ -1329,7 +1343,7 @@ sub processHandGrade {
 	my $ctr = 0;
 	while ($ctr < $ngrade) {
 	    my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
-	    my ($errorflag) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
+	    my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
 	    if ($errorflag eq 'no_score') {
 		$ctr++;
 		next;
@@ -1343,7 +1357,9 @@ sub processHandGrade {
 		foreach (@msgnum) {
 		    $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
 		}
-		#$message =~ s/\s+/ /g;
+		$message =~ s/<([^>]|\n)*>//g; # removes html codes Or should this be lonnet::escape ??
+		$message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
+		$message.=" for <a href=\"$url?symb=$symb\">$ENV{'form.probTitle'}</a>";
 		$msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
 							       $ENV{'form.msgsub'},$message);
 	    }
@@ -1481,8 +1497,9 @@ sub processHandGrade {
 #---- Save the score and award for each student, if changed
 sub saveHandGrade {
     my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
-    my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
-    my %newrecord;
+    my %record     = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
+    my %newrecord  = ();
+    my ($pts,$wgt) = ('','');
     foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
 	if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
 	    if ($record{'resource.'.$_.'.solved'} ne 'excused') {
@@ -1492,11 +1509,11 @@ sub saveHandGrade {
 		}
 	    }
 	} else {
-	    my $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ? 
-		       $ENV{'form.GD_BOX'.$newflg.'_'.$_} : 
-		       $ENV{'form.RADVAL'.$newflg.'_'.$_});
+	    $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ? 
+		    $ENV{'form.GD_BOX'.$newflg.'_'.$_} : 
+		    $ENV{'form.RADVAL'.$newflg.'_'.$_});
 	    return 'no_score' if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '');
-	    my $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : 
+	    $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : 
 		$ENV{'form.WGT'.$newflg.'_'.$_};
 	    my $partial= $pts/$wgt;
 	    $newrecord{'resource.'.$_.'.awarded'}  = $partial 
@@ -1519,7 +1536,7 @@ sub saveHandGrade {
 	&Apache::lonnet::cstore(\%newrecord,$symb,
 				$ENV{'request.course.id'},$domain,$stuname);
     }
-    return '';
+    return '',$pts,$wgt;
 }
 
 #--------------------------------------------------------------------------------------
@@ -1715,8 +1732,7 @@ sub viewgrades {
 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
 	'<input type="hidden" name="command" value="editgrades" />'."\n".
 	'<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n".
-	'<input type="hidden" name="lastCmd" value="'.$ENV{'form.lastCmd'}.'" />'."\n".
-	'<input type="hidden" name="lastSec" value="'.$ENV{'form.lastSec'}.'" />'."\n".
+	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
 	'<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
 
     $result.='<h3>Assign Common Grade To ';
@@ -1807,7 +1823,7 @@ sub viewgrades {
 
     #get info for each student
     #list all the students - with points and grade status
-    my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
+    my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
     my $ctr = 0;
     foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
 	my ($uname,$udom) = split(/:/);
@@ -2018,48 +2034,6 @@ sub split_part_type {
 #
 #-------------------------- Next few routines handles grading by csv upload
 #
-#--- Menu to upload a csv scores ---
-sub upcsvScores_form {
-    my ($request) = shift;
-    my ($symb,$url)=&get_symb_and_url($request);
-    if (!$symb) {return '';}
-    my $result =<<CSVFORMJS;
-<script type="text/javascript" language="javascript">
-    function checkUpload(formname) {
-	if (formname.upfile.value == "") {
-	    alert("Please use the browse button to select a file from your local directory.");
-	    return false;
-	}
-	formname.submit();
-	if (navigator.appName !="Netscape") {self.close()}; //if netscape if appears to close before submit!!!
-	    // any suggestion how to get around this??
-    }
-    </script>
-CSVFORMJS
-    $ENV{'form.probTitle'} = &Apache::lonnet::metadata($url,'title');
-    $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
-    $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
-    $result.='&nbsp;<b>Specify a file containing the class scores for problem - '.$ENV{'form.probTitle'}.
-	'.</b></td></tr>'."\n";
-    $result.='<tr bgcolor=#ffffe6><td>'."\n";
-    my $upfile_select=&Apache::loncommon::upfile_select_html();
-    $result.=<<ENDUPFORM;
-<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload" target="LONcatInfo">
-<input type="hidden" name="symb" value="$symb" />
-<input type="hidden" name="url" value="$url" />
-<input type="hidden" name="command" value="csvuploadmap" />
-<input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
-$upfile_select
-<br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scores" />&nbsp;
-<input type="button" value="Cancel" onClick="self.close()">
-
-</form>
-ENDUPFORM
-    $result.='</td></tr></table>'."\n";
-    $result.='</td></tr></table>'."\n";
-    return $result;
-}
-
 #--- Javascript to handle csv upload
 sub csvupload_javascript_reverse_associate {
   return(<<ENDPICK);
@@ -2175,8 +2149,7 @@ to this page if the data selected is ins
                                        value="$ENV{'form.upfile_associate'}" />
 <input type="hidden" name="symb"       value="$symb" />
 <input type="hidden" name="url"        value="$url" />
-<input type="hidden" name="lastCmd"    value="$ENV{'form.lastCmd'}" />
-<input type="hidden" name="lastSec"    value="$ENV{'form.lastSec'}" />
+<input type="hidden" name="saveState"  value="$ENV{'form.saveState'}" />
 <input type="hidden" name="probTitle"  value="$ENV{'form.probTitle'}" />
 <input type="hidden" name="command"    value="csvuploadassign" />
 <hr />
@@ -2323,8 +2296,7 @@ sub pickStudentPage {
 <script type="text/javascript" language="javascript">
 
 function checkPickOne(formname) {
-    var user = radioSelection(formname.student);
-    if (user == null) {
+    if (radioSelection(formname.student) == null) {
 	alert("Please select the student you wish to grade.");
 	return;
     }
@@ -2336,20 +2308,28 @@ function checkPickOne(formname) {
 
 function radioSelection(radioButton) {
     var selection=null;
-    for (var i=0; i<radioButton.length; i++) {
-        if (radioButton[i].checked) {
-            return radioButton[i].value;
-        }
+    if (radioButton.length > 1) {
+	for (var i=0; i<radioButton.length; i++) {
+	    if (radioButton[i].checked) {
+		return radioButton[i].value;
+	    }
+	}
+    } else {
+	if (radioButton.checked) return radioButton.value;
     }
     return selection;
 }
-
+    
 function pullDownSelection(selectOne) {
-    var selection=null;
-    for (var i=0; i<selectOne.length; i++) {
-        if (selectOne[i].selected) {
-            return selectOne[i].value;
-        }
+    var selection="";
+    if (selectOne.length > 1) {
+	for (var i=0; i<selectOne.length; i++) {
+	    if (selectOne[i].selected) {
+		return selectOne[i].value;
+	    }
+	}
+    } else {
+	if (selectOne.selected) return selectOne.value;
     }
 }
 </script>
@@ -2398,15 +2378,14 @@ LISTJAVASCRIPT
 	'<input type="hidden" name="command" value="displayPage" />'."\n".
 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."<br><br>\n".
-	'<input type="hidden" name="lastCmd" value="'.$ENV{'form.lastCmd'}.'" />'."\n".
-	'<input type="hidden" name="lastSec" value="'.$ENV{'form.lastSec'}.'" />'."\n";
+	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
 
     $result.='<br />&nbsp;<input type="button" '.
 	'onClick="javascript:checkPickOne(this.form);"value="Submit" /><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</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>'.
@@ -2414,7 +2393,7 @@ LISTJAVASCRIPT
 	'<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td>'.
 	'<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td></tr>';
  
-    my (undef,undef,$fullname) = &getclasslist($getsec,'0');
+    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);
@@ -2439,8 +2418,7 @@ LISTJAVASCRIPT
 
 sub getSymbMap {
     my ($request) = @_;
-    my $navmap = Apache::lonnavmaps::navmap-> new($request,
-						  $ENV{'request.course.fn'}.'.db',
+    my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
 						  $ENV{'request.course.fn'}.'_parms.db',1, 1);
 
     my $res = $navmap->firstResource(); # temp resource to access constants
@@ -2505,7 +2483,7 @@ sub displayPage {
     my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
     my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
     my $pageTitle = $ENV{'form.page'};
-    my (undef,undef,$fullname) = &getclasslist($getsec,'0');
+    my (undef,undef,$fullname) = &getclasslist($getsec,'1');
     my ($uname,$udom) = split(/:/,$ENV{'form.student'});
 
     my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
@@ -2515,8 +2493,7 @@ sub displayPage {
     &sub_page_js($request);
     $request->print($result);
 
-    my $navmap = Apache::lonnavmaps::navmap-> new($request,
-						  $ENV{'request.course.fn'}.'.db',
+    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 $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
@@ -2531,8 +2508,7 @@ sub displayPage {
 	'<input type="hidden" name="title"   value="'.$ENV{'form.title'}.'" />'."\n".
 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
-	'<input type="hidden" name="lastCmd" value="'.$ENV{'form.lastCmd'}.'" />'."\n".
-	'<input type="hidden" name="lastSec" value="'.$ENV{'form.lastSec'}.'" />'."\n";
+	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
 
     my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
 	'/check.gif" height="16" border="0" />';
@@ -2594,11 +2570,14 @@ sub displayPage {
 			my @displaySub = ();
 			foreach my $partid (@{$parts}) {
 			    my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys;
+			    next if ($record{"$version:resource.$partid.solved"} eq '');
+#			    next if ($record{"$version:resource.$partid.award"} eq 'APPROX_ANS' && 
+#				     $record{"$version:resource.$partid.solved"} eq '');
 			    $displaySub[0].=(exists $record{$version.':'.$matchKey[0]}) ? 
-				'<b>Part:</b> '.$partid.'&nbsp;<b>Submission:</b>&nbsp;'
+				'<b>Trial&nbsp;'.$version.'&nbsp;Part&nbsp;'.$partid.'</b>&nbsp; '
 				.$record{$version.':'.$matchKey[0]}.'<br />' : '';
 			    $displaySub[1].=(exists $record{"$version:resource.$partid.award"}) ?
-				'<b>Part:</b> '.$partid.'&nbsp;'.
+				'<b>Part&nbsp;'.$partid.'</b> &nbsp;'.
 				$record{"$version:resource.$partid.award"}.'/'.
 				$record{"$version:resource.$partid.solved"}.'<br />' : '';
 			    $displaySub[2].=(exists $record{"$version:resource.$partid.regrader"}) ?
@@ -2660,7 +2639,7 @@ sub updateGradeByPage {
     my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
     my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
     my $pageTitle = $ENV{'form.page'};
-    my (undef,undef,$fullname) = &getclasslist($getsec,'0');
+    my (undef,undef,$fullname) = &getclasslist($getsec,'1');
     my ($uname,$udom) = split(/:/,$ENV{'form.student'});
 
     my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
@@ -2669,8 +2648,7 @@ sub updateGradeByPage {
 
     $request->print($result);
 
-    my $navmap = Apache::lonnavmaps::navmap-> new($request,
-						  $ENV{'request.course.fn'}.'.db',
+    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 $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
@@ -2755,11 +2733,11 @@ sub updateGradeByPage {
     }
 
     $studentTable.='</td></tr></table></td></tr></table>';
-    $studentTable.=($changeflag == 0 ? 'No score was changed or updated.' :
-		    'The scores were changed for '.
-		    $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
     $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
-    $request->print($studentTable);
+    my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
+		  'The scores were changed for '.
+		  $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
+    $request->print($grademsg.$studentTable);
 
     return '';
 }
@@ -2768,6 +2746,110 @@ sub updateGradeByPage {
 #
 #-------------------------------------------------------------------
 
+#--------------------Scantron Grading-----------------------------------
+#
+#------ start of section for handling grading by page/sequence ---------
+
+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 $ctr=0;
+    foreach (@$titles) {
+	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
+	$result.='<option value="'.$$symbx{$_}.'" '.
+	    ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
+	    '>'.$showtitle.'</option>'."\n";
+	$ctr++;
+    }
+    $result.= '</select>';
+    return $result;
+}
+
+sub scantron_selectphase {
+    my ($r) = @_;
+    my ($symb,$url)=&get_symb_and_url($r);
+    if (!$symb) {return '';}
+    my $sequence_selector=&getSequenceDropDown($r,$symb);
+    my $result;
+    $result.= <<SCANTRONFORM;
+<form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
+  <input type="hidden" name="symb" value="$symb" />
+  <input type="hidden" name="url" value="$url" />
+  <input type="hidden" name="command" value="scantron_configphase" />
+  <table width="100%" border="0">
+    <tr>
+      <td bgcolor="#777777">
+        <table width="100%" border="0">
+          <tr bgcolor="#e6ffff">
+            <td>
+              &nbsp;<b>Specify file location and which Folder/Sequence to grade</b>
+            </td>
+          </tr>
+          <tr bgcolor="#ffffe6">
+            <td>
+               Sequence to grade: $sequence_selector
+	    </td>
+          </tr>
+          <tr bgcolor="#ffffe6">
+            <td>
+		<!-- FIXME I need to present a list of files from a specfic directory that has been configured, or any existing delay queues -->
+		Filename of scoring office file:
+		<select name="selectfile">
+		    <option value="filname1">filename1</option>
+		    <option value="filname2">filename2</option>
+		</select>
+	    </td>
+          </tr>
+        </table>
+      </td>
+    </tr>
+  </table>
+  <input type="submit" value="Submit" />
+</form>
+SCANTRONFORM
+
+    return $result;
+}
+
+sub scantron_configphase {
+    my ($r) = @_;
+    my $sequence=$ENV{'form.selectpage'};
+    my $result;
+    $result.="got page $sequence";
+    $Apache::lonxml::debug=1;
+    &Apache::lonhomework::showhash(%ENV);
+    $Apache::lonxml::debug=0;
+    #FIXME Needs to present some lines from the file and allow the instructor to specify which columns represent what data, possibly have some nice defaults setup, probably should do a pass through all problems for a student to get an idea of how many questions there are, and homw many lines we'll have,
+    return $result;
+}
+
+sub scantron_process_students {
+    #FIXME
+    #   loop through students, {
+    #      Check if studnet info valid, if not add line to delay queue
+    #      foreach question 'submit' the students answer to the server
+    #             through grade target {
+    #         generate data to pass back that includes grade recevied
+    #      }
+    #   }
+    #   loop through delay queue {
+    #      print out each delayed student with interface to select how
+    #          to repair student provided info
+    #       Expected errors include
+    #           1 bad/no stuid/username
+    #           2 invalid bubblings
+    #   }
+    # if delay queue exists 2 submits one to process delayed students one
+    #     to ignore delayed students, possibly saving the delay queue for later
+
+}
+#-------- end of section for handling grading scantron forms -------
+#
+#-------------------------------------------------------------------
+
+
 #-------------------------- Menu interface -------------------------
 #
 #--- Show a Grading Menu button - Calls the next routine ---
@@ -2776,40 +2858,43 @@ sub show_grading_menu_form {
     my $result.='<form action="/adm/grades" method="post">'."\n".
 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
-	'<input type="hidden" name="lastCmd" value="'.$ENV{'form.lastCmd'}.'" />'."\n".
-	'<input type="hidden" name="lastSec" value="'.$ENV{'form.lastSec'}.'" />'."\n".
+	'<input type="hidden" name="saveState"  value="'.$ENV{'form.saveState'}.'" />'."\n".
 	'<input type="hidden" name="command" value="gradingmenu" />'."\n".
 	'<input type="submit" name="submit" value="Grading Menu" />'."\n".
 	'</form>'."\n";
     return $result;
 }
 
+# -- Retrieve choices for grading form
+sub savedState {
+    my %savedState = ();
+    if ($ENV{'form.saveState'}) {
+	foreach (split(/:/,$ENV{'form.saveState'})) {
+	    my ($key,$value) = split(/=/,$_,2);
+	    $savedState{$key} = $value;
+	}
+    }
+    return \%savedState;
+}
+
 #--- Displays the main menu page -------
 sub gradingmenu {
     my ($request) = @_;
     my ($symb,$url)=&get_symb_and_url($request);
     if (!$symb) {return '';}
+    my $probTitle = &Apache::lonnet::gettitle($symb);
 
     $request->print(<<GRADINGMENUJS);
 <script type="text/javascript" language="javascript">
     function checkChoice(formname) {
 	var cmd = formname.command;
-	formname.lastCmd.value = radioSelection(formname.command);
-	formname.lastSec.value = pullDownSelection(formname.section);
-	if (cmd[0].checked || cmd[1].checked || cmd[2].checked) {
-	    formname.submit();
-	}
+	formname.saveState.value = "saveCmd="+radioSelection(cmd)+":saveSec="+pullDownSelection(formname.section)+
+	    ":saveSub="+radioSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.status);
+	if (cmd[0].checked || cmd[1].checked || cmd[2].checked || cmd[4].checked) formname.submit();
 
-	if (cmd[3].checked) {
-	    var url = "/adm/grades?command=csvform&symb="+formname.symb.value+"&url="+formname.url.value;
-	    var options = "width=620,height=340,screenx=70,screeny=75,";
-	    options += "resizable=no,scrollbars=no,status=no,";
-	    options += "menubar=no,toolbar=no,location=no,directories=no";
-	    var newWin = window.open(url, "CSVFile", options);
-	    newWin.focus();
-	}
+	if (cmd[3].checked) browseAndUpload();
 
-	if (cmd[4].checked) {
+	if (cmd[5].checked) {
 	    if (!checkReceiptNo(formname,'notOK')) { return false;}
 	    formname.submit();
 	}
@@ -2826,35 +2911,94 @@ sub gradingmenu {
 	    formname.receipt.focus();
 	    return false;
 	}
-	formname.command[4].checked = true;
+	formname.command[5].checked = true;
 	return true;
     }
 
     function radioSelection(radioButton) {
 	var selection=null;
-	for (var i=0; i<radioButton.length; i++) {
-	    if (radioButton[i].checked) {
-		return radioButton[i].value;
+	if (radioButton.length > 1) {
+	    for (var i=0; i<radioButton.length; i++) {
+		if (radioButton[i].checked) {
+		    return radioButton[i].value;
+		}
 	    }
+	} else {
+	    if (radioButton.checked) return radioButton.value;
 	}
 	return selection;
     }
 
     function pullDownSelection(selectOne) {
 	var selection="";
-	for (var i=0; i<selectOne.length; i++) {
-	    if (selectOne[i].selected) {
-		return selectOne[i].value;
+	if (selectOne.length > 1) {
+	    for (var i=0; i<selectOne.length; i++) {
+		if (selectOne[i].selected) {
+		    return selectOne[i].value;
+		}
 	    }
+	} else {
+	    if (selectOne.selected) return selectOne.value;
 	}
     }
+
+    function browseAndUpload() {
+	bNLoad = window.open('', 'BrowseAndUpload', 'toolbar=no,location=no,scrollbars=no,width=550,height=200,screenx=100,screeny=75');
+	bNLoad.focus();
+	var lDoc = bNLoad.document;
+	lDoc.write("<html><head>");
+	lDoc.write("<title>Browse And Upload</title>");
+	
+	lDoc.write("<script language=javascript>");
+	lDoc.write("function checkUpload(formname) {");
+	
+	lDoc.write("  if (formname.upfile.value == \\"\\") {");
+	lDoc.write("     alert(\\"Please use the browse button to select a file from your local directory.\\");");
+	lDoc.write("     return false;");
+	lDoc.write("   }");
+	lDoc.write("   var openformname = opener.document.gradingMenu;");
+	lDoc.write("   formname.saveState.value = \\"saveCmd=\\"+opener.radioSelection(openformname.command)+\\":saveSec=\\"+opener.pullDownSelection(openformname.section)+\\":saveSub=\\"+opener.radioSelection(openformname.submitonly)+\\":saveStatus=\\"+opener.pullDownSelection(openformname.status);");
+	lDoc.write("   document.gradesupload.submit();");
+	lDoc.write("   if (navigator.appName !=\\"Netscape\\") {self.close()};");
+	lDoc.write("   setTimeout('self.close()',750)"); 
+	lDoc.write("}");
+
+	lDoc.write("<");
+	lDoc.write("/script>");
+
+	lDoc.write("</head><body bgcolor=white>");
+	lDoc.write("<form method=\\"post\\" enctype=\\"multipart/form-data\\" action=\\"/adm/grades\\" name=\\"gradesupload\\" target=\\"LONcatInfo\\">");
+	lDoc.write("<input type=\\"hidden\\" name=\\"symb\\"       value=\\"$symb\\">");
+	lDoc.write("<input type=\\"hidden\\" name=\\"url\\"        value=\\"$url\\">");
+	lDoc.write("<input type=\\"hidden\\" name=\\"probTitle\\"  value=\\"$probTitle\\">");
+	lDoc.write("<input type=\\"hidden\\" name=\\"saveState\\"  value=\\"\\">");
+	lDoc.write("<input type=\\"hidden\\" name=\\"command\\"    value=\\"csvuploadmap\\">");
+
+	lDoc.write("<font color=\\"green\\" size=+1>&nbsp;<b>Specify a file containing the class scores for problem - $probTitle</b></font><br><br>");
+
+	lDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
+	lDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
+	lDoc.write("<td>");
+	lDoc.write("<input type=\\"file\\" name=\\"upfile\\" size=\\"50\\" />");
+	lDoc.write("<br />Type: <select name=\\"upfiletype\\">");
+        lDoc.write("<option value=\\"csv\\">CSV (comma separated values, spreadsheet)</option>");
+        lDoc.write("<option value=\\"space\\">Space separated</option>");
+        lDoc.write("<option value=\\"tab\\">Tabulator separated</option>");
+        lDoc.write("<option value=\\"xml\\">HTML/XML</option>");
+        lDoc.write("</select>");
+        lDoc.write("</td></tr></table>");
+        lDoc.write("</td></tr></table>&nbsp;");
+        lDoc.write("<input type=\\"button\\" value=\\"Upload Scores\\" onClick=\\"javascript:checkUpload(this.form)\\">&nbsp;&nbsp;");
+        lDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
+        lDoc.write("</form>");
+        lDoc.write("</body></html>");
+  }
 </script>
 GRADINGMENUJS
 
-    my $probTitle = &Apache::lonnet::metadata($ENV{'form.url'},'title');
     my $result='<h3>&nbsp;<font color="#339933">Manual Grading/View Submission</font></h3>'.
 	'<table border="0">'.
-	'<tr><td colspan=3><font size=+1><b>Problem: </b>'.$probTitle.'</font></td></tr>';
+	'<tr><td colspan=3><font size=+1><b>Problem: </b>'.$probTitle.'</font></td></tr>'."\n";
     my ($partlist,$handgrade) = &response_type($url);
     my ($resptype,$hdgrade)=('','no');
     for (sort keys(%$handgrade)) {
@@ -2865,11 +3009,14 @@ GRADINGMENUJS
 	    '<td><b>Type: </b>'.$responsetype.'</td>'.
 	    '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
     }
-    $result.='</table>';
+    $result.='</table>'."\n";
 
-    my ($classlist,$sections) = &getclasslist('all','0');
-    my $lastCmd = ($ENV{'form.lastCmd'} eq '' ? 'pickStudentPage' : $ENV{'form.lastCmd'});
-    my $lastSec = ($ENV{'form.lastSec'} eq '' ? 'all' : $ENV{'form.lastSec'});
+    my (undef,$sections) = &getclasslist('all','0');
+    my $savedState = &savedState();
+    my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'pickStudentPage' : $$savedState{'saveCmd'});
+    my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
+    my $saveSub = ($$savedState{'saveSub'} eq '' ? 'yes' : $$savedState{'saveSub'});
+    my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
 
     $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
 	'<input type="hidden" name="symb"        value="'.$symb.'" />'."\n".
@@ -2877,8 +3024,7 @@ GRADINGMENUJS
 	'<input type="hidden" name="response"    value="'.$resptype.'" />'."\n".
 	'<input type="hidden" name="handgrade"   value="'.$hdgrade.'" />'."\n".
 	'<input type="hidden" name="probTitle"   value="'.$probTitle.'" />'."\n".
-	'<input type="hidden" name="lastCmd"     value="" />'."\n".
-	'<input type="hidden" name="lastSec"     value="" />'."\n".
+	'<input type="hidden" name="saveState"   value="" />'."\n".
 	'<input type="hidden" name="showgrading" value="yes" />'."\n";
 
     $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n".
@@ -2889,31 +3035,37 @@ GRADINGMENUJS
     $result.='<table width=100% border=0>'.
 	'<tr bgcolor="#ffffe6" valign="top"><td colspan="2">'.
 	'<input type="radio" name="command" value="pickStudentPage" '.
-	($lastCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
+	($saveCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
 	'Handgrade/View Submission for a student by page/sequence</td></tr>'."\n".
 
 	'<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
 	'<input type="radio" name="command" value="viewgrades" '.
-	($lastCmd eq 'viewgrades' ? 'checked' : '').'> '.
+	($saveCmd eq 'viewgrades' ? 'checked' : '').'> '.
 	'Grade by section or class</td></tr>'."\n".
 
 	'<tr bgcolor="#ffffe6"valign="top"><td><input type="radio" name="command" value="submission" '.
-	($lastCmd eq 'submission' ? 'checked' : '').'> '.
+	($saveCmd eq 'submission' ? 'checked' : '').'> '.
 	($hdgrade eq 'yes' ? 'View/Grade essay response of' : 'View').
 	' an individual student </td>'."\n".
 	'<td>-->&nbsp;For students who has: '.
-	'<input type="radio" name="submitonly" value="yes" checked> submitted'.
-	'<input type="radio" name="submitonly" value="all"> everybody</td></tr>'."\n".
+	'<input type="radio" name="submitonly" value="yes" '.
+	($saveSub eq 'yes' ? 'checked' : '').' /> submitted'.
+	'<input type="radio" name="submitonly" value="all" '.
+	($saveSub eq 'all' ? 'checked' : '').' /> everybody</td></tr>'."\n".
 
 	'<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
 	'<input type="radio" name="command" value="csvupload" '.
-	($lastCmd eq 'csvupload' ? 'checked' : '').'> '.
+	($saveCmd eq 'csvupload' ? 'checked' : '').'> '.
 	'Upload scores from file</td></tr>'."\n";
 
+    $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
+	'<input type="radio" name="command" value="scantron_selectphase" /> '.
+        'Grade scantron forms</td></tr>'."\n";
+
     if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)) {
 	$result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
-	    '<input type="radio" name="command" value="verify" onSelect="javascript:this.form.receipt.focus()" '.
-	    ($lastCmd eq 'verify' ? 'checked' : '').'> '.
+	    '<input type="radio" name="command" value="verify" onChecked="javascript:this.form.receipt.focus()" '.
+	    ($saveCmd eq 'verify' ? 'checked' : '').'> '.
 	    'Verify a submission receipt issued by this server</td>'.
 	    '<td>-->&nbsp;Receipt no: '.unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).
 	    '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')">'.
@@ -2921,13 +3073,21 @@ GRADINGMENUJS
     } 
 
     $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2"><br />'."\n".
-	'&nbsp;Select section:</b> <select name="section">'."\n";
+	'&nbsp;Select section: <select name="section">'."\n";
     if (ref($sections)) {
 	foreach (sort (@$sections)) {$result.='<option value="'.$_.'" '.
-					 ($lastSec eq $_ ? 'selected="on"' : '').'>'.$_.'</option>'."\n";}
+					 ($saveSec eq $_ ? 'selected="on"' : '').'>'.$_.'</option>'."\n";}
     }
-    $result.= '<option value="all" '.($lastSec eq 'all' ? 'selected="on"' : ''). '>all</select> &nbsp; '.
-	'<font color="red">(Applies to the first three options only.)</font>'."\n";
+    $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</select> &nbsp; ';
+
+    $result.='Student Status:</b><select name="status">'.
+	'<option value="Active" '.($saveStatus eq 'Active' ? 'selected' : '').'>Active</option>'.
+	'<option value="Expired" '.($saveStatus eq 'Expired' ? 'selected' : '').'>Expired</option>'.
+	'<option value="Any" '.($saveStatus eq 'Any' ? 'selected' : '').'>Any</option>'.
+	'</select>';
+
+    $result.=' &nbsp; <font color="red">(Applies to the first three options only.)</font>'."\n";
+
     if (ref($sections)) {
 	$result.='&nbsp;(Section "no" implies the students were not assigned a section.)<br />' 
 	    if (grep /no/,@$sections);
@@ -3030,6 +3190,10 @@ sub handler {
 		}
 		$request->print(&csvuploadmap($request));
 	    }
+	} elsif ($command eq 'scantron_selectphase') {
+	    $request->print(&scantron_selectphase($request));
+	} elsif ($command eq 'scantron_configphase') {
+	    $request->print(&scantron_configphase($request));
 	} else {
 	    $request->print("Unknown action: $command:");
 	}