Annotation of loncom/homework/radiobuttonresponse.pm, revision 1.51

1.22      albertel    1: # The LearningOnline Network with CAPA
                      2: # mutliple choice style responses
1.31      albertel    3: #
1.51    ! albertel    4: # $Id: radiobuttonresponse.pm,v 1.50 2002/09/25 19:39:49 albertel Exp $
1.31      albertel    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: #
1.22      albertel   28: # 2/21 Guy
1.1       albertel   29: 
                     30: package Apache::radiobuttonresponse;
                     31: use strict;
1.42      albertel   32: use HTML::Entities();
1.1       albertel   33: 
1.36      harris41   34: BEGIN {
1.22      albertel   35:   &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
1.1       albertel   36: }
                     37: 
                     38: sub start_radiobuttonresponse {
1.22      albertel   39:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.26      albertel   40:   my $result;
1.3       albertel   41:   #when in a radiobutton response use these
1.22      albertel   42:   &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
1.26      albertel   43:   push (@Apache::lonxml::namespace,'radiobuttonresponse');
1.4       albertel   44:   my $id = &Apache::response::start_response($parstack,$safeeval);
1.25      albertel   45:   if ($target eq 'meta') {
                     46:     $result=&Apache::response::meta_package_write('radiobuttonresponse');
1.26      albertel   47:   } elsif ($target eq 'edit' ) {
                     48:     $result.=&Apache::edit::start_table($token).
1.35      matthew    49: 	'<tr><td>'.&Apache::lonxml::description($token)."</td><td>Delete:".
1.26      albertel   50: 	&Apache::edit::deletelist($target,$token)
1.35      matthew    51: 	."</td><td>&nbsp".&Apache::edit::end_row()
                     52:         .&Apache::edit::start_spanning_row();
                     53: 
1.47      albertel   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";
1.26      albertel   59:   } elsif ($target eq 'modified') {
                     60:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.47      albertel   61: 						 $safeeval,'max','randomize');
1.26      albertel   62:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38      sakharuk   63:   } elsif ($target eq 'tex') {
                     64:       $result .= '\begin{enumerate}';
1.25      albertel   65:   }
                     66:   return $result;
1.1       albertel   67: }
                     68: 
                     69: sub end_radiobuttonresponse {
1.26      albertel   70:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     71:   my $result;
                     72:   if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
1.38      sakharuk   73:   if ($target eq 'tex') { $result .= '\end{enumerate}'; }
1.22      albertel   74:   &Apache::response::end_response;
1.26      albertel   75:   pop @Apache::lonxml::namespace;
1.33      albertel   76:   &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
1.26      albertel   77:   return $result;
1.1       albertel   78: }
                     79: 
1.43      albertel   80: %Apache::response::foilgroup=();
1.1       albertel   81: sub start_foilgroup {
1.43      albertel   82:   %Apache::response::foilgroup=();
1.22      albertel   83:   $Apache::radiobuttonresponse::conceptgroup=0;
                     84:   &Apache::response::setrandomnumber();
                     85:   return '';
1.5       albertel   86: }
                     87: 
1.15      albertel   88: sub storesurvey {
1.33      albertel   89:   if ( !defined($ENV{'form.submitted'})) { return ''; }
                     90:   my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
                     91:   &Apache::lonxml::debug("Here I am!:$response:");
                     92:   if ( $response !~ /[0-9]+/) { return ''; }
                     93:   my $id = $Apache::inputtags::response['-1'];
                     94:   my @whichfoils=@{ $Apache::response::foilgroup{'names'} };
                     95:   my %responsehash;
                     96:   $responsehash{$whichfoils[$response]}=$response;
                     97:   $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=&Apache::lonnet::hash2str(%responsehash);
                     98:   $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='SUBMITTED';
                     99:   &Apache::lonxml::debug("submitted a $response<br />\n");
1.22      albertel  100:   return '';
1.15      albertel  101: }
                    102: 
