Diff for /loncom/homework/radiobuttonresponse.pm between versions 1.153.6.1 and 1.153.6.3

version 1.153.6.1, 2012/01/20 11:41:31 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 769  sub whichfoils { Line 772  sub whichfoils {
     return ( $answer, @whichfalse );      return ( $answer, @whichfalse );
 }  }
 ##  ##
 # Display foils in html rendition:  # 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 $whichfoils - Set of foils to display.
 # @param $target     - Rendition target...there are several html targets.  # @param $target     - Rendition target...there are several html targets.
Line 838  sub display_foils_html { Line 911  sub display_foils_html {
  $result .= $finalclose;   $result .= $finalclose;
   
     } else {      } else {
    $result .= '<br />'; # end line prior to foilgroup:
   
  #  Not showing the answers, we need to generate the HTML appropriate   #  Not showing the answers, we need to generate the HTML appropriate
  #  to allowing the student to respond.   #  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;      return $result;
Line 863  sub displayfoils { Line 964  sub displayfoils {
  $result = &display_foils_html(   $result = &display_foils_html(
     $whichfoils, $target, $direction, $part, $solved, 1);      $whichfoils, $target, $direction, $part, $solved, 1);
   
 #        if ( $direction eq 'horizontal' ) {      }  else {
 #            if ( $target ne 'tex' ) {  
 #                $result .= '<table><tr>';  
 #            }  
 #        }  
 #        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;
 }  }
   

Removed from v.1.153.6.1  
changed lines
  Added in v.1.153.6.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>