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

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

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