Annotation of loncom/homework/matchresponse.pm, revision 1.32

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # Full matching style response
                      3: #
1.32    ! sakharuk    4: # $Id: matchresponse.pm,v 1.31 2003/11/15 06:28:02 albertel Exp $
1.1       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: #
                     28: 
                     29: package Apache::matchresponse;
                     30: use strict;
                     31: use HTML::Entities();
                     32: use Math::Random();
1.6       sakharuk   33: use Apache::optionresponse;
                     34: 
1.1       albertel   35: BEGIN {
                     36:     &Apache::lonxml::register('Apache::matchresponse',('matchresponse'));
                     37: }
                     38: 
                     39: sub start_matchresponse {
                     40:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     41:     my $result;
                     42:     #when in a matchresponse use these
                     43:     &Apache::lonxml::register('Apache::matchresponse',
                     44: 			      ('foilgroup','foil','conceptgroup','item',
                     45: 			       'itemgroup'));
                     46:     push (@Apache::lonxml::namespace,'matchresponse');
                     47:     my $id = &Apache::response::start_response($parstack,$safeeval);
                     48:     %Apache::hint::match=();
                     49:     if ($target eq 'meta') {
                     50: 	$result=&Apache::response::meta_package_write('matchresponse');
                     51:     } elsif ($target eq 'edit' ) {
                     52: 	$result.=&Apache::edit::start_table($token).
                     53: 	    '<tr><td>'.&Apache::lonxml::description($token)."</td><td>Delete:".
                     54: 	    &Apache::edit::deletelist($target,$token)
                     55: 	    ."</td><td>&nbsp".&Apache::edit::end_row()
                     56: 	    .&Apache::edit::start_spanning_row();
                     57: 	
                     58: 	$result.=
                     59: 	    &Apache::edit::text_arg('Max Number Of Shown Foils:','max',$token,'4').
                     60: 	    &Apache::edit::select_arg('Randomize Foil Order','randomize',
                     61: 				      ['yes','no'],$token).
                     62: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row()."\n";
                     63:     } elsif ($target eq 'modified') {
                     64: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                     65: 						     $safeeval,'max',
                     66: 						     'randomize');
                     67: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.28      albertel   68:     } elsif ($target eq 'analyze') {
                     69: 	my $part_id="$Apache::inputtags::part.$id";
                     70: 	push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.1       albertel   71:     }
                     72:     return $result;
                     73: }
                     74: 
                     75: sub end_matchresponse {
                     76:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     77:     my $result;
                     78:     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
                     79:     &Apache::response::end_response;
                     80:     pop @Apache::lonxml::namespace;
                     81:     &Apache::lonxml::deregister('Apache::matchresponse',
                     82: 				('foilgroup','foil','conceptgroup'));
                     83:     return $result;
                     84: }
                     85: 
                     86: %Apache::response::itemgroup=();
                     87: sub start_itemgroup {
                     88:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     89:     my $result;
                     90:     %Apache::response::itemgroup=();
1.4       albertel   91:     %Apache::matchresponse::itemtable=();
1.15      albertel   92: 
1.1       albertel   93:     if ($target eq 'edit') {
                     94: 	$result=&Apache::edit::tag_start($target,$token);
                     95: 	$result.=&Apache::edit::select_arg('Randomize Order:','randomize',
                     96: 					   ['yes','no'],$token);
1.4       albertel   97: 	$result.=&Apache::edit::select_arg('Items Display Location:',
                     98: 					   'location',
                     99: 					   ['top','bottom','left','right'],
                    100: 					   $token);
1.1       albertel  101: 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.4       albertel  102:     } elsif ($target eq 'modified') {
                    103: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    104: 						     $safeeval,'randomize',
                    105: 						     'location');
                    106: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.21      sakharuk  107:     } elsif ($target eq 'web' or $target eq 'tex') {
1.4       albertel  108: 	$Apache::matchresponse::itemtable{'location'}=
                    109: 	    &Apache::lonxml::get_param('location',$parstack,$safeeval);
1.1       albertel  110:     }
                    111:     return $result;
                    112: }
                    113: 
                    114: sub end_itemgroup {
                    115:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    116:     my $result;
                    117: 
1.17      albertel  118:     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
1.1       albertel  119:     if (!defined(@{ $Apache::response::itemgroup{'names'} })) { return; }
                    120:     my @names=@{ $Apache::response::itemgroup{'names'} };
                    121:     my $randomize =&Apache::lonxml::get_param('randomize',$parstack,$safeeval);
1.2       albertel  122:     if ($randomize ne 'no' ) {
1.18      albertel  123: 	@names=&Apache::response::whichorder($#names+1,$randomize,0,
                    124: 					 \%Apache::response::itemgroup);
1.1       albertel  125:     }
1.30      albertel  126:     if ($target eq 'analyze') {
                    127: 	my $partid="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
                    128: 	push (@{ $Apache::lonhomework::analyze{"$partid.items"} }, @names);
                    129:     }
1.1       albertel  130:     my %letter_name_map;
                    131:     my %name_letter_map;
                    132:     my @alphabet=('A'..'Z');
                    133:     my $i=0;
                    134:     foreach my $name (@names) {
                    135: 	$letter_name_map{$alphabet[$i]}=$name;
                    136: 	$name_letter_map{$name}=$alphabet[$i];
                    137: 	$i++;
                    138:     }
1.15      albertel  139:     $Apache::response::itemgroup{'letter_name_map'}=\%letter_name_map;
1.1       albertel  140:     $Apache::response::itemgroup{'name_letter_map'}=\%name_letter_map;
                    141:     if ($target eq 'web') {
1.4       albertel  142: 	my $table='<table>';
1.1       albertel  143: 	my $i=0;
                    144: 	foreach my $name (@names) {
1.4       albertel  145: 	    $table.='<tr><td>'.$alphabet[$i].'</td><td>'.
1.1       albertel  146: 		$Apache::response::itemgroup{$name.'.text'}.
                    147: 		    '</td></tr>';
                    148: 	    $i++;
                    149: 	}
1.4       albertel  150: 	$table.='</table>';
                    151: 	$Apache::matchresponse::itemtable{'display'}=$table;
1.5       sakharuk  152:     } elsif ($target eq 'tex') {
1.22      sakharuk  153: 	my $table=' \begin{description} ';
1.5       sakharuk  154: 	my $i=0;
                    155: 	foreach my $name (@names) {
1.11      sakharuk  156: 	    $Apache::response::itemgroup{$name.'.text'}=~s/\$\$/\$/g;
1.19      sakharuk  157: 	    $table.='\item['.$alphabet[$i].'] '.
1.21      sakharuk  158: 		$Apache::response::itemgroup{$name.'.text'};
1.5       sakharuk  159: 	    $i++;
                    160: 	}
1.22      sakharuk  161: 	$table.=' \end{description} \strut ';
1.5       sakharuk  162: 	$Apache::matchresponse::itemtable{'display'}=$table;
1.17      albertel  163:     }
1.1       albertel  164:     return $result;
                    165: }
                    166: 
                    167: sub start_item {
                    168:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    169:     my $result='';
1.30      albertel  170:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  171: 	&Apache::lonxml::startredirection;
                    172:     } elsif ($target eq 'edit') {
1.3       albertel  173: 	my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
                    174: 						 $safeeval,'-2');
