[LON-CAPA-cvs] cvs: loncom /homework grades.pm

ng lon-capa-cvs@mail.lon-capa.org
Fri, 25 Jul 2003 20:35:40 -0000


This is a MIME encoded message

--ng1059165340
Content-Type: text/plain

ng		Fri Jul 25 16:35:40 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  Replace use of eval function in javascript.
  Fix bug 1842 - allows reset of award, tries to blank and zero - if records exist
                 This is done by selecting the reset status on the drop down menu.
  Probably fix bug 1433 - javascript throws an error on grading by page/sequence
                 on OS X. Test on OS X and have not seen the error.
  Have done fairly extensive testing of grades.pm on linux, windows and mac.
  Should include this version of grades.pm on release 1.0.
  
  
  
--ng1059165340
Content-Type: text/plain
Content-Disposition: attachment; filename="ng-20030725163540.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.124 loncom/homework/grades.pm:1.125
--- loncom/homework/grades.pm:1.124	Wed Jul 23 14:04:51 2003
+++ loncom/homework/grades.pm	Fri Jul 25 16:35:40 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.124 2003/07/23 18:04:51 ng Exp $
+# $Id: grades.pm,v 1.125 2003/07/25 20:35:40 ng Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,6 +33,7 @@
 # June-August H.K. Ng
 # Year 2003
 # February, March H.K. Ng
+# July, H. K. Ng
 #
 
 package Apache::grades;
@@ -98,7 +99,8 @@
 #--- Get the partlist and the response type for a given problem. ---
 #--- Indicate if a response type is coded handgraded or not. ---
 sub response_type {
-    my ($url) = shift;
+    my ($url,$symb) = shift;
+    $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url))) if ($symb eq '');
     my $allkeys = &Apache::lonnet::metadata($url,'keys');
     my %seen = ();
     my (@partlist,%handgrade);
@@ -107,7 +109,9 @@
 	    my ($responsetype,$part) = split(/_/,$_,2);
 	    my ($partid,$respid) = split(/_/,$part);
 	    $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
-	    $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
+#	    my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
+#	    $handgrade{$part} = $responsetype.':'.($value eq 'yes' ? 'yes' : 'no'); #a bug $value is 'yes' regardless
+	    $handgrade{$part} = $responsetype.':'.(($allkeys =~ /parameter_$part\_handgrade/) ? 'yes' : 'no');
 	    next if ($seen{$partid} > 0);
 	    $seen{$partid}++;
 	    push @partlist,$partid;
@@ -321,6 +325,7 @@
 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
 	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
 	'<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
+	'<input type="hidden" name="Status"  value="'.$ENV{'form.Status'}.'" />'."\n".
 	'<input type="hidden" name="command" value="submission" />'."\n".
 	'<input type="hidden" name="student" value="" />'."\n".
 	'<input type="hidden" name="userdom" value="" />'."\n".
@@ -645,9 +650,9 @@
     $request->print(<<SUBJAVASCRIPT);
 <script type="text/javascript" language="javascript">
     function updateRadio(formname,id,weight) {
-	var gradeBox = eval("formname.GD_BOX"+id);
-	var radioButton = eval("formname.RADVAL"+id);
-	var oldpts = eval("formname.oldpts"+id+".value");
+	var gradeBox = formname["GD_BOX"+id];
+	var radioButton = formname["RADVAL"+id];
+	var oldpts = formname["oldpts"+id].value;
 	var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
 	gradeBox.value = pts;
 	var resetbox = false;
@@ -669,7 +674,7 @@
 	    var resp = confirm("You entered a value ("+pts+
 			       ") greater than the weight for the part. Accept?");
 	    if (resp == false) {
-		gradeBox.value = "";
+		gradeBox.value = oldpts;
 		return;
 	    }
 	}
@@ -681,18 +686,17 @@
 	    }
 	}
 	updateSelect(formname,id);
