File:  [LON-CAPA] / loncom / homework / radiobuttonresponse.pm
Revision 1.68: download - view: text, annotated - select for diffs
Tue Apr 8 02:40:56 2003 UTC (21 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- brining consitancy to the homework input fields

    1: # The LearningOnline Network with CAPA
    2: # mutliple choice style responses
    3: #
    4: # $Id: radiobuttonresponse.pm,v 1.68 2003/04/08 02:40:56 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:   &Apache::lonxml::increment_counter();
  173:   return $result;
  174: }
  175: 
  176: sub getfoilcounts {
  177:   my @names;
  178:   my $truecnt=0;
  179:   my $falsecnt=0;
  180:   my $name;
  181:   if ( $Apache::response::foilgroup{'names'} ) {
  182:     @names= @{ $Apache::response::foilgroup{'names'} };
  183:   }
  184:   foreach $name (@names) {
  185:     if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  186:       $truecnt++;
  187:     } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
  188:       $falsecnt++;
  189:     }
  190:   }
  191:   return ($truecnt,$falsecnt);
  192: }
  193: 
  194: sub displayallfoils {
  195:   my $result;
  196:   &Apache::lonxml::debug("survey style display");
  197:   my @names = @{ $Apache::response::foilgroup{'names'} };
  198:   my $temp=0;
  199:   my $id=$Apache::inputtags::response['-1'];
  200:   my $part=$Apache::inputtags::part;
  201:   my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
  202:   my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
  203:   if (($Apache::lonhomework::history{"resource.$part.solved"} =~ /^correct/)  || ($Apache::inputtags::status[-1] eq  'SHOW_ANSWER')) {
  204:     foreach my $name (@names) {
  205:       if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
  206: 	$result.="<br />".$Apache::response::foilgroup{$name.'.value'};
  207: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  208: 	  $result.='<b>';
  209: 	}
  210: 	$result .= $Apache::response::foilgroup{$name.'.text'};
  211: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  212: 	  $result.='</b>';
  213: 	}
  214:       }
  215:     }
  216:   } else {
  217:     foreach my $name (@names) {
  218:       if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
  219: 	$result.="<br /><input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
  220: 	if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
  221: 	$result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
  222: 	$temp++;
  223:       }
  224:     }
  225:   }
  226:   return $result;
  227: }
  228: 
  229: sub whichfoils {
  230:   my ($max,$randomize)=@_;
  231: 
  232:   my @truelist;
  233:   my @falselist;
  234:   my @whichfalse =();
  235:   my ($truecnt,$falsecnt) = &getfoilcounts();
  236:   my $count=0;
  237:   # we will add in 1 of the true statements
  238:   if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
  239:   my $answer=int(&Math::Random::random_uniform() * ($count));
  240:   &Apache::lonxml::debug("Count is $count, $answer is $answer");
  241:   my @names;
  242:   if ( $Apache::response::foilgroup{'names'} ) {
  243:       @names= @{ $Apache::response::foilgroup{'names'} };
  244:   }
  245:   if (&Apache::response::showallfoils()) {
  246:       @whichfalse=@names;
  247:   } elsif ($randomize eq 'no') {
  248:       &Apache::lonxml::debug("No randomization");
  249:       my $havetrue=0;
  250:       foreach my $name (@names) {
  251: 	  if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  252: 	      if (!$havetrue ) {
  253: 		  push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
  254: 	      }
  255: 	  } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
  256: 	      push (@whichfalse,$name);
  257: 	  } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
  258: 	  } else {
  259: 	      &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>"));
  260: 	  }
  261:       }
  262:   } else {
  263:     my $current=0;
  264:     &Apache::lonhomework::showhash(%Apache::response::foilgroup);
  265:     my (%top,%bottom);
  266:     #first find out where everyone wants to be
  267:     foreach my $name (@names) {
  268: 	$current++;
  269: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  270: 	    push (@truelist,$name);
  271: 	    if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
  272: 		$top{$name}=$current;
  273: 	    } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
  274: 		$bottom{$name}=$current;
  275: 	    }
  276: 	} elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
  277: 	    push (@falselist,$name);
  278: 	    if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
  279: 		$top{$name}=$current;
  280: 	    } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
  281: 		$bottom{$name}=$current;
  282: 	    }
  283: 	} elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
  284: 	} else {
  285: 	    &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>"));
  286: 	}
  287:     }
  288:     #pick a true statement
  289:     my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
  290:     &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
  291:     my (@toplist, @bottomlist);
  292:     my $topcount=0;
  293:     # assign everyone to either toplist/bottomlist or whichfalse
  294:     # which false is randomized, toplist bottomlist are in order
  295:     while ((($#whichfalse) < $max-2) && ($#falselist > -1)) {
  296: 	&Apache::lonxml::debug("Have $#whichfalse max is $max");
  297: 	my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
  298: 	&Apache::lonxml::debug("From $#falselist elms, picking $afalse");
  299: 	$afalse=splice(@falselist,$afalse,1);
  300: 	&Apache::lonxml::debug("Picked $afalse");
  301: 	&Apache::lonhomework::showhash(('names'=>\@names));
  302: 	&Apache::lonhomework::showhash(%top);
  303: 	if ($top{$afalse}) {
  304: 	    $toplist[$top{$afalse}]=$afalse;
  305: 	    $topcount++;
  306: 	} elsif ($bottom{$afalse}) {
  307: 	    $bottomlist[$bottom{$afalse}]=$afalse;
  308: 	} else {
  309: 	    push (@whichfalse,$afalse);
  310: 	}
  311:     }
  312:     my $truename=$truelist[$whichtrue];
  313:     my $dosplice=1;
  314:     #insert the true statement, keeping track of where it wants to be
  315:     if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' ) {
  316: 	$toplist[$top{$truename}]=$truename;
  317: 	$answer=-1;
  318: 	foreach my $top (reverse(@toplist)) {
  319: 	    if ($top) { $answer++;}
  320: 	    if ($top eq $truename) { last; }
  321: 	}
  322: 	$dosplice=0;
  323:     } elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom') {
  324: 	$bottomlist[$bottom{$truename}]=$truename;
  325: 	$answer=-1;
  326: 	foreach my $bot (@bottomlist) {
  327: 	    if ($bot) { $answer++;}
  328: 	    if ($bot eq $truename) { last; }
  329: 	}
  330: 	$answer+=$topcount+$#whichfalse+1;
  331: 	$dosplice=0;
  332:     } else {
  333: 	if ($topcount>0) { 
  334: 	  $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
  335: 	    + $topcount;
  336: 	}
  337:     }
  338:     #add the top items to the top, bottom items to the bottom
  339:     for (my $i=0;$i<=$#toplist;$i++) {
  340: 	if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
  341:     }
  342:     for (my $i=0;$i<=$#bottomlist;$i++) {
  343: 	if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
  344:     }
  345:     #if the true statement is randomized insert it into the list
  346:     if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
  347:   }
  348:   &Apache::lonxml::debug("Answer is $answer");
  349:   return ($answer,@whichfalse);
  350: }
  351: 
  352: sub displayfoils {
  353:   my ($target,$max,$randomize)=@_;
  354:   my $result;
  355: 
  356:   my ($answer,@whichfoils)=&whichfoils($max,$randomize);
  357:   my $part=$Apache::inputtags::part;
  358:   my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
  359:   my $status=$Apache::inputtags::status[-1];
  360:   if ( ($target ne 'tex') &&
  361:        (($solved =~ /^correct/) || ($status eq  'SHOW_ANSWER')) ) {
  362:     foreach my $name (@whichfoils) {
  363:       if ($target ne 'tex') {
  364: 	  $result.="<br />";
  365:       } else {
  366: 	  $result.='\item \vskip -2 mm  ';
  367:       }
  368:       if ($Apache::response::foilgroup{$name.'.value'} eq 'true') { 
  369: 	  if ($target ne 'tex') { $result.='Correct:<b>'; } else { $result.='Correct: \textbf{';}
  370:       } else {
  371: 	$result.='Incorrect:';
  372:       }
  373:       if ($target ne 'tex') {
  374: 	  $result.=$Apache::response::foilgroup{$name.'.text'}."</input>\n";
  375:       } else {
  376: 	  $result.=$Apache::response::foilgroup{$name.'.text'};
  377:       }
  378:       if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
  379: 	  if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
  380:       }
  381:     }
  382:   } else {
  383:     my @alphabet = ('A'..'Z');
  384:     my $i = 0;
  385:     my $temp=0;  
  386:     my $id=$Apache::inputtags::response['-1'];
  387:     my $part=$Apache::inputtags::part;
  388:     my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
  389:     my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
  390:     foreach my $name (@whichfoils) {
  391:       if ($target ne 'tex') {
  392: 	  $result.="<br /><input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
  393: 	  if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
  394: 	  $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
  395:       } else {
  396: 	  if ($Apache::lonhomework::type eq 'exam') {
  397: 	      $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs
  398: 	      $i++;
  399: 	  } else {
  400: 	      $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
  401: 	  }
  402:       }
  403:       $temp++;
  404:     }
  405:   }
  406:   if ($target ne 'tex') { $result.="<br />"; } else { $result.='\vskip 0 mm '; }
  407:   return $result;
  408: }
  409: 
  410: sub displayanswers {
  411:   my ($max,$randomize)=@_;
  412:   my ($answer,@whichopt) = &whichfoils($max,$randomize);
  413:   my $result=&Apache::response::answer_header('radiobuttonresponse');
  414:   foreach my $name (@whichopt) {
  415:     $result.=&Apache::response::answer_part('radiobuttonresponse',
  416: 		     $Apache::response::foilgroup{$name.'.value'})
  417:   }
  418:   $result.=&Apache::response::answer_footer('radiobuttonresponse');
  419:   return $result;
  420: }
  421: 
  422: sub start_conceptgroup {
  423:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  424:   $Apache::radiobuttonresponse::conceptgroup=1;
  425:   %Apache::response::conceptgroup=();
  426:   my $result;
  427:   if ($target eq 'edit') {
  428:     $result.=&Apache::edit::tag_start($target,$token);
  429:     $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
  430: 	&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  431:   } elsif ($target eq 'modified') {
  432:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  433: 						 $safeeval,'concept');
  434:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  435:   }
  436:   return $result;
  437: }
  438: 
  439: sub end_conceptgroup {
  440:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  441:   $Apache::radiobuttonresponse::conceptgroup=0;
  442:   my $result;
  443:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'  || $target eq 'tex') {
  444:     if (defined(@{ $Apache::response::conceptgroup{'names'} })) {
  445:       my @names = @{ $Apache::response::conceptgroup{'names'} };
  446:       my $pick=int(&Math::Random::random_uniform() * ($#names+1));
  447:       my $name=$names[$pick];
  448:       push @{ $Apache::response::foilgroup{'names'} }, $name;
  449:       $Apache::response::foilgroup{"$name.text"} =  $Apache::response::conceptgroup{"$name.text"};
  450:       $Apache::response::foilgroup{"$name.value"} = $Apache::response::conceptgroup{"$name.value"};
  451:       $Apache::response::foilgroup{"$name.location"} = $Apache::response::conceptgroup{"$name.location"};
  452:       my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval);
  453:       $Apache::response::foilgroup{"$name.concept"} = $concept;
  454:       &Apache::lonxml::debug("Selecting $name in $concept");
  455:       my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  456:       push(@{ $Apache::hint::radiobutton{"$part_id.concepts"} },$concept);
  457:       $Apache::hint::radiobutton{"$part_id.concept.$concept"}=
  458: 	  $Apache::response::conceptgroup{'names'};
  459:     }
  460:   } elsif ($target eq 'edit') {
  461:     $result=&Apache::edit::end_table();
  462:   }
  463:   return $result;
  464: }
  465: 
  466: sub insert_conceptgroup {
  467:   my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
  468:   return $result;
  469: }
  470: 
  471: sub start_foil {
  472:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  473:   my $result='';
  474:   if ($target eq 'web' || $target eq 'tex') {
  475:     &Apache::lonxml::startredirection;
  476:   } elsif ($target eq 'edit') {
  477:     $result=&Apache::edit::tag_start($target,$token);
  478:     $result.=&Apache::edit::text_arg('Name:','name',$token);
  479:     $result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
  480: 				       ['unused','true','false'],$token);
  481:     my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
  482: 					     $safeeval,'-3');
  483:     if ($randomize ne 'no') {
  484:       $result.=&Apache::edit::select_arg('Location:','location',
  485: 					 ['random','top','bottom'],$token);
  486:     }
  487:     $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  488:   } elsif ($target eq 'modified') {
  489:      my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
  490: 						  'value','name','location');
  491:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  492:   } 
  493:   return $result;
  494: }
  495: 
  496: sub end_foil {
  497:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  498:   my $text='';
  499:   if ($target eq 'web' || $target eq 'tex') { $text=&Apache::lonxml::endredirection; }
  500:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'  || $target eq 'tex') {
  501:     my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
  502:     if ($value ne 'unused') {
  503:       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  504:       my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
  505:       if (!$name) { $name=$Apache::lonxml::curdepth; }
  506:       if ( $Apache::radiobuttonresponse::conceptgroup
  507: 	   && !&Apache::response::showallfoils() ) {
  508: 	push @{ $Apache::response::conceptgroup{'names'} }, $name;
  509: 	$Apache::response::conceptgroup{"$name.value"} = $value;
  510: 	$Apache::response::conceptgroup{"$name.text"} = $text;	
  511: 	$Apache::response::conceptgroup{"$name.location"} = $location;	
  512:       } else {
  513: 	push @{ $Apache::response::foilgroup{'names'} }, $name;
  514: 	$Apache::response::foilgroup{"$name.value"} = $value;
  515: 	$Apache::response::foilgroup{"$name.text"} = $text;
  516: 	$Apache::response::foilgroup{"$name.location"} = $location;
  517:       }
  518:     }
  519:   }
  520:   return '';
  521: }
  522: 
  523: sub insert_foil {
  524:   return '
  525: <foil name="" value="unused">
  526: <startouttext />
  527: <endouttext />
  528: </foil>';
  529: }
  530: 1;
  531: __END__
  532:  

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