File:  [LON-CAPA] / loncom / homework / radiobuttonresponse.pm
Revision 1.65: download - view: text, annotated - select for diffs
Fri Apr 4 23:35:17 2003 UTC (21 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- actually submitting scantron results now, I have gottne 1 question for one studnet marked incorrect

- radiobutton now understands a scantron submission,
- radiobuton increments the counter in end_foild group, that way it can be used to acquire the scantron submissions

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

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