--- loncom/homework/radiobuttonresponse.pm 2010/02/28 23:42:24 1.144
+++ loncom/homework/radiobuttonresponse.pm 2011/09/13 21:42:58 1.151
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# mutliple choice style responses
#
-# $Id: radiobuttonresponse.pm,v 1.144 2010/02/28 23:42:24 raeburn Exp $
+# $Id: radiobuttonresponse.pm,v 1.151 2011/09/13 21:42:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -105,8 +105,7 @@ sub start_radiobuttonresponse {
$result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
}
if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
- $result .= &Apache::lonxml::print_pdf_hiddenfield('meta', $env{'user.name'}, $env{'user.domain'});
- $result .= "\n\\\\\n\\\\\n";
+ $result .= '\begin{itemize}';
} else {
$result .= '\begin{enumerate}';
}
@@ -122,8 +121,12 @@ sub end_radiobuttonresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
- if ($target eq 'tex' and ($env{'form.pdfFormFields'} ne 'yes' or $Apache::inputtags::status[-1] ne 'CAN_ANSWER')) {
- $result .= '\end{enumerate}';
+ if ($target eq 'tex' ) {
+ if($env{'form.pdfFormFields'} eq 'yes' and $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
+ $result .= '\end{itemize}';
+ } else {
+ $result .= '\end{enumerate}';
+ }
}
&Apache::response::end_response;
pop @Apache::lonxml::namespace;
@@ -135,14 +138,10 @@ sub end_radiobuttonresponse {
%Apache::response::foilgroup=();
sub start_foilgroup {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
- my $result;
%Apache::response::foilgroup=();
$Apache::radiobuttonresponse::conceptgroup=0;
- &Apache::response::pushrandomnumber();
- if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
- $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
- }
- return $result;
+ &Apache::response::pushrandomnumber(undef,$target);
+ return;
}
sub storesurvey {
@@ -164,7 +163,7 @@ sub storesurvey {
if ($style eq 'anonsurvey') {
$ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
} elsif ($style eq 'anonsurveycred') {
- $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CRED';
+ $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CREDIT';
} elsif ($style eq 'surveycred') {
$ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
} else {
@@ -219,15 +218,10 @@ sub end_foilgroup {
my $result;
my $bubble_lines;
- my $bubbles_per_line;
my $answer_count;
my $id = $Apache::inputtags::response['-1'];
my $part = $Apache::inputtags::part;
- $bubbles_per_line =
- &Apache::response::get_response_param($Apache::inputtags::part."_$id",
- 'numbubbles',
- $default_bubbles_per_line);
-
+ my $bubbles_per_line = &getbubblesnum($part,$id);
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
$target eq 'tex' || $target eq 'analyze') {
@@ -257,7 +251,7 @@ sub end_foilgroup {
$answer_count = scalar(@shown);
if ($target eq 'web' || $target eq 'tex') {
- $result=&displayfoils($target,
+ $result=&displayfoils($target,
$answer, \@shown,
$direction,
$bubbles_per_line);
@@ -292,6 +286,20 @@ sub end_foilgroup {
return $result;
}
+sub getbubblesnum {
+ my ($part,$id) = @_;
+ my $bubbles_per_line;
+ my $default_numbubbles = $default_bubbles_per_line;
+ if (($env{'form.bubbles_per_row'} =~ /^\d+$/) &&
+ ($env{'form.bubbles_per_row'} > 0)) {
+ $default_numbubbles = $env{'form.bubbles_per_row'};
+ }
+ $bubbles_per_line =
+ &Apache::response::get_response_param($part."_$id",'numbubbles',
+ $default_numbubbles);
+ return $bubbles_per_line;
+}
+
sub getfoilcounts {
my @names;
my $truecnt=0;
@@ -333,14 +341,24 @@ sub displayallfoils {
my $i =0;
my $id=$Apache::inputtags::response['-1'];
my $part=$Apache::inputtags::part;
- my $lastresponse;
- unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) {
+ my ($lastresponse,$newvariation,$showanswer);
+ if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
+ ($Apache::lonhomework::type eq 'randomizetry')) &&
+ ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
+ if ($env{'form.'.$part.'.rndseed'} ne
+ $Apache::lonhomework::history{"resource.$part.rndseed"}) {
+ $newvariation = 1;
+ }
+ }
+ $showanswer = &Apache::response::show_answer();
+ unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'})) ||
+ ($newvariation && !$showanswer)) {
$lastresponse =
$Apache::lonhomework::history{"resource.$part.$id.submission"};
}
if ($direction eq 'horizontal') { $result.='
'; }
my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
- if (&Apache::response::show_answer() ) {
+ if ($showanswer) {
foreach my $name (@names) {
if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
if (($direction eq 'horizontal') && ($target ne 'tex')) {
@@ -374,15 +392,10 @@ sub displayallfoils {
} else {
if ($target eq 'tex') {
if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
- my $fieldname = $env{'request.symb'}.
- '&part_'. $Apache::inputtags::part.
- '&radiobuttonresponse'.
- '&HWVAL_' . $Apache::inputtags::response['-1'];
- my $value = $temp;
- my $text = $Apache::response::foilgroup{$name.'.text'};
- $result .= &Apache::lonxml::print_pdf_radiobutton($fieldname,
- $value,
- $text)."\n";
+ my $fieldname = $env{'request.symb'}.'&part_'. $Apache::inputtags::part
+ .'&radiobuttonresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'];
+ $result .= '\item[{'.&Apache::lonxml::print_pdf_radiobutton($fieldname,$temp).'}]'
+ .$Apache::response::foilgroup{$name.'.text'}."\n";
} else {
$result .= '\item \vskip -2mm ';
}
@@ -402,6 +415,7 @@ sub displayallfoils {
type=\"radio\"
name=\"HWVAL_$Apache::inputtags::response['-1']\"
value=\"$temp\"";
+
if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
$result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.
'';
@@ -546,8 +560,12 @@ sub whichfoils {
$dosplice=0;
} else {
if ($topcount>0 || $bottomcount>0) {
- $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
- + $topcount;
+ my $inc = 1;
+ if (($bottomcount > 0) && ($Apache::lonhomework::type ne 'exam')) {
+ $inc = 2;
+ }
+ $answer=int(&Math::Random::random_uniform() * ($#whichfalse+$inc))
+ + $topcount;
}
}
&Apache::lonxml::debug("Answer now wants $answer");
@@ -619,11 +637,46 @@ sub displayfoils {
my $temp=0;
my $id=$Apache::inputtags::response['-1'];
my $part=$Apache::inputtags::part;
- my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
+ my ($lastresponse,$newvariation);
+ if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
+ ($Apache::lonhomework::type eq 'randomizetry')) &&
+ ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
+ if ($env{'form.'.$part.'.rndseed'} ne
+ $Apache::lonhomework::history{"resource.$part.rndseed"}) {
+ $newvariation = 1;
+ }
+ }
+ unless ($newvariation) {
+ $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
+ }
my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
if ($target ne 'tex' && $direction eq 'horizontal') {
$result.="";
}
+ my $numlines;
+ if (($target eq 'tex') && ($Apache::lonhomework::type eq 'exam')) {
+ my $numitems = scalar(@{ $whichfoils });
+ $numlines = int($numitems/$bubbles_per_line);
+ if (($numitems % $bubbles_per_line) != 0) {
+ $numlines ++;
+ }
+ if ($numlines < 1) {
+ $numlines = 1;
+ }
+ if ($numlines > 1) {
+ my $linetext;
+ for (my $i=0; $i<$numlines; $i++) {
+ $linetext .= $Apache::lonxml::counter+$i.', ';
+ }
+ $linetext =~ s/,\s$//;
+ $result .= '\item[\small {\textbf{'.$linetext.'}}]'.
+ ' {\footnotesize '.
+ &mt('(Bubble once in [_1] lines)',$numlines).
+ '} \hspace*{\fill} \\\\';
+ } else {
+ $result .= '\item[\textbf{'.$Apache::lonxml::counter.'}.]';
+ }
+ }
foreach my $name (@{ $whichfoils }) {
if ($target ne 'tex') {
if ($direction eq 'horizontal') {
@@ -647,24 +700,23 @@ sub displayfoils {
$line++;
$i = 0;
$bubble_number = 0;
- $result.='\item[\textbf{'.($Apache::lonxml::counter+$line).'}.]';
}
- $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
+ my $identifier;
+ if ($numlines > 1) {
+ $identifier = $Apache::lonxml::counter+$line;
+ }
+ $result .= '{\small \textbf{'.$identifier.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
$i++;
$bubble_number++;
} else {
- if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
-
- my $fieldname = $env{'request.symb'}.
- '&part_'. $Apache::inputtags::part.
- '&radiobuttonresponse'.
- '&HWVAL_' . $Apache::inputtags::response['-1'];
- my $value = $temp;
- my $text = $Apache::response::foilgroup{$name.'.text'};
- $result .= &Apache::lonxml::print_pdf_radiobutton($fieldname, $value, $text).'\newline'."\n";
- } else {
- $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
- }
+ if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
+ my $fieldname = $env{'request.symb'}.'&part_'. $Apache::inputtags::part
+ .'&radiobuttonresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'];
+ $result .= '\item[{'.&Apache::lonxml::print_pdf_radiobutton($fieldname,$temp).'}]'
+ .$Apache::response::foilgroup{$name.'.text'}."\n";
+ } else {
+ $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
+ }
}
}
if ($target ne 'tex' && $direction eq 'horizontal') {
@@ -799,6 +851,9 @@ sub end_foil {
&Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
$name=$Apache::lonxml::curdepth;
}
+ if ($name eq "0") {
+ &Apache::lonxml::error(&mt('Foil name [_1] is not supported. Please choose another name.',''.$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.''));
}
@@ -829,6 +884,7 @@ sub insert_foil {
';
}
+
1;
__END__