1.32      albertel  103: sub grade_response {
1.49      albertel  104:   my ($max,$randomize)=@_;
1.32      albertel  105:   if (!defined($ENV{'form.submitted'})) { return; }
                    106:   my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
                    107:   if ( $response !~ /[0-9]+/) { return; }
                    108:   my $part=$Apache::inputtags::part;
                    109:   my $id = $Apache::inputtags::response['-1'];
1.49      albertel  110:   my ($answer,@whichfoils)=&whichfoils($max,$randomize);
1.32      albertel  111:   my %responsehash;
                    112:   $responsehash{$whichfoils[$response]}=$response;
                    113:   my $responsestr=&Apache::lonnet::hash2str(%responsehash);
                    114:   my %previous=&Apache::response::check_for_previous($responsestr,
                    115: 						     $part,$id);
                    116:   $Apache::lonhomework::results{"resource.$part.$id.submission"}=
                    117:     $responsestr;
                    118:   &Apache::lonxml::debug("submitted a $response<br />\n");
                    119:   my $ad;
                    120:   if ($response == $answer) {
                    121:     $ad='EXACT_ANS';
                    122:   } else {
                    123:     $ad='INCORRECT';
                    124:   }
                    125:   $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
                    126:   &Apache::response::handle_previous(\%previous,$ad);
                    127: }
                    128: 
1.1       albertel  129: sub end_foilgroup {
1.22      albertel  130:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.29      albertel  131: 
1.22      albertel  132:   my $result;
1.38      sakharuk  133:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.29      albertel  134:     my $style = $Apache::lonhomework::type;
1.22      albertel  135:     if ( $style eq 'survey' ) {
1.38      sakharuk  136:       if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.22      albertel  137: 	$result=&displayallfoils();
                    138:       } elsif ( $target eq 'grade' ) {
                    139: 	$result=&storesurvey();
                    140:       }
                    141:     } else {
                    142:       my $name;
1.49      albertel  143:       my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
1.47      albertel  144:       my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
                    145: 						 $safeeval,'-2');
1.38      sakharuk  146:       if ($target eq 'web' || $target eq 'tex') {
1.49      albertel  147: 	$result=&displayfoils($target,$max,$randomize);
1.28      albertel  148:       } elsif ($target eq 'answer' ) {
1.49      albertel  149: 	$result=&displayanswers($max,$randomize);
1.22      albertel  150:       } elsif ( $target eq 'grade') {
1.49      albertel  151: 	&grade_response($max,$randomize);
1.22      albertel  152:       }
1.5       albertel  153:     }
1.22      albertel  154:   }
                    155:   return $result;
1.6       albertel  156: }
                    157: 
                    158: sub getfoilcounts {
1.34      albertel  159:   my @names;
1.22      albertel  160:   my $truecnt=0;
                    161:   my $falsecnt=0;
                    162:   my $name;
1.34      albertel  163:   if ( $Apache::response::foilgroup{'names'} ) {
                    164:     @names= @{ $Apache::response::foilgroup{'names'} };
                    165:   }
1.22      albertel  166:   foreach $name (@names) {
                    167:     if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
                    168:       $truecnt++;
                    169:     } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
                    170:       $falsecnt++;
1.6       albertel  171:     }
1.22      albertel  172:   }
1.50      albertel  173:   return ($truecnt,$falsecnt);
1.5       albertel  174: }
                    175: 
