--- loncom/homework/optionresponse.pm 2002/11/11 20:13:47 1.61 +++ loncom/homework/optionresponse.pm 2003/03/26 18:42:29 1.69 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: optionresponse.pm,v 1.61 2002/11/11 20:13:47 sakharuk Exp $ +# $Id: optionresponse.pm,v 1.69 2003/03/26 18:42:29 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,8 @@ package Apache::optionresponse; use strict; use Apache::response; +my $flag_for_exam_printing = 1; + BEGIN { &Apache::lonxml::register('Apache::optionresponse',('optionresponse')); } @@ -141,7 +143,7 @@ ENDTABLE $result.=')">'; } # else nothing changed so just use the default mechanism } - if ($target eq 'tex') { + if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') { $result .= ' \begin{enumerate} '; } return $result; @@ -230,7 +232,7 @@ sub end_foilgroup { } elsif ($target eq 'edit') { $result.=&Apache::edit::end_table(); } - if ($target eq 'tex') {$result .= '\end{enumerate}';} + if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {$result .= '\end{enumerate}';} return $result; } @@ -248,6 +250,7 @@ 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); @@ -294,6 +297,7 @@ sub whichfoils { sub displayanswers { my ($max,$randomize,@opt)=@_; + if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;} my @names = @{ $Apache::response::foilgroup{'names'} }; my @whichopt = &whichfoils($max,$randomize); my $result=&Apache::response::answer_header('optionresponse'); @@ -307,6 +311,7 @@ sub displayanswers { sub displayfoils { my ($target,$max,$randomize,@opt)=@_; + if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;} my @names = @{ $Apache::response::foilgroup{'names'} }; my @truelist; my @falselist; @@ -318,22 +323,33 @@ sub displayfoils { my @whichopt = &whichfoils($max,$randomize); my $part=$Apache::inputtags::part; my $id=$Apache::inputtags::response[-1]; - if (($Apache::lonhomework::history{"resource.$part.solved"} =~ /^correct/) || ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER')) { - my $temp=1; #### + 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')) ) { foreach $name (@whichopt) { - if ($target eq 'web') { - $result.="
"; + my $text=$Apache::response::foilgroup{$name.'.text'}; + if ($text!~/^\s*$/) { + if ($target eq 'tex') { + $break='\vskip 0 mm '; + } elsif ($target eq 'web') { + $break='
'; + } + } + $result.=$break; + if ($target eq 'web') { + my $value=$Apache::response::foilgroup{$name.'.value'}; + if (!($text=~s||$value|)) { + if ($text=~/^\s*$/) { + $text=$value.$text; + } else { + $text=$value.': '.$text; + } + } + $result.=$text."\n"; } elsif ($target eq 'tex') { - $result.='\vskip 0 mm '; - } - if ($target ne 'tex') { - my $text=$Apache::response::foilgroup{$name.'.text'}; - my $value=$Apache::response::foilgroup{$name.'.value'}; - if (!($text=~s||$value|)) { - $text=$value.': '.$text; - } - $result.=$text."\n"; - } else { $Apache::response::foilgroup{$name.'.text'}=~s/\\item//; $result .='\item \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'. ":".$Apache::response::foilgroup{$name.'.text'}."\n"; @@ -345,12 +361,19 @@ sub displayfoils { $result.=&bubbles(\@alphabet,\@opt); } } - $temp++; } } else { my $temp=1; my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"}); foreach $name (@whichopt) { + my $text=$Apache::response::foilgroup{$name.'.text'}; + if ($text!~/^\s*$/) { + if ($target eq 'tex') { + $break='\vskip 0 mm '; + } elsif ($target eq 'web') { + $break='
'; + } + } my $lastopt=$lastresponse{$name}; my $optionlist="\n"; my $option; @@ -369,7 +392,7 @@ sub displayfoils { if (!($text=~s||$optionlist|)) { $text=$optionlist.$text; } - $result.="
".$text."\n"; + $result.=$break.$text."\n"; if ($Apache::lonhomework::type eq 'exam') { $result.=&webbubbles(\@opt,\@alphabet); } @@ -380,27 +403,27 @@ sub displayfoils { 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/\\item[\\textbf{$Apache::lonxml::counter}\.]/; + $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'}; } + $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'}; } else { if ($Apache::lonhomework::type eq 'exam') { - $result.= $texoptionlist.'\vspace*{-2 mm}\item[\textbf{'.$Apache::lonxml::counter.'}.]'.$Apache::response::foilgroup{$name.'.text'}; + $result.= $texoptionlist.' '.$Apache::response::foilgroup{$name.'.text'}; } else { $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'}; } } if ($Apache::lonhomework::type eq 'exam') { - $result.=&bubbles(\@alphabet,\@opt); + $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 '; } $displayoptionintex=1; } else { if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) { if ($Apache::lonhomework::type eq 'exam') { - $Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\item[\\textbf{$Apache::lonxml::counter}\.]/; + $Apache::response::foilgroup{$name.'.text'}=~s/\\item//; } if ($Apache::response::foilgroup{$name.'.text'}=~//) { $Apache::response::foilgroup{$name.'.text'}=~s|| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |; @@ -408,22 +431,21 @@ sub displayfoils { $result.= $Apache::response::foilgroup{$name.'.text'}; } else { if ($Apache::lonhomework::type eq 'exam') { - $result.= '\item[\textbf{'.$Apache::lonxml::counter.'}.]'.$Apache::response::foilgroup{$name.'.text'}; + $result.= ' '.$Apache::response::foilgroup{$name.'.text'}; } else { $result.= '\item '.$Apache::response::foilgroup{$name.'.text'}; } } if ($Apache::lonhomework::type eq 'exam') { - $result.=&bubbles(\@alphabet,\@opt); + $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 '; } } - } + } } - } - if ($target ne 'tex') { - return $result."
"; } - else { + if ($target ne 'tex') { + return $result.$break; + } else { return $result; } } @@ -440,6 +462,7 @@ sub optionlist_correction { $texoptionlist =~ s/>/\$>\$/g; $texoptionlist =~ s/\$$1\$<\/m>/g; return $texoptionlist; } @@ -595,7 +618,7 @@ sub end_foil { my $result = ''; if ($target eq 'web' || $target eq 'tex') { $text=&Apache::lonxml::endredirection; - if ($target eq 'tex') { $text = '\vspace*{-2 mm}\item '.$text; } + if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') { $text = '\vspace*{-2 mm}\item '.$text; } } if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { @@ -610,12 +633,28 @@ sub end_foil { && !&Apache::response::showallfoils() ) { push @{ $Apache::response::conceptgroup{'names'} }, $name; $Apache::response::conceptgroup{"$name.value"} = $value; - $Apache::response::conceptgroup{"$name.text"} = $text; + if ($target eq 'tex' and $Apache::lonhomework::type eq 'exam' and $flag_for_exam_printing) { + $Apache::response::conceptgroup{"$name.text"} = '\vskip 4 mm $\triangleright$ '.$text; + } else { + if ($target eq 'tex') { + $Apache::response::conceptgroup{"$name.text"} = ' $\triangleright$ '.$text; + } else { + $Apache::response::conceptgroup{"$name.text"} = $text; + } + } $Apache::response::conceptgroup{"$name.location"} = $location; } else { push @{ $Apache::response::foilgroup{'names'} }, $name; $Apache::response::foilgroup{"$name.value"} = $value; - $Apache::response::foilgroup{"$name.text"} = $text; + if ($Apache::lonhomework::type eq 'exam' and $flag_for_exam_printing) { + $Apache::response::foilgroup{"$name.text"} = '\vskip 5 mm $\triangleright$ '.$text; + } else { + if ($target eq 'tex') { + $Apache::response::foilgroup{"$name.text"} = ' $\triangleright$ '.$text; + } else { + $Apache::response::foilgroup{"$name.text"} = $text; + } + } $Apache::response::foilgroup{"$name.location"} = $location; } }