version 1.83, 2003/08/11 19:56:45
|
version 1.117, 2005/04/01 18:08:14
|
Line 25
|
Line 25
|
# |
# |
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
# 11/23,11/24,11/28 Gerd Kortemeyer |
|
# Guy Albertelli |
|
# 08/04,08/07 Gerd Kortemeyer |
|
|
|
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 48 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 76 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 { |
sub setrandomnumber { |
my $rand_alg=&Apache::lonnet::get_rand_alg(); |
my $rndseed; |
if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' || |
if ($ENV{'request.state'} eq "construct") { |
$rand_alg eq '64bit2') { |
$rndseed=$ENV{'form.rndseed'}; |
# do nothing |
if (!$rndseed) { $rndseed=time; } |
|
} else { |
} else { |
$rndseed=&Apache::lonnet::rndseed(); |
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 { |
|
my $rndseed; |
|
$rndseed=&Apache::structuretags::setup_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 118 sub meta_parameter_write {
|
Line 167 sub meta_parameter_write {
|
} |
} |
$result.= ' name="'.$name.'"'. |
$result.= ' name="'.$name.'"'. |
' type="'.$type.'"'. |
' type="'.$type.'"'. |
($default?' default="'.$default.'"':''). |
(defined($default)?' default="'.$default.'"':''). |
($display?' display="'.$display.' [Part: '.$partref.']"':'') |
(defined($display)?' display="'.$display.' [Part: '.$partref.']"':'') |
.'></parameter>' |
.'></parameter>' |
."\n"; |
."\n"; |
return $result; |
return $result; |
Line 180 sub mandatory_part_meta {
|
Line 229 sub mandatory_part_meta {
|
# |
# |
} |
} |
|
|
|
sub meta_part_order { |
|
if (@Apache::inputtags::partlist) { |
|
my @parts=@Apache::inputtags::partlist; |
|
shift(@parts); |
|
return '<partorder>'.join(',',@parts).'</partorder>'."\n"; |
|
} else { |
|
return '<partorder>0</partorder>'."\n"; |
|
} |
|
} |
|
|
|
sub meta_response_order { |
|
if (@Apache::inputtags::responselist) { |
|
return '<responseorder>'.join(',',@Apache::inputtags::responselist). |
|
'</responseorder>'."\n"; |
|
} |
|
} |
|
|
sub check_for_previous { |
sub check_for_previous { |
my ($curresponse,$partid,$id) = @_; |
my ($curresponse,$partid,$id) = @_; |
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 214 sub handle_previous {
|
Line 280 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 259 sub end_dataresponse {
|
Line 326 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 365 sub end_responseparam {
|
Line 432 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 379 sub reset_params {
|
Line 444 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 402 sub setup_params {
|
Line 467 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 412 sub answer_header {
|
Line 479 sub answer_header {
|
my ($type) = @_; |
my ($type) = @_; |
my $result; |
my $result; |
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
$result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: '. |
$result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: \verb|'. |
$Apache::inputtags::part.' \\\\ \hline '; |
$Apache::inputtags::part.'| \\\\ \hline '; |
} else { |
} else { |
$result = '<table border="1"><tr><td>Answer for Part:'. |
$result = '<table border="1"><tr><td>Answer for Part:'. |
$Apache::inputtags::part. '</td>'."\n"; |
$Apache::inputtags::part. '</td>'."\n"; |
Line 444 sub answer_footer {
|
Line 511 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 { |
my ($temp)=@_; |
my ($temp,$resulttype)=@_; |
my $formparm='form.HWVAL_'.$Apache::inputtags::response['-1']; |
my $formparm='form.HWVAL_'.$Apache::inputtags::response['-1']; |
my $response; |
my $response; |
if (!defined($temp)) { |
if (!defined($temp)) { |
Line 473 sub getresponse {
|
Line 543 sub getresponse {
|
# save bubbled letter for later |
# save bubbled letter for later |
$Apache::lonhomework::results{"resource.$part.$id.scantron"}.= |
$Apache::lonhomework::results{"resource.$part.$id.scantron"}.= |
$response; |
$response; |
$response = $let_to_num{$response}; |
if ($resulttype ne 'letter') { |
|
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 497 sub scored_response {
|
Line 573 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 552 sub whichorder {
|
Line 629 sub whichorder {
|
for (my $i=0;$i<=$#bottomlist;$i++) { |
for (my $i=0;$i<=$#bottomlist;$i++) { |
if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) } |
if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) } |
} |
} |
|
|
return @whichopt; |
return @whichopt; |
} |
} |
|
|
|
sub show_answer { |
|
my $part = $Apache::inputtags::part; |
|
my $award = $Apache::lonhomework::history{"resource.$part.solved"}; |
|
my $status = $Apache::inputtags::status[-1]; |
|
return ( ($award =~ /^correct/ |
|
&& lc($Apache::lonhomework::problemstatus) ne 'no') |
|
|| $status eq "SHOW_ANSWER"); |
|
} |
|
|
|
sub analyze_store_foilgroup { |
|
my ($shown,$attrs)=@_; |
|
my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]"; |
|
foreach my $name (@{ $Apache::response::foilgroup{'names'} }) { |
|
if (defined($Apache::lonhomework::analyze{"$part_id.foil.value.$name"})) { next; } |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },$name); |
|
foreach my $attr (@$attrs) { |
|
$Apache::lonhomework::analyze{"$part_id.foil.".$attr.".$name"} = |
|
$Apache::response::foilgroup{"$name.".$attr}; |
|
} |
|
} |
|
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 { |
|
my ($target,$attrs,$hinthash,$parstack,$safeeval)=@_; |
|
if (not defined(@{ $Apache::response::conceptgroup{'names'} })) { return; } |
|
my @names = @{ $Apache::response::conceptgroup{'names'} }; |
|
my $pick=int(&Math::Random::random_uniform() * ($#names+1)); |
|
my $name=$names[$pick]; |
|
push @{ $Apache::response::foilgroup{'names'} }, $name; |
|
foreach my $attr (@$attrs) { |
|
$Apache::response::foilgroup{"$name.".$attr} = |
|
$Apache::response::conceptgroup{"$name.".$attr}; |
|
} |
|
my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval); |
|
$Apache::response::foilgroup{"$name.concept"} = $concept; |
|
&Apache::lonxml::debug("Selecting $name in $concept"); |
|
my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]"; |
|
if ($target eq 'analyze') { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.concepts"} }, |
|
$concept); |
|
$Apache::lonhomework::analyze{"$part_id.concept.$concept"}= |
|
$Apache::response::conceptgroup{'names'}; |
|
foreach my $name (@{ $Apache::response::conceptgroup{'names'} }) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} }, |
|
$name); |
|
foreach my $attr (@$attrs) { |
|
$Apache::lonhomework::analyze{"$part_id.foil.$attr.$name"}= |
|
$Apache::response::conceptgroup{"$name.$attr"}; |
|
} |
|
} |
|
} |
|
push(@{ $hinthash->{"$part_id.concepts"} },$concept); |
|
$hinthash->{"$part_id.concept.$concept"}= |
|
$Apache::response::conceptgroup{'names'}; |
|
|
|
} |
|
|
|
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; |
|
} |
|
|
|
# basically undef and 0 (both false) mean that they still have work to do |
|
# and all true values mean that they can't do any more work |
|
# |
|
# a return of undef means it is unattempted |
|
# a return of 0 means it is attmpted and wrong but still has tries |
|
# a return of 1 means it is marked correct |
|
# a return of 2 means they have exceed maximum number of tries |
|
# a return of 3 means it after the answer date |
|
sub check_status { |
|
my ($id)=@_; |
|
if (!$id) { $id=$Apache::linputtags::part; } |
|
my $curtime=&Apache::lonnet::EXT('system.time'); |
|
my $opendate=&Apache::lonnet::EXT("resource.$id.opendate"); |
|
my $duedate=&Apache::lonnet::EXT("resource.$id.duedate"); |
|
my $answerdate=&Apache::lonnet::EXT("resource.$id.answerdate"); |
|
if ( $opendate && $curtime > $opendate && |
|
$duedate && $curtime > $duedate && |
|
$answerdate && $curtime > $answerdate) { |
|
return 3; |
|
} |
|
my $status=&Apache::lonnet::EXT("user.resource.resource.$id.solved"); |
|
if ($status =~ /^correct/) { return 1; } |
|
if (!$status) { return undef; } |
|
my $maxtries=&Apache::lonnet::EXT("resource.$id.maxtries"); |
|
if ($maxtries eq '') { $maxtries=2; } |
|
my $curtries=&Apache::lonnet::EXT("user.resource.resource.$id.tries"); |
|
if ($curtries < $maxtries) { return 0; } |
|
return 2; |
|
} |
|
|
1; |
1; |
__END__ |
__END__ |
|
|