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

raeburn raeburn@source.lon-capa.org
Sun, 28 Feb 2010 23:31:42 -0000


This is a MIME encoded message

--raeburn1267399902
Content-Type: text/plain

raeburn		Sun Feb 28 23:31:42 2010 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - Bug 6119 Anonymous Survey.
    - course personnel can not view both identity of submitter and submission details.
  
  
--raeburn1267399902
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100228233142.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.595 loncom/homework/grades.pm:1.596
--- loncom/homework/grades.pm:1.595	Mon Feb 22 23:08:16 2010
+++ loncom/homework/grades.pm	Sun Feb 28 23:31:42 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.595 2010/02/22 23:08:16 raeburn Exp $
+# $Id: grades.pm,v 1.596 2010/02/28 23:31:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2212,7 +2212,7 @@
 		foreach my $submission (@$string) {
 		    my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
 		    if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
-		    my ($ressub,$subval) = split(/:/,$submission,2);
+		    my ($ressub,$hide,$subval) = split(/:/,$submission,3);
 		    # Similarity check
 		    my $similar='';
 		    if($env{'form.checkPlag'}){
@@ -2224,16 +2224,21 @@
 				&Apache::lonnet::coursedescription($ocrsid,
 								   {'one_time' => 1});
 
-			    $similar="<hr /><h3><span class=\"LC_warning\">".
-				&mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
-				    $osim,
-				    &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
-				    $old_course_desc{'description'},
-				    $old_course_desc{'num'},
-				    $old_course_desc{'domain'}).
-				'</span></h3><blockquote><i>'.
-				&keywords_highlight($oessay).
-				'</i></blockquote><hr />';
+                            if ($hide) {
+                                $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
+                                         &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
+                            } else {
+			        $similar="<hr /><h3><span class=\"LC_warning\">".
+				    &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
+				        $osim,
+				        &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
+				        $old_course_desc{'description'},
+				        $old_course_desc{'num'},
+				        $old_course_desc{'domain'}).
+				    '</span></h3><blockquote><i>'.
+				    &keywords_highlight($oessay).
+				    '</i></blockquote><hr />';
+                            }
 			}
 		    }
 		    my $order=&get_order($partid,$respid,$symb,$uname,$udom);
@@ -2248,18 +2253,24 @@
                             '</b></span>&nbsp; &nbsp;';
 			my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
 			if (@$files) {
-			    $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
-			    my $file_counter = 0;
-			    foreach my $file (@$files) {
-			        $file_counter++;
-				&Apache::lonnet::allowuploaded('/adm/grades',$file);
-				$lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
-			    }
+                            if ($hide) {
+                                $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
+                            } else {
+                                $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
+                                foreach my $file (@$files) {
+                                    &Apache::lonnet::allowuploaded('/adm/grades',$file);
+                                    $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
+                                }
+                            }
 			    $lastsubonly.='<br />';
 			}
-			$lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
-			    &cleanRecord($subval,$responsetype,$symb,$partid,
-					 $respid,\%record,$order,undef,$uname,$udom);
+                        if ($hide) {
+                            $lastsubonly.='<b>'.&mt('Anonymous Survey').'</b>'; 
+                        } else {
+			    $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
+			        &cleanRecord($subval,$responsetype,$symb,$partid,
+					     $respid,\%record,$order,undef,$uname,$udom);
+                        }
 			if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
 			$lastsubonly.='</div>';
 		    }
@@ -2454,7 +2465,7 @@
 #--- Retrieve the last submission for all the parts
 sub get_last_submission {
     my ($returnhash)=@_;
-    my (@string,$timestamp);
+    my (@string,$timestamp,%lasthidden);
     if ($$returnhash{'version'}) {
 	my %lasthash=();
 	my ($version);
@@ -2466,13 +2477,39 @@
 		    &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
 	    }
 	}
