File:
[LON-CAPA] /
loncom /
homework /
radiobuttonresponse.pm
Revision
1.106:
download - view:
text,
annotated -
select for diffs
Mon Mar 27 21:18:16 2006 UTC (18 years, 5 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_2_X,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
HEAD
- BUG#4716
1: # The LearningOnline Network with CAPA
2: # mutliple choice style responses
3: #
4: # $Id: radiobuttonresponse.pm,v 1.106 2006/03/27 21:18:16 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;
238: if ( $Apache::response::foilgroup{'names'} ) {
239: @names= @{ $Apache::response::foilgroup{'names'} };
240: }
241: my $temp=0;
242: my $id=$Apache::inputtags::response['-1'];
243: my $part=$Apache::inputtags::part;
244: my $lastresponse=
245: $Apache::lonhomework::history{"resource.$part.$id.submission"};
246: if ($direction eq 'horizontal') { $result.='<table><tr>'; }
247: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
248: if (&Apache::response::show_answer() ) {
249: foreach my $name (@names) {
250: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
251: if ($direction eq 'horizontal') {
252: $result.="<td>";
253: } else {
254: $result.="<br />";
255: }
256: if (defined($lastresponse{$name})) {
257: $result.='<b>';
258: }
259: $result .= $Apache::response::foilgroup{$name.'.text'};
260: if (defined($lastresponse{$name})) {
261: $result.='</b>';
262: }
263: if ($direction eq 'horizontal') { $result.="</td>"; }
264: }
265: }
266: } else {
267: foreach my $name (@names) {
268: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
269: if ($direction eq 'horizontal') {
270: $result.="<td>";
271: } else {
272: $result.="<br />";
273: }
274: $result .= '<label>';
275: $result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
276: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
277: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}.
278: '</label>';
279: $temp++;
280: if ($direction eq 'horizontal') { $result.="</td>"; }
281: }
282: }
283: }
284: if ($direction eq 'horizontal') { $result.='</tr></table>'; }
285: return $result;
286: }
287:
288: sub whichfoils {
289: my ($max,$randomize)=@_;
290:
291: my @truelist;
292: my @falselist;
293: my @whichfalse =();
294: my ($truecnt,$falsecnt) = &getfoilcounts();
295: my $count=0;
296: # we will add in 1 of the true statements
297: if ( $max>0 && ($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; $max=$count; }
298: my $answer=int(&Math::Random::random_uniform() * ($count));
299: &Apache::lonxml::debug("Count is $count, $answer is $answer");
300: my @names;
301: if ( $Apache::response::foilgroup{'names'} ) {
302: @names= @{ $Apache::response::foilgroup{'names'} };
303: }
304: if (&Apache::response::showallfoils()) {
305: @whichfalse=@names;
306: } elsif ($randomize eq 'no') {
307: &Apache::lonxml::debug("No randomization");
308: my $havetrue=0;
309: foreach my $name (@names) {
310: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
311: if (!$havetrue ) {
312: push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
313: }
314: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
315: push (@whichfalse,$name);
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: if (!$havetrue && $Apache::lonhomework::type ne 'survey') {
322: &Apache::lonxml::error("There are no true statements available.<br />");
323: }
324: } else {
325: my $current=0;
326: &Apache::lonhomework::showhash(%Apache::response::foilgroup);
327: my (%top,%bottom);
328: #first find out where everyone wants to be
329: foreach my $name (@names) {
330: $current++;
331: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
332: push (@truelist,$name);
333: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
334: $top{$name}=$current;
335: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
336: $bottom{$name}=$current;
337: }
338: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
339: push (@falselist,$name);
340: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
341: $top{$name}=$current;
342: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
343: $bottom{$name}=$current;
344: }
345: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
346: } else {
347: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
348: }
349: }
350: #pick a true statement
351: my $notrue=0;
352: if (scalar(@truelist) == 0) { $notrue=1; }
353: my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
354: &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
355: my (@toplist, @bottomlist);
356: my $topcount=0;
357: my $bottomcount=0;
358: # assign everyone to either toplist/bottomlist or whichfalse
359: # which false is randomized, toplist bottomlist are in order
360: while ((($#whichfalse+$topcount+$bottomcount) < $max-2) && ($#falselist > -1)) {
361: &Apache::lonxml::debug("Have $#whichfalse max is $max");
362: my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
363: &Apache::lonxml::debug("From $#falselist elms, picking $afalse");
364: $afalse=splice(@falselist,$afalse,1);
365: &Apache::lonxml::debug("Picked $afalse");
366: &Apache::lonhomework::showhash(('names'=>\@names));
367: &Apache::lonhomework::showhash(%top);
368: if ($top{$afalse}) {
369: $toplist[$top{$afalse}]=$afalse;
370: $topcount++;
371: } elsif ($bottom{$afalse}) {
372: $bottomlist[$bottom{$afalse}]=$afalse;
373: $bottomcount++;
374: } else {
375: push (@whichfalse,$afalse);
376: }
377: }
378: &Apache::lonxml::debug("Answer wants $answer");
379: my $truename=$truelist[$whichtrue];
380: my $dosplice=1;
381: if ($notrue && $Apache::lonhomework::type ne 'survey') {
382: $dosplice=0;
383: &Apache::lonxml::error("There are no true statements available.<br />");
384: }
385: #insert the true statement, keeping track of where it wants to be
386: if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
387: $toplist[$top{$truename}]=$truename;
388: $answer=-1;
389: foreach my $top (reverse(@toplist)) {
390: if ($top) { $answer++;}
391: if ($top eq $truename) { last; }
392: }
393: $dosplice=0;
394: } elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom' && $dosplice) {
395: $bottomlist[$bottom{$truename}]=$truename;
396: $answer=-1;
397: foreach my $bot (@bottomlist) {
398: if ($bot) { $answer++;}
399: if ($bot eq $truename) { last; }
400: }
401: $answer+=$topcount+$#whichfalse+1;
402: $dosplice=0;
403: } else {
404: if ($topcount>0 || $bottomcount>0) {
405: $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
406: + $topcount;
407: }
408: }
409: &Apache::lonxml::debug("Answer now wants $answer");
410: #add the top items to the top, bottom items to the bottom
411: for (my $i=0;$i<=$#toplist;$i++) {
412: if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
413: }
414: for (my $i=0;$i<=$#bottomlist;$i++) {
415: if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
416: }
417: #if the true statement is randomized insert it into the list
418: if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
419: }
420: &Apache::lonxml::debug("Answer is $answer");
421: return ($answer,@whichfalse);
422: }
423:
424: sub displayfoils {
425: my ($target,$max,$randomize,$direction)=@_;
426: my $result;
427:
428: my ($answer,@whichfoils)=&whichfoils($max,$randomize);
429: my $part=$Apache::inputtags::part;
430: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
431: if ( ($target ne 'tex') &&
432: &Apache::response::show_answer() ) {
433: if ($direction eq 'horizontal') {
434: if ($target ne 'tex') {
435: $result.='<table><tr>';
436: }
437: }
438: foreach my $name (@whichfoils) {
439: if ($direction eq 'horizontal') {
440: if ($target ne 'tex') { $result.='<td>'; }
441: }
442: if ($target ne 'tex') {
443: $result.="<br />";
444: } else {
445: $result.='\item \vskip -2 mm ';
446: }
447: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
448: if ($target ne 'tex') { $result.='Correct:<b>'; } else { $result.='Correct: \textbf{';}
449: } else {
450: $result.='Incorrect:';
451: }
452: if ($target eq 'web') { $result.="<label>"; }
453: $result.=$Apache::response::foilgroup{$name.'.text'};
454: if ($target eq 'web') { $result.="</label>"; }
455: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
456: if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
457: }
458: if ($direction eq 'horizontal') {
459: if ($target ne 'tex') { $result.='</td>'; }
460: }
461: }
462: if ($direction eq 'horizontal') {
463: if ($target ne 'tex') {
464: $result.='</tr></table>';
465: }
466: }
467: } else {
468: my @alphabet = ('A'..'Z');
469: my $i = 0;
470: my $temp=0;
471: my $id=$Apache::inputtags::response['-1'];
472: my $part=$Apache::inputtags::part;
473: my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
474: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
475: if ($target ne 'tex' && $direction eq 'horizontal') {
476: $result.="<table><tr>";
477: }
478: foreach my $name (@whichfoils) {
479: if ($target ne 'tex') {
480: if ($direction eq 'horizontal') {
481: $result.="<td>";
482: } else {
483: $result.="<br />";
484: }
485: }
486: if ($target ne 'tex') {
487: $result.= '<label>';
488: $result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
489: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
490: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</label>";
491: } else {
492: if ($Apache::lonhomework::type eq 'exam') {
493: $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
494: $i++;
495: } else {
496: $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
497: }
498: }
499: if ($target ne 'tex' && $direction eq 'horizontal') {
500: $result.="</td>";
501: }
502: $temp++;
503: }
504: if ($target ne 'tex' && $direction eq 'horizontal') {
505: $result.="</tr></table>";
506: }
507: }
508: if ($target ne 'tex') { if ($direction ne 'horizontal') { $result.="<br />";} } else { $result.='\vskip 0 mm '; }
509: return $result;
510: }
511:
512: sub displayallanswers {
513: my @names;
514: if ( $Apache::response::foilgroup{'names'} ) {
515: @names= @{ $Apache::response::foilgroup{'names'} };
516: }
517:
518: my $result=&Apache::response::answer_header('radiobuttonresponse');
519: foreach my $name (@names) {
520: $result.=&Apache::response::answer_part('radiobuttonresponse',
521: $Apache::response::foilgroup{$name.'.value'});
522: }
523: $result.=&Apache::response::answer_footer('radiobuttonresponse');
524: return $result;
525: }
526:
527: sub displayanswers {
528: my ($max,$randomize)=@_;
529: my ($answer,@whichopt) = &whichfoils($max,$randomize);
530: my $result=&Apache::response::answer_header('radiobuttonresponse');
531: if ($Apache::lonhomework::type eq 'exam') {
532: my $correct = ('A'..'Z')[$answer];
533: $result.=&Apache::response::answer_part('radiobuttonresponse',
534: $correct);
535: }
536: foreach my $name (@whichopt) {
537: $result.=&Apache::response::answer_part('radiobuttonresponse',
538: $Apache::response::foilgroup{$name.'.value'});
539: }
540: $result.=&Apache::response::answer_footer('radiobuttonresponse');
541: return $result;
542: }
543:
544: sub start_conceptgroup {
545: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
546: $Apache::radiobuttonresponse::conceptgroup=1;
547: %Apache::response::conceptgroup=();
548: my $result;
549: if ($target eq 'edit') {
550: $result.=&Apache::edit::tag_start($target,$token);
551: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
552: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
553: } elsif ($target eq 'modified') {
554: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
555: $safeeval,'concept');
556: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
557: }
558: return $result;
559: }
560:
561: sub end_conceptgroup {
562: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
563: $Apache::radiobuttonresponse::conceptgroup=0;
564: my $result;
565: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
566: $target eq 'tex' || $target eq 'analyze') {
567: &Apache::response::pick_foil_for_concept($target,
568: ['value','text','location'],
569: \%Apache::hint::radiobutton,
570: $parstack,$safeeval);
571: } elsif ($target eq 'edit') {
572: $result=&Apache::edit::end_table();
573: }
574: return $result;
575: }
576:
577: sub insert_conceptgroup {
578: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
579: return $result;
580: }
581:
582: sub start_foil {
583: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
584: my $result='';
585: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
586: &Apache::lonxml::startredirection;
587: if ($target eq 'analyze') {
588: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
589: }
590: } elsif ($target eq 'edit') {
591: $result=&Apache::edit::tag_start($target,$token);
592: $result.=&Apache::edit::text_arg('Name:','name',$token);
593: $result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
594: ['unused','true','false'],
595: $token);
596: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
597: $safeeval,'-3');
598: if ($randomize ne 'no') {
599: $result.=&Apache::edit::select_arg('Location:','location',
600: ['random','top','bottom'],$token);
601: }
602: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
603: } elsif ($target eq 'modified') {
604: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
605: $safeeval,'value','name',
606: 'location');
607: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
608: }
609: return $result;
610: }
611:
612: sub end_foil {
613: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
614: my $text='';
615: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
616: $text=&Apache::lonxml::endredirection;
617: }
618: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
619: || $target eq 'tex' || $target eq 'analyze') {
620: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
621: if ($value ne 'unused') {
622: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
623: if ($name eq "") {
624: &Apache::lonxml::warning("Foils without names exist. This can cause problems to malfunction.");
625: $name=$Apache::lonxml::curdepth;
626: }
627: if (defined($Apache::response::foilnames{$name})) {
628: &Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
629: }
630: $Apache::response::foilnames{$name}++;
631: my $location =&Apache::lonxml::get_param('location',$parstack,
632: $safeeval);
633: if ( $Apache::radiobuttonresponse::conceptgroup
634: && !&Apache::response::showallfoils() ) {
635: push @{ $Apache::response::conceptgroup{'names'} }, $name;
636: $Apache::response::conceptgroup{"$name.value"} = $value;
637: $Apache::response::conceptgroup{"$name.text"} = $text;
638: $Apache::response::conceptgroup{"$name.location"} = $location;
639: } else {
640: push @{ $Apache::response::foilgroup{'names'} }, $name;
641: $Apache::response::foilgroup{"$name.value"} = $value;
642: $Apache::response::foilgroup{"$name.text"} = $text;
643: $Apache::response::foilgroup{"$name.location"} = $location;
644: }
645: }
646: }
647: return '';
648: }
649:
650: sub insert_foil {
651: return '
652: <foil name="" value="unused">
653: <startouttext />
654: <endouttext />
655: </foil>';
656: }
657: 1;
658: __END__
659:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>