1.15      albertel  176: sub displayallfoils {
1.22      albertel  177:   my $result;
                    178:   &Apache::lonxml::debug("survey style display");
                    179:   my @names = @{ $Apache::response::foilgroup{'names'} };
                    180:   my $temp=0;
                    181:   my $id=$Apache::inputtags::response['-1'];
                    182:   my $part=$Apache::inputtags::part;
                    183:   my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
1.32      albertel  184:   my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
1.45      albertel  185:   if (($Apache::lonhomework::history{"resource.$part.solved"} =~ /^correct/)  || ($Apache::inputtags::status[-1] eq  'SHOW_ANSWER')) {
                    186:     foreach my $name (@names) {
                    187:       if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
                    188: 	$result.="<br />".$Apache::response::foilgroup{$name.'.value'};
                    189: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
                    190: 	  $result.='<b>';
                    191: 	}
                    192: 	$result .= $Apache::response::foilgroup{$name.'.text'};
                    193: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
                    194: 	  $result.='</b>';
                    195: 	}
                    196:       }
                    197:     }
                    198:   } else {
                    199:     foreach my $name (@names) {
                    200:       if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
                    201: 	$result.="<br /><input type=\"radio\" name=\"HWVAL$Apache::inputtags::response['-1']\" value=\"$temp\" ";
                    202: 	if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
                    203: 	$result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
                    204: 	$temp++;
                    205:       }
1.15      albertel  206:     }
1.22      albertel  207:   }
                    208:   return $result;
1.15      albertel  209: }
                    210: 
1.28      albertel  211: sub whichfoils {
1.49      albertel  212:   my ($max,$randomize)=@_;
1.28      albertel  213: 
1.22      albertel  214:   my @truelist;
                    215:   my @falselist;
1.41      albertel  216:   my @whichfalse =();
1.50      albertel  217:   my ($truecnt,$falsecnt) = &getfoilcounts();
1.49      albertel  218:   my $count=0;
                    219:   # we will add in 1 of the true statements
                    220:   if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
1.51    ! albertel  221:   my $answer=int(&Math::Random::random_uniform() * ($count));
1.49      albertel  222:   &Apache::lonxml::debug("Count is $count, $answer is $answer");
1.34      albertel  223:   my @names;
                    224:   if ( $Apache::response::foilgroup{'names'} ) {
1.49      albertel  225:       @names= @{ $Apache::response::foilgroup{'names'} };
1.34      albertel  226:   }
1.41      albertel  227:   if (&Apache::response::showallfoils()) {
1.49      albertel  228:       @whichfalse=@names;
1.48      albertel  229:   } elsif ($randomize eq 'no') {
1.47      albertel  230:       &Apache::lonxml::debug("No randomization");
                    231:       my $havetrue=0;
                    232:       foreach my $name (@names) {
                    233: 	  if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
1.49      albertel  234: 	      if (!$havetrue ) {
                    235: 		  push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
                    236: 	      }
1.47      albertel  237: 	  } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
                    238: 	      push (@whichfalse,$name);
                    239: 	  } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
                    240: 	  } else {
                    241: 	      &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>"));
                    242: 	  }
                    243:       }
1.41      albertel  244:   } else {
1.49      albertel  245:     my $current=0;
                    246:     &Apache::lonhomework::showhash(%Apache::response::foilgroup);
                    247:     my (%top,%bottom);
                    248:     #first find out where everyone wants to be
1.41      albertel  249:     foreach my $name (@names) {
1.49      albertel  250: 	$current++;
                    251: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
                    252: 	    push (@truelist,$name);
                    253: 	    if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
                    254: 		$top{$name}=$current;
                    255: 	    } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
                    256: 		$bottom{$name}=$current;
                    257: 	    }
                    258: 	} elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
                    259: 	    push (@falselist,$name);
                    260: 	    if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
                    261: 		$top{$name}=$current;
                    262: 	    } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
                    263: 		$bottom{$name}=$current;
                    264: 	    }
                    265: 	} elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
                    266: 	} else {
                    267: 	    &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>"));
                    268: 	}
