File:  [LON-CAPA] / loncom / homework / radiobuttonresponse.pm
Revision 1.81: download - view: text, annotated - select for diffs
Wed Feb 25 00:41:47 2004 UTC (20 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG#2754, surveys rendered incorrectly in answer mode

    1: # The LearningOnline Network with CAPA
    2: # mutliple choice style responses
    3: #
    4: # $Id: radiobuttonresponse.pm,v 1.81 2004/02/25 00:41:47 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::radiobuttonresponse;
   30: use strict;
   31: use HTML::Entities();
   32: 
   33: BEGIN {
   34:   &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
   35: }
   36: 
   37: sub start_radiobuttonresponse {
   38:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   39:   my $result;
   40:   #when in a radiobutton response use these
   41:   &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
   42:   push (@Apache::lonxml::namespace,'radiobuttonresponse');
   43:   my $id = &Apache::response::start_response($parstack,$safeeval);
   44:   %Apache::hint::radiobutton=();
   45:   if ($target eq 'meta') {
   46:     $result=&Apache::response::meta_package_write('radiobuttonresponse');
   47:   } elsif ($target eq 'edit' ) {
   48:     $result.=&Apache::edit::start_table($token).
   49: 	'<tr><td>'.&Apache::lonxml::description($token).
   50: 	&Apache::loncommon::help_open_topic('Radio_Response_Problems').
   51: 	"</td><td>Delete:".
   52: 	&Apache::edit::deletelist($target,$token)
   53: 	."</td><td>&nbsp".&Apache::edit::end_row()
   54:         .&Apache::edit::start_spanning_row();
   55: 
   56:     $result.=
   57: 	&Apache::edit::text_arg('Max Number Of Shown Foils:','max',$token,'4').
   58: 	&Apache::edit::select_arg('Randomize Foil Order','randomize',
   59: 				  ['yes','no'],$token).
   60:         &Apache::edit::end_row().&Apache::edit::start_spanning_row()."\n";
   61:   } elsif ($target eq 'modified') {
   62:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
   63: 						 $safeeval,'max','randomize');
   64:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
   65:   } elsif ($target eq 'tex') {
   66:       my $type=&Apache::lonxml::get_param('TeXtype',$parstack,$safeeval,undef,0);
   67:       if ($type eq '1') {
   68: 	  $result .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}';
   69:       } elsif ($type eq 'A') {
   70: 	  $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
   71:       } elsif ($type eq 'a') {
   72: 	  $result .= ' \renewcommand{\labelenumi}{\alph{enumi}.}';
   73:       } elsif ($type eq 'i') {
   74: 	  $result .= ' \renewcommand{\labelenumi}{\roman{enumi}.}';
   75:       }
   76:       $result .= '\begin{enumerate}';
   77:   } elsif ($target eq 'analyze') {
   78:       my $part_id="$Apache::inputtags::part.$id";
   79:       push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
   80:   }
   81:   return $result;
   82: }
   83: 
   84: sub end_radiobuttonresponse {
   85:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   86:   my $result;
   87:   if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
   88:   if ($target eq 'tex') { $result .= '\end{enumerate}'; }
   89:   &Apache::response::end_response;
   90:   pop @Apache::lonxml::namespace;
   91:   &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
   92:   return $result;
   93: }
   94: 
   95: %Apache::response::foilgroup=();
   96: sub start_foilgroup {
   97:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   98:   my $result;
   99:   %Apache::response::foilgroup=();
  100:   $Apache::radiobuttonresponse::conceptgroup=0;
  101:   &Apache::response::setrandomnumber();
  102:   if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
  103:       $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
  104:   }
  105:   return $result;
  106: }
  107: 
  108: sub storesurvey {
  109:   if ( !defined($ENV{'form.submitted'})) { return ''; }
  110:   my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1']};
  111:   &Apache::lonxml::debug("Here I am!:$response:");
  112:   if ( $response !~ /[0-9]+/) { return ''; }
  113:   my $id = $Apache::inputtags::response['-1'];
  114:   my @whichfoils=@{ $Apache::response::foilgroup{'names'} };
  115:   my %responsehash;
  116:   $responsehash{$whichfoils[$response]}=$response;
  117:   $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=&Apache::lonnet::hash2str(%responsehash);
  118:   $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='SUBMITTED';
  119:   &Apache::lonxml::debug("submitted a $response<br />\n");
  120:   return '';
  121: }
  122: 
  123: sub grade_response {
  124:   my ($max,$randomize)=@_;
  125:   #keep the random numbers the same must always call this
  126:   my ($answer,@whichfoils)=&whichfoils($max,$randomize);
  127:   if (!defined($ENV{'form.submitted'})) { return; }
  128:   my $response;
  129:   if ($ENV{'form.submitted'} eq 'scantron') {
  130:       $response=&Apache::response::getresponse();
  131:   } else {
  132:       $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1']};
  133:   }
  134:   if ( $response !~ /[0-9]+/) { return; }
  135:   my $part=$Apache::inputtags::part;
  136:   my $id = $Apache::inputtags::response['-1'];
  137:   my %responsehash;
  138:   $responsehash{$whichfoils[$response]}=$response;
  139:   my $responsestr=&Apache::lonnet::hash2str(%responsehash);
  140:   my %previous=&Apache::response::check_for_previous($responsestr,
  141: 						     $part,$id);
  142:   $Apache::lonhomework::results{"resource.$part.$id.submission"}=
  143:     $responsestr;
  144:   &Apache::lonxml::debug("submitted a $response<br />\n");
  145:   my $ad;
  146:   if ($response == $answer) {
  147:     $ad='EXACT_ANS';
  148:   } else {
  149:     $ad='INCORRECT';
  150:   }
  151:   $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
  152:   &Apache::response::handle_previous(\%previous,$ad);
  153: }
  154: 
  155: sub end_foilgroup {
  156:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  157: 
  158:   my $result;
  159:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
  160:       $target eq 'tex' || $target eq 'analyze') {
  161:     my $style = $Apache::lonhomework::type;
  162:     if ( $style eq 'survey'  && $target ne 'analyze') {
  163: 	if ($target eq 'web' || $target eq 'tex') {
  164: 	    $result=&displayallfoils();
  165: 	} elsif ( $target eq 'answer' ) {
  166: 	    $result=&displayallanswers();
  167: 	} elsif ( $target eq 'grade' ) {
  168: 	    $result=&storesurvey();
  169: 	}
  170:     } else {
  171:       my $name;
  172:       my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
  173:       my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
  174: 						 $safeeval,'-2');
  175:       if ($target eq 'web' || $target eq 'tex') {
  176: 	$result=&displayfoils($target,$max,$randomize);
  177:       } elsif ($target eq 'answer' ) {
  178: 	$result=&displayanswers($max,$randomize);
  179:       } elsif ( $target eq 'grade') {
  180: 	&grade_response($max,$randomize);
  181:       }  elsif ( $target eq 'analyze') {
  182: 	  my @shown = &whichfoils($max,$randomize);
  183: 	  &Apache::response::analyze_store_foilgroup(\@shown,
  184: 						  ['text','value','location']);
  185: 	  my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  186: 	  push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },
  187: 		('true','false'));
  188:       }
  189:     }
  190:   }
  191:   &Apache::lonxml::increment_counter();
  192:   return $result;
  193: }
  194: 
  195: sub getfoilcounts {
  196:   my @names;
  197:   my $truecnt=0;
  198:   my $falsecnt=0;
  199:   my $name;
  200:   if ( $Apache::response::foilgroup{'names'} ) {
  201:     @names= @{ $Apache::response::foilgroup{'names'} };
  202:   }
  203:   foreach $name (@names) {
  204:     if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  205:       $truecnt++;
  206:     } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
  207:       $falsecnt++;
  208:     }
  209:   }
  210:   return ($truecnt,$falsecnt);
  211: }
  212: 
  213: sub displayallfoils {
  214:   my $result;
  215:   &Apache::lonxml::debug("survey style display");
  216:   my @names = @{ $Apache::response::foilgroup{'names'} };
  217:   my $temp=0;
  218:   my $id=$Apache::inputtags::response['-1'];
  219:   my $part=$Apache::inputtags::part;
  220:   my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
  221:   my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
  222:   if (&Apache::response::show_answer() ) {
  223:     foreach my $name (@names) {
  224:       if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
  225: 	$result.="<br />".$Apache::response::foilgroup{$name.'.value'};
  226: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  227: 	  $result.='<b>';
  228: 	}
  229: 	$result .= $Apache::response::foilgroup{$name.'.text'};
  230: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  231: 	  $result.='</b>';
  232: 	}
  233:       }
  234:     }
  235:   } else {
  236:     foreach my $name (@names) {
  237:       if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
  238: 	$result.="<br /><input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
  239: 	if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
  240: 	$result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
  241: 	$temp++;
  242:       }
  243:     }
  244:   }
  245:   return $result;
  246: }
  247: 
  248: sub whichfoils {
  249:   my ($max,$randomize)=@_;
  250: 
  251:   my @truelist;
  252:   my @falselist;
  253:   my @whichfalse =();
  254:   my ($truecnt,$falsecnt) = &getfoilcounts();
  255:   my $count=0;
  256:   # we will add in 1 of the true statements
  257:   if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
  258:   my $answer=int(&Math::Random::random_uniform() * ($count));
  259:   &Apache::lonxml::debug("Count is $count, $answer is $answer");
  260:   my @names;
  261:   if ( $Apache::response::foilgroup{'names'} ) {
  262:       @names= @{ $Apache::response::foilgroup{'names'} };
  263:   }
  264:   if (&Apache::response::showallfoils()) {
  265:       @whichfalse=@names;
  266:   } elsif ($randomize eq 'no') {
  267:       &Apache::lonxml::debug("No randomization");
  268:       my $havetrue=0;
  269:       foreach my $name (@names) {
  270: 	  if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  271: 	      if (!$havetrue ) {
  272: 		  push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
  273: 	      }
  274: 	  } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
  275: 	      push (@whichfalse,$name);
  276: 	  } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
  277: 	  } else {
  278: 	      &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>"));
  279: 	  }
  280:       }
  281:   } else {
  282:     my $current=0;
  283:     &Apache::lonhomework::showhash(%Apache::response::foilgroup);
  284:     my (%top,%bottom);
  285:     #first find out where everyone wants to be
  286:     foreach my $name (@names) {
  287: 	$current++;
  288: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  289: 	    push (@truelist,$name);
  290: 	    if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
  291: 		$top{$name}=$current;
  292: 	    } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
  293: 		$bottom{$name}=$current;
  294: 	    }
  295: 	} elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
  296: 	    push (@falselist,$name);
  297: 	    if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
  298: 		$top{$name}=$current;
  299: 	    } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
  300: 		$bottom{$name}=$current;
  301: 	    }
  302: 	} elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
  303: 	} else {
  304: 	    &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>"));
  305: 	}
  306:     }
  307:     #pick a true statement
  308:     my $notrue=0;
  309:     if (scalar(@truelist) == 0) { $notrue=1; }
  310:     my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
  311:     &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
  312:     my (@toplist, @bottomlist);
  313:     my $topcount=0;
  314:     my $bottomcount=0;
  315:     # assign everyone to either toplist/bottomlist or whichfalse
  316:     # which false is randomized, toplist bottomlist are in order
  317:     while ((($#whichfalse+$topcount+$bottomcount) < $max-2) && ($#falselist > -1)) {
  318: 	&Apache::lonxml::debug("Have $#whichfalse max is $max");
  319: 	my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
  320: 	&Apache::lonxml::debug("From $#falselist elms, picking $afalse");
  321: 	$afalse=splice(@falselist,$afalse,1);
  322: 	&Apache::lonxml::debug("Picked $afalse");
  323: 	&Apache::lonhomework::showhash(('names'=>\@names));
  324: 	&Apache::lonhomework::showhash(%top);
  325: 	if ($top{$afalse}) {
  326: 	    $toplist[$top{$afalse}]=$afalse;
  327: 	    $topcount++;
  328: 	} elsif ($bottom{$afalse}) {
  329: 	    $bottomlist[$bottom{$afalse}]=$afalse;
  330: 	    $bottomcount++;
  331: 	} else {
  332: 	    push (@whichfalse,$afalse);
  333: 	}
  334:     }
  335:     &Apache::lonxml::debug("Answer wants $answer");
  336:     my $truename=$truelist[$whichtrue];
  337:     my $dosplice=1;
  338:     if ($notrue) {
  339: 	$dosplice=0;
  340: 	&Apache::lonxml::error("There are no true statements available.<br />");
  341:     }
  342:     #insert the true statement, keeping track of where it wants to be
  343:     if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
  344: 	$toplist[$top{$truename}]=$truename;
  345: 	$answer=-1;
  346: 	foreach my $top (reverse(@toplist)) {
  347: 	    if ($top) { $answer++;}
  348: 	    if ($top eq $truename) { last; }
  349: 	}
  350: 	$dosplice=0;
  351:     } elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom' && $dosplice) {
  352: 	$bottomlist[$bottom{$truename}]=$truename;
  353: 	$answer=-1;
  354: 	foreach my $bot (@bottomlist) {
  355: 	    if ($bot) { $answer++;}
  356: 	    if ($bot eq $truename) { last; }
  357: 	}
  358: 	$answer+=$topcount+$#whichfalse+1;
  359: 	$dosplice=0;
  360:     } else {
  361: 	if ($topcount>0 || $bottomcount>0) {
  362: 	    $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
  363: 		+ $topcount;
  364: 	}
  365:     }
  366:     &Apache::lonxml::debug("Answer now wants $answer");
  367:     #add the top items to the top, bottom items to the bottom
  368:     for (my $i=0;$i<=$#toplist;$i++) {
  369: 	if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
  370:     }
  371:     for (my $i=0;$i<=$#bottomlist;$i++) {
  372: 	if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
  373:     }
  374:     #if the true statement is randomized insert it into the list
  375:     if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
  376:   }
  377:   &Apache::lonxml::debug("Answer is $answer");
  378:   return ($answer,@whichfalse);
  379: }
  380: 
  381: sub displayfoils {
  382:   my ($target,$max,$randomize)=@_;
  383:   my $result;
  384: 
  385:   my ($answer,@whichfoils)=&whichfoils($max,$randomize);
  386:   my $part=$Apache::inputtags::part;
  387:   my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
  388:   if ( ($target ne 'tex') &&
  389:        &Apache::response::show_answer() ) {
  390:     foreach my $name (@whichfoils) {
  391:       if ($target ne 'tex') {
  392: 	  $result.="<br />";
  393:       } else {
  394: 	  $result.='\item \vskip -2 mm  ';
  395:       }
  396:       if ($Apache::response::foilgroup{$name.'.value'} eq 'true') { 
  397: 	  if ($target ne 'tex') { $result.='Correct:<b>'; } else { $result.='Correct: \textbf{';}
  398:       } else {
  399: 	$result.='Incorrect:';
  400:       }
  401:       if ($target ne 'tex') {
  402: 	  $result.=$Apache::response::foilgroup{$name.'.text'}."</input>\n";
  403:       } else {
  404: 	  $result.=$Apache::response::foilgroup{$name.'.text'};
  405:       }
  406:       if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  407: 	  if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
  408:       }
  409:     }
  410:   } else {
  411:     my @alphabet = ('A'..'Z');
  412:     my $i = 0;
  413:     my $temp=0;  
  414:     my $id=$Apache::inputtags::response['-1'];
  415:     my $part=$Apache::inputtags::part;
  416:     my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
  417:     my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
  418:     foreach my $name (@whichfoils) {
  419:       if ($target ne 'tex') {
  420: 	  $result.="<br /><input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
  421: 	  if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
  422: 	  $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
  423:       } else {
  424: 	  if ($Apache::lonhomework::type eq 'exam') {
  425: 	      $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs
  426: 	      $i++;
  427: 	  } else {
  428: 	      $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
  429: 	  }
  430:       }
  431:       $temp++;
  432:     }
  433:   }
  434:   if ($target ne 'tex') { $result.="<br />"; } else { $result.='\vskip 0 mm '; }
  435:   return $result;
  436: }
  437: 
  438: sub displayallanswers {
  439:     my @names = @{ $Apache::response::foilgroup{'names'} };
  440:   
  441:     my $result=&Apache::response::answer_header('radiobuttonresponse');
  442:     foreach my $name (@names) {
  443: 	$result.=&Apache::response::answer_part('radiobuttonresponse',
  444: 				$Apache::response::foilgroup{$name.'.value'});
  445:     }
  446:     $result.=&Apache::response::answer_footer('radiobuttonresponse');
  447:     return $result;
  448: }
  449: 
  450: sub displayanswers {
  451:   my ($max,$randomize)=@_;
  452:   my ($answer,@whichopt) = &whichfoils($max,$randomize);
  453:   my $result=&Apache::response::answer_header('radiobuttonresponse');
  454:   foreach my $name (@whichopt) {
  455:     $result.=&Apache::response::answer_part('radiobuttonresponse',
  456: 		     $Apache::response::foilgroup{$name.'.value'})
  457:   }
  458:   $result.=&Apache::response::answer_footer('radiobuttonresponse');
  459:   return $result;
  460: }
  461: 
  462: sub start_conceptgroup {
  463:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  464:   $Apache::radiobuttonresponse::conceptgroup=1;
  465:   %Apache::response::conceptgroup=();
  466:   my $result;
  467:   if ($target eq 'edit') {
  468:     $result.=&Apache::edit::tag_start($target,$token);
  469:     $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
  470: 	&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  471:   } elsif ($target eq 'modified') {
  472:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  473: 						 $safeeval,'concept');
  474:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  475:   }
  476:   return $result;
  477: }
  478: 
  479: sub end_conceptgroup {
  480:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  481:   $Apache::radiobuttonresponse::conceptgroup=0;
  482:   my $result;
  483:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'  ||
  484:       $target eq 'tex' || $target eq 'analyze') {
  485:       &Apache::response::pick_foil_for_concept($target,
  486: 					       ['value','text','location'],
  487: 					       \%Apache::hint::radiobutton,
  488: 					       $parstack,$safeeval);
  489:   } elsif ($target eq 'edit') {
  490:     $result=&Apache::edit::end_table();
  491:   }
  492:   return $result;
  493: }
  494: 
  495: sub insert_conceptgroup {
  496:   my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
  497:   return $result;
  498: }
  499: 
  500: sub start_foil {
  501:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  502:   my $result='';
  503:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
  504:     &Apache::lonxml::startredirection;
  505:   } elsif ($target eq 'edit') {
  506:     $result=&Apache::edit::tag_start($target,$token);
  507:     $result.=&Apache::edit::text_arg('Name:','name',$token);
  508:     $result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
  509: 				       ['unused','true','false'],$token);
  510:     my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
  511: 					     $safeeval,'-3');
  512:     if ($randomize ne 'no') {
  513:       $result.=&Apache::edit::select_arg('Location:','location',
  514: 					 ['random','top','bottom'],$token);
  515:     }
  516:     $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  517:   } elsif ($target eq 'modified') {
  518:      my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
  519: 						  'value','name','location');
  520:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  521:   } 
  522:   return $result;
  523: }
  524: 
  525: sub end_foil {
  526:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  527:   my $text='';
  528:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
  529:       $text=&Apache::lonxml::endredirection;
  530:   }
  531:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'  || $target eq 'tex' || $target eq 'analyze') {
  532:     my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
  533:     if ($value ne 'unused') {
  534:       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  535:       my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
  536:       if (!$name) { $name=$Apache::lonxml::curdepth; }
  537:       if ( $Apache::radiobuttonresponse::conceptgroup
  538: 	   && !&Apache::response::showallfoils() ) {
  539: 	push @{ $Apache::response::conceptgroup{'names'} }, $name;
  540: 	$Apache::response::conceptgroup{"$name.value"} = $value;
  541: 	$Apache::response::conceptgroup{"$name.text"} = $text;	
  542: 	$Apache::response::conceptgroup{"$name.location"} = $location;	
  543:       } else {
  544: 	push @{ $Apache::response::foilgroup{'names'} }, $name;
  545: 	$Apache::response::foilgroup{"$name.value"} = $value;
  546: 	$Apache::response::foilgroup{"$name.text"} = $text;
  547: 	$Apache::response::foilgroup{"$name.location"} = $location;
  548:       }
  549:     }
  550:   }
  551:   return '';
  552: }
  553: 
  554: sub insert_foil {
  555:   return '
  556: <foil name="" value="unused">
  557: <startouttext />
  558: <endouttext />
  559: </foil>';
  560: }
  561: 1;
  562: __END__
  563:  

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