version 1.90, 2004/02/09 19:38:00
|
version 1.116, 2005/03/28 23:19:45
|
Line 28
|
Line 28
|
|
|
package Apache::response; |
package Apache::response; |
use strict; |
use strict; |
|
use Apache::lonlocal; |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse')); |
&Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse')); |
Line 45 sub start_response {
|
Line 46 sub start_response {
|
push (@Apache::inputtags::response,$id); |
push (@Apache::inputtags::response,$id); |
push (@Apache::inputtags::responselist,$id); |
push (@Apache::inputtags::responselist,$id); |
@Apache::inputtags::inputlist=(); |
@Apache::inputtags::inputlist=(); |
|
if ($Apache::inputtags::part eq '' && |
|
!$Apache::lonhomework::ignore_response_errors) { |
|
&Apache::lonxml::error(&HTML::Entities::encode(&mt("Found a <*response> outside of a <part> in a <part>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 <part> and outside of <part>, this is not a valid problem, errors in grading may occur."),'<>&"').'<br />'); |
|
} |
|
if ($Apache::inputtags::part eq '0') { |
|
$Apache::inputtags::response_with_no_part=1; |
|
} |
return $id; |
return $id; |
} |
} |
|
|
Line 73 sub end_hintresponse {
|
Line 85 sub end_hintresponse {
|
return ''; |
return ''; |
} |
} |
|
|
# used by response to set the non-safe space random number generator to something |
my @randomseeds; |
# that is stable and unique based on the part number and response number |
sub pushrandomnumber { |
|
my $rand_alg=&Apache::lonnet::get_rand_alg(); |
|
if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' || |
|
$rand_alg eq '64bit2') { |
|
# do nothing |
|
} else { |
|
my @seed=&Math::Random::random_get_seed(); |
|
push (@randomseeds,\@seed); |
|
} |
|
&Apache::response::setrandomnumber(); |
|
} |
|
sub poprandomnumber { |
|
my $rand_alg=&Apache::lonnet::get_rand_alg(); |
|
if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' || |
|
$rand_alg eq '64bit2') { |
|
return; |
|
} |
|
my $seed=pop(@randomseeds); |
|
if ($seed) { |
|
&Math::Random::random_set_seed(@$seed); |
|
} else { |
|
&Apache::lonxml::error("Unable to restore random algorithm."); |
|
} |
|
} |
sub setrandomnumber { |
sub setrandomnumber { |
my $rndseed; |
my $rndseed; |
$rndseed=&Apache::structuretags::setup_rndseed(); |
$rndseed=&Apache::structuretags::setup_rndseed(); |
if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); } |
if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); } |
&Apache::lonxml::debug("randseed $rndseed"); |
&Apache::lonxml::debug("randseed $rndseed"); |
# $rndseed=unpack("%32i",$rndseed); |
# $rndseed=unpack("%32i",$rndseed); |
my $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10); |
my $rand_alg=&Apache::lonnet::get_rand_alg(); |
if (defined($Apache::inputtags::response['-1'])) { |
my $rndmod; |
$rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]); |
if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' || |
} |
$rand_alg eq '64bit2') { |
if ($rndseed =~/,/) { |
$rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10); |
{ |
if (defined($Apache::inputtags::response[-1])) { |
use integer; |
$rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]); |
my ($num1,$num2)=split(/,/,$rndseed); |
} |
$num1+=$rndmod; |
} elsif ($rand_alg eq '64bit3') { |
$num2+=$rndmod; |
$rndmod=(&Apache::lonnet::numval2($Apache::inputtags::part) << 10); |
$rndseed="$num1,$num2"; |
if (defined($Apache::inputtags::response[-1])) { |
|
$rndmod+=&Apache::lonnet::numval2($Apache::inputtags::response[-1]); |
} |
} |
} else { |
} else { |
|
my $shift=(4*scalar(@Apache::inputtags::responselist))%30; |
|
$rndmod=(&Apache::lonnet::numval3($Apache::inputtags::part) << (($shift+15)%30)); |
|
if (defined($Apache::inputtags::response[-1])) { |
|
$rndmod+=(&Apache::lonnet::numval3($Apache::inputtags::response[-1]) << $shift ); |
|
} |
|
} |
|
if ($rndseed =~/([,:])/) { |
|
my $char=$1; |
|
use integer; |
|
my ($num1,$num2)=split(/\Q$char\E/,$rndseed); |
|
$num1+=$rndmod; |
|
$num2+=$rndmod; |
|
if($Apache::lonnet::_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
|
$rndseed=$num1.$char.$num2; |
|
} else { |
$rndseed+=$rndmod; |
$rndseed+=$rndmod; |
|
if($Apache::lonnet::_64bit) { |
|
use integer; |
|
$rndseed=(($rndseed<<32)>>32); |
|
} |
} |
} |
|
&Apache::lonxml::debug("randseed $rndmod $rndseed"); |
&Apache::lonnet::setup_random_from_rndseed($rndseed); |
&Apache::lonnet::setup_random_from_rndseed($rndseed); |
&Apache::lonxml::debug("randseed $rndseed"); |
|
return ''; |
return ''; |
} |
} |
|
|
Line 177 sub meta_part_order {
|
Line 232 sub meta_part_order {
|
if (@Apache::inputtags::partlist) { |
if (@Apache::inputtags::partlist) { |
my @parts=@Apache::inputtags::partlist; |
my @parts=@Apache::inputtags::partlist; |
shift(@parts); |
shift(@parts); |
return '<partorder>'.join(',',@parts).'</partorder>'; |
return '<partorder>'.join(',',@parts).'</partorder>'."\n"; |
} else { |
} else { |
return '<partorder>0</partorder>'; |
return '<partorder>0</partorder>'."\n"; |
|
} |
|
} |
|
|
|
sub meta_response_order { |
|
if (@Apache::inputtags::responselist) { |
|
return '<responseorder>'.join(',',@Apache::inputtags::responselist). |
|
'</responseorder>'."\n"; |
} |
} |
} |
} |
|
|
Line 188 sub check_for_previous {
|
Line 250 sub check_for_previous {
|
my %previous; |
my %previous; |
$previous{'used'} = 0; |
$previous{'used'} = 0; |
foreach my $key (sort(keys(%Apache::lonhomework::history))) { |
foreach my $key (sort(keys(%Apache::lonhomework::history))) { |
if ($key =~ /resource\.$partid\.$id\.submission/) { |
if ($key =~ /resource\.$partid\.$id\.submission$/) { |
&Apache::lonxml::debug("Trying $key"); |
&Apache::lonxml::debug("Trying $key"); |
my $pastresponse=$Apache::lonhomework::history{$key}; |
my $pastresponse=$Apache::lonhomework::history{$key}; |
if ($pastresponse eq $curresponse) { |
if ($pastresponse eq $curresponse) { |
Line 217 sub handle_previous {
|
Line 279 sub handle_previous {
|
if ($$previous{'used'} && ($$previous{'award'} eq $ad) ) { |
if ($$previous{'used'} && ($$previous{'award'} eq $ad) ) { |
if ($$previous{'last'}) { |
if ($$previous{'last'}) { |
push(@Apache::inputtags::previous,'PREVIOUSLY_LAST'); |
push(@Apache::inputtags::previous,'PREVIOUSLY_LAST'); |
} else { |
push(@Apache::inputtags::previous_version,$$previous{'version'}); |
|
} elsif ($Apache::lonhomework::type ne 'survey') { |
push(@Apache::inputtags::previous,'PREVIOUSLY_USED'); |
push(@Apache::inputtags::previous,'PREVIOUSLY_USED'); |
|
push(@Apache::inputtags::previous_version,$$previous{'version'}); |
} |
} |
push(@Apache::inputtags::previous_version,$$previous{'version'}); |
|
} |
} |
} |
} |
|
|
Line 262 sub end_dataresponse {
|
Line 325 sub end_dataresponse {
|
my ($symb,$courseid,$domain,$name)=&Apache::lonxml::whichuser(); |
my ($symb,$courseid,$domain,$name)=&Apache::lonxml::whichuser(); |
my $allowed=&Apache::lonnet::allowed('mgr',$courseid); |
my $allowed=&Apache::lonnet::allowed('mgr',$courseid); |
if ($allowed) { |
if ($allowed) { |
&Apache::response::setup_params('dataresponse'); |
&Apache::response::setup_params('dataresponse',$safeeval); |
my $partid = $Apache::inputtags::part; |
my $partid = $Apache::inputtags::part; |
my $id = $Apache::inputtags::response['-1']; |
my $id = $Apache::inputtags::response['-1']; |
my $response = $ENV{'form.HWVAL_'.$id}; |
my $response = $ENV{'form.HWVAL_'.$id}; |
Line 368 sub end_responseparam {
|
Line 431 sub end_responseparam {
|
} |
} |
|
|
sub start_parameter { |
sub start_parameter { |
my $result = &start_responseparam(@_); |
return &start_responseparam(@_); |
return $result; |
|
} |
} |
|
|
sub end_parameter { |
sub end_parameter { |
my $result = &end_responseparam(@_); |
return &end_responseparam(@_); |
return $result; |
|
} |
} |
|
|
sub reset_params { |
sub reset_params { |
Line 382 sub reset_params {
|
Line 443 sub reset_params {
|
} |
} |
|
|
sub setup_params { |
sub setup_params { |
my ($tag) = @_; |
my ($tag,$safeeval) = @_; |
|
|
if ($ENV{'request.state'} eq 'construct') { return; } |
if ($ENV{'request.state'} eq 'construct') { return; } |
my %paramlist=(); |
my %paramlist=(); |
Line 405 sub setup_params {
|
Line 466 sub setup_params {
|
&Apache::lonxml::debug("using nothing"); |
&Apache::lonxml::debug("using nothing"); |
$Apache::inputtags::params{$key}=''; |
$Apache::inputtags::params{$key}=''; |
} else { |
} 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; |
$Apache::inputtags::params{$key}=$value; |
} |
} |
} |
} |
Line 447 sub answer_footer {
|
Line 510 sub answer_footer {
|
} |
} |
|
|
sub showallfoils { |
sub showallfoils { |
my $return=0; |
if (defined($ENV{'form.showallfoils'})) { |
if (defined($ENV{'form.showallfoils'}) && |
my ($symb)=&Apache::lonxml::whichuser(); |
$ENV{'request.state'} eq 'construct') { |
if ($ENV{'request.state'} eq 'construct' || |
$return=1; |
$ENV{'user.adv'} ) { |
|
return 1; |
|
} |
} |
} |
return $return; |
if ($Apache::lonhomework::type eq 'survey') { return 1; } |
|
return 0; |
} |
} |
|
|
sub getresponse { |
sub getresponse { |
Line 477 sub getresponse {
|
Line 543 sub getresponse {
|
$Apache::lonhomework::results{"resource.$part.$id.scantron"}.= |
$Apache::lonhomework::results{"resource.$part.$id.scantron"}.= |
$response; |
$response; |
if ($resulttype ne 'letter') { |
if ($resulttype ne 'letter') { |
$response = $let_to_num{$response}; |
if ($resulttype eq 'A is 1') { |
|
$response = $let_to_num{$response}+1; |
|
} else { |
|
$response = $let_to_num{$response}; |
|
} |
} |
} |
} else { |
} else { |
$response = $ENV{$formparm}; |
$response = $ENV{$formparm}; |
Line 502 sub scored_response {
|
Line 572 sub scored_response {
|
if ($increase ne '') { $score+=$increase+1; } |
if ($increase ne '') { $score+=$increase+1; } |
} |
} |
my $weight = &Apache::lonnet::EXT("resource.$part.weight"); |
my $weight = &Apache::lonnet::EXT("resource.$part.weight"); |
|
if (!defined($weight) || $weight eq '' || $weight eq 0) { $weight = 1; } |
my $pcr=$score/$weight; |
my $pcr=$score/$weight; |
$Apache::lonhomework::results{"resource.$part.$id.awarded"}=$pcr; |
$Apache::lonhomework::results{"resource.$part.$id.awarded"}=$pcr; |
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}= |
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}= |
Line 583 sub analyze_store_foilgroup {
|
Line 654 sub analyze_store_foilgroup {
|
push (@{ $Apache::lonhomework::analyze{"$part_id.shown"} }, @{ $shown }); |
push (@{ $Apache::lonhomework::analyze{"$part_id.shown"} }, @{ $shown }); |
} |
} |
|
|
|
sub check_if_computed { |
|
my ($token,$parstack,$safeeval,$name)=@_; |
|
my $value = &Apache::lonxml::get_param($name,$parstack,$safeeval); |
|
if (ref($token->[2]) eq 'HASH' && $value ne $token->[2]{$name}) { |
|
my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]"; |
|
$Apache::lonhomework::analyze{"$part_id.answercomputed"} = 1; |
|
} |
|
} |
|
|
sub pick_foil_for_concept { |
sub pick_foil_for_concept { |
my ($target,$attrs,$hinthash,$parstack,$safeeval)=@_; |
my ($target,$attrs,$hinthash,$parstack,$safeeval)=@_; |
if (not defined(@{ $Apache::response::conceptgroup{'names'} })) { return; } |
if (not defined(@{ $Apache::response::conceptgroup{'names'} })) { return; } |
Line 618 sub pick_foil_for_concept {
|
Line 698 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; |
|
} |
|
|
|
sub submitted { |
|
my ($who)=@_; |
|
|
|
# when scatron grading any submission is a submission |
|
if ($ENV{'form.submitted'} eq 'scantron') { return 1; } |
|
# if the caller only cared if this was a scantron submission |
|
if ($who eq 'scantron') { return 0; } |
|
# if the Submit Answer button for this particular part was pressed |
|
my $partid=$Apache::inputtags::part; |
|
if (defined($ENV{'form.submit_'.$partid})) { return 1; } |
|
# otherwise no submission occured |
|
return 0; |
|
} |
1; |
1; |
__END__ |
__END__ |
|
|