--- loncom/imspackages/imsprocessor.pm 2005/07/12 16:05:59 1.22 +++ loncom/imspackages/imsprocessor.pm 2005/07/20 05:13:46 1.27 @@ -2095,7 +2095,7 @@ sub parse_webct4_questionDB { $$settings{$id}{$numid}{toltype} = $attr->{type}; } if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_unit") { - my $unitid = $attr->{ident}; + $unitid = $attr->{ident}; %{$$settings{$id}{$numid}{$unitid}} = (); push(@{$$settings{$id}{$numid}{units}},$unitid); $$settings{$id}{$numid}{$unitid}{value} = $attr->{value}; @@ -2864,13 +2864,10 @@ sub write_webct4_questions { $allfeedback .= $feedback; } if ($$settings{$id}{texttype} eq 'text/html') { - $$settings{$id}{text} = &HTML::Entities::decode($$settings{$id}{text}); + $$settings{$id}{text} =~ s/(\&)(nbsp|gt|lt)(?!;)/$1$2;$3/gi; $$settings{$id}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{text}); - $$settings{$id}{text} =~ s#(<img src=["']?)([^>]+)(/?>)#$1../../resfiles/$2 />#gi; + $$settings{$id}{text} =~ s#(<img src=["']?)([^>]+?)(/?>)#$1../../resfiles/$2 />#gi; $$settings{$id}{text} =~ s#<([bh])r>#<$1r />#g; -# $$settings{$id}{text} =~ s#<p>#</p><p>#g; -# $$settings{$id}{text} =~ s#</p></p>#</p>#; -# $$settings{$id}{text} =~ s#<p></p>##g; $$settings{$id}{text} =~ s#<p>#<br /><br />#g; $$settings{$id}{text} =~ s#</p>##g; } @@ -3060,7 +3057,7 @@ sub write_webct4_questions { } else { $output .= qq| <optionresponse max="10" randomize="yes"> - <foilgroup options=$allmatchlist> + <foilgroup options="$allmatchlist"> |; } } else { @@ -3251,11 +3248,34 @@ sub write_webct4_questions { } } } elsif ($$settings{$id}{class} eq 'numerical') { + my %mathfns = ( + 'abs' => 'abs', + 'acos' => 'acos', + 'asin' => 'asin', + 'atan' => 'atan', + 'ceil' => 'ceil', + 'cos' => 'cos', + 'exp' => 'exp', + 'fact' => 'factorial', + 'floor' => 'floor', + 'int' => 'int', + 'ln' => 'log', + 'log' => 'log', + 'max' => 'max', + 'min' => 'min', + 'round' => 'roundto', + 'sin' => 'sin', + 'sqrt' => 'sqrt', + 'tan' => 'tan', + ); + my $scriptblock = qq| <script type="loncapa/perl"> |; foreach my $numid (@{$$settings{$id}{numids}}) { my $formula = $$settings{$id}{$numid}{formula}; + my $pattern = join('|',(sort (keys (%mathfns)))); + $formula =~ s/($pattern)/\&$mathfns{$1}/g; foreach my $var (keys %{$$settings{$id}{$numid}{vars}}) { my $decnum = $$settings{$id}{$numid}{vars}{$var}{dec}; my $increment = '0.'; @@ -3269,9 +3289,7 @@ sub write_webct4_questions { } $increment .= '1'; } - $formula =~ s/{($var)}/\$$1/g; - $formula =~ s/ln\(?([^\)])\)?/ &log($1) /g; - $formula =~ s/sqrt/\&sqrt/g; + $formula =~ s/{($var)}/(\$$1)/g; $scriptblock .= qq| \$$var=&random($$settings{$id}{$numid}{vars}{$var}{min},$$settings{$id}{$numid}{vars}{$var}{max},$increment); |; @@ -3302,7 +3320,7 @@ sub write_webct4_questions { } my $unitentry = ''; if ($unit ne '') { - $unitentry = 'unit='.$unit; + $unitentry = 'unit="'.$unit.'"'; } $output .= qq| <numericalresponse $unitentry $ansformat answer="\$answervar">