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

1.22      albertel    1: # The LearningOnline Network with CAPA
                      2: # mutliple choice style responses
1.31      albertel    3: #
1.150   ! raeburn     4: # $Id: radiobuttonresponse.pm,v 1.149 2011/06/07 17:27:37 www 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
1.130     foxr       21: # along with LON-CAPA; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1.31      albertel   22: #
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
1.1       albertel   27: 
1.137     jms        28: 
                     29: 
1.1       albertel   30: package Apache::radiobuttonresponse;
                     31: use strict;
1.42      albertel   32: use HTML::Entities();
1.85      albertel   33: use Apache::lonlocal;
1.100     albertel   34: use Apache::lonnet;
1.115     foxr       35: use Apache::response;
1.1       albertel   36: 
1.120     foxr       37: my $default_bubbles_per_line = 10;
1.121     foxr       38: 
1.116     foxr       39: 
1.36      harris41   40: BEGIN {
1.83      albertel   41:     &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
1.1       albertel   42: }
                     43: 
1.121     foxr       44: sub bubble_line_count {
                     45:     my ($numfoils, $bubbles_per_line) = @_;
                     46:     my $bubble_lines;
                     47:     $bubble_lines = int($numfoils / $bubbles_per_line);
                     48:     if (($numfoils % $bubbles_per_line) != 0) {
                     49: 	$bubble_lines++;
                     50:     }
                     51:     return $bubble_lines;
                     52:     
                     53: }
                     54: 
                     55: 
1.1       albertel   56: sub start_radiobuttonresponse {
1.83      albertel   57:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     58:     my $result;
1.115     foxr       59: 
1.83      albertel   60:     #when in a radiobutton response use these
                     61:     &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
                     62:     push (@Apache::lonxml::namespace,'radiobuttonresponse');
                     63:     my $id = &Apache::response::start_response($parstack,$safeeval);
1.120     foxr       64: 
1.83      albertel   65:     %Apache::hint::radiobutton=();
1.85      albertel   66:     undef(%Apache::response::foilnames);
1.83      albertel   67:     if ($target eq 'meta') {
                     68: 	$result=&Apache::response::meta_package_write('radiobuttonresponse');
                     69:     } elsif ($target eq 'edit' ) {
1.136     bisitz     70: 	$result.=&Apache::edit::start_table($token)
                     71:            .'<tr><td>'.&Apache::lonxml::description($token)
                     72:            .&Apache::loncommon::help_open_topic('Radio_Response_Problems')
                     73:            .'</td>'
                     74:            .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
                     75:            .&Apache::edit::deletelist($target,$token)
                     76:            .'</span></td>'
1.140     raeburn    77:            .'<td>&nbsp;'.&Apache::edit::end_row()
1.136     bisitz     78:            .&Apache::edit::start_spanning_row();
1.83      albertel   79: 	$result.=
                     80: 	    &Apache::edit::text_arg('Max Number Of Shown Foils:','max',
1.141     raeburn    81: 				    $token,'4').'&nbsp;'x 3 .
1.136     bisitz     82: 	    &Apache::edit::select_arg('Randomize Foil Order:','randomize',
1.141     raeburn    83: 				      ['yes','no'],$token).'&nbsp;'x 3 .
                     84: 	    &Apache::edit::select_arg('Display Direction:','direction',
1.103     albertel   85: 				      ['vertical','horizontal'],$token).
1.83      albertel   86: 				      &Apache::edit::end_row().
                     87: 				      &Apache::edit::start_spanning_row()."\n";
                     88:     } elsif ($target eq 'modified') {
                     89: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                     90: 						     $safeeval,'max',
1.103     albertel   91: 						     'randomize','direction');
1.83      albertel   92: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                     93:     } elsif ($target eq 'tex') {
                     94: 	my $type=&Apache::lonxml::get_param('TeXtype',$parstack,$safeeval,
                     95: 					    undef,0);
                     96: 	if ($type eq '1') {
                     97: 	    $result .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}';
                     98: 	} elsif ($type eq 'A') {
                     99: 	    $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
                    100: 	} elsif ($type eq 'a') {
                    101: 	    $result .= ' \renewcommand{\labelenumi}{\alph{enumi}.}';
                    102: 	} elsif ($type eq 'i') {
                    103: 	    $result .= ' \renewcommand{\labelenumi}{\roman{enumi}.}';
1.88      albertel  104: 	} else {
                    105: 	    $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
1.83      albertel  106: 	}
1.143     onken     107:         if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.145     onken     108:             $result .= '\begin{itemize}';
1.135     onken     109:         } else {
                    110:             $result .= '\begin{enumerate}';
                    111:         }
1.83      albertel  112:     } elsif ($target eq 'analyze') {
                    113: 	my $part_id="$Apache::inputtags::part.$id";
1.131     raeburn   114:         $Apache::lonhomework::analyze{"$part_id.type"} = 'radiobuttonresponse';
1.83      albertel  115: 	push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
                    116:     }
                    117:     return $result;
1.1       albertel  118: }
                    119: 
                    120: sub end_radiobuttonresponse {
1.83      albertel  121:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    122:     my $result;
                    123:     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
1.145     onken     124:     if ($target eq 'tex' ) {
                    125:         if($env{'form.pdfFormFields'} eq 'yes' and $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                    126:             $result .= '\end{itemize}';
                    127:         } else {
                    128:             $result .= '\end{enumerate}';
                    129:         }
1.135     onken     130:     }
1.83      albertel  131:     &Apache::response::end_response;
                    132:     pop @Apache::lonxml::namespace;
                    133:     &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
1.85      albertel  134:     undef(%Apache::response::foilnames);
1.83      albertel  135:     return $result;
1.1       albertel  136: }
                    137: 
