--- loncom/homework/grades.pm	2007/10/09 23:42:49	1.451
+++ loncom/homework/grades.pm	2007/10/25 20:05:52	1.464
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.451 2007/10/09 23:42:49 albertel Exp $
+# $Id: grades.pm,v 1.464 2007/10/25 20:05:52 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,6 +35,7 @@ use Apache::loncommon;
 use Apache::lonhtmlcommon;
 use Apache::lonnavmaps;
 use Apache::lonhomework;
+use Apache::lonpickcode;
 use Apache::loncoursedata;
 use Apache::lonmsg();
 use Apache::Constants qw(:common);
@@ -56,9 +57,7 @@ my %first_bubble_line = ();	# First bubb
 
 
 sub save_bubble_lines {
-    &Apache::lonnet::logthis("Saving bubble_lines...");
     foreach my $line (keys(%bubble_lines_per_response)) {
-	&Apache::lonnet::logthis("Saving form.scantron.bubblelines.$line value: $bubble_lines_per_response{$line}");
 	$env{"form.scantron.bubblelines.$line"}  = $bubble_lines_per_response{$line};
 	$env{"form.scantron.first_bubble_line.$line"} =
 	    $first_bubble_line{$line};
@@ -71,7 +70,6 @@ sub restore_bubble_lines {
     %bubble_lines_per_response = ();
     while ($env{"form.scantron.bubblelines.$line"}) {
 	my $value = $env{"form.scantron.bubblelines.$line"};
-	&Apache::lonnet::logthis("Restoring form.scantron.bubblelines.$line value: $value");
 	$bubble_lines_per_response{$line} = $value;
 	$first_bubble_line{$line}  =
 	    $env{"form.scantron.first_bubble_line.$line"};
@@ -86,12 +84,14 @@ sub restore_bubble_lines {
 sub get_response_bubbles {
     my ($parsed_line, $response)  = @_;
 
-    my $bubble_line = $first_bubble_line{$response};
-    my $bubble_lines= $bubble_lines_per_response{$response};
+
+    my $bubble_line = $first_bubble_line{$response-1} +1;
+    my $bubble_lines= $bubble_lines_per_response{$response-1};
+    
     my $selected = "";
 
     for (my $bline = 0; $bline < $bubble_lines; $bline++) {
-	$selected .= $$parsed_line{"scantron.$bubble_line.answer"};
+	$selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
 	$bubble_line++;
     }
     return $selected;
@@ -526,12 +526,18 @@ sub getclasslist {
 	    }
 	}
 	# filter students according to groups selected
+	my @stu_groups = split(/,/,$group);
 	if (@getgroup) {
 	    my $exclude = 1;
-	    foreach my $grp(@getgroup) {
-	        if ($group eq $grp) {
-	            $exclude = 0;
+	    foreach my $grp (@getgroup) {
+	        foreach my $stu_group (@stu_groups) {
+	            if ($stu_group eq $grp) {
+	                $exclude = 0;
+    	            } 
 	        }
+    	        if (($grp eq 'none') && !$group) {
+        	        $exclude = 0;
+        	}
 	    }
 	    if ($exclude) {
 	        delete($classlist->{$student});
@@ -970,7 +976,7 @@ LISTJAVASCRIPT
 
 	$ctr++;
 	my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
-
+        my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
 	if ( $perm{'vgr'} eq 'F' ) {
 	    $gradeTable.='<tr bgcolor="#ffffe6">' if ($ctr%2 ==1);
 	    $gradeTable.='<td align="right">'.$ctr.'&nbsp;</td>'.
@@ -978,7 +984,7 @@ LISTJAVASCRIPT
                $student.':'.$$fullname{$student}.':::SECTION'.$section.
 	       ')&nbsp;" />&nbsp;&nbsp;</label></td>'."\n".'<td>'.
 	       &nameUserString(undef,$$fullname{$student},$uname,$udom).
-	       '&nbsp;'.$section.'</td>'."\n";
+	       '&nbsp;'.$section.'/'.$group.'</td>'."\n";
 
 	    if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
 		foreach (sort keys(%status)) {
@@ -1954,7 +1960,7 @@ KEYWORDS
 
 # This is where output for one specific student would start
     my $bgcolor='#DDEEDD';
-    if (int($counter/2) eq $counter) { $bgcolor='#DDDDEE'; }
+    if ($counter%2) { $bgcolor='#DDDDEE'; }
     $request->print("\n\n".
                     '<p><table border="2"><tr><th bgcolor="'.$bgcolor.'">'.$env{'form.fullname'}.'</th></tr><tr><td bgcolor="'.$bgcolor.'">');
 
@@ -1984,60 +1990,13 @@ KEYWORDS
 	'" value="'.$env{'form.fullname'}.'" />'."\n";
 
     # If any part of the problem is an essay-response (handgraded), then check for collaborators
-    my @col_fullnames;
-    my ($classlist,$fullname);
+    my $fullname;
+    my $col_fullnames = [];
     if ($env{'form.handgrade'} eq 'yes') {
-	($classlist,undef,$fullname) = &getclasslist('all','0');
-	for (keys (%$handgrade)) {
-	    my $ncol = &Apache::lonnet::EXT('resource.'.$_.
-					    '.maxcollaborators',
-                                            $symb,$udom,$uname);
-	    next if ($ncol <= 0);
-            s/\_/\./g;
-            next if ($record{'resource.'.$_.'.collaborators'} eq '');
-            my @goodcollaborators = ();
-            my @badcollaborators  = ();
-	    foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) { 
-		$_ =~ s/[\$\^\(\)]//g;
-		next if ($_ eq '');
-		my ($co_name,$co_dom) = split /\@|:/,$_;
-		$co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
-		next if ($co_name eq $uname && $co_dom eq $udom);
-		# Doing this grep allows 'fuzzy' specification
-		my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
-		if (! scalar(@Matches)) {
-		    push @badcollaborators,$_;
-		} else {
-		    push @goodcollaborators, @Matches;
-		}
-	    }
-            if (scalar(@goodcollaborators) != 0) {
-                $result.='<b>Collaborators: </b>';
-                foreach (@goodcollaborators) {
-		    my ($lastname,$givenn) = split(/,/,$$fullname{$_});
-		    push @col_fullnames, $givenn.' '.$lastname;
-		    $result.=$$fullname{$_}.'&nbsp; &nbsp; &nbsp;';
-		}
-                $result.='<br />'."\n";
-		my ($part)=split(/\./,$_);
-		$result.='<input type="hidden" name="collaborator'.$counter.
-		    '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
-		    "\n";
-	    }
-	    if (scalar(@badcollaborators) > 0) {
-		$result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
-		$result.='This student has submitted ';
-		$result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
-		$result .= ': '.join(', ',@badcollaborators);
-		$result .= '</td></tr></table>';
-	    }         
-	    if (scalar(@badcollaborators > $ncol)) {
-		$result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
-		$result .= 'This student has submitted too many '.
-		    'collaborators.  Maximum is '.$ncol.'.';
-		$result .= '</td></tr></table>';
-	    }
-	}
+	(my $sub_result,$fullname,$col_fullnames)=
+	    &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
+				 $counter);
+	$result.=$sub_result;
     }
     $request->print($result."\n");
 
@@ -2173,16 +2132,16 @@ KEYWORDS
     if ($env{'form.handgrade'} eq 'yes') {
 	my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
 	my $msgfor = $givenn.' '.$lastname;
-	if (scalar(@col_fullnames) > 0) {
-	    my $lastone = pop @col_fullnames;
-	    $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
+	if (scalar(@$col_fullnames) > 0) {
+	    my $lastone = pop(@$col_fullnames);
+	    $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
 	}
 	$msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
 	$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.
 	    ',\''.$msgfor.'\');" target="_self">'.
-	    &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
+	    &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
 	    &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
 	    '<img src="'.$request->dir_config('lonIconsURL').
 	    '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
@@ -2260,6 +2219,62 @@ KEYWORDS
     return '';
 }
 
+sub check_collaborators {
+    my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
+    my ($result,@col_fullnames);
+    my ($classlist,undef,$fullname) = &getclasslist('all','0');
+    foreach my $part (keys(%$handgrade)) {
+	my $ncol = &Apache::lonnet::EXT('resource.'.$part.
+					'.maxcollaborators',
+					$symb,$udom,$uname);
+	next if ($ncol <= 0);
+	$part =~ s/\_/\./g;
+	next if ($record->{'resource.'.$part.'.collaborators'} eq '');
+	my (@good_collaborators, @bad_collaborators);
+	foreach my $possible_collaborator
+	    (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) { 
+	    $possible_collaborator =~ s/[\$\^\(\)]//g;
+	    next if ($possible_collaborator eq '');
+	    my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
+	    $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
+	    next if ($co_name eq $uname && $co_dom eq $udom);
+	    # Doing this grep allows 'fuzzy' specification
+	    my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i, 
+			       keys(%$classlist));
+	    if (! scalar(@matches)) {
+		push(@bad_collaborators, $possible_collaborator);
+	    } else {
+		push(@good_collaborators, @matches);
+	    }
+	}
+	if (scalar(@good_collaborators) != 0) {
+	    $result.='<b>Collaborators: </b>';
+	    foreach my $name (@good_collaborators) {
+		my ($lastname,$givenn) = split(/,/,$$fullname{$name});
+		push(@col_fullnames, $givenn.' '.$lastname);
+		$result.=$fullname->{$name}.'&nbsp; &nbsp; &nbsp;';
+	    }
+	    $result.='<br />'."\n";
+	    my ($part)=split(/\./,$_);
+	    $result.='<input type="hidden" name="collaborator'.$counter.
+		'" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
+		"\n";
+	}
+	if (scalar(@bad_collaborators) > 0) {
+	    $result.='<div class="LC_error">';
+	    $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
+	    $result .= '</div>';
+	}         
+	if (scalar(@bad_collaborators > $ncol)) {
+	    $result .= '<div class="LC_error">';
+	    $result .= &mt('This student has submitted too many '.
+		'collaborators.  Maximum is [_1].',$ncol);
+	    $result .= '</div>';
+	}
+    }
+    return ($result,$fullname,\@col_fullnames);
+}
+
 #--- Retrieve the last submission for all the parts
 sub get_last_submission {
     my ($returnhash)=@_;
@@ -3906,7 +3921,8 @@ sub csvuploadassign {
                 if ($wgt) {
                     $entries{$fields{$dest}}=~s/\s//g;
                     my $pcr=$entries{$fields{$dest}} / $wgt;
-                    my $award='correct_by_override';
+                    my $award=($pcr == 0) ? 'incorrect_by_override'
+                                          : 'correct_by_override';
                     $grades{"resource.$part.awarded"}=$pcr;
                     $grades{"resource.$part.solved"}=$award;
                     $points{$part}=1;
@@ -4887,11 +4903,10 @@ SCANTRONFORM
     </tr>
 SCANTRONFORM
 
-    $r->print(<<SCANTRONFORM);
-  </table>
-$grading_menu_button
-SCANTRONFORM
-
+    $r->print('<tr><td bgcolor="#777777">');
+    &Apache::lonpickcode::code_list($r,2);
+    $r->print('</td></tr></table>');
+    $r->print($grading_menu_button);
     return
 }
 
@@ -5263,7 +5278,12 @@ sub scantron_parse_scanline {
 		|| (&occurence_count($currentquest, "[A-Z]") > 1)) {
 		push(@{$record{'scantron.doubleerror'}},$questnum);
 		for (my $ans = 0; $ans < $answers_needed; $ans++) { 
-		    $record{"scantron.$ansnum.answer"}='';
+		    my $bubble = substr($currentquest, $ans, 1);
+		    if ($bubble =~ /[A-Z]/ ) {
+			$record{"scantron.$ansnum.answer"} = $bubble;
+		    } else {
+			$record{"scantron.$ansnum.answer"}='';
+		    }
 		    $ansnum++;
 		}
 
@@ -5298,7 +5318,12 @@ sub scantron_parse_scanline {
 		|| (&occurence_count($currentquest, '\d') > 1)) {
 		push(@{$record{'scantron.doubleerror'}},$questnum);
 		for (my $ans = 0; $ans < $answers_needed; $ans++) {
-		    $record{"scantron.$ansnum.answer"}='';
+		    my $bubble = substr($currentquest, $ans, 1);
+		    if ($bubble =~ /\d/) {
+			$record{"scantron.$ansnum.answer"} = $alphabet[$bubble];
+		    } else {
+			$record{"scantron.$ansnum.answer"}=' ';
+		    }
 		    $ansnum++;
 		}
 
@@ -5345,7 +5370,7 @@ sub scantron_parse_scanline {
 		}
 	    } elsif (scalar(@array) lt 2) {
 
-		my $location      = [length($array[0])];
+		my $location      = length($array[0]);
 		my $line_num      = $location / $$scantron_config{'Qlength'};
 		my $bubble        = $alphabet[$location % $$scantron_config{'Qlength'}];
 
@@ -5368,20 +5393,22 @@ sub scantron_parse_scanline {
 
 		my $first_answer = $ansnum;
 		for (my $ans =0; $ans < $answers_needed; $ans++) {
-		    $record{"scantron.$ansnum.answer"} = '';
-		    $ans++;
+		    my $item = $first_answer+$ans;
+		    $record{"scantron.$item.answer"} = '';
 		}
 
 		my @ans=@array;
-		my $i=length($ans[0]);shift(@ans);
+		my $i=0;
+		my $increment = 0;
 		while ($#ans) {
-		    $i+=length($ans[0])+1;
-		    my $line   = $i/$$scantron_config{'Qlength'} + $first_answer;
+		    $i+=length($ans[0]) + $increment;
+		    my $line   = int($i/$$scantron_config{'Qlength'} + $first_answer);
 		    my $bubble = $i%$$scantron_config{'Qlength'};
-
 		    $record{"scantron.$line.answer"}.=$alphabet[$bubble];
 		    shift(@ans);
+		    $increment = 1;
 		}
+		$ansnum += $answers_needed;
 	    }
 	}
     }
@@ -5741,7 +5768,6 @@ SCANTRONFORM
 
   my $line = 0;
     while (defined($env{"form.scantron.bubblelines.$line"})) {
-	&Apache::lonnet::logthis("Saving chunk for $line");
        my $chunk =
 	   '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
        $chunk .=
@@ -5807,7 +5833,6 @@ sub scantron_validate_file {
     }
     my $currentphase=$env{'form.validatepass'};
 
-    &Apache::lonnet::logthis("Phase: $currentphase");
 
     my $stop=0;
     while (!$stop && $currentphase < scalar(@validate_phases)) {
@@ -6319,7 +6344,7 @@ sub scantron_validate_ID {
 sub scantron_get_correction {
     my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
 
-#FIXME in the case of a duplicated ID the previous line, probaly need
+#FIXME in the case of a duplicated ID the previous line, probably need
 #to show both the current line and the previous one and allow skipping
 #the previous one or the current one
 
@@ -6418,10 +6443,10 @@ ENDSCRIPT
 	$r->print($message);
 	$r->print("<p>Please indicate which bubble should be used for grading</p>");
 	foreach my $question (@{$arg}) {
-
 	    my $selected  = &get_response_bubbles($scan_record, $question);
+	    my @select_array = split(/:/,$selected);
 	    &scantron_bubble_selector($r,$scan_config,$question,
-				      split('',$selected));
+				      @select_array);
 	}
     } elsif ($error eq 'missingbubble') {
 	$r->print("<p>There have been <b>no</b> bubbles scanned for some question(s)</p>\n");
@@ -6452,22 +6477,24 @@ ENDSCRIPT
     $r           - Apache request object
     $scan_config - hash from &get_scantron_config()
     $quest       - number of the bubble line to make a corrector for
-    $selected    - array of letters of previously selected bubbles
+    $lines       - array of answer lines.
 
 =cut
 
 sub scantron_bubble_selector {
-    my ($r,$scan_config,$quest,@selected)=@_;
+    my ($r,$scan_config,$quest,@lines)=@_;
     my $max=$$scan_config{'Qlength'};
 
+
     my $scmode=$$scan_config{'Qon'};
 
+    my $bubble_length = scalar(@lines);
+
 
     if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }	     
 
     my $response = $quest-1;
     my $lines = $bubble_lines_per_response{$response};
-    &Apache::lonnet::logthis("Question $quest, lines: $lines");
 
     my $total_lines = $lines*2;
     my @alphabet=('A'..'Z');
@@ -6477,11 +6504,7 @@ sub scantron_bubble_selector {
 	if ($l != 0) {
 	    $r->print('<tr>');
 	}
-
-	# FIXME:  This loop probably has to be considerably more clever for
-	#  multiline bubbles: User can multibubble by having bubbles in
-	#  several lines.  User can skip lines legitimately etc. etc.
-
+	my @selected = split(//,$lines[$l]);
 	for (my $i=0;$i<$max;$i++) {
 	    $r->print("\n".'<td align="center">');
 	    if ($selected[0] eq $alphabet[$i]) { 
@@ -6731,14 +6754,11 @@ sub scantron_validate_doublebubble {
 =cut
 
 sub scantron_get_maxbubble {    
-    &Apache::lonnet::logthis("get_max_bubble");
     if (defined($env{'form.scantron_maxbubble'}) &&
 	$env{'form.scantron_maxbubble'}) {
-	&Apache::lonnet::logthis("cached");
 	&restore_bubble_lines();
 	return $env{'form.scantron_maxbubble'};
     }
-    &Apache::lonnet::logthis("computing");
 
     my (undef, undef, $sequence) =
 	&Apache::lonnet::decode_symb($env{'form.selectpage'});
@@ -6776,9 +6796,9 @@ sub scantron_get_maxbubble {
 
 
 	foreach my $part_id (@{$analysis{'parts'}}) {
-	    my ($trash, $part) = split(/\./, $part_id);
 
-	    my $lines = $analysis{"$part_id.bubble_lines"}[0];
+
+	    my $lines = $analysis{"$part_id.bubble_lines"};;
 
 	    # TODO - make this a persistent hash not an array.
 
@@ -7184,10 +7204,6 @@ sub grading_menu {
     my $probTitle = &Apache::lonnet::gettitle($symb);
     my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
 
-    #
-    # Define menu data
-    $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
-    my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
     $request->print($table);
     my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
                   'handgrade'=>$hdgrade,
@@ -7217,29 +7233,15 @@ sub grading_menu {
     $fields{'command'} = 'scantron_selectphase';
     $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
     push (@menu, { url => $url,
-                   name => &mt('Grade Scantron Forms'),
+                   name => &mt('Grade/Manage Scantron Forms'),
                    short_description => 
             &mt('')});
     $fields{'command'} = 'verify';
     $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
     push (@menu, { url => "",
-                   jscript => ' onClick="javascript:checkChoice2(document.forms.gradingMenu,\'5\',\'verify\')" ',
                    name => &mt('Verify Receipt'),
                    short_description => 
             &mt('')});
-    $fields{'command'} = 'manage';
-    $url = &Apache::lonhtmlcommon::build_url('/adm/helper/resettimes.helper',\%fields);
-    push (@menu, { url => $url,
-                   name => &mt('Manage Access Times'),
-                   short_description => 
-            &mt('')});
-    $fields{'command'} = 'view';
-    $url = &Apache::lonhtmlcommon::build_url('/adm/pickcode',\%fields);
-    push (@menu, { url => $url,
-                   name => &mt('View Saved CODEs'),
-                   short_description => 
-            &mt('')});
-
     #
     # Create the menu
     my $Str;
@@ -7261,10 +7263,10 @@ sub grading_menu {
                 $menudata->{'url'}.'" >'.
                 $menudata->{'name'}."</a></h3>\n";
         } else {
-            $Str .='    <h3><a '.
+            $Str .='    <h3><input type="button" value="Verify Receipt" '.
                 $menudata->{'jscript'}.
-                ' href="javascript:checkChoice2(document.forms.gradingMenu,\'5\',\'verify\')" >'.
-                $menudata->{'name'}."</a></h3>\n";
+                ' onClick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
+                ' /></h3>';
             $Str .= ('&nbsp;'x8).
                     ' receipt: '.&Apache::lonnet::recprefix($env{'request.course.id'}).
                     '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />';
@@ -7285,30 +7287,14 @@ sub grading_menu {
 	    cmdsave = 'submission';
 	}
 	formname.command.value = cmd;
-	formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
-	    ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
 	if (val < 5) formname.submit();
 	if (val == 5) {
-	    if (!checkReceiptNo(formname,'notOK')) { return false;}
-	    formname.submit();
-	}
-	if (val < 7) formname.submit();
-    }
-    function checkChoice2(formname,val,cmdx) {
-	if (val <= 2) {
-	    var cmd = radioSelection(formname.radioChoice);
-	    var cmdsave = cmd;
-	} else {
-	    cmd = cmdx;
-	    cmdsave = 'submission';
-	}
-	formname.command.value = cmd;
-	if (val < 5) formname.submit();
-	if (val == 5) {
-	    if (!checkReceiptNo(formname,'notOK')) { return false;}
-	    formname.submit();
+	    if (!checkReceiptNo(formname,'notOK')) { 
+	        return false;
+	    } else {
+	        formname.submit();
+	    }
 	}
-	if (val < 7) formname.submit();
     }
 
     function checkReceiptNo(formname,nospace) {
@@ -7327,43 +7313,6 @@ sub grading_menu {
 </script>
 GRADINGMENUJS
     &commonJSfunctions($request);
-    my $result='<h3>&nbsp;<span class="LC_info">Manual Grading/View Submission</span></h3>';
-    $result.=$table;
-    my (undef,$sections) = &getclasslist('all','0');
-    my $savedState = &savedState();
-    my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
-    my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
-    my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$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="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
-	'<input type="hidden" name="handgrade"   value="'.$hdgrade.'" />'."\n".
-	'<input type="hidden" name="probTitle"   value="'.$probTitle.'" ue="" />'."\n".
-	'<input type="hidden" name="saveState"   value="" />'."\n".
-	'<input type="hidden" name="gradingMenu" value="1" />'."\n".
-	'<input type="hidden" name="showgrading" value="yes" />'."\n";
-
-    $result.='<table width="100%" border="0"><tr><td bgcolor=#777777>'."\n".
-	'<table width="100%" border="0"><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
-	'&nbsp;<b>Select a Grading/Viewing Option</b></td></tr>'."\n".
-	'<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
-
-    $result.='<table width="100%" border="0">';
-    $result.='<tr bgcolor="#ffffe6" valign="top">'."\n";
-    $result.='<td><b>'.&mt('Sections').'</b></td>';
-#    $result.='<td>Groups</td>';
-    $result.='<td><b>'.&mt('Access Status').'</td>'."\n";
-    $result.='</tr>';
-    $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
-	'&nbsp;<select name="section" multiple="multiple" size="3">'."\n";
-    if (ref($sections)) {
-	foreach (sort (@$sections)) {
-	    $result.='<option value="'.$_.'" '.
-		($saveSec eq $_ ? 'selected="selected"':'').'>'.$_.'</option>'."\n";
-	}
-    }
-    $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> &nbsp; ';
     return $Str;    
 }
 
@@ -7441,6 +7390,7 @@ GRADINGMENUJS
     $result.='<td><b>'.&mt('Sections').'</b></td>';
     $result.='<td><b>'.&mt('Groups').'</b></td>';
     $result.='<td><b>'.&mt('Access Status').'</td>'."\n";
+    $result.='<td><b>'.&mt('Submission Status').'</td>'."\n";
     $result.='</tr>';
     $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
 	'&nbsp;<select name="section" multiple="multiple" size="3">'."\n";
@@ -7456,12 +7406,8 @@ GRADINGMENUJS
     $result.='</td><td>'."\n";
     $result.=&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,3,undef,'mult');
 
-    $result.='</td></tr>';
-
-    $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="3"><label>'.
-	'<input type="radio" name="radioChoice" value="submission" '.
-	($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
-	'</label> <select name="submitonly">'.
+    $result.='</td>';
+    $result.='<td><select name="submitonly" size="3">'.
 	'<option value="yes" '.
 	($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>'.
 	'<option value="queued" '.
@@ -7471,19 +7417,29 @@ GRADINGMENUJS
 	'<option value="incorrect" '.
 	($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>'.
 	'<option value="all" '.
-	($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option></select></td></tr>'."\n";
+	($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option></select></td></tr>';
+
+    $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="3"><label>'.
+	'<input type="radio" name="radioChoice" value="submission" '.
+	($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
+	'</label> </td></tr>'."\n";
 
-    $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
+    $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="3">'.
 	'<label><input type="radio" name="radioChoice" value="viewgrades" '.
 	($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
 	'<b>Current Resource:</b> For all students in selected section or course</label></td></tr>'."\n";
 
-    $result.='<tr bgcolor="#ffffe6" valign="top"><td colspan="2">'.
-	'<label><input type="radio" name="radioChoice" value="pickStudentPage" '.
+    $result.='<tr bgcolor="#ffffe6"><td colspan="3"><br />'.
+	'<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
+	'</td></tr>'."\n";
+
+
+    $result.='<tr bgcolor="#ffffe6" valign="top"><td colspan="3">'.
+	'<br /><label><input type="radio" name="radioChoice" value="pickStudentPage" '.
 	($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
-	'The <b>complete</b> set/page/sequence: For one student</label></td></tr>'."\n";
+	'The <b>complete</b> set/page/sequence/folder: For one student</label></td></tr>'."\n";
 
-    $result.='<tr bgcolor="#ffffe6"><td colspan="2"><br />'.
+    $result.='<tr bgcolor="#ffffe6"><td colspan="3"><br />'.
 	'<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
 	'</td></tr></table>'."\n";
 
@@ -8030,7 +7986,6 @@ ENDHEADER
 
 sub handler {
     my $request=$_[0];
-
     &reset_caches();
     if ($env{'browser.mathml'}) {
 	&Apache::loncommon::content_type($request,'text/xml');
@@ -8126,7 +8081,6 @@ sub handler {
 	} elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
 	    $request->print(&csvuploadassign($request));
 	} elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
-	    &Apache::lonnet::logthis("Selecting pyhase");
 	    $request->print(&scantron_selectphase($request));
  	} elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
  	    $request->print(&scantron_do_warning($request));