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