1.41      albertel  269:     }
1.49      albertel  270:     #pick a true statement
1.51    ! albertel  271:     my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
1.41      albertel  272:     &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
1.49      albertel  273:     my $numinserted;
                    274:     my (@toplist, @bottomlist);
                    275:     my $topcount=0;
                    276:     # assign everyone to either toplist/bottomlist or whichfalse
                    277:     # which false is randomized, toplist bottomlist are in order
                    278:     while ((($numinserted) < $max-1) && ($#falselist > -1)) {
                    279: 	&Apache::lonxml::debug("Have $#whichfalse max is $max");
1.51    ! albertel  280: 	my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
1.49      albertel  281: 	&Apache::lonxml::debug("From $#falselist elms, picking $afalse");
                    282: 	$afalse=splice(@falselist,$afalse,1);
                    283: 	&Apache::lonxml::debug("Picked $afalse");
                    284: 	&Apache::lonhomework::showhash(('names'=>\@names));
                    285: 	&Apache::lonhomework::showhash(%top);
                    286: 	if ($top{$afalse}) {
                    287: 	    $toplist[$top{$afalse}]=$afalse;
                    288: 	    $topcount++;
                    289: 	} elsif ($bottom{$afalse}) {
                    290: 	    $bottomlist[$bottom{$afalse}]=$afalse;
                    291: 	} else {
                    292: 	    push (@whichfalse,$afalse);
                    293: 	}
                    294:     }
                    295:     my $truename=$truelist[$whichtrue];
                    296:     my $dosplice=1;
                    297:     #insert the true statement, keeping track of where it wants to be
                    298:     if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' ) {
                    299: 	$toplist[$top{$truename}]=$truename;
                    300: 	$answer=-1;
                    301: 	foreach my $top (reverse(@toplist)) {
                    302: 	    if ($top) { $answer++;}
                    303: 	    if ($top eq $truename) { last; }
                    304: 	}
                    305: 	$dosplice=0;
                    306:     } elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom') {
                    307: 	$bottomlist[$bottom{$truename}]=$truename;
                    308: 	$answer=-1;
                    309: 	foreach my $bot (@bottomlist) {
                    310: 	    if ($bot) { $answer++;}
                    311: 	    if ($bot eq $truename) { last; }
                    312: 	}
                    313: 	$answer+=$topcount+$#whichfalse+1;
                    314: 	$dosplice=0;
                    315:     } else {
1.51    ! albertel  316: 	if ($topcount>0) { 
        !           317: 	  $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
        !           318: 	    + $topcount;
        !           319: 	}
1.49      albertel  320:     }
                    321:     #add the top items to the top, bottom items to the bottom
                    322:     for (my $i=0;$i<=$#toplist;$i++) {
                    323: 	if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
                    324:     }
                    325:     for (my $i=0;$i<=$#bottomlist;$i++) {
                    326: 	if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
1.3       albertel  327:     }
1.49      albertel  328:     #if the true statement is randomized insert it into the list
                    329:     if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
1.22      albertel  330:   }
1.49      albertel  331:   &Apache::lonxml::debug("Answer is $answer");
                    332:   return ($answer,@whichfalse);
