File:  [LON-CAPA] / loncom / homework / rankresponse.pm
Revision 1.64: download - view: text, annotated - select for diffs
Sun Dec 19 00:48:50 2010 UTC (13 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0, loncapaMITrelate_1, HEAD
- New Question Type - randomizetry
  - Only display rankings from last try when displaying options for new try,
    if rndseed for last try is the same as for current try.

    1: # The LearningOnline Network with CAPA
    2: # rank style response
    3: #
    4: # $Id: rankresponse.pm,v 1.64 2010/12/19 00:48:50 raeburn Exp $
    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();
   31: use Apache::optionresponse();
   32: use Apache::lonlocal;
   33: use Apache::lonxml;
   34: use Apache::lonnet;
   35: 
   36: BEGIN {
   37:     &Apache::lonxml::register('Apache::rankresponse',('rankresponse'));
   38: }
   39: 
   40: sub start_rankresponse {
   41:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   42:     my $result;
   43:     #when in a rank response use these
   44:     &Apache::lonxml::register('Apache::rankresponse',
   45: 			      ('foilgroup','foil','conceptgroup'));
   46:     push (@Apache::lonxml::namespace,'rankresponse');
   47:     my $id = &Apache::response::start_response($parstack,$safeeval);
   48:     %Apache::hint::rank=();
   49:     undef(%Apache::response::foilnames);
   50:     if ($target eq 'meta') {
   51: 	$result=&Apache::response::meta_package_write('rankresponse');
   52:     } elsif ($target eq 'edit' ) {
   53: 	$result.=&Apache::edit::start_table($token)
   54:            .'<tr><td>'.&Apache::lonxml::description($token).'</td>'
   55:            .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
   56:            .&Apache::edit::deletelist($target,$token)
   57:            .'</span></td>'
   58:            .'<td>&nbsp;'.&Apache::edit::end_row()
   59:            .&Apache::edit::start_spanning_row();
   60: 	
   61: 	$result.=
   62: 	    &Apache::edit::text_arg('Max Number Of Shown Foils:','max',$token,'4').
   63: 	    &Apache::edit::select_arg('Randomize Foil Order:','randomize',
   64: 				      ['yes','no'],$token).
   65: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row()."\n";
   66:     } elsif ($target eq 'modified') {
   67: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
   68: 						     $safeeval,'max',
   69: 						     'randomize');
   70: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
   71:     } elsif ($target eq 'analyze') {
   72: 	my $part_id="$Apache::inputtags::part.$id";
   73:         $Apache::lonhomework::analyze{"$part_id.type"} = 'rankresponse';
   74: 	push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
   75: 	push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} }, 1);
   76: 
   77:     }
   78:     return $result;
   79: }
   80: 
   81: sub end_rankresponse {
   82:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   83:     my $result;
   84:     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
   85:     &Apache::response::end_response;
   86:     pop @Apache::lonxml::namespace;
   87:     &Apache::lonxml::deregister('Apache::rankresponse',
   88: 				('foilgroup','foil','conceptgroup'));
   89:     undef(%Apache::response::foilnames);
   90:     return $result;
   91: }
   92: 
   93: %Apache::response::foilgroup=();
   94: sub start_foilgroup {
   95:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   96:     my $result;
   97:     %Apache::response::foilgroup=();
   98:     $Apache::rankresponse::conceptgroup=0;
   99:     &Apache::response::pushrandomnumber(undef,$target);
  100:     return $result;
  101: }
  102: 
  103: sub end_foilgroup {
  104:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  105:     my $result;
  106:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
  107: 	$target eq 'tex' || $target eq 'analyze') {
  108: 	my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
  109: 	my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
  110: 						   $safeeval,'-2');
  111: 	my $tol = &Apache::lonxml::get_param('tol',$parstack,$safeeval,'-2');
  112: 	if (!defined($tol)) { $tol=0; }
  113: 	if ($target eq 'web' || $target eq 'tex') {
  114: 	    $result=&displayfoils($target,$max,$randomize,$tol);
  115: 	    $Apache::lonxml::post_evaluate=0;
  116: 	} elsif ($target eq 'answer' ) {
  117: 	    $result=&displayanswers($max,$randomize,$tol);
  118: 	} elsif ( $target eq 'grade') {
  119: 	    &grade_response($max,$randomize,$tol);
  120: 	} elsif ( $target eq 'analyze') {
  121: 	    my @shown = &whichfoils($max,$randomize);
  122: 	    &Apache::response::analyze_store_foilgroup(\@shown,
  123: 						  ['text','value','location']);
  124: 	    my $part_id=
  125: 		"$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  126: 	    $Apache::lonhomework::analyze{"$part_id.tol"}=$tol;
  127: 	}
  128: 	my $part = $Apache::inputtags::part;
  129: 	my $id   = $Apache::inputtags::response[-1];
  130: 	&Apache::lonxml::increment_counter(&getfoilcounts($max),
  131: 					   "$part.$id");
  132: 	if ($target eq 'analyze') {
  133: 	    &Apache::lonhomework::set_bubble_lines();
  134: 	}
  135:     } elsif ($target eq 'edit') {
  136: 	$result=&Apache::edit::end_table();
  137:     }
  138:     &Apache::response::poprandomnumber();
  139:     return $result;
  140: }
  141: 
  142: sub get_correct_order {
  143:     my ($tol,@foils) =@_;
  144:     my @correctorder;
  145:     my @value_names;
  146:     foreach my $name (@foils) {
  147: 	my @pair=($Apache::response::foilgroup{$name.'.value'},$name);
  148: 	push(@value_names,\@pair);
  149:     }
  150:     @value_names =
  151: 	sort {
  152: 	    if (abs($a->[0] - $b->[0]) > $tol) {return ($a->[0] <=> $b->[0]);}
  153: 	    return 0;
  154: 	} @value_names;
  155:     my @value_names_tmp=@value_names;
  156:     my $firstpair=shift(@value_names_tmp);
  157:     my $order=1;
  158:     my %order;
  159:     my $count=1;
  160:     my $lastvalue=$firstpair->[0];
  161:     $order{$firstpair->[1]}=$order;
  162:     foreach my $pair (@value_names_tmp) {
  163: 	$count++;
  164: 	if (abs($pair->[0]-$lastvalue) > $tol ) {
  165: 	    $order=$count;
  166: 	}
  167: 	$order{$pair->[1]}=$order;
  168: 	$lastvalue=$pair->[0];
  169:     }
  170:     foreach my $name (@foils) {
  171: 	push(@correctorder,$order{$name});
  172:     }
  173:     &Apache::lonhomework::showhash('b' => \@value_names);
  174:     &Apache::lonhomework::showhash('b' => \@correctorder);
  175:     return @correctorder;
  176: }
  177: 
  178: sub displayanswers {
  179:     my ($max,$randomize,$tol,@opt)=@_;
  180:     if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
  181:     my @names = @{ $Apache::response::foilgroup{'names'} };
  182:     my @whichfoils = &whichfoils($max,$randomize);
  183:     my @correctorder=&get_correct_order($tol,@whichfoils);
  184:     my $result;
  185:     if ($Apache::lonhomework::type eq 'exam') {
  186: 	my @alphabet = ('A'..'Z');
  187: 	my $i=0;
  188: 	foreach my $order (@correctorder) {
  189: 	    $result.=&Apache::response::answer_header('rankresponse',$i++);
  190: 	    $result.=&Apache::response::answer_part('rankresponse',
  191: 						    $alphabet[$order-1]);
  192: 	    $result.=&Apache::response::answer_part('rankresponse',$order);
  193: 	    $result.=&Apache::response::answer_footer('rankresponse');
  194: 	}
  195:     } else {
  196: 	$result=&Apache::response::answer_header('rankresponse');
  197: 	foreach my $order (@correctorder) {
  198: 	    $result.=&Apache::response::answer_part('rankresponse',$order);
  199: 	}
  200: 	$result.=&Apache::response::answer_footer('rankresponse');
  201:     }
  202:     return $result;
  203: }
  204: 
  205: sub check_response_order {
  206:     my (%responsehash)=@_;
  207:     my @order=sort( {$a <=> $b} values(%responsehash));
  208:     my $lastvalue=0;
  209:     my $expected=1;
  210:     my $malformed=0;
  211:     foreach my $current (@order) {
  212: 	&Apache::lonxml::debug("$lastvalue $expected $malformed");
  213: 	if (!($current == $lastvalue || $current == $expected)) {
  214: 	    $malformed=1;
  215: 	}
  216: 	$expected++;
  217: 	$lastvalue=$current;
  218:     }
  219:     return $malformed;
  220: }
  221: 
  222: sub grade_response {
  223:     my ($max,$randomize,$tol)=@_;
  224:     my (@whichfoils)=&whichfoils($max,$randomize);
  225:     if (!&Apache::response::submitted()) { return; }
  226:     my %responsehash;
  227:     my %grade;
  228:     my ($temp,$right,$wrong,$ignored)=(1,0,0,0);
  229:     my @correctorder=&get_correct_order($tol,@whichfoils);
  230:     foreach my $name (@whichfoils) {
  231: 	my $response = &Apache::response::getresponse($temp,'A is 1');
  232: 	my $value=shift(@correctorder);
  233: 	if ( $response =~ /[^\s]/) {
  234: 	    $responsehash{$name}=$response;
  235: 	    &Apache::lonxml::debug("submitted a $response for $value<br />\n");
  236: 	    if ($value eq $response) {
  237: 		$grade{$name}='1'; $right++;
  238: 	    } else {
  239: 		$grade{$name}='0'; $wrong++;
  240: 	    }
  241: 	} else {
  242: 	    $ignored++;
  243: 	}
  244: 	$temp++;
  245:     }
  246:     my $malformed=&check_response_order(%responsehash);
  247:     my $part=$Apache::inputtags::part;
  248:     my $id = $Apache::inputtags::response['-1'];
  249:     my $responsestr=&Apache::lonnet::hash2str(%responsehash);
  250:     my $gradestr   =&Apache::lonnet::hash2str(%grade);
  251:     my %previous=&Apache::response::check_for_previous($responsestr,
  252: 						       $part,$id);
  253:     &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored and was $malformed malformed");
  254:     my $ad;
  255:     if ($malformed) {
  256: 	$ad='MISORDERED_RANK';
  257:     } elsif ($wrong==0 && $ignored==0) {
  258: 	$ad='EXACT_ANS';
  259:     } elsif ($wrong==0 && $right==0) {
  260: 	#nothing submitted
  261:     } else {
  262: 	if ($ignored==0) {
  263: 	    $ad='INCORRECT';
  264: 	} else {
  265: 	    $ad='MISSING_ANSWER';
  266: 	}
  267:     }
  268:     if (($ad eq 'INCORRECT' || $ad eq 'EXACT_ANS')) {
  269:         if ($Apache::lonhomework::type eq 'survey') {
  270:             $ad='SUBMITTED';
  271:         } elsif ($Apache::lonhomework::type eq 'surveycred') {
  272: 	    $ad='SUBMITTED_CREDIT';
  273:         } elsif ($Apache::lonhomework::type eq 'anonsurvey') {
  274:             $ad='ANONYMOUS';
  275:         } elsif ($Apache::lonhomework::type eq 'anonsurveycred') {
  276:             $ad='ANONYMOUS_CREDIT';
  277:         } else {
  278:             $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
  279:         }
  280:     } else {
  281: 	$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
  282:     }
  283:     if ($Apache::lonhomework::type eq 'randomizetry') {
  284:         if ($Apache::lonhomework::type eq 'randomizetry') {
  285:             $Apache::lonhomework::results{"resource.$part.$id.foilorder"} = &Apache::lonnet::array2str(@whichfoils);
  286:         }
  287:     }
  288:     $Apache::lonhomework::results{"resource.$part.$id.submission"}=
  289: 	$responsestr;
  290:     $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
  291:     &Apache::response::handle_previous(\%previous,$ad);
  292: }
  293: 
  294: sub format_prior_answer {
  295:     my ($mode,$answer,$other_data) = @_;
  296:     my %lastresponse=&Apache::lonnet::str2hash($answer);
  297:     my $foil_order  =$other_data->[0];
  298:     my %grading     =&Apache::lonnet::str2hash($other_data->[1]);
  299:     my $output;
  300:     foreach my $name (@{ $foil_order }) {
  301: 	next if (!defined($lastresponse{$name}));
  302: 	$output .= '<tr><td>'.$lastresponse{$name}.'</td></tr>';
  303:     }
  304:     return if (!defined($output));
  305:     $output =
  306: 	'<table class="LC_prior_rank">'.$output.'</table>';
  307:     return $output;
  308: }
  309: 
  310: sub displayfoils {
  311:     my ($target,$max,$randomize,$tol)=@_;
  312:     my $result;
  313:     my @alphabet=('A'..'Z');
  314:     my (@whichfoils)=&whichfoils($max,$randomize);
  315:     my $part=$Apache::inputtags::part;
  316:     my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
  317:     my @whichopt=(1..($#whichfoils+1));
  318:     my @correctorder=&get_correct_order($tol,@whichfoils);
  319:     if ( &Apache::response::show_answer() && ($target ne 'tex')) {
  320: 	foreach my $name (@whichfoils) {
  321: 	    my $text=$Apache::response::foilgroup{$name.'.text'};
  322: 	    my $value=shift(@correctorder);
  323: 	    if ($target eq 'web') {
  324: 		$result.='<br /><b>'.$value.':</b> '.$text;
  325: 	    } else {
  326: 		$result.=' \strut\\\\\strut '.$value.':'.$text;
  327: 	    }
  328: 	}
  329:     } else {
  330: 	my $i = 0;
  331: 	my $temp=1;
  332: 	my $id=$Apache::inputtags::response[-1];
  333: 	my $part=$Apache::inputtags::part;
  334:         my ($lastresponse,$newvariation);
  335:         if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
  336:              ($Apache::lonhomework::type eq 'randomizetry')) &&
  337:         ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
  338:             if ($env{'form.'.$part.'.rndseed'} ne
  339:                 $Apache::lonhomework::history{"resource.$part.rndseed"}) {
  340:                 $newvariation = 1;
  341:             }
  342:         }
  343:         unless (((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) || $newvariation) {
  344:             $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
  345:         }
  346: 	my %lastresponse=&Apache::lonnet::str2hash($lastresponse); 
  347: 	my @alp = splice @alphabet, 0, $#whichopt + 1;
  348: 	my $internal_counter=$Apache::lonxml::counter;
  349:         if($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
  350:             $result .= '\strut \\\\ \strut \\\\' ;
  351:         }
  352:         foreach my $name (@whichfoils) {
  353: 	    my $lastopt=$lastresponse{$name};
  354: 	    my $optionlist='';
  355: 	    if ($target ne 'tex') {
  356:                 $optionlist = "<option></option>\n";
  357:             } 
  358:             if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
  359:                 my $fieldname = $env{'request.symb'}.'&part_'.$Apache::inputtags::part.'&rankresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp;
  360:                 $optionlist =  &Apache::lonxml::print_pdf_start_combobox($fieldname);
  361:             }
  362: 	    my $option;
  363: 	    foreach $option (@whichopt) {
  364: 		if ($option eq $lastopt) {
  365: 		    if ($target ne 'tex' ) {
  366:                         $optionlist.="<option selected=\"selected\">$option</option>\n";
  367:                     } elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
  368:                         $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option); 
  369:                     }
  370: 		} else {
  371: 		    if ($target ne 'tex') {
  372:                         $optionlist.="<option>$option</option>\n";
  373:                     } elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
  374:                         $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option); 
  375:                     }
  376: 		} 
  377: 	    }
  378: 	    if ($target ne 'tex' && $Apache::lonhomework::type ne 'exam') {
  379: 		$optionlist='<select onchange="javascript:setSubmittedPart(\''.
  380: 		  $part.'\');" name="HWVAL_'.
  381: 		    $Apache::inputtags::response[-1].':'.$temp.'">'.
  382: 		        $optionlist."</select>\n";
  383: 	    } elsif ($env{'form.pdfFormFields'} eq 'yes') {
  384:                 #do nothing
  385:             } else {
  386: 		$optionlist=' '.$temp.' '.$optionlist.' ';
  387: 	    }
  388: 	    my $text=$Apache::response::foilgroup{$name.'.text'};
  389: 	    if ($target ne 'tex') {
  390: 		if ($Apache::lonhomework::type ne 'exam') {
  391: 		    $result.='<br />'.$optionlist.$text."\n";
  392: 		} else {
  393: 		    $result.='<br />'.$text."\n";
  394: 		}
  395: 		if ($Apache::lonhomework::type eq 'exam') {
  396: 		    my @values=(1..scalar(@whichopt));
  397: 		    $result.=&Apache::optionresponse::webbubbles(\@values,\@whichopt,$temp,$lastopt);
  398: 		}
  399: 	    } else {
  400: 		if ($Apache::lonhomework::type eq 'exam') {
  401: 		    $result .= '\vskip 0 mm '.$text.' \vskip 0 mm '."\n";
  402: 		    $result .= '\vskip -1 mm';
  403: 		    $result .= '\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]';
  404: 		    $result .= &Apache::optionresponse::bubbles(\@alp,\@whichopt,'rankresponse');
  405: 		    $result .= '\end{enumerate} \vskip -8 mm \strut ';
  406: 		    $internal_counter++;
  407: 		} else {
  408:                     if($env{'form.pdfFormFields'} ne 'yes') {
  409: 		        $result.=' \vskip 0mm \framebox[5 mm][s]{\tiny\strut} '.$text."\n";
  410:                     } else {
  411:                         $result.= $optionlist.' '. &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
  412:                     }
  413: 		}
  414: 	    }
  415: 	    $temp++;
  416: 	}
  417:     }
  418:     if ($target eq 'web') {
  419:         my $questiontype;
  420:         if ($Apache::lonhomework::type eq 'randomizetry') {
  421:             $questiontype = $Apache::lonhomework::type;
  422:         }
  423: 	&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
  424: 						  [\@whichfoils,
  425: 						   'submissiongrading'],
  426:                                                   $questiontype);
  427:     }
  428:     if ($target ne 'tex') {$result.="<br />";} else {$result.=' \vskip 0 mm ';}
  429:     return $result;
  430: }
  431: 
  432: sub getfoilcounts {
  433:     my ($max)=@_;
  434:     # +1 since instructors will count from 1
  435:     my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
  436:     if (&Apache::response::showallfoils()) { $max=$count; }
  437:     if ($count>$max) { $count=$max } 
  438:     &Apache::lonxml::debug("Count is $count from $max");
  439:     return $count;
  440: }
  441: 
  442: sub whichfoils {
  443:     my ($max,$randomize)=@_;
  444:     return &Apache::response::whichorder($max,$randomize,
  445: 					 &Apache::response::showallfoils(),
  446: 					 \%Apache::response::foilgroup);
  447: }
  448: 
  449: sub start_conceptgroup {
  450:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  451:     $Apache::rankresponse::conceptgroup=1;
  452:     %Apache::response::conceptgroup=();
  453:     my $result;
  454:     if ($target eq 'edit') {
  455: 	$result.=&Apache::edit::tag_start($target,$token,
  456: 					  "Concept Grouped Foils");
  457: 	$result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
  458: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row();
  459:     }
  460:     if ($target eq 'modified') {
  461: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  462: 						     $safeeval,'concept');
  463: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  464:     }
  465:     return $result;
  466: }
  467: 
  468: sub end_conceptgroup {
  469:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  470:     $Apache::rankresponse::conceptgroup=0;
  471:     my $result='';
  472:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  473: 	$target eq 'tex' || $target eq 'analyze') {
  474: 	#if not there aren't any foils to display and thus no question
  475: 	&Apache::response::pick_foil_for_concept($target,
  476: 						 ['value','text','location'],
  477: 						 \%Apache::hint::rank,
  478: 						 $parstack,$safeeval);
  479:     } elsif ($target eq 'edit') {
  480: 	$result=&Apache::edit::end_table();
  481:     }
  482:     return $result;
  483: }
  484: 
  485: sub insert_conceptgroup {
  486:     my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
  487:     return $result;
  488: }
  489: 
  490: sub start_foil {
  491:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  492:     my $result='';
  493:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
  494: 	&Apache::lonxml::startredirection;
  495: 	if ($target eq 'analyze') {
  496: 	    &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
  497: 	}
  498:     } elsif ($target eq 'edit') {
  499: 	$result=&Apache::edit::tag_start($target,$token,"Foil");
  500: 	my $level='-2';
  501: 	if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
  502: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
  503: 	$result.= &Apache::edit::text_arg('Rank Value:','value',$token,'15');
  504: 	my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
  505: 						 $safeeval,'-3');
  506: 	if ($randomize ne 'no') {
  507: 	    $result.=&Apache::edit::select_arg('Location:','location',
  508: 					     ['random','top','bottom'],$token);
  509: 	}
  510: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  511:     } elsif ($target eq 'modified') {
  512: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  513: 						     $safeeval,'value',
  514: 						     'name','location');
  515: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  516:     }
  517:     return $result;
  518: }
  519: 
  520: sub end_foil {
  521:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  522:     my $text ='';
  523:     my $result = '';
  524:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
  525: 	$text=&Apache::lonxml::endredirection;
  526:     }
  527:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  528: 	$target eq 'tex' || $target eq 'analyze') {
  529: 	my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
  530: 	if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
  531: 	    $text='\vskip 5mm $\triangleright$ '.$text;
  532: 	}
  533: 	if ($value ne 'unused') {
  534: 	    my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  535: 	    &Apache::lonxml::debug("Got a name of :$name:");
  536: 	    if ($name eq "") {
  537: 		&Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
  538: 		$name=$Apache::lonxml::curdepth;
  539: 	    }
  540: 	    &Apache::lonxml::debug("Using a name of :$name:");
  541: 	    if (defined($Apache::response::foilnames{$name})) {
  542: 		&Apache::lonxml::error(&mt('Foil name [_1] appears more than once. Foil names need to be unique.','<b><tt>'.$name.'</tt></b>'));
  543: 	    }
  544: 	    $Apache::response::foilnames{$name}++;
  545: 	    my $location =&Apache::lonxml::get_param('location',$parstack,
  546: 						     $safeeval);
  547: 	    if ( $Apache::rankresponse::conceptgroup
  548: 		 && !&Apache::response::showallfoils() ) {
  549: 		push @{ $Apache::response::conceptgroup{'names'} }, $name;
  550: 		$Apache::response::conceptgroup{"$name.value"} = $value;
  551: 		$Apache::response::conceptgroup{"$name.text"} = $text;
  552: 		$Apache::response::conceptgroup{"$name.location"} = $location;
  553: 	    } else {
  554: 		push @{ $Apache::response::foilgroup{'names'} }, $name;
  555: 		$Apache::response::foilgroup{"$name.value"} = $value;
  556: 		$Apache::response::foilgroup{"$name.text"} = $text;
  557: 		$Apache::response::foilgroup{"$name.location"} = $location;
  558: 	    }
  559: 	}
  560:     }
  561:     if ($target eq 'edit') {
  562: 	$result.= &Apache::edit::tag_end($target,$token,'');
  563:     }
  564:     return $result;
  565: }
  566: 
  567: sub insert_foil {
  568:     return '
  569: <foil name="" value="unused">
  570: <startouttext />
  571: <endouttext />
  572: </foil>';
  573: }
  574: 1;
  575: __END__

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