--- loncom/homework/response.pm	2011/09/13 21:42:58	1.226
+++ loncom/homework/response.pm	2011/11/14 03:08:01	1.227
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.226 2011/09/13 21:42:58 raeburn Exp $
+# $Id: response.pm,v 1.227 2011/11/14 03:08:01 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -494,8 +494,8 @@ sub end_customresponse {
     }
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || 
 	$target eq 'tex' || $target eq 'analyze') {
-	&Apache::lonxml::increment_counter(&Apache::response::repetition(),
-					   "$part.$id");
+        my $repetition = &repetition();
+	&Apache::lonxml::increment_counter($repetition,"$part.$id");
 	if ($target eq 'analyze') {
             $Apache::lonhomework::analyze{"$part.$id.type"} = 'customresponse';
 	    &Apache::lonhomework::set_bubble_lines();
@@ -1034,12 +1034,18 @@ sub getresponse {
 
 =item &repetition();
 
-Returns the number of lines that are required to encode the weight.
+In scalar context:
+
+returns: the number of lines that are required to encode the weight.
 (Default is for 10 bubbles per bubblesheet item; other (integer) 
 values can be specified by using a custom Bubblesheet format file 
 with an eighteenth entry (BubblesPerRow) set to the integer 
 appropriate for the bubblesheets which will be used to assign weights.
 
+In array context:
+ 
+returns: number of lines required to encode weight, and bubbles/line.
+
 =cut
 
 sub repetition {
@@ -1053,9 +1059,18 @@ sub repetition {
     } else {
         $bubbles_per_row = 10;
     }
-    my $repetition = int($weight/$bubbles_per_row);
-    if ($weight % $bubbles_per_row != 0) { $repetition++; } 
+    my $denominator = $bubbles_per_row;
+    if (($env{'form.scantron_lastbubblepoints'} == 0) && 
+        ($bubbles_per_row > 1)) {
+        $denominator = $bubbles_per_row - 1;
+    } 
+    my $repetition = int($weight/$denominator);
+    if ($weight % $denominator != 0) { $repetition++; } 
+    if (wantarray) {
+        return ($repetition,$bubbles_per_row);
+    }
     return $repetition;
+
 }
 
 =pod
@@ -1085,11 +1100,24 @@ Arguments
 sub scored_response {
     my ($part,$id)=@_;
     my $repetition=&repetition();
+    my $bubbles_per_row;
+    if (($env{'form.bubbles_per_row'} =~ /^\d+$/) &&
+        ($env{'form.bubbles_per_row'} > 0)) {
+        $bubbles_per_row = $env{'form.bubbles_per_row'};
+    } else {
+        $bubbles_per_row = 10;
+    }
     my $score=0;
     for (my $i=0;$i<$repetition;$i++) {
-	# A is 1, B is 2, etc. (get response return 0-9 and then we add 1)
+	# A is 1, B is 2, etc.
 	my $increase=&Apache::response::getresponse($i+1);
-	if ($increase ne '') { $score+=$increase+1; }
+        unless (($increase == $bubbles_per_row-1) &&
+                ($env{'form.scantron_lastbubblepoints'} == 0)) {
+            # (get response return 0-9 and then we add 1)
+            if ($increase ne '') {
+                $score+=$increase+1;
+            }
+        }
     }
     my $weight = &Apache::lonnet::EXT("resource.$part.weight");
     if (!defined($weight) || $weight eq '' || $weight eq 0) { $weight = 1; }