--- loncom/homework/optionresponse.pm 2004/02/19 19:20:25 1.96.2.2
+++ loncom/homework/optionresponse.pm 2004/05/06 07:31:32 1.109
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.96.2.2 2004/02/19 19:20:25 albertel Exp $
+# $Id: optionresponse.pm,v 1.109 2004/05/06 07:31:32 albertel 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,9 +42,11 @@ 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 ".
+ &Apache::loncommon::help_open_topic('Option_Response_Problems')." | Delete:".
&Apache::edit::deletelist($target,$token)
." | ".
&Apache::edit::end_row().
@@ -53,10 +56,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,6 +81,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;
}
@@ -140,7 +148,8 @@ ENDTABLE
} # 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;
}
@@ -155,13 +164,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,
+ -2,0);
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,
$safeeval,'-2');
if ($target eq 'web' || $target eq 'tex') {
- $result.=&displayfoils($target,$max,$randomize,@opt);
+ $result.=&displayfoils($target,$max,$randomize,$TeXlayout,@opt);
} elsif ( $target eq 'answer') {
$result.=&displayanswers($max,$randomize,@opt);
} elsif ( $target eq 'analyze') {
@@ -280,17 +291,39 @@ sub displayanswers {
return $result;
}
+sub check_for_invalid {
+ my ($names,$options) = @_;
+ my %bad_names;
+ foreach my $name (@{ $names }) {
+ my $value=$Apache::response::foilgroup{$name.'.value'};
+ my $found=0;
+ foreach my $option (@{ $options }) {
+ if ($value eq $option) { $found=1; }
+ }
+ if (!$found) { $bad_names{$name}=$value; }
+ }
+ if (%bad_names) {
+ my $error=&mt('The question can not be gotten correct, '.
+ 'the following foils in the <optionresponse> '.
+ 'have invalid correct options').' '.
+ 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)=@_;
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;
@@ -302,13 +335,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'};
@@ -322,18 +349,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++;
}
@@ -362,66 +380,55 @@ sub displayfoils {
}
if ($target ne 'tex') {
if ($Apache::lonhomework::type ne 'exam') {
- $optionlist=' |