+        my %typeparts;
+        my $showsurv = 
+            &Apache::lonnet::allowed('vas',$env{'request.course.id'});
+        foreach my $key (sort(keys(%lasthash))) {
+            if ($key =~ /\.type$/) {
+                if (($lasthash{$key} eq 'anonsurvey') || 
+                    ($lasthash{$key} eq 'anonsurveycred')) {
+                    my ($ign,@parts) = split(/\./,$key);
+                    pop(@parts);
+                    unless ($showsurv) {
+                        my $id = join(',',@parts);
+                        $typeparts{$ign.'.'.$id} = $lasthash{$key};
+                    }
+                    delete($lasthash{$key});
+                }
+            }
+        }
+        my @hidden = keys(%typeparts);
 	foreach my $key (keys(%lasthash)) {
 	    next if ($key !~ /\.submission$/);
-
+            my $hide;
+            if (@hidden) {
+                foreach my $id (@hidden) {
+                    if ($key =~ /^\Q$id\E/) {
+                        $hide = 1;
+                        last;
+                    }
+                }
+            }
 	    my ($partid,$foo) = split(/submission$/,$key);
 	    my $draft  = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
 		'<span class="LC_warning">Draft Copy</span> ' : '';
-	    push(@string, join(':', $key, $draft.$lasthash{$key}));
+	    push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
 	}
     }
     if (!@string) {
@@ -3561,6 +3598,7 @@
 		    'incorrect'=>'incorrect_by_override',
 		    'excused'  =>'excused',
 		    'ungraded' =>'ungraded_attempted',
+                    'credited' =>'credit_attempted',
 		    'nothing'  => '',
 		    );
     my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
@@ -4590,16 +4628,20 @@
 	my @versionKeys = split(/\:/,$$record{$version.':keys'});
 	my @displaySub = ();
 	foreach my $partid (@{$parts}) {
+            my $hidden;
+            if (($$record{$version.':resource.'.$partid.'.type'} eq 'anonsurvey') ||
+                ($$record{$version.':resource.'.$partid.'.type'} eq 'anonsurveycred')) {
+                $hidden = 1;
+            }
 	    my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
 			            : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
 	    
-
 #	    next if ($$record{"$version:resource.$partid.solved"} eq '');
 	    my $display_part=&get_display_part($partid,$symb);
 	    foreach my $matchKey (@matchKey) {
 		if (exists($$record{$version.':'.$matchKey}) &&
 		    $$record{$version.':'.$matchKey} ne '') {
-
+                    
 		    my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
 				               : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
                     $displaySub[0].='<span class="LC_nobreak"';
@@ -4608,23 +4650,27 @@
                                    .'('.&mt('Part ID: [_1]',$responseId).')'
                                    .'</span>'
                                    .' <b>';
-		    if ($$record{"$where.$partid.tries"} eq '') {
-			$displaySub[0].=&mt('Trial not counted');
-		    } else {
-			$displaySub[0].=&mt('Trial: [_1]',
+                    if ($hidden) {
+                        $displaySub[0].= &mt('Anonymous Survey').'</b>';
+                    } else {
+		        if ($$record{"$where.$partid.tries"} eq '') {
+			    $displaySub[0].=&mt('Trial not counted');
+		        } else {
+			    $displaySub[0].=&mt('Trial: [_1]',
 					    $$record{"$where.$partid.tries"});
-		    }
-		    my $responseType=($isTask ? 'Task'
+		        }
+		        my $responseType=($isTask ? 'Task'
                                               : $responseType->{$partid}->{$responseId});
-		    if (!exists($orders{$partid})) { $orders{$partid}={}; }
-		    if (!exists($orders{$partid}->{$responseId})) {
-			$orders{$partid}->{$responseId}=
-			    &get_order($partid,$responseId,$symb,$uname,$udom,
-                                       $no_increment);
-		    }
-		    $displaySub[0].='</b></span>'; # /nobreak
-		    $displaySub[0].='&nbsp; '.
-			&cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
+		        if (!exists($orders{$partid})) { $orders{$partid}={}; }
+		        if (!exists($orders{$partid}->{$responseId})) {
+			    $orders{$partid}->{$responseId}=
+			        &get_order($partid,$responseId,$symb,$uname,$udom,
+                                           $no_increment);
+		        }
+		        $displaySub[0].='</b></span>'; # /nobreak
+		        $displaySub[0].='&nbsp; '.
+			    &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
+                    }
 		}
 	    }
 	    if (exists($$record{"$where.$partid.checkedin"})) {

--raeburn1267399902--