1.1       albertel  175: 	$result=&Apache::edit::tag_start($target,$token,"Item");
                    176: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
1.3       albertel  177: 	if ($randomize ne 'no') {
                    178: 	    $result.=&Apache::edit::select_arg('Location:','location',
                    179: 					       ['random','top','bottom'],
                    180: 					       $token);
                    181: 	}
                    182: 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.1       albertel  183:     } elsif ($target eq 'modified') {
                    184: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.3       albertel  185: 						     $safeeval,'name',
                    186: 						     'location');
1.1       albertel  187: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    188:     }
                    189:     return $result;
                    190: }
                    191: 
                    192: sub end_item {
                    193:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    194:     my $text ='';
                    195:     my $result = '';
1.30      albertel  196:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  197: 	$text=&Apache::lonxml::endredirection;
                    198:     }
                    199:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.30      albertel  200: 	$target eq 'edit' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  201: 	my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.3       albertel  202: 	my $location=&Apache::lonxml::get_param('location',$parstack,
                    203: 						$safeeval);
1.1       albertel  204: 	&Apache::lonxml::debug("Got a name of :$name:");
                    205: 	if (!$name) { $name=$Apache::lonxml::curdepth; }
                    206: 	&Apache::lonxml::debug("Using a name of :$name:");
                    207: 	push @{ $Apache::response::itemgroup{'names'} }, $name;
                    208: 	$Apache::response::itemgroup{"$name.text"} = $text;
