Annotation of loncom/homework/caparesponse/caparesponse.pm, revision 1.184
1.3 albertel 1: # The LearningOnline Network with CAPA
2: # caparesponse definition
1.47 albertel 3: #
1.184 ! albertel 4: # $Id: caparesponse.pm,v 1.183 2005/12/01 22:30:55 albertel Exp $
1.47 albertel 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: #
1.3 albertel 28:
29: package Apache::caparesponse;
30: use strict;
1.4 albertel 31: use capa;
1.129 www 32: use Apache::lonlocal;
1.166 albertel 33: use Apache::lonnet;
1.3 albertel 34:
1.50 harris41 35: BEGIN {
1.89 albertel 36: &Apache::lonxml::register('Apache::caparesponse',('caparesponse','numericalresponse','stringresponse','formularesponse'));
1.3 albertel 37: }
38:
1.181 albertel 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 {
1.182 albertel 79: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.181 albertel 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' ) {
1.182 albertel 84: my $bodytext = &Apache::lonxml::get_all_text("/value",$parser,$style);
1.181 albertel 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 {
1.182 albertel 99: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.181 albertel 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' ) {
1.182 albertel 104: my $bodytext = &Apache::lonxml::get_all_text("/array",$parser,$style);
1.181 albertel 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:
1.89 albertel 130: sub start_numericalresponse {
131: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.181 albertel 132: &Apache::lonxml::register('Apache::caparesponse',('answer','answergroup','value','array','unit'));
1.89 albertel 133: my $id = &Apache::response::start_response($parstack,$safeeval);
134: my $result;
1.181 albertel 135: undef(%answer);
136: undef(%{$safeeval->varglob('LONCAPA::CAPAresponse_args')});
1.89 albertel 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') {
1.122 albertel 141: $result.=&Apache::edit::text_arg('Incorrect Answers:','incorrect',
1.149 www 142: $token).
143: &Apache::loncommon::help_open_topic('numerical_wrong_answers');
1.89 albertel 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',
1.156 albertel 159: 'incorrect','unit',
1.117 albertel 160: 'format');
1.89 albertel 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();
1.22 albertel 169: }
1.89 albertel 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();
1.96 albertel 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: }
1.146 albertel 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: }
1.156 albertel 200: if ($unit=~/\$/) { $format="\$".$format; $unit=~s/\$//g; }
201: if ($unit=~/\,/) { $format="\,".$format; $unit=~s/\,//g; }
1.153 albertel 202: my $formatted=&format_number($answer,$format,$target,
203: $safeeval);
204: $answertxt.=$formatted.',';
1.146 albertel 205: }
206: chop $answertxt;
207: if ($target eq 'web') {
1.148 albertel 208: $answertxt.=" $unit ";
1.146 albertel 209: }
210: $Apache::inputtags::answertxt{$id}=$answertxt;
211: }
1.16 albertel 212: }
1.89 albertel 213: return $result;
1.21 albertel 214: }
215:
1.167 albertel 216: sub check_submission {
1.171 albertel 217: my ($response,$partid,$id,$tag,$parstack,$safeeval,$ignore_sig)=@_;
1.167 albertel 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' ||
1.171 albertel 238: &Apache::response::submitted('scantron') ||
239: $ignore_sig) &&
1.167 albertel 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));
1.181 albertel 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);
1.167 albertel 276: }
277:
1.89 albertel 278: sub end_numericalresponse {
279: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.90 albertel 280: my $increment=1;
1.89 albertel 281: my $result = '';
282: if (!$Apache::lonxml::default_homework_loaded) {
283: &Apache::lonxml::default_homework_load($safeeval);
1.34 albertel 284: }
1.167 albertel 285: my $partid = $Apache::inputtags::part;
286: my $id = $Apache::inputtags::response[-1];
1.125 albertel 287: my $tag;
1.168 albertel 288: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
1.125 albertel 289: if (scalar(@$tagstack)) { $tag=$$tagstack[-1]; }
1.162 albertel 290: if ( $target eq 'grade' && &Apache::response::submitted() ) {
1.140 albertel 291: &Apache::response::setup_params($tag,$safeeval);
1.95 albertel 292: if ($Apache::lonhomework::type eq 'exam' &&
1.125 albertel 293: $tag eq 'formularesponse') {
1.95 albertel 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:
1.162 albertel 302: if ( &Apache::response::submitted('scantron')) {
1.184 ! albertel 303: my ($values,$display)=&make_numerical_bubbles($partid,$id,
! 304: $target,$parstack,$safeeval);
1.158 albertel 305: $response=$values->[$response];
1.95 albertel 306: }
1.115 albertel 307: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
1.181 albertel 308: my ($ad,$msg)=&check_submission($response,$partid,$id,
309: $tag,$parstack,$safeeval);
1.167 albertel 310:
1.142 albertel 311: &Apache::lonxml::debug('ad is'.$ad);
312: if ($ad eq 'SIG_FAIL') {
313: my ($sig_u,$sig_l)=
314: &get_sigrange($Apache::inputtags::params{'sig'});
315: $msg=join(':',$msg,$sig_l,$sig_u);
316: &Apache::lonxml::debug("sigs bad $sig_u $sig_l ".
317: $Apache::inputtags::params{'sig'});
318: }
1.95 albertel 319: &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
1.163 albertel 320: if ($Apache::lonhomework::type eq 'survey' &&
321: ($ad eq 'INCORRECT' || $ad eq 'APPROX_ANS' ||
322: $ad eq 'EXACT_ANS')) {
323: $ad='SUBMITTED';
324: }
1.95 albertel 325: &Apache::response::handle_previous(\%previous,$ad);
326: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
1.142 albertel 327: $Apache::lonhomework::results{"resource.$partid.$id.awardmsg"}=$msg;
1.95 albertel 328: $result='';
1.90 albertel 329: }
1.89 albertel 330: }
331: } elsif ($target eq 'web' || $target eq 'tex') {
1.90 albertel 332: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
333: $safeeval);
1.89 albertel 334: my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
335: my $status = $Apache::inputtags::status['-1'];
336: if ($Apache::lonhomework::type eq 'exam') {
1.184 ! albertel 337: my ($bubble_values,$bubble_display)=
! 338: &make_numerical_bubbles($partid,$id,$target,$parstack,
! 339: $safeeval);
! 340: my $number_of_bubbles = scalar(@{ $bubble_values });
1.89 albertel 341: my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
342: $safeeval);
343: my @alphabet=('A'..'Z');
344: if ($target eq 'web') {
1.125 albertel 345: if ($tag eq 'numericalresponse') {
1.89 albertel 346: if ($unit=~/\S/) {$result.=' (in '.$unit.')<br /><br />';}
347: $result.= '<table border="1"><tr>';
1.116 albertel 348: my $previous=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.$id.submission"};
1.90 albertel 349: for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
1.116 albertel 350: my $checked='';
1.158 albertel 351: if ($previous eq $bubble_values->[$ind]) {
1.116 albertel 352: $checked=" checked='on' ";
353: }
1.90 albertel 354: $result.='<td><input type="radio" name="HWVAL_'.$id.
1.158 albertel 355: '" value="'.$bubble_values->[$ind].'" '.$checked
1.116 albertel 356: .' /><b>'.$alphabet[$ind].'</b>: '.
1.158 albertel 357: $bubble_display->[$ind].'</td>';
1.89 albertel 358: }
359: $result.='</tr></table>';
1.125 albertel 360: } elsif ($tag eq 'formularesponse') {
1.90 albertel 361: $result.= '<br /><br /><font color="red">
362: <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
363: </textarea></font> <br /><br />';
1.89 albertel 364: }
365: } elsif ($target eq 'tex') {
1.107 sakharuk 366: if ((defined $unit) and ($unit=~/\S/) and ($Apache::lonhomework::type eq 'exam')) {
1.89 albertel 367: $result.=' \textit{(in} \verb|'.$unit.'|\textit{)} ';
368: }
1.125 albertel 369: if ($tag eq 'numericalresponse') {
1.90 albertel 370: my ($celllength,$number_of_tables,@table_range)=
1.159 albertel 371: &get_table_sizes($number_of_bubbles,$bubble_display);
1.89 albertel 372: my $j=0;
373: my $cou=0;
374: $result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]';
375: for (my $i=0;$i<$number_of_tables;$i++) {
1.144 sakharuk 376: $result.='\vskip -1 mm \noindent \setlength{\tabcolsep}{2 mm}\begin{tabular}{';
1.90 albertel 377: for (my $ind=0;$ind<$table_range[$j];$ind++) {
1.128 sakharuk 378: $result.='p{3 mm}p{'.$celllength.' mm}';
1.89 albertel 379: }
380: $result.='}';
1.90 albertel 381: for (my $ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
1.159 albertel 382: $result.='\hskip -4 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$ & \hskip -3 mm {\small '.$bubble_display->[$ind].'} ';
1.89 albertel 383: if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
384: }
385: $cou += $table_range[$j];
386: $j++;
387: $result.='\\\\\end{tabular}\vskip 0 mm ';
388: }
389: $result.='\end{enumerate}';
390: } else {
391: $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
1.93 albertel 392: my $repetition = &Apache::response::repetition();
1.89 albertel 393: $result.='\begin{enumerate}';
394: for (my $i=0;$i<$repetition;$i++) {
1.93 albertel 395: $result.='\item[\textbf{'.($Apache::lonxml::counter+$i).'}.]\textit{Leave blank on scoring form}\vskip 0 mm';
1.89 albertel 396: }
1.90 albertel 397: $increment=$repetition;
1.89 albertel 398: $result.= '\end{enumerate}';
399: }
400: }
401: }
402: } elsif ($target eq 'edit') {
403: $result.='</td></tr>'.&Apache::edit::end_table;
404: } elsif ($target eq 'answer' || $target eq 'analyze') {
1.167 albertel 405: my $part_id="$partid.$id";
1.89 albertel 406: if ($target eq 'analyze') {
407: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.125 albertel 408: $Apache::lonhomework::analyze{"$part_id.type"} = $tag;
1.117 albertel 409: my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
1.161 albertel 410: if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); }
1.117 albertel 411: push (@{ $Apache::lonhomework::analyze{"$part_id.incorrect"} }, @incorrect);
1.154 albertel 412: &Apache::response::check_if_computed($token,$parstack,
413: $safeeval,'answer');
1.89 albertel 414: }
1.125 albertel 415: if (scalar(@$tagstack)) {
1.140 albertel 416: &Apache::response::setup_params($tag,$safeeval);
1.125 albertel 417: }
1.89 albertel 418: my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
1.58 sakharuk 419: my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
420: my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval);
1.89 albertel 421: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval);
422:
423: if ($target eq 'answer') {
1.125 albertel 424: $result.=&Apache::response::answer_header($tag);
1.184 ! albertel 425: if ($Apache::lonhomework::type eq 'exam') {
! 426: my ($bubble_values,undef,$correct) = &make_numerical_bubbles($partid,
! 427: $id,$target,$parstack,$safeeval);
! 428: $result.=&Apache::response::answer_part($tag,$correct);
! 429: }
1.89 albertel 430: }
1.176 albertel 431: my ($sigline,$tolline);
1.89 albertel 432: for(my $i=0;$i<=$#answers;$i++) {
433: my $ans=$answers[$i];
1.90 albertel 434: my $fmt=$formats[0];
435: if (@formats && $#formats) {$fmt=$formats[$i];}
1.89 albertel 436: my ($high,$low);
437: if ($Apache::inputtags::params{'tol'}) {
438: ($high,$low)=&get_tolrange($ans,$Apache::inputtags::params{'tol'});
439: }
440: my ($sighigh,$siglow);
441: if ($Apache::inputtags::params{'sig'}) {
442: ($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'});
443: }
1.125 albertel 444: if ($fmt && $tag eq 'numericalresponse') {
1.112 albertel 445: $fmt=~s/e/E/g;
1.156 albertel 446: if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; }
447: if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }
1.153 albertel 448: $ans = &format_number($ans,$fmt,$target,$safeeval);
1.155 albertel 449: #if ($high) {
450: # $high=&format_number($high,$fmt,$target,$safeeval);
451: # $low =&format_number($low,$fmt,$target,$safeeval);
452: #}
1.60 sakharuk 453: }
1.89 albertel 454: if ($target eq 'answer') {
1.176 albertel 455: if ($high && $tag eq 'numericalresponse') {
456: $ans.=' ['.$low.','.$high.']';
457: $tolline .= "[$low, $high]";
458: }
1.145 albertel 459: if (defined($sighigh) && $tag eq 'numericalresponse') {
1.166 albertel 460: if ($env{'form.answer_output_mode'} eq 'tex') {
1.106 sakharuk 461: $ans.= " Sig $siglow - $sighigh";
1.98 sakharuk 462: } else {
1.101 albertel 463: $ans.= " Sig <i>$siglow - $sighigh</i>";
1.176 albertel 464: $sigline .= "[$siglow, $sighigh]";
1.98 sakharuk 465: }
466: }
1.125 albertel 467: $result.=&Apache::response::answer_part($tag,$ans);
1.89 albertel 468: } elsif ($target eq 'analyze') {
469: push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans);
470: if ($high) {
471: push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"} }, $high);
472: push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"} }, $low);
1.58 sakharuk 473: }
1.165 albertel 474: if ($fmt) {
475: push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt);
476: }
1.79 sakharuk 477: }
1.176 albertel 478: }
479:
480: my @fmt_ans;
481: for(my $i=0;$i<=$#answers;$i++) {
482: my $ans=$answers[$i];
483: my $fmt=$formats[0];
484: if (@formats && $#formats) {$fmt=$formats[$i];}
485: if ($fmt && $tag eq 'numericalresponse') {
486: $fmt=~s/e/E/g;
487: if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; }
488: if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }
489: $ans = &format_number($ans,$fmt,$target,$safeeval);
1.177 albertel 490: if ($fmt=~/\$/ && $unit!~/\$/) { $ans=~s/\$//; }
1.176 albertel 491: }
492: push(@fmt_ans,$ans);
493: }
494: my $response=join(', ',@fmt_ans);
495: my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.
496: $id.'.turnoffunit');
497: if ($unit ne '' &&
498: ! ($Apache::lonhomework::type eq 'exam' ||
499: lc($hideunit) eq "yes") ) {
500: my $cleanunit=$unit;
501: $cleanunit=~s/\$\,//g;
502: $response.=" $cleanunit";
503: }
504:
1.181 albertel 505: my ($ad,$msg)=&check_submission($response,$partid,$id,$tag,
506: $parstack,$safeeval);
1.176 albertel 507: if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
508: my $error;
509: if ($tag eq 'formularesponse') {
1.183 albertel 510: $error=&mt('Computer\'s answer is incorrect ("[_1]").',$response);
1.176 albertel 511: } else {
512: # answer failed check if it is sig figs that is failing
1.181 albertel 513: my ($ad,$msg)=&check_submission($response,$partid,$id,
514: $tag,$parstack,
515: $safeeval,1);
1.176 albertel 516: if ($sigline ne '') {
517: $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);
1.171 albertel 518: } else {
1.180 albertel 519: $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] needs to be adjusted.',$response,$tolline);
1.171 albertel 520: }
1.167 albertel 521: }
1.176 albertel 522: if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
523: &Apache::lonxml::error($error);
524: } else {
525: &Apache::lonxml::warning($error);
526: }
1.36 albertel 527: }
1.176 albertel 528:
1.102 albertel 529: if (defined($unit) and ($unit ne '') and
1.125 albertel 530: $tag eq 'numericalresponse') {
1.89 albertel 531: if ($target eq 'answer') {
1.166 albertel 532: if ($env{'form.answer_output_mode'} eq 'tex') {
1.125 albertel 533: $result.=&Apache::response::answer_part($tag,
1.106 sakharuk 534: " Unit: $unit ");
1.98 sakharuk 535: } else {
1.125 albertel 536: $result.=&Apache::response::answer_part($tag,
1.98 sakharuk 537: "Unit: <b>$unit</b>");
538: }
1.89 albertel 539: } elsif ($target eq 'analyze') {
1.103 albertel 540: push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} }, $unit);
1.89 albertel 541: }
542: }
1.125 albertel 543: if ($tag eq 'formularesponse' && $target eq 'answer') {
1.89 albertel 544: my $samples=&Apache::lonxml::get_param('samples',$parstack,$safeeval);
1.125 albertel 545: $result.=&Apache::response::answer_part($tag,$samples);
1.89 albertel 546: }
547: if ($target eq 'answer') {
1.125 albertel 548: $result.=&Apache::response::answer_footer($tag);
1.89 albertel 549: }
1.69 sakharuk 550: }
1.121 sakharuk 551: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.90 albertel 552: $target eq 'tex' || $target eq 'analyze') {
553: &Apache::lonxml::increment_counter($increment);
554: }
1.89 albertel 555: &Apache::response::end_response;
556: return $result;
1.90 albertel 557: }
558:
559: sub get_table_sizes {
1.128 sakharuk 560: my ($number_of_bubbles,$rbubble_values)=@_;
561: my $scale=2; #mm for one digit
562: my $cell_width=0;
563: foreach my $member (@$rbubble_values) {
564: my $cell_width_real=0;
1.160 albertel 565: if ($member=~/(\+|-)?(\d*)\.?(\d*)\s*\$?\\times\s*10\^{(\+|-)?(\d+)}\$?/) {
1.138 sakharuk 566: $cell_width_real=(length($2)+length($3)+length($5)+7)*$scale;
567: } elsif ($member=~/(\d*)\.?(\d*)(E|e)(\+|-)?(\d*)/) {
1.128 sakharuk 568: $cell_width_real=(length($1)+length($2)+length($5)+9)*$scale;
1.138 sakharuk 569: } elsif ($member=~/(\d*)\.(\d*)/) {
1.132 sakharuk 570: $cell_width_real=(length($1)+length($2)+3)*$scale;
1.128 sakharuk 571: } else {
1.138 sakharuk 572: $cell_width_real=(length($member)+1)*$scale*0.9;
1.128 sakharuk 573: }
574: if ($cell_width_real>$cell_width) {$cell_width=$cell_width_real;}
1.90 albertel 575: }
1.132 sakharuk 576: $cell_width+=8;
1.130 sakharuk 577: my $textwidth;
1.166 albertel 578: if ($env{'form.textwidth'} ne '') {
579: $env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
1.132 sakharuk 580: $textwidth=$1.'.'.$2;
1.130 sakharuk 581: } else {
1.166 albertel 582: $env{'form.textwidth'}=~/(\d+)\.?(\d*)/;
1.132 sakharuk 583: $textwidth=$1.'.'.$2;
1.130 sakharuk 584: }
1.128 sakharuk 585: my $bubbles_per_line=int($textwidth/$cell_width);
1.151 sakharuk 586: if ($bubbles_per_line > $number_of_bubbles) {
587: $bubbles_per_line=$number_of_bubbles;
588: }elsif (($bubbles_per_line > $number_of_bubbles/2) && ($number_of_bubbles % 2==0)) {$bubbles_per_line=$number_of_bubbles/2;}
1.128 sakharuk 589: my $number_of_tables = int($number_of_bubbles/$bubbles_per_line);
1.90 albertel 590: my @table_range = ();
1.128 sakharuk 591: for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$bubbles_per_line;}
592: if ($number_of_bubbles % $bubbles_per_line) {
1.90 albertel 593: $number_of_tables++;
1.128 sakharuk 594: push @table_range,($number_of_bubbles % $bubbles_per_line);
1.90 albertel 595: }
1.128 sakharuk 596: $cell_width-=8;
1.136 sakharuk 597: $cell_width=$cell_width*3/4;
1.128 sakharuk 598: return ($cell_width,$number_of_tables,@table_range);
1.90 albertel 599: }
600:
601: sub format_number {
1.153 albertel 602: my ($number,$format,$target,$safeeval)=@_;
1.90 albertel 603: my $ans;
1.153 albertel 604: if ($format eq '') {
1.90 albertel 605: #What is the number? (integer,decimal,floating point)
606: if ($number=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
1.113 sakharuk 607: $format = '3e';
1.90 albertel 608: } elsif ($number=~/^(\d*)\.(\d*)$/) {
609: $format = '4f';
610: } elsif ($number=~/^(\d*)$/) {
611: $format = 'd';
612: }
613: }
1.156 albertel 614: if (!$Apache::lonxml::default_homework_loaded) {
615: &Apache::lonxml::default_homework_load($safeeval);
616: }
1.153 albertel 617: $ans=&Apache::run::run("&prettyprint(q\0$number\0,q\0$format\0,q\0$target\0)",$safeeval);
1.90 albertel 618: return $ans;
619: }
620:
621: sub make_numerical_bubbles {
1.184 ! albertel 622: my ($part,$id,$target,$parstack,$safeeval) =@_;
! 623:
! 624: my $number_of_bubbles =
! 625: &Apache::response::get_response_param($part.'_'.$id,'numbubbles',8);
! 626:
! 627: my ($format)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
! 628: my ($answer)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
! 629: my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,
! 630: $safeeval);
! 631: if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); }
! 632:
1.158 albertel 633: my @bubble_values=();
1.184 ! albertel 634: my @alphabet=('A'..'Z');
! 635:
! 636: &Apache::lonxml::debug("answer is $answer incorrect is @incorrect");
1.119 albertel 637: my @oldseed=&Math::Random::random_get_seed();
1.184 ! albertel 638: if (@incorrect) {
! 639: &Apache::lonxml::debug("inside ".(scalar(@incorrect)+1 gt $number_of_bubbles));
! 640: if (defined($incorrect[0]) &&
! 641: scalar(@incorrect)+1 >= $number_of_bubbles) {
! 642: &Apache::lonxml::debug("inside ".(scalar(@incorrect)+1).":$number_of_bubbles");
1.117 albertel 643: &Apache::response::setrandomnumber();
1.184 ! albertel 644: my @rand_inc=&Math::Random::random_permutation(@incorrect);
1.117 albertel 645: @bubble_values=@rand_inc[0..($number_of_bubbles-2)];
646: @bubble_values=sort {$a <=> $b} (@bubble_values,$answer);
1.184 ! albertel 647: &Apache::lonxml::debug("Answer was :$answer: returning :".$#bubble_values.": which are :".join(':',@bubble_values));
1.119 albertel 648: &Math::Random::random_set_seed(@oldseed);
1.184 ! albertel 649:
! 650: my $correct;
! 651: for(my $i=0; $i<=$#bubble_values;$i++) {
! 652: if ($bubble_values[$i] eq $answer) {
! 653: $correct = $alphabet[$i];
! 654: last;
! 655: }
! 656: }
! 657:
1.134 albertel 658: if (defined($format) && $format ne '') {
1.158 albertel 659: my @bubble_display;
1.137 albertel 660: foreach my $value (@bubble_values) {
1.158 albertel 661: push(@bubble_display,
662: &format_number($value,$format,$target,$safeeval));
1.134 albertel 663: }
1.184 ! albertel 664: return (\@bubble_values,\@bubble_display,$correct);
1.158 albertel 665: } else {
1.184 ! albertel 666: return (\@bubble_values,\@bubble_values,$correct);
1.134 albertel 667: }
1.117 albertel 668: }
1.184 ! albertel 669: if (defined($incorrect[0]) &&
! 670: scalar(@incorrect)+1 < $number_of_bubbles) {
! 671: &Apache::lonxml::warning("Not enough incorrect answers were specified in the incorrect array, ignoring the specified incorrect answers and instead generating them (".join(',',@incorrect).").");
1.127 albertel 672: }
1.117 albertel 673: }
1.90 albertel 674: my @factors = (1.13,1.17,1.25,1.33,1.45); #default values of factors
1.126 albertel 675: my @powers = (1..$number_of_bubbles);
1.90 albertel 676: &Apache::response::setrandomnumber();
677: my $ind=&Math::Random::random_uniform_integer(1,0,$#powers);
678: my $power = $powers[$ind];
679: $ind=&Math::Random::random_uniform_integer(1,0,$#factors);
680: my $factor = $factors[$ind];
1.158 albertel 681: my @bubble_display;
1.90 albertel 682: for ($ind=0;$ind<$number_of_bubbles;$ind++) {
1.91 albertel 683: $bubble_values[$ind] = $answer*($factor**($power-$powers[$#powers-$ind]));
1.158 albertel 684: $bubble_display[$ind] = &format_number($bubble_values[$ind],
1.153 albertel 685: $format,$target,$safeeval);
1.91 albertel 686:
1.90 albertel 687: }
1.184 ! albertel 688: my $correct = $alphabet[$number_of_bubbles-$power];
1.119 albertel 689: &Math::Random::random_set_seed(@oldseed);
1.184 ! albertel 690: return (\@bubble_values,\@bubble_display,$correct);
1.51 albertel 691: }
692:
693: sub get_tolrange {
1.89 albertel 694: my ($ans,$tol)=@_;
695: my ($high,$low);
696: if ($tol =~ /%$/) {
697: chop($tol);
698: my $change=$ans*($tol/100.0);
699: $high=$ans+$change;
700: $low=$ans-$change;
701: } else {
702: $high=$ans+$tol;
703: $low=$ans-$tol;
704: }
705: return ($high,$low);
1.52 albertel 706: }
707:
708: sub get_sigrange {
1.89 albertel 709: my ($sig)=@_;
710: &Apache::lonxml::debug("Got a sig of :$sig:");
1.166 albertel 711: my $courseid=$env{'request.course.id'};
712: if (lc($env{"course.$courseid.disablesigfigs"}) eq 'yes') {
1.147 albertel 713: return (15,0);
714: }
1.89 albertel 715: my $sig_lbound;
716: my $sig_ubound;
717: if ($sig eq '') {
718: $sig_lbound = 0; #SIG_LB_DEFAULT
719: $sig_ubound =15; #SIG_UB_DEFAULT
720: } else {
721: ($sig_lbound,$sig_ubound) = split(/,/,$sig);
1.145 albertel 722: if (!defined($sig_lbound)) {
1.89 albertel 723: $sig_lbound = 0; #SIG_LB_DEFAULT
724: $sig_ubound =15; #SIG_UB_DEFAULT
725: }
1.145 albertel 726: if (!defined($sig_ubound)) { $sig_ubound=$sig_lbound; }
1.133 albertel 727: }
728: if (($sig_ubound<$sig_lbound) ||
729: ($sig_lbound > 15) ||
730: ($sig =~/(\+|-)/ ) ) {
731: my $errormsg=&mt("Invalid Significant figures detected")." ($sig)";
1.166 albertel 732: if ($env{'request.state'} eq 'construct') {
1.133 albertel 733: $errormsg.=
734: &Apache::loncommon::help_open_topic('Significant_Figures');
735: }
736: &Apache::lonxml::error($errormsg);
1.52 albertel 737: }
1.89 albertel 738: return ($sig_ubound,$sig_lbound);
1.34 albertel 739: }
740:
741: sub start_stringresponse {
1.89 albertel 742: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
743: my $result;
1.122 albertel 744: my $id = &Apache::response::start_response($parstack,$safeeval);
1.89 albertel 745: if ($target eq 'meta') {
746: $result=&Apache::response::meta_package_write('stringresponse');
1.122 albertel 747: } elsif ($target eq 'edit') {
748: $result.=&Apache::edit::tag_start($target,$token);
749: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
750: $result.=&Apache::edit::select_arg('Type:','type',
751: [['cs','Case Sensitive'],['ci','Case Insensitive'],
752: ['mc','Case Insensitive, Any Order'],
753: ['re','Regular Expression']],$token);
1.152 albertel 754: $result.=&Apache::edit::text_arg('String to display for answer:',
755: 'answerdisplay',$token);
1.122 albertel 756: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
757: } elsif ($target eq 'modified') {
1.146 albertel 758: my $constructtag;
759: $constructtag=&Apache::edit::get_new_args($token,$parstack,
760: $safeeval,'answer',
761: 'type','answerdisplay');
762: if ($constructtag) {
763: $result = &Apache::edit::rebuild_tag($token);
764: $result.=&Apache::edit::handle_insert();
765: }
766: } elsif ($target eq 'web') {
767: if ( &Apache::response::show_answer() ) {
1.152 albertel 768: my $answer=
769: &Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval);
770: if (!defined $answer || $answer eq '') {
771: $answer=
772: &Apache::lonxml::get_param('answer',$parstack,$safeeval);
773: }
774: $Apache::inputtags::answertxt{$id}=$answer;
1.146 albertel 775: }
1.122 albertel 776: } elsif ($target eq 'answer' || $target eq 'grade') {
777: &Apache::response::reset_params();
1.89 albertel 778: }
779: return $result;
1.34 albertel 780: }
781:
782: sub end_stringresponse {
1.122 albertel 783: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
784: my $increment=1;
785: my $result = '';
786: my $part=$Apache::inputtags::part;
787: my $id=$Apache::inputtags::response[-1];
788: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
789: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval);
1.129 www 790: my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval);
1.122 albertel 791: &Apache::lonxml::debug("current $answer ".$token->[2]);
792: if (!$Apache::lonxml::default_homework_loaded) {
793: &Apache::lonxml::default_homework_load($safeeval);
794: }
1.162 albertel 795: if ( $target eq 'grade' && &Apache::response::submitted() ) {
1.140 albertel 796: &Apache::response::setup_params('stringresponse',$safeeval);
1.122 albertel 797: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
798: if ($Apache::lonhomework::type eq 'exam' ||
1.162 albertel 799: &Apache::response::submitted('scantron')) {
1.122 albertel 800: $increment=&Apache::response::scored_response($part,$id);
801: } else {
802: my $response = &Apache::response::getresponse();
803: if ( $response =~ /[^\s]/) {
804: my %previous = &Apache::response::check_for_previous($response,
805: $part,$id);
806: &Apache::lonxml::debug("submitted a $response<br>\n");
807: &Apache::lonxml::debug($$parstack[-1] . "\n<br>");
808: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
809: $response;
1.142 albertel 810: my ($ad,$msg);
1.122 albertel 811: if ($type eq 're' ) {
812: # if the RE wasn't in a var it likely got munged,
813: # thus grab it from the var directly
814: # my $testans=$token->[2]->{'answer'};
815: # if ($testans !~ m/^\s*\$/) {
816: # $answer=$token->[2]->{'answer'};
817: # }
1.143 albertel 818: ${$safeeval->varglob('LONCAPA::response')}=$response;
1.179 albertel 819: $result = &Apache::run::run('if ($LONCAPA::response=~m'.$answer.') { return 1; } else { return 0; }',$safeeval);
1.122 albertel 820: &Apache::lonxml::debug("current $response");
821: &Apache::lonxml::debug("current $answer");
822: $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
823: } else {
1.143 albertel 824: my $args_ref=
825: \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
826:
827: $$args_ref{'response'}=$response;
1.122 albertel 828: &Apache::lonxml::debug("current $response");
1.143 albertel 829: $$args_ref{'type'}=
830: &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.122 albertel 831: foreach my $key (keys(%Apache::inputtags::params)) {
1.143 albertel 832: $$args_ref{$key}=$Apache::inputtags::params{$key};
1.122 albertel 833: }
834: &Apache::lonxml::debug('answer is'.join(':',$answer));
1.143 albertel 835: @{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=($answer);
836: ($result, my @msgs)=&Apache::run::run("&caparesponse_check_list()",$safeeval);
1.142 albertel 837: &Apache::lonxml::debug('msgs are'.join(':',@msgs));
838: my ($awards)=split(/:/,$result);
839: my (@awards) = split(/,/,$awards);
840: ($ad,$msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
1.122 albertel 841: &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
842: }
1.163 albertel 843: if ($Apache::lonhomework::type eq 'survey' &&
844: ($ad eq 'INCORRECT' || $ad eq 'APPROX_ANS' ||
845: $ad eq 'EXACT_ANS')) {
846: $ad='SUBMITTED';
847: }
1.122 albertel 848: &Apache::response::handle_previous(\%previous,$ad);
849: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
1.142 albertel 850: $Apache::lonhomework::results{"resource.$part.$id.awardmsg"}=$msg;
1.122 albertel 851: }
852: }
853: } elsif ($target eq 'web' || $target eq 'tex') {
854: my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
855: my $status = $Apache::inputtags::status['-1'];
856: if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') {
857: $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
858: $increment = &Apache::response::repetition();
859: $result.='\begin{enumerate}';
860: for (my $i=0;$i<$increment;$i++) {
861: $result.='\item[\textbf{'.($Apache::lonxml::counter+$i).
862: '}.]\textit{Leave blank on scoring form}\vskip 0 mm';
863: }
864: $result.= '\end{enumerate}';
865: }
866: } elsif ($target eq 'answer' || $target eq 'analyze') {
867: if ($target eq 'analyze') {
868: push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
1.125 albertel 869: $Apache::lonhomework::analyze{"$part.$id.type"} = 'stringresponse';
1.154 albertel 870: &Apache::response::check_if_computed($token,$parstack,$safeeval,
871: 'answer');
1.122 albertel 872: }
1.140 albertel 873: &Apache::response::setup_params('stringresponse',$safeeval);
1.122 albertel 874: if ($target eq 'answer') {
1.125 albertel 875: $result.=&Apache::response::answer_header('stringresponse');
1.122 albertel 876: }
877: # foreach my $ans (@answers) {
878: if ($target eq 'answer') {
1.125 albertel 879: $result.=&Apache::response::answer_part('stringresponse',$answer);
1.178 albertel 880: if ($type eq 're') {
881: $result.=&Apache::response::answer_part('stringresponse',
882: $answerdisplay);
883: }
1.122 albertel 884: } elsif ($target eq 'analyze') {
885: push (@{ $Apache::lonhomework::analyze{"$part.$id.answer"} },
886: $answer);
887: }
888: # }
889: my $string='Case Insensitive';
890: if ($type eq 'mc') {
891: $string='Multiple Choice';
892: } elsif ($type eq 'cs') {
893: $string='Case Sensitive';
894: } elsif ($type eq 'ci') {
895: $string='Case Insensitive';
896: } elsif ($type eq 're') {
897: $string='Regular Expression';
898: }
899: if ($target eq 'answer') {
1.166 albertel 900: if ($env{'form.answer_output_mode'} eq 'tex') {
1.125 albertel 901: $result.=&Apache::response::answer_part('stringresponse',
1.122 albertel 902: "$string");
903: } else {
1.125 albertel 904: $result.=&Apache::response::answer_part('stringresponse',
1.122 albertel 905: "<b>$string</b>");
906: }
907: } elsif ($target eq 'analyze') {
908: push (@{$Apache::lonhomework::analyze{"$part.$id.str_type"}},
909: $type);
910: }
911: if ($target eq 'answer') {
1.125 albertel 912: $result.=&Apache::response::answer_footer('stringresponse');
1.122 albertel 913: }
914: } elsif ($target eq 'edit') {
915: $result.='</td></tr>'.&Apache::edit::end_table;
916: }
917: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
918: $target eq 'tex' || $target eq 'analyze') {
919: &Apache::lonxml::increment_counter($increment);
920: }
921: &Apache::response::end_response;
922: return $result;
1.44 albertel 923: }
924:
925: sub start_formularesponse {
1.89 albertel 926: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
927: my $result;
928: if ($target eq 'meta') {
1.104 bowersj2 929: &Apache::response::start_response($parstack,$safeeval);
1.89 albertel 930: $result=&Apache::response::meta_package_write('formularesponse');
1.104 bowersj2 931: &Apache::response::end_response();
1.89 albertel 932: } else {
933: $result.=&start_numericalresponse(@_);
934: }
935: return $result;
1.44 albertel 936: }
937:
938: sub end_formularesponse {
1.89 albertel 939: return end_numericalresponse(@_);
1.3 albertel 940: }
941:
1.1 albertel 942: 1;
1.3 albertel 943: __END__
1.89 albertel 944:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>