File:  [LON-CAPA] / loncom / homework / radiobuttonresponse.pm
Revision 1.89: download - view: text, annotated - select for diffs
Thu May 27 04:25:13 2004 UTC (19 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, HEAD
- fixes for randnumber generation
   - due to a error in coding the 64bit and 64bit2 rnd seeds were throwing away the second half of the seed, we now preserve this functionality and make it explicit
   - additionally 64bit3 now uses all 64bits of the seed
   - also added new function pushrandomnumber poprandomnumber to be called instead of setrandomnumber before we were crunching the Safe space random number generator state, as this function is used bu thing the <optionresponse> and <radoibuttonresponse> this meant changes in the internal randomization code could screw up later Safe space random calls the old method is preserved for blank 64bit and 64bit2 randomiztion env.

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

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