--- loncom/homework/grades.pm	2002/12/02 17:30:30	1.64
+++ loncom/homework/grades.pm	2003/02/28 21:06:28	1.70
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.64 2002/12/02 17:30:30 albertel Exp $
+# $Id: grades.pm,v 1.70 2003/02/28 21:06:28 ng Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,6 +31,8 @@
 # 8/20 Gerd Kortemeyer
 # Year 2002
 # June-August H.K. Ng
+# Year 2003
+# February H.K. Ng
 #
 
 package Apache::grades;
@@ -39,12 +41,13 @@ use Apache::style;
 use Apache::lonxml;
 use Apache::lonnet;
 use Apache::loncommon;
+use Apache::lonnavmaps;
 use Apache::lonhomework;
 use Apache::loncoursedata;
 use Apache::lonmsg qw(:user_normal_msg);
 use Apache::Constants qw(:common);
 
-# ----- These first few routines are general use routines.-----
+# ----- These first few routines are general use routines.----
 #
 # --- Retrieve the parts that matches stores_\d+ from the metadata file.---
 sub getpartlist {
@@ -269,6 +272,10 @@ sub verifyreceipt {
     return $string.&show_grading_menu_form($symb,$url);
 }
 
+#
+# Pick student and page/sequence for manual grading
+
+
 #--- This is called by a number of programs.
 #--- Called from the Grading Menu - View/Grade an individual student
 #--- Also called directly when one clicks on the subm button 
@@ -293,12 +300,7 @@ sub listStudents {
     }
     $result.='</table>';
 
-    my $viewgrade;
-    if ($ENV{'form.handgrade'} eq 'yes') {
-	$viewgrade = 'View/Grade';
-    } else {
-	$viewgrade = 'View';
-    }
+    my $viewgrade = $ENV{'form.handgrade'} eq 'yes' ? 'View/Grade' : 'View';
 
     $result='<h3><font color="#339933">&nbsp;'.
 	$viewgrade.
@@ -352,7 +354,7 @@ LISTJAVASCRIPT
 	'<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
 	'<input type="hidden" name="submitonly"  value="'.$submitonly.'" />'."\n".
 	'<input type="hidden" name="response"    value="'.$ENV{'form.response'}.'" />'."\n".
-	'<input type="hidden" name="handgrade": #falue="'.$ENV{'form.handgrade'}.'" /><br />'."\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="url"  value="'.$url.'" />'."\n".
 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
@@ -846,7 +848,7 @@ sub submission {
 
 	# option to display problem, only once else it cause problems 
         # with the form later since the problem has a form.
-	if ($ENV{'form.vProb'} eq 'yes') {
+	if ($ENV{'form.vProb'} eq 'yes' or !$ENV{'form.vProb'}) {
 	    &show_problem($request,$symb,$uname,$udom,0);
 	}
 	
@@ -1021,7 +1023,12 @@ KEYWORDS
 			    my ($ressub,$subval) = split(/:/,$_,2);
 			    $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
 				$partid.'</b> <font color="#999999">( ID '.$respid.
-				' )</font>&nbsp; &nbsp;<b>Answer: </b>'.
+				' )</font>&nbsp; &nbsp;'.
+                                ($record{"resource.$partid.$respid.uploadedurl"}?
+                                '<a href="'.
+                                &Apache::lonnet::tokenwrapper($record{"resource.$partid.$respid.uploadedurl"}).
+   '"><img src="/adm/lonIcons/unknown.gif" border=0"> File uploaded by student</a> <font color="red" size="1">Like all files provided by users, this file may contain virusses</font><br />':'').
+                                '<b>Answer: </b>'.
 				&keywords_highlight($subval).'</td></tr>'."\n"
 				if ($ENV{'form.lastSub'} eq 'lastonly' || 
 				    ($ENV{'form.lastSub'} eq 'hdgrade' && 
@@ -1073,53 +1080,9 @@ KEYWORDS
 	$seen{$partid}++;
 	next if ($$handgrade{$_} =~ /:no$/);
 	push @partlist,$partid;
-	my $wgt    = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
-	my $wgtmsg = ($wgt > 0 ? '(problem weight)' : 
-		      '<font color="red">problem weight assigned by computer</font>');
-	$wgt       = ($wgt > 0 ? $wgt : '1');
-	my $score  = ($record{'resource.'.$partid.'.awarded'} eq '' ?
-		      '' : $record{'resource.'.$partid.'.awarded'}*$wgt);
-	$result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
-	$result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points: </b></td><td>';
 
-	my $ctr = 0;
-	$result.='<table border="0"><tr>';  # display radio buttons in a nice table 10 across
-	while ($ctr<=$wgt) {
-	    $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
-		'onclick="javascript:writeBox(this.form.GD_BOX'.$counter.'_'.$partid.
-		',this.form.GD_SEL'.$counter.'_'.$partid.','.$ctr.
-		',this.form.stores'.$counter.'_'.$partid.')" '.
-		($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
-	    $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
-	    $ctr++;
-	}
-	$result.='</tr></table>';
+	$result=&gradeBox($symb,$uname,$udom,$counter,$partid,\%record);
 
-	$result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';
-	$result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
-	    ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
-	    'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
-	    ',this.form.GD_BOX'.$counter.'_'.$partid.
-	    ',this.form.GD_SEL'.$counter.'_'.$partid.
-	    ',this.form.stores'.$counter.'_'.$partid.
-	    ','.$wgt.')" /></td>'."\n";
-	$result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
-
-	$result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
-	    'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
-	    ',this.form.GD_BOX'.$counter.'_'.$partid.
-	    ',this.form.GD_SEL'.$counter.'_'.$partid.
-	    ',this.form.stores'.$counter.'_'.$partid.')" >'."\n";
-	if ($record{'resource.'.$partid.'.solved'} eq 'excused') {
-	    $result.='<option> </option>'.
-		'<option selected="on">excused</option></select>';
-	} else {
-	    $result.='<option selected="on"> </option>'.
-		'<option>excused</option></select>';
-	}
-	$result.="&nbsp&nbsp\n";
-	$result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
-	$result.='</td></tr></table>'."\n";
 	$request->print($result);
     }
     $result='<input type="hidden" name="partlist'.$counter.
@@ -2193,6 +2156,7 @@ sub gradingmenu {
     $result.=&view_edit_entire_class_form($symb,$url).'<br />';
     $result.=&upcsvScores_form($symb,$url).'<br />';
     $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />';
+    $result.=&gradeByPage_form($symb,$url,$resptype,$hdgrade).'<br />';
     $result.=&verifyReceipt_form($symb,$url) 
 	if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb));
  
@@ -2264,12 +2228,7 @@ sub viewGradeaStu_form {
     my $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>';
-    if ($handgrade eq 'yes') {
-	$result.="View/Grade ";
-    } else {
-	$result.="View ";
-    }
-    $result.='an Individual Student\'s Submission</b></td></tr>'."\n";
+    $result.=($handgrade eq 'yes' ? 'View/Grade' : 'View').' an Individual Student\'s Submission</b></td></tr>'."\n";
     $result.='<tr bgcolor=#ffffe6><td>'."\n";
     $result.='<form action="/adm/grades" method="post">'."\n".
 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
@@ -2305,6 +2264,335 @@ sub viewGradeaStu_form {
     return $result;
 }
 
+#--- Handgrading problems by page/sequence for each student ---
+sub gradeByPage_form {
+    my ($symb,$url,$response,$handgrade) = @_;
+    my ($classlist,$sections) = &getclasslist('all','0');
+    my $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>';
+    $result.='Handgrade an Individual Student\'s by Page/Sequence</b></td></tr>'."\n";
+    $result.='<tr bgcolor=#ffffe6><td>'."\n";
+    $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="response" value="'.$response.'" />'."\n".
+	'<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
+	'<input type="hidden" name="showgrading" value="yes" />'."\n".
+	'<input type="hidden" name="command" value="pickStudentPage" />'."\n";
+
+    $result.='&nbsp;<b>Select section:</b> <select name="section">'."\n";
+    if (ref($sections)) {
+	foreach (sort (@$sections)) {$result.='<option>'.$_.'</option>'."\n";}
+    }
+    $result.= '<option selected="on">all</select>'."\n";
+
+    $result.='<br />&nbsp;<input type="button" onClick="submit();" value="';
+    $result.='View/Grade'.'" />'."\n".'</form>'."\n";
+    $result.='</td></tr></table>'."\n";
+    $result.='</td></tr></table>'."\n";
+    return $result;
+}
+
+
+sub pickStudentPage {
+    my ($request) = shift;
+
+    $request->print(<<LISTJAVASCRIPT);
+<script type="text/javascript" language="javascript">
+
+function checkPickOne(formname) {
+    var user = radioSelection(formname.student);
+    if (user == null) {
+	alert("Please select the student you wish to grade.");
+	return;
+    }
+    var ptr = pullDownSelection(formname.selectpage);
+    formname.page.value = formname.eval("page"+ptr).value;
+    formname.title.value = formname.eval("title"+ptr).value;
+    formname.submit();
+}
+
+function radioSelection(radioButton) {
+    var selection=null;
+    for (var i=0; i<radioButton.length; i++) {
+        if (radioButton[i].checked) {
+            selection=radioButton[i].value;
+            return selection;
+        }
+    }
+    return selection;
+}
+
+function pullDownSelection(selectOne) {
+    var selection=null;
+    for (var i=0; i<selectOne.length; i++) {
+        if (selectOne[i].selected) {
+            selection=selectOne[i].value;
+            return selection;
+        }
+    }
+}
+</script>
+LISTJAVASCRIPT
+
+    my ($symb,$url) = &get_symb_and_url();
+    my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
+    my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
+    my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
+
+    my $result='<h3><font color="#339933">&nbsp;'.
+	'Manual Grading by Page or Sequence</font></h3>';
+
+    my ($pagepath,$pagename,$type,$mapId) = ($symb =~ /(.*\/)(.*?\.(page|sequence))___(\d+)___/); 
+    my $curtitle = &Apache::lonnet::metadata($pagepath.$pagename,'title');
+
+    $result.='<form action="/adm/grades" method="post" name="displayPage">'."<br>\n";
+    $result.='&nbsp;<b>Problems from:</b> <select name="selectpage">'."\n";
+    my ($titles,$symbx) = &getSymbMap();
+#    shift @$titles; # skip the top level sequence
+    my $ctr=0;
+    foreach (@$titles) {
+	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
+	$result.='<option value="'.$ctr.'" '.
+	    ($showtitle eq $curtitle ? 'selected="on"' : '').'>'.$showtitle.'</option>'."\n";
+	$ctr++;
+    }
+    $result.= '</select>'."<br>\n";
+    $ctr=0;
+    foreach (@$titles) {
+	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
+	$result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
+	$result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
+	$ctr++;
+    }
+    $result.='<input type="hidden" name="page" />'."\n";
+    $result.='<input type="hidden" name="title" />'."\n";
+
+#    $result.='&nbsp;<b>View Problems: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
+#	'<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
+#    $result.='&nbsp;<b>Submission Details: </b>'.
+#	'<input type="radio" name="lastSub" value="last" checked /> last sub only'."\n".
+#	'<input type="radio" name="lastSub" value="all" /> all details'."\n";
+    $result.='<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
+	'<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";
+    $request->print($result);
+
+    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>'.
+	'<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td>'.
+	'<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 $ptr = 1;
+    foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
+	my ($uname,$udom) = split(/:/,$student);
+	$studentTable.=($ptr%4 == 1 ? '<tr bgcolor="#ffffe6"><td>' : '</td><td>');
+	$studentTable.='<input type="radio" name="student" value="'.$student.'" /> '.$$fullname{$student}.
+	    '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font>'."\n";
+	$studentTable.=($ptr%4 == 0 ? '</td></tr>' : '');
+	$ptr++;
+    }
+    $studentTable.='</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;' if ($ptr%4 == 2);
+    $studentTable.='</td><td>&nbsp;</td><td>&nbsp;' if ($ptr%4 == 3);
+    $studentTable.='</td><td>&nbsp;' if ($ptr%4 == 0);
+    $studentTable.='</td></tr></table></td></tr></table>'."\n";
+    $studentTable.='<br />&nbsp;<input type="button" '.
+	'onClick="javascript:checkPickOne(this.form);"value="Submit" /></form>'."\n";
+
+    $studentTable.=&show_grading_menu_form($symb,$url);
+    $request->print($studentTable);
+
+    return '';
+}
+
+sub getSymbMap {
+    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
+    $navmap->init();
+
+    # End navmap using boilerplate
+
+    my $iterator = $navmap->getIterator(undef, undef, undef, 1);
+    my $depth = 1;
+    $iterator->next(); # ignore first BEGIN_MAP
+    my $curRes = $iterator->next();
+
+    my %symbx = ();
+    my @titles = ();
+    my $minder=0;
+    while ($depth > 0) {
+        if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
+        if ($curRes == $iterator->END_MAP()) { $depth--; }
+
+        if (ref($curRes) && $curRes->is_map()) {
+            my $title = $curRes->compTitle();
+	    push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
+	    $symbx{$minder.'.'.$title} = $curRes->symb();
+	    $minder++;
+       }
+        $curRes = $iterator->next();
+    }
+
+    $navmap->untieHashes();
+    return \@titles,\%symbx;
+}
+
+sub displayPage {
+    my ($request) = shift;
+
+    my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
+    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 ($uname,$udom) = split(/:/,$ENV{'form.student'});
+    my ($idx,$showtitle) = ($pageTitle =~ /(\d+)\.(.*)/);
+
+    my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
+    $result.='<h3>&nbsp;Student: '.$$fullname{$ENV{'form.student'}}.
+	'<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
+
+    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
+
+    my $iterator = $navmap->getIterator($map->map_start(),
+					$map->map_finish());
+
+    my $depth = 1;
+    $iterator->next(); # skip the first BEGIN_MAP
+    my $curRes = $iterator->next(); # for "current resource"
+    my %symbx = ();
+    my @titles = ();
+    my %parts = ();
+    my $ctr=0;
+    my $minder=0;
+    while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
+        if($curRes == $iterator->BEGIN_MAP) { $depth++; }
+        if($curRes == $iterator->END_MAP) { $depth++; }
+
+        if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
+	    my $parts = $curRes->parts();
+            my $title = $curRes->compTitle();
+	    push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
+	    if (scalar(@{$parts}) > 1) { shift @{$parts}; }
+	    $parts{$minder.'.'.$title} = join '::',@{$parts};
+            $symbx{$minder.'.'.$title} = $curRes->symb();
+	    $minder++;
+
+       }
+        $curRes = $iterator->next();
+	$ctr++;
+    }
+
+
+    $navmap->init();
+    $request->print($result);
+    &sub_page_js($request);
+
+    my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
+	'<input type="hidden" name="command"  value="gradePage" />'."\n".
+	'<input type="hidden" name="student"  value="'.$ENV{'form.student'}.'" />'."\n".
+	'<input type="hidden" name="page"  value="'.$pageTitle.'" />'."\n".
+	'<input type="hidden" name="title" value="'.$ENV{'form.title'}.'" />'."\n";
+
+    $studentTable.=
+	'<table border="0"><tr><td bgcolor="#777777">'.
+	'<table border="0"><tr bgcolor="#e6ffff">'.
+	'<td align="center"><b>&nbsp;No&nbsp;</b></td>'.
+	'<td><b>&nbsp;Title</b></td>'.
+	'<td><b>&nbsp;Answer</b></td>'.
+	'<td><b>&nbsp;Grade</b></td></tr>';
+    my $question=1;
+    foreach (@titles) {
+	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
+	my @parts = split(/::/,$parts{$_});
+	$studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
+	    (scalar(@parts) == 1 ? '' : '<br>('.scalar(@parts).'&nbsp;parts)').'</td>';
+	$studentTable.='<td valign="top">&nbsp;'.$showtitle.'&nbsp;</td>';
+	$studentTable.='<td>&nbsp;'.
+	    &Apache::loncommon::get_student_answers($symbx{$_},$uname,$udom,$ENV{'request.course.id'}).'</td>';
+
+	my %record = &Apache::lonnet::restore($symbx{$_},$ENV{'request.course.id'},$udom,$uname);
+	$studentTable.='<td>&nbsp;';
+	foreach my $partid (@parts) {
+	    $studentTable.=&gradeBox($symbx{$_},$uname,$udom,$question,$partid,\%record);
+	    $question++;
+	}
+	$studentTable.='</td></tr>';
+
+    }
+
+    $studentTable.='</table></td></tr></table>';
+    $studentTable.='</form>';
+
+    $request->print($studentTable);
+
+    return '';
+}
+
+sub gradeBox {
+    my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
+    my $wgt    = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
+    my $wgtmsg = ($wgt > 0 ? '(problem weight)' : 
+		  '<font color="red">problem weight assigned by computer</font>');
+    $wgt       = ($wgt > 0 ? $wgt : '1');
+    my $score  = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
+		  '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
+    my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
+    $result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points: </b></td><td>';
+
+    my $ctr = 0;
+    $result.='<table border="0"><tr>';  # display radio buttons in a nice table 10 across
+    while ($ctr<=$wgt) {
+	$result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
+	    'onclick="javascript:writeBox(this.form.GD_BOX'.$counter.'_'.$partid.
+	    ',this.form.GD_SEL'.$counter.'_'.$partid.','.$ctr.
+	    ',this.form.stores'.$counter.'_'.$partid.')" '.
+	    ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
+	$result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
+	$ctr++;
+    }
+    $result.='</tr></table>';
+    $result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';
+    $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
+	($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
+	'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
+	',this.form.GD_BOX'.$counter.'_'.$partid.
+	',this.form.GD_SEL'.$counter.'_'.$partid.
+	',this.form.stores'.$counter.'_'.$partid.
+	','.$wgt.')" /></td>'."\n";
+    $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
+
+    $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
+	'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
+	',this.form.GD_BOX'.$counter.'_'.$partid.
+	',this.form.GD_SEL'.$counter.'_'.$partid.
+	',this.form.stores'.$counter.'_'.$partid.')" >'."\n";
+    if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
+	$result.='<option> </option>'.
+	    '<option selected="on">excused</option></select>';
+    } else {
+	$result.='<option selected="on"> </option>'.
+	    '<option>excused</option></select>';
+    }
+    $result.="&nbsp&nbsp\n";
+    $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
+    $result.='</td></tr></table>'."\n";
+    return $result;
+}
+
 #--- Form to input a receipt number ---
 sub verifyReceipt_form {
     my ($symb,$url) = @_;
@@ -2392,8 +2680,14 @@ sub handler {
     } else {
 	$Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
 	if ($command eq 'submission') {
-	    &listStudents($request) if ($ENV{'form.student'} eq '');
-	    &submission($request,0,0) if ($ENV{'form.student'} ne '');
+	    ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
+#	if ($command eq 'submission') {
+#	    &listStudents($request) if ($ENV{'form.student'} eq '');
+#	    &submission($request,0,0) if ($ENV{'form.student'} ne '');
+	} elsif ($command eq 'pickStudentPage') {
+	    &pickStudentPage($request);
+	} elsif ($command eq 'displayPage') {
+	    &displayPage($request);
 	} elsif ($command eq 'processGroup') {
 	    &processGroup($request);
 	} elsif ($command eq 'gradingmenu') {