--- loncom/homework/response.pm 2003/05/16 20:16:18 1.78
+++ loncom/homework/response.pm 2004/02/09 19:38:00 1.90
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# various response type definitons response definition
#
-# $Id: response.pm,v 1.78 2003/05/16 20:16:18 albertel Exp $
+# $Id: response.pm,v 1.90 2004/02/09 19:38:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,9 +25,6 @@
#
# http://www.lon-capa.org/
#
-# 11/23,11/24,11/28 Gerd Kortemeyer
-# Guy Albertelli
-# 08/04,08/07 Gerd Kortemeyer
package Apache::response;
use strict;
@@ -52,7 +49,7 @@ sub start_response {
}
sub end_response {
- pop @Apache::inputtags::response;
+ #pop @Apache::inputtags::response;
@Apache::inputtags::inputlist=();
return '';
}
@@ -62,6 +59,7 @@ sub start_hintresponse {
my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
if ($id eq '') { $id = $Apache::lonxml::curdepth; }
push (@Apache::inputtags::response,$id);
+ push (@Apache::inputtags::responselist,$id);
push (@Apache::inputtags::paramstack,[%Apache::inputtags::params]);
return $id;
}
@@ -79,23 +77,22 @@ sub end_hintresponse {
# that is stable and unique based on the part number and response number
sub setrandomnumber {
my $rndseed;
- if ($ENV{'request.state'} eq "construct") {
- $rndseed=$ENV{'form.rndseed'};
- if (!$rndseed) { $rndseed=time; }
- } else {
- $rndseed=&Apache::lonnet::rndseed();
- }
+ $rndseed=&Apache::structuretags::setup_rndseed();
+ if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); }
&Apache::lonxml::debug("randseed $rndseed");
# $rndseed=unpack("%32i",$rndseed);
my $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10);
if (defined($Apache::inputtags::response['-1'])) {
- $rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]);
+ $rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]);
}
if ($rndseed =~/,/) {
- my ($num1,$num2)=split(/,/,$rndseed);
- $num1+=$rndmod;
- $num2+=$rndmod;
- $rndseed="$num1,$num2";
+ {
+ use integer;
+ my ($num1,$num2)=split(/,/,$rndseed);
+ $num1+=$rndmod;
+ $num2+=$rndmod;
+ $rndseed="$num1,$num2";
+ }
} else {
$rndseed+=$rndmod;
}
@@ -114,8 +111,8 @@ sub meta_parameter_write {
}
$result.= ' name="'.$name.'"'.
' type="'.$type.'"'.
-($default?' default="'.$default.'"':'').
-($display?' display="'.$display.' [Part: '.$partref.']"':'')
+(defined($default)?' default="'.$default.'"':'').
+(defined($display)?' display="'.$display.' [Part: '.$partref.']"':'')
.'>'
."\n";
return $result;
@@ -176,6 +173,16 @@ sub mandatory_part_meta {
#
}
+sub meta_part_order {
+ if (@Apache::inputtags::partlist) {
+ my @parts=@Apache::inputtags::partlist;
+ shift(@parts);
+ return ''.join(',',@parts).'';
+ } else {
+ return '0';
+ }
+}
+
sub check_for_previous {
my ($curresponse,$partid,$id) = @_;
my %previous;
@@ -274,6 +281,24 @@ sub end_dataresponse {
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 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result='';
@@ -284,6 +309,19 @@ sub start_responseparam {
$token->[2]->{'description'});
} elsif ($target eq 'edit') {
$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.='';
+ }
+ }
+ if (defined($optionlist)) {
+ $result.='Use template:
';
+ }
$result.=&Apache::edit::text_arg('Name:','name',$token).
&Apache::edit::text_arg('Type:','type',$token).
&Apache::edit::text_arg('Description:','description',$token).
@@ -291,9 +329,22 @@ sub start_responseparam {
"";
$result.=&Apache::edit::end_table;
} elsif ($target eq 'modified') {
- my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
- 'name','type','description',
- 'default');
+ my $constructtag=&Apache::edit::get_new_args($token,$parstack,
+ $safeeval,'name','type',
+ '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) {
$result = &Apache::edit::rebuild_tag($token);
$result.=&Apache::edit::handle_insert();
@@ -364,16 +415,11 @@ sub answer_header {
my ($type) = @_;
my $result;
if ($ENV{'form.answer_output_mode'} eq 'tex') {
- $result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: '.
- $Apache::inputtags::part.' \\\\ \hline ';
+ $result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: \verb|'.
+ $Apache::inputtags::part.'| \\\\ \hline ';
} else {
- if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse' ) {
- $result = '
Answer for Part:'.
- $Apache::inputtags::part. ' |
---|
'."\n";
- } else {
- $result = 'Answer for Part:'.
- $Apache::inputtags::part. ' | '."\n";
- }
+ $result = 'Answer for Part:'.
+ $Apache::inputtags::part. ' | '."\n";
}
return $result;
}
@@ -382,13 +428,9 @@ sub answer_part {
my ($type,$answer) = @_;
my $result;
if ($ENV{'form.answer_output_mode'} eq 'tex') {
- $result = ' '.$answer.'\\\\ \hline ';
+ $result = ' \verb|'.$answer.'|\\\\ \hline ';
} else {
- if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') {
- $result = ''.$answer.' | ';
- } else {
- $result = ''.$answer.' | ';
- }
+ $result = ''.$answer.' | ';
}
return $result;
}
@@ -399,11 +441,7 @@ sub answer_footer {
if ($ENV{'form.answer_output_mode'} eq 'tex') {
$result = ' \end{tabular} \vskip 0 mm ';
} else {
- if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') {
- $result = '
';
- } else {
- $result = '
';
- }
+ $result = '
';
}
return $result;
}
@@ -418,7 +456,7 @@ sub showallfoils {
}
sub getresponse {
- my ($temp)=@_;
+ my ($temp,$resulttype)=@_;
my $formparm='form.HWVAL_'.$Apache::inputtags::response['-1'];
my $response;
if (!defined($temp)) {
@@ -438,7 +476,9 @@ sub getresponse {
# save bubbled letter for later
$Apache::lonhomework::results{"resource.$part.$id.scantron"}.=
$response;
- $response = $let_to_num{$response};
+ if ($resulttype ne 'letter') {
+ $response = $let_to_num{$response};
+ }
} else {
$response = $ENV{$formparm};
}
@@ -517,10 +557,68 @@ sub whichorder {
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;
__END__