version 1.77, 2003/05/14 13:33:00
|
version 1.87, 2003/10/27 19:27:09
|
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 52 sub start_response {
|
Line 49 sub start_response {
|
} |
} |
|
|
sub end_response { |
sub end_response { |
pop @Apache::inputtags::response; |
#pop @Apache::inputtags::response; |
@Apache::inputtags::inputlist=(); |
@Apache::inputtags::inputlist=(); |
return ''; |
return ''; |
} |
} |
Line 62 sub start_hintresponse {
|
Line 59 sub start_hintresponse {
|
my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); |
my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); |
if ($id eq '') { $id = $Apache::lonxml::curdepth; } |
if ($id eq '') { $id = $Apache::lonxml::curdepth; } |
push (@Apache::inputtags::response,$id); |
push (@Apache::inputtags::response,$id); |
|
push (@Apache::inputtags::responselist,$id); |
push (@Apache::inputtags::paramstack,[%Apache::inputtags::params]); |
push (@Apache::inputtags::paramstack,[%Apache::inputtags::params]); |
return $id; |
return $id; |
} |
} |
Line 92 sub setrandomnumber {
|
Line 90 sub setrandomnumber {
|
$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 176 sub mandatory_part_meta {
|
Line 177 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 274 sub end_dataresponse {
|
Line 285 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 284 sub start_responseparam {
|
Line 313 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 291 sub start_responseparam {
|
Line 333 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 364 sub answer_header {
|
Line 419 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 382 sub answer_part {
|
Line 432 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 399 sub answer_footer {
|
Line 445 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 469 sub scored_response {
|
Line 511 sub scored_response {
|
return $repetition; |
return $repetition; |
} |
} |
|
|
|
sub whichorder { |
|
my ($max,$randomize,$showall,$hash)=@_; |
|
#&Apache::lonxml::debug("man $max randomize $randomize"); |
|
if (!defined(@{ $$hash{'names'} })) { return; } |
|
my @names = @{ $$hash{'names'} }; |
|
my @whichopt =(); |
|
my (%top,@toplist,%bottom,@bottomlist); |
|
if (!($showall || ($randomize eq 'no'))) { |
|
my $current=0; |
|
foreach my $name (@names) { |
|
$current++; |
|
if ($$hash{"$name.location"} eq 'top') { |
|
$top{$name}=$current; |
|
} elsif ($$hash{"$name.location"} eq 'bottom') { |
|
$bottom{$name}=$current; |
|
} |
|
} |
|
} |
|
my $topcount=0; |
|
my $bottomcount=0; |
|
while (((scalar(@whichopt)+$topcount+$bottomcount) < $max || $showall) |
|
&& ($#names > -1)) { |
|
#&Apache::lonxml::debug("Have $#whichopt max is $max"); |
|
my $aopt; |
|
if ($showall || ($randomize eq 'no')) { |
|
$aopt=0; |
|
} else { |
|
$aopt=int(&Math::Random::random_uniform() * ($#names+1)); |
|
} |
|
#&Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt"); |
|
$aopt=splice(@names,$aopt,1); |
|
#&Apache::lonxml::debug("Picked $aopt"); |
|
if ($top{$aopt}) { |
|
$toplist[$top{$aopt}]=$aopt; |
|
$topcount++; |
|
} elsif ($bottom{$aopt}) { |
|
$bottomlist[$bottom{$aopt}]=$aopt; |
|
$bottomcount++; |
|
} else { |
|
push (@whichopt,$aopt); |
|
} |
|
} |
|
for (my $i=0;$i<=$#toplist;$i++) { |
|
if ($toplist[$i]) { unshift(@whichopt,$toplist[$i]) } |
|
} |
|
for (my $i=0;$i<=$#bottomlist;$i++) { |
|
if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) } |
|
} |
|
|
|
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__ |
|
|