File:
[LON-CAPA] /
loncom /
homework /
optionresponse.pm
Revision
1.195:
download - view:
text,
annotated -
select for diffs
Fri Nov 28 18:23:04 2014 UTC (9 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_11_X,
HEAD
- Optionresponse in "checkbox" mode:
- Additional (optional) attributes: maxcheck and mincheck available to enforce
requirement on number of checkboxes which may be checked.
- Intended use case is polling with optionresponse used in survey mode,
and maximum number of selections voter may make is to be limited.
1: # LearningOnline Network with CAPA
2: # option list style responses
3: #
4: # $Id: optionresponse.pm,v 1.195 2014/11/28 18:23:04 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29:
30:
31:
32:
33: package Apache::optionresponse;
34: use strict;
35: use Apache::response();
36: use Apache::lonlocal;
37: use Apache::lonnet;
38:
39: BEGIN {
40: &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
41: }
42:
43: sub start_optionresponse {
44: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
45: my $result='';
46: #when in a option response use these
47: &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
48: push (@Apache::lonxml::namespace,'optionresponse');
49: my $id = &Apache::response::start_response($parstack,$safeeval);
50: %Apache::hint::option=();
51: undef(%Apache::response::foilnames);
52: if ($target eq 'edit') {
53: $result.=&Apache::edit::start_table($token)
54: .'<tr><td><span class="LC_nobreak">'.&mt('Multiple Option Response Question').'</span> '
55: .&Apache::loncommon::help_open_topic('Option_Response_Problems')."</td>"
56: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
57: .&Apache::edit::deletelist($target,$token)
58: .'</span></td>'
59: ."<td> "
60: .&Apache::edit::end_row()
61: .&Apache::edit::start_spanning_row()
62: ."\n";
63: $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max',
64: $token,'4').
65: &Apache::edit::select_arg('Randomize Foil Order:','randomize',
66: ['yes','no'],$token).
67: &Apache::edit::select_arg('Display of options when printed','TeXlayout',
68: [['horizontal','Normal list'],
69: ['vertical','Listed in a vertical column']],$token).
70: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
71: } elsif ($target eq 'modified') {
72: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
73: $safeeval,'max','randomize',
74: 'TeXlayout');
75: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
76: } elsif ($target eq 'meta') {
77: $result=&Apache::response::meta_package_write('optionresponse');
78: } elsif ($target eq 'analyze') {
79: my $part_id="$Apache::inputtags::part.$id";
80: $Apache::lonhomework::analyze{"$part_id.type"} = 'optionresponse';
81: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
82: push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} }, 1);
83:
84: }
85: return $result;
86: }
87:
88: sub end_optionresponse {
89: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
90: &Apache::response::end_response;
91: pop @Apache::lonxml::namespace;
92: &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
93: my $result;
94: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
95: undef(%Apache::response::foilnames);
96: return $result;
97: }
98:
99: %Apache::response::foilgroup=();
100: sub start_foilgroup {
101: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
102:
103: my $result='';
104: %Apache::response::foilgroup=();
105: $Apache::optionresponse::conceptgroup=0;
106: &Apache::response::pushrandomnumber(undef,$target);
107: if ($target eq 'edit') {
108: my $optionlist="<option></option>\n";
109: my $option;
110: my @opt;
111: my @raw_options = &Apache::lonxml::get_param('options', $parstack, $safeeval, 0, 0, 1);
112:
113:
114: eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval, 0, 0, 1);
115:
116: my $count=1;
117: foreach $option (@opt) {
118: $optionlist.="<option value=\"$count\">$option</option>\n";
119: $count++;
120: }
121: my $insertlist=&Apache::edit::insertlist($target,$token);
122: $result.=&Apache::edit::start_table($token);
123: my %lt = &Apache::lonlocal::texthash(
124: sel => 'Select Options',
125: add => 'Add new Option:',
126: del => 'Delete an Option:',
127: maxcheck => 'Enter maximum number students may check (e.g., 3)',
128: mincheck => 'Enter minimum number students need to check (e.g., 1)',
129: );
130: $result.= (<<ENDTABLE);
131: <tr><td>$lt{'sel'}</td>
132: <td>
133: $lt{'add'} <input type="text" name="$Apache::lonxml::curdepth.options" />
134: </td>
135: <td>$lt{'del'}
136: <select name="$Apache::lonxml::curdepth.deleteopt">$optionlist</select>
137: </td>
138: ENDTABLE
139: $result.= '<td>'.&Apache::edit::checked_arg('Print options:','texoptions',
140: [ ['nochoice',"Don't show option list"] ]
141: ,$token).'</td>';
142: $result.= '<td><label>'.&mt('Two-option checkboxes for:').
143: '<select name="checkboxvalue_'.$Apache::lonxml::curdepth.'">';
144: foreach $option (('',@opt)) {
145: $result.='<option value="'.$option.'"';
146: if ($option eq &Apache::lonxml::get_param('checkboxvalue',$parstack,$safeeval)) {
147: $result.=' selected="selected"';
148: }
149: $result.='>'.$option.'</option>';
150: }
151: $result.='</select></label> ';
152: my %checknumtxt = (
153: maxcheck => 'Max. boxes permitted to check',
154: mincheck => 'Min. boxes required to check',
155: );
156: my (%onclicknum,%checknum);
157: foreach my $item ('maxcheck','mincheck') {
158: $onclicknum{$item} = 'onclick="'."updateNumber('$item','$Apache::lonxml::curdepth','check','$lt{$item}');".'"';
159: $checknum{$item} = &Apache::lonxml::get_param($item,$parstack,$safeeval);
160: }
161: $result.=&Apache::edit::checked_arg('Checkbox options:','checkboxoptions',
162: [ ['nochoice',"Don't show option list"] ]
163: ,$token).' '.
164: &Apache::edit::checked_arg('','noprompt',
165: [ ['nochoice','Omit "Select all that are ... "' ] ]
166: ,$token);
167: foreach my $item ('maxcheck','mincheck') {
168: my $currnum = $checknum{$item};
169: unless ($currnum =~ /^\d+$/) {
170: $currnum = 'nochoice';
171: }
172: $result.= ' <span class="LC_nobreak">'.
173: &Apache::edit::checked_arg('',$item,[ [$currnum,$checknumtxt{$item}] ],
174: $token,$onclicknum{$item},1).' '.
175: '<span id="'.$item.'_numtext_'.$Apache::lonxml::curdepth.'">';
176: if ($checknum{$item} ne '') {
177: $result .= ': <a href="javascript:updateNumber('."'$item','$Apache::lonxml::curdepth','link','$lt{$item}'".')">'.
178: $checknum{$item}.'</a>';
179: }
180: $result .= '</span></span>';
181: }
182: $result.= '</td>';
183: $result.= &Apache::edit::end_row();
184: $result.= &Apache::edit::start_spanning_row();
185: $result.= $insertlist.'<br />';
186: }
187: if ($target eq 'modified') {
188: my @options;
189: my $optchanged=0;
190:
191:
192: eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval, 0, 0, 1);
193:
194: if ($env{"form.$Apache::lonxml::curdepth.deleteopt"}) {
195: my $delopt=$env{"form.$Apache::lonxml::curdepth.deleteopt"};
196: &Apache::lonxml::debug("Deleting :$delopt:");
197: splice(@options,$delopt-1,1);
198: $optchanged=1;
199: }
200: if ($env{"form.$Apache::lonxml::curdepth.options"} ne '') {
201: my $newopt = $env{"form.$Apache::lonxml::curdepth.options"};
202: push(@options,$newopt);
203: $optchanged=1;
204: }
205: my $rebuildtag = &Apache::edit::get_new_args($token,$parstack,$safeeval,
206: 'texoptions','checkboxvalue','checkboxoptions',
207: 'noprompt','maxcheck','mincheck');
208: if ($rebuildtag) {
209: my $maxcheck = $token->[2]->{'maxcheck'};
210: my $mincheck = $token->[2]->{'mincheck'};
211: if ($mincheck =~ /D/) {
212: $token->[2]->{'mincheck'}='';
213: }
214: if ($maxcheck =~ /D/) {
215: $token->[2]->{'maxcheck'}='';
216: }
217: if (($mincheck ne '') && ($maxcheck ne '')) {
218: if ($mincheck > $maxcheck) {
219: $token->[2]->{'mincheck'}=$maxcheck;
220: }
221: }
222: }
223: if ($optchanged || $rebuildtag ) {
224: $result = "<foilgroup options=\"(";
225: foreach my $option (@options) {
226: $option=~s/\'/\\\'/g;
227: &Apache::lonxml::debug("adding option :$option:");
228: $result .="'".$option."',";
229: }
230: chop $result;
231: $result.=')" ';
232: $result .= 'texoptions="'.$token->[2]{'texoptions'}.'" ';
233: $result .= 'checkboxoptions="'.$token->[2]{'checkboxoptions'}.'" ';
234: $result .= 'checkboxvalue="'.$token->[2]{'checkboxvalue'}.'" ';
235: $result .= 'noprompt="'.$token->[2]{'noprompt'}.'" ';
236: $result .= 'maxcheck="'.$token->[2]{'maxcheck'}.'" ';
237: $result .= 'mincheck="'.$token->[2]{'mincheck'}.'"';
238: $result .= '>';
239: } # else nothing changed so just use the default mechanism
240: }
241: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
242: if($env{'form.pdfFormFields'} ne 'yes') {
243: $result .= ' \begin{itemize} ';
244: } else {
245: $result .= "\\\\";
246: }
247: }
248: return $result;
249: }
250:
251: sub end_foilgroup {
252: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
253:
254: my $result;
255: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
256: $target eq 'tex' || $target eq 'analyze') {
257: my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
258: my $name;
259: my @opt;
260: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
261: &Apache::lonxml::debug("options:".join(':',@opt));
262:
263: my $TeXlayout=&Apache::lonxml::get_param('TeXlayout',$parstack,$safeeval,
264: -2,0);
265: my $checkboxvalue=&Apache::lonxml::get_param('checkboxvalue',$parstack,$safeeval);
266: my $checkboxchoices=(&Apache::lonxml::get_param('checkboxoptions',$parstack,$safeeval) ne 'nochoice');
267: my $maxcheck=&Apache::lonxml::get_param('maxcheck', $parstack, $safeeval);
268: $maxcheck =~ s/\D+//g;
269: my $mincheck=&Apache::lonxml::get_param('mincheck', $parstack, $safeeval);
270: $mincheck =~ s/\D+//g;
271: my $noprompt=&Apache::lonxml::get_param('noprompt', $parstack, $safeeval);
272:
273: if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
274: &Apache::lonxml::debug("Options are $#opt");
275: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
276: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
277: $safeeval,'-2');
278: if ($target eq 'web' || $target eq 'tex') {
279: $result.=&displayfoils($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,$tex_option_switch, $noprompt,$maxcheck,$mincheck, @opt);
280: $Apache::lonxml::post_evaluate=0;
281: } elsif ( $target eq 'answer') {
282: $result.=&displayanswers($max,$randomize,@opt);
283:
284: } elsif ( $target eq 'analyze') {
285: my @shown = &whichfoils($max,$randomize);
286: &Apache::response::analyze_store_foilgroup(\@shown,
287: ['text','value','location']);
288: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
289: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
290: } elsif ( $target eq 'grade') {
291:
292: if ( &Apache::response::submitted()) {
293:
294: my @whichopt = &whichfoils($max,$randomize);
295: my $temp=1;my $name;
296: my %responsehash;
297: my %grade;
298: my $right=0;
299: my $wrong=0;
300: my $ignored=0;
301: my $checked=0;
302: my ($numrows,$bubbles_per_row);
303: if ($Apache::lonhomework::scantronmode) {
304: my $numitems = scalar(@opt);
305: ($numrows,$bubbles_per_row) =
306: &Apache::optionresponse::getnumrows($numitems);
307: }
308: if ($numrows < 1) {
309: $numrows = 1;
310: }
311: my $checkboxopt;
312: if ($checkboxvalue) {
313: $checkboxopt = &check_box_opt($target,$checkboxvalue,@opt);
314: if (($checkboxopt) && ($Apache::lonhomework::type !~ /survey/)) {
315: my $corrnumcheck = 0;
316: if (($maxcheck ne '') || ($mincheck ne '')) {
317: foreach $name (@whichopt) {
318: if ($Apache::response::foilgroup{$name.'.value'} eq $checkboxopt) {
319: $corrnumcheck ++;
320: }
321: }
322: if (($maxcheck ne '') && ($corrnumcheck > $maxcheck)) {
323: $maxcheck = $corrnumcheck;
324: }
325: if (($mincheck ne '') && ($corrnumcheck < $mincheck)) {
326: $mincheck = $corrnumcheck;
327: }
328: }
329: }
330: }
331: foreach $name (@whichopt) {
332: my $response;
333: if ($env{'form.submitted'} eq 'scantron') {
334: if ($numrows > 1) {
335: my $num = $temp;
336: my $totalnum;
337: for (my $i=0; $i<$numrows; $i++) {
338: my $item = &Apache::response::getresponse($num);
339: if ($item =~ /^\d+$/) {
340: $totalnum = $i*$bubbles_per_row + $item;
341: }
342: $num ++;
343: }
344: if ($totalnum =~ /^\d+$/) {
345: $response = $opt[$totalnum];
346: }
347: $temp += $numrows;
348: } else {
349: $response=&Apache::response::getresponse($temp);
350: if ($response=~/\S/) {
351: $response = $opt[$response];
352: }
353: $temp ++;
354: }
355: } else {
356: $response=&Apache::response::getresponse($temp);
357: $temp ++;
358: }
359: if ( $response =~ /[^\s]/) {
360: $responsehash{$name}=$response;
361: my $value=$Apache::response::foilgroup{$name.'.value'};
362: &Apache::lonxml::debug("submitted a $response for $value<br />\n");
363: if ($value eq $response) {
364: $grade{$name}='1'; $right++;
365: } else {
366: $grade{$name}='0'; $wrong++;
367: }
368: if ($checkboxopt) {
369: if ($response eq $checkboxopt) {
370: $checked++;
371: }
372: }
373: } else {
374: $ignored++;
375: }
376: }
377: my $part=$Apache::inputtags::part;
378: my $nonlenient=&grading_is_nonlenient($part);
379: my $id = $Apache::inputtags::response['-1'];
380: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
381: my $gradestr =&Apache::lonnet::hash2str(%grade);
382: my %previous=&Apache::response::check_for_previous($responsestr,
383: $part,$id);
384: &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
385: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
386: $responsestr;
387: $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
388: if ($Apache::lonhomework::type eq 'randomizetry') {
389: $Apache::lonhomework::results{"resource.$part.$id.foilorder"} = &Apache::lonnet::array2str(@whichopt);
390: }
391: my $skipaward;
392: if ($checkboxvalue) {
393: if ((($maxcheck ne '') && ($checked > $maxcheck)) ||
394: (($mincheck ne '') && ($checked < $mincheck))) {
395: my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='WRONG_NUMBOXESCHECKED';
396: &Apache::response::handle_previous(\%previous,$ad);
397: $skipaward = 1;
398: }
399: }
400: unless ($skipaward) {
401: if (($Apache::lonhomework::type eq 'survey') ||
402: ($Apache::lonhomework::type eq 'surveycred') ||
403: ($Apache::lonhomework::type eq 'anonsurvey') ||
404: ($Apache::lonhomework::type eq 'anonsurveycred')) {
405: if ($ignored == 0) {
406: my $ad;
407: if ($Apache::lonhomework::type eq 'anonsurveycred') {
408: $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CREDIT';
409: } elsif ($Apache::lonhomework::type eq 'anonsurvey') {
410: $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
411: } elsif ($Apache::lonhomework::type eq 'surveycred') {
412: $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
413: } else {
414: $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
415: }
416: &Apache::response::handle_previous(\%previous,$ad);
417: } elsif ($wrong==0 && $right==0) {
418: } else {
419: my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='MISSING_ANSWER';
420: &Apache::response::handle_previous(\%previous,$ad);
421: }
422: } elsif ($nonlenient) {
423: #
424: # Non-lenient mode. All right or all wrong
425: #
426: my $ad;
427: if ($wrong==0 && $ignored==0) {
428: $ad='EXACT_ANS';
429: } elsif ($wrong==0 && $right==0) {
430: #nothing submitted
431: } else {
432: if ($ignored==0) {
433: $ad='INCORRECT';
434: } else {
435: $ad='MISSING_ANSWER';
436: }
437: }
438: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
439: &Apache::response::handle_previous(\%previous,$ad);
440: } else {
441: #
442: # This is lenient mode
443: #
444: my $ad;
445: if ($wrong==0 && $right==0) {
446: #nothing submitted only assign a score if we
447: #need to override a previous grade
448: if (defined($Apache::lonhomework::history{"resource.$part.$id.awarddetail"})) {
449: $ad='ASSIGNED_SCORE';
450: }
451: } else {
452: $ad='ASSIGNED_SCORE';
453: }
454: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
455: $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
456: $right/(scalar(@whichopt));
457: $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
458: scalar(@whichopt);
459: }
460: }
461: }
462: }
463: my $part_id = $Apache::inputtags::part;
464: my $response_id = $Apache::inputtags::response[-1];
465: my ($numrows,$bubbles_per_row);
466: if (($target eq 'tex') && ($Apache::lonhomework::type eq 'exam')) {
467: ($numrows,$bubbles_per_row) =
468: &Apache::optionresponse::getnumrows(scalar(@opt));
469: }
470: if ($numrows < 1) {
471: $numrows = 1;
472: }
473: my $increment = &getfoilcounts($max) * $numrows;
474: &Apache::lonxml::increment_counter($increment,"$part_id.$response_id");
475: if ($target eq 'analyze') {
476: &Apache::lonhomework::set_bubble_lines();
477: }
478:
479: } elsif ($target eq 'edit') {
480: $result.=&Apache::edit::end_table();
481: }
482: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
483: if($env{'form.pdfFormFields'} ne 'yes') {
484: $result .= '\end{itemize}';
485: } else {
486: $result .= "\\\\";
487: }
488: }
489: &Apache::response::poprandomnumber();
490: return $result;
491: }
492:
493: sub grading_is_nonlenient {
494: my ($part) = @_;
495: # Web mode: we are non-lenient unless told otherwise
496: my $defaultparm = 'off';
497: my $nonlenient = 0;
498: # Grading a bubblesheet exam: we are grading lenient unless told otherwise
499: if ($Apache::lonhomework::scantronmode) {
500: $defaultparm = 'on';
501: $nonlenient = 1;
502: }
503: my $lenientparm =
504: &Apache::response::get_response_param($part,'lenient',$defaultparm);
505: if ($lenientparm=~/^0|off|no$/i) {
506: $nonlenient = 1;
507: } elsif ($lenientparm=~/^1|on|yes$/i) {
508: $nonlenient = 0;
509: }
510: return $nonlenient;
511: }
512:
513: sub getfoilcounts {
514: my ($max)=@_;
515: # +1 since instructors will count from 1
516: my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
517: if (&Apache::response::showallfoils()) { $max=$count; }
518: if ($count>$max) { $count=$max }
519: &Apache::lonxml::debug("Count is $count from $max");
520: return $count;
521: }
522:
523: sub whichfoils {
524: my ($max,$randomize)=@_;
525: return &Apache::response::whichorder($max,$randomize,
526: &Apache::response::showallfoils(),
527: \%Apache::response::foilgroup);
528: }
529:
530: sub displayanswers {
531: my ($max,$randomize,@opt)=@_;
532: my @names;
533: if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
534: @names = @{ $Apache::response::foilgroup{'names'} };
535: }
536: return if (!@names);
537: my @whichopt = &whichfoils($max,$randomize);
538: my $result;
539: if ($Apache::lonhomework::type eq 'exam') {
540: my $i = 0;
541: my %opt = map { ($_,$i++) } @opt;
542:
543: $i = 0;
544: my @alphabet = ('A'..'Z');
545: foreach my $name (@whichopt) {
546: $result.=&Apache::response::answer_header('optionresponse',$i++);
547: $result.=&Apache::response::answer_part('optionresponse',
548: $alphabet[$opt{$Apache::response::foilgroup{$name.'.value'}}]);
549: $result.=&Apache::response::answer_part('optionresponse',
550: $Apache::response::foilgroup{$name.'.value'});
551: $result.=&Apache::response::answer_footer('optionresponse');
552: }
553: } else {
554: $result=&Apache::response::answer_header('optionresponse');
555: foreach my $name (@whichopt) {
556: $result.=&Apache::response::answer_part('optionresponse',
557: $Apache::response::foilgroup{$name.'.value'});
558: }
559: $result.=&Apache::response::answer_footer('optionresponse');
560: }
561: return $result;
562: }
563:
564: sub check_box_opt {
565: my ($target,$checkboxvalue,@opt)=@_;
566: # Check if we are in checkbox mode: checkboxvalue specified, on web, only two options.
567: # If so, return "checked" value
568: if ($#opt!=1) { return ''; }
569: unless (($target eq 'web') || ($target eq 'grade')) { return ''; }
570: return $checkboxvalue;
571: }
572:
573: sub check_for_invalid {
574: my ($names,$options) = @_;
575: my %bad_names;
576: foreach my $name (@{ $names }) {
577: my $value=$Apache::response::foilgroup{$name.'.value'};
578: my $found=0;
579: foreach my $option (@{ $options }) {
580: if ($value eq $option) { $found=1; }
581: }
582: if (!$found) { $bad_names{$name}=$value; }
583: }
584: if (%bad_names) {
585: my $error=&mt('The question can not be gotten correct, '.
586: 'the following foils in the <optionresponse> '.
587: 'have invalid correct options').' <br /><tt>'.
588: join('<br />',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))).
589: "</tt>";
590: &Apache::lonxml::error($error);
591: }
592: }
593:
594: sub displayfoils {
595: my ($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,
596: $tex_option_switch, $no_tfprompt, $maxcheck, $mincheck, @opt)=@_;
597: my @names;
598: if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
599: @names = @{ $Apache::response::foilgroup{'names'} };
600: }
601: unless (@names > 0) { return;}
602: my @truelist;
603: my @falselist;
604: my $result;
605: my $name;
606: my $displayoptionintex=1;
607: my @alphabet = ('A'..'Z');
608: my @whichopt = &whichfoils($max,$randomize);
609: unless (($target eq 'tex') && ($tex_option_switch eq 'nochoice')) {
610: &check_for_invalid(\@whichopt,\@opt);
611: }
612: my $part=$Apache::inputtags::part;
613: my $id=$Apache::inputtags::response[-1];
614: my $break;
615: if ( ($target ne 'tex') &&
616: &Apache::response::show_answer() ) {
617: my $temp=1;
618: foreach $name (@whichopt) {
619: my $text=$Apache::response::foilgroup{$name.'.text'};
620: my $lastresp;
621: if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
622: (($env{'form.grade_username'} eq $env{'user.name'}) &&
623: ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
624: $lastresp = $Apache::lonhomework::history{"resource.$part.$id.submission"};
625: } else {
626: unless (($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') ||
627: ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) {
628: $lastresp = $Apache::lonhomework::history{"resource.$part.$id.submission"};
629: }
630: }
631: my %lastresponse=&Apache::lonnet::str2hash($lastresp);
632: my $lastopt=$lastresponse{$name};
633: if ($text!~/^\s*$/) { $break='<br />'; }
634: $result.=$break;
635: if ($target eq 'web') {
636: my $value=$Apache::response::foilgroup{$name.'.value'};
637: if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
638: if ($text=~/^\s*$/) {
639: $text=$value.$text;
640: } else {
641: $text='<b>'.$value.':</b> '.$text;
642: }
643: } else {
644: if (@whichopt > 1) {
645: $text='•'.$text;
646: }
647: }
648: $result.=$text."\n";
649: }
650: if ($Apache::lonhomework::type eq 'exam') {
651: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
652: }
653: $temp++;
654: }
655: } else {
656: my $temp=1;
657: my %lastresponse;
658: my $newvariation;
659: if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
660: ($Apache::lonhomework::type eq 'randomizetry')) &&
661: ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
662: if ($env{'form.'.$part.'.rndseed'} ne
663: $Apache::lonhomework::history{"resource.$part.rndseed"}) {
664: $newvariation = 1;
665: }
666: }
667: unless ($newvariation) {
668: if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
669: (($env{'form.grade_username'} eq $env{'user.name'}) &&
670: ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
671: %lastresponse =
672: &Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
673: } else {
674: unless (($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') ||
675: ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) {
676: %lastresponse =
677: &Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
678: }
679: }
680: }
681: my $internal_counter=$Apache::lonxml::counter;
682: my $checkboxopt;
683: if ($target eq 'web') {
684: $checkboxopt=&check_box_opt($target,$checkboxvalue,@opt);
685: }
686: if ($checkboxopt && (!$no_tfprompt)) {
687: $result.='<br />'.
688: ($checkboxchoices?&mt('Choices: ').'<b>'.$opt[0].','.$opt[1].'</b>. ':'').
689: &mt('Select all that are [_1].','<b>'.$checkboxopt.'</b>');
690: }
691: foreach $name (@whichopt) {
692: my $text=$Apache::response::foilgroup{$name.'.text'};
693: if ($text!~/^\s*$/) {
694: if ($target eq 'tex') {
695: $break='\vskip 0 mm ';
696: } elsif ($target eq 'web') {
697: $break='<br />';
698: }
699: }
700: my $lastopt=$lastresponse{$name};
701: my $optionlist="<option></option>\n";
702:
703: if($target eq 'tex' and $env{'form.pdfFormFields'} eq 'yes'
704: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
705: my $fieldname = $env{'request.symb'}.'&part_'.$Apache::inputtags::part.'&optionresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp;
706: $optionlist = &Apache::lonxml::print_pdf_start_combobox($fieldname);
707: }
708:
709: foreach my $option (@opt) {
710: my $escopt=&HTML::Entities::encode($option,'\'"&<>');
711: if ($option eq $lastopt) {
712: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
713: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
714: && $Apache::lonhomework::type ne 'exam') {
715: $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
716: } else {
717: $optionlist.="<option value='".$escopt."' selected=\"selected\">$option</option>\n";
718: }
719: } else {
720: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
721: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
722: && $Apache::lonhomework::type ne 'exam') {
723: $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
724: } else {
725: $optionlist.="<option value='".$escopt."'>$option</option>\n";
726: }
727: }
728: }
729: if ($target ne 'tex') {
730: if ($Apache::lonhomework::type ne 'exam') {
731: # we are on the web, this is not an exam, and the problem can be answered
732: if ($checkboxopt) {
733: # generate checkboxes
734: my $fieldname=$Apache::inputtags::response['-1'].':'.$temp;
735: my $altopt=$opt[0];
736: if ($opt[0] eq $checkboxopt) {
737: $altopt=$opt[1];
738: }
739: my $defopt=$lastopt;
740: unless ($defopt) { $defopt=$altopt; }
741: my $escdefopt=&HTML::Entities::encode($defopt,'\'"&<>');
742: my $esccheckboxopt=&HTML::Entities::encode($checkboxopt,'\'"&<>');
743: my $escaltopt=&HTML::Entities::encode($altopt,'\'"&<>');
744: # checkboxopt is how the box is labelled
745: # altopt is the alternative option
746: # lastopt is what the user submitted before
747: # defopt is what the field is going to start out with: either previous choice or altopt
748: # fieldname is this input field's name after HWVAL_
749: $optionlist='<input type="hidden" name="HWVAL_'.$fieldname.'" value="'.$escdefopt.'" />'.
750: '<input type="checkbox" name="HWCHK_'.$fieldname.'" onclick="javascript:if (this.form.elements[\'HWCHK_'.
751: $fieldname.'\'].checked) { this.form.elements[\'HWVAL_'.$fieldname.'\'].value=\''.$esccheckboxopt.'\'; } else { this.form.elements[\'HWVAL_'.$fieldname.'\'].value=\''.$escaltopt.'\'; };setSubmittedPart(\''.$part.'\');"'.($defopt eq $checkboxopt?' checked="checked"':'')." />\n";
752: } else {
753: # classic selection list
754: $optionlist='<select onchange="javascript:setSubmittedPart(\''.
755: $part.'\');" name="HWVAL_'.
756: $Apache::inputtags::response['-1'].':'.$temp.'">'.
757: $optionlist."</select>\n";
758: }
759: } else {
760: $optionlist='<u>'.(' 'x10).'</u>';
761: }
762: if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
763: if ($Apache::lonhomework::type ne 'exam') {
764: if (@whichopt > 1) {
765: $text='•'.$text;
766: }
767: }
768: } else {
769: if ($Apache::lonhomework::type ne 'exam') {
770: $text=$optionlist.$text;
771: }
772: }
773: $result.=$break.$text."\n";
774: if ($Apache::lonhomework::type eq 'exam') {
775: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
776: }
777: $temp++;
778: } else {
779: my $texoptionlist='';
780: if ($displayoptionintex &&
781: $Apache::lonhomework::type ne 'exam') {
782: $texoptionlist = &optionlist_correction($TeXlayout,@opt);
783: }
784: if ($text=~/<drawoptionlist\s*\/>/) {
785: $text=~s|<drawoptionlist\s*\/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |g;
786: }
787:
788: if ($text=~m/\\item /) {
789: if ($Apache::lonhomework::type eq 'exam') {
790: $text=~s/\\item/\\vskip 2 mm/;
791: } elsif ($env{'form.pdfFormFields'} ne 'yes') {
792: $result.= $texoptionlist.$text;
793: }
794: } else {
795: if ($Apache::lonhomework::type eq 'exam') {
796: $result.= $texoptionlist.' '.$text;
797: } elsif ($env{'form.pdfFormFields'} ne 'yes') {
798: if ($text=~/\S/) {
799: $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
800: } else {
801: $result.= $texoptionlist;
802: }
803: }
804: }
805: if ($Apache::lonhomework::type eq 'exam') {
806: $result.='\vskip -1 mm\noindent';
807: my ($numrows,$bubbles_per_row) = &getnumrows(scalar(@opt));
808: if ($numrows == 1) {
809: $result .= '\textbf{'.$internal_counter.'}. \vskip -3mm';
810: } else {
811: my $linetext;
812: for (my $i=0; $i<$numrows; $i++) {
813: $linetext .= $internal_counter+$i.', ';
814: }
815: $linetext =~ s/,\s$//;
816: $result .= '\small {\textbf{'.$linetext.'}} '.
817: '\hskip 2 mm {\footnotesize '.
818: &mt('(Bubble once in [_1] lines)',$numrows).
819: '} \vskip 1 mm';
820: }
821: $result.= &bubbles(\@alphabet,\@opt,undef,undef,$numrows,
822: $bubbles_per_row,$internal_counter).
823: ' \strut ';
824: $internal_counter += $numrows;
825: }
826: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
827: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
828: && $Apache::lonhomework::type ne 'exam') {
829: $text =~ s/\\item//m;
830: $result .= " $optionlist ". &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
831: $temp++;
832: }
833: $displayoptionintex=0;
834: }
835: }
836: }
837:
838: if ($target eq 'web') {
839: my $data = [\@whichopt,'submissiongrading'];
840: my $questiontype;
841: if ($Apache::lonhomework::type eq 'randomizetry') {
842: $questiontype = $Apache::lonhomework::type,
843: }
844: &Apache::response::setup_prior_tries_hash(\&Apache::rankresponse::format_prior_answer,$data,$questiontype);
845: }
846:
847: if ($target ne 'tex') {
848: return $result.$break;
849: } else {
850: return $result;
851: }
852: }
853:
854:
855: sub optionlist_correction {
856: my ($TeXlayout,@options) = @_;
857: my $texoptionlist='\\item [] '.&mt('Choices:').' ';
858: if ($TeXlayout eq 'vertical') {$texoptionlist='\\item []';}
859: if (scalar(@options) > 0) {
860: foreach my $option (@options) {
861: $texoptionlist.='{\bf '.
862: &Apache::lonxml::latex_special_symbols($option).
863: '}';
864: if ($TeXlayout eq 'vertical') {
865: $texoptionlist.=' \vskip 0 mm ',
866: } else {
867: $texoptionlist.=', ';
868: }
869: }
870: $texoptionlist=~s/, $//;
871: if ($TeXlayout ne 'vertical') {$texoptionlist.='.';}
872: } else {
873: if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';}
874: }
875: return $texoptionlist;
876: }
877:
878:
879: sub webbubbles {
880: my ($ropt,$ralphabet,$temp,$lastopt)=@_;
881: my @opt=@$ropt;
882: my @alphabet=@$ralphabet;
883: my $result='';
884: my $number_of_bubbles = $#opt + 1;
885: $result.= '<table border="1"><tr>';
886: for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
887: my $checked='';
888: if ($lastopt eq $opt[$ind]) {
889: $checked=' checked="on" ';
890: }
891: $result.='<td><input type="radio" name="HWVAL_'.
892: $Apache::inputtags::response['-1'].':'.$temp.
893: '" value="'.$opt[$ind].'" '.$checked.' />';
894: if ($alphabet[$ind]) {
895: $result.=$alphabet[$ind].': ';
896: }
897: $result.=$opt[$ind].'</td>';
898: }
899: $result.='</tr></table>';
900: return $result;
901: }
902:
903:
904: sub bubbles {
905: my ($ralphabet,$ropt,$response,$max_width,$numrows,$bubbles_per_row,
906: $internal_counter) = @_;
907: my @alphabet = @$ralphabet;
908: my @opt = @$ropt;
909: my ($result,$head,$line) =('','','');
910: my $number_of_bubbles = $#opt + 1;
911: my $current_length = 0;
912: my $textwidth;
913: if (defined($max_width)) {
914: $textwidth=$max_width;
915: &Apache::lonxml::debug("Max width passed in: $max_width");
916: } elsif ($env{'form.textwidth'} ne '') {
917: $env{'form.textwidth'}=~/(\d+)/;
918: $textwidth=$1;
919: &Apache::lonxml::debug("Max width from form: $textwidth");
920: } else {
921: $env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
922: $textwidth=$1.'.'.$2;
923: &Apache::lonxml::debug("Max width defaults? $textwidth");
924: }
925: &Apache::lonxml::debug("Final maxwidth: $textwidth");
926: for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
927: my $item;
928: if ($numrows > 1) {
929: my $num = $internal_counter+int($ind/$bubbles_per_row);
930: my $idx = int($ind % $bubbles_per_row);
931: $item = $num.$alphabet[$idx];
932: } else {
933: $item = $alphabet[$ind];
934: }
935: my $leftmargin;
936: $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
937: if ($response eq 'rankresponse') {$opt[$ind]='Rank '.$opt[$ind];}
938: if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
939:
940: $current_length += (length($opt[$ind])+length($item)+5)*2;
941:
942: if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
943:
944: $line.='\hskip 4 mm {\small \textbf{'.$item.'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
945: $head.='lr';
946: } else {
947: $line=~s/\&\s*$//;
948: $result.='\vskip -1 mm\noindent\setlength{\tabcolsep}{2 mm}\renewcommand{\arraystretch}{1.25}\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm';
949: $line = '\hskip 4 mm {\small \textbf{'.$item.'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
950: $head ='lr';
951: $current_length = (length($opt[$ind])+length($item))*2;
952: }
953:
954: }
955: return $result;
956: }
957:
958: sub start_conceptgroup {
959: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
960: $Apache::optionresponse::conceptgroup=1;
961: %Apache::response::conceptgroup=();
962: my $result;
963: if ($target eq 'edit') {
964: $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
965: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
966: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
967: }
968: if ($target eq 'modified') {
969: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
970: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
971: }
972: return $result;
973: }
974:
975: sub end_conceptgroup {
976: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
977: $Apache::optionresponse::conceptgroup=0;
978: my $result='';
979: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
980: $target eq 'tex' || $target eq 'analyze') {
981: #if not there aren't any foils to display and thus no question
982: &Apache::response::pick_foil_for_concept($target,
983: ['value','text','location'],
984: \%Apache::hint::option,
985: $parstack,$safeeval);
986: } elsif ($target eq 'edit') {
987: $result=&Apache::edit::end_table();
988: }
989: return $result;
990: }
991:
992: sub insert_conceptgroup {
993: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
994: return $result;
995: }
996:
997: sub start_foil {
998: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
999: my $result='';
1000: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
1001: &Apache::lonxml::startredirection;
1002: if ($target eq 'analyze') {
1003: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
1004: }
1005: } elsif ($target eq 'edit') {
1006: $result=&Apache::edit::tag_start($target,$token,"Foil");
1007: my $level='-2';
1008: if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
1009: my @opt;
1010: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
1011: $result.=&Apache::edit::text_arg('Name:','name',$token);
1012: $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
1013: ['unused',(@opt)],$token,'15');
1014: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
1015: $safeeval,'-3');
1016: if ($randomize ne 'no') {
1017: $result.=&Apache::edit::select_arg('Location:','location',
1018: ['random','top','bottom'],$token);
1019: }
1020: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1021: } elsif ($target eq 'modified') {
1022: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
1023: 'value','name','location');
1024: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1025: }
1026: return $result;
1027: }
1028:
1029: sub end_foil {
1030: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1031: my $text ='';
1032: my $result = '';
1033: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1034: $text=&Apache::lonxml::endredirection;
1035: if ($target eq 'tex') {$text=~s/\\strut\s*\\\\\s*\\strut/\\vskip 0 mm/;}
1036: if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;}
1037: }
1038: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
1039: || $target eq 'tex' || $target eq 'analyze') {
1040: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
1041: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
1042: $text='\vskip 5mm $\triangleright$ '.$text;
1043: }
1044: if ($value ne 'unused') {
1045: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
1046: &Apache::lonxml::debug("Got a name of :$name:");
1047: if ($name eq "") {
1048: &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
1049: $name=$Apache::lonxml::curdepth;
1050: }
1051: &Apache::lonxml::debug("Using a name of :$name:");
1052: if (defined($Apache::response::foilnames{$name})) {
1053: &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",'<b><tt>'.$name.'</tt></b>'));
1054: }
1055: $Apache::response::foilnames{$name}++;
1056: my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
1057: if ( $Apache::optionresponse::conceptgroup
1058: && !&Apache::response::showallfoils() ) {
1059: push @{ $Apache::response::conceptgroup{'names'} }, $name;
1060: $Apache::response::conceptgroup{"$name.value"} = $value;
1061: $Apache::response::conceptgroup{"$name.text"} = $text;
1062: $Apache::response::conceptgroup{"$name.location"} = $location;
1063: } else {
1064: push @{ $Apache::response::foilgroup{'names'} }, $name;
1065: $Apache::response::foilgroup{"$name.value"} = $value;
1066: $Apache::response::foilgroup{"$name.text"} = $text;
1067: $Apache::response::foilgroup{"$name.location"} = $location;
1068: }
1069: }
1070: }
1071: if ($target eq 'edit') {
1072: $result.= &Apache::edit::tag_end($target,$token,'');
1073: }
1074: return $result;
1075: }
1076:
1077: sub start_drawoptionlist {
1078: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1079: if ($target !~ /^(?:meta|answer|modified|edit)$/) {
1080: return $token->[4];
1081: }
1082: }
1083:
1084: sub end_drawoptionlist {
1085: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1086: if ($target !~ /^(?:meta|answer|modified|edit)$/) {
1087: return $token->[2];
1088: }
1089: }
1090:
1091: sub insert_foil {
1092: return '
1093: <foil name="" value="unused">
1094: <startouttext />
1095: <endouttext />
1096: </foil>';
1097: }
1098:
1099: sub insert_drawoptionlist {
1100: return '<drawoptionlist />';
1101: }
1102:
1103: sub getnumrows {
1104: my ($numitems) = @_;
1105: my $bubbles_per_row;
1106: my $default_numbubbles = 10;
1107: if (($env{'form.bubbles_per_row'} =~ /^\d+$/) &&
1108: ($env{'form.bubbles_per_row'} > 0)) {
1109: $bubbles_per_row = $env{'form.bubbles_per_row'};
1110: } else {
1111: $bubbles_per_row = $default_numbubbles;
1112: }
1113: my $numrows = int ($numitems/$bubbles_per_row);
1114: if (($numitems % $bubbles_per_row) != 0) {
1115: $numrows ++;
1116: }
1117: return ($numrows,$bubbles_per_row);
1118: }
1119:
1120: 1;
1121: __END__
1122:
1123: =head1 NAME
1124:
1125: Apache::optionresponse.pm;
1126:
1127: =head1 SYNOPSIS
1128:
1129: Handles tags associated with showing a list of
1130: options.
1131:
1132: This is part of the LearningOnline Network with CAPA project
1133: described at http://www.lon-capa.org.
1134:
1135: =head1 HANDLER SUBROUTINE
1136:
1137: start_optionresponse()
1138:
1139: =head1 OTHER SUBROUTINES
1140:
1141: =over
1142:
1143: =item end_optionresponse()
1144:
1145: =item start_foilgroup()
1146:
1147: =item end_foilgroup()
1148:
1149: =item getfoilcounts()
1150:
1151: =item displayanswers()
1152:
1153: =item check_for_invalid()
1154:
1155: =item displayfoils()
1156:
1157: =item optionlist_correction()
1158:
1159: =item webbubbles()
1160:
1161: =item bubbles()
1162:
1163: =item start_conceptgroup()
1164:
1165: =item end_conceptgroup()
1166:
1167: =item insert_conceptgroup()
1168:
1169: =item start_foil()
1170:
1171: =item end_foil()
1172:
1173: =item start_drawoptionlist()
1174:
1175: =item end_drawoptionlist()
1176:
1177: =item insert_foil()
1178:
1179: =item insert_drawoptionlist()
1180:
1181: =back
1182:
1183: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>