--- loncom/homework/optionresponse.pm 2004/01/14 22:08:22 1.98 +++ 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.98 2004/01/14 22:08:22 www 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; my @falselist; my $result; my $name; - my $displayoptionintex=0; + 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; @@ -303,13 +331,7 @@ sub displayfoils { my $text=$Apache::response::foilgroup{$name.'.text'}; my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"}); my $lastopt=$lastresponse{$name}; - if ($text!~/^\s*$/) { - if ($target eq 'tex') { - $break='\vskip 0 mm '; - } elsif ($target eq 'web') { - $break='
'; - } - } + if ($text!~/^\s*$/) { $break='
'; } $result.=$break; if ($target eq 'web') { my $value=$Apache::response::foilgroup{$name.'.value'}; @@ -323,18 +345,9 @@ sub displayfoils { $text='•'.$text; } $result.=$text."\n"; - } elsif ($target eq 'tex') { - $Apache::response::foilgroup{$name.'.text'}=~s/\\item//; - if ($max>1) {$result .='\item ';} - $result .=' \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'. - ":".$Apache::response::foilgroup{$name.'.text'}."\n"; } if ($Apache::lonhomework::type eq 'exam') { - if ($target ne 'tex') { $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt); - } else { - $result.=&bubbles(\@alphabet,\@opt); - } } $temp++; } @@ -363,66 +376,55 @@ sub displayfoils { } if ($target ne 'tex') { if ($Apache::lonhomework::type ne 'exam') { - $optionlist=''. $optionlist."\n"; + } else { + $optionlist=''.(' 'x10).''; } - my $text=$Apache::response::foilgroup{$name.'.text'}; - if (!($text=~s||$optionlist|) && $Apache::lonhomework::type ne 'exam') { - $text=$optionlist.$text; + if ($text=~s||$optionlist|) { + if ($Apache::lonhomework::type ne 'exam') { + $text='•'.$text; + } } else { - $text='•'.$text; + if ($Apache::lonhomework::type ne 'exam') { + $text=$optionlist.$text; + } } $result.=$break.$text."\n"; if ($Apache::lonhomework::type eq 'exam') { - $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt); + $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt); } $temp++; } else { - my $texoptionlist = &optionlist_correction($optionlist); - if ($displayoptionintex == 0) { - if ($Apache::lonhomework::type eq 'exam') {$texoptionlist='';} #if exam we do not need to show optionlist - if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) { - if ($Apache::lonhomework::type eq 'exam') { - $Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\vskip 2 mm/; - } - if ($Apache::response::foilgroup{$name.'.text'}=~//) { - $Apache::response::foilgroup{$name.'.text'}=~s|| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |; - } - $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'}; - } else { - if ($Apache::lonhomework::type eq 'exam') { - $result.= $texoptionlist.' '.$Apache::response::foilgroup{$name.'.text'}; - } else { - $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'}; - } - } + my $texoptionlist=''; + if ($displayoptionintex && + $Apache::lonhomework::type ne 'exam') { + $texoptionlist = &optionlist_correction($TeXlayout,@opt); + } + if ($text=~//) { + $text=~s|| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |; + } + + if ($text=~m/\\item /) { if ($Apache::lonhomework::type eq 'exam') { - $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++; + $text=~s/\\item/\\vskip 2 mm/; } - $displayoptionintex=1; + $result.= $texoptionlist.$text; } else { - if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) { - if ($Apache::lonhomework::type eq 'exam') { - $Apache::response::foilgroup{$name.'.text'}=~s/\\item//; - } - if ($Apache::response::foilgroup{$name.'.text'}=~//) { - $Apache::response::foilgroup{$name.'.text'}=~s|| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |; - } - $result.= $Apache::response::foilgroup{$name.'.text'}; - } else { - if ($Apache::lonhomework::type eq 'exam') { - $result.= ' '.$Apache::response::foilgroup{$name.'.text'}; - } else { - $result.= '\item '.$Apache::response::foilgroup{$name.'.text'}; - } - } if ($Apache::lonhomework::type eq 'exam') { - $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++; + $result.= $texoptionlist.' '.$text; + } else { + if ($text=~/\S/) {$result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;} else {$result.= $texoptionlist;} } } + if ($Apache::lonhomework::type eq 'exam') { + $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'. + $internal_counter.'}.]'.&bubbles(\@alphabet,\@opt). + '\end{enumerate} \vskip -8 mm \strut '; + $internal_counter++; + } + $displayoptionintex=0; } } } @@ -435,27 +437,31 @@ sub displayfoils { sub optionlist_correction { - - my $texoptionlist = shift; - if ($texoptionlist=~/