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