1.43      albertel  138: %Apache::response::foilgroup=();
1.1       albertel  139: sub start_foilgroup {
1.83      albertel  140:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    141:     my $result;
                    142:     %Apache::response::foilgroup=();
                    143:     $Apache::radiobuttonresponse::conceptgroup=0;
1.147     raeburn   144:     &Apache::response::pushrandomnumber(undef,$target);
1.83      albertel  145:     if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
                    146: 	$result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
                    147:     }
                    148:     return $result;
1.5       albertel  149: }
                    150: 
1.15      albertel  151: sub storesurvey {
1.144     raeburn   152:     my ($style) = @_;
1.99      albertel  153:     if ( !&Apache::response::submitted() ) { return ''; }
1.100     albertel  154:     my $response = $env{'form.HWVAL_'.$Apache::inputtags::response['-1']};
1.83      albertel  155:     &Apache::lonxml::debug("Here I am!:$response:");
                    156:     if ( $response !~ /[0-9]+/) { return ''; }
1.96      albertel  157:     my $part = $Apache::inputtags::part;
1.83      albertel  158:     my $id = $Apache::inputtags::response['-1'];
                    159:     my @whichfoils=@{ $Apache::response::foilgroup{'names'} };
                    160:     my %responsehash;
                    161:     $responsehash{$whichfoils[$response]}=$response;
1.96      albertel  162:     my $responsestr=&Apache::lonnet::hash2str(%responsehash);
                    163:     $Apache::lonhomework::results{"resource.$part.$id.submission"}=
                    164: 	$responsestr;
                    165:     my %previous=&Apache::response::check_for_previous($responsestr,$part,$id);
1.144     raeburn   166:     my $ad;
                    167:     if ($style eq 'anonsurvey') {
                    168:         $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
                    169:     } elsif ($style eq 'anonsurveycred') {
1.146     raeburn   170:         $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CREDIT';
1.144     raeburn   171:     } elsif ($style eq 'surveycred') {
                    172:         $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
                    173:     } else {
                    174:         $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
                    175:     }
1.96      albertel  176:     &Apache::response::handle_previous(\%previous,$ad);
1.83      albertel  177:     &Apache::lonxml::debug("submitted a $response<br />\n");
                    178:     return '';
1.15      albertel  179: }
                    180: 
1.120     foxr      181: 
1.32      albertel  182: sub grade_response {
1.123     albertel  183:     my ($answer, $whichfoils, $bubbles_per_line)=@_;
                    184: 
1.99      albertel  185:     if ( !&Apache::response::submitted() ) { return; }
1.83      albertel  186:     my $response;
1.118     foxr      187:     
1.100     albertel  188:     if ($env{'form.submitted'} eq 'scantron') {
1.121     foxr      189: 	$response = &Apache::response::getresponse(1,undef,
1.123     albertel  190: 						   &bubble_line_count(scalar(@{ $whichfoils}),
1.121     foxr      191: 								      $bubbles_per_line),
                    192: 						   $bubbles_per_line);
1.116     foxr      193: 
1.83      albertel  194:     } else {
1.100     albertel  195: 	$response = $env{'form.HWVAL_'.$Apache::inputtags::response['-1']};
1.83      albertel  196:     }
1.120     foxr      197: 
1.118     foxr      198: 
1.83      albertel  199:     if ( $response !~ /[0-9]+/) { return; }
                    200:     my $part=$Apache::inputtags::part;
                    201:     my $id = $Apache::inputtags::response['-1'];
                    202:     my %responsehash;
1.123     albertel  203:     $responsehash{$whichfoils->[$response]}=$response;
1.83      albertel  204:     my $responsestr=&Apache::lonnet::hash2str(%responsehash);
                    205:     my %previous=&Apache::response::check_for_previous($responsestr,
                    206: 						       $part,$id);
                    207:     $Apache::lonhomework::results{"resource.$part.$id.submission"}=
                    208: 	$responsestr;
                    209:     &Apache::lonxml::debug("submitted a $response<br />\n");
                    210:     my $ad;
                    211:     if ($response == $answer) {
                    212: 	$ad='EXACT_ANS';
                    213:     } else {
                    214: 	$ad='INCORRECT';
                    215:     }
                    216:     $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
                    217:     &Apache::response::handle_previous(\%previous,$ad);
1.32      albertel  218: }
                    219: 
