version 1.153, 2012/01/05 11:56:34
|
version 1.153.6.3, 2012/01/21 21:40:41
|
Line 33 use Apache::lonnet;
|
Line 33 use Apache::lonnet;
|
use Apache::response; |
use Apache::response; |
|
|
my $default_bubbles_per_line = 10; |
my $default_bubbles_per_line = 10; |
|
my @alphabet = ( 'A' .. 'Z' ); # Foil labels. |
|
|
|
|
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register( 'Apache::radiobuttonresponse', |
&Apache::lonxml::register( 'Apache::radiobuttonresponse', |
Line 387 sub format_prior_answer {
|
Line 390 sub format_prior_answer {
|
|
|
} |
} |
|
|
|
## |
sub displayallfoils { |
sub displayallfoils { |
my ( $direction, $target ) = @_; |
my ( $direction, $target ) = @_; |
my $result; |
my $result; |
Line 767 sub whichfoils {
|
Line 771 sub whichfoils {
|
&Apache::lonxml::debug("Answer is $answer"); |
&Apache::lonxml::debug("Answer is $answer"); |
return ( $answer, @whichfalse ); |
return ( $answer, @whichfalse ); |
} |
} |
|
## |
|
# Generate the HTML for a single html foil. |
|
# @param $part - The part for which the response is being generated. |
|
# @param $fieldname - The basename of the radiobutton field |
|
# @param $name - The foilname. |
|
# @param $last_responses - Reference to a hash that holds the most recent |
|
# responses. |
|
# @param $value - radiobutton value. |
|
# |
|
# @return text |
|
# @retval The generated html. |
|
# |
|
sub html_radiobutton { |
|
my ($part, $fieldname, $name, $last_responses, $value) = @_; |
|
|
|
my $result='<label>'; |
|
|
|
$result .= '<input type="radio" |
|
onchange="javascript:setSubmittedPart(' . "'$part');\"" |
|
. 'name="HWVAL_' . $fieldname . '"' |
|
. "value='$value'"; |
|
|
|
if (defined($last_responses->{$name})) { |
|
$result .= ' checked="checked" '; |
|
} |
|
$result .= ' />'; |
|
$result .= $Apache::response::foilgroup{$name . '.text'}; |
|
$result .= '</label>'; |
|
|
|
return $result; |
|
|
|
} |
|
## |
|
# Return a reference to the last response hash. This hash has exactly |
|
# one or zero entries. The one entry is keyed by the foil 'name' of |
|
# the prior response |
|
# |
|
# @param $part - Number of the problem part. |
|
# |
|
# @return reference to a hash. |
|
# @retval see above. |
|
# |
|
sub get_last_response { |
|
my ($part) = @_; |
|
|
|
my $id = $Apache::inputtags::response['-1']; |
|
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); |
|
|
|
return \%lastresponse; |
|
} |
|
|
|
## |
|
# Display foils in html rendition.: |
|
# |
|
# @param $whichfoils - Set of foils to display. |
|
# @param $target - Rendition target...there are several html targets. |
|
# @param $direction - 'horizontal' if layout is horizontal. |
|
# @param $part - Part of the problem that's being displayed. |
|
# @param $solved - Solution state of the problem. |
|
# @param $show_answer- True if answers should be shown. |
|
# |
|
# @return string |
|
# @retval generated html. |
|
# |
|
sub display_foils_html { |
|
my ($whichfoils, $target, $direction, $part, $solved, $show_answer) = @_; |
|
my $result; |
|
|
|
# if the answers get shown, we need to label each item as correct or |
|
# incorrect. |
|
|
|
if ($show_answer) { |
|
my $item_pretext = '<br />'; # html prior to each item |
|
my $item_posttext = ''; # html after each item. |
|
my $finalclose = ''; # html to close off the whole shebang |
|
|
|
|
|
# Horizontal layout is a table with each foil in a cell |
|
|
|
if ($direction eq 'horizontal') { |
|
$result = '<table><tr>'; |
|
$item_pretext = '<td>' . $item_pretext; |
|
$item_posttext = '</td>'; |
|
$finalclose = '</tr></table>'; |
|
} |
|
|
|
foreach my $name (@{$whichfoils}) { |
|
|
|
# If the item gets further surrounded by tags, this |
|
# holds the closures for those tages. |
|
|
|
my $item_closetag = ''; |
|
|
|
$result .= $item_pretext; |
|
|
|
# Label each foil as correct or incorrect: |
|
|
|
if ($Apache::response::foilgroup{$name . '.value'} eq 'true') { |
|
$result .= &mt('Correct:') . '<b>'; |
|
$item_closetag .= '</b>'; |
|
|
|
} else { |
|
$result .= &mt('Incorrect'); |
|
} |
|
|
|
# Web rendition encloses the |
|
# item text in a label tag as well: |
|
|
|
if ($target eq 'web') { |
|
$result .= '<label>'; |
|
$item_closetag = '</label>' . $item_closetag; |
|
} |
|
$result .= $Apache::response::foilgroup{$name . '.text'}; |
|
$result .= $item_closetag; |
|
$result .= $item_posttext; |
|
$result .= "\n"; # make the html a bit more readable. |
|
} |
|
|
|
$result .= $finalclose; |
|
|
|
} else { |
|
$result .= '<br />'; # end line prior to foilgroup: |
|
|
|
# Not showing the answers, we need to generate the HTML appropriate |
|
# to allowing the student to respond. |
|
|
|
my $item_pretext; |
|
my $item_posttext; |
|
my $lastresponse = &get_last_response($part); |
|
|
|
if ( $direction eq 'horizontal' ) { |
|
$item_pretext = '<td>'; |
|
$item_posttext = '</td>'; |
|
} |
|
else { |
|
$item_pretext = '<br/>'; |
|
} |
|
my $item_no = 0; |
|
foreach my $name (@{$whichfoils}) { |
|
$result .= $item_pretext; |
|
$result .= &html_radiobutton( |
|
$part, $Apache::inputtags::response[-1], |
|
$name, $lastresponse, $item_no |
|
); |
|
$result .= $item_posttext; |
|
$item_no++; |
|
} |
|
|
|
if ($direction eq 'horizontal' ) { |
|
$result .= "</tr></table>"; |
|
} else { |
|
$result .= "<br />"; |
|
} |
|
} |
|
|
|
return $result; |
|
} |
|
|
|
|
|
## |
|
|
sub displayfoils { |
sub displayfoils { |
my ( $target, $answer, $whichfoils, $direction, $bubbles_per_line ) = @_; |
my ( $target, $answer, $whichfoils, $direction, $bubbles_per_line ) = @_; |
Line 777 sub displayfoils {
|
Line 960 sub displayfoils {
|
if ( ( $target ne 'tex' ) |
if ( ( $target ne 'tex' ) |
&& &Apache::response::show_answer() ) |
&& &Apache::response::show_answer() ) |
{ |
{ |
if ( $direction eq 'horizontal' ) { |
|
if ( $target ne 'tex' ) { |
$result = &display_foils_html( |
$result .= '<table><tr>'; |
$whichfoils, $target, $direction, $part, $solved, 1); |
} |
|
} |
} else { |
foreach my $name ( @{$whichfoils} ) { |
|
if ( $direction eq 'horizontal' ) { |
|
if ( $target ne 'tex' ) { $result .= '<td>'; } |
|
} |
|
if ( $target ne 'tex' ) { |
|
$result .= "<br />"; |
|
} |
|
else { |
|
$result .= '\item \vskip -2 mm '; |
|
} |
|
if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) { |
|
if ( $target ne 'tex' ) { |
|
$result .= &mt('Correct:') . '<b>'; |
|
} |
|
else { |
|
$result .= &mt('Correct:') . ' \textbf{'; |
|
} |
|
} |
|
else { |
|
$result .= &mt('Incorrect:'); |
|
} |
|
if ( $target eq 'web' ) { $result .= "<label>"; } |
|
$result .= $Apache::response::foilgroup{ $name . '.text' }; |
|
if ( $target eq 'web' ) { $result .= "</label>"; } |
|
if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) { |
|
if ( $target ne 'tex' ) { $result .= '</b>'; } |
|
else { $result .= '}'; } |
|
} |
|
if ( $direction eq 'horizontal' ) { |
|
if ( $target ne 'tex' ) { $result .= '</td>'; } |
|
} |
|
} |
|
if ( $direction eq 'horizontal' ) { |
|
if ( $target ne 'tex' ) { |
|
$result .= '</tr></table>'; |
|
} |
|
} |
|
} |
|
else { |
|
my @alphabet = ( 'A' .. 'Z' ); |
|
my $i = 0; |
my $i = 0; |
my $bubble_number = 0; |
my $bubble_number = 0; |
my $line = 0; |
my $line = 0; |
my $temp = 0; |
my $temp = 0; |
my $id = $Apache::inputtags::response['-1']; |
my $id = $Apache::inputtags::response['-1']; |
my $part = $Apache::inputtags::part; |
my $part = $Apache::inputtags::part; |
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 |
if ($target ne 'tex') { |
$Apache::lonhomework::history{"resource.$part.rndseed"} ) |
$result = &display_foils_html($whichfoils, $target, $direction, $part, |
{ |
0, 0); |
$newvariation = 1; |
} else { |
} |
|
} |
|
unless ($newvariation) { |
my $numlines; |
$lastresponse = |
|
$Apache::lonhomework::history{"resource.$part.$id.submission"}; |
|
} |
|
my %lastresponse = &Apache::lonnet::str2hash($lastresponse); |
# Rendering for latex exams. |
if ( $target ne 'tex' && $direction eq 'horizontal' ) { |
|
$result .= "<table><tr>"; |
if ( ( $Apache::lonhomework::type eq 'exam' ) ) |
} |
{ |
my $numlines; |
my $numitems = scalar( @{$whichfoils} ); |
if ( ( $target eq 'tex' ) && ( $Apache::lonhomework::type eq 'exam' ) ) |
$numlines = int( $numitems / $bubbles_per_line ); |
{ |
if ( ( $numitems % $bubbles_per_line ) != 0 ) { |
my $numitems = scalar( @{$whichfoils} ); |
$numlines++; |
$numlines = int( $numitems / $bubbles_per_line ); |
} |
if ( ( $numitems % $bubbles_per_line ) != 0 ) { |
if ( $numlines < 1 ) { |
$numlines++; |
$numlines = 1; |
} |
} |
if ( $numlines < 1 ) { |
if ( $numlines > 1 ) { |
$numlines = 1; |
my $linetext; |
} |
for ( my $i = 0 ; $i < $numlines ; $i++ ) { |
if ( $numlines > 1 ) { |
$linetext .= $Apache::lonxml::counter + $i . ', '; |
my $linetext; |
} |
for ( my $i = 0 ; $i < $numlines ; $i++ ) { |
$linetext =~ s/,\s$//; |
$linetext .= $Apache::lonxml::counter + $i . ', '; |
$result .= |
} |
'\item[\small {\textbf{' |
$linetext =~ s/,\s$//; |
. $linetext . '}}]' |
$result .= |
. ' {\footnotesize ' |
'\item[\small {\textbf{' |
. &mt( '(Bubble once in [_1] lines)', $numlines ) |
. $linetext . '}}]' |
. '} \hspace*{\fill} \\\\'; |
. ' {\footnotesize ' |
} |
. &mt( '(Bubble once in [_1] lines)', $numlines ) |
else { |
. '} \hspace*{\fill} \\\\'; |
$result .= '\item[\textbf{' . $Apache::lonxml::counter . '}.]'; |
} |
} |
else { |
} # tex/exam |
$result .= '\item[\textbf{' . $Apache::lonxml::counter . '}.]'; |
|
} |
|
} |
foreach my $name ( @{$whichfoils} ) { |
foreach my $name ( @{$whichfoils} ) { |
|
if ( $target ne 'tex' ) { |
|
if ( $direction eq 'horizontal' ) { |
if ( $Apache::lonhomework::type eq 'exam' ) { |
$result .= "<td>"; |
if ( $bubble_number >= $bubbles_per_line ) { |
} |
$line++; |
else { |
$i = 0; |
$result .= "<br />"; |
$bubble_number = 0; |
} |
} |
} |
my $identifier; |
if ( $target ne 'tex' ) { |
if ( $numlines > 1 ) { |
$result .= '<label>'; |
$identifier = $Apache::lonxml::counter + $line; |
$result .= "<input type=\"radio\" |
} |
onchange=\"javascript:setSubmittedPart('$part');\" |
$result .= |
name=\"HWVAL_$Apache::inputtags::response['-1']\" |
'{\small \textbf{' |
value=\"$temp\""; |
. $identifier |
if ( defined( $lastresponse{$name} ) ) { |
. $alphabet[$i] |
$result .= ' checked="checked"'; |
. '}}$\bigcirc$' |
} |
. $Apache::response::foilgroup{ $name . '.text' } |
$result .= ' />' |
. '\\\\'; #' stupid emacs |
. $Apache::response::foilgroup{ $name . '.text' } |
$i++; |
. "</label>"; |
$bubble_number++; |
} |
} |
else { |
else { |
if ( $Apache::lonhomework::type eq 'exam' ) { |
if ( $env{'form.pdfFormFields'} eq 'yes' |
if ( $bubble_number >= $bubbles_per_line ) { |
&& $Apache::inputtags::status[-1] eq 'CAN_ANSWER' ) |
$line++; |
{ |
$i = 0; |
my $fieldname = |
$bubble_number = 0; |
$env{'request.symb'} |
} |
. '&part_' |
my $identifier; |
. $Apache::inputtags::part |
if ( $numlines > 1 ) { |
. '&radiobuttonresponse' |
$identifier = $Apache::lonxml::counter + $line; |
. '&HWVAL_' |
} |
. $Apache::inputtags::response['-1']; |
$result .= |
$result .= '\item[{' |
'{\small \textbf{' |
. &Apache::lonxml::print_pdf_radiobutton( $fieldname, |
. $identifier |
$temp ) |
. $alphabet[$i] |
. '}]' |
. '}}$\bigcirc$' |
. $Apache::response::foilgroup{ $name . '.text' } |
. $Apache::response::foilgroup{ $name . '.text' } |
. "\n"; |
. '\\\\'; #' stupid emacs |
} |
$i++; |
else { |
$bubble_number++; |
$result .= '\vspace*{-2 mm}\item ' |
} |
. $Apache::response::foilgroup{ $name . '.text' }; |
else { |
} |
if ( $env{'form.pdfFormFields'} eq 'yes' |
} |
&& $Apache::inputtags::status[-1] eq 'CAN_ANSWER' ) |
|
{ |
$temp++; |
my $fieldname = |
} |
$env{'request.symb'} |
if ($target eq 'tex') { |
. '&part_' |
$result .= '\vskip 0 mm '; |
. $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' ) { |
|
$result .= "</td>"; |
|
} |
|
$temp++; |
|
} |
|
if ( $target ne 'tex' && $direction eq 'horizontal' ) { |
|
$result .= "</tr></table>"; |
|
} |
|
} |
|
if ( $target ne 'tex' ) { |
|
if ( $direction ne 'horizontal' ) { $result .= "<br />"; } |
|
} |
} |
else { $result .= '\vskip 0 mm '; } |
|
return $result; |
return $result; |
} |
} |
|
|