Annotation of loncom/homework/radiobuttonresponse.pm, revision 1.106
1.22 albertel 1: # The LearningOnline Network with CAPA
2: # mutliple choice style responses
1.31 albertel 3: #
1.106 ! albertel 4: # $Id: radiobuttonresponse.pm,v 1.105 2005/12/06 10:03:57 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).
1.103 albertel 63: &Apache::edit::select_arg('Display Direction','direction',
64: ['vertical','horizontal'],$token).
1.83 albertel 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',
1.103 albertel 70: 'randomize','direction');
1.83 albertel 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}.}';
1.88 albertel 83: } else {
84: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
1.83 albertel 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;
1.1 albertel 92: }
93:
94: sub end_radiobuttonresponse {
1.83 albertel 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'));
1.85 albertel 102: undef(%Apache::response::foilnames);
1.83 albertel 103: return $result;
1.1 albertel 104: }
105:
1.43 albertel 106: %Apache::response::foilgroup=();
1.1 albertel 107: sub start_foilgroup {
1.83 albertel 108: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
109: my $result;
110: %Apache::response::foilgroup=();
111: $Apache::radiobuttonresponse::conceptgroup=0;
1.89 albertel 112: &Apache::response::pushrandomnumber();
1.83 albertel 113: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
114: $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
115: }
116: return $result;
1.5 albertel 117: }
118:
1.15 albertel 119: sub storesurvey {
1.99 albertel 120: if ( !&Apache::response::submitted() ) { return ''; }
1.100 albertel 121: my $response = $env{'form.HWVAL_'.$Apache::inputtags::response['-1']};
1.83 albertel 122: &Apache::lonxml::debug("Here I am!:$response:");
123: if ( $response !~ /[0-9]+/) { return ''; }
1.96 albertel 124: my $part = $Apache::inputtags::part;
1.83 albertel 125: my $id = $Apache::inputtags::response['-1'];
126: my @whichfoils=@{ $Apache::response::foilgroup{'names'} };
127: my %responsehash;
128: $responsehash{$whichfoils[$response]}=$response;
1.96 albertel 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);
1.83 albertel 135: &Apache::lonxml::debug("submitted a $response<br />\n");
136: return '';
1.15 albertel 137: }
138:
1.32 albertel 139: sub grade_response {
1.83 albertel 140: my ($max,$randomize)=@_;
141: #keep the random numbers the same must always call this
142: my ($answer,@whichfoils)=&whichfoils($max,$randomize);
1.99 albertel 143: if ( !&Apache::response::submitted() ) { return; }
1.83 albertel 144: my $response;
1.100 albertel 145: if ($env{'form.submitted'} eq 'scantron') {
1.83 albertel 146: $response=&Apache::response::getresponse();
147: } else {
1.100 albertel 148: $response = $env{'form.HWVAL_'.$Apache::inputtags::response['-1']};
1.83 albertel 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);
1.32 albertel 169: }
170:
1.1 albertel 171: sub end_foilgroup {
1.83 albertel 172: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.29 albertel 173:
1.83 albertel 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;
1.93 albertel 178: my $direction = &Apache::lonxml::get_param('direction',$parstack,
179: $safeeval,'-2');
1.83 albertel 180: if ( $style eq 'survey' && $target ne 'analyze') {
181: if ($target eq 'web' || $target eq 'tex') {
1.93 albertel 182: $result=&displayallfoils($direction);
1.83 albertel 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') {
1.90 albertel 195: $result=&displayfoils($target,$max,$randomize,$direction);
1.83 albertel 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: }
1.81 albertel 208: }
1.83 albertel 209: }
1.89 albertel 210: &Apache::response::poprandomnumber();
1.83 albertel 211: &Apache::lonxml::increment_counter();
212: return $result;
1.6 albertel 213: }
214:
215: sub getfoilcounts {
1.83 albertel 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'} };
1.6 albertel 222: }
1.83 albertel 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);
1.5 albertel 231: }
232:
1.15 albertel 233: sub displayallfoils {
1.93 albertel 234: my ($direction)=@_;
1.83 albertel 235: my $result;
236: &Apache::lonxml::debug("survey style display");
1.106 ! albertel 237: my @names;
! 238: if ( $Apache::response::foilgroup{'names'} ) {
! 239: @names= @{ $Apache::response::foilgroup{'names'} };
! 240: }
1.83 albertel 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"};
1.93 albertel 246: if ($direction eq 'horizontal') { $result.='<table><tr>'; }
1.83 albertel 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') {
1.93 albertel 251: if ($direction eq 'horizontal') {
252: $result.="<td>";
253: } else {
254: $result.="<br />";
255: }
1.84 albertel 256: if (defined($lastresponse{$name})) {
1.83 albertel 257: $result.='<b>';
258: }
259: $result .= $Apache::response::foilgroup{$name.'.text'};
1.84 albertel 260: if (defined($lastresponse{$name})) {
1.83 albertel 261: $result.='</b>';
262: }
1.93 albertel 263: if ($direction eq 'horizontal') { $result.="</td>"; }
1.83 albertel 264: }
1.45 albertel 265: }
1.83 albertel 266: } else {
267: foreach my $name (@names) {
268: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
1.93 albertel 269: if ($direction eq 'horizontal') {
270: $result.="<td>";
271: } else {
272: $result.="<br />";
273: }
1.94 matthew 274: $result .= '<label>';
1.93 albertel 275: $result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
1.83 albertel 276: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
1.94 matthew 277: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}.
278: '</label>';
1.83 albertel 279: $temp++;
1.93 albertel 280: if ($direction eq 'horizontal') { $result.="</td>"; }
1.83 albertel 281: }
1.45 albertel 282: }
283: }
1.93 albertel 284: if ($direction eq 'horizontal') { $result.='</tr></table>'; }
1.83 albertel 285: return $result;
1.15 albertel 286: }
287:
1.28 albertel 288: sub whichfoils {
1.83 albertel 289: my ($max,$randomize)=@_;
1.28 albertel 290:
1.83 albertel 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
1.104 albertel 297: if ( $max>0 && ($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; $max=$count; }
1.83 albertel 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 {
1.87 albertel 318: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
1.83 albertel 319: }
320: }
1.97 albertel 321: if (!$havetrue && $Apache::lonhomework::type ne 'survey') {
322: &Apache::lonxml::error("There are no true statements available.<br />");
323: }
1.83 albertel 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 {
1.87 albertel 347: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
1.83 albertel 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; }
1.49 albertel 392: }
1.83 albertel 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; }
1.49 albertel 400: }
1.83 albertel 401: $answer+=$topcount+$#whichfalse+1;
402: $dosplice=0;
1.49 albertel 403: } else {
1.83 albertel 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]) }
1.49 albertel 413: }
1.83 albertel 414: for (my $i=0;$i<=$#bottomlist;$i++) {
415: if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
1.49 albertel 416: }
1.83 albertel 417: #if the true statement is randomized insert it into the list
418: if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
1.49 albertel 419: }
1.83 albertel 420: &Apache::lonxml::debug("Answer is $answer");
421: return ($answer,@whichfalse);
1.28 albertel 422: }
423:
424: sub displayfoils {
1.90 albertel 425: my ($target,$max,$randomize,$direction)=@_;
1.83 albertel 426: my $result;
1.28 albertel 427:
1.83 albertel 428: my ($answer,@whichfoils)=&whichfoils($max,$randomize);
1.22 albertel 429: my $part=$Apache::inputtags::part;
1.83 albertel 430: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
431: if ( ($target ne 'tex') &&
432: &Apache::response::show_answer() ) {
1.90 albertel 433: if ($direction eq 'horizontal') {
434: if ($target ne 'tex') {
435: $result.='<table><tr>';
436: }
437: }
1.83 albertel 438: foreach my $name (@whichfoils) {
1.90 albertel 439: if ($direction eq 'horizontal') {
440: if ($target ne 'tex') { $result.='<td>'; }
441: }
1.83 albertel 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: }
1.94 matthew 452: if ($target eq 'web') { $result.="<label>"; }
1.90 albertel 453: $result.=$Apache::response::foilgroup{$name.'.text'};
1.94 matthew 454: if ($target eq 'web') { $result.="</label>"; }
1.83 albertel 455: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
456: if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
457: }
1.90 albertel 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: }
1.83 albertel 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);
1.90 albertel 475: if ($target ne 'tex' && $direction eq 'horizontal') {
476: $result.="<table><tr>";
477: }
1.83 albertel 478: foreach my $name (@whichfoils) {
479: if ($target ne 'tex') {
1.90 albertel 480: if ($direction eq 'horizontal') {
481: $result.="<td>";
482: } else {
483: $result.="<br />";
484: }
485: }
486: if ($target ne 'tex') {
1.94 matthew 487: $result.= '<label>';
1.90 albertel 488: $result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
1.83 albertel 489: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
1.94 matthew 490: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</label>";
1.83 albertel 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: }
1.90 albertel 499: if ($target ne 'tex' && $direction eq 'horizontal') {
500: $result.="</td>";
501: }
1.83 albertel 502: $temp++;
503: }
1.90 albertel 504: if ($target ne 'tex' && $direction eq 'horizontal') {
505: $result.="</tr></table>";
506: }
1.83 albertel 507: }
1.92 albertel 508: if ($target ne 'tex') { if ($direction ne 'horizontal') { $result.="<br />";} } else { $result.='\vskip 0 mm '; }
1.83 albertel 509: return $result;
1.81 albertel 510: }
511:
512: sub displayallanswers {
1.106 ! albertel 513: my @names;
! 514: if ( $Apache::response::foilgroup{'names'} ) {
! 515: @names= @{ $Apache::response::foilgroup{'names'} };
! 516: }
1.81 albertel 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;
1.14 albertel 525: }
526:
1.28 albertel 527: sub displayanswers {
1.83 albertel 528: my ($max,$randomize)=@_;
529: my ($answer,@whichopt) = &whichfoils($max,$randomize);
530: my $result=&Apache::response::answer_header('radiobuttonresponse');
1.105 albertel 531: if ($Apache::lonhomework::type eq 'exam') {
532: my $correct = ('A'..'Z')[$answer];
533: $result.=&Apache::response::answer_part('radiobuttonresponse',
534: $correct);
535: }
1.83 albertel 536: foreach my $name (@whichopt) {
537: $result.=&Apache::response::answer_part('radiobuttonresponse',
1.105 albertel 538: $Apache::response::foilgroup{$name.'.value'});
539: }
1.83 albertel 540: $result.=&Apache::response::answer_footer('radiobuttonresponse');
541: return $result;
1.28 albertel 542: }
543:
1.14 albertel 544: sub start_conceptgroup {
1.83 albertel 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;
1.14 albertel 559: }
560:
561: sub end_conceptgroup {
1.83 albertel 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;
1.26 albertel 575: }
576:
577: sub insert_conceptgroup {
1.83 albertel 578: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
579: return $result;
1.1 albertel 580: }
581:
582: sub start_foil {
1.83 albertel 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;
1.95 albertel 587: if ($target eq 'analyze') {
588: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
589: }
1.83 albertel 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;
1.1 albertel 610: }
611:
612: sub end_foil {
1.83 albertel 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: }
1.85 albertel 618: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
619: || $target eq 'tex' || $target eq 'analyze') {
1.83 albertel 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);
1.102 albertel 623: if ($name eq "") {
1.101 albertel 624: &Apache::lonxml::warning("Foils without names exist. This can cause problems to malfunction.");
1.98 albertel 625: $name=$Apache::lonxml::curdepth;
626: }
1.85 albertel 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: }
1.86 albertel 630: $Apache::response::foilnames{$name}++;
1.85 albertel 631: my $location =&Apache::lonxml::get_param('location',$parstack,
632: $safeeval);
1.83 albertel 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: }
1.18 albertel 646: }
1.83 albertel 647: return '';
1.1 albertel 648: }
649:
1.27 albertel 650: sub insert_foil {
1.83 albertel 651: return '
1.27 albertel 652: <foil name="" value="unused">
653: <startouttext />
654: <endouttext />
655: </foil>';
656: }
1.1 albertel 657: 1;
658: __END__
659:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>