Annotation of loncom/homework/rankresponse.pm, revision 1.52

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # rank style response
                      3: #
1.52    ! albertel    4: # $Id: rankresponse.pm,v 1.51 2007/03/27 19:20:49 albertel Exp $
1.1       albertel    5: # Copyright Michigan State University Board of Trustees
                      6: #
                      7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      8: #
                      9: # LON-CAPA is free software; you can redistribute it and/or modify
                     10: # it under the terms of the GNU General Public License as published by
                     11: # the Free Software Foundation; either version 2 of the License, or
                     12: # (at your option) any later version.
                     13: #
                     14: # LON-CAPA is distributed in the hope that it will be useful,
                     15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     17: # GNU General Public License for more details.
                     18: #
                     19: # You should have received a copy of the GNU General Public License
                     20: # along with LON-CAPA; if not, write to the Free Software
                     21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     22: #
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: 
                     28: package Apache::rankresponse;
                     29: use strict;
                     30: use HTML::Entities();
1.30      albertel   31: use Apache::optionresponse();
                     32: use Apache::lonlocal;
1.1       albertel   33: 
                     34: BEGIN {
                     35:     &Apache::lonxml::register('Apache::rankresponse',('rankresponse'));
                     36: }
                     37: 
                     38: sub start_rankresponse {
                     39:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     40:     my $result;
                     41:     #when in a rank response use these
                     42:     &Apache::lonxml::register('Apache::rankresponse',
                     43: 			      ('foilgroup','foil','conceptgroup'));
                     44:     push (@Apache::lonxml::namespace,'rankresponse');
                     45:     my $id = &Apache::response::start_response($parstack,$safeeval);
                     46:     %Apache::hint::rank=();
1.30      albertel   47:     undef(%Apache::response::foilnames);
1.1       albertel   48:     if ($target eq 'meta') {
                     49: 	$result=&Apache::response::meta_package_write('rankresponse');
                     50:     } elsif ($target eq 'edit' ) {
                     51: 	$result.=&Apache::edit::start_table($token).
                     52: 	    '<tr><td>'.&Apache::lonxml::description($token)."</td><td>Delete:".
                     53: 	    &Apache::edit::deletelist($target,$token)
                     54: 	    ."</td><td>&nbsp".&Apache::edit::end_row()
                     55: 	    .&Apache::edit::start_spanning_row();
                     56: 	
                     57: 	$result.=
                     58: 	    &Apache::edit::text_arg('Max Number Of Shown Foils:','max',$token,'4').
                     59: 	    &Apache::edit::select_arg('Randomize Foil Order','randomize',
                     60: 				      ['yes','no'],$token).
                     61: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row()."\n";
                     62:     } elsif ($target eq 'modified') {
                     63: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                     64: 						     $safeeval,'max',
                     65: 						     'randomize');
                     66: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.25      albertel   67:     } elsif ($target eq 'analyze') {
                     68: 	my $part_id="$Apache::inputtags::part.$id";
                     69: 	push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.1       albertel   70:     }
                     71:     return $result;
                     72: }
                     73: 
                     74: sub end_rankresponse {
                     75:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     76:     my $result;
                     77:     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
                     78:     &Apache::response::end_response;
                     79:     pop @Apache::lonxml::namespace;
                     80:     &Apache::lonxml::deregister('Apache::rankresponse',
                     81: 				('foilgroup','foil','conceptgroup'));
1.30      albertel   82:     undef(%Apache::response::foilnames);
1.1       albertel   83:     return $result;
                     84: }
                     85: 
                     86: %Apache::response::foilgroup=();
                     87: sub start_foilgroup {
                     88:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     89:     my $result;
                     90:     %Apache::response::foilgroup=();
                     91:     $Apache::rankresponse::conceptgroup=0;
1.34      albertel   92:     &Apache::response::pushrandomnumber();
1.1       albertel   93:     return $result;
                     94: }
                     95: 
                     96: sub end_foilgroup {
                     97:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     98:     my $result;
1.26      albertel   99:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
                    100: 	$target eq 'tex' || $target eq 'analyze') {
1.1       albertel  101: 	my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
                    102: 	my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
                    103: 						   $safeeval,'-2');
                    104: 	my $tol = &Apache::lonxml::get_param('tol',$parstack,$safeeval,'-2');
                    105: 	if (!defined($tol)) { $tol=0; }