1.1       albertel  220: sub end_foilgroup {
1.83      albertel  221:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.29      albertel  222: 
1.83      albertel  223:     my $result;
1.121     foxr      224:     my $bubble_lines;
                    225:     my $bubbles_per_line;
                    226:     my $answer_count;
1.129     foxr      227:     my $id   = $Apache::inputtags::response['-1'];
                    228:     my $part = $Apache::inputtags::part;
1.121     foxr      229:     $bubbles_per_line = 
                    230: 	&Apache::response::get_response_param($Apache::inputtags::part."_$id",
                    231: 					      'numbubbles',
                    232: 					      $default_bubbles_per_line);
                    233: 
                    234: 
1.83      albertel  235:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
                    236: 	$target eq 'tex' || $target eq 'analyze') {
                    237: 	my $style = $Apache::lonhomework::type;
1.93      albertel  238: 	my $direction = &Apache::lonxml::get_param('direction',$parstack,
                    239: 						   $safeeval,'-2');
1.144     raeburn   240: 	if ( (($style eq 'survey') || ($style eq 'surveycred') || 
                    241:               ($style eq 'anonsurvey') || ($style eq 'anonsurveycred')) 
                    242:              && ($target ne 'analyze')) {
1.83      albertel  243: 	    if ($target eq 'web' || $target eq 'tex') {
1.110     foxr      244: 		$result=&displayallfoils($direction, $target);
1.83      albertel  245: 	    } elsif ( $target eq 'answer' ) {
                    246: 		$result=&displayallanswers();
                    247: 	    } elsif ( $target eq 'grade' ) {
1.144     raeburn   248: 		$result=&storesurvey($style);
1.83      albertel  249: 	    }
1.121     foxr      250: 	    $answer_count = scalar(@{$Apache::response::foilgroup{'names'}});
                    251: 
1.83      albertel  252: 	} else {
1.121     foxr      253: 
1.83      albertel  254: 	    my $name;
                    255: 	    my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,
                    256: 						 '-2');
                    257: 	    my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
                    258: 						       $safeeval,'-2');
1.123     albertel  259: 	    my ($answer, @shown) = &whichfoils($max, $randomize);
1.121     foxr      260: 	    $answer_count = scalar(@shown);
                    261: 
1.83      albertel  262: 	    if ($target eq 'web' || $target eq 'tex') {
1.121     foxr      263: 		$result=&displayfoils($target,
1.123     albertel  264: 				      $answer, \@shown,
1.121     foxr      265: 				      $direction,
                    266: 				      $bubbles_per_line);
1.83      albertel  267: 	    } elsif ($target eq 'answer' ) {
1.124     albertel  268: 		$result=&displayanswers($answer, \@shown, $bubbles_per_line);
1.83      albertel  269: 	    } elsif ( $target eq 'grade') {
1.123     albertel  270: 		&grade_response($answer, \@shown, $bubbles_per_line);
1.83      albertel  271: 	    }  elsif ( $target eq 'analyze') {
1.126     foxr      272: 		my $bubble_lines = &bubble_line_count($answer_count, 
                    273: 						      $bubbles_per_line);
1.83      albertel  274: 		&Apache::response::analyze_store_foilgroup(\@shown,
                    275: 							   ['text','value','location']);
1.129     foxr      276: 		my $part_id="$part.$id";
1.83      albertel  277: 		push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },
                    278: 		      ('true','false'));
1.130     foxr      279: 
1.83      albertel  280: 	    }
1.81      albertel  281: 	}
1.111     albertel  282: 	$Apache::lonxml::post_evaluate=0;
1.83      albertel  283:     }
1.114     albertel  284:     if ($target eq 'web') {
                    285: 	&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
                    286: 						  [\%Apache::response::foilgroup]);
                    287:     }
1.128     foxr      288:     &Apache::response::poprandomnumber();
1.121     foxr      289:     $bubble_lines = &bubble_line_count($answer_count, $bubbles_per_line);
1.128     foxr      290:     &Apache::lonxml::increment_counter($bubble_lines,
1.129     foxr      291: 				       "$part.$id");
1.128     foxr      292:     if ($target eq 'analyze') {
                    293: 	&Apache::lonhomework::set_bubble_lines();
                    294:     }
1.83      albertel  295:     return $result;
1.6       albertel  296: }
                    297: 
                    298: sub getfoilcounts {
1.83      albertel  299:     my @names;
                    300:     my $truecnt=0;
                    301:     my $falsecnt=0;
                    302:     my $name;
                    303:     if ( $Apache::response::foilgroup{'names'} ) {
                    304: 	@names= @{ $Apache::response::foilgroup{'names'} };
1.6       albertel  305:     }
1.83      albertel  306:     foreach $name (@names) {
                    307: 	if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
                    308: 	    $truecnt++;
                    309: 	} elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
                    310: 	    $falsecnt++;
                    311: 	}
                    312:     }
                    313:     return ($truecnt,$falsecnt);
1.5       albertel  314: }
                    315: 
1.114     albertel  316: sub format_prior_answer {
                    317:     my ($mode,$answer,$other_data) = @_;
                    318:     my $foil_data = $other_data->[0];
                    319:     my %response = &Apache::lonnet::str2hash($answer);
                    320:     my ($name)   = keys(%response);
                    321:     return '<span class="LC_prior_radiobutton">'.
                    322: 	$foil_data->{$name.'.text'}.'</span>';
                    323: 
1.112     albertel  324: }
                    325: 
1.15      albertel  326: sub displayallfoils {
1.110     foxr      327:     my ($direction, $target)=@_;
1.83      albertel  328:     my $result;
                    329:     &Apache::lonxml::debug("survey style display");
1.106     albertel  330:     my @names;
                    331:     if ( $Apache::response::foilgroup{'names'} ) {
                    332: 	@names= @{ $Apache::response::foilgroup{'names'} };
                    333:     }
1.120     foxr      334: 
1.83      albertel  335:     my $temp=0;
1.110     foxr      336:     my $i   =0;
1.83      albertel  337:     my $id=$Apache::inputtags::response['-1'];
                    338:     my $part=$Apache::inputtags::part;
1.147     raeburn   339:     my ($lastresponse,$newvariation,$showanswer);
                    340:     if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
                    341:         ($Apache::lonhomework::type eq 'randomizetry')) &&
                    342:         ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
                    343:         if ($env{'form.'.$part.'.rndseed'} ne
                    344:             $Apache::lonhomework::history{"resource.$part.rndseed"}) {
                    345:             $newvariation = 1;
                    346:         }
                    347:     }
                    348:     $showanswer = &Apache::response::show_answer();
                    349:     unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'})) ||
                    350:            ($newvariation && !$showanswer)) {
1.144     raeburn   351:         $lastresponse = 
                    352: 	    $Apache::lonhomework::history{"resource.$part.$id.submission"};
                    353:     }
