--- loncom/homework/optionresponse.pm 2003/04/21 22:09:47 1.75 +++ loncom/homework/optionresponse.pm 2003/10/03 15:23:53 1.88 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: optionresponse.pm,v 1.75 2003/04/21 22:09:47 albertel Exp $ +# $Id: optionresponse.pm,v 1.88 2003/10/03 15:23:53 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -152,9 +152,11 @@ sub end_foilgroup { my $result; if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { + my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval); my $name; my @opt; eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval); + if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();} &Apache::lonxml::debug("Options are $#opt"); my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2'); my $randomize = &Apache::lonxml::get_param('randomize',$parstack, @@ -239,6 +241,8 @@ sub end_foilgroup { $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad; $Apache::lonhomework::results{"resource.$part.$id.awarded"}= $right/(scalar(@whichopt)); + $Apache::lonhomework::results{"resource.$part.$id.numfoils"}= + scalar(@whichopt); } } } @@ -263,52 +267,10 @@ sub getfoilcounts { } sub whichfoils { - my ($max,$randomize)=@_; - $max = &getfoilcounts($max); - &Apache::lonxml::debug("randomize $randomize"); - if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;} - my @names = @{ $Apache::response::foilgroup{'names'} }; - my @whichopt =(); - my (%top,@toplist,%bottom,@bottomlist); - if (!(&Apache::response::showallfoils() || ($randomize eq 'no'))) { - my $current=0; - foreach my $name (@names) { - $current++; - if ($Apache::response::foilgroup{$name.'.location'} eq 'top') { - $top{$name}=$current; - } elsif ($Apache::response::foilgroup{$name.'.location'} eq - 'bottom') { - $bottom{$name}=$current; - } - } - } - while ((($#whichopt+1) < $max) && ($#names > -1)) { - &Apache::lonxml::debug("Have $#whichopt max is $max"); - my $aopt; - if (&Apache::response::showallfoils() || ($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; - } elsif ($bottom{$aopt}) { - $bottomlist[$bottom{$aopt}]=$aopt; - } 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; + my ($max,$randomize)=@_; + return &Apache::response::whichorder($max,$randomize, + &Apache::response::showallfoils(), + \%Apache::response::foilgroup); } sub displayanswers { @@ -331,7 +293,7 @@ sub displayfoils { my @names = @{ $Apache::response::foilgroup{'names'} }; my @truelist; my @falselist; - my $result; + my $result; my $name; my $displayoptionintex=0; my @alphabet = ('A'..'Z'); @@ -341,9 +303,8 @@ sub displayfoils { my $break; my $solved=$Apache::lonhomework::history{"resource.$part.solved"}; my $status=$Apache::inputtags::status[-1]; - if ( - ($target ne 'tex') && - (($solved =~ /^correct/) || ($status eq 'SHOW_ANSWER')) ) { + if ( ($target ne 'tex') && + &Apache::response::show_answer() ) { foreach $name (@whichopt) { my $text=$Apache::response::foilgroup{$name.'.text'}; if ($text!~/^\s*$/) { @@ -366,7 +327,8 @@ sub displayfoils { $result.=$text."\n"; } elsif ($target eq 'tex') { $Apache::response::foilgroup{$name.'.text'}=~s/\\item//; - $result .='\item \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'. + if ($max>1) {$result .='\item ';} + $result .=' \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'. ":".$Apache::response::foilgroup{$name.'.text'}."\n"; } if ($Apache::lonhomework::type eq 'exam') { @@ -380,6 +342,7 @@ sub displayfoils { } else { my $temp=1; my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"}); + my $internal_counter=$Apache::lonxml::counter; foreach $name (@whichopt) { my $text=$Apache::response::foilgroup{$name.'.text'}; if ($text!~/^\s*$/) { @@ -434,7 +397,8 @@ sub displayfoils { } } if ($Apache::lonhomework::type eq 'exam') { - $result.='\vskip -2 mm\parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]\parbox{\textwidth - 5 mm}{'.&bubbles(\@alphabet,\@opt).'}\end{enumerate}} \vskip -9 mm \strut '; + $result.='\vskip -2 mm\parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]\parbox{\textwidth - 5 mm}{'.&bubbles(\@alphabet,\@opt).'}\end{enumerate}} \vskip -9 mm \strut '; + $internal_counter++; } $displayoptionintex=1; } else { @@ -454,7 +418,8 @@ sub displayfoils { } } if ($Apache::lonhomework::type eq 'exam') { - $result.='\vskip -2 mm \parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]\parbox{\textwidth - 5 mm}{'.&bubbles(\@alphabet,\@opt).'}\end{enumerate}} \vskip -9 mm \strut '; + $result.='\vskip -2 mm \parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]\parbox{\textwidth - 5 mm}{'.&bubbles(\@alphabet,\@opt).'}\end{enumerate}} \vskip -9 mm \strut '; + $internal_counter++; } } } @@ -471,15 +436,19 @@ sub displayfoils { sub optionlist_correction { my $texoptionlist = shift; - $texoptionlist =~ s/