1.3       sakharuk  106: 	if ($target eq 'web' || $target eq 'tex') {
1.1       albertel  107: 	    $result=&displayfoils($target,$max,$randomize,$tol);
1.50      albertel  108: 	    $Apache::lonxml::post_evaluate=0;
1.1       albertel  109: 	} elsif ($target eq 'answer' ) {
                    110: 	    $result=&displayanswers($max,$randomize,$tol);
                    111: 	} elsif ( $target eq 'grade') {
                    112: 	    &grade_response($max,$randomize,$tol);
1.25      albertel  113: 	} elsif ( $target eq 'analyze') {
                    114: 	    my @shown = &whichfoils($max,$randomize);
                    115: 	    &Apache::response::analyze_store_foilgroup(\@shown,
1.26      albertel  116: 						  ['text','value','location']);
1.41      albertel  117: 	    my $part_id=
                    118: 		"$Apache::inputtags::part.$Apache::inputtags::response[-1]";
                    119: 	    $Apache::lonhomework::analyze{"$part_id.tol"}=$tol;
1.1       albertel  120: 	}
1.24      sakharuk  121: 	&Apache::lonxml::increment_counter(&getfoilcounts($max));
1.14      albertel  122:     } elsif ($target eq 'edit') {
                    123: 	$result=&Apache::edit::end_table();
1.1       albertel  124:     }
1.34      albertel  125:     &Apache::response::poprandomnumber();
1.1       albertel  126:     return $result;
                    127: }
                    128: 
                    129: sub get_correct_order {
                    130:     my ($tol,@foils) =@_;
                    131:     my @correctorder;
                    132:     my @value_names;
                    133:     foreach my $name (@foils) {
                    134: 	my @pair=($Apache::response::foilgroup{$name.'.value'},$name);
                    135: 	push(@value_names,\@pair);
                    136:     }
                    137:     @value_names =
                    138: 	sort {
1.17      albertel  139: 	    if (abs($a->[0] - $b->[0]) > $tol) {return ($a->[0] <=> $b->[0]);}
1.1       albertel  140: 	    return 0;
                    141: 	} @value_names;
                    142:     my @value_names_tmp=@value_names;
                    143:     my $firstpair=shift(@value_names_tmp);
                    144:     my $order=1;
                    145:     my %order;
                    146:     my $count=1;
                    147:     my $lastvalue=$firstpair->[0];
                    148:     $order{$firstpair->[1]}=$order;
                    149:     foreach my $pair (@value_names_tmp) {
                    150: 	$count++;
                    151: 	if (abs($pair->[0]-$lastvalue) > $tol ) {
                    152: 	    $order=$count;
                    153: 	}
                    154: 	$order{$pair->[1]}=$order;
                    155: 	$lastvalue=$pair->[0];
                    156:     }
                    157:     foreach my $name (@foils) {
                    158: 	push(@correctorder,$order{$name});
                    159:     }
                    160:     &Apache::lonhomework::showhash('b' => \@value_names);
                    161:     &Apache::lonhomework::showhash('b' => \@correctorder);
                    162:     return @correctorder;
                    163: }
                    164: 
                    165: sub displayanswers {
                    166:     my ($max,$randomize,$tol,@opt)=@_;
                    167:     if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
                    168:     my @names = @{ $Apache::response::foilgroup{'names'} };
                    169:     my @whichfoils = &whichfoils($max,$randomize);
                    170:     my @correctorder=&get_correct_order($tol,@whichfoils);
1.49      albertel  171:     my $result;
                    172:     if ($Apache::lonhomework::type eq 'exam') {
                    173: 	my @alphabet = ('A'..'Z');
                    174: 	my $i=0;
                    175: 	foreach my $order (@correctorder) {
                    176: 	    $result.=&Apache::response::answer_header('rankresponse',$i++);
                    177: 	    $result.=&Apache::response::answer_part('rankresponse',
                    178: 						    $alphabet[$order-1]);
                    179: 	    $result.=&Apache::response::answer_part('rankresponse',$order);
                    180: 	    $result.=&Apache::response::answer_footer('rankresponse');
                    181: 	}
                    182:     } else {
                    183: 	$result=&Apache::response::answer_header('rankresponse');
                    184: 	foreach my $order (@correctorder) {
                    185: 	    $result.=&Apache::response::answer_part('rankresponse',$order);
                    186: 	}
                    187: 	$result.=&Apache::response::answer_footer('rankresponse');
1.1       albertel  188:     }
                    189:     return $result;
                    190: }
                    191: 
                    192: sub check_response_order {
                    193:     my (%responsehash)=@_;
1.45      albertel  194:     my @order=sort( {$a <=> $b} values(%responsehash));
1.1       albertel  195:     my $lastvalue=0;
                    196:     my $expected=1;
                    197:     my $malformed=0;
                    198:     foreach my $current (@order) {
                    199: 	&Apache::lonxml::debug("$lastvalue $expected $malformed");
                    200: 	if (!($current == $lastvalue || $current == $expected)) {
                    201: 	    $malformed=1;
                    202: 	}
                    203: 	$expected++;
                    204: 	$lastvalue=$current;
                    205:     }
                    206:     return $malformed;
                    207: }
                    208: 
                    209: sub grade_response {
                    210:     my ($max,$randomize,$tol)=@_;
                    211:     my (@whichfoils)=&whichfoils($max,$randomize);
1.44      albertel  212:     if (!&Apache::response::submitted()) { return; }
1.1       albertel  213:     my %responsehash;
                    214:     my %grade;
1.28      albertel  215:     my ($temp,$right,$wrong,$ignored)=(1,0,0,0);
1.1       albertel  216:     my @correctorder=&get_correct_order($tol,@whichfoils);
                    217:     foreach my $name (@whichfoils) {
1.38      albertel  218: 	my $response = &Apache::response::getresponse($temp,'A is 1');
1.1       albertel  219: 	my $value=shift(@correctorder);
                    220: 	if ( $response =~ /[^\s]/) {
1.27      albertel  221: 	    $responsehash{$name}=$response;
1.1       albertel  222: 	    &Apache::lonxml::debug("submitted a $response for $value<br />\n");
                    223: 	    if ($value eq $response) {
                    224: 		$grade{$name}='1'; $right++;
                    225: 	    } else {
                    226: 		$grade{$name}='0'; $wrong++;
                    227: 	    }
                    228: 	} else {
                    229: 	    $ignored++;
                    230: 	}
                    231: 	$temp++;
                    232:     }
                    233:     my $malformed=&check_response_order(%responsehash);
                    234:     my $part=$Apache::inputtags::part;
                    235:     my $id = $Apache::inputtags::response['-1'];
                    236:     my $responsestr=&Apache::lonnet::hash2str(%responsehash);
                    237:     my $gradestr   =&Apache::lonnet::hash2str(%grade);
                    238:     my %previous=&Apache::response::check_for_previous($responsestr,
                    239: 						       $part,$id);
                    240:     &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored and was $malformed malformed");
                    241:     my $ad;
                    242:     if ($malformed) {
                    243: 	$ad='MISORDERED_RANK';
                    244:     } elsif ($wrong==0 && $ignored==0) {
                    245: 	$ad='EXACT_ANS';
                    246:     } elsif ($wrong==0 && $right==0) {
                    247: 	#nothing submitted
                    248:     } else {
                    249: 	if ($ignored==0) {
                    250: 	    $ad='INCORRECT';
                    251: 	} else {
                    252: 	    $ad='MISSING_ANSWER';
                    253: 	}
                    254:     }
1.40      albertel  255:     if ($Apache::lonhomework::type eq 'survey' &&
                    256: 	($ad eq 'INCORRECT' || $ad eq 'EXACT_ANS') ) {
                    257: 	$ad='SUBMITTED';
                    258:     } else {
                    259: 	$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
                    260:     }
1.1       albertel  261:     $Apache::lonhomework::results{"resource.$part.$id.submission"}=
                    262: 	$responsestr;
                    263:     $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
                    264:     &Apache::response::handle_previous(\%previous,$ad);
                    265: }
                    266: 