1.93      albertel  354:     if ($direction eq 'horizontal') { $result.='<table><tr>'; }
1.83      albertel  355:     my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
1.147     raeburn   356:     if ($showanswer) {
1.83      albertel  357: 	foreach my $name (@names) {
                    358: 	    if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
1.110     foxr      359: 		if (($direction eq 'horizontal') && ($target ne 'tex')) {
1.93      albertel  360: 		    $result.="<td>";
                    361: 		} else {
1.110     foxr      362: 		    if ($target eq 'tex') {
                    363: 			$result .= '\item \vskip -2mm ';
                    364: 		    } else {
                    365: 			$result.="<br />";
                    366: 		    }
1.93      albertel  367: 		}
1.84      albertel  368: 		if (defined($lastresponse{$name})) {
1.110     foxr      369: 		    if ($target eq 'tex') {
                    370: 			$result .= '}';
                    371: 		    } else {
                    372: 			$result.='<b>';
                    373: 		    }
1.83      albertel  374: 		}
                    375: 		$result .= $Apache::response::foilgroup{$name.'.text'};
1.110     foxr      376: 		if (defined($lastresponse{$name}) && ($target ne 'tex')) {
1.83      albertel  377: 		    $result.='</b>';
                    378: 		}
1.110     foxr      379: 		if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.="</td>"; }
1.83      albertel  380: 	    }
1.45      albertel  381: 	}
1.83      albertel  382:     } else {
                    383: 	foreach my $name (@names) {
                    384: 	    if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
1.93      albertel  385: 		if ($direction eq 'horizontal') {
                    386: 		    $result.="<td>";
                    387: 		} else {
1.110     foxr      388: 		    if ($target eq 'tex') {
1.143     onken     389: 		        if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.145     onken     390:                             my $fieldname = $env{'request.symb'}.'&part_'. $Apache::inputtags::part
                    391:                                             .'&radiobuttonresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'];
                    392:                             $result .= '\item[{'.&Apache::lonxml::print_pdf_radiobutton($fieldname,$temp).'}]'
                    393:                                        .$Apache::response::foilgroup{$name.'.text'}."\n";
1.135     onken     394:                         } else {
                    395:                             $result .= '\item \vskip -2mm ';
                    396:                         }
                    397:                     } else {
1.110     foxr      398: 			$result.="<br />";
                    399: 		    }
                    400: 		}
                    401: 		if ($target eq 'tex') {
1.143     onken     402: 		    if($env{'form.pdfFormFields'} ne 'yes' or $Apache::inputtags::status[-1] ne 'CAN_ANSWER') {
1.135     onken     403:                         $result .= '$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs
                    404:                     }
1.110     foxr      405: 		    $i++;
                    406: 		} else {
                    407: 		    $result .= '<label>';
1.113     albertel  408: 		    $result.="<input
                    409:                        onchange=\"javascript:setSubmittedPart('$part');\"
                    410:                        type=\"radio\"
                    411:                        name=\"HWVAL_$Apache::inputtags::response['-1']\"
1.142     bisitz    412:                        value=\"$temp\"";
1.147     raeburn   413: 
1.142     bisitz    414: 		    if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
1.110     foxr      415: 		    $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.
                    416: 			'</label>';
1.93      albertel  417: 		}
1.83      albertel  418: 		$temp++;
1.110     foxr      419: 		if ($target ne 'tex') {
                    420: 		    if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.="</td>"; }
                    421: 		} else {
                    422: 		    $result.='\vskip 0 mm ';
                    423: 		}
1.83      albertel  424: 	    }
1.45      albertel  425: 	}
                    426:     }
1.120     foxr      427:     
1.110     foxr      428:     if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.='</tr></table>'; }
1.83      albertel  429:     return $result;
1.15      albertel  430: }
                    431: 
1.122     albertel  432: 
1.28      albertel  433: sub whichfoils {
1.83      albertel  434:     my ($max,$randomize)=@_;
1.28      albertel  435: 
1.83      albertel  436:     my @truelist;
                    437:     my @falselist;
                    438:     my @whichfalse =();
                    439:     my ($truecnt,$falsecnt) = &getfoilcounts();
                    440:     my $count=0;
                    441:     # we will add in 1 of the true statements
1.104     albertel  442:     if ( $max>0 && ($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; $max=$count; }
1.83      albertel  443:     my $answer=int(&Math::Random::random_uniform() * ($count));
                    444:     &Apache::lonxml::debug("Count is $count, $answer is $answer");
                    445:     my @names;
                    446:     if ( $Apache::response::foilgroup{'names'} ) {
                    447: 	@names= @{ $Apache::response::foilgroup{'names'} };
                    448:     }
                    449:     if (&Apache::response::showallfoils()) {
                    450: 	@whichfalse=@names;
                    451:     } elsif ($randomize eq 'no') {
                    452: 	&Apache::lonxml::debug("No randomization");
                    453: 	my $havetrue=0;
                    454: 	foreach my $name (@names) {
                    455: 	    if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
                    456: 		if (!$havetrue ) {
                    457: 		    push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
                    458: 		}
                    459: 	    } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
                    460: 		push (@whichfalse,$name);
                    461: 	    } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
                    462: 	    } else {
1.87      albertel  463: 		&Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
1.83      albertel  464: 	    }
                    465: 	}