1.3       albertel  209: 	$Apache::response::itemgroup{"$name.location"} = $location;
1.1       albertel  210:     }
                    211:     if ($target eq 'edit') {
                    212: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    213:     }
                    214:     return $result;
                    215: }
                    216: 
                    217: sub insert_item {
                    218:     return '
                    219: <item name="">
                    220: <startouttext />
                    221: <endouttext />
                    222: </item>';
                    223: }
                    224: 
                    225: %Apache::response::foilgroup=();
                    226: sub start_foilgroup {
                    227:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    228:     my $result;
                    229:     %Apache::response::foilgroup=();
                    230:     $Apache::matchresponse::conceptgroup=0;
                    231:     &Apache::response::setrandomnumber();
                    232:     if ($target eq 'edit') {
                    233: 	$result.=&Apache::edit::start_table($token)
                    234: 	    ."<tr><td>Collection Of Foils</td><td>Delete:"
                    235: 	    .&Apache::edit::deletelist($target,$token)
                    236: 	    ."</td><td>&nbsp;".&Apache::edit::end_row()
                    237:             .&Apache::edit::start_spanning_row()."\n";
                    238:     }
                    239:     return $result;
                    240: }
                    241: 
                    242: sub end_foilgroup {
                    243:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    244:     my $result;
1.28      albertel  245:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  246: 	my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
                    247: 	my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
                    248: 						   $safeeval,'-2');
1.5       sakharuk  249: 	if ($target eq 'web' || $target eq 'tex') {
1.1       albertel  250: 	    $result=&displayfoils($target,$max,$randomize);
                    251: 	} elsif ($target eq 'answer' ) {
                    252: 	    $result=&displayanswers($max,$randomize);
                    253: 	} elsif ( $target eq 'grade') {
                    254: 	    &grade_response($max,$randomize);
1.28      albertel  255: 	} elsif ( $target eq 'analyze') {
                    256: 	    my @shown=&whichfoils($max,$randomize);
                    257: 	    &Apache::response::analyze_store_foilgroup(\@shown,
1.29      albertel  258: 						 ['text','value','location']);
1.28      albertel  259: 	    #FIXME need to store options in some way
1.1       albertel  260: 	}
1.20      sakharuk  261: 	&Apache::lonxml::increment_counter(&getfoilcounts($max));
1.1       albertel  262:     } elsif ($target eq 'edit') {
                    263: 	$result=&Apache::edit::end_table();
                    264:     }
                    265:     return $result;
1.29      albertel  266: }
                    267: 
                    268: sub whichfoils {
                    269:     my ($max,$randomize)=@_;
                    270:     return &Apache::response::whichorder(&getfoilcounts($max),
                    271: 					 $randomize,
                    272: 					 &Apache::response::showallfoils(),
                    273: 					 \%Apache::response::foilgroup);
1.1       albertel  274: }
                    275: 
                    276: sub displayanswers {
                    277:     my ($max,$randomize,@opt)=@_;
                    278:     if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
                    279:     my @names = @{ $Apache::response::foilgroup{'names'} };
1.18      albertel  280:     my @whichfoils = &Apache::response::whichorder(&getfoilcounts($max),
                    281: 						   $randomize,
                    282: 					  &Apache::response::showallfoils(),
                    283: 					 \%Apache::response::foilgroup);
1.1       albertel  284:     my $result=&Apache::response::answer_header('matchresponse');
                    285:     my %name_letter_map;
                    286:     if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
                    287: 	%name_letter_map=
                    288: 	    %{ $Apache::response::itemgroup{'name_letter_map'} };
                    289:     }
                    290:     foreach my $name (@whichfoils) {
                    291: 	my $value_name=$Apache::response::foilgroup{$name.'.value'};
                    292: 	my $letter=$name_letter_map{$value_name};
                    293: 	$result.=&Apache::response::answer_part('matchresponse',$letter);
                    294:     }
                    295:     $result.=&Apache::response::answer_footer('matchresponse');
                    296:     return $result;
                    297: }
                    298: 
                    299: 
                    300: sub grade_response {
                    301:     my ($max,$randomize)=@_;
1.18      albertel  302:     my (@whichfoils)=&Apache::response::whichorder(&getfoilcounts($max),
                    303: 						   $randomize,
                    304: 				            &Apache::response::showallfoils(),
                    305: 				           \%Apache::response::foilgroup);
1.1       albertel  306:     if (!defined($ENV{'form.submitted'})) { return; }
                    307:     my %responsehash;
                    308:     my %grade;
                    309:     my ($temp,$right,$wrong,$ignored)=(0,0,0,0);
                    310:     my %letter_name_map;
                    311:     if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
                    312: 	%letter_name_map=
                    313: 	    %{ $Apache::response::itemgroup{'letter_name_map'} };
                    314:     }
