File:  [LON-CAPA] / loncom / homework / radiobuttonresponse.pm
Revision 1.72: download - view: text, annotated - select for diffs
Fri Jun 20 04:05:13 2003 UTC (20 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: version_1_0_2, version_1_0_1, version_1_0_0, version_0_99_5, version_0_99_4, version_0_99_3, HEAD
- Bug #35, RBR now complains if no true foils available

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

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