--- loncom/homework/grades.pm	2007/10/30 00:27:23	1.471
+++ loncom/homework/grades.pm	2007/11/06 19:19:54	1.484
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.471 2007/10/30 00:27:23 albertel Exp $
+# $Id: grades.pm,v 1.484 2007/11/06 19:19:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -865,7 +865,7 @@ LISTJAVASCRIPT
     my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
     $env{'form.Status'} = $saveStatus;
     $gradeTable.='<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only </label>'."\n".
-	'<label><input type="radio" name="lastSub" value="last" /> last submission & parts info </label>'."\n".
+	'<label><input type="radio" name="lastSub" value="last" /> last submission &amp; parts info </label>'."\n".
 	'<label><input type="radio" name="lastSub" value="datesub" /> by dates and submissions </label>'."\n".
 	'<label><input type="radio" name="lastSub" value="all" /> all details</label><br />'."\n".
         '&nbsp;<b>Grading Increments:</b> <select name="increment">'.
@@ -902,27 +902,27 @@ LISTJAVASCRIPT
     $gradeTable.=&check_buttons();
     $gradeTable.='<label><input type="checkbox" name="checkPlag" checked="checked" />Check For Plagiarism</label>';
     my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
-    $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
-	'<table border="0"><tr bgcolor="#e6ffff">';
+    $gradeTable.= &Apache::loncommon::start_data_table().
+	&Apache::loncommon::start_data_table_header_row();
     my $loop = 0;
     while ($loop < 2) {
-	$gradeTable.='<td><b>&nbsp;No.</b>&nbsp;</td><td><b>&nbsp;Select&nbsp;</b></td>'.
-	    '<td>'.&nameUserString('header').'&nbsp;Section/Group</td>';
+	$gradeTable.='<th>No.</th><th>Select</th>'.
+	    '<th>'.&nameUserString('header').'&nbsp;'.'Section/Group</th>';
 	if ($env{'form.showgrading'} eq 'yes' 
 	    && $submitonly ne 'queued'
 	    && $submitonly ne 'all') {
 	    foreach (sort(@$partlist)) {
 		my $display_part=&get_display_part((split(/_/))[0],$symb);
-		$gradeTable.='<td><b>&nbsp;Part: '.$display_part.
-		    ' Status&nbsp;</b></td>';
+		$gradeTable.='<th>Part: '.$display_part.
+		    ' Status</h>';
 	    }
 	} elsif ($submitonly eq 'queued') {
-	    $gradeTable.='<td><b>&nbsp;'.&mt('Queue Status').'&nbsp;</b></td>';
+	    $gradeTable.='<th>'.&mt('Queue Status').'&nbsp;</th>';
 	}
 	$loop++;
 #	$gradeTable.='<td></td>' if ($loop%2 ==1);
     }
-    $gradeTable.='</tr>'."\n";
+    $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
 
     my $ctr = 0;
     foreach my $student (sort 
@@ -978,13 +978,15 @@ LISTJAVASCRIPT
 	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);
+	    if ($ctr%2 ==1) {
+		$gradeTable.= &Apache::loncommon::start_data_table_row();
+	    }
 	    $gradeTable.='<td align="right">'.$ctr.'&nbsp;</td>'.
                '<td align="center"><label><input type=checkbox name="stuinfo" value="'.
                $student.':'.$$fullname{$student}.':::SECTION'.$section.
 	       ')&nbsp;" />&nbsp;&nbsp;</label></td>'."\n".'<td>'.
 	       &nameUserString(undef,$$fullname{$student},$uname,$udom).
-	       '&nbsp;'.$section.'/'.$group.'</td>'."\n";
+	       '&nbsp;'.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
 
 	    if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
 		foreach (sort keys(%status)) {
@@ -993,7 +995,9 @@ LISTJAVASCRIPT
 		}
 	    }
 #	    $gradeTable.='<td></td>' if ($ctr%2 ==1);
-	    $gradeTable.='</tr>'."\n" if ($ctr%2 ==0);
+	    if ($ctr%2 ==0) {
+		$gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
+	    }
 	}
     }
     if ($ctr%2 ==1) {
@@ -1007,10 +1011,10 @@ LISTJAVASCRIPT
 	    } elsif ($submitonly eq 'queued') {
 		$gradeTable.='<td>&nbsp;</td>';
 	    }
-	$gradeTable.='</tr>';
+	$gradeTable.=&Apache::loncommon::end_data_table_row();
     }
 
