--- loncom/homework/grades.pm	2005/06/03 18:23:19	1.269
+++ loncom/homework/grades.pm	2005/06/04 02:56:44	1.270
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.269 2005/06/03 18:23:19 raeburn Exp $
+# $Id: grades.pm,v 1.270 2005/06/04 02:56:44 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1352,15 +1352,14 @@ sub gradeBox {
     my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
 
     my $display_part=&get_display_part($partid,undef,$symb);
-    my @partids = ("$partid");
-    my %last_resets = ();
-    &get_last_resets($symb,$env{'request.course.id'},\%last_resets,\@partids);
-    my $aggtries;
+
+    my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+				       [$partid]);
+    my $aggtries = $$record{'resource.'.$partid.'.tries'};
     if ($last_resets{$partid}) {
         $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
-    } else {
-        $aggtries = $$record{'resource.'.$partid.'.tries'};
     }
+
     $result.='<table border="0"><tr><td>'.
 	'<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n";
 
@@ -2156,17 +2155,17 @@ sub saveHandGrade {
 	    }
 	    $newrecord{'resource.'.$new_part.'.regrader'}=
 		"$env{'user.name'}:$env{'user.domain'}";
-            my @partids = ("$new_part");
-            my %last_resets = ();
-            &get_last_resets($symb,$env{'request.course.id'},\%last_resets,\@partids);
-            my ($totaltries,$aggtries,$solvedstatus);
-            $totaltries = $record{'resource.'.$part.'.tries'};
+            my $totaltries = $record{'resource.'.$part.'.tries'};
+
+            my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+					       [$new_part]);
+            my $aggtries =$totaltries;
             if ($last_resets{$new_part}) {
-                $aggtries = &get_num_tries(\%record,$last_resets{$new_part},$new_part);
-            } else {
-                $aggtries = $totaltries;
+                $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
+					   $new_part);
             }
-            $solvedstatus = $record{'resource.'.$new_part.'.solved'};
+
+            my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
             if ($aggtries > 0) {
                 &decrement($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
                 $aggregateflag = 1;
@@ -2270,22 +2269,24 @@ sub decrement_aggs {
 
 # ----------- Determine timestamps for last reset of aggregate totals for parts  
 sub get_last_resets {
-    my ($symb,$courseid,$last_resets,$partids) =@_;
+    my ($symb,$courseid,$partids) =@_;
+    my %last_resets;
     my $cdom = $env{'course.'.$courseid.'.domain'};
     my $cname = $env{'course.'.$courseid.'.num'};
-    my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',$cdom,$cname);
+    my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',
+					     $cdom,$cname);
     if ($resethash{'version'}) {
         foreach my $part (@{$partids}) {
-            $$last_resets{$part} = '';
+            $last_resets{$part} = '';
             for (my $version=$resethash{'version'};$version>=1;$version--) {
                 if (exists($resethash{$version.':'.$part."\0".'prev_attempts'})) {
-                    $$last_resets{$part} = $resethash{$version.':timestamp'};
+                    $last_resets{$part} = $resethash{$version.':timestamp'};
                     last;
                 }
             }
         }
     }
-    return;
+    return %last_resets;
 }
 
 # ----------- Handles creating versions for portfolio files as answers
@@ -2630,9 +2631,8 @@ sub viewgrades {
     }
     $result.='</tr>';
 
-    # retrieve last reset information
-    my %last_resets = ();
-    &get_last_resets($symb,$env{'request.course.id'},\%last_resets,\@partids);
+    my %last_resets = 
+	&get_last_resets($symb,$env{'request.course.id'},\@partids);
 
     #get info for each student
     #list all the students - with points and grade status
@@ -2675,12 +2675,13 @@ sub viewstudentgrade {
         $result.='<td align="middle">';
         my ($aggtries,$totaltries);
         unless (exists($aggregates{$part})) {
-            $totaltries = $record{'resource.'.$part.'.tries'};
+	    $totaltries = $record{'resource.'.$part.'.tries'};
+
+	    $aggtries = $totaltries;
             if ($$last_resets{$part}) {  
-                $aggtries = &get_num_tries(\%record,$$last_resets{$part},$part);
-            } else {
-                $aggtries = $totaltries;
-            } 
+                $aggtries = &get_num_tries(\%record,$$last_resets{$part},
+					   $part);
+            }
             $result.='<input type="hidden" name="'.
                 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
             $result.='<input type="hidden" name="'.