--- loncom/homework/optionresponse.pm 2004/02/19 19:06:35 1.101 +++ loncom/homework/optionresponse.pm 2004/04/23 17:57:18 1.107 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: optionresponse.pm,v 1.101 2004/02/19 19:06:35 albertel Exp $ +# $Id: optionresponse.pm,v 1.107 2004/04/23 17:57:18 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,7 +27,8 @@ # package Apache::optionresponse; use strict; -use Apache::response; +use Apache::response(); +use Apache::lonlocal; BEGIN { &Apache::lonxml::register('Apache::optionresponse',('optionresponse')); @@ -41,6 +42,7 @@ sub start_optionresponse { push (@Apache::lonxml::namespace,'optionresponse'); my $id = &Apache::response::start_response($parstack,$safeeval); %Apache::hint::option=(); + undef(%Apache::response::foilnames); if ($target eq 'edit') { $result.=&Apache::edit::start_table($token). "Multiple Option Response Question ". @@ -75,6 +77,7 @@ sub end_optionresponse { &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup')); my $result; if ($target eq 'edit') { $result=&Apache::edit::end_table(); } + undef(%Apache::response::foilnames); return $result; } @@ -156,13 +159,15 @@ sub end_foilgroup { my $name; my @opt; eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval); + my $TeXlayout=&Apache::lonxml::get_param('TeXlayout',$parstack,$safeeval,undef,0); + &Apache::lonnet::logthis("PARAMETER U>$TeXlayout'. + join('
',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))). + "
"; + &Apache::lonxml::error($error); + } +} + sub displayfoils { - my ($target,$max,$randomize,@opt)=@_; + my ($target,$max,$randomize,$TeXlayout,@opt)=@_; + &Apache::lonnet::logthis("PARAMETER >>$TeXlayout<<"); if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;} my @names = @{ $Apache::response::foilgroup{'names'} }; my @truelist; @@ -292,6 +319,7 @@ sub displayfoils { my $displayoptionintex=1; my @alphabet = ('A'..'Z'); my @whichopt = &whichfoils($max,$randomize); + &check_for_invalid(\@whichopt,\@opt); my $part=$Apache::inputtags::part; my $id=$Apache::inputtags::response[-1]; my $break; @@ -372,7 +400,7 @@ sub displayfoils { my $texoptionlist=''; if ($displayoptionintex && $Apache::lonhomework::type ne 'exam') { - $texoptionlist = &optionlist_correction(@opt); + $texoptionlist = &optionlist_correction($TeXlayout,@opt); } if ($text=~//) { $text=~s|| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |; @@ -387,7 +415,7 @@ sub displayfoils { if ($Apache::lonhomework::type eq 'exam') { $result.= $texoptionlist.' '.$text; } else { - $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text; + if ($text=~/\S/) {$result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;} else {$result.= $texoptionlist;} } } if ($Apache::lonhomework::type eq 'exam') { @@ -409,18 +437,25 @@ sub displayfoils { sub optionlist_correction { - my @options = @_; + my ($TeXlayout,@options) = @_; + &Apache::lonnet::logthis("PARAMETER >$TeXlayout<"); my $texoptionlist='\\item [] Choices: '; + if ($TeXlayout eq 'vertical') {$texoptionlist='\\item []';} if (scalar(@options) > 0) { foreach my $option (@options) { $texoptionlist.='{\bf '. &Apache::lonxml::latex_special_symbols($option). - '},'; + '}'; + if ($TeXlayout eq 'vertical') { + $texoptionlist.=' \vskip 0 mm ', + } else { + $texoptionlist.=','; + } } chop($texoptionlist); - $texoptionlist.='.'; + if ($TeXlayout ne 'vertical') {$texoptionlist.='.';} } else { - $texoptionlist='\\item [] \\vskip -5 mm'; + if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';} } return $texoptionlist; } @@ -460,20 +495,20 @@ sub bubbles { $ENV{'form.textwidth'}=~/(\d+)/; $textwidth=$1; } else { - $ENV{'textwidth'}=~/(\d+)/; - $textwidth=$1; + $ENV{'textwidth'}=~/(\d*)\.?(\d*)/; + $textwidth=$1.'.'.$2; } for (my $ind=0;$ind<=$number_of_bubbles;$ind++) { my $leftmargin; $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]); if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;} - $current_length += (length($opt[$ind])+length($alphabet[$ind])+3)*2; + $current_length += (length($opt[$ind])+length($alphabet[$ind])+4)*2; if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) { $line.='\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & '; $head.='lr'; } else { $line=~s/\&\s*$//; - $result.='\vskip -2 mm\noindent\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}'; + $result.='\vskip -2 mm\noindent\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm'; $line = '\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';; $head ='lr'; $current_length = (length($opt[$ind])+length($alphabet[$ind]))*2; @@ -527,7 +562,10 @@ sub start_foil { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) { - &Apache::lonxml::startredirection; + &Apache::lonxml::startredirection; + if ($target eq 'analyze') { + &Apache::response::check_if_computed($token,$parstack,$safeeval,'value'); + } } elsif ($target eq 'edit') { $result=&Apache::edit::tag_start($target,$token,"Foil"); my $level='-2'; @@ -558,17 +596,23 @@ sub end_foil { my $result = ''; if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') { $text=&Apache::lonxml::endredirection; - if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') { $text = '\vspace*{-2 mm}\item '.$text; } + $text=~/(\w)/; + &Apache::lonnet::logthis("TTTEXT IS HERE NOW >>$text<< >>>$1<<<"); + if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;} } if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval); if ($value ne 'unused') { my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); - my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval); &Apache::lonxml::debug("Got a name of :$name:"); if (!$name) { $name=$Apache::lonxml::curdepth; } &Apache::lonxml::debug("Using a name of :$name:"); + if (defined($Apache::response::foilnames{$name})) { + &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",$name)); + } + $Apache::response::foilnames{$name}++; + my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval); if ( $Apache::optionresponse::conceptgroup && !&Apache::response::showallfoils() ) { push @{ $Apache::response::conceptgroup{'names'} }, $name;