-    $gradeTable.='</table></td></tr></table>'."\n".
+    $gradeTable.=&Apache::loncommon::end_data_table()."\n".
 	'<input type="button" '.
 	'onClick="javascript:checkSelect(this.form.stuinfo);" '.
 	'value="Next->" /></form>'."\n";
@@ -1028,7 +1032,7 @@ LISTJAVASCRIPT
 		' students checked for '.$submissions.')</span><br />';
 	}
     } elsif ($ctr == 1) {
-	$gradeTable =~ s/type=checkbox/type=checkbox checked/;
+	$gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
     }
     $gradeTable.=&show_grading_menu_form($symb);
     $request->print($gradeTable);
@@ -1969,7 +1973,7 @@ KEYWORDS
 	    $mode='answer';
 	}
 	&Apache::lonxml::clear_problem_counter();
-	$request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
+	$request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
     }
 
     my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
@@ -3169,14 +3173,12 @@ sub viewgrades {
 	$sectionClass=&mt('Students in Section(s) [_1]',$section_display).'</h3>';
     }
     $result.='<h3>'.&mt('Assign Common Grade To [_1]',$sectionClass);
-    $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
-	'<table border=0><tr bgcolor="#ffffdd"><td>';
+    $result.= &Apache::loncommon::start_data_table();
     #radio buttons/text box for assigning points for a section or class.
     #handles different parts of a problem
     my ($partlist,$handgrade,$responseType) = &response_type($symb);
     my %weight = ();
     my $ctsparts = 0;
