File:  [LON-CAPA] / loncom / homework / optionresponse.pm
Revision 1.50: download - view: text, annotated - select for diffs
Tue Oct 1 20:17:04 2002 UTC (21 years, 8 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Corrections + cleanuo.

    1: # LearningOnline Network with CAPA
    2: # option list style responses
    3: #
    4: # $Id: optionresponse.pm,v 1.50 2002/10/01 20:17:04 sakharuk 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: # 01/18 Alex
   30: package Apache::optionresponse;
   31: use strict;
   32: use Apache::response;
   33: 
   34: BEGIN {
   35:   &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
   36: }
   37: 
   38: sub start_optionresponse {
   39:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   40:   my $result='';
   41:   #when in a option response use these
   42:   &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
   43:   push (@Apache::lonxml::namespace,'optionresponse');
   44:   my $id = &Apache::response::start_response($parstack,$safeeval);
   45:   if ($target eq 'edit') {
   46:     $result.=&Apache::edit::start_table($token).
   47: 	"<tr><td>Multiple Option Response Question</td><td>Delete:".
   48: 	&Apache::edit::deletelist($target,$token)
   49: 	."</td><td>&nbsp;".
   50:         &Apache::edit::end_row().
   51:         &Apache::edit::start_spanning_row().
   52:         "\n";
   53:     $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max',
   54: 				     $token,'4').
   55:         &Apache::edit::select_arg('Randomize Foil Order','randomize',
   56: 				  ['yes','no'],$token).
   57:         &Apache::edit::end_row().&Apache::edit::start_spanning_row();
   58:   } elsif ($target eq 'modified') {
   59:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
   60: 						 $safeeval,'max','randomize');
   61:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
   62:   } elsif ($target eq 'meta') {
   63:     $result=&Apache::response::meta_package_write('optionresponse');
   64:   } elsif ($target eq 'analyze') {
   65:     my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
   66:     push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
   67:   }
   68:   return $result;
   69: }
   70: 
   71: sub end_optionresponse {
   72:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   73:   &Apache::response::end_response;
   74:   pop @Apache::lonxml::namespace;
   75:   &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
   76:   my $result;
   77:   if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
   78:   return $result;
   79: }
   80: 
   81: %Apache::response::foilgroup=();
   82: sub start_foilgroup {
   83:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   84: 
   85:   my $result='';
   86:   %Apache::response::foilgroup=();
   87:   $Apache::optionresponse::conceptgroup=0;
   88:   &Apache::response::setrandomnumber();
   89:   if ($target eq 'edit') {
   90:     my $optionlist="<option></option>\n";
   91:     my $option;
   92:     my @opt;
   93:     eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval);
   94:     my $count=1;
   95:     foreach $option (@opt) {
   96:       $optionlist.="<option value=\"$count\">$option</option>\n";
   97:       $count++;
   98:     }
   99:     my $insertlist=&Apache::edit::insertlist($target,$token);
  100:     $result.=&Apache::edit::start_table($token);
  101:     $result.= (<<ENDTABLE);
  102:       <tr><td>Select Options</td>
  103:         <td>
  104: 	  Add new Option: <input type="text" name="$Apache::lonxml::curdepth.options" />
  105:         </td>
  106:         <td>Delete an Option:
  107: 	  <select name="$Apache::lonxml::curdepth.deleteopt">$optionlist</select>
  108: ENDTABLE
  109:     $result.= &Apache::edit::end_row();
  110:     $result.= &Apache::edit::start_spanning_row();
  111:     $result.= $insertlist.'<br />';
  112:   }
  113:   if ($target eq 'modified') {
  114:     my @options;
  115:     my $optchanged=0;
  116:     eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
  117:     if ($ENV{"form.$Apache::lonxml::curdepth.deleteopt"}) {
  118:       my $delopt=$ENV{"form.$Apache::lonxml::curdepth.deleteopt"};
  119:       &Apache::lonxml::debug("Deleting :$delopt:");
  120:       splice(@options,$delopt-1,1);
  121:       $optchanged=1;
  122:     }
  123:     if ($ENV{"form.$Apache::lonxml::curdepth.options"}) {
  124:       my $newopt = $ENV{"form.$Apache::lonxml::curdepth.options"};
  125:       if ($options[0]) {
  126: 	push(@options,$newopt);
  127:       } else {
  128: 	$options[0]=$newopt;
  129:       }
  130:       $optchanged=1;
  131:     }
  132:     if ($optchanged) {
  133:       $result = "<foilgroup options=\"(";
  134:       foreach my $option (@options) {
  135: 	$option=~s/\'/\\\'/g;
  136: 	&Apache::lonxml::debug("adding option :$option:");
  137: 	$result .="'".$option."',";
  138:       }
  139:       chop $result;
  140:       $result.=')">';
  141:     } # else nothing changed so just use the default mechanism
  142:   }
  143:   if ($target eq 'tex') {
  144:       $result .= ' \begin{enumerate} ';
  145:   }
  146:   return $result;
  147: }
  148: 
  149: sub end_foilgroup {
  150:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  151:   
  152:   my $result;
  153:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') {
  154:     my $name;
  155:     my @opt;
  156:     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
  157:     &Apache::lonxml::debug("Options are $#opt");
  158:     my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
  159:     my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
  160: 					       $safeeval,'-2');
  161:     if ($target eq 'web' || $target eq 'tex') {
  162:       $result.=&displayfoils($target,$max,$randomize,@opt);
  163:     } elsif ( $target eq 'answer') {
  164:       $result.=&displayanswers($max,$randomize,@opt);
  165:     } elsif ( $target eq 'analyze') {
  166:       my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  167:       foreach my $name (@{ $Apache::response::foilgroup{'names'} }) {
  168: 	if (defined($Apache::lonhomework::analyze{"$part_id.foil.value.$name"})) { next; }
  169: 	push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },$name);
  170: 	$Apache::lonhomework::analyze{"$part_id.foil.value.$name"} =
  171: 	  $Apache::response::foilgroup{"$name.value"};
  172: 	$Apache::lonhomework::analyze{"$part_id.foil.text.$name"} =
  173: 	  $Apache::response::foilgroup{"$name.text"};
  174:       }
  175:       push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
  176:       push (@{ $Apache::lonhomework::analyze{"$part_id.shown"} },&whichfoils($max,$randomize));
  177:     } elsif ( $target eq 'grade') {
  178:       if ( defined $ENV{'form.submitted'}) {
  179: 	my @whichopt = &whichfoils($max,$randomize);
  180: 	my $temp=1;my $name;
  181: 	my %responsehash;
  182: 	my $right=0;
  183: 	my $wrong=0;
  184: 	my $ignored=0;
  185: 	foreach $name (@whichopt) {
  186: 	  my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1'].":$temp"};
  187: 	  $responsehash{$name}=$response;
  188: 	  if ( $response =~ /[^\s]/) {
  189: 	    my $value=$Apache::response::foilgroup{$name.'.value'};
  190: 	    &Apache::lonxml::debug("submitted a $response for $value<br />\n");
  191: 	    if ($value eq $response) {$right++;} else {$wrong++;}
  192: 	  } else {
  193: 	    $ignored++;
  194: 	  }
  195: 	  $temp++;
  196: 	}
  197: 	my $part=$Apache::inputtags::part;
  198: 	my $id = $Apache::inputtags::response['-1'];
  199: 	my $responsestr=&Apache::lonnet::hash2str(%responsehash);
  200: 	my %previous=&Apache::response::check_for_previous($responsestr,
  201: 							   $part,$id);
  202: 	&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
  203: 	my $ad;
  204: 	if ($wrong==0 && $ignored==0) {
  205: 	  $ad='EXACT_ANS';
  206: 	} elsif ($wrong==0 && $right==0) {
  207: 	  #nothing submitted
  208: 	} else {
  209: 	  if ($ignored==0) {
  210: 	    $ad='INCORRECT';
  211: 	  } else {
  212: 	    $ad='MISSING_ANSWER';
  213: 	  }
  214: 	}
  215: 	$Apache::lonhomework::results{"resource.$part.$id.submission"}=
  216: 	  $responsestr;
  217: 	$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
  218: 	  $ad;
  219: 	&Apache::response::handle_previous(\%previous,$ad);
  220:       }
  221:     }
  222:   } elsif ($target eq 'edit') {
  223:     $result.=&Apache::edit::end_table();
  224:   }  
  225:   if ($target eq 'tex') {$result .= '\end{enumerate}';}
  226:   return $result;
  227: }
  228: 
  229: sub getfoilcounts {
  230:   my ($max)=@_;
  231:   # +1 since instructors will count from 1
  232:   my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
  233:   if (&Apache::response::showallfoils()) { $max=$count; }
  234:   if ($count>$max) { $count=$max } 
  235:   &Apache::lonxml::debug("Count is $count from $max");
  236:   return $count;
  237: }
  238: 
  239: sub whichfoils {
  240:   my ($max,$randomize)=@_;
  241:   $max = &getfoilcounts($max);
  242:   &Apache::lonxml::debug("randomize $randomize");
  243:   my @names = @{ $Apache::response::foilgroup{'names'} };
  244:   my @whichopt =();
  245:   my (%top,@toplist,%bottom,@bottomlist);
  246:   if (!(&Apache::response::showallfoils() || ($randomize eq 'no'))) {
  247:       my $current=0;
  248:       foreach my $name (@names) {
  249: 	  $current++;
  250: 	  if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
  251: 	      $top{$name}=$current;
  252: 	  } elsif ($Apache::response::foilgroup{$name.'.location'} eq
  253: 		   'bottom') {
  254: 	      $bottom{$name}=$current;
  255: 	  }
  256:       }
  257:   }
  258:   while ((($#whichopt+1) < $max) && ($#names > -1)) {
  259:     &Apache::lonxml::debug("Have $#whichopt max is $max");
  260:     my $aopt;
  261:     if (&Apache::response::showallfoils() || ($randomize eq 'no')) {
  262:       $aopt=0;
  263:     } else {
  264:       $aopt=int(&Math::Random::random_uniform() * ($#names+1));
  265:     }
  266:     &Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt");
  267:     $aopt=splice(@names,$aopt,1);
  268:     &Apache::lonxml::debug("Picked $aopt");
  269:     if ($top{$aopt}) {
  270: 	$toplist[$top{$aopt}]=$aopt;
  271:     } elsif ($bottom{$aopt}) {
  272: 	$bottomlist[$bottom{$aopt}]=$aopt;
  273:     } else {
  274: 	push (@whichopt,$aopt);
  275:     }
  276:   }
  277:   for (my $i=0;$i<=$#toplist;$i++) {
  278:       if ($toplist[$i]) { unshift(@whichopt,$toplist[$i]) }
  279:   }
  280:   for (my $i=0;$i<=$#bottomlist;$i++) {
  281:       if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) }
  282:   }
  283: 
  284:   return @whichopt;
  285: }
  286: 
  287: sub displayanswers {
  288:   my ($max,$randomize,@opt)=@_;
  289:   my @names = @{ $Apache::response::foilgroup{'names'} };
  290:   my @whichopt = &whichfoils($max,$randomize);
  291:   my $result=&Apache::response::answer_header('optionresponse');
  292:   foreach my $name (@whichopt) {
  293:     $result.=&Apache::response::answer_part('optionresponse',
  294: 		     $Apache::response::foilgroup{$name.'.value'})
  295:   }
  296:   $result.=&Apache::response::answer_footer('optionresponse');
  297:   return $result;
  298: }
  299: 
  300: sub displayfoils {
  301:   my ($target,$max,$randomize,@opt)=@_;
  302:   my @names = @{ $Apache::response::foilgroup{'names'} };
  303:   my @truelist;
  304:   my @falselist;
  305:   my $result;
  306:   my $name;
  307:   my $displayoptionintex=0;
  308:   my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
  309: 		  'Q','R','S','T','U','V','W','X','Y','Z');
  310:   my @whichopt = &whichfoils($max,$randomize);
  311:   my $part=$Apache::inputtags::part;
  312:   my $id=$Apache::inputtags::response[-1];
  313:   if (($Apache::lonhomework::history{"resource.$part.solved"} =~ /^correct/)  || ($Apache::inputtags::status[-1] eq  'SHOW_ANSWER')) {
  314:     foreach $name (@whichopt) {
  315:       if ($target eq 'web') {
  316: 	  $result.="<br />";
  317:       } elsif ($target eq 'tex') {
  318: 	  $result.='\vskip 0 mm ';
  319:       }
  320:       if ($target ne 'tex') {
  321: 	  $result .=$Apache::response::foilgroup{$name.'.value'}.
  322: 	      ":".$Apache::response::foilgroup{$name.'.text'}."\n";
  323:       } else {
  324:  	  $result .='\item '.$Apache::response::foilgroup{$name.'.value'}.
  325: 	      ":".$Apache::response::foilgroup{$name.'.text'}."\n";
  326:       }
  327:     }
  328:   } else {
  329:     my $temp=1;
  330:     my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
  331:     foreach $name (@whichopt) {
  332:       my $lastopt=$lastresponse{$name};
  333:       my $optionlist="<option></option>\n";
  334:       my $option;
  335:       foreach $option (@opt) {
  336: 	if ($option eq $lastopt) {
  337: 	  $optionlist.="<option selected=\"on\">$option</option>\n";
  338: 	} else {
  339: 	  $optionlist.="<option>$option</option>\n";
  340: 	}
  341:       }
  342:       if ($target ne 'tex') {
  343: 	  $result.="<br /><select name=\"HWVAL_$Apache::inputtags::response['-1']:$temp\">"
  344: 	      .$optionlist
  345: 		  ."</select>\n".$Apache::response::foilgroup{$name.'.text'}."\n";
  346: 	  if ($Apache::lonhomework::type eq 'exam') {
  347: 		  my $number_of_bubbles = $#opt + 1;
  348: 		  $result.= '<table border="1"><tr>';
  349: 		  for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
  350: 		      $result.='<td>'.$alphabet[$ind].': '.$opt[$ind].'</td>';
  351: 		  }
  352: 		  $result.='</tr></table>';
  353: 	  }
  354: 	  $temp++;
  355:       } else {
  356: 	  if ($displayoptionintex == 0) {
  357:               my $texoptionlist = &optionlist_correction($optionlist);
  358: 	      if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
  359: 		  $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'};
  360: 	      } else {
  361: 		  $result.= $texoptionlist.'\item '.$Apache::response::foilgroup{$name.'.text'};
  362: 	      }
  363: 	      if ($Apache::lonhomework::type eq 'exam') {
  364: 		  $result.=&bubbles(\@alphabet,\@opt);
  365: 	      }
  366: 	      $displayoptionintex=1;
  367: 	  } else {
  368: 	      if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
  369: 		  $result.= $Apache::response::foilgroup{$name.'.text'};
  370: 	      } else {
  371: 		  $result.= '\item '.$Apache::response::foilgroup{$name.'.text'};
  372: 	      }
  373: 	      if ($Apache::lonhomework::type eq 'exam') {
  374: 		  $result.=&bubbles(\@alphabet,\@opt);
  375: 	      }
  376: 	  }
  377:       } 
  378:     }
  379:   } 
  380:   if ($target ne 'tex') {
  381:       return $result."<br />";
  382:   }
  383:   else {
  384:       return $result;
  385:   }
  386: }
  387: 
  388: 
  389: sub optionlist_correction {
  390: 
  391:     my $texoptionlist = shift;
  392:     $texoptionlist =~ s/<option><\/option>/\\item \[\] The possible answers are:/;
  393:     $texoptionlist =~ s/<option>/\{\\bf /g;
  394:     $texoptionlist =~ s/<option selected="on">/\{\\bf /g;
  395:     $texoptionlist =~ s/<\/option>/\},/g;
  396:     $texoptionlist =~ s/,$/\./g;
  397:     $texoptionlist =~ s/>/\$>\$/g;
  398:     $texoptionlist =~ s/</\$<\$/g;
  399:     $texoptionlist =~ s/=/\$=\$/g;
  400:     return $texoptionlist;
  401: }
  402: 
  403: 
  404: sub bubbles {
  405: 
  406:     my ($ralphabit,$ropt) = @_;
  407:     my @alphabet = @$ralphabit;
  408:     my @opt = @$ropt;
  409:     my $result='';
  410:     my $number_of_bubbles = $#opt + 1;
  411:     $result.= '\vskip 2 mm \noindent \begin{tabular}{|';
  412:     for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
  413: 	$result.='lr|';
  414:     }
  415:     $result.='}\hline ';
  416:     for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
  417: 	$result.=' '.$alphabet[$ind].': & '.$opt[$ind].' ';
  418: 	if ($ind != $number_of_bubbles - 1) {$result.=' & ';}
  419:     }
  420:     $result.='\\\\\hline\end{tabular}\vskip 0 mm ';
  421:     return $result;
  422: }
  423: 
  424: 
  425: sub start_conceptgroup {
  426:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  427:   $Apache::optionresponse::conceptgroup=1;
  428:   %Apache::response::conceptgroup=();
  429:   my $result;
  430:   if ($target eq 'edit') {
  431:     $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
  432:     $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
  433:         &Apache::edit::end_row().&Apache::edit::start_spanning_row();
  434:   }
  435:   if ($target eq 'modified') {
  436:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
  437:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  438:   }
  439:   return $result;
  440: }
  441: 
  442: sub end_conceptgroup {
  443:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  444:   $Apache::optionresponse::conceptgroup=0;
  445:   my $result='';
  446:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
  447:       || $target eq 'tex' || $target eq 'analyze') {
  448:     #if not there aren't any foils to display and thus no question
  449:     if (defined(@{ $Apache::response::conceptgroup{'names'} })) {
  450:       my @names = @{ $Apache::response::conceptgroup{'names'} };
  451:       my $pick=int(&Math::Random::random_uniform() * ($#names+1));
  452:       my $name=$names[$pick];
  453:       push @{ $Apache::response::foilgroup{'names'} }, $name;
  454:       $Apache::response::foilgroup{"$name.value"} =
  455: 	$Apache::response::conceptgroup{"$name.value"};
  456:       $Apache::response::foilgroup{"$name.text"} =
  457: 	$Apache::response::conceptgroup{"$name.text"};
  458:       $Apache::response::foilgroup{"$name.location"} =
  459: 	$Apache::response::conceptgroup{"$name.location"};
  460:       my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval);
  461:       $Apache::response::foilgroup{"$name.concept"} = $concept;
  462:       &Apache::lonxml::debug("Selecting $name in $concept");
  463:       if ($target eq 'analyze') {
  464: 	my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  465:         push (@{ $Apache::lonhomework::analyze{"$part_id.concepts"} },
  466: 	      $concept);
  467: 	$Apache::lonhomework::analyze{"$part_id.concept.$concept"}=
  468: 	  $Apache::response::conceptgroup{'names'};
  469: 	foreach my $name (@{ $Apache::response::conceptgroup{'names'} }) {
  470: 	  push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },
  471: 		$name);
  472: 	  $Apache::lonhomework::analyze{"$part_id.foil.value.$name"} =
  473: 	    $Apache::response::conceptgroup{"$name.value"};
  474: 	  $Apache::lonhomework::analyze{"$part_id.foil.text.$name"} =
  475: 	    $Apache::response::conceptgroup{"$name.text"};
  476: 	  $Apache::lonhomework::analyze{"$part_id.foil.location.$name"} =
  477: 	    $Apache::response::conceptgroup{"$name.location"};
  478: 	}
  479:       }
  480:     }
  481:   } elsif ($target eq 'edit') {
  482:     $result=&Apache::edit::end_table();
  483:   }
  484:   return $result;
  485: }
  486: 
  487: sub insert_conceptgroup {
  488:   my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
  489:   return $result;
  490: }
  491: 
  492: sub start_foil {
  493:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  494:   my $result='';
  495:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
  496:     &Apache::lonxml::startredirection;
  497:   } elsif ($target eq 'edit') {
  498:     $result=&Apache::edit::tag_start($target,$token,"Foil");
  499:     my $level='-2';
  500:     if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
  501:     my @opt;
  502:     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
  503:     $result.=&Apache::edit::text_arg('Name:','name',$token);
  504:     $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
  505: 					       ['unused',(@opt)],$token,'15');
  506:     my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
  507: 					     $safeeval,'-3');
  508:     if ($randomize ne 'no') {
  509: 	$result.=&Apache::edit::select_arg('Location:','location',
  510: 					   ['random','top','bottom'],$token);
  511:     }
  512:     $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  513:   } elsif ($target eq 'modified') {
  514:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
  515: 						 'value','name','location');
  516:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  517:   } 
  518:   return $result;
  519: }
  520: 
  521: sub end_foil {
  522:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  523:   my $text ='';
  524:   my $result = '';
  525:   if ($target eq 'web' || $target eq 'tex') { 
  526:       $text=&Apache::lonxml::endredirection;
  527:       if ($target eq 'tex') { $text = '\item '.$text; }
  528:   }
  529:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' 
  530:       || $target eq 'tex' || $target eq 'analyze') {
  531:     my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
  532:     if ($value ne 'unused') {
  533:       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  534:       my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
  535:       &Apache::lonxml::debug("Got a name of :$name:");
  536:       if (!$name) { $name=$Apache::lonxml::curdepth; }
  537:       &Apache::lonxml::debug("Using a name of :$name:");
  538:       if ( $Apache::optionresponse::conceptgroup
  539: 	   && !&Apache::response::showallfoils() ) {
  540: 	push @{ $Apache::response::conceptgroup{'names'} }, $name;
  541: 	$Apache::response::conceptgroup{"$name.value"} = $value;
  542: 	$Apache::response::conceptgroup{"$name.text"} = $text;
  543: 	$Apache::response::conceptgroup{"$name.location"} = $location;
  544:       } else {
  545: 	push @{ $Apache::response::foilgroup{'names'} }, $name;
  546: 	$Apache::response::foilgroup{"$name.value"} = $value;
  547: 	$Apache::response::foilgroup{"$name.text"} = $text;
  548: 	$Apache::response::foilgroup{"$name.location"} = $location;
  549:       }
  550:     }
  551:   }
  552:   if ($target eq 'edit') {
  553:     $result.= &Apache::edit::tag_end($target,$token,'');
  554:   }
  555:   return $result;
  556: }
  557: 
  558: sub insert_foil {
  559:   return '
  560: <foil name="" value="unused">
  561: <startouttext />
  562: <endouttext />
  563: </foil>';
  564: }
  565: 1;
  566: __END__
  567:  

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