--- loncom/homework/grades.pm	2004/09/24 21:08:27	1.204.2.4
+++ loncom/homework/grades.pm	2004/10/14 20:39:34	1.221
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.204.2.4 2004/09/24 21:08:27 albertel Exp $
+# $Id: grades.pm,v 1.221 2004/10/14 20:39:34 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -25,16 +25,6 @@
 #
 # http://www.lon-capa.org/
 #
-# 2/9,2/13 Guy Albertelli
-# 6/8 Gerd Kortemeyer
-# 7/26 H.K. Ng
-# 8/20 Gerd Kortemeyer
-# Year 2002
-# June-August H.K. Ng
-# Year 2003
-# February, March H.K. Ng
-# July, H. K. Ng
-#
 
 package Apache::grades;
 use strict;
@@ -174,7 +164,6 @@ sub get_display_part {
 	if ($symb eq '') { $symb=&Apache::lonnet::symbread($url) }
     }
     my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
-    &Apache::lonnet::logthis("\nsymb $symb\n url  $url\npartID $partID\ndisplay $display \n");
     if (defined($display) and $display ne '') {
 	$display.= " (<font color=\"#999900\">id $partID</font>)";
     } else {
@@ -365,27 +354,36 @@ sub getclasslist {
     #
     my %sections;
     my %fullnames;
-    foreach (keys(%$classlist)) {
-        # the following undefs are for 'domain', and 'username' respectively.
-	my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
-            @{$classlist->{$_}};
+    foreach my $student (keys(%$classlist)) {
+        my $end      = 
+            $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
+        my $start    = 
+            $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
+        my $id       = 
+            $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
+        my $section  = 
+            $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
+        my $fullname = 
+            $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
+        my $status   = 
+            $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
 	# filter students according to status selected
 	if ($filterlist && $ENV{'form.Status'} ne 'Any') {
 	    if ($ENV{'form.Status'} ne $status) {
-		delete ($classlist->{$_});
+		delete ($classlist->{$student});
 		next;
 	    }
 	}
-	$section = ($section ne '' ? $section : 'no');
+	$section = ($section ne '' ? $section : 'none');
 	if (&canview($section)) {
 	    if ($getsec eq 'all' || $getsec eq $section) {
 		$sections{$section}++;
-		$fullnames{$_}=$fullname;
+		$fullnames{$student}=$fullname;
 	    } else {
-		delete($classlist->{$_});
+		delete($classlist->{$student});
 	    }
 	} else {
-	    delete($classlist->{$_});
+	    delete($classlist->{$student});
 	}
     }
     my %seen = ();
@@ -993,6 +991,7 @@ sub sub_page_kw_js {
     my $request = shift;
     my $iconpath = $request->dir_config('lonIconsURL');
     &commonJSfunctions($request);
+    my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
     $request->print(<<SUBJAVASCRIPT);
 <script type="text/javascript" language="javascript">
 
@@ -1105,7 +1104,7 @@ sub sub_page_kw_js {
     pWin = window.open('', 'MessageCenter', 'resizable=yes,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.$docopen;
     pDoc.write("<html><head>");
     pDoc.write("<title>Message Central</title>");
 
@@ -1236,7 +1235,7 @@ sub sub_page_kw_js {
     hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,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.$docopen;
     hDoc.write("<html><head>");
     hDoc.write("<title>Highlight Central</title>");
 
@@ -2320,7 +2319,7 @@ sub viewgrades {
     my $sectionClass;
     if ($ENV{'form.section'} eq 'all') {
 	$sectionClass='Class </h3>';
-    } elsif ($ENV{'form.section'} eq 'no') {
+    } elsif ($ENV{'form.section'} eq 'none') {
 	$sectionClass='Students in no Section </h3>';
     } else {
 	$sectionClass='Students in Section '.$ENV{'form.section'}.'</h3>';
@@ -3071,8 +3070,6 @@ sub getSymbMap {
 	    $minder++;
 	}
     }
-
-    $navmap->untieHashes();
     return \@titles,\%symbx;
 }
 
@@ -3205,8 +3202,6 @@ sub displayPage {
         $curRes = $iterator->next();
     }
 
-    $navmap->untieHashes();
-
     $studentTable.='</td></tr></table></td></tr></table>'."\n".
 	'<input type="button" value="Save" '.
 	'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
@@ -3402,8 +3397,6 @@ sub updateGradeByPage {
         $curRes = $iterator->next();
     }
 
-    $navmap->untieHashes();
-
     $studentTable.='</td></tr></table></td></tr></table>';
     $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
     my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
@@ -3464,10 +3457,11 @@ sub scantron_filenames {
 }
 
 sub scantron_uploads {
+    my ($file2grade) = @_;
     my $result=	'<select name="scantron_selectfile">';
     $result.="<option></option>";
     foreach my $filename (sort(&scantron_filenames())) {
-	$result.="<option>$filename</option>\n";
+	$result.="<option".($filename eq $file2grade ? ' selected="on"':'').">$filename</option>\n";
     }
     $result.="</select>";
     return $result;
@@ -3513,13 +3507,13 @@ sub scantron_CODEunique {
 }
 
 sub scantron_selectphase {
-    my ($r) = @_;
+    my ($r,$file2grade) = @_;
     my ($symb,$url)=&get_symb_and_url($r);
     if (!$symb) {return '';}
     my $sequence_selector=&getSequenceDropDown($r,$symb);
     my $default_form_data=&defaultFormData($symb,$url);
     my $grading_menu_button=&show_grading_menu_form($symb,$url);
-    my $file_selector=&scantron_uploads();
+    my $file_selector=&scantron_uploads($file2grade);
     my $format_selector=&scantron_scantab();
     my $CODE_selector=&scantron_CODElist();
     my $CODE_unique=&scantron_CODEunique();
@@ -3846,7 +3840,8 @@ sub scantron_find_student {
 
 sub scantron_filter {
     my ($curres)=@_;
-    if (ref($curres) && $curres->is_problem() && !$curres->randomout) {
+                        # randomout is dysfunctional at best for this purpose
+    if (ref($curres) && $curres->is_problem()) { #&& !$curres->randomout) {
 	return 1;
     }
     return 0;
@@ -3998,7 +3993,7 @@ sub scantron_form_start {
   <input type="hidden" name="selectpage" value="$ENV{'form.selectpage'}" />
   <input type="hidden" name="scantron_format" value="$ENV{'form.scantron_format'}" />
   <input type="hidden" name="scantron_selectfile" value="$ENV{'form.scantron_selectfile'}" />
-  <input type="hidden" name="scantron_maxbubble" value="$max_bubble'" />
+  <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
   <input type="hidden" name="scantron_CODElist" value="$ENV{'form.scantron_CODElist'}" />
   <input type="hidden" name="scantron_CODEunique" value="$ENV{'form.scantron_CODEunique'}" />
   <input type="hidden" name="scantron_options_redo" value="$ENV{'form.scantron_options_redo'}" />
@@ -4465,13 +4460,15 @@ sub scantron_validate_CODE {
 						 $scan_data);
 	my $CODE=$$scan_record{'scantron.CODE'};
 	my $error=0;
-	if (!exists($allcodes{$CODE}) && !$$scan_record{'scantron.useCODE'}) {
+	if (%allcodes && !exists($allcodes{$CODE}) 
+	    && !$$scan_record{'scantron.useCODE'}) {
 	    &scantron_get_correction($r,$i,$scan_record,
 				     \%scantron_config,
 				     $line,'incorrectCODE',\%allcodes);
 	    return(1,$currentphase);
 	}
-	if (exists($usedCODEs{$CODE}) && $ENV{'form.scantron_CODEunique'}
+	if (exists($usedCODEs{$CODE}) 
+	    && $ENV{'form.scantron_CODEunique'} eq 'yes'
 	    && !$$scan_record{'scantron.CODE_ignore_dup'}) {
 	    &scantron_get_correction($r,$i,$scan_record,
 				     \%scantron_config,
@@ -4650,7 +4647,6 @@ SCANTRONFORM
 #    my $lasttime = &Time::HiRes::time()-$start;
 #    $r->print("<p>took $lasttime</p>");
 
-    $navmap->untieHashes();
     $r->print("</form>");
     $r->print(&show_grading_menu_form($symb,$url));
     return '';
@@ -4711,7 +4707,8 @@ sub scantron_upload_scantron_data_save {
 	}
 	return '';
     }
-    $r->print("Doing upload to ".$ENV{'form.courseid'}." <br />");
+    my %coursedata=&Apache::lonnet::coursedescription($ENV{'form.domainid'}.'_'.$ENV{'form.courseid'});
+    $r->print("Doing upload to ".$coursedata{'description'}." <br />");
     my $home=&Apache::lonnet::homeserver($ENV{'form.courseid'},
 					 $ENV{'form.domainid'});
     my $fname=$ENV{'form.upfile.filename'};
@@ -4728,6 +4725,7 @@ sub scantron_upload_scantron_data_save {
     $fname=~s/[^\w\.\-]//g;
     # See if there is anything left
     unless ($fname) { return 'error: no uploaded file'; }
+    my $uploadedfile=$fname;
     $fname='scantron_orig_'.$fname;
     if (length($ENV{'form.upfile'}) < 2) {
 	$r->print("<font color='red'>Error:</font> The file you attempted to upload, <tt>".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"')."</tt>, contained no information. Please check that you entered the correct filename.");
@@ -4736,11 +4734,11 @@ sub scantron_upload_scantron_data_save {
 	if ($result =~ m|^/uploaded/|) {
 	    $r->print("<font color='green'>Success:</font> Successfully uploaded ".(length($ENV{'form.upfile'})-1)." bytes of data into location <tt>".$result."</tt>");
 	} else {
-	    $r->print("<font color='red'>Error:</font> An error (".$result.") occured when attempting to upload the file, <tt>".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"')."</tt>");
+	    $r->print("<font color='red'>Error:</font> An error (".$result.") occurred when attempting to upload the file, <tt>".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"')."</tt>");
 	}
     }
     if ($symb) {
-	$r->print(&show_grading_menu_form($symb,$url));
+	$r->print(&scantron_selectphase($r,$uploadedfile));
     } else {
 	$r->print($doanotherupload);
     }
@@ -4905,9 +4903,6 @@ GRADINGMENUJS
 
     $result.=&mt('Student Status').':</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
 
-    if (ref($sections) && (grep /no/,@$sections)) {
-	$result.='&nbsp;(Section "no" implies the students were not assigned a section.)<br />';
-    }
     $result.='</td></tr>';
 
     $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.