--- loncom/homework/grades.pm	2006/02/27 21:23:52	1.322
+++ loncom/homework/grades.pm	2006/02/28 02:47:30	1.323
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.322 2006/02/27 21:23:52 albertel Exp $
+# $Id: grades.pm,v 1.323 2006/02/28 02:47:30 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1471,14 +1471,23 @@ sub gradeBox {
         '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
         $aggtries.'" />'."\n";
     $result.='</td></tr></table>'."\n";
-    $result.=&handback_box($uname,$udom,$counter,$partid,$record);
+    $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
     return $result;
 }
 
 sub handback_box {
-    my ($uname,$udom,$counter,$partid,$record) = @_;
+    my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
+    my ($map,$resid,$url) = &Apache::lonnet::decode_symb($symb);
+    my ($partlist,$handgrade,$responseType) = &response_type($url,$symb);
+    my (@respids);
+    foreach my $part_resp (sort(keys(%$handgrade))) {
+        my ($part,$resp) = split(/_/,$part_resp);
+        if ($part eq $partid) {
+            push @respids,$resp;
+        }
+    }
     my $result;
-    foreach my $respid (undef) {
+    foreach my $respid (@respids) {
 	my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
 	my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
 	next if (!@$files);
@@ -1487,8 +1496,8 @@ sub handback_box {
 	    my ($file_disp) = ($file =~ m|.+/(.+)$|);
 	    $result.=&mt('Return commented version of [_1] to student.',
 			 '<span class="filename">'.$file_disp.'</span>');
-	    $result.='<input type="file"   name="'.$prefix.'_returndoc'.$file_counter.'" />'."\n";
-	    $result.='<input type="hidden" name="'.$prefix.'_origdoc'.$file_counter.'" value="'.$file.'" /><br />';
+	    $result.='<input type="file"   name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
+	    $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
 	    $file_counter++;
 	}
     }
@@ -2317,19 +2326,18 @@ sub saveHandGrade {
 		"$env{'user.name'}:$env{'user.domain'}";
 	}
 	my ($partlist,$handgrade,$responseType) = &response_type($url,$symb);
-	my $portfolio_root = &Apache::loncommon::propath($domain,
-        					 $stuname).
-        					'/userfiles/portfolio';
 	foreach my $part_resp (sort(keys(%$handgrade))) {
 	    my ($part_id, $resp_id) = split(/_/,$part_resp);
-            if ($env{'form.'.$part_resp.'_returndoc1'} && ($new_part eq $part_id)) {
+	    &Apache::lonnet::logthis('form.'.$newflg.'_'.$part_resp.'_returndoc1');
+	    &Apache::lonnet::logthis("new part is $new_part and partid is $part_id");
+            if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
                 # if multiple files are uploaded names will be 'returndoc2','returndoc3'
                 my $file_counter = 1;
-                while ($env{'form.'.$part_resp.'_returndoc'.$file_counter}) {
-                    my $fname=$env{'form.returndoc'.$file_counter.'.filename'};
+                while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
+                    my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
                     $newrecord{"resource.$new_part.$resp_id.handback"} = $env{'form.returndocorig'.$file_counter};
                     $request->print("<br />".$fname." will be the uploaded file name");
-                    $request->print("<font color=\"red\">Will upload document</font>".$env{'form.returndocorig'.$file_counter});
+                    $request->print("<font color=\"red\">Will upload document</font>".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
                     $file_counter++;
                 }
             }