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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 09 Mar 2006 00:41:24 -0000


albertel		Wed Mar  8 19:41:24 2006 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
    /loncom/homework	inputtags.pm 
  Log:
  - centralizign the printed/ionline exam box generation
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.187 loncom/homework/caparesponse/caparesponse.pm:1.188
--- loncom/homework/caparesponse/caparesponse.pm:1.187	Mon Feb  6 18:02:50 2006
+++ loncom/homework/caparesponse/caparesponse.pm	Wed Mar  8 19:41:13 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.187 2006/02/06 23:02:50 albertel Exp $
+# $Id: caparesponse.pm,v 1.188 2006/03/09 00:41:13 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -362,10 +362,6 @@
 			    $bubble_display->[$ind].'</td>';
 		    }
 		    $result.='</tr></table>';
-		} elsif ($tag eq 'formularesponse') {
-		    $result.= '<br /><br /><font color="red">
-                           <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
-                           </textarea></font> <br /><br />';
 		}
 	    } elsif ($target eq 'tex') {
 		if ((defined $unit) and ($unit=~/\S/) and ($Apache::lonhomework::type eq 'exam')) {
@@ -393,14 +389,7 @@
 		    }
 		    $result.='\end{enumerate}';
 		} else {
-		    $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
-		    my $repetition = &Apache::response::repetition();
-		    $result.='\begin{enumerate}';
-		    for (my $i=0;$i<$repetition;$i++) {
-			$result.='\item[\textbf{'.($Apache::lonxml::counter+$i).'}.]\textit{Leave blank on scoring form}\vskip 0 mm';
-		    }
-		    $increment=$repetition;
-		    $result.= '\end{enumerate}';
+		    $increment = &Apache::response::repetition();
 		}
 	    }
 	}
@@ -856,19 +845,6 @@
 		$Apache::lonhomework::results{"resource.$part.$id.awardmsg"}=$msg;
 	    }
 	}
-    } elsif ($target eq 'web' || $target eq 'tex') {
-	my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
-	my $status = $Apache::inputtags::status['-1'];
-	if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') {
-	    $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
-	    $increment = &Apache::response::repetition();
-	    $result.='\begin{enumerate}';
-	    for (my $i=0;$i<$increment;$i++) {
-		$result.='\item[\textbf{'.($Apache::lonxml::counter+$i).
-		    '}.]\textit{Leave blank on scoring form}\vskip 0 mm';
-	    }
-	    $result.= '\end{enumerate}';
-	}
     } elsif ($target eq 'answer' || $target eq 'analyze') {
 	if ($target eq 'analyze') {
 	    push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.187 loncom/homework/inputtags.pm:1.188
--- loncom/homework/inputtags.pm:1.187	Tue Feb 21 17:41:29 2006
+++ loncom/homework/inputtags.pm	Wed Mar  8 19:41:24 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.187 2006/02/21 22:41:29 albertel Exp $
+# $Id: inputtags.pm,v 1.188 2006/03/09 00:41:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -222,6 +222,47 @@
     return $result;
 }
 
+sub exam_box {
+    my ($target) = @_;
+    my $result;
+
+    if ($target eq 'tex') {
+	$result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
+	my $repetition = &Apache::response::repetition();
+	$result.='\begin{enumerate}';
+	foreach my $i (0..$repetition-1) {
+	    $result.='\item[\textbf{'.
+		($Apache::lonxml::counter+$i).
+		'}.]\textit{Leave blank on scoring form}\vskip 0 mm';
+	}
+	$result.= '\end{enumerate}';
+
+    } elsif ($target eq 'web') {
+	my $id=$Apache::inputtags::response[-1];
+	$result.= '<br /><br />
+                   <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
+                   </textarea> <br /><br />';
+    }
+    return $result;
+}
+
+sub needs_exam_box {
+    my ($tagstack) = @_;
+    my @tags = ('formularesponse',
+		'stringresponse',
+		'reactionresponse',
+		'organicresponse',
+		'imageresponse',
+		);
+
+    foreach my $tag (@tags) {
+	if (grep(/\Q$tag\E/,@$tagstack)) {
+	    return 1;
+	}
+    }
+    return 0;
+}
+
 sub start_textline {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result = "";
@@ -252,6 +293,10 @@
 		$result.= '<input type="text" '.$readonly.' name="HWVAL_'.$id.'" value="'.
 		    $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
 	    }
+	    if ($Apache::lonhomework::type eq 'exam'
+		&& &needs_exam_box($tagstack)) {
+		$result.=&exam_box($target);
+	    }
 	} else {
 	    #right or wrong don't show what was last typed in.
 	    $result='<b>'.$Apache::inputtags::answertxt{$id}.'</b>';
@@ -271,10 +316,16 @@
 						     $safeeval,'size',
 						     'addchars','readonly');
 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
-    } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
+    } elsif ($target eq 'tex' 
+	     && $Apache::lonhomework::type ne 'exam') {
 	my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
 	if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
 	$result='\framebox['.$size.'][s]{\tiny\strut}';
+
+    } elsif ($target eq 'tex' 
+	     && $Apache::lonhomework::type eq 'exam'
+	     && &needs_exam_box($tagstack)) {
+	$result.=&exam_box($target);
     }
     return $result;
 }