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