1.28      albertel  333: }
                    334: 
                    335: sub displayfoils {
1.49      albertel  336:   my ($target,$max,$randomize)=@_;
1.28      albertel  337:   my $result;
                    338: 
1.49      albertel  339:   my ($answer,@whichfoils)=&whichfoils($max,$randomize);
1.45      albertel  340:   if ($Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"} =~ /^correct/ || ($Apache::inputtags::status[-1] eq  'SHOW_ANSWER')) {
1.28      albertel  341:     foreach my $name (@whichfoils) {
1.38      sakharuk  342:       if ($target ne 'tex') {
                    343: 	  $result.="<br />";
1.44      sakharuk  344:       } else {
1.46      sakharuk  345: 	  $result.='\vskip 0 mm \item ';
1.38      sakharuk  346:       }
1.22      albertel  347:       if ($Apache::response::foilgroup{$name.'.value'} eq 'true') { 
1.46      sakharuk  348: 	  if ($target ne 'tex') { $result.='Correct:<b>'; } else { $result.='Correct: ';}
1.22      albertel  349:       } else {
1.45      albertel  350: 	$result.='Incorrect:';
                    351:       }
1.46      sakharuk  352:       if ($target ne 'tex') {
                    353: 	  $result.=$Apache::response::foilgroup{$name.'.text'}."</input>\n";
                    354:       } else {
                    355: 	  $result.=$Apache::response::foilgroup{$name.'.text'};
                    356:       }
1.45      albertel  357:       if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
1.46      sakharuk  358: 	  if ($target ne 'tex') { $result.='</b>';}
1.22      albertel  359:       }
1.10      albertel  360:     }
1.22      albertel  361:   } else {
                    362:     my $temp=0;
                    363:     my $id=$Apache::inputtags::response['-1'];
                    364:     my $part=$Apache::inputtags::part;
                    365:     my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
1.32      albertel  366:     my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
1.28      albertel  367:     foreach my $name (@whichfoils) {
1.38      sakharuk  368:       if ($target ne 'tex') {
                    369: 	  $result.="<br /><input type=\"radio\" name=\"HWVAL$Apache::inputtags::response['-1']\" value=\"$temp\" ";
                    370: 	  if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
                    371: 	  $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
                    372:       } else {
1.44      sakharuk  373: 	  $result .= '\item '.$Apache::response::foilgroup{$name.'.text'};
1.38      sakharuk  374:       }
1.22      albertel  375:       $temp++;
1.10      albertel  376:     }
1.22      albertel  377:   }
1.44      sakharuk  378:   if ($target ne 'tex') { $result.="<br />"; } else { $result.='\vskip 0 mm '; }
1.39      albertel  379:   return $result;
1.14      albertel  380: }
                    381: 
1.28      albertel  382: sub displayanswers {
1.49      albertel  383:   my ($max,$randomize)=@_;
                    384:   my ($answer,@whichopt) = &whichfoils($max,$randomize);
1.28      albertel  385:   my $result=&Apache::response::answer_header('radiobuttonresponse');
                    386:   foreach my $name (@whichopt) {
                    387:     $result.=&Apache::response::answer_part('radiobuttonresponse',
                    388: 		     $Apache::response::foilgroup{$name.'.value'})
                    389:   }
                    390:   $result.=&Apache::response::answer_footer('radiobuttonresponse');
                    391:   return $result;
                    392: }
                    393: 
1.14      albertel  394: sub start_conceptgroup {
1.27      albertel  395:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.22      albertel  396:   $Apache::radiobuttonresponse::conceptgroup=1;
1.43      albertel  397:   %Apache::response::conceptgroup=();
1.26      albertel  398:   my $result;
                    399:   if ($target eq 'edit') {
                    400:     $result.=&Apache::edit::tag_start($target,$token);
                    401:     $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
1.35      matthew   402: 	&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.26      albertel  403:   } elsif ($target eq 'modified') {
                    404:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    405: 						 $safeeval,'concept');
                    406:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    407:   }
                    408:   return $result;
