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