-    $result.='<table border="0">';
     my %seen = ();
     my @part_response_id = &flatten_responseType($responseType);
     foreach my $part_response_id (@part_response_id) {
@@ -3188,12 +3190,14 @@ sub viewgrades {
 	my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
 	$weight{$partid} = $wgt eq '' ? '1' : $wgt;
 
+	$result.=&Apache::loncommon::start_data_table_row().'<td>';
 	$result.='<input type="hidden" name="partid_'.
 	    $ctsparts.'" value="'.$partid.'" />'."\n";
 	$result.='<input type="hidden" name="weight_'.
 	    $partid.'" value="'.$weight{$partid}.'" />'."\n";
 	my $display_part=&get_display_part($partid,$symb);
-	$result.='<tr><td><b>Part:</b> '.$display_part.'&nbsp; &nbsp;<b>Point:</b> </td><td>';
+	$result.=
+	    '<b>Part:</b> '.$display_part.'&nbsp; &nbsp;<b>Point:</b> </td><td>';
 	$result.='<table border="0"><tr>';  
 	my $ctr = 0;
 	while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
@@ -3208,26 +3212,27 @@ sub viewgrades {
 	    $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
 		$partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
 	    $weight{$partid}.' (problem weight)</td>'."\n";
-	$result.= '</td><td><select name="SELVAL_'.$partid.'"'.
+	$result.= '<td><select name="SELVAL_'.$partid.'"'.
 	    'onChange="javascript:writeRadText(\''.$partid.'\','.
 		$weight{$partid}.')"> '.
 	    '<option selected="selected"> </option>'.
 	    '<option>excused</option>'.
 	    '<option>reset status</option></select></td>'.
-            '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td></tr>'."\n";
+            '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td>'.&Apache::loncommon::end_data_table_row()."\n";
 	$ctsparts++;
     }
-    $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
+    $result.=&Apache::loncommon::end_data_table()."\n".
 	'<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
     $result.='<input type="button" value="Revert to Default" '.
-	'onClick="javascript:resetEntry('.$ctsparts.');" target="_self" />';
+	'onClick="javascript:resetEntry('.$ctsparts.');" />';
 
     #table listing all the students in a section/class
     #header of table
     $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
-    $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
-	'<table border=0><tr bgcolor="#deffff"><td>&nbsp;<b>No.</b>&nbsp;</td>'.
-	'<td>'.&nameUserString('header')."</td>\n";
+    $result.= &Apache::loncommon::start_data_table().
+	&Apache::loncommon::start_data_table_header_row().
+	'<th>No.</th>'.
+	'<th>'.&nameUserString('header')."</th>\n";
     my (@parts) = sort(&getpartlist($symb));
     my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
     my @partids = ();
@@ -3239,16 +3244,16 @@ sub viewgrades {
         push(@partids, $partid);
 	my $display_part=&get_display_part($partid,$symb);
 	if ($display =~ /^Partial Credit Factor/) {
-	    $result.='<td><b>Score Part:</b> '.$display_part.
-		' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n";
+	    $result.='<th>Score Part: '.$display_part.
+		' <br />(weight = '.$weight{$partid}.')</th>'."\n";
 	    next;
 	} else {
 	    $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
 	}
 	$display =~ s|Problem Status|Grade Status<br />|;
-	$result.='<td><b>'.$display.'</td>'."\n";
+	$result.='<th>'.$display.'</th>'."\n";
     }
-    $result.='</tr>';
+    $result.=&Apache::loncommon::end_data_table_header_row();
 
     my %last_resets = 
 	&get_last_resets($symb,$env{'request.course.id'},\@partids);
@@ -3268,7 +3273,7 @@ sub viewgrades {
 	$result.=&viewstudentgrade($symb,$env{'request.course.id'},
 				   $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
     }
-    $result.='</table></td></tr></table>';
+    $result.=&Apache::loncommon::end_data_table();
     $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
     $result.='<input type="button" value="Save" '.
 	'onClick="javascript:submit();" target="_self" /></form>'."\n";
@@ -3291,7 +3296,7 @@ sub viewstudentgrade {
     my ($uname,$udom) = split(/:/,$student);
     my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
     my %aggregates = (); 
-    my $result='<tr bgcolor="#ffffdd"><td align="right">'.
+    my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
 	'<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
 	"\n".$ctr.'&nbsp;</td><td>&nbsp;'.
 	'<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
@@ -3346,7 +3351,7 @@ sub viewstudentgrade {
 		'value="'.$score.'" size="4" /></td>'."\n";
 	}
     }
-    $result.='</tr>';
+    $result.=&Apache::loncommon::end_data_table_row();
     return $result;
 }
 
@@ -3357,15 +3362,14 @@ sub editgrades {
 
     my $symb=&get_symb($request);
     my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
-    my $title='<h3><span class="LC_info">'.&mt('Current Grade Status').'</span></h3>';
-    $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4><br />'."\n";
+    my $title='<h2>'.&mt('Current Grade Status').'</h2>';
+    $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
     $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
 
-    my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
-    $result.= '<table border="0"><tr bgcolor="#deffff">'.
-	'<td rowspan=2 valign="center">&nbsp;<b>No.</b>&nbsp;</td>'.
-	'<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
-
+    my $result= &Apache::loncommon::start_data_table().
+	&Apache::loncommon::start_data_table_header_row().
+	'<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
+	'<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
     my %scoreptr = (
 		    'correct'  =>'correct_by_override',
 		    'incorrect'=>'incorrect_by_override',
@@ -3390,8 +3394,8 @@ sub editgrades {
     }
     my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
     foreach my $partid (@partid) {
-	$header .= '<td align="center">&nbsp;<b>Old Score</b>&nbsp;</td>'.
-	    '<td align="center">&nbsp;<b>New Score</b>&nbsp;</td>';
+	$header .= '<th align="center">'.&mt('Old Score').'</th>'.
+	    '<th align="center">'.&mt('New Score').'</th>';
 	$columns{$partid}=2;
 	foreach my $stores (@parts) {
 	    my ($part,$type) = &split_part_type($stores);
@@ -3400,22 +3404,23 @@ sub editgrades {
 	    my $display=&Apache::lonnet::metadata($url,$stores.'.display');
 	    $display =~ s/\[Part: (\w)+\]//;
 	    $display =~ s/Number of Attempts/Tries/;
-	    $header .= '<td align="center">&nbsp;<b>Old '.$display.'</b>&nbsp;</td>'.
-		'<td align="center">&nbsp;<b>New '.$display.'</b>&nbsp;</td>';
+	    $header .= '<th align="center">'.&mt('Old '.$display).'</th>'.
+		'<th align="center">'.&mt('New '.$display).'</th>';
 	    $columns{$partid}+=2;
 	}
     }
     foreach my $partid (@partid) {
 	my $display_part=&get_display_part($partid,$symb);
-	$result .= '<td colspan="'.$columns{$partid}.
-	    '" align="center"><b>Part:</b> '.$display_part.
-	    ' (Weight = '.$weight{$partid}.')</td>';
+	$result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
+	    &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
+	    '</th>';
 
     }
-    $result .= '</tr><tr bgcolor="#deffff">';
-    $result .= $header;
-    $result .= '</tr>'."\n";
-    my $noupdate;
+    $result .= &Apache::loncommon::end_data_table_header_row().
+	&Apache::loncommon::start_data_table_header_row().
+	$header.
+	&Apache::loncommon::end_data_table_header_row();
+    my @noupdate;
     my ($updateCtr,$noupdateCtr) = (1,1);
     for ($i=0; $i<$env{'form.total'}; $i++) {
 	my $line;
@@ -3427,7 +3432,9 @@ sub editgrades {
 	my $usec=$classlist->{"$uname:$udom"}[5];
 	if (!&canmodify($usec)) {
 	    my $numcols=scalar(@partid)*4+2;
-	    $noupdate.=$line."<td colspan=\"$numcols\"><span class=\"LC_warning\">Not allowed to modify student</span></td></tr>";
+	    push(@noupdate,
+		 $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
+		 &mt('Not allowed to modify student')."</span></td></tr>");
 	    next;
 	}
         my %aggregate = ();
@@ -3496,7 +3503,7 @@ sub editgrades {
 		    '<td align="center">'.$awarded.'&nbsp;</td>';
 	    }
 	}
-	$line.='</tr>'."\n";
+	$line.="\n";
 
 	my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 	my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
@@ -3529,10 +3536,13 @@ sub editgrades {
 		}
 	    }
 
-	    $result.='<tr bgcolor="#ffffde"><td align="right">&nbsp;'.$updateCtr.'&nbsp;</td>'.$line;
+	    $result.=&Apache::loncommon::start_data_table_row().
+		'<td align="right">&nbsp;'.$updateCtr.'&nbsp;</td>'.$line.
+		&Apache::loncommon::end_data_table_row();
 	    $updateCtr++;
 	} else {
-	    $noupdate.='<tr bgcolor="#ffffde"><td align="right">&nbsp;'.$noupdateCtr.'&nbsp;</td>'.$line;
+	    push(@noupdate,
+		 '<td align="right">&nbsp;'.$noupdateCtr.'&nbsp;</td>'.$line);
 	    $noupdateCtr++;
 	}
         if ($aggregateflag) {
@@ -3540,16 +3550,28 @@ sub editgrades {
 				  $cdom,$cnum);
         }
     }
-    if ($noupdate) {
+    if (@noupdate) {
 #	my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
 	my $numcols=scalar(@partid)*4+2;
-	$result .= '<tr bgcolor="#ffffff"><td align="center" colspan="'.$numcols.'">No Changes Occurred For the Students Below</td></tr><tr bgcolor="#ffffde">'.$noupdate;
+	$result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
+	    '<td align="center" colspan="'.$numcols.'">'.
+	    &mt('No Changes Occurred For the Students Below').
+	    '</td>'.
+	    &Apache::loncommon::end_data_table_row();
+	foreach my $line (@noupdate) {
+	    $result.=
+		&Apache::loncommon::start_data_table_row().
+		$line.
+		&Apache::loncommon::end_data_table_row();
+	}
     }
-    $result .= '</table></td></tr></table>'."\n".
-	&show_grading_menu_form ($symb);
-    my $msg = '<br /><b>Number of records updated = '.$rec_update.
-	' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
-	'<b>Total number of students = '.$env{'form.total'}.'</b><br />';
+    $result .= &Apache::loncommon::end_data_table().
+	&show_grading_menu_form($symb);
+    my $msg = '<p><b>'.
+	&mt('Number of records updated = [_1] for [quant,_2,student].',
+	    $rec_update,$count).'</b><br />'.
+	'<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
+	'</b></p>';
     return $title.$msg.$result;
 }
 
@@ -4077,12 +4099,13 @@ LISTJAVASCRIPT
     $request->print($result);
 
     my $studentTable.='&nbsp;<b>Select a student you wish to grade and then click on the Next button.</b><br />'.
-	'<table border="0"><tr><td bgcolor="#777777">'.
-	'<table border="0"><tr bgcolor="#e6ffff">'.
-	'<td align="right">&nbsp;<b>No.</b></td>'.
-	'<td>'.&nameUserString('header').'</td>'.
-	'<td align="right">&nbsp;<b>No.</b></td>'.
-	'<td>'.&nameUserString('header').'</td></tr>';
+	&Apache::loncommon::start_data_table().
+	&Apache::loncommon::start_data_table_header_row().
+	'<th align="right">&nbsp;No.</th>'.
+	'<th>'.&nameUserString('header').'</th>'.
+	'<th align="right">&nbsp;No.</th>'.
+	'<th>'.&nameUserString('header').'</th>'.
+	&Apache::loncommon::end_data_table_header_row();
  
     my (undef,undef,$fullname) = &getclasslist($getsec,'1');
     my $ptr = 1;
@@ -4094,15 +4117,21 @@ LISTJAVASCRIPT
 			     return $a cmp $b;
 			 } (keys(%$fullname))) {
 	my ($uname,$udom) = split(/:/,$student);
-	$studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
+	$studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
+                                  : '</td>');
 	$studentTable.='<td align="right">'.$ptr.'&nbsp;</td>';
 	$studentTable.='<td>&nbsp;<label><input type="radio" name="student" value="'.$student.'" /> '
 	    .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
-	$studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
+	$studentTable.=
+	    ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row() 
+                         : '');
 	$ptr++;
     }
