--- loncom/homework/response.pm 2006/10/17 19:35:37 1.149 +++ loncom/homework/response.pm 2006/12/11 17:37:43 1.153 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # various response type definitons response definition # -# $Id: response.pm,v 1.149 2006/10/17 19:35:37 albertel Exp $ +# $Id: response.pm,v 1.153 2006/12/11 17:37:43 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,6 +30,7 @@ package Apache::response; use strict; use Apache::lonlocal; use Apache::lonnet; +use Apache::lonmaxima(); BEGIN { &Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse','customresponse','mathresponse')); @@ -373,7 +374,7 @@ sub start_customresponse { if ( &Apache::response::show_answer() ) { my $answer = &Apache::lonxml::get_param('answerdisplay',$parstack, $safeeval); - $Apache::inputtags::answertxt{$id}=$answer; + $Apache::inputtags::answertxt{$id}=[$answer]; } } elsif ($target eq 'edit') { $result.=&Apache::edit::tag_start($target,$token); @@ -464,23 +465,33 @@ sub start_mathresponse { if ( &Apache::response::show_answer() ) { my $answer = &Apache::lonxml::get_param('answerdisplay',$parstack, $safeeval); - $Apache::inputtags::answertxt{$id}=$answer; + $Apache::inputtags::answertxt{$id}=[$answer]; } } elsif ($target eq 'edit') { $result.=&Apache::edit::tag_start($target,$token); $result.=&Apache::edit::text_arg('String to display for answer:', 'answerdisplay',$token); + $result.=&Apache::edit::select_arg('Algebra System:', + 'cas', + ['maxima'], + $token); + $result.=&Apache::edit::text_arg('Argument Array:', + 'args',$token); $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); } elsif ($target eq 'modified') { my $constructtag; $constructtag=&Apache::edit::get_new_args($token,$parstack, - $safeeval,'answerdisplay'); + $safeeval,'answerdisplay','cas','args'); if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); $result.=&Apache::edit::handle_insert(); } } elsif ($target eq 'answer' || $target eq 'grade') { &Apache::response::reset_params(); + my $args_ref= \%{$safeeval->varglob('LONCAPA::mathresponse_args')}; + undef(%{ $args_ref }); + $$args_ref{'cas'}=$token->[2]{'cas'}; + $$args_ref{'args'}=$token->[2]{'args'}; } elsif ($target eq 'meta') { $result .= &Apache::response::meta_package_write('mathresponse'); } @@ -494,8 +505,7 @@ sub end_mathresponse { my $id=$Apache::inputtags::response[-1]; if ( $target eq 'grade' && &Apache::response::submitted() ) { my $response = &Apache::response::getresponse(); - if ( $response =~ /[^\s]/ && - $Apache::response::custom_answer_type eq 'loncapa/perl') { + if ( $response =~ /[^\s]/ ) { if (!$Apache::lonxml::default_homework_loaded) { &Apache::lonxml::default_homework_load($safeeval); } @@ -504,10 +514,11 @@ sub end_mathresponse { $Apache::lonhomework::results{"resource.$part.$id.submission"}= $response; my $error; - ${$safeeval->varglob('LONCAPA::mathresponse_submission')}= - $response; - - my $award = &Apache::run::run('{ my $submission=$LONCAPA::mathresponse_submission;'.$Apache::response::custom_answer.'}',$safeeval); + my $args_ref= \%{$safeeval->varglob('LONCAPA::mathresponse_args')}; + my $award; + if ($$args_ref{'cas'} eq 'maxima') { + $award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer,$response,$$args_ref{'args'}); + } if (!&Apache::inputtags::valid_award($award)) { $error = $award; $award = 'ERROR';