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

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

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