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