1.144     raeburn   466: 	if ((!$havetrue) && 
                    467:             ($Apache::lonhomework::type ne 'survey') && 
                    468:             ($Apache::lonhomework::type ne 'surveycred') &&
                    469:             ($Apache::lonhomework::type ne 'anonsurvey') &&
                    470:             ($Apache::lonhomework::type ne 'anonsurveycred')) {
1.134     bisitz    471: 	    &Apache::lonxml::error(&mt('There are no true statements available.').'<br />');
1.97      albertel  472: 	}
1.83      albertel  473:     } else {
                    474: 	my $current=0;
                    475: 	&Apache::lonhomework::showhash(%Apache::response::foilgroup);
                    476: 	my (%top,%bottom);
                    477: 	#first find out where everyone wants to be
                    478: 	foreach my $name (@names) {
                    479: 	    $current++;
                    480: 	    if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
                    481: 		push (@truelist,$name);
                    482: 		if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
                    483: 		    $top{$name}=$current;
                    484: 		} elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
                    485: 		    $bottom{$name}=$current;
                    486: 		}
                    487: 	    } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
                    488: 		push (@falselist,$name);
                    489: 		if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
                    490: 		    $top{$name}=$current;
                    491: 		} elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
                    492: 		    $bottom{$name}=$current;
                    493: 		}
                    494: 	    } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
                    495: 	    } else {
1.87      albertel  496: 		&Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
1.83      albertel  497: 	    }
                    498: 	}
                    499: 	#pick a true statement
                    500: 	my $notrue=0;
                    501: 	if (scalar(@truelist) == 0) { $notrue=1; }
                    502: 	my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
                    503: 	&Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
                    504: 	my (@toplist, @bottomlist);
                    505: 	my $topcount=0;
                    506: 	my $bottomcount=0;
                    507: 	# assign everyone to either toplist/bottomlist or whichfalse
                    508: 	# which false is randomized, toplist bottomlist are in order
                    509: 	while ((($#whichfalse+$topcount+$bottomcount) < $max-2) && ($#falselist > -1)) {
                    510: 	    &Apache::lonxml::debug("Have $#whichfalse max is $max");
                    511: 	    my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
                    512: 	    &Apache::lonxml::debug("From $#falselist elms, picking $afalse");
                    513: 	    $afalse=splice(@falselist,$afalse,1);
                    514: 	    &Apache::lonxml::debug("Picked $afalse");
                    515: 	    &Apache::lonhomework::showhash(('names'=>\@names));
                    516: 	    &Apache::lonhomework::showhash(%top);
                    517: 	    if ($top{$afalse}) {
                    518: 		$toplist[$top{$afalse}]=$afalse;
                    519: 		$topcount++;
                    520: 	    } elsif ($bottom{$afalse}) {
                    521: 		$bottomlist[$bottom{$afalse}]=$afalse;
                    522: 		$bottomcount++;
                    523: 	    } else {
                    524: 		push (@whichfalse,$afalse);
                    525: 	    }
                    526: 	}
                    527: 	&Apache::lonxml::debug("Answer wants $answer");
                    528: 	my $truename=$truelist[$whichtrue];
                    529: 	my $dosplice=1;
1.144     raeburn   530: 	if (($notrue) && 
                    531:             ($Apache::lonhomework::type ne 'survey') &&
                    532:             ($Apache::lonhomework::type ne 'surveycred') &&
                    533:             ($Apache::lonhomework::type ne 'anonsurvey') &&
                    534:             ($Apache::lonhomework::type ne 'anonsurveycred')) {
1.83      albertel  535: 	    $dosplice=0;
1.134     bisitz    536: 	    &Apache::lonxml::error(&mt('There are no true statements available.').'<br />');
1.83      albertel  537: 	}
                    538: 	#insert the true statement, keeping track of where it wants to be
                    539: 	if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
                    540: 	    $toplist[$top{$truename}]=$truename;
                    541: 	    $answer=-1;
                    542: 	    foreach my $top (reverse(@toplist)) {
                    543: 		if ($top) { $answer++;}
                    544: 		if ($top eq $truename) { last; }
1.49      albertel  545: 	    }
1.83      albertel  546: 	    $dosplice=0;
                    547: 	} elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom' && $dosplice) {
                    548: 	    $bottomlist[$bottom{$truename}]=$truename;
                    549: 	    $answer=-1;
                    550: 	    foreach my $bot (@bottomlist) {
                    551: 		if ($bot) { $answer++;}
                    552: 		if ($bot eq $truename) { last; }
1.49      albertel  553: 	    }
1.83      albertel  554: 	    $answer+=$topcount+$#whichfalse+1;
                    555: 	    $dosplice=0;
1.49      albertel  556: 	} else {
1.83      albertel  557: 	    if ($topcount>0 || $bottomcount>0) {
1.150   ! raeburn   558:                 my $inc = 1;
        !           559:                 if (($bottomcount > 0) && ($Apache::lonhomework::type ne 'exam')) {
        !           560:                     $inc = 2;
        !           561:                 }
        !           562:                 $answer=int(&Math::Random::random_uniform() * ($#whichfalse+$inc))
        !           563:                         + $topcount;
1.83      albertel  564: 	    }
                    565: 	}
                    566: 	&Apache::lonxml::debug("Answer now wants $answer");
                    567: 	#add the top items to the top, bottom items to the bottom
                    568: 	for (my $i=0;$i<=$#toplist;$i++) {
                    569: 	    if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
1.49      albertel  570: 	}
1.83      albertel  571: 	for (my $i=0;$i<=$#bottomlist;$i++) {
                    572: 	    if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
1.49      albertel  573: 	}
1.83      albertel  574: 	#if the true statement is randomized insert it into the list
                    575: 	if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
1.49      albertel  576:     }
1.83      albertel  577:     &Apache::lonxml::debug("Answer is $answer");
                    578:     return ($answer,@whichfalse);
1.28      albertel  579: }
                    580: 
                    581: sub displayfoils {
1.123     albertel  582:     my ($target,$answer,$whichfoils,$direction, $bubbles_per_line)=@_;
1.83      albertel  583:     my $result;
1.28      albertel  584: 
1.22      albertel  585:     my $part=$Apache::inputtags::part;
1.83      albertel  586:     my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
                    587:     if ( ($target ne 'tex') &&
                    588: 	 &Apache::response::show_answer() ) {
1.90      albertel  589: 	if ($direction eq 'horizontal') {
                    590: 	    if ($target ne 'tex') {
                    591: 		$result.='<table><tr>';
                    592: 	    }
                    593: 	}
1.123     albertel  594: 	foreach my $name (@{ $whichfoils }) {
1.90      albertel  595: 	    if ($direction eq 'horizontal') {
                    596: 		if ($target ne 'tex') { $result.='<td>'; }
                    597: 	    }
1.83      albertel  598: 	    if ($target ne 'tex') {
                    599: 		$result.="<br />";
                    600: 	    } else {
                    601: 		$result.='\item \vskip -2 mm  ';
                    602: 	    }
                    603: 	    if ($Apache::response::foilgroup{$name.'.value'} eq 'true') { 
1.132     bisitz    604: 		if ($target ne 'tex') {
                    605:                     $result.=&mt('Correct:').'<b>';
                    606:                 } else {
                    607:                     $result.=&mt('Correct:').' \textbf{';
                    608:                 }
1.83      albertel  609: 	    } else {
1.132     bisitz    610: 		$result.=&mt('Incorrect:');
1.83      albertel  611: 	    }
1.94      matthew   612: 	    if ($target eq 'web') { $result.="<label>"; }
1.90      albertel  613: 	    $result.=$Apache::response::foilgroup{$name.'.text'};
1.94      matthew   614: 	    if ($target eq 'web') { $result.="</label>"; }
1.83      albertel  615: 	    if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
                    616: 		if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
                    617: 	    }
1.90      albertel  618: 	    if ($direction eq 'horizontal') {
                    619: 		if ($target ne 'tex') { $result.='</td>'; }
                    620: 	    }
                    621: 	}
                    622: 	if ($direction eq 'horizontal') {
                    623: 	    if ($target ne 'tex') {
                    624: 		$result.='</tr></table>';
                    625: 	    }
1.83      albertel  626: 	}
                    627:     } else {
                    628: 	my @alphabet = ('A'..'Z');
                    629: 	my $i = 0;
1.116     foxr      630: 	my $bubble_number = 0;
1.124     albertel  631: 	my $line = 0;
1.83      albertel  632: 	my $temp=0;  
                    633: 	my $id=$Apache::inputtags::response['-1'];
                    634: 	my $part=$Apache::inputtags::part;
1.147     raeburn   635:         my ($lastresponse,$newvariation);
                    636:         if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
                    637:              ($Apache::lonhomework::type eq 'randomizetry')) && 
                    638:         ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
                    639:             if ($env{'form.'.$part.'.rndseed'} ne
                    640:                 $Apache::lonhomework::history{"resource.$part.rndseed"}) {
                    641:                 $newvariation = 1;
                    642:             }
                    643:         }
                    644:         unless ($newvariation) {
                    645: 	    $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
                    646:         }
