version 1.79, 2003/05/23 19:37:33
|
version 1.92, 2004/02/27 17:18:32
|
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; |
Line 48 sub start_response {
|
Line 45 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 87 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 =~/,/) { |
my ($num1,$num2)=split(/,/,$rndseed); |
{ |
$num1+=$rndmod; |
use integer; |
$num2+=$rndmod; |
my ($num1,$num2)=split(/,/,$rndseed); |
$rndseed="$num1,$num2"; |
$num1+=$rndmod; |
|
$num2+=$rndmod; |
|
$rndseed="$num1,$num2"; |
|
} |
} else { |
} else { |
$rndseed+=$rndmod; |
$rndseed+=$rndmod; |
} |
} |
Line 115 sub meta_parameter_write {
|
Line 121 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 177 sub mandatory_part_meta {
|
Line 183 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 275 sub end_dataresponse {
|
Line 291 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 285 sub start_responseparam {
|
Line 319 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 292 sub start_responseparam {
|
Line 339 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 365 sub answer_header {
|
Line 425 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 { |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse' ) { |
$result = '<table border="1"><tr><td>Answer for Part:'. |
$result = '<table border="1"><tr><th>Answer for Part:'. |
$Apache::inputtags::part. '</td>'."\n"; |
$Apache::inputtags::part. '</th></tr><tr>'."\n"; |
|
} else { |
|
$result = '<table border="1"><tr><td>Answer for Part:'. |
|
$Apache::inputtags::part. '</td>'."\n"; |
|
} |
|
} |
} |
return $result; |
return $result; |
} |
} |
Line 383 sub answer_part {
|
Line 438 sub answer_part {
|
my ($type,$answer) = @_; |
my ($type,$answer) = @_; |
my $result; |
my $result; |
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
$result = ' '.$answer.'\\\\ \hline '; |
$result = ' \verb|'.$answer.'|\\\\ \hline '; |
} else { |
} else { |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { |
$result = '<td>'.$answer.'</td>'; |
$result = '<td>'.$answer.'</td>'; |
|
} else { |
|
$result = '<td>'.$answer.'</td>'; |
|
} |
|
} |
} |
return $result; |
return $result; |
} |
} |
Line 400 sub answer_footer {
|
Line 451 sub answer_footer {
|
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
$result = ' \end{tabular} \vskip 0 mm '; |
$result = ' \end{tabular} \vskip 0 mm '; |
} else { |
} else { |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { |
$result = '</tr></table>'; |
$result = '</tr></table>'; |
|
} else { |
|
$result = '</tr></table>'; |
|
} |
|
} |
} |
return $result; |
return $result; |
} |
} |
Line 419 sub showallfoils {
|
Line 466 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 439 sub getresponse {
|
Line 486 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 463 sub scored_response {
|
Line 512 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 518 sub whichorder {
|
Line 568 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 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'}; |
|
|
|
} |
|
|
|
|
1; |
1; |
__END__ |
__END__ |
|
|