-    $studentTable.='</td><td>&nbsp;</td><td>&nbsp;</td></tr>' if ($ptr%2 == 0);
-    $studentTable.='</table></td></tr></table>'."\n";
+    if ($ptr%2 == 0) {
+	$studentTable.='</td><td>&nbsp;</td><td>&nbsp;</td>'.
+	    &Apache::loncommon::end_data_table_row();
+    }
+    $studentTable.=&Apache::loncommon::end_data_table()."\n";
     $studentTable.='<input type="button" '.
 	'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
 
@@ -4202,10 +4231,11 @@ sub displayPage {
 
     $studentTable.='&nbsp;<b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
 	' symbol.'."\n".
-	'<table border="0"><tr><td bgcolor="#777777">'.
-	'<table border="0"><tr bgcolor="#e6ffff">'.
-	'<td align="center"><b>&nbsp;Prob.&nbsp;</b></td>'.
-	'<td><b>&nbsp;'.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
+	&Apache::loncommon::start_data_table().
+	&Apache::loncommon::start_data_table_header_row().
+	'<th align="center">&nbsp;Prob.&nbsp;</th>'.
+	'<th>&nbsp;'.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</th>'.
+	&Apache::loncommon::end_data_table_header_row();
 
     &Apache::lonxml::clear_problem_counter();
     my ($depth,$question,$prob) = (1,1,1);
@@ -4219,7 +4249,9 @@ sub displayPage {
 	    my $parts = $curRes->parts();
             my $title = $curRes->compTitle();
 	    my $symbx = $curRes->symb();
-	    $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
+	    $studentTable.=
+		&Apache::loncommon::start_data_table_row().
+		'<td align="center" valign="top" >'.$prob.
 		(scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).'&nbsp;parts)').'</td>';
 	    $studentTable.='<td valign="top">';
 	    my %form = ('CODE' => $env{'form.CODE'},);
@@ -4427,12 +4459,14 @@ sub updateGradeByPage {
     my $iterator = $navmap->getIterator($map->map_start(),
 					$map->map_finish());
 
-    my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
-	'<table border="0"><tr bgcolor="#e6ffff">'.
-	'<td align="center"><b>&nbsp;Prob.&nbsp;</b></td>'.
-	'<td><b>&nbsp;Title&nbsp;</b></td>'.
-	'<td><b>&nbsp;Previous Score&nbsp;</b></td>'.
-	'<td><b>&nbsp;New Score&nbsp;</b></td></tr>';
+    my $studentTable=
+	&Apache::loncommon::start_data_table().
+	&Apache::loncommon::start_data_table_header_row().
+	'<th align="center">&nbsp;Prob.&nbsp;</th>'.
+	'<th>&nbsp;Title&nbsp;</th>'.
+	'<th>&nbsp;Previous Score&nbsp;</th>'.
+	'<th>&nbsp;New Score&nbsp;</th>'.
+	&Apache::loncommon::end_data_table_header_row();
 
     $iterator->next(); # skip the first BEGIN_MAP
     my $curRes = $iterator->next(); # for "current resource"
@@ -4445,7 +4479,9 @@ sub updateGradeByPage {
 	    my $parts = $curRes->parts();
             my $title = $curRes->compTitle();
 	    my $symbx = $curRes->symb();
-	    $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
+	    $studentTable.=
+		&Apache::loncommon::start_data_table_row().
+		'<td align="center" valign="top" >'.$prob.
 		(scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).'&nbsp;parts)').'</td>';
 	    $studentTable.='<td valign="top">&nbsp;<b>'.$title.'</b>&nbsp;</td>';
 
@@ -4533,14 +4569,14 @@ sub updateGradeByPage {
 
 	    $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
 		'<td valign="top">'.$displayPts[1].'</td>'.
-		'</tr>';
+		&Apache::loncommon::end_data_table_row();
 
 	    $prob++;
 	}
         $curRes = $iterator->next();
     }
 
-    $studentTable.='</td></tr></table></td></tr></table>';
+    $studentTable.=&Apache::loncommon::end_data_table();
     $studentTable.=&show_grading_menu_form($env{'form.symb'});
     my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
 		  'The scores were changed for '.
@@ -5094,7 +5130,8 @@ sub username_to_idmap {
 
 sub scantron_fixup_scanline {
     my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
-
+    
+    
     if ($field eq 'ID') {
 	if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
 	    return ($line,1,'New value too large');
@@ -5125,28 +5162,58 @@ sub scantron_fixup_scanline {
 		   $$scantron_config{'CODElength'})=$args->{'CODE'};
 	}
     } elsif ($field eq 'answer') {
-	my $length=$scantron_config->{'Qlength'};
+	&scantron_get_maxbubble(); # Need the bubble counter info.
+	my $length =$scantron_config->{'Qlength'};
 	my $off=$scantron_config->{'Qoff'};
 	my $on=$scantron_config->{'Qon'};
-	my $answer=${off}x$length;
-	if ($args->{'response'} eq 'none') {
-	    &scan_data($scan_data,
-		       "$whichline.no_bubble.".$args->{'question'},'1');
-	} else {
-	    if ($on eq 'letter') {
-		my @alphabet=('A'..'Z');
-		$answer=$alphabet[$args->{'response'}];
-	    } elsif ($on eq 'number') {
-		$answer=$args->{'response'}+1;
-		if ($answer == 10) { $answer = '0'; }
+        my $question_number = $args->{'question'} -1;
+        my $first_position  = $first_bubble_line{$question_number};
+	my $bubble_count    = $bubble_lines_per_response{$question_number};
+        my $bubbles_per_line= $$scantron_config{'Qlength'};
+	my $answer=${off}x($bubbles_per_line*$bubble_count);
+        my $final_answer;
+        if ($$scantron_config{'Qon'} eq 'letter'  ||
+	    $$scantron_config{'Qon'} eq 'number') { 
+	    $bubbles_per_line = 10;
+	}
+	if (defined $args->{'response'}) {
+	    
+	    if ($args->{'response'} eq 'none') {
+		&scan_data($scan_data,
+			   "$whichline.no_bubble.".$args->{'question'},'1');
 	    } else {
-		substr($answer,$args->{'response'},1)=$on;
+		my ($bubble_line, $bubble_number) = split(/:/,$args->{'response'});
+		if ($on eq 'letter') {
+		    my @alphabet=('A'..'Z');
+		    $answer=$alphabet[$bubble_number];
+		} elsif ($on eq 'number') {
+		    $answer= $bubble_number+1;
+		    if ($answer == 10) { $answer = '0'; }
+		} else {
+		    substr($answer,$bubble_number+$bubble_line*$bubbles_per_line,1)=$on;
+		    $final_answer = $answer;
+		}
+		&scan_data($scan_data,
+			   "$whichline.no_bubble.".$args->{'question'},undef,'1');
+		
+		# Positional notation already has the right final answer length..
+
+		if (($on eq 'letter') || ($on eq 'number')) {
+		    for (my $l = 0; $l < $bubble_count; $l++) {
+			if ($l eq $bubble_line) {
+			    $final_answer .= $answer;
+			} else {
+			    $final_answer .= ' ';
+			}
+		    }
+		}
 	    }
-	    &scan_data($scan_data,
-		       "$whichline.no_bubble.".$args->{'question'},undef,'1');
+	    # $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
+	    #substr($line,$where-1,$length)=$answer;
+	    substr($line, 
+		   $scantron_config->{'Qstart'}+$first_position-1,
+		   $bubbles_per_line*$length) = $final_answer;
 	}
-	my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
-	substr($line,$where-1,$length)=$answer;
     }
     return $line;
 }
@@ -5393,11 +5460,16 @@ sub scantron_parse_scanline {
 		if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
 		    push(@{$record{"scantron.missingerror"}},$questnum);
 		}
-	    } elsif (scalar(@array) lt 2) {
+		
+		#  If the bubble is not the last position, there will be
+		# 2 elements.  If it is the last position, there will be 1 element.
+
+	    } elsif (scalar(@array) le 2) {
 
 		my $location      = length($array[0]);
-		my $line_num      = $location / $$scantron_config{'Qlength'};
+		my $line_num      = int($location / $$scantron_config{'Qlength'});
 		my $bubble        = $alphabet[$location % $$scantron_config{'Qlength'}];
+		
 
 		for (my $ans = 0; $ans < $answers_needed; $ans++) {
 		    if ($ans eq $line_num) {
@@ -6524,6 +6596,7 @@ sub scantron_bubble_selector {
 
     my $total_lines = $lines*2;
     my @alphabet=('A'..'Z');
+
     $r->print("<table border='1'><tr><td rowspan='".$total_lines."'>$quest</td>");
 
     for (my $l = 0; $l < $lines; $l++) {
@@ -6557,9 +6630,10 @@ sub scantron_bubble_selector {
 	#        multiline questions (different values e.g..).
 
 	for (my $i=0;$i<$max;$i++) {
+	    my $value = "$l:$i";	# Relative bubble line #: Bubble in line.
 	    $r->print("\n".
 		      '<td><label><input type="radio" name="scantron_correct_Q_'.
-		      $quest.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
+		      $quest.'" value="'.$value.'" />'.$alphabet[$i]."</label></td>");
 	}
 	$r->print('</tr>');
 
@@ -7209,7 +7283,7 @@ sub show_grading_menu_form {
 	'<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\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".
+	'<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
 	'</form>'."\n";
     return $result;
 }
@@ -7279,7 +7353,7 @@ sub grading_menu {
     $Str .= '<input type="hidden" name="command" value="" />'.
     	'<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="probTitle"   value="'.$probTitle.'" />'."\n".
 	'<input type="hidden" name="saveState"   value="" />'."\n".
 	'<input type="hidden" name="gradingMenu" value="1" />'."\n".
 	'<input type="hidden" name="showgrading" value="yes" />'."\n";
@@ -7303,7 +7377,6 @@ sub grading_menu {
         $Str .= '    '.('&nbsp;'x8).$menudata->{'short_description'}.
             "\n";
     }
-    $Str .="</dl>\n";
     $Str .="</form>\n";
     $request->print(<<GRADINGMENUJS);
 <script type="text/javascript" language="javascript">
@@ -7390,9 +7463,8 @@ sub submit_options {
 </script>
 GRADINGMENUJS
     &commonJSfunctions($request);
-    my $result='<h3>&nbsp;<span class="LC_info">Manual Grading/View Submission</span></h3>';
     my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
-    $result.=$table;
+    my $result;
     my (undef,$sections) = &getclasslist('all','0');
     my $savedState = &savedState();
     my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
@@ -7409,102 +7481,104 @@ GRADINGMENUJS
 	'<input type="hidden" name="gradingMenu" value="1" />'."\n".
 	'<input type="hidden" name="showgrading" value="yes" />'."\n";
 
-    $result.='<table border="0"><tr><td bgcolor=#777777>'."\n".
-	'<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\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><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";
+    $result.='
+    <div class="LC_grade_select_mode">
+      <div class="LC_grade_select_mode_current">
+        <h2>
+          '.&mt('Grade Current Resource').'
+        </h2>
+        <div class="LC_grade_select_mode_body">
+          <div class="LC_grades_resource_info">
+           '.$table.'
+          </div>
+          <div class="LC_grade_select_mode_selector">
+             <div class="LC_grade_select_mode_selector_header">
+                '.&mt('Sections').'
+             </div>
+             <div class="LC_grade_select_mode_selector_body">
+	       <select name="section" multiple="multiple" size="5">'."\n";
     if (ref($sections)) {
-	foreach (sort (@$sections)) {
-	    $result.='<option value="'.$_.'" '.
-		($saveSec eq $_ ? 'selected="selected"':'').'>'.$_.'</option>'."\n";
+	foreach my $section (sort (@$sections)) {
+	    $result.='<option value="'.$section.'" '.
+		($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
 	}
     }
     $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> &nbsp; ';
-    $result.= '</td><td>'."\n";
-    $result.= &Apache::lonstatistics::GroupSelect('group','multiple',3);
-    $result.='</td><td>'."\n";
-    $result.=&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,3,undef,'mult');
-
-    $result.='</td>';
-    $result.='<td><select name="submitonly" size="3">'.
-	'<option value="yes" '.
-	($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>'.
-	'<option value="queued" '.
-	($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>'.
-	'<option value="graded" '.
-	($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>'.
-	'<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>';
-
-    $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="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"><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/folder: For one student</label></td></tr>'."\n";
-
-    $result.='<tr bgcolor="#ffffe6"><td colspan="3"><br />'.
-	'<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
-	'</td></tr></table>'."\n";
-
-    $result.='</td>'; #<td valign="top">';
-
-#    $result.='<table width="100%" border="0">';
-#    $result.='<tr bgcolor="#ffffe6"><td>'.
-#	'<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
-#	' '.&mt('scores from file').' </td></tr>'."\n";
-#
-#    $result.='<tr bgcolor="#ffffe6"><td>'.
-#        '<input type="button" onClick="javascript:checkChoice(this.form,\'6\',\'processclicker\');" value="'.&mt('Process').'" />'.
-#        ' '.&mt('clicker file').' </td></tr>'."\n";
-#
-#    $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
-#	'<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
-#	'" value="'.&mt('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="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="'.&mt('Verify').'" />'.
-#	    ' '.&mt('receipt').': '.
-#	    &Apache::lonnet::recprefix($env{'request.course.id'}).
-#	    '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />'.
-#	    '</td></tr>'."\n";
-#    } 
-#    $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
-#	'<input type="button" onClick="javascript:this.form.action=\'/adm/helper/resettimes.helper\';this.form.submit();'.
-#	'" value="'.&mt('Manage').'" /> access times.</td></tr>'."\n";
-#    $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
-#	'<input type="button" onClick="javascript:this.form.command.value=\'codelist\';this.form.action=\'/adm/pickcode\';this.form.submit();'.
-#	'" value="'.&mt('View').'" /> saved CODEs.</td></tr>'."\n";
-#
-#    $result.='</table>'."\n".'</td>';
-    $result.= '</tr></table>'."\n".
-	'</td></tr></table></form>'."\n";
+    $result.='
+             </div>
+          </div>
+          <div class="LC_grade_select_mode_selector">
+             <div class="LC_grade_select_mode_selector_header">
+                '.&mt('Groups').'
+             </div>
+             <div class="LC_grade_select_mode_selector_body">
+                '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
+             </div>
+          </div>
+          <div class="LC_grade_select_mode_selector">
+             <div class="LC_grade_select_mode_selector_header">
+                '.&mt('Access Status').'
+             </div>
+             <div class="LC_grade_select_mode_selector_body">
+                '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
+             </div>
+          </div>
+          <div class="LC_grade_select_mode_selector">
+             <div class="LC_grade_select_mode_selector_header">
+                '.&mt('Submission Status').'
+             </div>
+             <div class="LC_grade_select_mode_selector_body">
+               <select name="submitonly" size="5">
+	         <option value="yes" '.      ($saveSub eq 'yes'       ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
+	         <option value="queued" '.   ($saveSub eq 'queued'    ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
+	         <option value="graded" '.   ($saveSub eq 'graded'    ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
+	         <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>
+             </div>
+          </div>
+          <div class="LC_grade_select_mode_type_body">
+            <div class="LC_grade_select_mode_type">
+              <label>
+                <input type="radio" name="radioChoice" value="submission" '.
+                  ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
+             &mt('Select individual students to grade and view submissions.').'
+	      </label> 
+            </div>
+            <div class="LC_grade_select_mode_type">
+	      <label>
+                <input type="radio" name="radioChoice" value="viewgrades" '.
+                  ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
+                    &mt('Grade all selected students in a grading table.').'
+              </label>
+            </div>
+            <div class="LC_grade_select_mode_type">
+	      <input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next-&gt;').'" />
+            </div>
+          </div>
+        </div>
+      </div>
+      <div class="LC_grade_select_mode_page">
+        <h2>
+         '.&mt('Grade Complete Folder for One Student').'
+        </h2>
+        <div class="LC_grades_select_mode_body">
+          <div class="LC_grade_select_mode_type_body">
+            <div class="LC_grade_select_mode_type">
+              <label>
+                <input type="radio" name="radioChoice" value="pickStudentPage" '.
+	  ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
+  &mt('The <b>complete</b> page/sequence/folder: For one student').'
+              </label>
+            </div>
+            <div class="LC_grade_select_mode_type">
+	      <input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next-&gt;').'" />
+            </div>
+          </div>
+        </div>
+      </div>
+    </div>
+  </form>';
     return $result;
 }