1.83      albertel  647: 	my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
1.90      albertel  648: 	if ($target ne 'tex' && $direction eq 'horizontal') {
                    649: 	    $result.="<table><tr>";
                    650: 	}
1.123     albertel  651: 	foreach my $name (@{ $whichfoils }) {
1.83      albertel  652: 	    if ($target ne 'tex') {
1.90      albertel  653: 		if ($direction eq 'horizontal') {
                    654: 		    $result.="<td>"; 
                    655: 		} else { 
                    656: 		    $result.="<br />";
                    657: 		} 
                    658: 	    }
                    659: 	    if ($target ne 'tex') { 
1.94      matthew   660:                 $result.= '<label>';
1.113     albertel  661: 		$result.=
                    662: 		    "<input type=\"radio\"
                    663:                             onchange=\"javascript:setSubmittedPart('$part');\"
                    664:                             name=\"HWVAL_$Apache::inputtags::response['-1']\"
1.142     bisitz    665:                             value=\"$temp\"";
                    666: 		if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
1.108     albertel  667: 		$result .= ' />'.$Apache::response::foilgroup{$name.'.text'}."</label>";
1.83      albertel  668: 	    } else {
                    669: 		if ($Apache::lonhomework::type eq 'exam') {
1.116     foxr      670: 		    if($bubble_number >= $bubbles_per_line) {
1.124     albertel  671: 			$line++;
1.116     foxr      672: 			$i = 0;
                    673: 			$bubble_number = 0;
1.124     albertel  674: 			$result.='\item[\textbf{'.($Apache::lonxml::counter+$line).'}.]';
1.116     foxr      675: 		    }
1.124     albertel  676: 		    $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\';  #' stupid emacs
                    677: 		    $i++;
                    678: 		    $bubble_number++;
1.83      albertel  679: 		} else {
1.145     onken     680:                     if($env{'form.pdfFormFields'} eq 'yes' && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                    681:                         my $fieldname = $env{'request.symb'}.'&part_'. $Apache::inputtags::part
                    682:                                         .'&radiobuttonresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'];
                    683:                         $result .= '\item[{'.&Apache::lonxml::print_pdf_radiobutton($fieldname,$temp).'}]'
                    684:                                    .$Apache::response::foilgroup{$name.'.text'}."\n";
                    685:                     } else { 
                    686:                         $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
                    687:                     }
1.135     onken     688:                 }
1.83      albertel  689: 	    }
1.90      albertel  690: 	    if ($target ne 'tex' && $direction eq 'horizontal') {
                    691: 		$result.="</td>"; 
                    692: 	    }