1.14      albertel  409: }
                    410: 
                    411: sub end_conceptgroup {
1.22      albertel  412:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    413:   $Apache::radiobuttonresponse::conceptgroup=0;
1.26      albertel  414:   my $result;
1.38      sakharuk  415:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'  || $target eq 'tex') {
1.27      albertel  416:     if (defined(@{ $Apache::response::conceptgroup{'names'} })) {
                    417:       my @names = @{ $Apache::response::conceptgroup{'names'} };
1.51    ! albertel  418:       my $pick=int(&Math::Random::random_uniform() * ($#names+1));
1.27      albertel  419:       my $name=$names[$pick];
                    420:       push @{ $Apache::response::foilgroup{'names'} }, $name;
                    421:       $Apache::response::foilgroup{"$name.text"} =  $Apache::response::conceptgroup{"$name.text"};
                    422:       $Apache::response::foilgroup{"$name.value"} = $Apache::response::conceptgroup{"$name.value"};
1.49      albertel  423:       $Apache::response::foilgroup{"$name.location"} = $Apache::response::conceptgroup{"$name.location"};
1.27      albertel  424:       my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval);
                    425:       $Apache::response::foilgroup{"$name.concept"} = $concept;
                    426:       &Apache::lonxml::debug("Selecting $name in $concept");
                    427:     }
1.26      albertel  428:   } elsif ($target eq 'edit') {
                    429:     $result=&Apache::edit::end_table();
1.22      albertel  430:   }
1.26      albertel  431:   return $result;
                    432: }
                    433: 
                    434: sub insert_conceptgroup {
                    435:   my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
                    436:   return $result;
1.1       albertel  437: }
                    438: 
                    439: sub start_foil {
1.24      albertel  440:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    441:   my $result='';
1.38      sakharuk  442:   if ($target eq 'web' || $target eq 'tex') {
1.27      albertel  443:     &Apache::lonxml::startredirection;
                    444:   } elsif ($target eq 'edit') {
                    445:     $result=&Apache::edit::tag_start($target,$token);
                    446:     $result.=&Apache::edit::text_arg('Name:','name',$token);
1.42      albertel  447:     $result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
1.28      albertel  448: 				       ['unused','true','false'],$token);
1.51    ! albertel  449:     my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
        !           450: 					     $safeeval,'-3');
        !           451:     if ($randomize eq 'yes') {
        !           452:       $result.=&Apache::edit::select_arg('Location:','location',
        !           453: 					 ['random','bottom','top'],$token);
        !           454:     }
1.35      matthew   455:     $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.27      albertel  456:   } elsif ($target eq 'modified') {
                    457:      my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
1.48      albertel  458: 						  'value','name','location');
1.27      albertel  459:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38      sakharuk  460:   } 
1.27      albertel  461:   return $result;
1.1       albertel  462: }
                    463: 
                    464: sub end_foil {
1.22      albertel  465:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    466:   my $text='';
1.38      sakharuk  467:   if ($target eq 'web' || $target eq 'tex') { $text=&Apache::lonxml::endredirection; }
                    468:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'  || $target eq 'tex') {
1.19      albertel  469:     my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
1.18      albertel  470:     if ($value ne 'unused') {
1.19      albertel  471:       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.48      albertel  472:       my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
1.27      albertel  473:       if (!$name) { $name=$Apache::lonxml::curdepth; }
1.41      albertel  474:       if ( $Apache::radiobuttonresponse::conceptgroup
                    475: 	   && !&Apache::response::showallfoils() ) {
1.18      albertel  476: 	push @{ $Apache::response::conceptgroup{'names'} }, $name;
                    477: 	$Apache::response::conceptgroup{"$name.value"} = $value;
                    478: 	$Apache::response::conceptgroup{"$name.text"} = $text;	
1.48      albertel  479: 	$Apache::response::conceptgroup{"$name.location"} = $location;	
1.18      albertel  480:       } else {
                    481: 	push @{ $Apache::response::foilgroup{'names'} }, $name;
                    482: 	$Apache::response::foilgroup{"$name.value"} = $value;
                    483: 	$Apache::response::foilgroup{"$name.text"} = $text;
1.48      albertel  484: 	$Apache::response::foilgroup{"$name.location"} = $location;
1.18      albertel  485:       }
                    486:     }
1.4       albertel  487:   }
1.1       albertel  488:   return '';
                    489: }
                    490: 
1.27      albertel  491: sub insert_foil {
                    492:   return '
                    493: <foil name="" value="unused">
                    494: <startouttext />
                    495: <endouttext />
                    496: </foil>';
                    497: }
1.1       albertel  498: 1;
                    499: __END__
                    500:  

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