Diff for /loncom/homework/radiobuttonresponse.pm between versions 1.134.2.1 and 1.143

version 1.134.2.1, 2008/12/11 03:29:30 version 1.143, 2009/05/23 05:04:58
Line 25 Line 25
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
   
   
 package Apache::radiobuttonresponse;  package Apache::radiobuttonresponse;
 use strict;  use strict;
 use HTML::Entities();  use HTML::Entities();
Line 65  sub start_radiobuttonresponse { Line 67  sub start_radiobuttonresponse {
     if ($target eq 'meta') {      if ($target eq 'meta') {
  $result=&Apache::response::meta_package_write('radiobuttonresponse');   $result=&Apache::response::meta_package_write('radiobuttonresponse');
     } elsif ($target eq 'edit' ) {      } elsif ($target eq 'edit' ) {
         $result.=&Apache::edit::start_table($token)   $result.=&Apache::edit::start_table($token)
            .'<tr><td>'.&Apache::lonxml::description($token)             .'<tr><td>'.&Apache::lonxml::description($token)
            .&Apache::loncommon::help_open_topic('Radio_Response_Problems')             .&Apache::loncommon::help_open_topic('Radio_Response_Problems')
            .'</td>'             .'</td>'
Line 102  sub start_radiobuttonresponse { Line 104  sub start_radiobuttonresponse {
  } else {   } else {
     $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';      $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
  }   }
  $result .= '\begin{enumerate}';          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";
           } else {
               $result .= '\begin{enumerate}';
           }
     } elsif ($target eq 'analyze') {      } elsif ($target eq 'analyze') {
  my $part_id="$Apache::inputtags::part.$id";   my $part_id="$Apache::inputtags::part.$id";
         $Apache::lonhomework::analyze{"$part_id.type"} = 'radiobuttonresponse';          $Apache::lonhomework::analyze{"$part_id.type"} = 'radiobuttonresponse';
Line 115  sub end_radiobuttonresponse { Line 122  sub end_radiobuttonresponse {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;      my $result;
     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }      if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
     if ($target eq 'tex') { $result .= '\end{enumerate}'; }      if ($target eq 'tex' and ($env{'form.pdfFormFields'} ne 'yes' or $Apache::inputtags::status[-1] ne 'CAN_ANSWER')) {
           $result .= '\end{enumerate}'; 
       }
     &Apache::response::end_response;      &Apache::response::end_response;
     pop @Apache::lonxml::namespace;      pop @Apache::lonxml::namespace;
     &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));      &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
Line 349  sub displayallfoils { Line 358  sub displayallfoils {
     $result.="<td>";      $result.="<td>";
  } else {   } else {
     if ($target eq 'tex') {      if ($target eq 'tex') {
  $result .= '\item \vskip -2mm ';          if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
     } else {                              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";
                           } else {
                               $result .= '\item \vskip -2mm ';
                           }
                       } else {
  $result.="<br />";   $result.="<br />";
     }      }
  }   }
  if ($target eq 'tex') {   if ($target eq 'tex') {
     $result .= '$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs      if($env{'form.pdfFormFields'} ne 'yes' or $Apache::inputtags::status[-1] ne 'CAN_ANSWER') {
                           $result .= '$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs
                       }
     $i++;      $i++;
  } else {   } else {
     $result .= '<label>';      $result .= '<label>';
Line 363  sub displayallfoils { Line 386  sub displayallfoils {
                        onchange=\"javascript:setSubmittedPart('$part');\"                         onchange=\"javascript:setSubmittedPart('$part');\"
                        type=\"radio\"                         type=\"radio\"
                        name=\"HWVAL_$Apache::inputtags::response['-1']\"                         name=\"HWVAL_$Apache::inputtags::response['-1']\"
                        value=\"$temp\" ";                         value=\"$temp\"";
     if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }      if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
     $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.      $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.
  '</label>';   '</label>';
  }   }
Line 382  sub displayallfoils { Line 405  sub displayallfoils {
     return $result;      return $result;
 }  }
   
 =pod  
   
 =item &whichfoils($max,$randomize)  
   
 Randomizes the list of foils.  
 Respects  
   - each foils desire to be randomized  
   - the existance of Concept groups of foils (select 1 foil from each)  
   - and selects a single correct statement from all possilble true statments  
   - and limits it to a toal of $max foils  
   
 WARNING: this routine uses the random number generator, it should only  
 be called once per target, otherwise it can cause randomness changes in  
 homework problems.  
   
 Arguments  
   $max - maximum number of foils to select (including the true one)  
          (so a max of 5 is: 1 true, 4 false)  
   
   $randomize - whether to randomize the listing of foils, by default  
                will randomize, only if randomize is 'no' will it not  
   
 Returns  
   $answer - location in the array of the correct answer  
   @foils  - array of foil names in to display order  
   
 =cut  
   
 sub whichfoils {  sub whichfoils {
     my ($max,$randomize)=@_;      my ($max,$randomize)=@_;
Line 619  sub displayfoils { Line 615  sub displayfoils {
     "<input type=\"radio\"      "<input type=\"radio\"
                             onchange=\"javascript:setSubmittedPart('$part');\"                              onchange=\"javascript:setSubmittedPart('$part');\"
                             name=\"HWVAL_$Apache::inputtags::response['-1']\"                              name=\"HWVAL_$Apache::inputtags::response['-1']\"
                             value=\"$temp\" ";                              value=\"$temp\"";
  if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }   if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
  $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}."</label>";   $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}."</label>";
     } else {      } else {
  if ($Apache::lonhomework::type eq 'exam') {   if ($Apache::lonhomework::type eq 'exam') {
Line 634  sub displayfoils { Line 630  sub displayfoils {
     $i++;      $i++;
     $bubble_number++;      $bubble_number++;
  } else {   } 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'];
                            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 ($target ne 'tex' && $direction eq 'horizontal') {      if ($target ne 'tex' && $direction eq 'horizontal') {
  $result.="</td>";    $result.="</td>"; 
Line 801  sub insert_foil { Line 808  sub insert_foil {
 }  }
 1;  1;
 __END__  __END__
   
   
   
   =head1 NAME
   
   Apache::radiobuttonresponse
   
   =head1 SYNOPSIS
   
   Handles multiple-choice style responses.
   
   This is part of the LearningOnline Network with CAPA project
   described at http://www.lon-capa.org.
   
   =head1 SUBROUTINES
   
   =over
   
   =item start_radiobuttonresponse()
   
   =item bubble_line_count()
   
   =item end_radiobuttonresponse()
   
   =item start_foilgroup()
   
   =item storesurvey()
   
   =item grade_response()
   
   =item end_foilgroup()
   
   =item getfoilcounts()
   
   =item format_prior_answer()
   
   =item displayallfoils()
   
   =item &whichfoils($max,$randomize)
   
   Randomizes the list of foils.
   Respects
     - each foils desire to be randomized
     - the existance of Concept groups of foils (select 1 foil from each)
     - and selects a single correct statement from all possilble true statments
     - and limits it to a toal of $max foils
   
   WARNING: this routine uses the random number generator, it should only
   be called once per target, otherwise it can cause randomness changes in
   homework problems.
   
   Arguments
     $max - maximum number of foils to select (including the true one)
            (so a max of 5 is: 1 true, 4 false)
   
     $randomize - whether to randomize the listing of foils, by default
                  will randomize, only if randomize is 'no' will it not
   
   Returns
     $answer - location in the array of the correct answer
     @foils  - array of foil names in to display order
   
   =item displayfoils()
   
   =item displayallanswers()
   
   =item displayanswers()
   
   =item start_conceptgroup()
   
   =item end_conceptgroup()
   
   =item insert_conceptgroup()
   
   =item start_foil()
   
   =item end_foil()
   
   =item insert_foil()
   
   =back
   
   =cut
     

Removed from v.1.134.2.1  
changed lines
  Added in v.1.143


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