File:  [LON-CAPA] / loncom / homework / caparesponse / caparesponse.pm
Revision 1.182: download - view: text, annotated - select for diffs
Thu Dec 1 18:46:48 2005 UTC (18 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- finish off the conversion to allowing style tags get_all_text across tags
- BUG#4428

    1: # The LearningOnline Network with CAPA
    2: # caparesponse definition
    3: #
    4: # $Id: caparesponse.pm,v 1.182 2005/12/01 18:46:48 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::caparesponse;
   30: use strict;
   31: use capa;
   32: use Apache::lonlocal;
   33: use Apache::lonnet;
   34: 
   35: BEGIN {
   36:     &Apache::lonxml::register('Apache::caparesponse',('caparesponse','numericalresponse','stringresponse','formularesponse'));
   37: }
   38: 
   39: my %answer;
   40: my $cur_name;
   41: sub start_answer {
   42:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   43:     my $result;
   44:     $cur_name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
   45:     if ($cur_name =~ /^\s*$/) { $cur_name = $Apache::lonxml::curdepth; }
   46:     my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
   47:     if (!defined($type) && $tagstack->[-2] eq 'answergroup') {
   48: 	$type = &Apache::lonxml::get_param('type',$parstack,$safeeval,-2);
   49:     }
   50:     if (!defined($type)) { $type = 'ordered' };
   51:     $answer{$cur_name}= { 'type' => $type,
   52: 			  'answers' => [] };
   53:     return $result;
   54: }
   55: 
   56: sub end_answer {
   57:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   58:     my $result;
   59:     undef($cur_name);
   60:     return $result;
   61: }
   62: 
   63: sub start_answergroup {
   64:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   65:     my $result;
   66:     my $id = $Apache::inputtags::response[-1];
   67:     my $dis = &Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval);
   68:     if (defined($dis)) { $Apache::inputtags::answertxt{$id}=$dis; }
   69:     return $result;
   70: }
   71: 
   72: sub end_answergroup {
   73:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   74:     my $result;
   75:     return $result;
   76: }
   77: 
   78: sub start_value {
   79:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   80:     my $result;
   81:     if ( $target eq 'web' || $target eq 'tex' ||
   82: 	 $target eq 'grade' || $target eq 'webgrade' ||
   83: 	 $target eq 'answer' || $target eq 'analyze' ) {
   84: 	my $bodytext = &Apache::lonxml::get_all_text("/value",$parser,$style);
   85: 	$bodytext = &Apache::run::evaluate($bodytext,$safeeval,
   86: 					   $$parstack[-1]);
   87: 	push(@{ $answer{$cur_name}{'answers'} },$bodytext);
   88:     }
   89:     return $result;
   90: }
   91: 
   92: sub end_value {
   93:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   94:     my $result;
   95:     return $result;
   96: }
   97: 
   98: sub start_array {
   99:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  100:     my $result;
  101:     if ( $target eq 'web' || $target eq 'tex' ||
  102: 	 $target eq 'grade' || $target eq 'webgrade' ||
  103: 	 $target eq 'answer' || $target eq 'analyze' ) {
  104: 	my $bodytext = &Apache::lonxml::get_all_text("/array",$parser,$style);
  105: 	my @values = &Apache::run::evaluate($bodytext,$safeeval,
  106: 					    $$parstack[-1]);
  107: 	push(@{ $answer{$cur_name}{'answers'} },@values);
  108:     }
  109:     return $result;
  110: }
  111: 
  112: sub end_array {
  113:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  114:     my $result;
  115:     return $result;
  116: }
  117: 
  118: sub start_unit {
  119:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  120:     my $result;
  121:     return $result;
  122: }
  123: 
  124: sub end_unit {
  125:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  126:     my $result;
  127:     return $result;
  128: }
  129: 
  130: sub start_numericalresponse {
  131:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  132:     &Apache::lonxml::register('Apache::caparesponse',('answer','answergroup','value','array','unit'));
  133:     my $id = &Apache::response::start_response($parstack,$safeeval);
  134:     my $result;
  135:     undef(%answer);
  136:     undef(%{$safeeval->varglob('LONCAPA::CAPAresponse_args')});
  137:     if ($target eq 'edit') {
  138: 	$result.=&Apache::edit::tag_start($target,$token);
  139: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token);
  140: 	if ($token->[1] eq 'numericalresponse') {
  141: 	    $result.=&Apache::edit::text_arg('Incorrect Answers:','incorrect',
  142: 					     $token).
  143: 		&Apache::loncommon::help_open_topic('numerical_wrong_answers');
  144: 	    $result.=&Apache::edit::text_arg('Unit:','unit',$token,5).
  145: 		&Apache::loncommon::help_open_topic('Physical_Units');
  146: 	    $result.=&Apache::edit::text_arg('Format:','format',$token,4).
  147: 		&Apache::loncommon::help_open_topic('Numerical_Response_Format');
  148: 	} elsif ($token->[1] eq 'formularesponse') {
  149: 	    $result.=&Apache::edit::text_arg('Sample Points:','samples',
  150: 					     $token,40).
  151: 	      &Apache::loncommon::help_open_topic('Formula_Response_Sampling');
  152: 	}
  153: 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  154:     } elsif ($target eq 'modified') {
  155: 	my $constructtag;
  156: 	if ($token->[1] eq 'numericalresponse') {
  157: 	    $constructtag=&Apache::edit::get_new_args($token,$parstack,
  158: 						      $safeeval,'answer',
  159:  						      'incorrect','unit',
  160: 						      'format');
  161: 	} elsif ($token->[1] eq 'formularesponse') {
  162: 	    $constructtag=&Apache::edit::get_new_args($token,$parstack,
  163: 						      $safeeval,'answer',
  164: 						      'samples');
  165: 	}
  166: 	if ($constructtag) {
  167: 	    $result = &Apache::edit::rebuild_tag($token);
  168: 	    $result.=&Apache::edit::handle_insert();
  169: 	}
  170:     } elsif ($target eq 'meta') {
  171: 	$result=&Apache::response::meta_package_write('numericalresponse');
  172:     } elsif ($target eq 'answer' || $target eq 'grade') {
  173: 	&Apache::response::reset_params();
  174:     } elsif ($target eq 'web') {
  175: 	my $partid = $Apache::inputtags::part;
  176: 	my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit');
  177: 	&Apache::lonxml::debug("Got unit $hideunit for $partid $id");
  178: 	#no way to enter units, with radio buttons
  179: 	if (lc($hideunit) eq "yes") {
  180: 	    my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
  181: 						    $safeeval);
  182: 	    if ($unit =~ /\S/) { $result.=" (in $unit) "; }
  183: 	}
  184: 	if (  &Apache::response::show_answer() ) {
  185: 	    my $answertxt;
  186: 	    my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
  187: 							 $safeeval);
  188: 	    my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,
  189: 							 $safeeval);
  190: 	    my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
  191: 						    $safeeval);
  192: 	    for (my $i=0; $i <= $#answers; $i++) {
  193: 		my $answer=$answers[$i];
  194: 		my $format;
  195: 		if ($#formats > 0) {
  196: 		    $format=$formats[$i];
  197: 		} else {
  198: 		    $format=$formats[0];
  199: 		}
  200: 		if ($unit=~/\$/) { $format="\$".$format; $unit=~s/\$//g; }
  201: 		if ($unit=~/\,/) { $format="\,".$format; $unit=~s/\,//g; }
  202: 		my $formatted=&format_number($answer,$format,$target,
  203: 					     $safeeval);
  204: 		$answertxt.=$formatted.',';
  205: 	    }
  206: 	    chop $answertxt;
  207: 	    if ($target eq 'web') {
  208: 		$answertxt.=" $unit ";
  209: 	    }
  210: 	    $Apache::inputtags::answertxt{$id}=$answertxt;
  211: 	}
  212:     }
  213:     return $result;
  214: }
  215: 
  216: sub check_submission {
  217:     my ($response,$partid,$id,$tag,$parstack,$safeeval,$ignore_sig)=@_;
  218:     my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
  219:     $$args_ref{'response'}=$response;
  220:     my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit');
  221:     
  222:     foreach my $arg ('type','tol','sig','format','unit','calc',
  223: 		     'samples') {
  224: 	$$args_ref{$arg}=
  225: 	    &Apache::lonxml::get_param($arg,$parstack,$safeeval);
  226:     }
  227:     foreach my $key (keys(%Apache::inputtags::params)) {
  228: 	$$args_ref{$key}=$Apache::inputtags::params{$key};
  229:     }
  230:     
  231:     #no way to enter units, with radio buttons
  232:     if ($Apache::lonhomework::type eq 'exam' ||
  233: 	lc($hideunit) eq "yes") {
  234: 	delete($$args_ref{'unit'});
  235:     }
  236:     #sig fig don't make much sense either
  237:     if (($Apache::lonhomework::type eq 'exam' ||
  238: 	 &Apache::response::submitted('scantron') ||
  239: 	 $ignore_sig) &&
  240: 	$tag eq 'numericalresponse') {
  241: 	delete($$args_ref{'sig'});
  242:     }
  243:     
  244:     if ($tag eq 'formularesponse') {
  245: 	$$args_ref{'type'}='fml';
  246:     } elsif ($tag eq 'numericalresponse') {
  247: 	$$args_ref{'type'}='float';
  248:     }
  249:     my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
  250:     &Apache::lonxml::debug('answer is'.join(':',@answer));
  251:     if (@answer && defined($answer[0])) {
  252: 	$answer{'INTERNAL'}= {'type' => 'ordered',
  253: 			      'answers' => \@answer };
  254:     }
  255:     #FIXME would be nice if we could save name so we know who graded him
  256:     #correct
  257:     my (%results,@final_awards,@final_msgs,@names);
  258:     foreach my $name (keys(%answer)) {
  259: 	&Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} }));
  260: 	@{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=@{ $answer{$name}{'answers'} };
  261: 	my ($result,@msgs) = 
  262: 	    &Apache::run::run("&caparesponse_check_list()",$safeeval);
  263: 	&Apache::lonxml::debug('msgs are '.join(':',@msgs));
  264: 	my ($awards)=split(/:/,$result);
  265: 	my @awards= split(/,/,$awards);
  266: 	my ($ad, $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
  267: 	$results{$name}= [$ad,$msg];
  268: 	push(@final_awards,$ad);
  269: 	push(@final_msgs,$msg);
  270: 	push(@names,$name);
  271:     }
  272:     my ($ad, $msg, $name) = &Apache::inputtags::finalizeawards(\@final_awards,
  273: 							       \@final_msgs,
  274: 							       \@names,1);
  275:     return($ad,$msg);
  276: }
  277: 
  278: sub end_numericalresponse {
  279:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  280:     my $increment=1;
  281:     my $result = '';
  282:     if (!$Apache::lonxml::default_homework_loaded) {
  283: 	&Apache::lonxml::default_homework_load($safeeval);
  284:     }
  285:     my $partid = $Apache::inputtags::part;
  286:     my $id = $Apache::inputtags::response[-1];
  287:     my $tag;
  288:     $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
  289:     if (scalar(@$tagstack)) { $tag=$$tagstack[-1]; }
  290:     if ( $target eq 'grade' && &Apache::response::submitted() ) {
  291: 	&Apache::response::setup_params($tag,$safeeval);
  292: 	if ($Apache::lonhomework::type eq 'exam' && 
  293: 	    $tag eq 'formularesponse') {
  294: 	    $increment=&Apache::response::scored_response($partid,$id);
  295: 	} else {
  296: 	    my $response = &Apache::response::getresponse();
  297: 	    if ( $response =~ /[^\s]/) {
  298: 		my %previous = &Apache::response::check_for_previous($response,$partid,$id);
  299: 		&Apache::lonxml::debug("submitted a $response<br>\n");
  300: 		&Apache::lonxml::debug($$parstack[-1] . "\n<br>");
  301: 		
  302: 		if ( &Apache::response::submitted('scantron')) {
  303: 		    my $number_of_bubbles = &Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.numbubbles');
  304: 		    if (!$number_of_bubbles) { $number_of_bubbles=8; }
  305: 		    my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
  306: 		    my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
  307: 		    my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
  308: 		    if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); }
  309: 		    my ($values,$display)=&make_numerical_bubbles($number_of_bubbles,$target,$answers[0],$formats[0],\@incorrect,$safeeval);
  310: 		    $response=$values->[$response];
  311: 		}
  312: 		$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
  313: 		my ($ad,$msg)=&check_submission($response,$partid,$id,
  314: 						$tag,$parstack,$safeeval);
  315: 
  316: 		&Apache::lonxml::debug('ad is'.$ad);
  317: 		if ($ad eq 'SIG_FAIL') {
  318: 		    my ($sig_u,$sig_l)=
  319: 			&get_sigrange($Apache::inputtags::params{'sig'});
  320: 		    $msg=join(':',$msg,$sig_l,$sig_u);
  321: 		    &Apache::lonxml::debug("sigs bad $sig_u $sig_l ".
  322: 					   $Apache::inputtags::params{'sig'});
  323: 		}
  324: 		&Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
  325: 		if ($Apache::lonhomework::type eq 'survey' &&
  326: 		    ($ad eq 'INCORRECT' || $ad eq 'APPROX_ANS' ||
  327: 		     $ad eq 'EXACT_ANS')) {
  328: 		    $ad='SUBMITTED';
  329: 		}
  330: 		&Apache::response::handle_previous(\%previous,$ad);
  331: 		$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
  332: 		$Apache::lonhomework::results{"resource.$partid.$id.awardmsg"}=$msg;
  333: 		$result='';
  334: 	    }
  335: 	}
  336:     } elsif ($target eq 'web' || $target eq 'tex') {
  337: 	my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
  338: 						     $safeeval);
  339: 	my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
  340: 	my $status = $Apache::inputtags::status['-1'];
  341: 	if ($Apache::lonhomework::type eq 'exam') {
  342: 	    my $number_of_bubbles = &Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.numbubbles');
  343: 	    if ($Apache::inputtags::params{'numbubbles'}) {
  344: 		$number_of_bubbles = $Apache::inputtags::params{'numbubbles'};
  345: 	    }
  346: 	    if (!$number_of_bubbles) { $number_of_bubbles=8; }
  347: 	    
  348: 	    my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,
  349: 							 $safeeval);
  350: 	    my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
  351: 						    $safeeval);
  352: 	    my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
  353: 	    if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); }
  354: 	    my ($bubble_values,$bubble_display)=
  355: 		&make_numerical_bubbles($number_of_bubbles,
  356: 					$target,$answers[0],
  357: 					$formats[0],\@incorrect,$safeeval);
  358: 	    my @alphabet=('A'..'Z');
  359: 	    if ($target eq 'web') {
  360: 		if ($tag eq 'numericalresponse') {
  361: 		    if ($unit=~/\S/) {$result.=' (in '.$unit.')<br /><br />';}
  362: 		    $result.= '<table border="1"><tr>';
  363: 		    my $previous=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.$id.submission"};
  364: 		    for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
  365: 			my $checked='';
  366: 			if ($previous eq $bubble_values->[$ind]) {
  367: 			    $checked=" checked='on' ";
  368: 			}
  369: 			$result.='<td><input type="radio" name="HWVAL_'.$id.
  370: 			    '" value="'.$bubble_values->[$ind].'" '.$checked
  371: 			    .' /><b>'.$alphabet[$ind].'</b>: '.
  372: 			    $bubble_display->[$ind].'</td>';
  373: 		    }
  374: 		    $result.='</tr></table>';
  375: 		} elsif ($tag eq 'formularesponse') {
  376: 		    $result.= '<br /><br /><font color="red">
  377:                            <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
  378:                            </textarea></font> <br /><br />';
  379: 		}
  380: 	    } elsif ($target eq 'tex') {
  381: 		if ((defined $unit) and ($unit=~/\S/) and ($Apache::lonhomework::type eq 'exam')) {
  382: 		    $result.=' \textit{(in} \verb|'.$unit.'|\textit{)} ';
  383: 		}
  384: 		if ($tag eq 'numericalresponse') {
  385: 		    my ($celllength,$number_of_tables,@table_range)=
  386: 			&get_table_sizes($number_of_bubbles,$bubble_display);
  387: 		    my $j=0;
  388: 		    my $cou=0;
  389: 		    $result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]';
  390: 		    for (my $i=0;$i<$number_of_tables;$i++) {
  391: 			$result.='\vskip -1 mm \noindent \setlength{\tabcolsep}{2 mm}\begin{tabular}{';
  392: 			for (my $ind=0;$ind<$table_range[$j];$ind++) {
  393: 			    $result.='p{3 mm}p{'.$celllength.' mm}';
  394: 			}
  395: 			$result.='}';
  396: 			for (my $ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
  397: 			    $result.='\hskip -4 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$ & \hskip -3 mm {\small '.$bubble_display->[$ind].'} ';
  398: 			    if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
  399: 			}
  400: 			$cou += $table_range[$j];
  401: 			$j++;
  402: 			$result.='\\\\\end{tabular}\vskip 0 mm ';
  403: 		    }
  404: 		    $result.='\end{enumerate}';
  405: 		} else {
  406: 		    $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
  407: 		    my $repetition = &Apache::response::repetition();
  408: 		    $result.='\begin{enumerate}';
  409: 		    for (my $i=0;$i<$repetition;$i++) {
  410: 			$result.='\item[\textbf{'.($Apache::lonxml::counter+$i).'}.]\textit{Leave blank on scoring form}\vskip 0 mm';
  411: 		    }
  412: 		    $increment=$repetition;
  413: 		    $result.= '\end{enumerate}';
  414: 		}
  415: 	    }
  416: 	}
  417:     } elsif ($target eq 'edit') {
  418: 	$result.='</td></tr>'.&Apache::edit::end_table;
  419:     } elsif ($target eq 'answer' || $target eq 'analyze') {
  420: 	my $part_id="$partid.$id";
  421: 	if ($target eq 'analyze') {
  422: 	    push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
  423: 	    $Apache::lonhomework::analyze{"$part_id.type"} = $tag;
  424: 	    my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
  425: 	    if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); }
  426: 	    push (@{ $Apache::lonhomework::analyze{"$part_id.incorrect"} }, @incorrect);
  427: 	    &Apache::response::check_if_computed($token,$parstack,
  428: 						 $safeeval,'answer');
  429: 	}
  430: 	if (scalar(@$tagstack)) {
  431: 	    &Apache::response::setup_params($tag,$safeeval);
  432: 	}
  433: 	my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
  434: 	my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
  435: 	my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval);
  436: 	my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval);
  437: 	
  438: 	if ($target eq 'answer') {
  439: 	    $result.=&Apache::response::answer_header($tag);
  440: 	}
  441: 	my ($sigline,$tolline);
  442: 	for(my $i=0;$i<=$#answers;$i++) {
  443: 	    my $ans=$answers[$i];
  444: 	    my $fmt=$formats[0];
  445: 	    if (@formats && $#formats) {$fmt=$formats[$i];}
  446: 	    my ($high,$low);
  447: 	    if ($Apache::inputtags::params{'tol'}) {
  448: 		($high,$low)=&get_tolrange($ans,$Apache::inputtags::params{'tol'});
  449: 	    }
  450: 	    my ($sighigh,$siglow);
  451: 	    if ($Apache::inputtags::params{'sig'}) {
  452: 		($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'});
  453: 	    }
  454: 	    if ($fmt && $tag eq 'numericalresponse') {
  455: 		$fmt=~s/e/E/g;
  456: 		if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; }
  457: 		if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }
  458: 		$ans = &format_number($ans,$fmt,$target,$safeeval);
  459: 		#if ($high) {
  460: 		#    $high=&format_number($high,$fmt,$target,$safeeval);
  461: 		#    $low =&format_number($low,$fmt,$target,$safeeval);
  462: 		#}
  463: 	    }
  464: 	    if ($target eq 'answer') {
  465: 		if ($high && $tag eq 'numericalresponse') {
  466: 		    $ans.=' ['.$low.','.$high.']';
  467: 		    $tolline .= "[$low, $high]";
  468: 		}
  469: 		if (defined($sighigh) && $tag eq 'numericalresponse') {
  470: 		    if ($env{'form.answer_output_mode'} eq 'tex') {
  471: 			$ans.= " Sig $siglow - $sighigh";
  472: 		    } else {
  473: 			$ans.= " Sig <i>$siglow - $sighigh</i>";
  474: 			$sigline .= "[$siglow, $sighigh]";
  475: 		    }
  476: 		}
  477: 		$result.=&Apache::response::answer_part($tag,$ans);
  478: 	    } elsif ($target eq 'analyze') {
  479: 		push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans);
  480: 		if ($high) {
  481: 		    push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"} }, $high);
  482: 		    push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"} }, $low);
  483: 		}
  484: 		if ($fmt) {
  485: 		    push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt);
  486: 		}
  487: 	    }
  488: 	}
  489: 
  490: 	my @fmt_ans;
  491: 	for(my $i=0;$i<=$#answers;$i++) {
  492: 	    my $ans=$answers[$i];
  493: 	    my $fmt=$formats[0];
  494: 	    if (@formats && $#formats) {$fmt=$formats[$i];}
  495: 	    if ($fmt && $tag eq 'numericalresponse') {
  496: 		$fmt=~s/e/E/g;
  497: 		if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; }
  498: 		if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }
  499: 		$ans = &format_number($ans,$fmt,$target,$safeeval);
  500: 		if ($fmt=~/\$/ && $unit!~/\$/) { $ans=~s/\$//; }
  501: 	    }
  502: 	    push(@fmt_ans,$ans);
  503: 	}
  504: 	my $response=join(', ',@fmt_ans);
  505: 	my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.
  506: 					  $id.'.turnoffunit');
  507: 	if ($unit ne ''  && 
  508: 	    ! ($Apache::lonhomework::type eq 'exam' ||
  509: 	       lc($hideunit) eq "yes") )  {
  510: 	    my $cleanunit=$unit;
  511: 	    $cleanunit=~s/\$\,//g;
  512: 	    $response.=" $cleanunit";
  513: 	}
  514: 
  515: 	my ($ad,$msg)=&check_submission($response,$partid,$id,$tag,
  516: 					$parstack,$safeeval);
  517: 	if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
  518: 	    my $error;
  519: 	    if ($tag eq 'formularesponse') {
  520: 		$error=&mt('Computer\'s answer is incorrect ("[_1]").');
  521: 	    } else {
  522: 		# answer failed check if it is sig figs that is failing
  523: 		my ($ad,$msg)=&check_submission($response,$partid,$id,
  524: 						$tag,$parstack,
  525: 						$safeeval,1);
  526: 		if ($sigline ne '') {
  527: 		    $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] or significant figures [_3] need to be adjusted.',$response,$tolline,$sigline);
  528: 		} else {
  529: 		    $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] needs to be adjusted.',$response,$tolline);
  530: 		}
  531: 	    }
  532: 	    if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
  533: 		&Apache::lonxml::error($error);
  534: 	    } else {
  535: 		&Apache::lonxml::warning($error);
  536: 	    }
  537: 	}
  538: 
  539: 	if (defined($unit) and ($unit ne '') and
  540: 	    $tag eq 'numericalresponse') {
  541: 	    if ($target eq 'answer') {
  542: 		if ($env{'form.answer_output_mode'} eq 'tex') {
  543: 		    $result.=&Apache::response::answer_part($tag,
  544: 							    " Unit: $unit ");
  545: 		} else {
  546: 		    $result.=&Apache::response::answer_part($tag,
  547: 							    "Unit: <b>$unit</b>");
  548: 		}
  549: 	    } elsif ($target eq 'analyze') {
  550: 		push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} }, $unit);
  551: 	    }
  552: 	}
  553: 	if ($tag eq 'formularesponse' && $target eq 'answer') {
  554: 	    my $samples=&Apache::lonxml::get_param('samples',$parstack,$safeeval);
  555: 	    $result.=&Apache::response::answer_part($tag,$samples);
  556: 	}
  557: 	if ($target eq 'answer') {
  558: 	    $result.=&Apache::response::answer_footer($tag);
  559: 	}
  560:     }
  561:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || 
  562: 	$target eq 'tex' || $target eq 'analyze') {
  563: 	&Apache::lonxml::increment_counter($increment);
  564:     }
  565:     &Apache::response::end_response;
  566:     return $result;
  567: }
  568: 
  569: sub get_table_sizes {
  570:     my ($number_of_bubbles,$rbubble_values)=@_;
  571:     my $scale=2; #mm for one digit
  572:     my $cell_width=0;
  573:     foreach my $member (@$rbubble_values) {
  574: 	my $cell_width_real=0;
  575: 	if ($member=~/(\+|-)?(\d*)\.?(\d*)\s*\$?\\times\s*10\^{(\+|-)?(\d+)}\$?/) {
  576: 	    $cell_width_real=(length($2)+length($3)+length($5)+7)*$scale;
  577: 	} elsif ($member=~/(\d*)\.?(\d*)(E|e)(\+|-)?(\d*)/) {
  578: 	    $cell_width_real=(length($1)+length($2)+length($5)+9)*$scale;
  579:         } elsif ($member=~/(\d*)\.(\d*)/) {
  580: 	    $cell_width_real=(length($1)+length($2)+3)*$scale;
  581: 	} else {
  582: 	    $cell_width_real=(length($member)+1)*$scale*0.9;
  583: 	}
  584: 	if ($cell_width_real>$cell_width) {$cell_width=$cell_width_real;}
  585:     }
  586:     $cell_width+=8; 
  587:     my $textwidth;
  588:     if ($env{'form.textwidth'} ne '') {
  589: 	$env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
  590: 	$textwidth=$1.'.'.$2;
  591:     } else {
  592: 	$env{'form.textwidth'}=~/(\d+)\.?(\d*)/;
  593: 	$textwidth=$1.'.'.$2;
  594:     }
  595:     my $bubbles_per_line=int($textwidth/$cell_width);
  596:     if ($bubbles_per_line > $number_of_bubbles) {
  597: 	$bubbles_per_line=$number_of_bubbles;
  598:     }elsif (($bubbles_per_line > $number_of_bubbles/2) && ($number_of_bubbles % 2==0)) {$bubbles_per_line=$number_of_bubbles/2;}
  599:     my $number_of_tables = int($number_of_bubbles/$bubbles_per_line);
  600:     my @table_range = ();
  601:     for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$bubbles_per_line;}
  602:     if ($number_of_bubbles % $bubbles_per_line) {
  603: 	$number_of_tables++;
  604: 	push @table_range,($number_of_bubbles % $bubbles_per_line);
  605:     }
  606:     $cell_width-=8;
  607:     $cell_width=$cell_width*3/4;
  608:     return ($cell_width,$number_of_tables,@table_range);
  609: }
  610: 
  611: sub format_number {
  612:     my ($number,$format,$target,$safeeval)=@_;
  613:     my $ans;
  614:     if ($format eq '') {
  615: 	#What is the number? (integer,decimal,floating point)
  616: 	if ($number=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
  617: 	    $format = '3e';
  618: 	} elsif ($number=~/^(\d*)\.(\d*)$/) {
  619: 	    $format = '4f';
  620: 	} elsif ($number=~/^(\d*)$/) {
  621: 	    $format = 'd';
  622: 	}
  623:     }
  624:     if (!$Apache::lonxml::default_homework_loaded) {
  625: 	&Apache::lonxml::default_homework_load($safeeval);
  626:     }
  627:     $ans=&Apache::run::run("&prettyprint(q\0$number\0,q\0$format\0,q\0$target\0)",$safeeval);
  628:     return $ans;
  629: }
  630: 
  631: sub make_numerical_bubbles {
  632:     my ($number_of_bubbles,$target,$answer,$format,$incorrect,$safeeval) =@_;
  633:     my @bubble_values=();
  634:     &Apache::lonxml::debug("answer is $answer incorrect is $incorrect");
  635:     my @oldseed=&Math::Random::random_get_seed();
  636:     if (defined($incorrect) && ref($incorrect)) {
  637: 	&Apache::lonxml::debug("inside ".(scalar(@$incorrect)+1 gt $number_of_bubbles));
  638: 	if (defined($$incorrect[0]) &&
  639: 	    scalar(@$incorrect)+1 >= $number_of_bubbles) {
  640: 	    &Apache::lonxml::debug("inside ".(scalar(@$incorrect)+1).":$number_of_bubbles");
  641: 	    &Apache::response::setrandomnumber();
  642: 	    my @rand_inc=&Math::Random::random_permutation(@$incorrect);
  643: 	    @bubble_values=@rand_inc[0..($number_of_bubbles-2)];
  644: 	    @bubble_values=sort {$a <=> $b} (@bubble_values,$answer);
  645: 	    &Apache::lonxml::debug("Answer was :$answer: returning :".$#bubble_values.": whih are :".join(':',@bubble_values));
  646: 	    &Math::Random::random_set_seed(@oldseed);
  647: 	    if (defined($format) && $format ne '') {
  648: 		my @bubble_display;
  649: 		foreach my $value (@bubble_values) {
  650: 		    push(@bubble_display,
  651: 			 &format_number($value,$format,$target,$safeeval));
  652: 		}
  653: 		return (\@bubble_values,\@bubble_display);
  654: 	    } else {
  655: 		return (\@bubble_values,\@bubble_values);
  656: 	    }
  657: 	}
  658: 	if (defined($$incorrect[0]) &&
  659: 	    scalar(@$incorrect)+1 < $number_of_bubbles) {
  660: 	    &Apache::lonxml::warning("Not enough incorrect answers were specified in the incorrect array, ignoring the specified incorrect answers and instead generating them (".join(',',@$incorrect).").");
  661: 	}
  662:     }
  663:     my @factors = (1.13,1.17,1.25,1.33,1.45); #default values of factors
  664:     my @powers = (1..$number_of_bubbles);
  665:     &Apache::response::setrandomnumber();
  666:     my $ind=&Math::Random::random_uniform_integer(1,0,$#powers);
  667:     my $power = $powers[$ind];
  668:     $ind=&Math::Random::random_uniform_integer(1,0,$#factors);
  669:     my $factor = $factors[$ind];
  670:     my @bubble_display;
  671:     for ($ind=0;$ind<$number_of_bubbles;$ind++) {
  672: 	$bubble_values[$ind] = $answer*($factor**($power-$powers[$#powers-$ind]));
  673: 	$bubble_display[$ind] = &format_number($bubble_values[$ind],
  674: 					       $format,$target,$safeeval);
  675: 
  676:     }
  677:     &Math::Random::random_set_seed(@oldseed);
  678:     return (\@bubble_values,\@bubble_display);
  679: }
  680: 
  681: sub get_tolrange {
  682:     my ($ans,$tol)=@_;
  683:     my ($high,$low);
  684:     if ($tol =~ /%$/) {
  685: 	chop($tol);
  686: 	my $change=$ans*($tol/100.0);
  687: 	$high=$ans+$change;
  688: 	$low=$ans-$change;
  689:     } else {
  690: 	$high=$ans+$tol;
  691: 	$low=$ans-$tol;
  692:     }
  693:     return ($high,$low);
  694: }
  695: 
  696: sub get_sigrange {
  697:     my ($sig)=@_;
  698:     &Apache::lonxml::debug("Got a sig of :$sig:");
  699:     my $courseid=$env{'request.course.id'};
  700:     if (lc($env{"course.$courseid.disablesigfigs"}) eq 'yes') {
  701: 	return (15,0);
  702:     }
  703:     my $sig_lbound;
  704:     my $sig_ubound;
  705:     if ($sig eq '') {
  706: 	$sig_lbound = 0; #SIG_LB_DEFAULT
  707: 	$sig_ubound =15; #SIG_UB_DEFAULT
  708:     } else {
  709: 	($sig_lbound,$sig_ubound) = split(/,/,$sig);
  710: 	if (!defined($sig_lbound)) {
  711: 	    $sig_lbound = 0; #SIG_LB_DEFAULT
  712: 	    $sig_ubound =15; #SIG_UB_DEFAULT
  713: 	}
  714: 	if (!defined($sig_ubound)) { $sig_ubound=$sig_lbound; }
  715:     }
  716:     if (($sig_ubound<$sig_lbound) ||
  717: 	($sig_lbound > 15) ||
  718: 	($sig =~/(\+|-)/ ) ) {
  719: 	my $errormsg=&mt("Invalid Significant figures detected")." ($sig)";
  720: 	if ($env{'request.state'} eq 'construct') {
  721: 	    $errormsg.=
  722: 		&Apache::loncommon::help_open_topic('Significant_Figures');
  723: 	}
  724: 	&Apache::lonxml::error($errormsg);
  725:     }
  726:     return ($sig_ubound,$sig_lbound);
  727: }
  728: 
  729: sub start_stringresponse {
  730:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  731:     my $result;
  732:     my $id = &Apache::response::start_response($parstack,$safeeval);
  733:     if ($target eq 'meta') {
  734: 	$result=&Apache::response::meta_package_write('stringresponse');
  735:     } elsif ($target eq 'edit') {
  736: 	$result.=&Apache::edit::tag_start($target,$token);
  737: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token);
  738: 	$result.=&Apache::edit::select_arg('Type:','type',
  739: 			 [['cs','Case Sensitive'],['ci','Case Insensitive'],
  740: 			  ['mc','Case Insensitive, Any Order'],
  741: 			  ['re','Regular Expression']],$token);
  742: 	$result.=&Apache::edit::text_arg('String to display for answer:',
  743: 					 'answerdisplay',$token);
  744: 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  745:     } elsif ($target eq 'modified') {
  746: 	my $constructtag;
  747: 	$constructtag=&Apache::edit::get_new_args($token,$parstack,
  748: 						  $safeeval,'answer',
  749: 						  'type','answerdisplay');
  750: 	if ($constructtag) {
  751: 	    $result = &Apache::edit::rebuild_tag($token);
  752: 	    $result.=&Apache::edit::handle_insert();
  753: 	}
  754:     } elsif ($target eq 'web') {
  755: 	if (  &Apache::response::show_answer() ) {
  756: 	    my $answer=
  757: 	       &Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval);
  758: 	    if (!defined $answer || $answer eq '') {
  759: 		$answer=
  760: 		    &Apache::lonxml::get_param('answer',$parstack,$safeeval);
  761: 	    }
  762: 	    $Apache::inputtags::answertxt{$id}=$answer;
  763: 	} 
  764:     } elsif ($target eq 'answer' || $target eq 'grade') {
  765: 	&Apache::response::reset_params();
  766:     }
  767:     return $result;
  768: }
  769: 
  770: sub end_stringresponse {
  771:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  772:     my $increment=1;
  773:     my $result = '';
  774:     my $part=$Apache::inputtags::part;
  775:     my $id=$Apache::inputtags::response[-1];
  776:     my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
  777:     my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval);
  778:     my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval);
  779:     &Apache::lonxml::debug("current $answer ".$token->[2]);
  780:     if (!$Apache::lonxml::default_homework_loaded) {
  781: 	&Apache::lonxml::default_homework_load($safeeval);
  782:     }
  783:     if ( $target eq 'grade' && &Apache::response::submitted() ) {
  784: 	&Apache::response::setup_params('stringresponse',$safeeval);
  785: 	$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
  786: 	if ($Apache::lonhomework::type eq 'exam' ||
  787: 	    &Apache::response::submitted('scantron')) {
  788: 	    $increment=&Apache::response::scored_response($part,$id);
  789: 	} else {
  790: 	    my $response = &Apache::response::getresponse();
  791: 	    if ( $response =~ /[^\s]/) {
  792: 		my %previous = &Apache::response::check_for_previous($response,
  793: 								    $part,$id);
  794: 		&Apache::lonxml::debug("submitted a $response<br>\n");
  795: 		&Apache::lonxml::debug($$parstack[-1] . "\n<br>");
  796: 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=
  797: 		    $response;
  798: 		my ($ad,$msg);
  799: 		if ($type eq 're' ) { 
  800: 		    # if the RE wasn't in a var it likely got munged,
  801:                     # thus grab it from the var directly
  802: #		    my $testans=$token->[2]->{'answer'};
  803: #		    if ($testans !~ m/^\s*\$/) {
  804: #			$answer=$token->[2]->{'answer'};
  805: #		    }
  806: 		    ${$safeeval->varglob('LONCAPA::response')}=$response;
  807: 		    $result = &Apache::run::run('if ($LONCAPA::response=~m'.$answer.') { return 1; } else { return 0; }',$safeeval);
  808: 		    &Apache::lonxml::debug("current $response");
  809: 		    &Apache::lonxml::debug("current $answer");
  810: 		    $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
  811: 		} else {
  812: 		    my $args_ref= 
  813: 			\%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
  814: 		
  815: 		    $$args_ref{'response'}=$response;
  816: 		    &Apache::lonxml::debug("current $response");
  817: 		    $$args_ref{'type'}=
  818: 			&Apache::lonxml::get_param('type',$parstack,$safeeval);
  819: 		    foreach my $key (keys(%Apache::inputtags::params)) {
  820: 			$$args_ref{$key}=$Apache::inputtags::params{$key};
  821: 		    }
  822: 		    &Apache::lonxml::debug('answer is'.join(':',$answer));
  823: 		    @{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=($answer);
  824: 		    ($result, my @msgs)=&Apache::run::run("&caparesponse_check_list()",$safeeval);
  825: 		    &Apache::lonxml::debug('msgs are'.join(':',@msgs));
  826: 		    my ($awards)=split(/:/,$result);
  827: 		    my (@awards) = split(/,/,$awards);
  828: 		    ($ad,$msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
  829: 		    &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
  830: 		}
  831: 		if ($Apache::lonhomework::type eq 'survey' &&
  832: 		    ($ad eq 'INCORRECT' || $ad eq 'APPROX_ANS' ||
  833: 		     $ad eq 'EXACT_ANS')) {
  834: 		    $ad='SUBMITTED';
  835: 		}
  836: 		&Apache::response::handle_previous(\%previous,$ad);
  837: 		$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
  838: 		$Apache::lonhomework::results{"resource.$part.$id.awardmsg"}=$msg;
  839: 	    }
  840: 	}
  841:     } elsif ($target eq 'web' || $target eq 'tex') {
  842: 	my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
  843: 	my $status = $Apache::inputtags::status['-1'];
  844: 	if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') {
  845: 	    $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
  846: 	    $increment = &Apache::response::repetition();
  847: 	    $result.='\begin{enumerate}';
  848: 	    for (my $i=0;$i<$increment;$i++) {
  849: 		$result.='\item[\textbf{'.($Apache::lonxml::counter+$i).
  850: 		    '}.]\textit{Leave blank on scoring form}\vskip 0 mm';
  851: 	    }
  852: 	    $result.= '\end{enumerate}';
  853: 	}
  854:     } elsif ($target eq 'answer' || $target eq 'analyze') {
  855: 	if ($target eq 'analyze') {
  856: 	    push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
  857: 	    $Apache::lonhomework::analyze{"$part.$id.type"} = 'stringresponse';
  858: 	    &Apache::response::check_if_computed($token,$parstack,$safeeval,
  859: 						 'answer');
  860: 	}
  861: 	&Apache::response::setup_params('stringresponse',$safeeval);
  862: 	if ($target eq 'answer') {
  863: 	    $result.=&Apache::response::answer_header('stringresponse');
  864: 	}
  865: #	foreach my $ans (@answers) {
  866: 	    if ($target eq 'answer') {
  867: 		$result.=&Apache::response::answer_part('stringresponse',$answer);
  868: 		if ($type eq 're') {
  869: 		    $result.=&Apache::response::answer_part('stringresponse',
  870: 							    $answerdisplay);
  871: 		}
  872: 	    } elsif ($target eq 'analyze') {
  873: 		push (@{ $Apache::lonhomework::analyze{"$part.$id.answer"} },
  874: 		      $answer);
  875: 	    }
  876: #	}
  877: 	my $string='Case Insensitive';
  878: 	if ($type eq 'mc') {
  879: 	    $string='Multiple Choice';
  880: 	} elsif ($type eq 'cs') {
  881: 	    $string='Case Sensitive';
  882: 	} elsif ($type eq 'ci') {
  883: 	    $string='Case Insensitive';
  884: 	} elsif ($type eq 're') {
  885: 	    $string='Regular Expression';
  886: 	}
  887: 	if ($target eq 'answer') {
  888: 	    if ($env{'form.answer_output_mode'} eq 'tex') {
  889: 		$result.=&Apache::response::answer_part('stringresponse',
  890: 							"$string");
  891: 	    } else {
  892: 		$result.=&Apache::response::answer_part('stringresponse',
  893: 							"<b>$string</b>");
  894: 	    }
  895: 	} elsif ($target eq 'analyze') {
  896: 	    push (@{$Apache::lonhomework::analyze{"$part.$id.str_type"}},
  897: 		  $type);
  898: 	}
  899: 	if ($target eq 'answer') {
  900: 	    $result.=&Apache::response::answer_footer('stringresponse');
  901: 	}
  902:     } elsif ($target eq 'edit') {
  903: 	$result.='</td></tr>'.&Apache::edit::end_table;
  904:     }
  905:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || 
  906: 	$target eq 'tex' || $target eq 'analyze') {
  907: 	&Apache::lonxml::increment_counter($increment);
  908:     }
  909:     &Apache::response::end_response;
  910:     return $result;
  911: }
  912: 
  913: sub start_formularesponse {
  914:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  915:     my $result;
  916:     if ($target eq 'meta') {
  917: 	&Apache::response::start_response($parstack,$safeeval);
  918: 	$result=&Apache::response::meta_package_write('formularesponse');
  919: 	&Apache::response::end_response();
  920:     } else {
  921: 	$result.=&start_numericalresponse(@_);
  922:     }
  923:     return $result;
  924: }
  925: 
  926: sub end_formularesponse {
  927:     return end_numericalresponse(@_);
  928: }
  929: 
  930: 1;
  931: __END__
  932: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>