1.30      albertel  315:     my @items;
1.1       albertel  316:     foreach my $name (@whichfoils) {
1.27      albertel  317: 	my $response = &Apache::response::getresponse($temp);
1.30      albertel  318: 	push(@items,$response);
1.1       albertel  319: 	my $responsename = $letter_name_map{$response};
                    320: 	my $value=$Apache::response::foilgroup{$name.'.value'};
                    321: 	if ( $response =~ /[^\s]/) {
1.31      albertel  322: 	    $responsehash{$name}=$responsename;
1.1       albertel  323: 	    &Apache::lonxml::debug("submitted a $response for $value<br />\n");
                    324: 	    if ($value eq $responsename) {
                    325: 		$grade{$name}='1'; $right++;
                    326: 	    } else {
                    327: 		$grade{$name}='0'; $wrong++;
                    328: 	    }
                    329: 	} else {
                    330: 	    $ignored++;
                    331: 	}
                    332: 	$temp++;
                    333:     }
                    334:     my $part=$Apache::inputtags::part;
                    335:     my $id = $Apache::inputtags::response['-1'];
                    336:     my $responsestr=&Apache::lonnet::hash2str(%responsehash);
1.30      albertel  337:     my $itemstr    =&Apache::lonnet::array2str(@items);
1.1       albertel  338:     my $gradestr   =&Apache::lonnet::hash2str(%grade);
1.30      albertel  339:     my %previous=&Apache::response::check_for_previous($responsestr,$part,$id);
1.1       albertel  340:     &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored ");
                    341:     my $ad;
                    342:     if ($wrong==0 && $ignored==0) {
                    343: 	$ad='EXACT_ANS';
                    344:     } elsif ($wrong==0 && $right==0) {
                    345: 	#nothing submitted
                    346:     } else {
                    347: 	if ($ignored==0) {
                    348: 	    $ad='INCORRECT';
                    349: 	} else {
                    350: 	    $ad='MISSING_ANSWER';
                    351: 	}
                    352:     }
                    353:     $Apache::lonhomework::results{"resource.$part.$id.submission"}=
                    354: 	$responsestr;
1.30      albertel  355:     $Apache::lonhomework::results{"resource.$part.$id.submissionitems"}=
                    356: 	$itemstr;
1.1       albertel  357:     $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=
                    358: 	$gradestr;
                    359:     $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
                    360:     &Apache::response::handle_previous(\%previous,$ad);
                    361: }
                    362: 
1.4       albertel  363: sub itemdisplay {
                    364:     my ($location)=@_;
                    365:     if ($location eq 'top' &&
                    366: 	!defined($Apache::matchresponse::itemtable{'location'})) {
                    367: 	return $Apache::matchresponse::itemtable{'display'};
                    368:     }
                    369:     if ($Apache::matchresponse::itemtable{'location'} eq $location) {
                    370: 	return $Apache::matchresponse::itemtable{'display'};
                    371:     }
                    372:     return undef;
                    373: }