1.83      albertel  693: 	    $temp++;
                    694: 	}
1.90      albertel  695: 	if ($target ne 'tex' && $direction eq 'horizontal') {
                    696: 	    $result.="</tr></table>";
                    697: 	}
1.83      albertel  698:     }
1.92      albertel  699:     if ($target ne 'tex') { if ($direction ne 'horizontal') { $result.="<br />";} } else { $result.='\vskip 0 mm '; }
1.83      albertel  700:     return $result;
1.81      albertel  701: }
                    702: 
                    703: sub displayallanswers {
1.106     albertel  704:     my @names;
                    705:     if ( $Apache::response::foilgroup{'names'} ) {
                    706: 	@names= @{ $Apache::response::foilgroup{'names'} };
                    707:     }
1.81      albertel  708:     my $result=&Apache::response::answer_header('radiobuttonresponse');
                    709:     foreach my $name (@names) {
                    710: 	$result.=&Apache::response::answer_part('radiobuttonresponse',
                    711: 				$Apache::response::foilgroup{$name.'.value'});
                    712:     }
                    713:     $result.=&Apache::response::answer_footer('radiobuttonresponse');
                    714:     return $result;
1.14      albertel  715: }
                    716: 
1.28      albertel  717: sub displayanswers {
1.124     albertel  718:     my ($answer, $whichopt, $bubbles_per_line)=@_;
                    719:     my $result;
                    720: 
1.105     albertel  721:     if ($Apache::lonhomework::type eq 'exam') {
1.124     albertel  722: 	my $line = int($answer/$bubbles_per_line);
                    723: 	my $correct = ('A'..'Z')[$answer%$bubbles_per_line];
                    724: 	$result .= &Apache::response::answer_header('radiobuttonresponse',
                    725: 						    $line);
                    726: 	$result .= &Apache::response::answer_part('radiobuttonresponse',
                    727: 						  $correct);
                    728:     } else {
                    729: 	$result .= &Apache::response::answer_header('radiobuttonresponse');
1.105     albertel  730:     }
1.123     albertel  731:     foreach my $name (@{ $whichopt }) {
1.83      albertel  732: 	$result.=&Apache::response::answer_part('radiobuttonresponse',
1.105     albertel  733: 						$Apache::response::foilgroup{$name.'.value'});
                    734:     }
1.83      albertel  735:     $result.=&Apache::response::answer_footer('radiobuttonresponse');
                    736:     return $result;
1.28      albertel  737: }
                    738: 
1.14      albertel  739: sub start_conceptgroup {
1.83      albertel  740:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    741:     $Apache::radiobuttonresponse::conceptgroup=1;
                    742:     %Apache::response::conceptgroup=();
                    743:     my $result;
                    744:     if ($target eq 'edit') {
                    745: 	$result.=&Apache::edit::tag_start($target,$token);
                    746: 	$result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
                    747: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    748:     } elsif ($target eq 'modified') {
                    749: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    750: 						     $safeeval,'concept');
                    751: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    752:     }
                    753:     return $result;
1.14      albertel  754: }
                    755: 
                    756: sub end_conceptgroup {
1.83      albertel  757:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    758:     $Apache::radiobuttonresponse::conceptgroup=0;
                    759:     my $result;
                    760:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'  ||
                    761: 	$target eq 'tex' || $target eq 'analyze') {
                    762: 	&Apache::response::pick_foil_for_concept($target,
                    763: 						 ['value','text','location'],
                    764: 						 \%Apache::hint::radiobutton,
                    765: 						 $parstack,$safeeval);
                    766:     } elsif ($target eq 'edit') {
                    767: 	$result=&Apache::edit::end_table();
                    768:     }
                    769:     return $result;
1.26      albertel  770: }
                    771: 
                    772: sub insert_conceptgroup {
1.83      albertel  773:     my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
                    774:     return $result;
1.1       albertel  775: }
                    776: 
                    777: sub start_foil {
1.83      albertel  778:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    779:     my $result='';
                    780:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
                    781: 	&Apache::lonxml::startredirection;
1.95      albertel  782: 	if ($target eq 'analyze') {
                    783: 	    &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
                    784: 	}
1.83      albertel  785:     } elsif ($target eq 'edit') {
                    786: 	$result=&Apache::edit::tag_start($target,$token);
                    787: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
                    788: 	$result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
                    789: 						   ['unused','true','false'],
                    790: 						   $token);
                    791: 	my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
                    792: 						 $safeeval,'-3');
                    793: 	if ($randomize ne 'no') {
                    794: 	    $result.=&Apache::edit::select_arg('Location:','location',
                    795: 					       ['random','top','bottom'],$token);
                    796: 	}
                    797: 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    798:     } elsif ($target eq 'modified') {
                    799: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    800: 						     $safeeval,'value','name',
                    801: 						     'location');
                    802: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    803:     } 
                    804:     return $result;
