1: # The LearningOnline Network with CAPA
2: # mutliple choice style responses
3: #
4: # $Id: radiobuttonresponse.pm,v 1.90 2004/08/24 23:32:13 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::radiobuttonresponse;
30: use strict;
31: use HTML::Entities();
32: use Apache::lonlocal;
33:
34: BEGIN {
35: &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
36: }
37:
38: sub start_radiobuttonresponse {
39: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
40: my $result;
41: #when in a radiobutton response use these
42: &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
43: push (@Apache::lonxml::namespace,'radiobuttonresponse');
44: my $id = &Apache::response::start_response($parstack,$safeeval);
45: %Apache::hint::radiobutton=();
46: undef(%Apache::response::foilnames);
47: if ($target eq 'meta') {
48: $result=&Apache::response::meta_package_write('radiobuttonresponse');
49: } elsif ($target eq 'edit' ) {
50: $result.=&Apache::edit::start_table($token).
51: '<tr><td>'.&Apache::lonxml::description($token).
52: &Apache::loncommon::help_open_topic('Radio_Response_Problems').
53: "</td><td>Delete:".
54: &Apache::edit::deletelist($target,$token)
55: ."</td><td> ".&Apache::edit::end_row()
56: .&Apache::edit::start_spanning_row();
57: $result.=
58: &Apache::edit::text_arg('Max Number Of Shown Foils:','max',
59: $token,'4').
60: &Apache::edit::select_arg('Randomize Foil Order','randomize',
61: ['yes','no'],$token).
62: &Apache::edit::end_row().
63: &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); }
69: } elsif ($target eq 'tex') {
70: my $type=&Apache::lonxml::get_param('TeXtype',$parstack,$safeeval,
71: undef,0);
72: if ($type eq '1') {
73: $result .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}';
74: } elsif ($type eq 'A') {
75: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
76: } elsif ($type eq 'a') {
77: $result .= ' \renewcommand{\labelenumi}{\alph{enumi}.}';
78: } elsif ($type eq 'i') {
79: $result .= ' \renewcommand{\labelenumi}{\roman{enumi}.}';
80: } else {
81: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
82: }
83: $result .= '\begin{enumerate}';
84: } elsif ($target eq 'analyze') {
85: my $part_id="$Apache::inputtags::part.$id";
86: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
87: }
88: return $result;
89: }
90:
91: sub end_radiobuttonresponse {
92: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
93: my $result;
94: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
95: if ($target eq 'tex') { $result .= '\end{enumerate}'; }
96: &Apache::response::end_response;
97: pop @Apache::lonxml::namespace;
98: &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
99: undef(%Apache::response::foilnames);
100: return $result;
101: }
102:
103: %Apache::response::foilgroup=();
104: sub start_foilgroup {
105: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
106: my $result;
107: %Apache::response::foilgroup=();
108: $Apache::radiobuttonresponse::conceptgroup=0;
109: &Apache::response::pushrandomnumber();
110: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
111: $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
112: }
113: return $result;
114: }
115:
116: sub storesurvey {
117: if ( !defined($ENV{'form.submitted'})) { return ''; }
118: my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1']};
119: &Apache::lonxml::debug("Here I am!:$response:");
120: if ( $response !~ /[0-9]+/) { return ''; }
121: my $id = $Apache::inputtags::response['-1'];
122: my @whichfoils=@{ $Apache::response::foilgroup{'names'} };
123: my %responsehash;
124: $responsehash{$whichfoils[$response]}=$response;
125: $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=&Apache::lonnet::hash2str(%responsehash);
126: $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='SUBMITTED';
127: &Apache::lonxml::debug("submitted a $response<br />\n");
128: return '';
129: }
130:
131: sub grade_response {
132: my ($max,$randomize)=@_;
133: #keep the random numbers the same must always call this
134: my ($answer,@whichfoils)=&whichfoils($max,$randomize);
135: if (!defined($ENV{'form.submitted'})) { return; }
136: my $response;
137: if ($ENV{'form.submitted'} eq 'scantron') {
138: $response=&Apache::response::getresponse();
139: } else {
140: $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1']};
141: }
142: if ( $response !~ /[0-9]+/) { return; }
143: my $part=$Apache::inputtags::part;
144: my $id = $Apache::inputtags::response['-1'];
145: my %responsehash;
146: $responsehash{$whichfoils[$response]}=$response;
147: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
148: my %previous=&Apache::response::check_for_previous($responsestr,
149: $part,$id);
150: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
151: $responsestr;
152: &Apache::lonxml::debug("submitted a $response<br />\n");
153: my $ad;
154: if ($response == $answer) {
155: $ad='EXACT_ANS';
156: } else {
157: $ad='INCORRECT';
158: }
159: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
160: &Apache::response::handle_previous(\%previous,$ad);
161: }
162:
163: sub end_foilgroup {
164: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
165:
166: my $result;
167: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
168: $target eq 'tex' || $target eq 'analyze') {
169: my $style = $Apache::lonhomework::type;
170: if ( $style eq 'survey' && $target ne 'analyze') {
171: if ($target eq 'web' || $target eq 'tex') {
172: $result=&displayallfoils();
173: } elsif ( $target eq 'answer' ) {
174: $result=&displayallanswers();
175: } elsif ( $target eq 'grade' ) {
176: $result=&storesurvey();
177: }
178: } else {
179: my $name;
180: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,
181: '-2');
182: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
183: $safeeval,'-2');
184: my $direction = &Apache::lonxml::get_param('direction',$parstack,
185: $safeeval,'-2');
186: &Apache::lonxml::debug("direction is $direction");
187: if ($target eq 'web' || $target eq 'tex') {
188: $result=&displayfoils($target,$max,$randomize,$direction);
189: } elsif ($target eq 'answer' ) {
190: $result=&displayanswers($max,$randomize);
191: } elsif ( $target eq 'grade') {
192: &grade_response($max,$randomize);
193: } elsif ( $target eq 'analyze') {
194: my @shown = &whichfoils($max,$randomize);
195: &Apache::response::analyze_store_foilgroup(\@shown,
196: ['text','value','location']);
197: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
198: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },
199: ('true','false'));
200: }
201: }
202: }
203: &Apache::response::poprandomnumber();
204: &Apache::lonxml::increment_counter();
205: return $result;
206: }
207:
208: sub getfoilcounts {
209: my @names;
210: my $truecnt=0;
211: my $falsecnt=0;
212: my $name;
213: if ( $Apache::response::foilgroup{'names'} ) {
214: @names= @{ $Apache::response::foilgroup{'names'} };
215: }
216: foreach $name (@names) {
217: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
218: $truecnt++;
219: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
220: $falsecnt++;
221: }
222: }
223: return ($truecnt,$falsecnt);
224: }
225:
226: sub displayallfoils {
227: my $result;
228: &Apache::lonxml::debug("survey style display");
229: my @names = @{ $Apache::response::foilgroup{'names'} };
230: my $temp=0;
231: my $id=$Apache::inputtags::response['-1'];
232: my $part=$Apache::inputtags::part;
233: my $lastresponse=
234: $Apache::lonhomework::history{"resource.$part.$id.submission"};
235: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
236: if (&Apache::response::show_answer() ) {
237: foreach my $name (@names) {
238: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
239: $result.="<br />";
240: if (defined($lastresponse{$name})) {
241: $result.='<b>';
242: }
243: $result .= $Apache::response::foilgroup{$name.'.text'};
244: if (defined($lastresponse{$name})) {
245: $result.='</b>';
246: }
247: }
248: }
249: } else {
250: foreach my $name (@names) {
251: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
252: $result.="<br /><input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
253: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
254: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
255: $temp++;
256: }
257: }
258: }
259: return $result;
260: }
261:
262: sub whichfoils {
263: my ($max,$randomize)=@_;
264:
265: my @truelist;
266: my @falselist;
267: my @whichfalse =();
268: my ($truecnt,$falsecnt) = &getfoilcounts();
269: my $count=0;
270: # we will add in 1 of the true statements
271: if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
272: my $answer=int(&Math::Random::random_uniform() * ($count));
273: &Apache::lonxml::debug("Count is $count, $answer is $answer");
274: my @names;
275: if ( $Apache::response::foilgroup{'names'} ) {
276: @names= @{ $Apache::response::foilgroup{'names'} };
277: }
278: if (&Apache::response::showallfoils()) {
279: @whichfalse=@names;
280: } elsif ($randomize eq 'no') {
281: &Apache::lonxml::debug("No randomization");
282: my $havetrue=0;
283: foreach my $name (@names) {
284: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
285: if (!$havetrue ) {
286: push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
287: }
288: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
289: push (@whichfalse,$name);
290: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
291: } else {
292: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
293: }
294: }
295: } else {
296: my $current=0;
297: &Apache::lonhomework::showhash(%Apache::response::foilgroup);
298: my (%top,%bottom);
299: #first find out where everyone wants to be
300: foreach my $name (@names) {
301: $current++;
302: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
303: push (@truelist,$name);
304: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
305: $top{$name}=$current;
306: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
307: $bottom{$name}=$current;
308: }
309: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
310: push (@falselist,$name);
311: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
312: $top{$name}=$current;
313: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
314: $bottom{$name}=$current;
315: }
316: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
317: } else {
318: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
319: }
320: }
321: #pick a true statement
322: my $notrue=0;
323: if (scalar(@truelist) == 0) { $notrue=1; }
324: my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
325: &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
326: my (@toplist, @bottomlist);
327: my $topcount=0;
328: my $bottomcount=0;
329: # assign everyone to either toplist/bottomlist or whichfalse
330: # which false is randomized, toplist bottomlist are in order
331: while ((($#whichfalse+$topcount+$bottomcount) < $max-2) && ($#falselist > -1)) {
332: &Apache::lonxml::debug("Have $#whichfalse max is $max");
333: my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
334: &Apache::lonxml::debug("From $#falselist elms, picking $afalse");
335: $afalse=splice(@falselist,$afalse,1);
336: &Apache::lonxml::debug("Picked $afalse");
337: &Apache::lonhomework::showhash(('names'=>\@names));
338: &Apache::lonhomework::showhash(%top);
339: if ($top{$afalse}) {
340: $toplist[$top{$afalse}]=$afalse;
341: $topcount++;
342: } elsif ($bottom{$afalse}) {
343: $bottomlist[$bottom{$afalse}]=$afalse;
344: $bottomcount++;
345: } else {
346: push (@whichfalse,$afalse);
347: }
348: }
349: &Apache::lonxml::debug("Answer wants $answer");
350: my $truename=$truelist[$whichtrue];
351: my $dosplice=1;
352: if ($notrue && $Apache::lonhomework::type ne 'survey') {
353: $dosplice=0;
354: &Apache::lonxml::error("There are no true statements available.<br />");
355: }
356: #insert the true statement, keeping track of where it wants to be
357: if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
358: $toplist[$top{$truename}]=$truename;
359: $answer=-1;
360: foreach my $top (reverse(@toplist)) {
361: if ($top) { $answer++;}
362: if ($top eq $truename) { last; }
363: }
364: $dosplice=0;
365: } elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom' && $dosplice) {
366: $bottomlist[$bottom{$truename}]=$truename;
367: $answer=-1;
368: foreach my $bot (@bottomlist) {
369: if ($bot) { $answer++;}
370: if ($bot eq $truename) { last; }
371: }
372: $answer+=$topcount+$#whichfalse+1;
373: $dosplice=0;
374: } else {
375: if ($topcount>0 || $bottomcount>0) {
376: $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
377: + $topcount;
378: }
379: }
380: &Apache::lonxml::debug("Answer now wants $answer");
381: #add the top items to the top, bottom items to the bottom
382: for (my $i=0;$i<=$#toplist;$i++) {
383: if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
384: }
385: for (my $i=0;$i<=$#bottomlist;$i++) {
386: if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
387: }
388: #if the true statement is randomized insert it into the list
389: if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
390: }
391: &Apache::lonxml::debug("Answer is $answer");
392: return ($answer,@whichfalse);
393: }
394:
395: sub displayfoils {
396: my ($target,$max,$randomize,$direction)=@_;
397: my $result;
398:
399: my ($answer,@whichfoils)=&whichfoils($max,$randomize);
400: my $part=$Apache::inputtags::part;
401: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
402: if ( ($target ne 'tex') &&
403: &Apache::response::show_answer() ) {
404: if ($direction eq 'horizontal') {
405: if ($target ne 'tex') {
406: $result.='<table><tr>';
407: }
408: }
409: foreach my $name (@whichfoils) {
410: if ($direction eq 'horizontal') {
411: if ($target ne 'tex') { $result.='<td>'; }
412: }
413: if ($target ne 'tex') {
414: $result.="<br />";
415: } else {
416: $result.='\item \vskip -2 mm ';
417: }
418: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
419: if ($target ne 'tex') { $result.='Correct:<b>'; } else { $result.='Correct: \textbf{';}
420: } else {
421: $result.='Incorrect:';
422: }
423: $result.=$Apache::response::foilgroup{$name.'.text'};
424: if ($target eq 'web') { $result.="</input>\n"; }
425: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
426: if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
427: }
428: if ($direction eq 'horizontal') {
429: if ($target ne 'tex') { $result.='</td>'; }
430: }
431: }
432: if ($direction eq 'horizontal') {
433: if ($target ne 'tex') {
434: $result.='</tr></table>';
435: }
436: }
437: } else {
438: my @alphabet = ('A'..'Z');
439: my $i = 0;
440: my $temp=0;
441: my $id=$Apache::inputtags::response['-1'];
442: my $part=$Apache::inputtags::part;
443: my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
444: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
445: if ($target ne 'tex' && $direction eq 'horizontal') {
446: $result.="<table><tr>";
447: }
448: foreach my $name (@whichfoils) {
449: if ($target ne 'tex') {
450: if ($direction eq 'horizontal') {
451: $result.="<td>";
452: } else {
453: $result.="<br />";
454: }
455: }
456: if ($target ne 'tex') {
457: $result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
458: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
459: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
460: } else {
461: if ($Apache::lonhomework::type eq 'exam') {
462: $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
463: $i++;
464: } else {
465: $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
466: }
467: }
468: if ($target ne 'tex' && $direction eq 'horizontal') {
469: $result.="</td>";
470: }
471: $temp++;
472: }
473: if ($target ne 'tex' && $direction eq 'horizontal') {
474: $result.="</tr></table>";
475: }
476: }
477: if ($target ne 'tex') { $result.="<br />"; } else { $result.='\vskip 0 mm '; }
478: return $result;
479: }
480:
481: sub displayallanswers {
482: my @names = @{ $Apache::response::foilgroup{'names'} };
483:
484: my $result=&Apache::response::answer_header('radiobuttonresponse');
485: foreach my $name (@names) {
486: $result.=&Apache::response::answer_part('radiobuttonresponse',
487: $Apache::response::foilgroup{$name.'.value'});
488: }
489: $result.=&Apache::response::answer_footer('radiobuttonresponse');
490: return $result;
491: }
492:
493: sub displayanswers {
494: my ($max,$randomize)=@_;
495: my ($answer,@whichopt) = &whichfoils($max,$randomize);
496: my $result=&Apache::response::answer_header('radiobuttonresponse');
497: foreach my $name (@whichopt) {
498: $result.=&Apache::response::answer_part('radiobuttonresponse',
499: $Apache::response::foilgroup{$name.'.value'})
500: }
501: $result.=&Apache::response::answer_footer('radiobuttonresponse');
502: return $result;
503: }
504:
505: sub start_conceptgroup {
506: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
507: $Apache::radiobuttonresponse::conceptgroup=1;
508: %Apache::response::conceptgroup=();
509: my $result;
510: if ($target eq 'edit') {
511: $result.=&Apache::edit::tag_start($target,$token);
512: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
513: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
514: } elsif ($target eq 'modified') {
515: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
516: $safeeval,'concept');
517: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
518: }
519: return $result;
520: }
521:
522: sub end_conceptgroup {
523: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
524: $Apache::radiobuttonresponse::conceptgroup=0;
525: my $result;
526: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
527: $target eq 'tex' || $target eq 'analyze') {
528: &Apache::response::pick_foil_for_concept($target,
529: ['value','text','location'],
530: \%Apache::hint::radiobutton,
531: $parstack,$safeeval);
532: } elsif ($target eq 'edit') {
533: $result=&Apache::edit::end_table();
534: }
535: return $result;
536: }
537:
538: sub insert_conceptgroup {
539: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
540: return $result;
541: }
542:
543: sub start_foil {
544: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
545: my $result='';
546: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
547: &Apache::lonxml::startredirection;
548: } elsif ($target eq 'edit') {
549: $result=&Apache::edit::tag_start($target,$token);
550: $result.=&Apache::edit::text_arg('Name:','name',$token);
551: $result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
552: ['unused','true','false'],
553: $token);
554: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
555: $safeeval,'-3');
556: if ($randomize ne 'no') {
557: $result.=&Apache::edit::select_arg('Location:','location',
558: ['random','top','bottom'],$token);
559: }
560: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
561: } elsif ($target eq 'modified') {
562: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
563: $safeeval,'value','name',
564: 'location');
565: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
566: }
567: return $result;
568: }
569:
570: sub end_foil {
571: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
572: my $text='';
573: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
574: $text=&Apache::lonxml::endredirection;
575: }
576: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
577: || $target eq 'tex' || $target eq 'analyze') {
578: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
579: if ($value ne 'unused') {
580: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
581: if (!$name) { $name=$Apache::lonxml::curdepth; }
582: if (defined($Apache::response::foilnames{$name})) {
583: &Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
584: }
585: $Apache::response::foilnames{$name}++;
586: my $location =&Apache::lonxml::get_param('location',$parstack,
587: $safeeval);
588: if ( $Apache::radiobuttonresponse::conceptgroup
589: && !&Apache::response::showallfoils() ) {
590: push @{ $Apache::response::conceptgroup{'names'} }, $name;
591: $Apache::response::conceptgroup{"$name.value"} = $value;
592: $Apache::response::conceptgroup{"$name.text"} = $text;
593: $Apache::response::conceptgroup{"$name.location"} = $location;
594: } else {
595: push @{ $Apache::response::foilgroup{'names'} }, $name;
596: $Apache::response::foilgroup{"$name.value"} = $value;
597: $Apache::response::foilgroup{"$name.text"} = $text;
598: $Apache::response::foilgroup{"$name.location"} = $location;
599: }
600: }
601: }
602: return '';
603: }
604:
605: sub insert_foil {
606: return '
607: <foil name="" value="unused">
608: <startouttext />
609: <endouttext />
610: </foil>';
611: }
612: 1;
613: __END__
614:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>