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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 07 Nov 2003 19:10:51 -0000


albertel		Fri Nov  7 14:10:51 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - fixes disfunctionalities in multipart problems with collaborators
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.149 loncom/homework/grades.pm:1.150
--- loncom/homework/grades.pm:1.149	Fri Nov  7 13:05:33 2003
+++ loncom/homework/grades.pm	Fri Nov  7 14:10:51 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.149 2003/11/07 18:05:33 albertel Exp $
+# $Id: grades.pm,v 1.150 2003/11/07 19:10:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -665,8 +665,9 @@
 		my ($foo,$partid,$foo1) = split(/\./,$_);
 		if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
 		    $submitted = 0;
+		    my ($part)=split(/\./,$partid);
 		    $gradeTable.='<input type="hidden" name="'.
-			$student.':submitted_by" value="'.
+			$student.':'.$part.':submitted_by" value="'.
 			$status{'resource.'.$partid.'.submitted_by'}.'" />';
 		}
 	    }
@@ -1532,8 +1533,10 @@
 		    $result.=$$fullname{$_}.'&nbsp; &nbsp; &nbsp;';
 		}
                 $result.='<br />'."\n";
+		my ($part)=split(/\./,$_);
 		$result.='<input type="hidden" name="collaborator'.$counter.
-		    '" value="'.(join ':',@goodcollaborators).'" />'."\n";
+		    '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
+		    "\n";
 	    }
 	    if (scalar(@badcollaborators) > 0) {
 		$result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
@@ -1559,15 +1562,6 @@
     #             (3) Last submission plus the parts info
     #             (4) The whole record for this student
     if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
-	if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
-	    my $submitby=''.
-		'<b>Collaborative submission by: </b>'.
-		'<a href="javascript:viewSubmitter(\''.
-		$ENV{'form.'.$uname.':'.$udom.':submitted_by'}.
-		'\')"; TARGET=_self>'.
-		$$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
-	    $request->print($submitby);
-	} else {
 	    my ($string,$timestamp)= &get_last_submission(\%record);
 	    my $lastsubonly=''.
 		($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
@@ -1575,8 +1569,21 @@
 	    if ($$timestamp eq '') {
 		$lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0]; 
 	    } else {
+		my %seenparts;
 		for my $part (sort keys(%$handgrade)) {
 		    my ($partid,$respid) = split(/_/,$part);
+		    if ($ENV{"form.$uname:$udom:$partid:submitted_by"}) {
+			if (exists($seenparts{$partid})) { next; }
+			$seenparts{$partid}=1;
+			my $submitby='<b>Part '.$partid.
+			    ' Collaborative submission by: </b>'.
+			    '<a href="javascript:viewSubmitter(\''.
+			    $ENV{"form.$uname:$udom:$partid:submitted_by"}.
+			    '\')"; TARGET=_self>'.
+			    $$fullname{$ENV{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
+			$request->print($submitby);
+			next;
+		    }
 		    my $responsetype = $responseType->{$partid}->{$respid};
 		    if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) {
 			$lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
@@ -1628,7 +1635,6 @@
 	    }
 	    $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
 	    $request->print($lastsubonly);
-	}
     } elsif ($ENV{'form.lastSub'} eq 'datesub') {
 	my (undef,$responseType,undef,$parts) = &showResourceInfo($url);
 	$request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
@@ -1804,18 +1810,27 @@
 							       $ENV{'form.msgsub'},$message);
 	    }
 	    if ($ENV{'form.collaborator'.$ctr}) {
-		my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
-		foreach (@collaborators) {
-		    my ($errorflag,$pts,$wgt) = 
-			&saveHandGrade($request,$url,$symb,$_,$udom,$ctr,$ENV{'form.unamedom'.$ctr});
-		    if ($errorflag eq 'not_allowed') {
-			$request->print("<font color=\"red\">Not allowed to modify grades for $_:$udom</font>");
-			next;
-		    } else {
-			if ($message ne '') {
-			    $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
-									   $ENV{'form.msgsub'},
-									   $message);
+		&Apache::lonnet::logthis('collab '.(join(':',@{ $ENV{'form.collaborator'.$ctr} })));
+		my @collabstrs;
+		if (ref($ENV{'form.collaborator'.$ctr}) eq 'ARRAY') {
+		    @collabstrs=@{$ENV{'form.collaborator'.$ctr}};
+		} else {
+		    @collabstrs=$ENV{'form.collaborator'.$ctr};
+		}
+		foreach my $collabstr (@collabstrs) {
+		    my ($part,@collaborators) = split(/:/,$collabstr);
+		    foreach (@collaborators) {
+			my ($errorflag,$pts,$wgt) = 
+			    &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
+					   $ENV{'form.unamedom'.$ctr},$part);
+			if ($errorflag eq 'not_allowed') {
+			    $request->print("<font color=\"red\">Not allowed to modify grades for $_:$udom</font>");
+			    next;
+			} else {
+			    if ($message ne '') {
+				$msgstatus = &Apache::lonmsg::user_normal_msg($_,$udom,$ENV{'form.msgsub'},$message);
+			    }
+			    
 			}
 		    }
 		}
@@ -1967,7 +1982,7 @@
 
 #---- Save the score and award for each student, if changed
 sub saveHandGrade {
-    my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
+    my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
     my $usec = &Apache::lonnet::getsection($domain,$stuname,
 					   $ENV{'request.course.id'});
     if (!&canmodify($usec)) { return('not_allowed'); }
@@ -1975,6 +1990,9 @@
     my %newrecord  = ();
     my ($pts,$wgt) = ('','');
     foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
+	&Apache::lonnet::logthis("-$submitter-$stuname-$part-$_");
+	#collaborator may vary for different parts
+	if ($submitter && $_ ne $part) { next; }
 	my $dropMenu = $ENV{'form.GD_SEL'.$newflg.'_'.$_};
 	if ($dropMenu eq 'excused') {
 	    if ($record{'resource.'.$_.'.solved'} ne 'excused') {
@@ -2010,6 +2028,7 @@
 		$newrecord{$reckey} = 'correct_by_override' 
 		    if ($record{$reckey} ne 'correct_by_override');
 	    }
+	    
 	    $newrecord{'resource.'.$_.'.submitted_by'} = $submitter 
 		if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
 	    $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
@@ -3925,6 +3944,11 @@
 #remotewindow.close();
 #</script>"); 
     $request->print(&Apache::loncommon::bodytag('Grading'));
+    foreach my $key (sort(keys(%ENV))) {
+	if ($key =~ /^form\./) {
+	    Apache->request->print("$key => $ENV{$key} <br />");
+	}
+    }
 }
 
 sub send_footer {