-	var stores = eval("formname.stores"+id);
-	stores.value = "0";
+	formname["stores"+id].value = "0";
     }
 
     function writeBox(formname,id,pts) {
-	var gradeBox = eval("formname.GD_BOX"+id);
+	var gradeBox = formname["GD_BOX"+id];
 	if (checkSolved(formname,id) == 'update') {
 	    gradeBox.value = pts;
 	} else {
-	    var oldpts = eval("formname.oldpts"+id+".value");
+	    var oldpts = formname["oldpts"+id].value;
 	    gradeBox.value = oldpts;
-	    var radioButton = eval("formname.RADVAL"+id);
+	    var radioButton = formname["RADVAL"+id];
 	    for (var i=0; i<radioButton.length; i++) {
 		radioButton[i].checked=false;
 		if (i == oldpts) {
@@ -700,8 +704,7 @@
 		}
 	    }
 	}
-	var stores = eval("formname.stores"+id);
-	stores.value = "0";
+	formname["stores"+id].value = "0";
 	updateSelect(formname,id);
 	return;
     }
@@ -711,17 +714,17 @@
 	    updateSelect(formname,id);
 	    return;
 	}
-	gradeSelect = eval("formname.GD_SEL"+id);
+	gradeSelect = formname["GD_SEL"+id];
 	for (var i=0; i<gradeSelect.length; i++) {
 	    if (gradeSelect[i].selected) {
 		var selectx=i;
 	    }
 	}
-	var stores = eval("formname.stores"+id);
+	var stores = formname["stores"+id];
 	if (selectx == stores.value) { return };
-	var gradeBox = eval("formname.GD_BOX"+id);
+	var gradeBox = formname["GD_BOX"+id];
 	gradeBox.value = "";
-	var radioButton = eval("formname.RADVAL"+id);
+	var radioButton = formname["RADVAL"+id];
 	for (var i=0; i<radioButton.length; i++) {
 	    radioButton[i].checked=false;
 	}
