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