--- loncom/homework/caparesponse/caparesponse.pm 2003/04/08 04:17:13 1.92 +++ loncom/homework/caparesponse/caparesponse.pm 2003/05/19 21:40:04 1.103 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # caparesponse definition # -# $Id: caparesponse.pm,v 1.92 2003/04/08 04:17:13 albertel Exp $ +# $Id: caparesponse.pm,v 1.103 2003/05/19 21:40:04 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -79,6 +79,16 @@ sub start_numericalresponse { $result=&Apache::response::meta_package_write('numericalresponse'); } elsif ($target eq 'answer' || $target eq 'grade') { &Apache::response::reset_params(); + } elsif ($target eq 'web') { + my $partid = $Apache::inputtags::part; + my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit'); + &Apache::lonxml::debug("Got unit $hideunit for $partid $id"); + #no way to enter units, with radio buttons + if (lc($hideunit) eq "yes") { + my $unit=&Apache::lonxml::get_param_var('unit',$parstack, + $safeeval); + if ($unit =~ /\S/) { $result.=" (in $unit) "; } + } } return $result; } @@ -90,64 +100,75 @@ sub end_numericalresponse { if (!$Apache::lonxml::default_homework_loaded) { &Apache::lonxml::default_homework_load($safeeval); } - if ( $target eq 'grade' && defined $ENV{'form.submitted'}) { + if ( $target eq 'grade' && defined($ENV{'form.submitted'})) { &Apache::response::setup_params($$tagstack[-1]); $safeeval->share_from('capa',['&caparesponse_capa_check_answer']); my $partid = $Apache::inputtags::part; my $id = $Apache::inputtags::response['-1']; - my $response = &Apache::response::getresponse(); - if ( $response =~ /[^\s]/) { - my $ad; - my %previous = &Apache::response::check_for_previous($response,$partid,$id); - $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response; - &Apache::lonxml::debug("submitted a $response
\n"); - &Apache::lonxml::debug($$parstack[-1] . "\n
"); - - if ($ENV{'form.submitted'} eq 'scantron') { - my $number_of_bubbles = 8;#default values for number of bubbles - my (@formats)=&Apache::lonxml::get_param_var('format', - $parstack,$safeeval); - my (@answers)=&Apache::lonxml::get_param_var('answer', - $parstack,$safeeval); - my @values=&make_numerical_bubbles($number_of_bubbles,$target, - $answers[0],$formats[0]); - $response=$values[$response]; - } else { - $response =~ s/\\/\\\\/g; - $response =~ s/\'/\\\'/g; - } - &Apache::lonxml::debug("current $response"); - my $expression="&caparesponse_check_list('".$response."','". - $$parstack[-1]; - #no way to enter units, with radio buttons - if ($Apache::lonhomework::type eq 'exam') { - $expression.=';my $unit=undef;'; - } - foreach my $key (keys(%Apache::inputtags::params)) { - $expression.= ';my $'. #' - $key.'="'.$Apache::inputtags::params{$key}.'"'; - } - if ($$tagstack[-1] eq 'formularesponse') { - $expression.=';my $type="fml";'; - } elsif ($$tagstack[-1] eq 'numericalresponse') { - $expression.=';my $type="float";'; - } - $expression.="');"; - $result = &Apache::run::run($expression,$safeeval); - my ($awards) = split /:/ , $result; - ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards); - &Apache::lonxml::debug("$expression"); - &Apache::lonxml::debug("\n
result:$result:$Apache::lonxml::curdepth
\n"); - &Apache::response::handle_previous(\%previous,$ad); - $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; - $result=''; + if ($Apache::lonhomework::type eq 'exam' && + ($$tagstack[-1] eq 'formularesponse' || + $$tagstack[-1] eq 'stringresponse')) { + $increment=&Apache::response::scored_response($partid,$id); + } else { + my $response = &Apache::response::getresponse(); + if ( $response =~ /[^\s]/) { + my $ad; + my %previous = &Apache::response::check_for_previous($response,$partid,$id); + $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response; + &Apache::lonxml::debug("submitted a $response
\n"); + &Apache::lonxml::debug($$parstack[-1] . "\n
"); + + if ($ENV{'form.submitted'} eq 'scantron') { + my $number_of_bubbles = 8;#default values for number of bubbles + my (@formats)=&Apache::lonxml::get_param_var('format', + $parstack,$safeeval); + my (@answers)=&Apache::lonxml::get_param_var('answer', + $parstack,$safeeval); + my @values=&make_numerical_bubbles($number_of_bubbles,$target, + $answers[0],$formats[0]); + $response=$values[$response]; + } else { + $response =~ s/\\/\\\\/g; + $response =~ s/\'/\\\'/g; + } + &Apache::lonxml::debug("current $response"); + my $expression="&caparesponse_check_list('".$response."','". + $$parstack[-1]; + my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit'); + #no way to enter units, with radio buttons + if ($Apache::lonhomework::type eq 'exam' || + lc($hideunit) eq "yes") { + $expression.=';my $unit=undef;'; + } + foreach my $key (keys(%Apache::inputtags::params)) { + $expression.= ';my $'. #' + $key.'="'.$Apache::inputtags::params{$key}.'"'; + } + if ($$tagstack[-1] eq 'formularesponse') { + $expression.=';my $type="fml";'; + } elsif ($$tagstack[-1] eq 'numericalresponse') { + $expression.=';my $type="float";'; + } + $expression.="');"; + $result = &Apache::run::run($expression,$safeeval); + my ($awards) = split /:/ , $result; + ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards); + &Apache::lonxml::debug("$expression"); + &Apache::lonxml::debug("\n
result:$result:$Apache::lonxml::curdepth
\n"); + &Apache::response::handle_previous(\%previous,$ad); + $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; + $result=''; + } } } elsif ($target eq 'web' || $target eq 'tex') { my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack, $safeeval); my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; my $status = $Apache::inputtags::status['-1']; - if ($award =~ /^correct/ || $status eq "SHOW_ANSWER" ) { + if ( ($award =~ /^correct/ + && lc($Apache::lonhomework::problemstatus) ne 'no') + || $status eq "SHOW_ANSWER" + || $ENV{'form.texaward'} eq 'SHOW_ANSWER') { my (@formats)=&Apache::lonxml::get_param_var('format',$parstack, $safeeval); my $unit=&Apache::lonxml::get_param_var('unit',$parstack, @@ -155,7 +176,9 @@ sub end_numericalresponse { if ($target eq 'web') { $result="
The correct answer is "; } elsif ($target eq 'tex') { - #$result='\vskip 0 mm The correct answer is \\texttt{'; + if ($ENV{'form.texaward'} eq 'SHOW_ANSWER') { + $result='\vskip 0 mm The correct answer is \\texttt{ '; + } } for (my $i=0; $i <= $#answers; $i++) { my $answer=$answers[$i]; @@ -173,7 +196,9 @@ sub end_numericalresponse { &Apache::lonxml::debug("no format answer :$answer:"); $formatted="$answer,"; } - + if ($ENV{'form.texaward'} eq 'SHOW_ANSWER') { + $result.=$formatted; + } if ($target eq 'tex') { $formatted=''; #$formatted=&Apache::lonxml::latex_special_symbols($formatted); @@ -183,9 +208,11 @@ sub end_numericalresponse { chop $result; if ($target eq 'web') { $result.=" $unit.
"; - } elsif ($target eq 'tex') { - #$result.=&Apache::lonxml::latex_special_symbols($unit); - #$result.="}. \\vskip 0 mm "; + } elsif ($target eq 'tex') { + if ($ENV{'form.texaward'} eq 'SHOW_ANSWER') { + $result.=&Apache::lonxml::latex_special_symbols($unit); + $result.="}. \\vskip 0 mm "; + } } } if ($Apache::lonhomework::type eq 'exam') { @@ -242,13 +269,10 @@ sub end_numericalresponse { $result.='\end{enumerate}'; } else { $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}'; - my $id = $Apache::inputtags::part; - my $weight = &Apache::lonnet::EXT("resource.$id.weight"); - my $repetition = int $weight/9; - if ($weight % 9 != 0) {$repetition++;} + my $repetition = &Apache::response::repetition(); $result.='\begin{enumerate}'; for (my $i=0;$i<$repetition;$i++) { - $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]\textit{Leave blank on scoring form}\vskip 0 mm'; + $result.='\item[\textbf{'.($Apache::lonxml::counter+$i).'}.]\textit{Leave blank on scoring form}\vskip 0 mm'; } $increment=$repetition; $result.= '\end{enumerate}'; @@ -285,7 +309,7 @@ sub end_numericalresponse { if ($Apache::inputtags::params{'sig'}) { ($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'}); } - if ($fmt) { + if ($fmt && $$tagstack[-1] eq 'numericalresponse') { $ans = sprintf('%.'.$fmt,$ans); if ($high) { $high=sprintf('%.'.$fmt,$high); @@ -293,8 +317,14 @@ sub end_numericalresponse { } } if ($target eq 'answer') { - if ($high) { $ans.=' ['.$low.','.$high.']'; } - if ($sighigh) { $ans.= " Sig $siglow - $sighigh"; } + if ($high && $$tagstack[-1] eq 'numericalresponse') { $ans.=' ['.$low.','.$high.']'; } + if ($sighigh && $$tagstack[-1] eq 'numericalresponse') { + if ($ENV{'form.answer_output_mode'} eq 'tex') { + $ans.= " Sig \\textit{$siglow - $sighigh}"; + } else { + $ans.= " Sig $siglow - $sighigh"; + } + } $result.=&Apache::response::answer_part($$tagstack[-1],$ans); } elsif ($target eq 'analyze') { push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans); @@ -304,16 +334,21 @@ sub end_numericalresponse { } } } - if ($unit) { + if (defined($unit) and ($unit ne '') and + $$tagstack[-1] eq 'numericalresponse') { if ($target eq 'answer') { - $result.=&Apache::response::answer_part($$tagstack[-1], - "Unit: $unit"); + if ($ENV{'form.answer_output_mode'} eq 'tex') { + $result.=&Apache::response::answer_part($$tagstack[-1], + "Unit: \\verb|$unit|"); + } else { + $result.=&Apache::response::answer_part($$tagstack[-1], + "Unit: $unit"); + } } elsif ($target eq 'analyze') { - push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} }, - $unit); + push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} }, $unit); } } - if ($type || $token->[1] eq 'stringresponse') { + if ($type || $$tagstack[-1] eq 'stringresponse') { my $string='Case Insensitive'; if ($type eq 'mc') { $string='Multiple Choice'; @@ -325,10 +360,15 @@ sub end_numericalresponse { $string='Formula'; } if ($target eq 'answer') { - $result.=&Apache::response::answer_part($$tagstack[-1], - ''.$string.''); + if ($ENV{'form.answer_output_mode'} eq 'tex') { + $result.=&Apache::response::answer_part($$tagstack[-1], + "\\textbf{$string}"); + } else { + $result.=&Apache::response::answer_part($$tagstack[-1], + "$string"); + } } elsif ($target eq 'analyze') { - push (@{ $Apache::lonhomework::analyze{"$part_id.type"} }, + push (@{ $Apache::lonhomework::analyze{"$part_id.str_type"} }, $type); } }