1.52    ! albertel  267: sub format_prior_answer {
        !           268:     my ($mode,$answer,$other_data) = @_;
        !           269:     my %lastresponse=&Apache::lonnet::str2hash($answer);
        !           270:     my $foil_order  =$other_data->[0];
        !           271:     my %grading     =&Apache::lonnet::str2hash($other_data->[1]);
        !           272:     my $output;
        !           273:     foreach my $name (@{ $foil_order }) {
        !           274: 	next if (!defined($lastresponse{$name}));
        !           275: 	$output .= '<tr><td>'.$lastresponse{$name}.'</td></tr>';
        !           276:     }
        !           277:     return if (!defined($output));
        !           278:     $output =
        !           279: 	'<table class="LC_prior_rank">'.$output.'</table>';
        !           280:     return $output;
        !           281: }
        !           282: 
1.1       albertel  283: sub displayfoils {
                    284:     my ($target,$max,$randomize,$tol)=@_;
                    285:     my $result;
1.4       sakharuk  286:     my @alphabet=('A'..'Z');
1.1       albertel  287:     my (@whichfoils)=&whichfoils($max,$randomize);
                    288:     my $part=$Apache::inputtags::part;
                    289:     my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
                    290:     my @whichopt=(1..($#whichfoils+1));
                    291:     my @correctorder=&get_correct_order($tol,@whichfoils);
1.20      sakharuk  292:     if ( &Apache::response::show_answer() && ($target ne 'tex')) {
1.1       albertel  293: 	foreach my $name (@whichfoils) {
                    294: 	    my $text=$Apache::response::foilgroup{$name.'.text'};
                    295: 	    my $value=shift(@correctorder);
1.46      albertel  296: 	    if ($target eq 'web') {
                    297: 		$result.='<br /><b>'.$value.':</b> '.$text;
                    298: 	    } else {
                    299: 		$result.=' \strut\\\\\strut '.$value.':'.$text;
                    300: 	    }
1.1       albertel  301: 	}
                    302:     } else {
                    303: 	my $i = 0;
1.29      albertel  304: 	my $temp=1;
1.1       albertel  305: 	my $id=$Apache::inputtags::response[-1];
                    306: 	my $part=$Apache::inputtags::part;
                    307: 	my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
1.5       sakharuk  308: 	my %lastresponse=&Apache::lonnet::str2hash($lastresponse); 
                    309: 	my @alp = splice @alphabet, 0, $#whichopt + 1;
1.15      sakharuk  310: 	my $internal_counter=$Apache::lonxml::counter;
1.1       albertel  311: 	foreach my $name (@whichfoils) {
                    312: 	    my $lastopt=$lastresponse{$name};
1.3       sakharuk  313: 	    my $optionlist='';
                    314: 	    if ($target ne 'tex') {$optionlist="<option></option>\n";}
1.1       albertel  315: 	    my $option;
                    316: 	    foreach $option (@whichopt) {
                    317: 		if ($option eq $lastopt) {
1.3       sakharuk  318: 		    if ($target ne 'tex') {$optionlist.="<option selected=\"on\">$option</option>\n";}
1.1       albertel  319: 		} else {
1.3       sakharuk  320: 		    if ($target ne 'tex') {$optionlist.="<option>$option</option>\n";}
1.1       albertel  321: 		}
                    322: 	    }
1.12      sakharuk  323: 	    if ($target ne 'tex' && $Apache::lonhomework::type ne 'exam') {
1.51      albertel  324: 		$optionlist='<select onchange="javascript:setSubmittedPart(\''.
                    325: 		  $part.'\');" name="HWVAL_'.
1.3       sakharuk  326: 		    $Apache::inputtags::response[-1].':'.$temp.'">'.
                    327: 		        $optionlist."</select>\n";
                    328: 	    } else {
                    329: 		$optionlist=' '.$temp.' '.$optionlist.' ';
                    330: 	    }
1.1       albertel  331: 	    my $text=$Apache::response::foilgroup{$name.'.text'};
1.3       sakharuk  332: 	    if ($target ne 'tex') {
1.12      sakharuk  333: 		if ($Apache::lonhomework::type ne 'exam') {
                    334: 		    $result.='<br />'.$optionlist.$text."\n";
                    335: 		} else {
                    336: 		    $result.='<br />'.$text."\n";
                    337: 		}
1.4       sakharuk  338: 		if ($Apache::lonhomework::type eq 'exam') {
1.22      albertel  339: 		    my @values=(1..scalar(@whichopt));
                    340: 		    $result.=&Apache::optionresponse::webbubbles(\@values,\@whichopt,$temp,$lastopt);
1.4       sakharuk  341: 		}
                    342: 	    } else {
                    343: 		if ($Apache::lonhomework::type eq 'exam') {
1.33      sakharuk  344: 		    $result.='\vskip 0 mm   '.$text.' \vskip 0 mm '."\n";
1.36      albertel  345: 		    $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]'.&Apache::optionresponse::bubbles(\@alp,\@whichopt,'rankresponse').'\end{enumerate} \vskip -8 mm \strut ';
1.15      sakharuk  346: 		    $internal_counter++;
1.4       sakharuk  347: 		} else {
1.16      sakharuk  348: 		    $result.=' \vskip 0mm \framebox[5 mm][s]{\tiny\strut} '.$text."\n";
1.4       sakharuk  349: 		}
                    350: 	    }
1.1       albertel  351: 	    $temp++;
                    352: 	}
                    353:     }
1.52    ! albertel  354:     if ($target eq 'web') {
        !           355: 	&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
        !           356: 						  [\@whichfoils,
        !           357: 						   'submissiongrading']);
        !           358:     }
1.5       sakharuk  359:     if ($target ne 'tex') {$result.="<br />";} else {$result.=' \vskip 0 mm ';}
1.1       albertel  360:     return $result;
                    361: }
                    362: 
                    363: sub getfoilcounts {
                    364:     my ($max)=@_;
                    365:     # +1 since instructors will count from 1
                    366:     my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
                    367:     if (&Apache::response::showallfoils()) { $max=$count; }
                    368:     if ($count>$max) { $count=$max } 
                    369:     &Apache::lonxml::debug("Count is $count from $max");
                    370:     return $count;
                    371: }
                    372: 
                    373: sub whichfoils {
                    374:     my ($max,$randomize)=@_;
1.13      albertel  375:     return &Apache::response::whichorder($max,$randomize,
                    376: 					 &Apache::response::showallfoils(),
                    377: 					 \%Apache::response::foilgroup);
1.1       albertel  378: }
                    379: 
                    380: sub start_conceptgroup {
                    381:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    382:     $Apache::rankresponse::conceptgroup=1;
                    383:     %Apache::response::conceptgroup=();
                    384:     my $result;
                    385:     if ($target eq 'edit') {
                    386: 	$result.=&Apache::edit::tag_start($target,$token,
                    387: 					  "Concept Grouped Foils");
                    388: 	$result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
                    389: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    390:     }
                    391:     if ($target eq 'modified') {
                    392: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    393: 						     $safeeval,'concept');
                    394: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    395:     }
                    396:     return $result;
                    397: }
                    398: 
                    399: sub end_conceptgroup {
                    400:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    401:     $Apache::rankresponse::conceptgroup=0;
                    402:     my $result='';
1.25      albertel  403:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    404: 	$target eq 'tex' || $target eq 'analyze') {
1.1       albertel  405: 	#if not there aren't any foils to display and thus no question
1.25      albertel  406: 	&Apache::response::pick_foil_for_concept($target,
                    407: 						 ['value','text','location'],
                    408: 						 \%Apache::hint::rank,
                    409: 						 $parstack,$safeeval);
1.1       albertel  410:     } elsif ($target eq 'edit') {
                    411: 	$result=&Apache::edit::end_table();
                    412:     }
                    413:     return $result;
                    414: }
                    415: 
                    416: sub insert_conceptgroup {
                    417:     my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
                    418:     return $result;
                    419: }
                    420: 
                    421: sub start_foil {
                    422:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    423:     my $result='';
1.25      albertel  424:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  425: 	&Apache::lonxml::startredirection;
1.39      albertel  426: 	if ($target eq 'analyze') {
                    427: 	    &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
                    428: 	}
1.1       albertel  429:     } elsif ($target eq 'edit') {
                    430: 	$result=&Apache::edit::tag_start($target,$token,"Foil");
                    431: 	my $level='-2';
                    432: 	if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
                    433: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
                    434: 	$result.= &Apache::edit::text_arg('Rank Value:','value',$token,'15');
                    435: 	my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
                    436: 						 $safeeval,'-3');
                    437: 	if ($randomize ne 'no') {
                    438: 	    $result.=&Apache::edit::select_arg('Location:','location',
                    439: 					     ['random','top','bottom'],$token);
                    440: 	}
                    441: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    442:     } elsif ($target eq 'modified') {
                    443: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    444: 						     $safeeval,'value',
                    445: 						     'name','location');
                    446: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    447:     }
                    448:     return $result;
                    449: }
                    450: 
                    451: sub end_foil {
                    452:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    453:     my $text ='';
                    454:     my $result = '';
1.25      albertel  455:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  456: 	$text=&Apache::lonxml::endredirection;
                    457:     }