1.1       albertel  374: sub displayfoils {
                    375:     my ($target,$max,$randomize)=@_;
                    376:     my $result;
1.4       albertel  377:     my $question;
1.18      albertel  378:     my (@whichfoils)=&Apache::response::whichorder(&getfoilcounts($max),
                    379: 						   $randomize,
                    380: 				            &Apache::response::showallfoils(),
                    381: 				           \%Apache::response::foilgroup);
1.1       albertel  382:     my $part=$Apache::inputtags::part;
                    383:     my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
                    384:     my %letter_name_map;
                    385:     if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
                    386: 	%letter_name_map=
                    387: 	    %{ $Apache::response::itemgroup{'letter_name_map'} };
                    388:     }
                    389:     my %name_letter_map;
                    390:     if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
                    391: 	%name_letter_map=
                    392: 	    %{ $Apache::response::itemgroup{'name_letter_map'} };
                    393:     }
1.25      albertel  394:     if ( &Apache::response::show_answer() && ($target ne 'tex')) {
1.1       albertel  395: 	foreach my $name (@whichfoils) {
                    396: 	    my $text=$Apache::response::foilgroup{$name.'.text'};
                    397: 	    my $value=$Apache::response::foilgroup{$name.'.value'};
                    398: 	    my $letter=$name_letter_map{$value};
1.5       sakharuk  399: 	    if ($target eq 'tex') {
                    400: 		$question.=' \\\\ '.$letter.':'.$text;
                    401: 	    } else {
                    402: 		$question.='<br />'.$letter.':'.$text;
                    403: 	    }
1.1       albertel  404: 	}
                    405:     } else {
                    406: 	my $i = 0;
                    407: 	my $temp=0;
                    408: 	my $id=$Apache::inputtags::response[-1];
                    409: 	my $part=$Apache::inputtags::part;
                    410: 	my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
1.9       sakharuk  411: 	my %lastresponse=&Apache::lonnet::str2hash($lastresponse);    
                    412: 	my @alphabet=('A'..'Z');
1.15      albertel  413: 	my @used_letters=sort(keys(%letter_name_map));
1.20      sakharuk  414: 	my $internal_counter=$Apache::lonxml::counter;
1.1       albertel  415: 	foreach my $name (@whichfoils) {
                    416: 	    my $lastopt=$lastresponse{$name};
                    417: 	    my $last_letter=$name_letter_map{$lastopt};
1.5       sakharuk  418: 	    my $optionlist = '';
1.7       sakharuk  419: 	    if ($target ne 'tex') {
                    420: 		$optionlist="<option></option>\n";
                    421: 	    } else {
                    422: 		if ($Apache::lonhomework::type ne 'exam') {
                    423: 		    $optionlist='\framebox[5 mm][s]{\tiny\strut}';
                    424: 		}
                    425: 	    }
1.1       albertel  426: 	    my $option;
1.15      albertel  427: 	    foreach $option (@used_letters) {
1.1       albertel  428: 		if ($option eq $last_letter) {
1.6       sakharuk  429: 		    if ($target ne 'tex') {$optionlist.="<option selected=\"on\">$option</option>\n";}
1.1       albertel  430: 		} else {
1.6       sakharuk  431: 		    if ($target ne 'tex') {$optionlist.="<option>$option</option>\n";}
1.1       albertel  432: 		}
                    433: 	    }
1.19      sakharuk  434: 	    if ($target ne 'tex' && $Apache::lonhomework::type ne 'exam') {
1.5       sakharuk  435: 	        $optionlist='<select name="HWVAL_'.
                    436: 		    $Apache::inputtags::response[-1].':'.$temp.'">'.
                    437: 		        $optionlist."</select>\n";
                    438: 	    }
1.1       albertel  439: 	    my $text=$Apache::response::foilgroup{$name.'.text'};
1.5       sakharuk  440: 	    if ($target ne 'tex') {
1.19      sakharuk  441: 		if ($Apache::lonhomework::type ne 'exam') {
                    442: 		    $question.='<br />'.$optionlist.$text."\n";
                    443: 		} else {
                    444: 		    $question.='<br />'.$text."\n";
                    445: 		}
1.6       sakharuk  446: 		if ($Apache::lonhomework::type eq 'exam') {
1.27      albertel  447: 		    $question.=&Apache::optionresponse::webbubbles(\@used_letters,\@used_letters,$temp,$last_letter);
1.6       sakharuk  448: 		}
                    449: 	    } else {		
                    450: 		if ($Apache::lonhomework::type eq 'exam') {
                    451: 		    $question.=' '.$optionlist.$text."\n";
1.13      sakharuk  452: 		    my @emptyItems = ();
1.16      albertel  453: 		    for (my $i=0;$i<=$#used_letters;$i++) {push @emptyItems, ' ';}
1.20      sakharuk  454: 		    $question.='\vskip -2 mm\parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]\parbox{\textwidth - 5 mm}{'.&Apache::optionresponse::bubbles(\@used_letters,\@emptyItems).'}\end{enumerate}} \vskip -10 mm \strut ';
                    455: 		    $internal_counter++;
1.6       sakharuk  456: 	        } else {
1.22      sakharuk  457: 		    $question.=' '.$optionlist.$text.'\strut\\\\\strut '."\n";
1.6       sakharuk  458: 		}
1.5       sakharuk  459:             } 
1.1       albertel  460: 	    $temp++;
                    461: 	}
1.4       albertel  462:     }
                    463:     if ($result=&itemdisplay('top')) {
                    464: 	$result.=$question;
                    465:     } elsif ($result=&itemdisplay('bottom')) {
                    466: 	$result=$question.$result;
                    467:     } elsif ($result=&itemdisplay('right')) {
1.32    ! sakharuk  468: 	if ($target ne 'tex') {
        !           469: 	    $result='<table><tr><td>'.$question.'</td><td>'.$result.
        !           470: 		'</td></tr></table>';
        !           471: 	} else {
        !           472: 	    $result='\begin{tabular}{p{\textwidth/2}p{\textwidth/2}}\begin{minipage}{\textwidth/2}'.$question.'\end{minipage}&\begin{minipage}{\textwidth/2}'.$result.'\end{minipage}\end{tabular}';
        !           473: 	}
1.4       albertel  474:     } elsif ($result=&itemdisplay('left')) {
1.32    ! sakharuk  475: 	if ($target ne 'tex') {
        !           476: 	    $result='<table><tr><td>'.$result.'</td><td>'.$question.
        !           477: 		'</td></tr></table>';
        !           478: 	} else {
        !           479: 	    $result='\begin{tabular}{p{\textwidth/2}p{\textwidth/2}}\begin{minipage}{\textwidth/2}'.$result.'\end{minipage}&\begin{minipage}{\textwidth/2}'.$question.'\end{minipage}\end{tabular}';
        !           480: 	}
1.1       albertel  481:     }
1.5       sakharuk  482:     if ($target ne 'tex') {$result.="<br />";} else {$result.=' \\\\ ';}
1.1       albertel  483:     return $result;
                    484: }
                    485: 
                    486: sub getfoilcounts {
                    487:     my ($max)=@_;
                    488:     # +1 since instructors will count from 1
                    489:     my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
                    490:     if (&Apache::response::showallfoils()) { $max=$count; }
                    491:     if ($count>$max) { $count=$max } 
                    492:     &Apache::lonxml::debug("Count is $count from $max");
                    493:     return $count;
                    494: }
                    495: 
                    496: 
                    497: sub start_conceptgroup {
                    498:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    499:     $Apache::matchresponse::conceptgroup=1;
                    500:     %Apache::response::conceptgroup=();
                    501:     my $result;
                    502:     if ($target eq 'edit') {
                    503: 	$result.=&Apache::edit::tag_start($target,$token,
                    504: 					  "Concept Grouped Foils");
                    505: 	$result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
                    506: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    507:     }
                    508:     if ($target eq 'modified') {
                    509: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    510: 						     $safeeval,'concept');
                    511: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    512:     }
                    513:     return $result;
                    514: }
                    515: 
                    516: sub end_conceptgroup {
                    517:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    518:     $Apache::matchresponse::conceptgroup=0;
                    519:     my $result='';
1.28      albertel  520:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    521: 	$target eq 'tex' || $target eq 'analyze') {
                    522: 	&Apache::response::pick_foil_for_concept($target,
                    523: 						 ['value','text','location'],
                    524: 						 \%Apache::hint::match,
                    525: 						 $parstack,$safeeval);
1.1       albertel  526:     } elsif ($target eq 'edit') {
                    527: 	$result=&Apache::edit::end_table();
                    528:     }
                    529:     return $result;
                    530: }
                    531: 
                    532: sub insert_conceptgroup {
                    533:     my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
                    534:     return $result;
                    535: }
                    536: 
                    537: sub start_foil {
                    538:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    539:     my $result='';
1.28      albertel  540:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  541: 	&Apache::lonxml::startredirection;
                    542:     } elsif ($target eq 'edit') {
                    543: 	$result=&Apache::edit::tag_start($target,$token,"Foil");
                    544: 	my $level='-2';
                    545: 	if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
                    546: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
                    547: 	my @names;
                    548: 	if (defined(@{ $Apache::response::itemgroup{'names'} })) {
                    549: 	    @names=@{ $Apache::response::itemgroup{'names'} };
                    550: 	}
                    551: 	$result.= &Apache::edit::select_or_text_arg('Correct Option:','value',['unused',@names],$token,'15');
                    552: 	my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
                    553: 						 $safeeval,'-3');
                    554: 	if ($randomize ne 'no') {
                    555: 	    $result.=&Apache::edit::select_arg('Location:','location',
                    556: 					     ['random','top','bottom'],$token);
                    557: 	}
                    558: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    559:     } elsif ($target eq 'modified') {
                    560: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    561: 						     $safeeval,'value',
                    562: 						     'name','location');
                    563: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    564:     }
                    565:     return $result;
                    566: }
                    567: 
                    568: sub end_foil {
                    569:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    570:     my $text ='';
                    571:     my $result = '';
1.28      albertel  572:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  573: 	$text=&Apache::lonxml::endredirection;
                    574:     }
