version 1.82.2.1, 2003/09/23 01:52:57
|
version 1.96, 2004/03/25 16:55:16
|
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::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 80 sub end_hintresponse {
|
Line 88 sub end_hintresponse {
|
# that is stable and unique based on the part number and response number |
# that is stable and unique based on the part number and response number |
sub setrandomnumber { |
sub setrandomnumber { |
my $rndseed; |
my $rndseed; |
if ($ENV{'request.state'} eq "construct") { |
$rndseed=&Apache::structuretags::setup_rndseed(); |
$rndseed=$ENV{'form.rndseed'}; |
if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); } |
if (!$rndseed) { $rndseed=time; } |
|
} else { |
|
$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 $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10); |
if (defined($Apache::inputtags::response['-1'])) { |
if (defined($Apache::inputtags::response['-1'])) { |
$rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]); |
$rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]); |
} |
} |
if ($rndseed =~/,/) { |
if ($rndseed =~/,/) { |
{ |
{ |
Line 118 sub meta_parameter_write {
|
Line 122 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 184 sub mandatory_part_meta {
|
# |
# |
} |
} |
|
|
|
sub meta_part_order { |
|
if (@Apache::inputtags::partlist) { |
|
my @parts=@Apache::inputtags::partlist; |
|
shift(@parts); |
|
return '<partorder>'.join(',',@parts).'</partorder>'; |
|
} else { |
|
return '<partorder>0</partorder>'; |
|
} |
|
} |
|
|
sub check_for_previous { |
sub check_for_previous { |
my ($curresponse,$partid,$id) = @_; |
my ($curresponse,$partid,$id) = @_; |
my %previous; |
my %previous; |
Line 259 sub end_dataresponse {
|
Line 273 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 278 sub end_dataresponse {
|
Line 292 sub end_dataresponse {
|
return $result; |
return $result; |
} |
} |
|
|
|
sub decide_package { |
|
my ($tagstack)=@_; |
|
my $package; |
|
if ($$tagstack[-1] eq 'parameter') { |
|
$package='part'; |
|
} else { |
|
my $i=-1; |
|
while (defined($$tagstack[$i])) { |
|
if ($$tagstack[$i] =~ /(response|hint)$/) { |
|
$package=$$tagstack[$i]; |
|
last; |
|
} |
|
$i--; |
|
} |
|
} |
|
return $package; |
|
} |
|
|
sub start_responseparam { |
sub start_responseparam { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my $result=''; |
my $result=''; |
Line 288 sub start_responseparam {
|
Line 320 sub start_responseparam {
|
$token->[2]->{'description'}); |
$token->[2]->{'description'}); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_start($target,$token); |
$result.=&Apache::edit::tag_start($target,$token); |
|
my $optionlist; |
|
my $package=&decide_package($tagstack); |
|
foreach my $key (sort(keys(%Apache::lonnet::packagetab))) { |
|
if ($key =~ /^\Q$package\E&(.*)&display$/) { |
|
$optionlist.='<option value="'.$1.'">'. |
|
$Apache::lonnet::packagetab{$key}.'</option>'; |
|
} |
|
} |
|
if (defined($optionlist)) { |
|
$result.='Use template: <select name="'. |
|
&Apache::edit::html_element_name('parameter_package').'">'. |
|
'<option value=""></option>'.$optionlist.'</select><br />'; |
|
} |
$result.=&Apache::edit::text_arg('Name:','name',$token). |
$result.=&Apache::edit::text_arg('Name:','name',$token). |
&Apache::edit::text_arg('Type:','type',$token). |
&Apache::edit::text_arg('Type:','type',$token). |
&Apache::edit::text_arg('Description:','description',$token). |
&Apache::edit::text_arg('Description:','description',$token). |
Line 295 sub start_responseparam {
|
Line 340 sub start_responseparam {
|
"</td></tr>"; |
"</td></tr>"; |
$result.=&Apache::edit::end_table; |
$result.=&Apache::edit::end_table; |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval, |
my $constructtag=&Apache::edit::get_new_args($token,$parstack, |
'name','type','description', |
$safeeval,'name','type', |
'default'); |
'description','default'); |
|
my $element=&Apache::edit::html_element_name('parameter_package'); |
|
if (defined($ENV{"form.$element"}) && $ENV{"form.$element"} ne '') { |
|
my $name=$ENV{"form.$element"}; |
|
my $tag=&decide_package($tagstack); |
|
$token->[2]->{'name'}=$name; |
|
$token->[2]->{'type'}= |
|
$Apache::lonnet::packagetab{"$tag&$name&type"}; |
|
$token->[2]->{'description'}= |
|
$Apache::lonnet::packagetab{"$tag&$name&display"}; |
|
$token->[2]->{'default'}= |
|
$Apache::lonnet::packagetab{"$tag&$name&default"}; |
|
$constructtag=1; |
|
} |
if ($constructtag) { |
if ($constructtag) { |
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
$result.=&Apache::edit::handle_insert(); |
$result.=&Apache::edit::handle_insert(); |
Line 335 sub reset_params {
|
Line 393 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 358 sub setup_params {
|
Line 416 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 368 sub answer_header {
|
Line 428 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 409 sub showallfoils {
|
Line 469 sub showallfoils {
|
} |
} |
|
|
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 429 sub getresponse {
|
Line 489 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') { |
|
$response = $let_to_num{$response}; |
|
} |
} else { |
} else { |
$response = $ENV{$formparm}; |
$response = $ENV{$formparm}; |
} |
} |
Line 453 sub scored_response {
|
Line 515 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 508 sub whichorder {
|
Line 571 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; |
} |
} |
|
|
Line 520 sub show_answer {
|
Line 582 sub show_answer {
|
&& lc($Apache::lonhomework::problemstatus) ne 'no') |
&& lc($Apache::lonhomework::problemstatus) ne 'no') |
|| $status eq "SHOW_ANSWER"); |
|| $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 ($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; |
|
} |
|
|
1; |
1; |
__END__ |
__END__ |
|
|