--- loncom/homework/optionresponse.pm 2004/04/23 17:57:18 1.107
+++ loncom/homework/optionresponse.pm 2006/03/15 00:08:53 1.134
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.107 2004/04/23 17:57:18 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.134 2006/03/15 00:08:53 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -29,6 +29,7 @@ package Apache::optionresponse;
use strict;
use Apache::response();
use Apache::lonlocal;
+use Apache::lonnet;
BEGIN {
&Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
@@ -38,7 +39,7 @@ sub start_optionresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result='';
#when in a option response use these
- &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
+ &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
push (@Apache::lonxml::namespace,'optionresponse');
my $id = &Apache::response::start_response($parstack,$safeeval);
%Apache::hint::option=();
@@ -56,10 +57,14 @@ sub start_optionresponse {
$token,'4').
&Apache::edit::select_arg('Randomize Foil Order','randomize',
['yes','no'],$token).
+ &Apache::edit::select_arg(&mt('Display of options when printed'),'TeXlayout',
+ [['horizontal',&mt('Normal list')],
+ ['vertical',&mt('Listed in a vertical column')]],$token).
&Apache::edit::end_row().&Apache::edit::start_spanning_row();
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
- $safeeval,'max','randomize');
+ $safeeval,'max','randomize',
+ 'TeXlayout');
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
} elsif ($target eq 'meta') {
$result=&Apache::response::meta_package_write('optionresponse');
@@ -74,7 +79,7 @@ sub end_optionresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
&Apache::response::end_response;
pop @Apache::lonxml::namespace;
- &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
+ &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
my $result;
if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
undef(%Apache::response::foilnames);
@@ -88,7 +93,7 @@ sub start_foilgroup {
my $result='';
%Apache::response::foilgroup=();
$Apache::optionresponse::conceptgroup=0;
- &Apache::response::setrandomnumber();
+ &Apache::response::pushrandomnumber();
if ($target eq 'edit') {
my $optionlist="\n";
my $option;
@@ -109,6 +114,9 @@ sub start_foilgroup {
Delete an Option:
ENDTABLE
+ $result.= &Apache::edit::checked_arg('Print options:','texoptions',
+ [ ['nochoice','Don\'t show option list'] ]
+ ,$token);
$result.= &Apache::edit::end_row();
$result.= &Apache::edit::start_spanning_row();
$result.= $insertlist.' ';
@@ -117,14 +125,14 @@ ENDTABLE
my @options;
my $optchanged=0;
eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
- if ($ENV{"form.$Apache::lonxml::curdepth.deleteopt"}) {
- my $delopt=$ENV{"form.$Apache::lonxml::curdepth.deleteopt"};
+ if ($env{"form.$Apache::lonxml::curdepth.deleteopt"}) {
+ my $delopt=$env{"form.$Apache::lonxml::curdepth.deleteopt"};
&Apache::lonxml::debug("Deleting :$delopt:");
splice(@options,$delopt-1,1);
$optchanged=1;
}
- if ($ENV{"form.$Apache::lonxml::curdepth.options"}) {
- my $newopt = $ENV{"form.$Apache::lonxml::curdepth.options"};
+ if ($env{"form.$Apache::lonxml::curdepth.options"}) {
+ my $newopt = $env{"form.$Apache::lonxml::curdepth.options"};
if ($options[0]) {
push(@options,$newopt);
} else {
@@ -132,7 +140,9 @@ ENDTABLE
}
$optchanged=1;
}
- if ($optchanged) {
+ my $rebuildtag = &Apache::edit::get_new_args($token,$parstack,$safeeval,
+ ('texoptions'));
+ if ($optchanged || $rebuildtag ) {
$result = "';
+ $result.=')" ';
+ $result .= 'texoptions="'.$token->[2]{'texoptions'}.'" ';
+ $result .= '>';
} # else nothing changed so just use the default mechanism
}
if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
- $result .= ' \begin{enumerate} ';
+ $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}
+ \begin{enumerate} ';
}
return $result;
}
@@ -159,8 +172,10 @@ 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>$TeXlayout<<");
if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
my @names = @{ $Apache::response::foilgroup{'names'} };
my @truelist;
@@ -339,13 +384,13 @@ sub displayfoils {
if ($text=~/^\s*$/) {
$text=$value.$text;
} else {
- $text=$value.': '.$text;
+ $text=''.$value.': '.$text;
}
} else {
$text=''.$text;
}
$result.=$text."\n";
- }
+ }
if ($Apache::lonhomework::type eq 'exam') {
$result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
}
@@ -366,13 +411,13 @@ sub displayfoils {
}
my $lastopt=$lastresponse{$name};
my $optionlist="\n";
- my $option;
- foreach $option (@opt) {
- if ($option eq $lastopt) {
- $optionlist.="\n";
- } else {
- $optionlist.="\n";
- }
+ foreach my $option (@opt) {
+ my $escopt=&HTML::Entities::encode($option,'\'"&<>');
+ if ($option eq $lastopt) {
+ $optionlist.="\n";
+ } else {
+ $optionlist.="\n";
+ }
}
if ($target ne 'tex') {
if ($Apache::lonhomework::type ne 'exam') {
@@ -436,23 +481,81 @@ sub displayfoils {
}
+# Correct a single option list element.
+# - For embedded tags,
+# we pass literally the stuff between them.
+# - For everything else, we run through latex_special_symbols
+# so that any symbols that have meaning to LaTeX will be
+# correctly escaped.
+#
+sub correct_option {
+ my $option = shift;
+
+
+ # There's probably a beter way with perl if I was
+ # more of a regexp wiz..(RF).
+
+ my $strlen = length($option);
+ my $here = 0; # Where to start searching for
+ my $result =""; # The return string is built here.
+
+ while ($here < $strlen) {
+ # look for an opening tag:
+
+ my $openloc = index($option, "", $here);
+ if ($openloc == -1) {
+ # No more... operate with latex_special_symbols on
+ # the rest of the string.
+
+ $result .= &Apache::lonxml::latex_special_symbols(substr($option, $here));
+ return $result;
+ } else {
+ # Need to pass the string up to the tag
+ # through l_s_s ...
+ $result .= &Apache::lonxml::latex_special_symbols(substr($option, $here, $openloc-$here));
+ }
+ # look for the closing tag...
+ # We're a bit stupid..or tolerant...
+ # in that if the user forgets the tag
+ # we infer they intended one at the end of the option.
+ $openloc += 9; # 9 chars in
+
+ my $closeloc = index($option, "", $openloc); # 9 chars in
+ if ($closeloc == -1) {
+ $closeloc = $strlen + 9; # 10chars in faked off end.
+ }
+ # Pass from openloc through closeloc without any interpretation:
+
+ &Apache::lonnet::logthis("Segment inside display: $openloc through $closeloc");
+ $result .= substr($option, $openloc, $closeloc - $openloc);
+ $here = $closeloc + 10; # Next search is after the
+ }
+
+ return $result;
+
+ # return &Apache::lonxml::latex_special_symbols($option);
+}
+
+# Correct the option list elements so that if there
+# are special symbosl that have meaning to LaTeX
+# they get fixed up to display correctly.
+
sub optionlist_correction {
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).
+ &correct_option($option).
'}';
if ($TeXlayout eq 'vertical') {
$texoptionlist.=' \vskip 0 mm ',
} else {
- $texoptionlist.=',';
+ $texoptionlist.=', ';
}
}
- chop($texoptionlist);
+ $texoptionlist=~s/, $//;
if ($TeXlayout ne 'vertical') {$texoptionlist.='.';}
} else {
if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';}
@@ -475,8 +578,11 @@ sub webbubbles {
}
$result.='