1.28      albertel  575:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    576: 	$target eq 'tex' || $target eq 'analyze') {
1.1       albertel  577: 	my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
                    578: 	if ($value ne 'unused') {
                    579: 	    my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    580: 	    my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
                    581: 	    &Apache::lonxml::debug("Got a name of :$name:");
                    582: 	    if (!$name) { $name=$Apache::lonxml::curdepth; }
                    583: 	    &Apache::lonxml::debug("Using a name of :$name:");
                    584: 	    if ( $Apache::matchresponse::conceptgroup
                    585: 		 && !&Apache::response::showallfoils() ) {
                    586: 		push @{ $Apache::response::conceptgroup{'names'} }, $name;
                    587: 		$Apache::response::conceptgroup{"$name.value"} = $value;
1.19      sakharuk  588: 		if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
1.14      sakharuk  589: 		    $Apache::response::conceptgroup{"$name.text"} = ' $\triangleright$ '.$text;
                    590: 		} else {
                    591: 		    $Apache::response::conceptgroup{"$name.text"} = $text;
                    592: 		}
1.1       albertel  593: 		$Apache::response::conceptgroup{"$name.location"} = $location;
                    594: 	    } else {
                    595: 		push @{ $Apache::response::foilgroup{'names'} }, $name;
                    596: 		$Apache::response::foilgroup{"$name.value"} = $value;
1.16      albertel  597: 		if ($Apache::lonhomework::type eq 'exam') {
1.19      sakharuk  598: 		    if ($target eq 'tex') {
                    599: 			$Apache::response::foilgroup{"$name.text"} = '\vskip 5 mm $\triangleright$ '.$text;
                    600: 		    } else {
                    601: 			$Apache::response::foilgroup{"$name.text"} = $text;
                    602: 		    }
1.14      sakharuk  603: 		} else {
                    604: 		    if ($target eq 'tex') {
1.24      sakharuk  605: 			$Apache::response::foilgroup{"$name.text"} = $text;
1.14      sakharuk  606: 		    } else {
                    607: 			$Apache::response::foilgroup{"$name.text"} = $text;
                    608: 		    }
                    609: 		}
1.1       albertel  610: 		$Apache::response::foilgroup{"$name.location"} = $location;
                    611: 	    }
                    612: 	}
                    613:     }
                    614:     if ($target eq 'edit') {
                    615: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    616:     }
                    617:     return $result;
                    618: }
                    619: 
                    620: sub insert_foil {
                    621:     return '
                    622: <foil name="" value="unused">
                    623: <startouttext />
                    624: <endouttext />
                    625: </foil>';
                    626: }
                    627: 1;
                    628: __END__

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