Annotation of loncom/homework/optionresponse.pm, revision 1.183
1.46 sakharuk 1: # LearningOnline Network with CAPA
1.22 albertel 2: # option list style responses
1.27 albertel 3: #
1.183 ! raeburn 4: # $Id: optionresponse.pm,v 1.182 2011/11/08 05:19:14 raeburn Exp $
1.27 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.154 jms 28:
29:
30:
31:
32:
1.1 albertel 33: package Apache::optionresponse;
34: use strict;
1.183 ! raeburn 35: use Apache::inputtags();
1.103 albertel 36: use Apache::response();
37: use Apache::lonlocal;
1.125 albertel 38: use Apache::lonnet;
1.1 albertel 39:
1.31 harris41 40: BEGIN {
1.1 albertel 41: &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
42: }
43:
44: sub start_optionresponse {
1.22 albertel 45: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
46: my $result='';
1.29 albertel 47: #when in a option response use these
1.112 sakharuk 48: &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
1.22 albertel 49: push (@Apache::lonxml::namespace,'optionresponse');
50: my $id = &Apache::response::start_response($parstack,$safeeval);
1.57 albertel 51: %Apache::hint::option=();
1.103 albertel 52: undef(%Apache::response::foilnames);
1.22 albertel 53: if ($target eq 'edit') {
1.153 bisitz 54: $result.=&Apache::edit::start_table($token)
55: .'<tr><td><span class="LC_nobreak">'.&mt('Multiple Option Response Question').'</span> '
56: .&Apache::loncommon::help_open_topic('Option_Response_Problems')."</td>"
57: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
58: .&Apache::edit::deletelist($target,$token)
59: .'</span></td>'
60: ."<td> "
61: .&Apache::edit::end_row()
62: .&Apache::edit::start_spanning_row()
63: ."\n";
1.48 albertel 64: $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max',
65: $token,'4').
1.153 bisitz 66: &Apache::edit::select_arg('Randomize Foil Order:','randomize',
1.48 albertel 67: ['yes','no'],$token).
1.108 albertel 68: &Apache::edit::select_arg(&mt('Display of options when printed'),'TeXlayout',
1.157 raeburn 69: [['horizontal','Normal list'],
70: ['vertical','Listed in a vertical column']],$token).
1.48 albertel 71: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.34 albertel 72: } elsif ($target eq 'modified') {
1.23 albertel 73: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.108 albertel 74: $safeeval,'max','randomize',
75: 'TeXlayout');
1.22 albertel 76: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.34 albertel 77: } elsif ($target eq 'meta') {
1.23 albertel 78: $result=&Apache::response::meta_package_write('optionresponse');
1.34 albertel 79: } elsif ($target eq 'analyze') {
1.93 albertel 80: my $part_id="$Apache::inputtags::part.$id";
1.149 raeburn 81: $Apache::lonhomework::analyze{"$part_id.type"} = 'optionresponse';
1.34 albertel 82: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.148 raeburn 83: push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} }, 1);
1.145 foxr 84:
1.22 albertel 85: }
86: return $result;
1.1 albertel 87: }
88:
89: sub end_optionresponse {
1.22 albertel 90: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
91: &Apache::response::end_response;
92: pop @Apache::lonxml::namespace;
1.112 sakharuk 93: &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
1.22 albertel 94: my $result;
95: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
1.103 albertel 96: undef(%Apache::response::foilnames);
1.22 albertel 97: return $result;
1.1 albertel 98: }
99:
1.44 albertel 100: %Apache::response::foilgroup=();
1.1 albertel 101: sub start_foilgroup {
1.22 albertel 102: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
103:
104: my $result='';
1.44 albertel 105: %Apache::response::foilgroup=();
1.22 albertel 106: $Apache::optionresponse::conceptgroup=0;
1.173 raeburn 107: &Apache::response::pushrandomnumber(undef,$target);
1.22 albertel 108: if ($target eq 'edit') {
109: my $optionlist="<option></option>\n";
110: my $option;
111: my @opt;
112: eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval);
113: my $count=1;
114: foreach $option (@opt) {
115: $optionlist.="<option value=\"$count\">$option</option>\n";
116: $count++;
117: }
118: my $insertlist=&Apache::edit::insertlist($target,$token);
119: $result.=&Apache::edit::start_table($token);
120: $result.= (<<ENDTABLE);
121: <tr><td>Select Options</td>
1.13 albertel 122: <td>
123: Add new Option: <input type="text" name="$Apache::lonxml::curdepth.options" />
124: </td>
125: <td>Delete an Option:
126: <select name="$Apache::lonxml::curdepth.deleteopt">$optionlist</select>
1.162 www 127: </td>
1.13 albertel 128: ENDTABLE
1.162 www 129: $result.= '<td>'.&Apache::edit::checked_arg('Print options:','texoptions',
1.132 albertel 130: [ ['nochoice','Don\'t show option list'] ]
1.162 www 131: ,$token).'</td>';
132: $result.= '<td><label>'.&mt('Two-option checkboxes for:').
133: '<select name="checkboxvalue_'.$Apache::lonxml::curdepth.'">';
134: foreach $option (('',@opt)) {
135: $result.='<option value="'.$option.'"';
136: if ($option eq &Apache::lonxml::get_param('checkboxvalue',$parstack,$safeeval)) {
137: $result.=' selected="selected"';
138: }
139: $result.='>'.$option.'</option>';
140: }
1.172 www 141: $result.='</select></label>';
142: $result.=&Apache::edit::checked_arg('Checkbox options:','checkboxoptions',
143: [ ['nochoice','Don\'t show option list'] ]
144: ,$token).'</td>';
1.30 matthew 145: $result.= &Apache::edit::end_row();
146: $result.= &Apache::edit::start_spanning_row();
147: $result.= $insertlist.'<br />';
1.22 albertel 148: }
149: if ($target eq 'modified') {
150: my @options;
151: my $optchanged=0;
152: eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.125 albertel 153: if ($env{"form.$Apache::lonxml::curdepth.deleteopt"}) {
154: my $delopt=$env{"form.$Apache::lonxml::curdepth.deleteopt"};
1.22 albertel 155: &Apache::lonxml::debug("Deleting :$delopt:");
156: splice(@options,$delopt-1,1);
157: $optchanged=1;
158: }
1.180 raeburn 159: if ($env{"form.$Apache::lonxml::curdepth.options"} ne '') {
1.125 albertel 160: my $newopt = $env{"form.$Apache::lonxml::curdepth.options"};
1.180 raeburn 161: push(@options,$newopt);
1.22 albertel 162: $optchanged=1;
163: }
1.132 albertel 164: my $rebuildtag = &Apache::edit::get_new_args($token,$parstack,$safeeval,
1.172 www 165: 'texoptions','checkboxvalue','checkboxoptions');
1.132 albertel 166: if ($optchanged || $rebuildtag ) {
1.22 albertel 167: $result = "<foilgroup options=\"(";
168: foreach my $option (@options) {
1.41 albertel 169: $option=~s/\'/\\\'/g;
1.22 albertel 170: &Apache::lonxml::debug("adding option :$option:");
171: $result .="'".$option."',";
172: }
173: chop $result;
1.132 albertel 174: $result.=')" ';
175: $result .= 'texoptions="'.$token->[2]{'texoptions'}.'" ';
1.172 www 176: $result .= 'checkboxoptions="'.$token->[2]{'checkboxoptions'}.'" ';
1.162 www 177: $result .= 'checkboxvalue="'.$token->[2]{'checkboxvalue'}.'"';
1.132 albertel 178: $result .= '>';
1.22 albertel 179: } # else nothing changed so just use the default mechanism
180: }
1.68 sakharuk 181: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.152 onken 182: if($env{'form.pdfFormFields'} ne 'yes') {
1.167 raeburn 183: $result .= ' \begin{itemize} ';
1.152 onken 184: } else {
185: $result .= "\\\\";
186: }
1.42 sakharuk 187: }
1.22 albertel 188: return $result;
1.1 albertel 189: }
190:
191: sub end_foilgroup {
1.22 albertel 192: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
193:
194: my $result;
1.94 albertel 195: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
196: $target eq 'tex' || $target eq 'analyze') {
1.81 sakharuk 197: my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
1.22 albertel 198: my $name;
199: my @opt;
200: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.126 albertel 201: &Apache::lonxml::debug("options:".join(':',@opt));
202:
1.108 albertel 203: my $TeXlayout=&Apache::lonxml::get_param('TeXlayout',$parstack,$safeeval,
204: -2,0);
1.161 www 205: my $checkboxvalue=&Apache::lonxml::get_param('checkboxvalue',$parstack,$safeeval);
1.172 www 206: my $checkboxchoices=(&Apache::lonxml::get_param('checkboxoptions',$parstack,$safeeval) ne 'nochoice');
1.81 sakharuk 207: if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
1.22 albertel 208: &Apache::lonxml::debug("Options are $#opt");
1.48 albertel 209: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
210: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
211: $safeeval,'-2');
1.32 sakharuk 212: if ($target eq 'web' || $target eq 'tex') {
1.182 raeburn 213: $result.=&displayfoils($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,$tex_option_switch,@opt);
1.137 albertel 214: $Apache::lonxml::post_evaluate=0;
1.25 albertel 215: } elsif ( $target eq 'answer') {
1.48 albertel 216: $result.=&displayanswers($max,$randomize,@opt);
1.136 foxr 217:
1.34 albertel 218: } elsif ( $target eq 'analyze') {
1.93 albertel 219: my @shown = &whichfoils($max,$randomize);
1.94 albertel 220: &Apache::response::analyze_store_foilgroup(\@shown,
221: ['text','value','location']);
1.93 albertel 222: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
223: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
1.22 albertel 224: } elsif ( $target eq 'grade') {
1.175 www 225:
1.124 albertel 226: if ( &Apache::response::submitted()) {
1.175 www 227:
1.48 albertel 228: my @whichopt = &whichfoils($max,$randomize);
1.22 albertel 229: my $temp=1;my $name;
1.26 albertel 230: my %responsehash;
1.57 albertel 231: my %grade;
1.22 albertel 232: my $right=0;
233: my $wrong=0;
234: my $ignored=0;
1.177 raeburn 235: my ($numrows,$bubbles_per_row);
236: if ($Apache::lonhomework::scantronmode) {
237: my $numitems = scalar(@opt);
238: ($numrows,$bubbles_per_row) =
239: &Apache::optionresponse::getnumrows($numitems);
240: }
241: if ($numrows < 1) {
242: $numrows = 1;
243: }
1.22 albertel 244: foreach $name (@whichopt) {
1.177 raeburn 245: my $response;
246: if ($env{'form.submitted'} eq 'scantron') {
247: if ($numrows > 1) {
248: my $num = $temp;
249: my $totalnum;
250: for (my $i=0; $i<$numrows; $i++) {
251: my $item = &Apache::response::getresponse($num);
252: if ($item =~ /^\d+$/) {
253: $totalnum = $i*$bubbles_per_row + $item;
254: }
255: $num ++;
256: }
257: if ($totalnum =~ /^\d+$/) {
258: $response = $opt[$totalnum];
259: }
260: $temp += $numrows;
261: } else {
1.178 raeburn 262: $response=&Apache::response::getresponse($temp);
1.177 raeburn 263: if ($response=~/\S/) {
264: $response = $opt[$response];
265: }
266: $temp ++;
267: }
268: } else {
1.178 raeburn 269: $response=&Apache::response::getresponse($temp);
1.177 raeburn 270: $temp ++;
271: }
1.22 albertel 272: if ( $response =~ /[^\s]/) {
1.96 albertel 273: $responsehash{$name}=$response;
1.22 albertel 274: my $value=$Apache::response::foilgroup{$name.'.value'};
1.34 albertel 275: &Apache::lonxml::debug("submitted a $response for $value<br />\n");
1.57 albertel 276: if ($value eq $response) {
277: $grade{$name}='1'; $right++;
278: } else {
279: $grade{$name}='0'; $wrong++;
280: }
1.22 albertel 281: } else {
282: $ignored++;
283: }
284: }
1.28 albertel 285: my $part=$Apache::inputtags::part;
1.183 ! raeburn 286: my $nonlenient=&Apache::inputtags::grading_is_nonlenient($part);
1.22 albertel 287: my $id = $Apache::inputtags::response['-1'];
1.28 albertel 288: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
1.57 albertel 289: my $gradestr =&Apache::lonnet::hash2str(%grade);
1.28 albertel 290: my %previous=&Apache::response::check_for_previous($responsestr,
291: $part,$id);
1.22 albertel 292: &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
1.75 albertel 293: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
294: $responsestr;
295: $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
1.173 raeburn 296: if ($Apache::lonhomework::type eq 'randomizetry') {
297: $Apache::lonhomework::results{"resource.$part.$id.foilorder"} = &Apache::lonnet::array2str(@whichopt);
298: }
1.163 raeburn 299: if (($Apache::lonhomework::type eq 'survey') ||
300: ($Apache::lonhomework::type eq 'surveycred') ||
301: ($Apache::lonhomework::type eq 'anonsurvey') ||
302: ($Apache::lonhomework::type eq 'anonsurveycred')) {
1.121 albertel 303: if ($ignored == 0) {
1.163 raeburn 304: my $ad;
305: if ($Apache::lonhomework::type eq 'anonsurveycred') {
306: $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CREDIT';
307: } elsif ($Apache::lonhomework::type eq 'anonsurvey') {
308: $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
309: } elsif ($Apache::lonhomework::type eq 'surveycred') {
310: $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
311: } else {
312: $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
313: }
1.121 albertel 314: &Apache::response::handle_previous(\%previous,$ad);
315: } elsif ($wrong==0 && $right==0) {
316: } else {
317: my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='MISSING_ANSWER';
318: &Apache::response::handle_previous(\%previous,$ad);
319: }
1.174 www 320: } elsif ($nonlenient) {
321: #
322: # Non-lenient mode. All right or all wrong
323: #
1.75 albertel 324: my $ad;
325: if ($wrong==0 && $ignored==0) {
326: $ad='EXACT_ANS';
327: } elsif ($wrong==0 && $right==0) {
328: #nothing submitted
329: } else {
330: if ($ignored==0) {
331: $ad='INCORRECT';
332: } else {
333: $ad='MISSING_ANSWER';
334: }
335: }
336: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
337: &Apache::response::handle_previous(\%previous,$ad);
1.22 albertel 338: } else {
1.174 www 339: #
340: # This is lenient mode
341: #
1.75 albertel 342: my $ad;
343: if ($wrong==0 && $right==0) {
1.120 albertel 344: #nothing submitted only assign a score if we
345: #need to override a previous grade
346: if (defined($Apache::lonhomework::history{"resource.$part.$id.awarddetail"})) {
347: $ad='ASSIGNED_SCORE';
348: }
1.75 albertel 349: } else {
350: $ad='ASSIGNED_SCORE';
351: }
352: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
353: $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
354: $right/(scalar(@whichopt));
1.76 albertel 355: $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
356: scalar(@whichopt);
1.1 albertel 357: }
1.22 albertel 358: }
1.1 albertel 359: }
1.147 foxr 360: my $part_id = $Apache::inputtags::part;
361: my $response_id = $Apache::inputtags::response[-1];
1.177 raeburn 362: my ($numrows,$bubbles_per_row);
363: if (($target eq 'tex') && ($Apache::lonhomework::type eq 'exam')) {
364: ($numrows,$bubbles_per_row) =
365: &Apache::optionresponse::getnumrows(scalar(@opt));
366: }
367: if ($numrows < 1) {
368: $numrows = 1;
369: }
370: my $increment = &getfoilcounts($max) * $numrows;
371: &Apache::lonxml::increment_counter($increment,"$part_id.$response_id");
1.146 foxr 372: if ($target eq 'analyze') {
373: &Apache::lonhomework::set_bubble_lines();
374: }
375:
1.25 albertel 376: } elsif ($target eq 'edit') {
1.22 albertel 377: $result.=&Apache::edit::end_table();
1.74 albertel 378: }
379: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.152 onken 380: if($env{'form.pdfFormFields'} ne 'yes') {
1.167 raeburn 381: $result .= '\end{itemize}';
1.152 onken 382: } else {
383: $result .= "\\\\";
384: }
1.74 albertel 385: }
1.110 albertel 386: &Apache::response::poprandomnumber();
1.22 albertel 387: return $result;
1.1 albertel 388: }
389:
390: sub getfoilcounts {
1.48 albertel 391: my ($max)=@_;
1.22 albertel 392: # +1 since instructors will count from 1
393: my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
1.39 albertel 394: if (&Apache::response::showallfoils()) { $max=$count; }
1.48 albertel 395: if ($count>$max) { $count=$max }
396: &Apache::lonxml::debug("Count is $count from $max");
397: return $count;
1.1 albertel 398: }
399:
400: sub whichfoils {
1.77 albertel 401: my ($max,$randomize)=@_;
402: return &Apache::response::whichorder($max,$randomize,
403: &Apache::response::showallfoils(),
404: \%Apache::response::foilgroup);
1.1 albertel 405: }
406:
1.25 albertel 407: sub displayanswers {
1.130 albertel 408: my ($max,$randomize,@opt)=@_;
409: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
410: my @names = @{ $Apache::response::foilgroup{'names'} };
411: my @whichopt = &whichfoils($max,$randomize);
412: my $result;
413: if ($Apache::lonhomework::type eq 'exam') {
414: my $i = 0;
415: my %opt = map { ($_,$i++) } @opt;
416:
417: $i = 0;
418: my @alphabet = ('A'..'Z');
419: foreach my $name (@whichopt) {
420: $result.=&Apache::response::answer_header('optionresponse',$i++);
421: $result.=&Apache::response::answer_part('optionresponse',
422: $alphabet[$opt{$Apache::response::foilgroup{$name.'.value'}}]);
423: $result.=&Apache::response::answer_part('optionresponse',
424: $Apache::response::foilgroup{$name.'.value'});
425: $result.=&Apache::response::answer_footer('optionresponse');
426: }
427: } else {
428: $result=&Apache::response::answer_header('optionresponse');
429: foreach my $name (@whichopt) {
430: $result.=&Apache::response::answer_part('optionresponse',
431: $Apache::response::foilgroup{$name.'.value'});
432: }
433: $result.=&Apache::response::answer_footer('optionresponse');
434: }
435: return $result;
1.25 albertel 436: }
437:
1.160 www 438: sub check_box_opt {
1.161 www 439: my ($target,$checkboxvalue,@opt)=@_;
440: # Check if we are in checkbox mode: checkboxvalue specified, on web, only two options.
441: # If so, return "checked" value
442: if ($#opt!=1) { return ''; }
443: if ($target ne 'web') { return ''; }
444: return $checkboxvalue;
1.160 www 445: }
446:
1.106 albertel 447: sub check_for_invalid {
448: my ($names,$options) = @_;
449: my %bad_names;
450: foreach my $name (@{ $names }) {
451: my $value=$Apache::response::foilgroup{$name.'.value'};
452: my $found=0;
453: foreach my $option (@{ $options }) {
454: if ($value eq $option) { $found=1; }
455: }
456: if (!$found) { $bad_names{$name}=$value; }
457: }
458: if (%bad_names) {
459: my $error=&mt('The question can not be gotten correct, '.
460: 'the following foils in the <optionresponse> '.
461: 'have invalid correct options').' <br /><tt>'.
462: join('<br />',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))).
463: "</tt>";
464: &Apache::lonxml::error($error);
465: }
466: }
467:
1.1 albertel 468: sub displayfoils {
1.182 raeburn 469: my ($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,
470: $tex_option_switch,@opt)=@_;
1.67 albertel 471: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
1.22 albertel 472: my @names = @{ $Apache::response::foilgroup{'names'} };
473: my @truelist;
474: my @falselist;
1.79 sakharuk 475: my $result;
1.22 albertel 476: my $name;
1.101 albertel 477: my $displayoptionintex=1;
1.72 sakharuk 478: my @alphabet = ('A'..'Z');
1.48 albertel 479: my @whichopt = &whichfoils($max,$randomize);
1.182 raeburn 480: unless (($target eq 'tex') && ($tex_option_switch eq 'nochoice')) {
481: &check_for_invalid(\@whichopt,\@opt);
482: }
1.28 albertel 483: my $part=$Apache::inputtags::part;
484: my $id=$Apache::inputtags::response[-1];
1.62 albertel 485: my $break;
1.86 albertel 486: if ( ($target ne 'tex') &&
487: &Apache::response::show_answer() ) {
1.90 albertel 488: my $temp=1;
1.22 albertel 489: foreach $name (@whichopt) {
1.62 albertel 490: my $text=$Apache::response::foilgroup{$name.'.text'};
1.163 raeburn 491: my $lastresp;
492: unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) {
493: $lastresp = $Apache::lonhomework::history{"resource.$part.$id.submission"};
494: }
495: my %lastresponse=&Apache::lonnet::str2hash($lastresp);
1.90 albertel 496: my $lastopt=$lastresponse{$name};
1.101 albertel 497: if ($text!~/^\s*$/) { $break='<br />'; }
1.62 albertel 498: $result.=$break;
1.113 sakharuk 499: if ($target eq 'web') {
1.62 albertel 500: my $value=$Apache::response::foilgroup{$name.'.value'};
501: if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
502: if ($text=~/^\s*$/) {
503: $text=$value.$text;
504: } else {
1.127 albertel 505: $text='<b>'.$value.':</b> '.$text;
1.62 albertel 506: }
1.95 albertel 507: } else {
1.170 raeburn 508: if (@whichopt > 1) {
509: $text='•'.$text;
510: }
1.62 albertel 511: }
512: $result.=$text."\n";
1.112 sakharuk 513: }
1.58 sakharuk 514: if ($Apache::lonhomework::type eq 'exam') {
1.90 albertel 515: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
1.58 sakharuk 516: }
1.90 albertel 517: $temp++;
1.22 albertel 518: }
519: } else {
520: my $temp=1;
1.173 raeburn 521: my %lastresponse;
522: my $newvariation;
523: if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
524: ($Apache::lonhomework::type eq 'randomizetry')) &&
525: ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
526: if ($env{'form.'.$part.'.rndseed'} ne
527: $Apache::lonhomework::history{"resource.$part.rndseed"}) {
528: $newvariation = 1;
529: }
530: }
531: unless ($newvariation) {
532: %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
533: }
1.79 sakharuk 534: my $internal_counter=$Apache::lonxml::counter;
1.161 www 535: my $checkboxopt=&check_box_opt($target,$checkboxvalue,@opt);
1.160 www 536: if ($checkboxopt) {
1.172 www 537: $result.='<br />'.
538: ($checkboxchoices?&mt('Choices: ').'<b>'.$opt[0].','.$opt[1].'</b>. ':'').
1.168 www 539: &mt('Select all that are <b>[_1]</b>.',$checkboxopt);
1.160 www 540: }
1.22 albertel 541: foreach $name (@whichopt) {
1.62 albertel 542: my $text=$Apache::response::foilgroup{$name.'.text'};
543: if ($text!~/^\s*$/) {
544: if ($target eq 'tex') {
545: $break='\vskip 0 mm ';
546: } elsif ($target eq 'web') {
547: $break='<br />';
548: }
549: }
1.28 albertel 550: my $lastopt=$lastresponse{$name};
551: my $optionlist="<option></option>\n";
1.152 onken 552:
1.158 onken 553: if($target eq 'tex' and $env{'form.pdfFormFields'} eq 'yes'
554: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.152 onken 555: my $fieldname = $env{'request.symb'}.'&part_'.$Apache::inputtags::part.'&optionresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp;
556: $optionlist = &Apache::lonxml::print_pdf_start_combobox($fieldname);
557: }
558:
1.126 albertel 559: foreach my $option (@opt) {
560: my $escopt=&HTML::Entities::encode($option,'\'"&<>');
1.152 onken 561: if ($option eq $lastopt) {
1.158 onken 562: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
1.164 onken 563: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
564: && $Apache::lonhomework::type ne 'exam') {
1.152 onken 565: $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
566: } else {
567: $optionlist.="<option value='".$escopt."' selected=\"selected\">$option</option>\n";
568: }
569: } else {
1.158 onken 570: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
1.164 onken 571: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
572: && $Apache::lonhomework::type ne 'exam') {
1.152 onken 573: $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
574: } else {
575: $optionlist.="<option value='".$escopt."'>$option</option>\n";
576: }
577: }
1.28 albertel 578: }
1.32 sakharuk 579: if ($target ne 'tex') {
1.72 sakharuk 580: if ($Apache::lonhomework::type ne 'exam') {
1.159 www 581: # we are on the web, this is not an exam, and the problem can be answered
582: if ($checkboxopt) {
583: # generate checkboxes
584: my $fieldname=$Apache::inputtags::response['-1'].':'.$temp;
585: my $altopt=$opt[0];
586: if ($opt[0] eq $checkboxopt) {
587: $altopt=$opt[1];
588: }
589: my $defopt=$lastopt;
590: unless ($defopt) { $defopt=$altopt; }
591: my $escdefopt=&HTML::Entities::encode($defopt,'\'"&<>');
592: my $esccheckboxopt=&HTML::Entities::encode($checkboxopt,'\'"&<>');
593: my $escaltopt=&HTML::Entities::encode($altopt,'\'"&<>');
594: # checkboxopt is how the box is labelled
595: # altopt is the alternative option
596: # lastopt is what the user submitted before
597: # defopt is what the field is going to start out with: either previous choice or altopt
598: # fieldname is this input field's name after HWVAL_
599: $optionlist='<input type="hidden" name="HWVAL_'.$fieldname.'" value="'.$escdefopt.'" />'.
1.160 www 600: '<input type="checkbox" name="HWCHK_'.$fieldname.'" onclick="javascript:if (this.form.elements[\'HWCHK_'.
601: $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";
1.159 www 602: } else {
603: # classic selection list
604: $optionlist='<select onchange="javascript:setSubmittedPart(\''.
1.139 albertel 605: $part.'\');" name="HWVAL_'.
1.101 albertel 606: $Apache::inputtags::response['-1'].':'.$temp.'">'.
1.59 albertel 607: $optionlist."</select>\n";
1.159 www 608: }
1.101 albertel 609: } else {
610: $optionlist='<u>'.(' 'x10).'</u>';
1.72 sakharuk 611: }
1.101 albertel 612: if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
613: if ($Apache::lonhomework::type ne 'exam') {
1.170 raeburn 614: if (@whichopt > 1) {
615: $text='•'.$text;
616: }
1.101 albertel 617: }
1.95 albertel 618: } else {
1.101 albertel 619: if ($Apache::lonhomework::type ne 'exam') {
620: $text=$optionlist.$text;
621: }
1.59 albertel 622: }
1.62 albertel 623: $result.=$break.$text."\n";
1.49 sakharuk 624: if ($Apache::lonhomework::type eq 'exam') {
1.101 albertel 625: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
1.49 sakharuk 626: }
1.32 sakharuk 627: $temp++;
628: } else {
1.101 albertel 629: my $texoptionlist='';
630: if ($displayoptionintex &&
631: $Apache::lonhomework::type ne 'exam') {
1.107 sakharuk 632: $texoptionlist = &optionlist_correction($TeXlayout,@opt);
1.101 albertel 633: }
634: if ($text=~/<drawoptionlist\s*\/>/) {
1.136 foxr 635: $text=~s|<drawoptionlist\s*\/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |g;
1.101 albertel 636: }
637:
638: if ($text=~m/\\item /) {
1.50 sakharuk 639: if ($Apache::lonhomework::type eq 'exam') {
1.101 albertel 640: $text=~s/\\item/\\vskip 2 mm/;
1.152 onken 641: } elsif ($env{'form.pdfFormFields'} ne 'yes') {
642: $result.= $texoptionlist.$text;
643: }
644: } else {
1.101 albertel 645: if ($Apache::lonhomework::type eq 'exam') {
646: $result.= $texoptionlist.' '.$text;
1.152 onken 647: } elsif ($env{'form.pdfFormFields'} ne 'yes') {
648: if ($text=~/\S/) {
649: $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
650: } else {
651: $result.= $texoptionlist;
652: }
1.50 sakharuk 653: }
1.32 sakharuk 654: }
1.101 albertel 655: if ($Apache::lonhomework::type eq 'exam') {
1.165 foxr 656: $result.='\vskip -1 mm\noindent';
1.177 raeburn 657: my ($numrows,$bubbles_per_row) = &getnumrows(scalar(@opt));
658: if ($numrows == 1) {
659: $result .= '\textbf{'.$internal_counter.'}. \vskip -3mm';
660: } else {
661: my $linetext;
662: for (my $i=0; $i<$numrows; $i++) {
663: $linetext .= $internal_counter+$i.', ';
664: }
665: $linetext =~ s/,\s$//;
666: $result .= '\small {\textbf{'.$linetext.'}} '.
667: '\hskip 2 mm {\footnotesize '.
668: &mt('(Bubble once in [_1] lines)',$numrows).
669: '} \vskip 1 mm';
670: }
671: $result.= &bubbles(\@alphabet,\@opt,undef,undef,$numrows,
672: $bubbles_per_row,$internal_counter).
673: ' \strut ';
674: $internal_counter += $numrows;
1.101 albertel 675: }
1.158 onken 676: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
1.164 onken 677: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
678: && $Apache::lonhomework::type ne 'exam') {
1.158 onken 679: $text =~ s/\\item//m;
1.152 onken 680: $result .= " $optionlist ". &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
681: $temp++;
682: }
1.101 albertel 683: $displayoptionintex=0;
1.62 albertel 684: }
1.1 albertel 685: }
1.62 albertel 686: }
1.138 albertel 687:
688: if ($target eq 'web') {
1.173 raeburn 689: my $data = [\@whichopt,'submissiongrading'];
690: my $questiontype;
691: if ($Apache::lonhomework::type eq 'randomizetry') {
692: $questiontype = $Apache::lonhomework::type,
693: }
694: &Apache::response::setup_prior_tries_hash(\&Apache::rankresponse::format_prior_answer,$data,$questiontype);
1.138 albertel 695: }
696:
1.32 sakharuk 697: if ($target ne 'tex') {
1.62 albertel 698: return $result.$break;
699: } else {
1.32 sakharuk 700: return $result;
1.22 albertel 701: }
1.50 sakharuk 702: }
703:
704:
705: sub optionlist_correction {
1.107 sakharuk 706: my ($TeXlayout,@options) = @_;
1.150 bisitz 707: my $texoptionlist='\\item [] '.&mt('Choices:').' ';
1.107 sakharuk 708: if ($TeXlayout eq 'vertical') {$texoptionlist='\\item []';}
1.101 albertel 709: if (scalar(@options) > 0) {
710: foreach my $option (@options) {
711: $texoptionlist.='{\bf '.
1.135 albertel 712: &Apache::lonxml::latex_special_symbols($option).
1.107 sakharuk 713: '}';
714: if ($TeXlayout eq 'vertical') {
715: $texoptionlist.=' \vskip 0 mm ',
716: } else {
1.115 sakharuk 717: $texoptionlist.=', ';
1.107 sakharuk 718: }
1.101 albertel 719: }
1.116 albertel 720: $texoptionlist=~s/, $//;
1.107 sakharuk 721: if ($TeXlayout ne 'vertical') {$texoptionlist.='.';}
1.80 sakharuk 722: } else {
1.107 sakharuk 723: if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';}
1.80 sakharuk 724: }
1.50 sakharuk 725: return $texoptionlist;
1.58 sakharuk 726: }
727:
728:
729: sub webbubbles {
1.90 albertel 730: my ($ropt,$ralphabet,$temp,$lastopt)=@_;
1.58 sakharuk 731: my @opt=@$ropt;
732: my @alphabet=@$ralphabet;
733: my $result='';
1.90 albertel 734: my $number_of_bubbles = $#opt + 1;
735: $result.= '<table border="1"><tr>';
736: for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
737: my $checked='';
738: if ($lastopt eq $opt[$ind]) {
739: $checked=' checked="on" ';
1.58 sakharuk 740: }
1.90 albertel 741: $result.='<td><input type="radio" name="HWVAL_'.
742: $Apache::inputtags::response['-1'].':'.$temp.
1.111 albertel 743: '" value="'.$opt[$ind].'" '.$checked.' />';
744: if ($alphabet[$ind]) {
745: $result.=$alphabet[$ind].': ';
746: }
747: $result.=$opt[$ind].'</td>';
1.90 albertel 748: }
749: $result.='</tr></table>';
750: return $result;
1.50 sakharuk 751: }
752:
753:
754: sub bubbles {
1.177 raeburn 755: my ($ralphabet,$ropt,$response,$max_width,$numrows,$bubbles_per_row,
756: $internal_counter) = @_;
1.119 albertel 757: my @alphabet = @$ralphabet;
1.50 sakharuk 758: my @opt = @$ropt;
1.51 sakharuk 759: my ($result,$head,$line) =('','','');
1.50 sakharuk 760: my $number_of_bubbles = $#opt + 1;
1.51 sakharuk 761: my $current_length = 0;
1.100 sakharuk 762: my $textwidth;
1.141 albertel 763: if (defined($max_width)) {
1.140 foxr 764: $textwidth=$max_width;
1.141 albertel 765: &Apache::lonxml::debug("Max width passed in: $max_width");
766: } elsif ($env{'form.textwidth'} ne '') {
1.125 albertel 767: $env{'form.textwidth'}=~/(\d+)/;
1.100 sakharuk 768: $textwidth=$1;
1.141 albertel 769: &Apache::lonxml::debug("Max width from form: $textwidth");
1.100 sakharuk 770: } else {
1.125 albertel 771: $env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
1.102 sakharuk 772: $textwidth=$1.'.'.$2;
1.141 albertel 773: &Apache::lonxml::debug("Max width defaults? $textwidth");
1.100 sakharuk 774: }
1.141 albertel 775: &Apache::lonxml::debug("Final maxwidth: $textwidth");
1.51 sakharuk 776: for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
1.177 raeburn 777: my $item;
778: if ($numrows > 1) {
779: my $num = $internal_counter+int($ind/$bubbles_per_row);
780: my $idx = int($ind % $bubbles_per_row);
781: $item = $num.$alphabet[$idx];
782: } else {
783: $item = $alphabet[$ind];
784: }
1.99 sakharuk 785: my $leftmargin;
1.101 albertel 786: $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
1.119 albertel 787: if ($response eq 'rankresponse') {$opt[$ind]='Rank '.$opt[$ind];}
1.99 sakharuk 788: if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
1.140 foxr 789:
1.177 raeburn 790: $current_length += (length($opt[$ind])+length($item)+4)*2;
791:
1.99 sakharuk 792: if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
1.177 raeburn 793:
794: $line.='\hskip 4 mm {\small \textbf{'.$item.'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
1.51 sakharuk 795: $head.='lr';
796: } else {
797: $line=~s/\&\s*$//;
1.171 raeburn 798: $result.='\vskip -1 mm\noindent\setlength{\tabcolsep}{2 mm}\renewcommand{\arraystretch}{1.25}\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm';
1.177 raeburn 799: $line = '\hskip 4 mm {\small \textbf{'.$item.'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
1.51 sakharuk 800: $head ='lr';
1.177 raeburn 801: $current_length = (length($opt[$ind])+length($item))*2;
1.51 sakharuk 802: }
803:
1.50 sakharuk 804: }
805: return $result;
1.1 albertel 806: }
807:
1.2 albertel 808: sub start_conceptgroup {
1.22 albertel 809: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
810: $Apache::optionresponse::conceptgroup=1;
1.44 albertel 811: %Apache::response::conceptgroup=();
1.22 albertel 812: my $result;
813: if ($target eq 'edit') {
814: $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
1.30 matthew 815: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
816: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.22 albertel 817: }
818: if ($target eq 'modified') {
819: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
820: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
821: }
822: return $result;
1.2 albertel 823: }
824:
825: sub end_conceptgroup {
1.22 albertel 826: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
827: $Apache::optionresponse::conceptgroup=0;
828: my $result='';
1.93 albertel 829: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
830: $target eq 'tex' || $target eq 'analyze') {
1.22 albertel 831: #if not there aren't any foils to display and thus no question
1.93 albertel 832: &Apache::response::pick_foil_for_concept($target,
833: ['value','text','location'],
834: \%Apache::hint::option,
835: $parstack,$safeeval);
1.34 albertel 836: } elsif ($target eq 'edit') {
1.22 albertel 837: $result=&Apache::edit::end_table();
838: }
839: return $result;
1.2 albertel 840: }
841:
1.16 albertel 842: sub insert_conceptgroup {
1.22 albertel 843: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
844: return $result;
1.16 albertel 845: }
846:
1.1 albertel 847: sub start_foil {
1.22 albertel 848: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
849: my $result='';
1.34 albertel 850: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
1.105 albertel 851: &Apache::lonxml::startredirection;
852: if ($target eq 'analyze') {
853: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
854: }
1.25 albertel 855: } elsif ($target eq 'edit') {
1.22 albertel 856: $result=&Apache::edit::tag_start($target,$token,"Foil");
857: my $level='-2';
858: if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
859: my @opt;
860: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
861: $result.=&Apache::edit::text_arg('Name:','name',$token);
1.48 albertel 862: $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
863: ['unused',(@opt)],$token,'15');
864: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
865: $safeeval,'-3');
866: if ($randomize ne 'no') {
867: $result.=&Apache::edit::select_arg('Location:','location',
868: ['random','top','bottom'],$token);
869: }
1.30 matthew 870: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.25 albertel 871: } elsif ($target eq 'modified') {
1.48 albertel 872: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
873: 'value','name','location');
1.22 albertel 874: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.32 sakharuk 875: }
1.22 albertel 876: return $result;
1.1 albertel 877: }
878:
879: sub end_foil {
1.22 albertel 880: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
881: my $text ='';
882: my $result = '';
1.88 albertel 883: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.48 albertel 884: $text=&Apache::lonxml::endredirection;
1.114 sakharuk 885: if ($target eq 'tex') {$text=~s/\\strut\s*\\\\\s*\\strut/\\vskip 0 mm/;}
1.107 sakharuk 886: if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;}
1.32 sakharuk 887: }
888: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
1.34 albertel 889: || $target eq 'tex' || $target eq 'analyze') {
1.22 albertel 890: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
1.122 albertel 891: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
892: $text='\vskip 5mm $\triangleright$ '.$text;
893: }
1.22 albertel 894: if ($value ne 'unused') {
895: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
896: &Apache::lonxml::debug("Got a name of :$name:");
1.129 albertel 897: if ($name eq "") {
1.151 bisitz 898: &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
1.123 albertel 899: $name=$Apache::lonxml::curdepth;
900: }
1.22 albertel 901: &Apache::lonxml::debug("Using a name of :$name:");
1.103 albertel 902: if (defined($Apache::response::foilnames{$name})) {
1.151 bisitz 903: &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",'<b><tt>'.$name.'</tt></b>'));
1.103 albertel 904: }
1.104 albertel 905: $Apache::response::foilnames{$name}++;
1.103 albertel 906: my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
1.39 albertel 907: if ( $Apache::optionresponse::conceptgroup
908: && !&Apache::response::showallfoils() ) {
1.22 albertel 909: push @{ $Apache::response::conceptgroup{'names'} }, $name;
910: $Apache::response::conceptgroup{"$name.value"} = $value;
1.122 albertel 911: $Apache::response::conceptgroup{"$name.text"} = $text;
1.48 albertel 912: $Apache::response::conceptgroup{"$name.location"} = $location;
1.22 albertel 913: } else {
914: push @{ $Apache::response::foilgroup{'names'} }, $name;
1.48 albertel 915: $Apache::response::foilgroup{"$name.value"} = $value;
1.122 albertel 916: $Apache::response::foilgroup{"$name.text"} = $text;
1.48 albertel 917: $Apache::response::foilgroup{"$name.location"} = $location;
1.22 albertel 918: }
919: }
920: }
921: if ($target eq 'edit') {
922: $result.= &Apache::edit::tag_end($target,$token,'');
923: }
924: return $result;
1.1 albertel 925: }
926:
1.112 sakharuk 927: sub start_drawoptionlist {
928: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.144 albertel 929: if ($target !~ /^(?:meta|answer|modified|edit)$/) {
1.117 albertel 930: return $token->[4];
931: }
1.112 sakharuk 932: }
933:
934: sub end_drawoptionlist {
935: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.144 albertel 936: if ($target !~ /^(?:meta|answer|modified|edit)$/) {
1.117 albertel 937: return $token->[2];
938: }
1.112 sakharuk 939: }
940:
1.7 albertel 941: sub insert_foil {
1.144 albertel 942: return '
1.15 albertel 943: <foil name="" value="unused">
1.14 albertel 944: <startouttext />
945: <endouttext />
1.7 albertel 946: </foil>';
947: }
1.144 albertel 948:
949: sub insert_drawoptionlist {
950: return '<drawoptionlist />';
951: }
1.177 raeburn 952:
953: sub getnumrows {
954: my ($numitems) = @_;
955: my $bubbles_per_row;
956: my $default_numbubbles = 10;
957: if (($env{'form.bubbles_per_row'} =~ /^\d+$/) &&
958: ($env{'form.bubbles_per_row'} > 0)) {
959: $bubbles_per_row = $env{'form.bubbles_per_row'};
960: } else {
961: $bubbles_per_row = $default_numbubbles;
962: }
963: my $numrows = int ($numitems/$bubbles_per_row);
964: if (($numitems % $bubbles_per_row) != 0) {
965: $numrows ++;
966: }
967: return ($numrows,$bubbles_per_row);
968: }
969:
1.1 albertel 970: 1;
971: __END__
972:
1.156 jms 973: =head1 NAME
974:
975: Apache::optionresponse.pm;
976:
977: =head1 SYNOPSIS
978:
979: Handles tags associated with showing a list of
980: options.
981:
982: This is part of the LearningOnline Network with CAPA project
983: described at http://www.lon-capa.org.
984:
985: =head1 HANDLER SUBROUTINE
986:
987: start_optionresponse()
988:
989: =head1 OTHER SUBROUTINES
990:
991: =over
992:
993: =item end_optionresponse()
994:
995: =item start_foilgroup()
996:
997: =item end_foilgroup()
998:
999: =item getfoilcounts()
1000:
1001: =item displayanswers()
1002:
1003: =item check_for_invalid()
1004:
1005: =item displayfoils()
1006:
1007: =item optionlist_correction()
1008:
1009: =item webbubbles()
1010:
1011: =item bubbles()
1012:
1013: =item start_conceptgroup()
1014:
1015: =item end_conceptgroup()
1016:
1017: =item insert_conceptgroup()
1018:
1019: =item start_foil()
1020:
1021: =item end_foil()
1022:
1023: =item start_drawoptionlist()
1024:
1025: =item end_drawoptionlist()
1026:
1027: =item insert_foil()
1028:
1029: =item insert_drawoptionlist()
1030:
1031: =back
1032:
1.157 raeburn 1033: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>