Annotation of loncom/homework/radiobuttonresponse.pm, revision 1.95
1.22 albertel 1: # The LearningOnline Network with CAPA
2: # mutliple choice style responses
1.31 albertel 3: #
1.95 ! albertel 4: # $Id: radiobuttonresponse.pm,v 1.94 2004/10/04 17:41:01 matthew Exp $
1.31 albertel 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: #
1.1 albertel 28:
29: package Apache::radiobuttonresponse;
30: use strict;
1.42 albertel 31: use HTML::Entities();
1.85 albertel 32: use Apache::lonlocal;
1.1 albertel 33:
1.36 harris41 34: BEGIN {
1.83 albertel 35: &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
1.1 albertel 36: }
37:
38: sub start_radiobuttonresponse {
1.83 albertel 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=();
1.85 albertel 46: undef(%Apache::response::foilnames);
1.83 albertel 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}.}';
1.88 albertel 80: } else {
81: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
1.83 albertel 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;
1.1 albertel 89: }
90:
91: sub end_radiobuttonresponse {
1.83 albertel 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'));
1.85 albertel 99: undef(%Apache::response::foilnames);
1.83 albertel 100: return $result;
1.1 albertel 101: }
102:
1.43 albertel 103: %Apache::response::foilgroup=();
1.1 albertel 104: sub start_foilgroup {
1.83 albertel 105: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
106: my $result;
107: %Apache::response::foilgroup=();
108: $Apache::radiobuttonresponse::conceptgroup=0;
1.89 albertel 109: &Apache::response::pushrandomnumber();
1.83 albertel 110: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
111: $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
112: }
113: return $result;
1.5 albertel 114: }
115:
1.15 albertel 116: sub storesurvey {
1.83 albertel 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 '';
1.15 albertel 129: }
130:
1.32 albertel 131: sub grade_response {
1.83 albertel 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);
1.32 albertel 161: }
162:
1.1 albertel 163: sub end_foilgroup {
1.83 albertel 164: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.29 albertel 165:
1.83 albertel 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;
1.93 albertel 170: my $direction = &Apache::lonxml::get_param('direction',$parstack,
171: $safeeval,'-2');
1.83 albertel 172: if ( $style eq 'survey' && $target ne 'analyze') {
173: if ($target eq 'web' || $target eq 'tex') {
1.93 albertel 174: $result=&displayallfoils($direction);
1.83 albertel 175: } elsif ( $target eq 'answer' ) {
176: $result=&displayallanswers();
177: } elsif ( $target eq 'grade' ) {
178: $result=&storesurvey();
179: }
180: } else {
181: my $name;
182: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,
183: '-2');
184: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
185: $safeeval,'-2');
186: if ($target eq 'web' || $target eq 'tex') {
1.90 albertel 187: $result=&displayfoils($target,$max,$randomize,$direction);
1.83 albertel 188: } elsif ($target eq 'answer' ) {
189: $result=&displayanswers($max,$randomize);
190: } elsif ( $target eq 'grade') {
191: &grade_response($max,$randomize);
192: } elsif ( $target eq 'analyze') {
193: my @shown = &whichfoils($max,$randomize);
194: &Apache::response::analyze_store_foilgroup(\@shown,
195: ['text','value','location']);
196: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
197: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },
198: ('true','false'));
199: }
1.81 albertel 200: }
1.83 albertel 201: }
1.89 albertel 202: &Apache::response::poprandomnumber();
1.83 albertel 203: &Apache::lonxml::increment_counter();
204: return $result;
1.6 albertel 205: }
206:
207: sub getfoilcounts {
1.83 albertel 208: my @names;
209: my $truecnt=0;
210: my $falsecnt=0;
211: my $name;
212: if ( $Apache::response::foilgroup{'names'} ) {
213: @names= @{ $Apache::response::foilgroup{'names'} };
1.6 albertel 214: }
1.83 albertel 215: foreach $name (@names) {
216: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
217: $truecnt++;
218: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
219: $falsecnt++;
220: }
221: }
222: return ($truecnt,$falsecnt);
1.5 albertel 223: }
224:
1.15 albertel 225: sub displayallfoils {
1.93 albertel 226: my ($direction)=@_;
1.83 albertel 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"};
1.93 albertel 235: if ($direction eq 'horizontal') { $result.='<table><tr>'; }
1.83 albertel 236: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
237: if (&Apache::response::show_answer() ) {
238: foreach my $name (@names) {
239: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
1.93 albertel 240: if ($direction eq 'horizontal') {
241: $result.="<td>";
242: } else {
243: $result.="<br />";
244: }
1.84 albertel 245: if (defined($lastresponse{$name})) {
1.83 albertel 246: $result.='<b>';
247: }
248: $result .= $Apache::response::foilgroup{$name.'.text'};
1.84 albertel 249: if (defined($lastresponse{$name})) {
1.83 albertel 250: $result.='</b>';
251: }
1.93 albertel 252: if ($direction eq 'horizontal') { $result.="</td>"; }
1.83 albertel 253: }
1.45 albertel 254: }
1.83 albertel 255: } else {
256: foreach my $name (@names) {
257: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
1.93 albertel 258: if ($direction eq 'horizontal') {
259: $result.="<td>";
260: } else {
261: $result.="<br />";
262: }
1.94 matthew 263: $result .= '<label>';
1.93 albertel 264: $result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
1.83 albertel 265: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
1.94 matthew 266: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}.
267: '</label>';
1.83 albertel 268: $temp++;
1.93 albertel 269: if ($direction eq 'horizontal') { $result.="</td>"; }
1.83 albertel 270: }
1.45 albertel 271: }
272: }
1.93 albertel 273: if ($direction eq 'horizontal') { $result.='</tr></table>'; }
1.83 albertel 274: return $result;
1.15 albertel 275: }
276:
1.28 albertel 277: sub whichfoils {
1.83 albertel 278: my ($max,$randomize)=@_;
1.28 albertel 279:
1.83 albertel 280: my @truelist;
281: my @falselist;
282: my @whichfalse =();
283: my ($truecnt,$falsecnt) = &getfoilcounts();
284: my $count=0;
285: # we will add in 1 of the true statements
286: if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
287: my $answer=int(&Math::Random::random_uniform() * ($count));
288: &Apache::lonxml::debug("Count is $count, $answer is $answer");
289: my @names;
290: if ( $Apache::response::foilgroup{'names'} ) {
291: @names= @{ $Apache::response::foilgroup{'names'} };
292: }
293: if (&Apache::response::showallfoils()) {
294: @whichfalse=@names;
295: } elsif ($randomize eq 'no') {
296: &Apache::lonxml::debug("No randomization");
297: my $havetrue=0;
298: foreach my $name (@names) {
299: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
300: if (!$havetrue ) {
301: push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
302: }
303: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
304: push (@whichfalse,$name);
305: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
306: } else {
1.87 albertel 307: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
1.83 albertel 308: }
309: }
310: } else {
311: my $current=0;
312: &Apache::lonhomework::showhash(%Apache::response::foilgroup);
313: my (%top,%bottom);
314: #first find out where everyone wants to be
315: foreach my $name (@names) {
316: $current++;
317: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
318: push (@truelist,$name);
319: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
320: $top{$name}=$current;
321: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
322: $bottom{$name}=$current;
323: }
324: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
325: push (@falselist,$name);
326: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
327: $top{$name}=$current;
328: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
329: $bottom{$name}=$current;
330: }
331: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
332: } else {
1.87 albertel 333: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
1.83 albertel 334: }
335: }
336: #pick a true statement
337: my $notrue=0;
338: if (scalar(@truelist) == 0) { $notrue=1; }
339: my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
340: &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
341: my (@toplist, @bottomlist);
342: my $topcount=0;
343: my $bottomcount=0;
344: # assign everyone to either toplist/bottomlist or whichfalse
345: # which false is randomized, toplist bottomlist are in order
346: while ((($#whichfalse+$topcount+$bottomcount) < $max-2) && ($#falselist > -1)) {
347: &Apache::lonxml::debug("Have $#whichfalse max is $max");
348: my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
349: &Apache::lonxml::debug("From $#falselist elms, picking $afalse");
350: $afalse=splice(@falselist,$afalse,1);
351: &Apache::lonxml::debug("Picked $afalse");
352: &Apache::lonhomework::showhash(('names'=>\@names));
353: &Apache::lonhomework::showhash(%top);
354: if ($top{$afalse}) {
355: $toplist[$top{$afalse}]=$afalse;
356: $topcount++;
357: } elsif ($bottom{$afalse}) {
358: $bottomlist[$bottom{$afalse}]=$afalse;
359: $bottomcount++;
360: } else {
361: push (@whichfalse,$afalse);
362: }
363: }
364: &Apache::lonxml::debug("Answer wants $answer");
365: my $truename=$truelist[$whichtrue];
366: my $dosplice=1;
367: if ($notrue && $Apache::lonhomework::type ne 'survey') {
368: $dosplice=0;
369: &Apache::lonxml::error("There are no true statements available.<br />");
370: }
371: #insert the true statement, keeping track of where it wants to be
372: if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
373: $toplist[$top{$truename}]=$truename;
374: $answer=-1;
375: foreach my $top (reverse(@toplist)) {
376: if ($top) { $answer++;}
377: if ($top eq $truename) { last; }
1.49 albertel 378: }
1.83 albertel 379: $dosplice=0;
380: } elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom' && $dosplice) {
381: $bottomlist[$bottom{$truename}]=$truename;
382: $answer=-1;
383: foreach my $bot (@bottomlist) {
384: if ($bot) { $answer++;}
385: if ($bot eq $truename) { last; }
1.49 albertel 386: }
1.83 albertel 387: $answer+=$topcount+$#whichfalse+1;
388: $dosplice=0;
1.49 albertel 389: } else {
1.83 albertel 390: if ($topcount>0 || $bottomcount>0) {
391: $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
392: + $topcount;
393: }
394: }
395: &Apache::lonxml::debug("Answer now wants $answer");
396: #add the top items to the top, bottom items to the bottom
397: for (my $i=0;$i<=$#toplist;$i++) {
398: if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
1.49 albertel 399: }
1.83 albertel 400: for (my $i=0;$i<=$#bottomlist;$i++) {
401: if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
1.49 albertel 402: }
1.83 albertel 403: #if the true statement is randomized insert it into the list
404: if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
1.49 albertel 405: }
1.83 albertel 406: &Apache::lonxml::debug("Answer is $answer");
407: return ($answer,@whichfalse);
1.28 albertel 408: }
409:
410: sub displayfoils {
1.90 albertel 411: my ($target,$max,$randomize,$direction)=@_;
1.83 albertel 412: my $result;
1.28 albertel 413:
1.83 albertel 414: my ($answer,@whichfoils)=&whichfoils($max,$randomize);
1.22 albertel 415: my $part=$Apache::inputtags::part;
1.83 albertel 416: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
417: if ( ($target ne 'tex') &&
418: &Apache::response::show_answer() ) {
1.90 albertel 419: if ($direction eq 'horizontal') {
420: if ($target ne 'tex') {
421: $result.='<table><tr>';
422: }
423: }
1.83 albertel 424: foreach my $name (@whichfoils) {
1.90 albertel 425: if ($direction eq 'horizontal') {
426: if ($target ne 'tex') { $result.='<td>'; }
427: }
1.83 albertel 428: if ($target ne 'tex') {
429: $result.="<br />";
430: } else {
431: $result.='\item \vskip -2 mm ';
432: }
433: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
434: if ($target ne 'tex') { $result.='Correct:<b>'; } else { $result.='Correct: \textbf{';}
435: } else {
436: $result.='Incorrect:';
437: }
1.94 matthew 438: if ($target eq 'web') { $result.="<label>"; }
1.90 albertel 439: $result.=$Apache::response::foilgroup{$name.'.text'};
1.94 matthew 440: if ($target eq 'web') { $result.="</label>"; }
1.83 albertel 441: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
442: if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
443: }
1.90 albertel 444: if ($direction eq 'horizontal') {
445: if ($target ne 'tex') { $result.='</td>'; }
446: }
447: }
448: if ($direction eq 'horizontal') {
449: if ($target ne 'tex') {
450: $result.='</tr></table>';
451: }
1.83 albertel 452: }
453: } else {
454: my @alphabet = ('A'..'Z');
455: my $i = 0;
456: my $temp=0;
457: my $id=$Apache::inputtags::response['-1'];
458: my $part=$Apache::inputtags::part;
459: my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
460: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
1.90 albertel 461: if ($target ne 'tex' && $direction eq 'horizontal') {
462: $result.="<table><tr>";
463: }
1.83 albertel 464: foreach my $name (@whichfoils) {
465: if ($target ne 'tex') {
1.90 albertel 466: if ($direction eq 'horizontal') {
467: $result.="<td>";
468: } else {
469: $result.="<br />";
470: }
471: }
472: if ($target ne 'tex') {
1.94 matthew 473: $result.= '<label>';
1.90 albertel 474: $result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
1.83 albertel 475: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
1.94 matthew 476: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</label>";
1.83 albertel 477: } else {
478: if ($Apache::lonhomework::type eq 'exam') {
479: $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
480: $i++;
481: } else {
482: $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
483: }
484: }
1.90 albertel 485: if ($target ne 'tex' && $direction eq 'horizontal') {
486: $result.="</td>";
487: }
1.83 albertel 488: $temp++;
489: }
1.90 albertel 490: if ($target ne 'tex' && $direction eq 'horizontal') {
491: $result.="</tr></table>";
492: }
1.83 albertel 493: }
1.92 albertel 494: if ($target ne 'tex') { if ($direction ne 'horizontal') { $result.="<br />";} } else { $result.='\vskip 0 mm '; }
1.83 albertel 495: return $result;
1.81 albertel 496: }
497:
498: sub displayallanswers {
499: my @names = @{ $Apache::response::foilgroup{'names'} };
500:
501: my $result=&Apache::response::answer_header('radiobuttonresponse');
502: foreach my $name (@names) {
503: $result.=&Apache::response::answer_part('radiobuttonresponse',
504: $Apache::response::foilgroup{$name.'.value'});
505: }
506: $result.=&Apache::response::answer_footer('radiobuttonresponse');
507: return $result;
1.14 albertel 508: }
509:
1.28 albertel 510: sub displayanswers {
1.83 albertel 511: my ($max,$randomize)=@_;
512: my ($answer,@whichopt) = &whichfoils($max,$randomize);
513: my $result=&Apache::response::answer_header('radiobuttonresponse');
514: foreach my $name (@whichopt) {
515: $result.=&Apache::response::answer_part('radiobuttonresponse',
516: $Apache::response::foilgroup{$name.'.value'})
517: }
518: $result.=&Apache::response::answer_footer('radiobuttonresponse');
519: return $result;
1.28 albertel 520: }
521:
1.14 albertel 522: sub start_conceptgroup {
1.83 albertel 523: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
524: $Apache::radiobuttonresponse::conceptgroup=1;
525: %Apache::response::conceptgroup=();
526: my $result;
527: if ($target eq 'edit') {
528: $result.=&Apache::edit::tag_start($target,$token);
529: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
530: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
531: } elsif ($target eq 'modified') {
532: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
533: $safeeval,'concept');
534: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
535: }
536: return $result;
1.14 albertel 537: }
538:
539: sub end_conceptgroup {
1.83 albertel 540: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
541: $Apache::radiobuttonresponse::conceptgroup=0;
542: my $result;
543: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
544: $target eq 'tex' || $target eq 'analyze') {
545: &Apache::response::pick_foil_for_concept($target,
546: ['value','text','location'],
547: \%Apache::hint::radiobutton,
548: $parstack,$safeeval);
549: } elsif ($target eq 'edit') {
550: $result=&Apache::edit::end_table();
551: }
552: return $result;
1.26 albertel 553: }
554:
555: sub insert_conceptgroup {
1.83 albertel 556: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
557: return $result;
1.1 albertel 558: }
559:
560: sub start_foil {
1.83 albertel 561: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
562: my $result='';
563: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
564: &Apache::lonxml::startredirection;
1.95 ! albertel 565: if ($target eq 'analyze') {
! 566: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
! 567: }
1.83 albertel 568: } elsif ($target eq 'edit') {
569: $result=&Apache::edit::tag_start($target,$token);
570: $result.=&Apache::edit::text_arg('Name:','name',$token);
571: $result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
572: ['unused','true','false'],
573: $token);
574: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
575: $safeeval,'-3');
576: if ($randomize ne 'no') {
577: $result.=&Apache::edit::select_arg('Location:','location',
578: ['random','top','bottom'],$token);
579: }
580: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
581: } elsif ($target eq 'modified') {
582: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
583: $safeeval,'value','name',
584: 'location');
585: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
586: }
587: return $result;
1.1 albertel 588: }
589:
590: sub end_foil {
1.83 albertel 591: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
592: my $text='';
593: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
594: $text=&Apache::lonxml::endredirection;
595: }
1.85 albertel 596: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
597: || $target eq 'tex' || $target eq 'analyze') {
1.83 albertel 598: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
599: if ($value ne 'unused') {
600: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
601: if (!$name) { $name=$Apache::lonxml::curdepth; }
1.85 albertel 602: if (defined($Apache::response::foilnames{$name})) {
603: &Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
604: }
1.86 albertel 605: $Apache::response::foilnames{$name}++;
1.85 albertel 606: my $location =&Apache::lonxml::get_param('location',$parstack,
607: $safeeval);
1.83 albertel 608: if ( $Apache::radiobuttonresponse::conceptgroup
609: && !&Apache::response::showallfoils() ) {
610: push @{ $Apache::response::conceptgroup{'names'} }, $name;
611: $Apache::response::conceptgroup{"$name.value"} = $value;
612: $Apache::response::conceptgroup{"$name.text"} = $text;
613: $Apache::response::conceptgroup{"$name.location"} = $location;
614: } else {
615: push @{ $Apache::response::foilgroup{'names'} }, $name;
616: $Apache::response::foilgroup{"$name.value"} = $value;
617: $Apache::response::foilgroup{"$name.text"} = $text;
618: $Apache::response::foilgroup{"$name.location"} = $location;
619: }
620: }
1.18 albertel 621: }
1.83 albertel 622: return '';
1.1 albertel 623: }
624:
1.27 albertel 625: sub insert_foil {
1.83 albertel 626: return '
1.27 albertel 627: <foil name="" value="unused">
628: <startouttext />
629: <endouttext />
630: </foil>';
631: }
1.1 albertel 632: 1;
633: __END__
634:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>