--- loncom/homework/response.pm 2004/02/16 20:09:51 1.91 +++ loncom/homework/response.pm 2004/03/16 22:00:51 1.95 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # various response type definitons response definition # -# $Id: response.pm,v 1.91 2004/02/16 20:09:51 albertel Exp $ +# $Id: response.pm,v 1.95 2004/03/16 22:00:51 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -28,6 +28,7 @@ package Apache::response; use strict; +use Apache::lonlocal; BEGIN { &Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse')); @@ -45,6 +46,16 @@ sub start_response { push (@Apache::inputtags::response,$id); push (@Apache::inputtags::responselist,$id); @Apache::inputtags::inputlist=(); + if ($Apache::inputtags::part eq '') { + &Apache::lonxml::error(&HTML::Entities::encode(&mt("Found a <*response> outside of a in a ed problem"))); + } + if ($Apache::inputtags::response_with_no_part && + $Apache::inputtags::part ne '0') { + &Apache::lonxml::error(&HTML::Entities::encode(&mt("<*response>s are both inside of and outside of , this is not a valid problem, errors in grading may occur.")).'
'); + } + if ($Apache::inputtags::part eq '0') { + $Apache::inputtags::response_with_no_part=1; + } return $id; } @@ -262,7 +273,7 @@ sub end_dataresponse { my ($symb,$courseid,$domain,$name)=&Apache::lonxml::whichuser(); my $allowed=&Apache::lonnet::allowed('mgr',$courseid); if ($allowed) { - &Apache::response::setup_params('dataresponse'); + &Apache::response::setup_params('dataresponse',$safeeval); my $partid = $Apache::inputtags::part; my $id = $Apache::inputtags::response['-1']; my $response = $ENV{'form.HWVAL_'.$id}; @@ -382,7 +393,7 @@ sub reset_params { } sub setup_params { - my ($tag) = @_; + my ($tag,$safeeval) = @_; if ($ENV{'request.state'} eq 'construct') { return; } my %paramlist=(); @@ -405,7 +416,9 @@ sub setup_params { &Apache::lonxml::debug("using nothing"); $Apache::inputtags::params{$key}=''; } else { - &Apache::lonxml::debug("using value"); + my $string="{return qq\0".$value."\0}"; + my $newvalue=&Apache::run::run($string,$safeeval,1); + if (defined($newvalue)) { $value=$newvalue; } $Apache::inputtags::params{$key}=$value; } } @@ -619,6 +632,20 @@ sub pick_foil_for_concept { } +sub get_response_param { + my ($id,$name,$default)=@_; + my $parameter; + if ($ENV{'request.state'} eq 'construct' && + defined($Apache::inputtags::params{$name})) { + $parameter=$Apache::inputtags::params{$name}; + } else { + $parameter=&Apache::lonnet::EXT("resource.$id.$name"); + } + if (!defined($parameter) || $parameter eq '') { + $parameter = $default; + } + return $parameter; +} 1; __END__