1.1       albertel  805: }
                    806: 
                    807: sub end_foil {
1.83      albertel  808:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    809:     my $text='';
                    810:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
                    811: 	$text=&Apache::lonxml::endredirection;
                    812:     }
1.85      albertel  813:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
                    814: 	|| $target eq 'tex' || $target eq 'analyze') {
1.83      albertel  815: 	my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
                    816: 	if ($value ne 'unused') {
                    817: 	    my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.102     albertel  818: 	    if ($name eq "") {
1.134     bisitz    819: 		&Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
1.98      albertel  820: 		$name=$Apache::lonxml::curdepth;
                    821: 	    }
1.149     www       822:             if ($name eq "0") {
                    823:                 &Apache::lonxml::error(&mt('Foil name [_1] is not supported. Please choose another name.','<b><tt>'.$name.'</tt></b>'));
                    824:             }
1.85      albertel  825: 	    if (defined($Apache::response::foilnames{$name})) {
1.134     bisitz    826: 		&Apache::lonxml::error(&mt('Foil name [_1] appears more than once. Foil names need to be unique.','<b><tt>'.$name.'</tt></b>'));
1.85      albertel  827: 	    }
1.86      albertel  828: 	    $Apache::response::foilnames{$name}++;
1.85      albertel  829: 	    my $location =&Apache::lonxml::get_param('location',$parstack,
                    830: 						     $safeeval);
1.83      albertel  831: 	    if ( $Apache::radiobuttonresponse::conceptgroup
                    832: 		 && !&Apache::response::showallfoils() ) {
                    833: 		push @{ $Apache::response::conceptgroup{'names'} }, $name;
                    834: 		$Apache::response::conceptgroup{"$name.value"} = $value;
                    835: 		$Apache::response::conceptgroup{"$name.text"} = $text;	
                    836: 		$Apache::response::conceptgroup{"$name.location"} = $location;
                    837: 	    } else {
                    838: 		push @{ $Apache::response::foilgroup{'names'} }, $name;
                    839: 		$Apache::response::foilgroup{"$name.value"} = $value;
                    840: 		$Apache::response::foilgroup{"$name.text"} = $text;
                    841: 		$Apache::response::foilgroup{"$name.location"} = $location;
                    842: 	    }
                    843: 	}
1.18      albertel  844:     }
1.83      albertel  845:     return '';
1.1       albertel  846: }
                    847: 
1.27      albertel  848: sub insert_foil {
1.83      albertel  849:     return '
1.27      albertel  850: <foil name="" value="unused">
                    851: <startouttext />
                    852: <endouttext />
                    853: </foil>';
                    854: }
1.1       albertel  855: 1;
                    856: __END__
1.139     jms       857: 
                    858: 
                    859: 
                    860: =head1 NAME
                    861: 
                    862: Apache::radiobuttonresponse
                    863: 
                    864: =head1 SYNOPSIS
                    865: 
                    866: Handles multiple-choice style responses.
                    867: 
                    868: This is part of the LearningOnline Network with CAPA project
                    869: described at http://www.lon-capa.org.
                    870: 
                    871: =head1 SUBROUTINES
                    872: 
                    873: =over
                    874: 
                    875: =item start_radiobuttonresponse()
                    876: 
                    877: =item bubble_line_count()
                    878: 
                    879: =item end_radiobuttonresponse()
                    880: 
                    881: =item start_foilgroup()
                    882: 
                    883: =item storesurvey()
                    884: 
                    885: =item grade_response()
                    886: 
                    887: =item end_foilgroup()
                    888: 
                    889: =item getfoilcounts()
                    890: 
                    891: =item format_prior_answer()
                    892: 
                    893: =item displayallfoils()
                    894: 
                    895: =item &whichfoils($max,$randomize)
                    896: 
                    897: Randomizes the list of foils.
                    898: Respects
                    899:   - each foils desire to be randomized
                    900:   - the existance of Concept groups of foils (select 1 foil from each)
                    901:   - and selects a single correct statement from all possilble true statments
                    902:   - and limits it to a toal of $max foils
                    903: 
                    904: WARNING: this routine uses the random number generator, it should only
                    905: be called once per target, otherwise it can cause randomness changes in
                    906: homework problems.
                    907: 
                    908: Arguments
                    909:   $max - maximum number of foils to select (including the true one)
                    910:          (so a max of 5 is: 1 true, 4 false)
                    911: 
                    912:   $randomize - whether to randomize the listing of foils, by default
                    913:                will randomize, only if randomize is 'no' will it not
                    914: 
                    915: Returns
                    916:   $answer - location in the array of the correct answer
                    917:   @foils  - array of foil names in to display order
                    918: 
                    919: =item displayfoils()
                    920: 
                    921: =item displayallanswers()
                    922: 
                    923: =item displayanswers()
                    924: 
                    925: =item start_conceptgroup()
                    926: 
                    927: =item end_conceptgroup()
                    928: 
                    929: =item insert_conceptgroup()
                    930: 
                    931: =item start_foil()
                    932: 
                    933: =item end_foil()
                    934: 
                    935: =item insert_foil()
                    936: 
                    937: =back
                    938: 
                    939: =cut
1.1       albertel  940:  

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