File:  [LON-CAPA] / loncom / homework / radiobuttonresponse.pm
Revision 1.79: download - view: text, annotated - select for diffs
Mon Oct 27 20:04:34 2003 UTC (20 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: version_1_1_X, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, HEAD
- took a look at all of the analyze outputs and corrected the buglets

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