File:  [LON-CAPA] / loncom / homework / matchresponse.pm
Revision 1.29: download - view: text, annotated - select for diffs
Mon Oct 27 20:04:34 2003 UTC (20 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- took a look at all of the analyze outputs and corrected the buglets

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

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