@@ -729,7 +732,7 @@
     }
 
     function checkSolved(formname,id) {
-	if (eval("formname.solved"+id+".value") == "correct_by_student" && formname.overRideScore.value == 'no') {
+	if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
 	    var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
 	    if (!reply) {return "noupdate";}
 	    formname.overRideScore.value = 'yes';
@@ -738,8 +741,7 @@
     }
 
     function updateSelect(formname,id) {
-	var gradeSelect = eval("formname.GD_SEL"+id);
-	gradeSelect[0].selected = true;
+	formname["GD_SEL"+id][0].selected = true;
 	return;
     }
 
@@ -749,15 +751,15 @@
 	if (val == "Save & Next") {
 	    for (i=0;i<=total;i++) {
 		for (j=0;j<parttot;j++) {
-		    var partid = eval("formname.partid"+i+"_"+j+".value");
-		    var selopt = eval("formname.GD_SEL"+i+"_"+partid);
+		    var partid = formname["partid"+i+"_"+j].value;
+		    var selopt = formname["GD_SEL"+i+"_"+partid];
 		    if (selopt[0].selected) {
-			var points = eval("formname.GD_BOX"+i+"_"+partid+".value");
+			var points = formname["GD_BOX"+i+"_"+partid].value;
 			if (points == "") {
-			    var name = eval("formname.name"+i+".value");
+			    var name = formname["name"+i].value;
 			    var resp = confirm("You did not assign a score for "+name+", part "+partid+". Continue?");
 			    if (resp == false) {
-				eval("formname.GD_BOX"+i+"_"+partid+".focus()");
+				formname["GD_BOX"+i+"_"+partid].focus();
 				return false;
 			    }
 			}
@@ -782,11 +784,11 @@
 	noscore = new Array(100);
 	var ptr = 0;
 	for (i=1;i<total;i++) {
-	    var partid = eval("formname.q_"+i+".value");
-	    var selopt = eval("formname.GD_SEL"+i+"_"+partid);
+	    var partid = formname["q_"+i].value;
+	    var selopt = formname["GD_SEL"+i+"_"+partid];
 	    if (selopt[0].selected) {
-		var points = eval("formname.GD_BOX"+i+"_"+partid+".value");
-		var status = eval("formname.solved"+i+"_"+partid+".value");
+		var points = formname["GD_BOX"+i+"_"+partid].value;
+		var status = formname["solved"+i+"_"+partid].value;
 		if (points == "" && status != "correct_by_student") {
 		    noscore[ptr] = i;
 		    ptr++;
@@ -880,7 +882,7 @@
     var Nmsg  = msgform.savemsgN.value;
     savedMsgHeader(Nmsg,usrctr,fullname);
     var subject = msgform.msgsub.value;
-    var rtrchk  = eval("document.SCORE.includemsg"+usrctr);
+    var rtrchk  = document.SCORE["includemsg"+usrctr];
     var msgchk = rtrchk.value;
     re = /msgsub/;
     var shwsel = "";
@@ -892,13 +894,13 @@
 	re = new RegExp(testmsg,"g");
 	shwsel = "";
 	if (re.test(msgchk)) { shwsel = "checked" }
-	var message = eval("document.SCORE.savemsg"+i+".value");
-	var shownOnce = eval("document.SCORE.shownOnce"+i+".value");
+	var message = document.SCORE["savemsg"+i].value;
+	var shownOnce = document.SCORE["shownOnce"+i].value;
 	message = (shownOnce == 0 ? checkEntities(message) : message);
 	displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
 	                                   //any &lt; is already converted to <, etc. However, only once!!
     }
-    newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
+    newmsg = document.SCORE["newmsg"+usrctr].value;
     shwsel = "";
     re = /newmsg/;
     if (re.test(msgchk)) { shwsel = "checked" }
@@ -947,7 +949,7 @@
     pDoc.write("  opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);");
     pDoc.write("  var nmsg   = opener.document.SCORE.savemsgN.value;");
     pDoc.write("  var usrctr = document.msgcenter.usrctr.value;");
-    pDoc.write("  var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
+    pDoc.write("  var newval = opener.document.SCORE[\\"newmsg\\"+usrctr];");
     pDoc.write("  newval.value = opener.checkEntities(document.msgcenter.newmsg.value);");
 
     pDoc.write("  var msgchk = \\"\\";");
@@ -956,12 +958,12 @@
     pDoc.write("  }");
     pDoc.write("  var includemsg = 0;");
     pDoc.write("  for (var i=1; i<=nmsg; i++) {");
-    pDoc.write("      var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
-    pDoc.write("      var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
+    pDoc.write("      var opnmsg = opener.document.SCORE[\\"savemsg\\"+i];");
+    pDoc.write("      var frmmsg = document.msgcenter[\\"msg\\"+i];");
     pDoc.write("      opnmsg.value = opener.checkEntities(frmmsg.value);");
-    pDoc.write("      var showflg = eval(\\"opener.document.SCORE.shownOnce\\"+i);");
+    pDoc.write("      var showflg = opener.document.SCORE[\\"shownOnce\\"+i];");
     pDoc.write("      showflg.value = \\"1\\";");
-    pDoc.write("      var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
+    pDoc.write("      var chkbox = document.msgcenter[\\"msgn\\"+i];");
     pDoc.write("      if (chkbox.checked) {");
     pDoc.write("         msgchk += \\"savemsg\\"+i+\\",\\";");
     pDoc.write("         includemsg = 1;");
@@ -971,9 +973,9 @@
     pDoc.write("     msgchk += \\"newmsg\\"+usrctr;");
     pDoc.write("     includemsg = 1;");
     pDoc.write("  }");
-    pDoc.write("  imgformname = eval(\\"opener.document.SCORE.mailicon\\"+usrctr);");
+    pDoc.write("  imgformname = opener.document.SCORE[\\"mailicon\\"+usrctr];");
     pDoc.write("  imgformname.src = \\"$iconpath/\\"+((includemsg) ? \\"mailto.gif\\" : \\"mailbkgrd.gif\\");");
-    pDoc.write("  var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
+    pDoc.write("  var includemsg = opener.document.SCORE[\\"includemsg\\"+usrctr];");
     pDoc.write("  includemsg.value = msgchk;");
 
     pDoc.write("  self.close()");
@@ -1165,11 +1167,12 @@
 	'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
     if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
 	$result.='<option> </option>'.
-	    '<option selected="on">excused</option></select>'."\n";
+	    '<option selected="on">excused</option>';
     } else {
 	$result.='<option selected="on"> </option>'.
-	    '<option>excused</option></select>'."\n";
+	    '<option>excused</option>';
     }
+    $result.='<option>reset status</option></select>'."\n";
     $result.="&nbsp&nbsp\n";
     $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
 	'<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
@@ -1340,7 +1343,8 @@
 	$request->print(&show_problem($request,$symb,$uname,$udom,1,1));
     }
     my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
-    my ($partlist,$handgrade) = &response_type($url);
+
+    my ($partlist,$handgrade) = &response_type($url,$symb);
 
     # Display student info
     $request->print(($counter == 0 ? '' : '<br />'));
@@ -1438,7 +1442,8 @@
 		    if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) {
 			$lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
 			    $partid.'</b> <font color="#999999">( ID '.$respid.
-			    ' )</font>&nbsp; &nbsp;Nothing submitted - no attempts<br /><br />';
+			    ' )</font>&nbsp; &nbsp;'.
+			    '<font color="red">Nothing submitted - no attempts</font><br /><br />';
  		    } else {
 			foreach (@$string) {
 			    my ($partid,$respid) = /^resource\.(\w+)\.(\w+)\.submission/;
@@ -1465,7 +1470,6 @@
 				     'this file may contain virusses</font><br />':'').
 				     '<b>Submitted Answer: </b>'.($responsetype =~ /^(essay|option)$/ ? 
 								  '<blockquote>' : '').
-#				     &cleanRecord(&keywords_highlight($subval),$responsetype).
 				     &cleanRecord($subval,$responsetype,$symb).
 				     ($responsetype =~ /^(essay|option)$/ ? '</blockquote><br />' : 
 				      '<br /><br />').$similar."\n"
@@ -1596,7 +1600,7 @@
 	    }
 	}
     }
-    @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
+    @string = $string[0] eq '' ? '<font color="red">Nothing submitted - no attempts.</font>' : @string;
     return \@string,\$timestamp;
 }
 
@@ -1766,7 +1770,7 @@
 	}
     }
     $ctr = 0;
-    my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
+    my ($partlist,$handgrade) = &response_type($ENV{'form.url'},$symb);
     @parsedlist = reverse @parsedlist if ($button eq 'Previous');
     foreach my $student (@parsedlist) {
 	my ($uname,$udom) = split(/:/,$student);
@@ -1815,14 +1819,23 @@
     my %newrecord  = ();
     my ($pts,$wgt) = ('','');
     foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
-	if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
+	my $dropMenu = $ENV{'form.GD_SEL'.$newflg.'_'.$_};
+	if ($dropMenu eq 'excused') {
 	    if ($record{'resource.'.$_.'.solved'} ne 'excused') {
 		$newrecord{'resource.'.$_.'.solved'} = 'excused';
 		if (exists($record{'resource.'.$_.'.awarded'})) {
 		    $newrecord{'resource.'.$_.'.awarded'} = '';
 		}
+	    $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
 	    }
-	} else {
+	} elsif ($dropMenu eq 'reset status'
+		 && exists($record{'resource.'.$_.'.solved'})) { #don't bother if no old records -> no attempts
+	    $newrecord{'resource.'.$_.'.tries'} = 0;
+	    $newrecord{'resource.'.$_.'.solved'} = '';
+	    $newrecord{'resource.'.$_.'.award'} = '';
+	    $newrecord{'resource.'.$_.'.awarded'} = 0;
+	    $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
+	} elsif ($dropMenu eq '') {
 	    $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ? 
 		    $ENV{'form.GD_BOX'.$newflg.'_'.$_} : 
 		    $ENV{'form.RADVAL'.$newflg.'_'.$_});
@@ -1865,10 +1878,10 @@
     $request->print(<<VIEWJAVASCRIPT);
 <script type="text/javascript" language="javascript">
    function writePoint(partid,weight,point) {
-	var radioButton = eval("document.classgrade.RADVAL_"+partid);
-	var textbox = eval("document.classgrade.TEXTVAL_"+partid);
+	var radioButton = document.classgrade["RADVAL_"+partid];
+	var textbox = document.classgrade["TEXTVAL_"+partid];
 	if (point == "textval") {
-	    var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
+	    point = document.classgrade["TEXTVAL_"+partid].value;
 	    if (isNaN(point) || parseFloat(point) < 0) {
 		alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
 		var resetbox = false;
@@ -1899,15 +1912,13 @@
 	    }
 
 	} else {
-	    textbox.value = point;
+	    textbox.value = parseFloat(point);
 	}
 	for (i=0;i<document.classgrade.total.value;i++) {
-	    var user = eval("document.classgrade.ctr"+i+".value");
-	    var scorename = eval("document.classgrade.GD_"+user+
-				 "_"+partid+"_awarded");
-	    var saveval   = eval("document.classgrade.GD_"+user+
-				 "_"+partid+"_solved_s.value");
-	    var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
+	    var user = document.classgrade["ctr"+i].value;
+	    var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
+	    var saveval   = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
+	    var selname   = document.classgrade["GD_"+user+"_"+partid+"_solved"];
 	    if (saveval != "correct") {
 		scorename.value = point;
 		if (selname[0].selected != true) {
@@ -1915,15 +1926,14 @@
 		}
 	    }
 	}
-	var selval   = eval("document.classgrade.SELVAL_"+partid);
-	selval[0].selected = true;
+	document.classgrade["SELVAL_"+partid][0].selected = true;
     }
 
     function writeRadText(partid,weight) {
-	var selval   = eval("document.classgrade.SELVAL_"+partid);
-	var radioButton = eval("document.classgrade.RADVAL_"+partid);
-	var textbox = eval("document.classgrade.TEXTVAL_"+partid);
-	if (selval[1].selected) {
+	var selval   = document.classgrade["SELVAL_"+partid];
+	var radioButton = document.classgrade["RADVAL_"+partid];
+	var textbox = document.classgrade["TEXTVAL_"+partid];
+	if (selval[1].selected || selval[2].selected) {
 	    for (var i=0; i<radioButton.length; i++) {
 		radioButton[i].checked=false;
 
@@ -1931,30 +1941,29 @@
 	    textbox.value = "";
 
 	    for (i=0;i<document.classgrade.total.value;i++) {
-		var user = eval("document.classgrade.ctr"+i+".value");
-		var scorename = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_awarded");
-		var saveval   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_solved_s.value");
-		var selname   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_solved");
+		var user = document.classgrade["ctr"+i].value;
+		var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
+		var saveval   = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
+		var selname   = document.classgrade["GD_"+user+"_"+partid+"_solved"];
 		if (saveval != "correct") {
 		    scorename.value = "";
-		    selname[1].selected = true;
+		    if (selval[1].selected) {
+			selname[1].selected = true;
+		    } else {
+			selname[2].selected = true;
+			if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value)) 
+			{document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
+		    }
 		}
 	    }
 	} else {
 	    for (i=0;i<document.classgrade.total.value;i++) {
-		var user = eval("document.classgrade.ctr"+i+".value");
-		var scorename = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_awarded");
-		var saveval   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_solved_s.value");
-		var selname   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_solved");
+		var user = document.classgrade["ctr"+i].value;
+		var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
+		var saveval   = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
+		var selname   = document.classgrade["GD_"+user+"_"+partid+"_solved"];
 		if (saveval != "correct") {
-		    scorename.value = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_awarded_s.value");;
+		    scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
 		    selname[0].selected = true;
 		}
 	    }
@@ -1962,10 +1971,10 @@
     }
 
     function changeSelect(partid,user) {
-	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
-	var textbox = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
+	var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
+	var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
 	var point  = textbox.value;
-	var weight = eval("document.classgrade.weight_"+partid+".value");
+	var weight = document.classgrade["weight_"+partid].value;
 
 	if (isNaN(point) || parseFloat(point) < 0) {
 	    alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
@@ -1984,19 +1993,21 @@
     }
 
     function changeOneScore(partid,user) {
-	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
-	if (selval[1].selected) {
-	    var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
-	    boxval.value = "";
+	var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
+	if (selval[1].selected || selval[2].selected) {
+	    document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
+	    if (selval[2].selected) {
+		document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
+	    }
 	}
     }
 
     function resetEntry(numpart) {
 	for (ctpart=0;ctpart<numpart;ctpart++) {
-	    var partid = eval("document.classgrade.partid_"+ctpart+".value");
-	    var radioButton = eval("document.classgrade.RADVAL_"+partid);
-	    var textbox = eval("document.classgrade.TEXTVAL_"+partid);
-	    var selval  = eval("document.classgrade.SELVAL_"+partid);
+	    var partid = document.classgrade["partid_"+ctpart].value;
+	    var radioButton = document.classgrade["RADVAL_"+partid];
+	    var textbox = document.classgrade["TEXTVAL_"+partid];
+	    var selval  = document.classgrade["SELVAL_"+partid];
 	    for (var i=0; i<radioButton.length; i++) {
 		radioButton[i].checked=false;
 
@@ -2005,16 +2016,13 @@
 	    selval[0].selected = true;
 
 	    for (i=0;i<document.classgrade.total.value;i++) {
-		var user = eval("document.classgrade.ctr"+i+".value");
-		var resetscore = eval("document.classgrade.GD_"+user+
-				      "_"+partid+"_awarded");
-		resetscore.value = eval("document.classgrade.GD_"+user+
-					"_"+partid+"_awarded_s.value");
-
-		var saveselval   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_solved_s.value");
-
-		var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
+		var user = document.classgrade["ctr"+i].value;
+		var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
+		resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
+		var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
+		resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
+		var saveselval   = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
+		var selname   = document.classgrade["GD_"+user+"_"+partid+"_solved"];
 		if (saveselval == "excused") {
 		    if (selname[1].selected == false) { selname[1].selected = true;}
 		} else {
@@ -2048,6 +2056,7 @@
 	'<input type="hidden" name="command" value="editgrades" />'."\n".
 	'<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n".
 	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
+	'<input type="hidden" name="Status" value="'.$ENV{'form.Status'}.'" />'."\n".
 	'<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
 
     $result.='<h3>Assign Common Grade To ';
@@ -2062,7 +2071,7 @@
 	'<table border=0><tr bgcolor="#ffffdd"><td>';
     #radio buttons/text box for assigning points for a section or class.
     #handles different parts of a problem
-    my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
+    my ($partlist,$handgrade) = &response_type($url,$symb);
     my %weight = ();
     my $ctsparts = 0;
     $result.='<table border="0">';
@@ -2098,7 +2107,9 @@
 	    'onChange="javascript:writeRadText(\''.$partid.'\','.
 		$weight{$partid}.')"> '.
 	    '<option selected="on"> </option>'.
-	    '<option>excused</option></select></td></tr>'."\n";
+#	    '<option>excused</option></select></td></tr>'."\n";
+	    '<option>excused</option>'.
+	    '<option>reset status</option></select></td></tr>'."\n";
 	$ctsparts++;
     }
     $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
@@ -2189,10 +2200,13 @@
 	    $result.='<td align="middle"><select name="'.
 		'GD_'.$student.'_'.$part.'_solved" '.
 		'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
-	    my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
-	    $optsel = '<option> </option><option selected="on">excused</option>'."\n"
-		if ($status eq 'excused');
-	    $result.=$optsel;
+#	    my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
+#	    $optsel = '<option> </option><option selected="on">excused</option>'."\n"
+#		if ($status eq 'excused');
+#	    $result.=$optsel;
+	    $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>' 
+		: '<option selected="on"> </option><option>excused</option>')."\n";
+	    $result.='<option>reset status</option>';
 	    $result.="</select></td>\n";
 	} else {
 	    $result.='<input type="hidden" name="'.
@@ -2253,8 +2267,9 @@
 	    if ($type eq 'awarded' || $type eq 'solved') { next; }
 	    my $display=&Apache::lonnet::metadata($url,$stores.'.display');
 	    $display =~ s/\[Part: (\w)+\]//;
-	    $header .= '<td align="center">&nbsp;<b>Old</b> '.$display.'&nbsp;</td>'.
-		'<td align="center">&nbsp;<b>New</b> '.$display.'&nbsp;</td>';
+	    $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>';
 	    $columns{$partid}+=2;
 	}
     }
@@ -2302,8 +2317,20 @@
 	    } elsif ($partial == 0) {
 		$score = 'incorrect_by_override';
 	    }
-	    $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
-				   ($score ne 'excused'));
+	    my $dropMenu = $ENV{'form.GD_'.$user.'_'.$_.'_solved'};
+	    $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
+
+	    if ($dropMenu eq 'reset status' &&
+		$old_score ne '') { # ignore if no previous attempts => nothing to reset
+		print "reset status<br>";
+		$newrecord{'resource.'.$_.'.tries'} = 0;
+		$newrecord{'resource.'.$_.'.solved'} = '';
+		$newrecord{'resource.'.$_.'.award'} = '';
+		$newrecord{'resource.'.$_.'.awarded'} = 0;
+		$newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
+		$updateflag = 1;
+	    }
+
 	    $line .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
 		'<td align="center">'.$awarded.
 		($score eq 'excused' ? $score : '').'&nbsp;</td>';
@@ -2347,7 +2374,7 @@
     }
     $result .= '</table></td></tr></table>'."\n".
 	&show_grading_menu_form ($symb,$url);
-    my $msg = '<b>Number of records updated = '.$rec_update.
+    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 />';
     return $title.$msg.$result;
@@ -2679,9 +2706,9 @@
 	alert("Please select the student you wish to grade.");
 	return;
     }
-    var ptr = pullDownSelection(formname.selectpage);
-    formname.page.value = eval("formname.page"+ptr+".value");
-    formname.title.value = eval("formname.title"+ptr+".value");
+    ptr = pullDownSelection(formname.selectpage);
+    formname.page.value = formname["page"+ptr].value;
+    formname.title.value = formname["title"+ptr].value;
     formname.submit();
 }
 
@@ -2761,7 +2788,7 @@
     $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" '.
+    $studentTable.='<br /><input type="button" '.
 	'onClick="javascript:checkPickOne(this.form);"value="Submit" /></form>'."\n";
 
     $studentTable.=&show_grading_menu_form($symb,$url);
@@ -2830,11 +2857,13 @@
 
     my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
 	'<input type="hidden" name="command" value="gradeByPage" />'."\n".
+	'<input type="hidden" name="fullname" value="'.$$fullname{$ENV{'form.student'}}.'" />'."\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".
 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
+	'<input type="hidden" name="overRideScore" value="no" />'."\n".
 	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
 
     my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
@@ -2877,6 +2906,7 @@
 	    }
 
 	    my %record = &Apache::lonnet::restore($symbx,$ENV{'request.course.id'},$udom,$uname);
+
 	    if ($ENV{'form.lastSub'} eq 'datesub') {
 		if ($record{'version'} eq '') {
 		    $studentTable.='<br />&nbsp;<font color="red">No recorded submission for this problem</font><br />';
@@ -2910,7 +2940,7 @@
     $navmap->untieHashes();
 
     $studentTable.='</td></tr></table></td></tr></table>'."\n".
-	'&nbsp;&nbsp;<input type="button" value="Save" '.
+	'<input type="button" value="Save" '.
 	'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
 	'</form>'."\n";
     $studentTable.=&show_grading_menu_form($symb,$url);
@@ -2976,7 +3006,7 @@
 	return;
     }
     my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
-    $result.='<h3>&nbsp;Student: '.$$fullname{$ENV{'form.student'}}.
+    $result.='<h3>&nbsp;Student: '.$ENV{'form.fullname'}.
 	'<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
 
     $request->print($result);
@@ -2991,7 +3021,7 @@
 
     my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
 	'<table border="0"><tr bgcolor="#e6ffff">'.
-	'<td align="center"><b>&nbsp;No&nbsp;</b></td>'.
+	'<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>';
@@ -3023,31 +3053,40 @@
 		my $score;
 		if ($partial > 0) {
 		    $score = 'correct_by_override';
-		} elsif ($partial == 0) {
+		} elsif ($newpts ne '') { #empty is taken as 0
 		    $score = 'incorrect_by_override';
 		}
-		if ($ENV{'form.GD_SEL'.$question.'_'.$partid} eq 'excused') {
+		my $dropMenu = $ENV{'form.GD_SEL'.$question.'_'.$partid};
+		if ($dropMenu eq 'excused') {
 		    $partial = '';
 		    $score = 'excused';
+		} elsif ($dropMenu eq 'reset status'
+			 && $ENV{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
+		    print "got to reset = $ENV{'form.solved'.$question.'_'.$partid}:<br>";
+		    $newrecord{'resource.'.$partid.'.tries'} = 0;
+		    $newrecord{'resource.'.$partid.'.solved'} = '';
+		    $newrecord{'resource.'.$partid.'.award'} = '';
+		    $newrecord{'resource.'.$partid.'.awarded'} = 0;
+		    $newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}";
+		    $changeflag++;
+		    $newpts = '';
 		}
+
 		my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid};
 		$displayPts[0].='&nbsp;<b>Part</b> '.$partid.' = '.
 		    (($oldstatus eq 'excused') ? 'excused' : $oldpts).
 		    '&nbsp;<br>';
 		$displayPts[1].='&nbsp;<b>Part</b> '.$partid.' = '.
-		    ($oldstatus eq 'correct_by_student' ? $oldpts :
-		     (($score eq 'excused') ? 'excused' : $newpts)).
+		     (($score eq 'excused') ? 'excused' : $newpts).
 		    '&nbsp;<br>';
 
 		$question++;
-		if (($oldstatus eq 'correct_by_student') ||
-		    ($newpts eq $oldpts && $score eq $oldstatus))
-		{
-		    next;
-		}
+		next if ($dropMenu eq 'reset status' || ($newpts == $oldpts && $score ne 'excused'));
+
 		$newrecord{'resource.'.$partid.'.awarded'}  = $partial if $partial ne '';
-		$newrecord{'resource.'.$partid.'.solved'}   = $score;
-		$newrecord{'resource.'.$partid.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
+		$newrecord{'resource.'.$partid.'.solved'}   = $score if $score ne '';
+		$newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}"
+		    if (scalar(keys(%newrecord)) > 0);
 
 		$changeflag++;
 	    }
@@ -3055,6 +3094,7 @@
 		&Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'},
 					$udom,$uname);
 	    }
+
 	    $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
 		'<td valign="top">'.$displayPts[1].'</td>'.
 		'</tr>';
@@ -3396,7 +3436,7 @@
 #--- Show a Grading Menu button - Calls the next routine ---
 sub show_grading_menu_form {
     my ($symb,$url)=@_;
-    my $result.='<form action="/adm/grades" method="post">'."\n".
+    my $result.='<br /><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="saveState"  value="'.$ENV{'form.saveState'}.'" />'."\n".

--ng1059165340--