1.25      albertel  458:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    459: 	$target eq 'tex' || $target eq 'analyze') {
1.1       albertel  460: 	my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
1.42      albertel  461: 	if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
                    462: 	    $text='\vskip 5mm $\triangleright$ '.$text;
                    463: 	}
1.1       albertel  464: 	if ($value ne 'unused') {
                    465: 	    my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    466: 	    &Apache::lonxml::debug("Got a name of :$name:");
1.48      albertel  467: 	    if ($name eq "") {
1.47      albertel  468: 		&Apache::lonxml::warning("Foils without names exist. This can cause problems to malfunction.");
1.43      albertel  469: 		$name=$Apache::lonxml::curdepth;
                    470: 	    }
1.1       albertel  471: 	    &Apache::lonxml::debug("Using a name of :$name:");
1.30      albertel  472: 	    if (defined($Apache::response::foilnames{$name})) {
                    473: 		&Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
                    474: 	    }
1.31      albertel  475: 	    $Apache::response::foilnames{$name}++;
1.30      albertel  476: 	    my $location =&Apache::lonxml::get_param('location',$parstack,
                    477: 						     $safeeval);
1.1       albertel  478: 	    if ( $Apache::rankresponse::conceptgroup
                    479: 		 && !&Apache::response::showallfoils() ) {
                    480: 		push @{ $Apache::response::conceptgroup{'names'} }, $name;
                    481: 		$Apache::response::conceptgroup{"$name.value"} = $value;
1.42      albertel  482: 		$Apache::response::conceptgroup{"$name.text"} = $text;
1.1       albertel  483: 		$Apache::response::conceptgroup{"$name.location"} = $location;
                    484: 	    } else {
                    485: 		push @{ $Apache::response::foilgroup{'names'} }, $name;
                    486: 		$Apache::response::foilgroup{"$name.value"} = $value;
1.42      albertel  487: 		$Apache::response::foilgroup{"$name.text"} = $text;
1.1       albertel  488: 		$Apache::response::foilgroup{"$name.location"} = $location;
                    489: 	    }
                    490: 	}
                    491:     }
                    492:     if ($target eq 'edit') {
                    493: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    494:     }
                    495:     return $result;
                    496: }
                    497: 
                    498: sub insert_foil {
                    499:     return '
                    500: <foil name="" value="unused">
                    501: <startouttext />
                    502: <endouttext />
                    503: </foil>';
                    504: }
                    505: 1;
                    506: __END__

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