File:
[LON-CAPA] /
loncom /
homework /
radiobuttonresponse.pm
Revision
1.136:
download - view:
text,
annotated -
select for diffs
Fri Oct 24 16:22:54 2008 UTC (15 years, 9 months ago) by
bisitz
Branches:
MAIN
CVS tags:
HEAD
Localization, wording, nobreaks for Colorful Editor
- Added missing &mt() calls at several places (more to be done)
- Same wording "Delete?" for all Delete options
- Same wording style, e.g. added ":" after text and before optionlist
- Added nobreak style for some elements which need to stay together, e.g. help_open_topic in loncommon.pm
- Added/updated some related German translations
1: # The LearningOnline Network with CAPA
2: # mutliple choice style responses
3: #
4: # $Id: radiobuttonresponse.pm,v 1.136 2008/10/24 16:22:54 bisitz 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# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: package Apache::radiobuttonresponse;
29: use strict;
30: use HTML::Entities();
31: use Apache::lonlocal;
32: use Apache::lonnet;
33: use Apache::response;
34:
35: my $default_bubbles_per_line = 10;
36:
37:
38: BEGIN {
39: &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
40: }
41:
42: sub bubble_line_count {
43: my ($numfoils, $bubbles_per_line) = @_;
44: my $bubble_lines;
45: $bubble_lines = int($numfoils / $bubbles_per_line);
46: if (($numfoils % $bubbles_per_line) != 0) {
47: $bubble_lines++;
48: }
49: return $bubble_lines;
50:
51: }
52:
53:
54: sub start_radiobuttonresponse {
55: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
56: my $result;
57:
58: #when in a radiobutton response use these
59: &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
60: push (@Apache::lonxml::namespace,'radiobuttonresponse');
61: my $id = &Apache::response::start_response($parstack,$safeeval);
62:
63: %Apache::hint::radiobutton=();
64: undef(%Apache::response::foilnames);
65: if ($target eq 'meta') {
66: $result=&Apache::response::meta_package_write('radiobuttonresponse');
67: } elsif ($target eq 'edit' ) {
68: $result.=&Apache::edit::start_table($token)
69: .'<tr><td>'.&Apache::lonxml::description($token)
70: .&Apache::loncommon::help_open_topic('Radio_Response_Problems')
71: .'</td>'
72: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
73: .&Apache::edit::deletelist($target,$token)
74: .'</span></td>'
75: .'<td> '.&Apache::edit::end_row()
76: .&Apache::edit::start_spanning_row();
77: $result.=
78: &Apache::edit::text_arg('Max Number Of Shown Foils:','max',
79: $token,'4').
80: &Apache::edit::select_arg('Randomize Foil Order:','randomize',
81: ['yes','no'],$token).
82: &Apache::edit::select_arg('Display Direction','direction',
83: ['vertical','horizontal'],$token).
84: &Apache::edit::end_row().
85: &Apache::edit::start_spanning_row()."\n";
86: } elsif ($target eq 'modified') {
87: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
88: $safeeval,'max',
89: 'randomize','direction');
90: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
91: } elsif ($target eq 'tex') {
92: my $type=&Apache::lonxml::get_param('TeXtype',$parstack,$safeeval,
93: undef,0);
94: if ($type eq '1') {
95: $result .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}';
96: } elsif ($type eq 'A') {
97: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
98: } elsif ($type eq 'a') {
99: $result .= ' \renewcommand{\labelenumi}{\alph{enumi}.}';
100: } elsif ($type eq 'i') {
101: $result .= ' \renewcommand{\labelenumi}{\roman{enumi}.}';
102: } else {
103: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
104: }
105: if($env{'form.pdfFormFields'} eq 'yes') {
106: $result .= &Apache::lonxml::print_pdf_hiddenfield('meta', $env{'user.name'}, $env{'user.domain'});
107: $result .= "\n\\\\\n\\\\\n";
108: } else {
109: $result .= '\begin{enumerate}';
110: }
111: } elsif ($target eq 'analyze') {
112: my $part_id="$Apache::inputtags::part.$id";
113: $Apache::lonhomework::analyze{"$part_id.type"} = 'radiobuttonresponse';
114: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
115: }
116: return $result;
117: }
118:
119: sub end_radiobuttonresponse {
120: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
121: my $result;
122: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
123: if ($target eq 'tex' and $env{'form.pdfFormFields'} ne 'yes') {
124: $result .= '\end{enumerate}';
125: }
126: &Apache::response::end_response;
127: pop @Apache::lonxml::namespace;
128: &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
129: undef(%Apache::response::foilnames);
130: return $result;
131: }
132:
133: %Apache::response::foilgroup=();
134: sub start_foilgroup {
135: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
136: my $result;
137: %Apache::response::foilgroup=();
138: $Apache::radiobuttonresponse::conceptgroup=0;
139: &Apache::response::pushrandomnumber();
140: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
141: $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
142: }
143: return $result;
144: }
145:
146: sub storesurvey {
147: if ( !&Apache::response::submitted() ) { return ''; }
148: my $response = $env{'form.HWVAL_'.$Apache::inputtags::response['-1']};
149: &Apache::lonxml::debug("Here I am!:$response:");
150: if ( $response !~ /[0-9]+/) { return ''; }
151: my $part = $Apache::inputtags::part;
152: my $id = $Apache::inputtags::response['-1'];
153: my @whichfoils=@{ $Apache::response::foilgroup{'names'} };
154: my %responsehash;
155: $responsehash{$whichfoils[$response]}=$response;
156: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
157: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
158: $responsestr;
159: my %previous=&Apache::response::check_for_previous($responsestr,$part,$id);
160: my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
161: &Apache::response::handle_previous(\%previous,$ad);
162: &Apache::lonxml::debug("submitted a $response<br />\n");
163: return '';
164: }
165:
166:
167: sub grade_response {
168: my ($answer, $whichfoils, $bubbles_per_line)=@_;
169:
170: if ( !&Apache::response::submitted() ) { return; }
171: my $response;
172:
173: if ($env{'form.submitted'} eq 'scantron') {
174: $response = &Apache::response::getresponse(1,undef,
175: &bubble_line_count(scalar(@{ $whichfoils}),
176: $bubbles_per_line),
177: $bubbles_per_line);
178:
179: } else {
180: $response = $env{'form.HWVAL_'.$Apache::inputtags::response['-1']};
181: }
182:
183:
184: if ( $response !~ /[0-9]+/) { return; }
185: my $part=$Apache::inputtags::part;
186: my $id = $Apache::inputtags::response['-1'];
187: my %responsehash;
188: $responsehash{$whichfoils->[$response]}=$response;
189: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
190: my %previous=&Apache::response::check_for_previous($responsestr,
191: $part,$id);
192: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
193: $responsestr;
194: &Apache::lonxml::debug("submitted a $response<br />\n");
195: my $ad;
196: if ($response == $answer) {
197: $ad='EXACT_ANS';
198: } else {
199: $ad='INCORRECT';
200: }
201: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
202: &Apache::response::handle_previous(\%previous,$ad);
203: }
204:
205: sub end_foilgroup {
206: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
207:
208: my $result;
209: my $bubble_lines;
210: my $bubbles_per_line;
211: my $answer_count;
212: my $id = $Apache::inputtags::response['-1'];
213: my $part = $Apache::inputtags::part;
214: $bubbles_per_line =
215: &Apache::response::get_response_param($Apache::inputtags::part."_$id",
216: 'numbubbles',
217: $default_bubbles_per_line);
218:
219:
220: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
221: $target eq 'tex' || $target eq 'analyze') {
222: my $style = $Apache::lonhomework::type;
223: my $direction = &Apache::lonxml::get_param('direction',$parstack,
224: $safeeval,'-2');
225: if ( $style eq 'survey' && $target ne 'analyze') {
226: if ($target eq 'web' || $target eq 'tex') {
227: $result=&displayallfoils($direction, $target);
228: } elsif ( $target eq 'answer' ) {
229: $result=&displayallanswers();
230: } elsif ( $target eq 'grade' ) {
231: $result=&storesurvey();
232: }
233: $answer_count = scalar(@{$Apache::response::foilgroup{'names'}});
234:
235: } else {
236:
237: my $name;
238: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,
239: '-2');
240: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
241: $safeeval,'-2');
242: my ($answer, @shown) = &whichfoils($max, $randomize);
243: $answer_count = scalar(@shown);
244:
245: if ($target eq 'web' || $target eq 'tex') {
246: $result=&displayfoils($target,
247: $answer, \@shown,
248: $direction,
249: $bubbles_per_line);
250: } elsif ($target eq 'answer' ) {
251: $result=&displayanswers($answer, \@shown, $bubbles_per_line);
252: } elsif ( $target eq 'grade') {
253: &grade_response($answer, \@shown, $bubbles_per_line);
254: } elsif ( $target eq 'analyze') {
255: my $bubble_lines = &bubble_line_count($answer_count,
256: $bubbles_per_line);
257: &Apache::response::analyze_store_foilgroup(\@shown,
258: ['text','value','location']);
259: my $part_id="$part.$id";
260: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },
261: ('true','false'));
262:
263: }
264: }
265: $Apache::lonxml::post_evaluate=0;
266: }
267: if ($target eq 'web') {
268: &Apache::response::setup_prior_tries_hash(\&format_prior_answer,
269: [\%Apache::response::foilgroup]);
270: }
271: &Apache::response::poprandomnumber();
272: $bubble_lines = &bubble_line_count($answer_count, $bubbles_per_line);
273: &Apache::lonxml::increment_counter($bubble_lines,
274: "$part.$id");
275: if ($target eq 'analyze') {
276: &Apache::lonhomework::set_bubble_lines();
277: }
278: return $result;
279: }
280:
281: sub getfoilcounts {
282: my @names;
283: my $truecnt=0;
284: my $falsecnt=0;
285: my $name;
286: if ( $Apache::response::foilgroup{'names'} ) {
287: @names= @{ $Apache::response::foilgroup{'names'} };
288: }
289: foreach $name (@names) {
290: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
291: $truecnt++;
292: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
293: $falsecnt++;
294: }
295: }
296: return ($truecnt,$falsecnt);
297: }
298:
299: sub format_prior_answer {
300: my ($mode,$answer,$other_data) = @_;
301: my $foil_data = $other_data->[0];
302: my %response = &Apache::lonnet::str2hash($answer);
303: my ($name) = keys(%response);
304: return '<span class="LC_prior_radiobutton">'.
305: $foil_data->{$name.'.text'}.'</span>';
306:
307: }
308:
309: sub displayallfoils {
310: my ($direction, $target)=@_;
311: my $result;
312: &Apache::lonxml::debug("survey style display");
313: my @names;
314: if ( $Apache::response::foilgroup{'names'} ) {
315: @names= @{ $Apache::response::foilgroup{'names'} };
316: }
317:
318: my $temp=0;
319: my $i =0;
320: my $id=$Apache::inputtags::response['-1'];
321: my $part=$Apache::inputtags::part;
322: my $lastresponse=
323: $Apache::lonhomework::history{"resource.$part.$id.submission"};
324: if ($direction eq 'horizontal') { $result.='<table><tr>'; }
325: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
326: if (&Apache::response::show_answer() ) {
327: foreach my $name (@names) {
328: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
329: if (($direction eq 'horizontal') && ($target ne 'tex')) {
330: $result.="<td>";
331: } else {
332: if ($target eq 'tex') {
333: $result .= '\item \vskip -2mm ';
334: } else {
335: $result.="<br />";
336: }
337: }
338: if (defined($lastresponse{$name})) {
339: if ($target eq 'tex') {
340: $result .= '}';
341: } else {
342: $result.='<b>';
343: }
344: }
345: $result .= $Apache::response::foilgroup{$name.'.text'};
346: if (defined($lastresponse{$name}) && ($target ne 'tex')) {
347: $result.='</b>';
348: }
349: if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.="</td>"; }
350: }
351: }
352: } else {
353: foreach my $name (@names) {
354: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
355: if ($direction eq 'horizontal') {
356: $result.="<td>";
357: } else {
358: if ($target eq 'tex') {
359: if($env{'form.pdfFormFields'} eq 'yes') {
360: my $fieldname = $env{'request.symb'}.
361: '&part_'. $Apache::inputtags::part.
362: '&radiobuttonresponse'.
363: '&HWVAL_' . $Apache::inputtags::response['-1'];
364: my $value = $temp;
365: my $text = $Apache::response::foilgroup{$name.'.text'};
366: $result .= &Apache::lonxml::print_pdf_radiobutton($fieldname,
367: $value,
368: $text)."\n";
369: } else {
370: $result .= '\item \vskip -2mm ';
371: }
372: } else {
373: $result.="<br />";
374: }
375: }
376: if ($target eq 'tex') {
377: if($env{'form.pdfFormFields'} ne 'yes') {
378: $result .= '$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
379: }
380: $i++;
381: } else {
382: $result .= '<label>';
383: $result.="<input
384: onchange=\"javascript:setSubmittedPart('$part');\"
385: type=\"radio\"
386: name=\"HWVAL_$Apache::inputtags::response['-1']\"
387: value=\"$temp\" ";
388: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
389: $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.
390: '</label>';
391: }
392: $temp++;
393: if ($target ne 'tex') {
394: if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.="</td>"; }
395: } else {
396: $result.='\vskip 0 mm ';
397: }
398: }
399: }
400: }
401:
402: if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.='</tr></table>'; }
403: return $result;
404: }
405:
406: =pod
407:
408: =item &whichfoils($max,$randomize)
409:
410: Randomizes the list of foils.
411: Respects
412: - each foils desire to be randomized
413: - the existance of Concept groups of foils (select 1 foil from each)
414: - and selects a single correct statement from all possilble true statments
415: - and limits it to a toal of $max foils
416:
417: WARNING: this routine uses the random number generator, it should only
418: be called once per target, otherwise it can cause randomness changes in
419: homework problems.
420:
421: Arguments
422: $max - maximum number of foils to select (including the true one)
423: (so a max of 5 is: 1 true, 4 false)
424:
425: $randomize - whether to randomize the listing of foils, by default
426: will randomize, only if randomize is 'no' will it not
427:
428: Returns
429: $answer - location in the array of the correct answer
430: @foils - array of foil names in to display order
431:
432: =cut
433:
434: sub whichfoils {
435: my ($max,$randomize)=@_;
436:
437: my @truelist;
438: my @falselist;
439: my @whichfalse =();
440: my ($truecnt,$falsecnt) = &getfoilcounts();
441: my $count=0;
442: # we will add in 1 of the true statements
443: if ( $max>0 && ($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; $max=$count; }
444: my $answer=int(&Math::Random::random_uniform() * ($count));
445: &Apache::lonxml::debug("Count is $count, $answer is $answer");
446: my @names;
447: if ( $Apache::response::foilgroup{'names'} ) {
448: @names= @{ $Apache::response::foilgroup{'names'} };
449: }
450: if (&Apache::response::showallfoils()) {
451: @whichfalse=@names;
452: } elsif ($randomize eq 'no') {
453: &Apache::lonxml::debug("No randomization");
454: my $havetrue=0;
455: foreach my $name (@names) {
456: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
457: if (!$havetrue ) {
458: push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
459: }
460: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
461: push (@whichfalse,$name);
462: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
463: } else {
464: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
465: }
466: }
467: if (!$havetrue && $Apache::lonhomework::type ne 'survey') {
468: &Apache::lonxml::error(&mt('There are no true statements available.').'<br />');
469: }
470: } else {
471: my $current=0;
472: &Apache::lonhomework::showhash(%Apache::response::foilgroup);
473: my (%top,%bottom);
474: #first find out where everyone wants to be
475: foreach my $name (@names) {
476: $current++;
477: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
478: push (@truelist,$name);
479: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
480: $top{$name}=$current;
481: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
482: $bottom{$name}=$current;
483: }
484: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
485: push (@falselist,$name);
486: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
487: $top{$name}=$current;
488: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
489: $bottom{$name}=$current;
490: }
491: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
492: } else {
493: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
494: }
495: }
496: #pick a true statement
497: my $notrue=0;
498: if (scalar(@truelist) == 0) { $notrue=1; }
499: my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
500: &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
501: my (@toplist, @bottomlist);
502: my $topcount=0;
503: my $bottomcount=0;
504: # assign everyone to either toplist/bottomlist or whichfalse
505: # which false is randomized, toplist bottomlist are in order
506: while ((($#whichfalse+$topcount+$bottomcount) < $max-2) && ($#falselist > -1)) {
507: &Apache::lonxml::debug("Have $#whichfalse max is $max");
508: my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
509: &Apache::lonxml::debug("From $#falselist elms, picking $afalse");
510: $afalse=splice(@falselist,$afalse,1);
511: &Apache::lonxml::debug("Picked $afalse");
512: &Apache::lonhomework::showhash(('names'=>\@names));
513: &Apache::lonhomework::showhash(%top);
514: if ($top{$afalse}) {
515: $toplist[$top{$afalse}]=$afalse;
516: $topcount++;
517: } elsif ($bottom{$afalse}) {
518: $bottomlist[$bottom{$afalse}]=$afalse;
519: $bottomcount++;
520: } else {
521: push (@whichfalse,$afalse);
522: }
523: }
524: &Apache::lonxml::debug("Answer wants $answer");
525: my $truename=$truelist[$whichtrue];
526: my $dosplice=1;
527: if ($notrue && $Apache::lonhomework::type ne 'survey') {
528: $dosplice=0;
529: &Apache::lonxml::error(&mt('There are no true statements available.').'<br />');
530: }
531: #insert the true statement, keeping track of where it wants to be
532: if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
533: $toplist[$top{$truename}]=$truename;
534: $answer=-1;
535: foreach my $top (reverse(@toplist)) {
536: if ($top) { $answer++;}
537: if ($top eq $truename) { last; }
538: }
539: $dosplice=0;
540: } elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom' && $dosplice) {
541: $bottomlist[$bottom{$truename}]=$truename;
542: $answer=-1;
543: foreach my $bot (@bottomlist) {
544: if ($bot) { $answer++;}
545: if ($bot eq $truename) { last; }
546: }
547: $answer+=$topcount+$#whichfalse+1;
548: $dosplice=0;
549: } else {
550: if ($topcount>0 || $bottomcount>0) {
551: $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
552: + $topcount;
553: }
554: }
555: &Apache::lonxml::debug("Answer now wants $answer");
556: #add the top items to the top, bottom items to the bottom
557: for (my $i=0;$i<=$#toplist;$i++) {
558: if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
559: }
560: for (my $i=0;$i<=$#bottomlist;$i++) {
561: if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
562: }
563: #if the true statement is randomized insert it into the list
564: if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
565: }
566: &Apache::lonxml::debug("Answer is $answer");
567: return ($answer,@whichfalse);
568: }
569:
570: sub displayfoils {
571: my ($target,$answer,$whichfoils,$direction, $bubbles_per_line)=@_;
572: my $result;
573:
574: my $part=$Apache::inputtags::part;
575: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
576: if ( ($target ne 'tex') &&
577: &Apache::response::show_answer() ) {
578: if ($direction eq 'horizontal') {
579: if ($target ne 'tex') {
580: $result.='<table><tr>';
581: }
582: }
583: foreach my $name (@{ $whichfoils }) {
584: if ($direction eq 'horizontal') {
585: if ($target ne 'tex') { $result.='<td>'; }
586: }
587: if ($target ne 'tex') {
588: $result.="<br />";
589: } else {
590: $result.='\item \vskip -2 mm ';
591: }
592: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
593: if ($target ne 'tex') {
594: $result.=&mt('Correct:').'<b>';
595: } else {
596: $result.=&mt('Correct:').' \textbf{';
597: }
598: } else {
599: $result.=&mt('Incorrect:');
600: }
601: if ($target eq 'web') { $result.="<label>"; }
602: $result.=$Apache::response::foilgroup{$name.'.text'};
603: if ($target eq 'web') { $result.="</label>"; }
604: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
605: if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
606: }
607: if ($direction eq 'horizontal') {
608: if ($target ne 'tex') { $result.='</td>'; }
609: }
610: }
611: if ($direction eq 'horizontal') {
612: if ($target ne 'tex') {
613: $result.='</tr></table>';
614: }
615: }
616: } else {
617: my @alphabet = ('A'..'Z');
618: my $i = 0;
619: my $bubble_number = 0;
620: my $line = 0;
621: my $temp=0;
622: my $id=$Apache::inputtags::response['-1'];
623: my $part=$Apache::inputtags::part;
624: my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
625: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
626: if ($target ne 'tex' && $direction eq 'horizontal') {
627: $result.="<table><tr>";
628: }
629: foreach my $name (@{ $whichfoils }) {
630: if ($target ne 'tex') {
631: if ($direction eq 'horizontal') {
632: $result.="<td>";
633: } else {
634: $result.="<br />";
635: }
636: }
637: if ($target ne 'tex') {
638: $result.= '<label>';
639: $result.=
640: "<input type=\"radio\"
641: onchange=\"javascript:setSubmittedPart('$part');\"
642: name=\"HWVAL_$Apache::inputtags::response['-1']\"
643: value=\"$temp\" ";
644: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
645: $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}."</label>";
646: } else {
647: if ($Apache::lonhomework::type eq 'exam') {
648: if($bubble_number >= $bubbles_per_line) {
649: $line++;
650: $i = 0;
651: $bubble_number = 0;
652: $result.='\item[\textbf{'.($Apache::lonxml::counter+$line).'}.]';
653: }
654: $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
655: $i++;
656: $bubble_number++;
657: } else {
658: if($env{'form.pdfFormFields'} eq 'yes') {
659:
660: my $fieldname = $env{'request.symb'}.
661: '&part_'. $Apache::inputtags::part.
662: '&radiobuttonresponse'.
663: '&HWVAL_' . $Apache::inputtags::response['-1'];
664: my $value = $temp;
665: my $text = $Apache::response::foilgroup{$name.'.text'};
666: $result .= &Apache::lonxml::print_pdf_radiobutton($fieldname, $value, $text).'\newline'."\n";
667: } else {
668: $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
669: }
670: }
671: }
672: if ($target ne 'tex' && $direction eq 'horizontal') {
673: $result.="</td>";
674: }
675: $temp++;
676: }
677: if ($target ne 'tex' && $direction eq 'horizontal') {
678: $result.="</tr></table>";
679: }
680: }
681: if ($target ne 'tex') { if ($direction ne 'horizontal') { $result.="<br />";} } else { $result.='\vskip 0 mm '; }
682: return $result;
683: }
684:
685: sub displayallanswers {
686: my @names;
687: if ( $Apache::response::foilgroup{'names'} ) {
688: @names= @{ $Apache::response::foilgroup{'names'} };
689: }
690: my $result=&Apache::response::answer_header('radiobuttonresponse');
691: foreach my $name (@names) {
692: $result.=&Apache::response::answer_part('radiobuttonresponse',
693: $Apache::response::foilgroup{$name.'.value'});
694: }
695: $result.=&Apache::response::answer_footer('radiobuttonresponse');
696: return $result;
697: }
698:
699: sub displayanswers {
700: my ($answer, $whichopt, $bubbles_per_line)=@_;
701: my $result;
702:
703: if ($Apache::lonhomework::type eq 'exam') {
704: my $line = int($answer/$bubbles_per_line);
705: my $correct = ('A'..'Z')[$answer%$bubbles_per_line];
706: $result .= &Apache::response::answer_header('radiobuttonresponse',
707: $line);
708: $result .= &Apache::response::answer_part('radiobuttonresponse',
709: $correct);
710: } else {
711: $result .= &Apache::response::answer_header('radiobuttonresponse');
712: }
713: foreach my $name (@{ $whichopt }) {
714: $result.=&Apache::response::answer_part('radiobuttonresponse',
715: $Apache::response::foilgroup{$name.'.value'});
716: }
717: $result.=&Apache::response::answer_footer('radiobuttonresponse');
718: return $result;
719: }
720:
721: sub start_conceptgroup {
722: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
723: $Apache::radiobuttonresponse::conceptgroup=1;
724: %Apache::response::conceptgroup=();
725: my $result;
726: if ($target eq 'edit') {
727: $result.=&Apache::edit::tag_start($target,$token);
728: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
729: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
730: } elsif ($target eq 'modified') {
731: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
732: $safeeval,'concept');
733: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
734: }
735: return $result;
736: }
737:
738: sub end_conceptgroup {
739: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
740: $Apache::radiobuttonresponse::conceptgroup=0;
741: my $result;
742: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
743: $target eq 'tex' || $target eq 'analyze') {
744: &Apache::response::pick_foil_for_concept($target,
745: ['value','text','location'],
746: \%Apache::hint::radiobutton,
747: $parstack,$safeeval);
748: } elsif ($target eq 'edit') {
749: $result=&Apache::edit::end_table();
750: }
751: return $result;
752: }
753:
754: sub insert_conceptgroup {
755: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
756: return $result;
757: }
758:
759: sub start_foil {
760: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
761: my $result='';
762: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
763: &Apache::lonxml::startredirection;
764: if ($target eq 'analyze') {
765: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
766: }
767: } elsif ($target eq 'edit') {
768: $result=&Apache::edit::tag_start($target,$token);
769: $result.=&Apache::edit::text_arg('Name:','name',$token);
770: $result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
771: ['unused','true','false'],
772: $token);
773: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
774: $safeeval,'-3');
775: if ($randomize ne 'no') {
776: $result.=&Apache::edit::select_arg('Location:','location',
777: ['random','top','bottom'],$token);
778: }
779: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
780: } elsif ($target eq 'modified') {
781: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
782: $safeeval,'value','name',
783: 'location');
784: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
785: }
786: return $result;
787: }
788:
789: sub end_foil {
790: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
791: my $text='';
792: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
793: $text=&Apache::lonxml::endredirection;
794: }
795: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
796: || $target eq 'tex' || $target eq 'analyze') {
797: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
798: if ($value ne 'unused') {
799: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
800: if ($name eq "") {
801: &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
802: $name=$Apache::lonxml::curdepth;
803: }
804: if (defined($Apache::response::foilnames{$name})) {
805: &Apache::lonxml::error(&mt('Foil name [_1] appears more than once. Foil names need to be unique.','<b><tt>'.$name.'</tt></b>'));
806: }
807: $Apache::response::foilnames{$name}++;
808: my $location =&Apache::lonxml::get_param('location',$parstack,
809: $safeeval);
810: if ( $Apache::radiobuttonresponse::conceptgroup
811: && !&Apache::response::showallfoils() ) {
812: push @{ $Apache::response::conceptgroup{'names'} }, $name;
813: $Apache::response::conceptgroup{"$name.value"} = $value;
814: $Apache::response::conceptgroup{"$name.text"} = $text;
815: $Apache::response::conceptgroup{"$name.location"} = $location;
816: } else {
817: push @{ $Apache::response::foilgroup{'names'} }, $name;
818: $Apache::response::foilgroup{"$name.value"} = $value;
819: $Apache::response::foilgroup{"$name.text"} = $text;
820: $Apache::response::foilgroup{"$name.location"} = $location;
821: }
822: }
823: }
824: return '';
825: }
826:
827: sub insert_foil {
828: return '
829: <foil name="" value="unused">
830: <startouttext />
831: <endouttext />
832: </foil>';
833: }
834: 1;
835: __END__
836:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>