--- loncom/homework/grades.pm	2004/04/20 06:11:49	1.186
+++ loncom/homework/grades.pm	2004/04/24 08:35:10	1.189
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.186 2004/04/20 06:11:49 albertel Exp $
+# $Id: grades.pm,v 1.189 2004/04/24 08:35:10 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3487,7 +3487,7 @@ sub scantron_selectphase {
     <table width="100%" border="0">
     <tr>
       <td bgcolor="#777777">
-       <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
+       <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
        <input type="hidden" name="command" value="scantron_validate" />
         $default_form_data
         <table width="100%" border="0">
@@ -3519,6 +3519,13 @@ sub scantron_selectphase {
 	    </td>
           </tr>
           <tr bgcolor="#ffffe6">
+	    <td> Options: </td>
+            <td>
+                <input type="checkbox" name="scantron_options" value="redo_skipped"/> Redo skipped records <br />
+                <input type="checkbox" name="scantron_options" value="ignore_corrections"/> Ignore Original Corrections
+	    </td>
+          </tr>
+          <tr bgcolor="#ffffe6">
             <td colspan="2">
               <input type="submit" value="Validate Scantron Records" />
             </td>
@@ -3579,6 +3586,40 @@ UPLOAD
     </tr>
 SCANTRONFORM
     }
+    $r->print(<<SCANTRONFORM);
+    <tr>
+      <td bgcolor="#777777">
+        <form action='/adm/grades' name='scantron_download'>
+          <input type="hidden" name="command" value="scantron_download" />
+          <table width="100%" border="0">
+            <tr bgcolor="#e6ffff">
+              <td colspan="2">
+                &nbsp;<b>Download a scoring office file</b>
+              </td>
+            </tr>
+            <tr bgcolor="#ffffe6">
+              <td> Filename of scoring office file: </td><td> $file_selector </td>
+            </tr>
+            <tr bgcolor="#ffffe6">
+	      <td>
+                Records to download
+              </td>
+              <td>
+                  <input type="radio" name="scantron_options" value="download_skipped"/> Skipped Records <br />
+                  <input type="radio" name="scantron_options" value="download_corrected"/> Corrected Records <br />
+                  <input checked="on" type="radio" name="scantron_options" value="dowload_orig"/> Original Records
+              </td>
+            </tr>
+            <tr bgcolor="#ffffe6">
+              <td colspan="2">
+                <input type="submit" value="Validate Scantron Records" />
+              </td>
+            </tr>
+          </table>
+        </form>
+      </td>
+    </tr>
+SCANTRONFORM
 
     $r->print(<<SCANTRONFORM);
   </table>
@@ -3690,7 +3731,7 @@ sub scan_data {
 }
 
 sub scantron_parse_scanline {
-    my ($line,$whichline,$scantron_config,$scan_data)=@_;
+    my ($line,$whichline,$scantron_config,$scan_data,$justCODE)=@_;
     my %record;
     my $questions=substr($line,$$scantron_config{'Qstart'}-1);
     my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
@@ -3702,6 +3743,7 @@ sub scantron_parse_scanline {
 	    #FIXME interpret first N questions
 	}
     }
+    if ($justCODE) { return \%record; }
     $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
 				  $$scantron_config{'IDlength'});
     $record{'scantron.PaperID'}=
@@ -4061,18 +4103,42 @@ sub scantron_get_correction {
 	$r->print('</li>');
     } elsif ($error =~ /CODE$/) {
 	if ($error eq 'incorrectCODE') {
-	    $r->print("The encoded CODE is not in the list of possible CODEs</p>\n");
+	    $r->print("</p><p>The encoded CODE is not in the list of possible CODEs</p>\n");
 	} elsif ($error eq 'duplicateCODE') {
-	    $r->print("The encoded CODE has also been used by a previous paper $arg, and CODEs were supposed to be unique</p>\n");
+	    $r->print("</p><p>The encoded CODE has also been used by a previous paper $arg, and CODEs were supposed to be unique</p>\n");
 	}
+	$r->print("<p>The CODE on the form is  <tt>".
+		  $$scan_record{'scantron.CODE'}."</tt><br />\n");
 	$r->print("<p>The ID on the form is  <tt>".
 		  $$scan_record{'scantron.ID'}."</tt><br />\n");
 	$r->print("The name on the paper is ".
 		  $$scan_record{'scantron.LastName'}.",".
 		  $$scan_record{'scantron.FirstName'}."</p>");
 	$r->print("<p>How should I handle this? <br /> \n");
-	$r->print("\n<ul><li> ");
-	$r->print('</li>');
+	$r->print("\n<br /> ");
+	$r->print("<input type='radio' name='scan_CODE_resolution' value='use_unfound' checked='on' /> Use the CODE <b><tt>".$$scan_record{'scantron.CODE'}."</tt></b> that is was on the paper, ignoring the error.");
+	$r->print("\n<br />");
+	$r->print(<<ENDSCRIPT);
+<script type="text/javascript">
+function change_radio(field) {
+    var slct=document.scantronupload.scan_CODE_resolution;
+    var i;
+    for (i=0;i<slct.length;i++) {
+        if (slct[i].value==field) { slct[i].checked=true; }
+    }
+}
+</script>
+ENDSCRIPT
+	my $href="/adm/pickcode?".
+	   "form=".&Apache::lonnet::escape("scantronupload").
+	   "&scantron_format=".&Apache::lonnet::escape($ENV{'form.scantron_format'}).
+	   "&scantron_CODElist=".&Apache::lonnet::escape($ENV{'form.scantron_CODElist'}).
+	   "&curCODE=".&Apache::lonnet::escape($$scan_record{'scantron.CODE'}).
+	   "&scantron_selectfile=".&Apache::lonnet::escape($ENV{'form.scantron_selectfile'});
+	$r->print("<input type='radio' name='scan_CODE_resolution' value='use_found' /> <a target='_blank' href='$href'>Select</a> a CODE from the list of all CODEs and use it. Selected CODE is <input readonly='true' type='text' size='8' name='scan_CODE_selectedvalue' onfocus=\"javascript:change_radio('use_found')\" onchange=\"javascript:change_radio('use_found')\" />");
+	$r->print("\n<br />");
+	$r->print("<input type='radio' name='scan_CODE_resolution' value='use_typed' /> Use <input type='text' size='8' name='scan_CODE_newvalue' onfocus=\"javascript:change_radio('use_typed')\" onkeypress=\"javascript:change_radio('use_typed')\" /> as the CODE.");
+	$r->print("\n<br /><br />");
     } elsif ($error eq 'doublebubble') {
 #FIXME Need to print out who this is along with the paper info
 	$r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
@@ -4142,7 +4208,7 @@ sub scantron_validate_CODE {
     my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
     my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
     my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum);
-    my %allcodes=map {($_,1)} split(',',$result{$old_name});
+    my %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
 
     my ($scanlines,$scan_data)=&scantron_getfile();
     for (my $i=0;$i<=$scanlines->{'count'};$i++) {