Diff for /loncom/homework/radiobuttonresponse.pm between versions 1.145 and 1.151

version 1.145, 2010/05/03 14:43:50 version 1.151, 2011/09/13 21:42:58
Line 138  sub end_radiobuttonresponse { Line 138  sub end_radiobuttonresponse {
 %Apache::response::foilgroup=();  %Apache::response::foilgroup=();
 sub start_foilgroup {  sub start_foilgroup {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;  
     %Apache::response::foilgroup=();      %Apache::response::foilgroup=();
     $Apache::radiobuttonresponse::conceptgroup=0;      $Apache::radiobuttonresponse::conceptgroup=0;
     &Apache::response::pushrandomnumber();      &Apache::response::pushrandomnumber(undef,$target);
     if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {      return;
  $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';  
     }  
     return $result;  
 }  }
   
 sub storesurvey {  sub storesurvey {
Line 167  sub storesurvey { Line 163  sub storesurvey {
     if ($style eq 'anonsurvey') {      if ($style eq 'anonsurvey') {
         $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';          $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
     } elsif ($style eq 'anonsurveycred') {      } 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') {      } elsif ($style eq 'surveycred') {
         $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';          $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
     } else {      } else {
Line 222  sub end_foilgroup { Line 218  sub end_foilgroup {
   
     my $result;      my $result;
     my $bubble_lines;      my $bubble_lines;
     my $bubbles_per_line;  
     my $answer_count;      my $answer_count;
     my $id   = $Apache::inputtags::response['-1'];      my $id   = $Apache::inputtags::response['-1'];
     my $part = $Apache::inputtags::part;      my $part = $Apache::inputtags::part;
     $bubbles_per_line =       my $bubbles_per_line = &getbubblesnum($part,$id);
  &Apache::response::get_response_param($Apache::inputtags::part."_$id",  
       'numbubbles',  
       $default_bubbles_per_line);  
   
   
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||      if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
  $target eq 'tex' || $target eq 'analyze') {   $target eq 'tex' || $target eq 'analyze') {
Line 260  sub end_foilgroup { Line 251  sub end_foilgroup {
     $answer_count = scalar(@shown);      $answer_count = scalar(@shown);
   
     if ($target eq 'web' || $target eq 'tex') {      if ($target eq 'web' || $target eq 'tex') {
  $result=&displayfoils($target,                  $result=&displayfoils($target,
       $answer, \@shown,        $answer, \@shown,
       $direction,        $direction,
       $bubbles_per_line);        $bubbles_per_line);
Line 295  sub end_foilgroup { Line 286  sub end_foilgroup {
     return $result;      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 {  sub getfoilcounts {
     my @names;      my @names;
     my $truecnt=0;      my $truecnt=0;
Line 336  sub displayallfoils { Line 341  sub displayallfoils {
     my $i   =0;      my $i   =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;      my ($lastresponse,$newvariation,$showanswer);
     unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) {      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 =           $lastresponse = 
     $Apache::lonhomework::history{"resource.$part.$id.submission"};      $Apache::lonhomework::history{"resource.$part.$id.submission"};
     }      }
     if ($direction eq 'horizontal') { $result.='<table><tr>'; }      if ($direction eq 'horizontal') { $result.='<table><tr>'; }
     my %lastresponse=&Apache::lonnet::str2hash($lastresponse);      my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
     if (&Apache::response::show_answer() ) {      if ($showanswer) {
  foreach my $name (@names) {   foreach my $name (@names) {
     if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {      if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
  if (($direction eq 'horizontal') && ($target ne 'tex')) {   if (($direction eq 'horizontal') && ($target ne 'tex')) {
Line 400  sub displayallfoils { Line 415  sub displayallfoils {
                        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="checked"'; }      if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
     $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.      $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.
  '</label>';   '</label>';
Line 544  sub whichfoils { Line 560  sub whichfoils {
     $dosplice=0;      $dosplice=0;
  } else {   } else {
     if ($topcount>0 || $bottomcount>0) {      if ($topcount>0 || $bottomcount>0) {
  $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))                  my $inc = 1;
     + $topcount;                  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");   &Apache::lonxml::debug("Answer now wants $answer");
Line 617  sub displayfoils { Line 637  sub displayfoils {
  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=$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);   my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
  if ($target ne 'tex' && $direction eq 'horizontal') {   if ($target ne 'tex' && $direction eq 'horizontal') {
     $result.="<table><tr>";      $result.="<table><tr>";
  }   }
           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 }) {   foreach my $name (@{ $whichfoils }) {
     if ($target ne 'tex') {      if ($target ne 'tex') {
  if ($direction eq 'horizontal') {   if ($direction eq 'horizontal') {
Line 645  sub displayfoils { Line 700  sub displayfoils {
  $line++;   $line++;
  $i = 0;   $i = 0;
  $bubble_number = 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++;      $i++;
     $bubble_number++;      $bubble_number++;
  } else {   } else {
Line 793  sub end_foil { Line 851  sub end_foil {
  &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));   &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
  $name=$Apache::lonxml::curdepth;   $name=$Apache::lonxml::curdepth;
     }      }
               if ($name eq "0") {
                   &Apache::lonxml::error(&mt('Foil name [_1] is not supported. Please choose another name.','<b><tt>'.$name.'</tt></b>'));
               }
     if (defined($Apache::response::foilnames{$name})) {      if (defined($Apache::response::foilnames{$name})) {
  &Apache::lonxml::error(&mt('Foil name [_1] appears more than once. Foil names need to be unique.','<b><tt>'.$name.'</tt></b>'));   &Apache::lonxml::error(&mt('Foil name [_1] appears more than once. Foil names need to be unique.','<b><tt>'.$name.'</tt></b>'));
     }      }
Line 823  sub insert_foil { Line 884  sub insert_foil {
 <endouttext />  <endouttext />
 </foil>';  </foil>';
 }  }
   
 1;  1;
 __END__  __END__
   

Removed from v.1.145  
changed lines
  Added in v.1.151


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