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