1: # LearningOnline Network with CAPA
2: # option list style responses
3: #
4: # $Id: optionresponse.pm,v 1.151.2.1 2008/12/11 01:59:01 raeburn Exp $
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: #
28: package Apache::optionresponse;
29: use strict;
30: use Apache::response();
31: use Apache::lonlocal;
32: use Apache::lonnet;
33:
34: BEGIN {
35: &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
36: }
37:
38: sub start_optionresponse {
39: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
40: my $result='';
41: #when in a option response use these
42: &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
43: push (@Apache::lonxml::namespace,'optionresponse');
44: my $id = &Apache::response::start_response($parstack,$safeeval);
45: %Apache::hint::option=();
46: undef(%Apache::response::foilnames);
47: if ($target eq 'edit') {
48: $result.=&Apache::edit::start_table($token)
49: .'<tr><td><span class="LC_nobreak">'.&mt('Multiple Option Response Question').'</span> '
50: .&Apache::loncommon::help_open_topic('Option_Response_Problems')."</td>"
51: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
52: .&Apache::edit::deletelist($target,$token)
53: .'</span></td>'
54: ."<td> "
55: .&Apache::edit::end_row()
56: .&Apache::edit::start_spanning_row()
57: ."\n";
58: $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max',
59: $token,'4').
60: &Apache::edit::select_arg('Randomize Foil Order:','randomize',
61: ['yes','no'],$token).
62: &Apache::edit::select_arg(&mt('Display of options when printed'),'TeXlayout',
63: [['horizontal','Normal list'],
64: ['vertical','Listed in a vertical column']],$token).
65: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
66: } elsif ($target eq 'modified') {
67: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
68: $safeeval,'max','randomize',
69: 'TeXlayout');
70: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
71: } elsif ($target eq 'meta') {
72: $result=&Apache::response::meta_package_write('optionresponse');
73: } elsif ($target eq 'analyze') {
74: my $part_id="$Apache::inputtags::part.$id";
75: $Apache::lonhomework::analyze{"$part_id.type"} = 'optionresponse';
76: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
77: push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} }, 1);
78:
79: }
80: return $result;
81: }
82:
83: sub end_optionresponse {
84: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
85: &Apache::response::end_response;
86: pop @Apache::lonxml::namespace;
87: &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
88: my $result;
89: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
90: undef(%Apache::response::foilnames);
91: return $result;
92: }
93:
94: %Apache::response::foilgroup=();
95: sub start_foilgroup {
96: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
97:
98: my $result='';
99: %Apache::response::foilgroup=();
100: $Apache::optionresponse::conceptgroup=0;
101: &Apache::response::pushrandomnumber();
102: if ($target eq 'edit') {
103: my $optionlist="<option></option>\n";
104: my $option;
105: my @opt;
106: eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval);
107: my $count=1;
108: foreach $option (@opt) {
109: $optionlist.="<option value=\"$count\">$option</option>\n";
110: $count++;
111: }
112: my $insertlist=&Apache::edit::insertlist($target,$token);
113: $result.=&Apache::edit::start_table($token);
114: $result.= (<<ENDTABLE);
115: <tr><td>Select Options</td>
116: <td>
117: Add new Option: <input type="text" name="$Apache::lonxml::curdepth.options" />
118: </td>
119: <td>Delete an Option:
120: <select name="$Apache::lonxml::curdepth.deleteopt">$optionlist</select>
121: ENDTABLE
122: $result.= &Apache::edit::checked_arg('Print options:','texoptions',
123: [ ['nochoice','Don\'t show option list'] ]
124: ,$token);
125: $result.= &Apache::edit::end_row();
126: $result.= &Apache::edit::start_spanning_row();
127: $result.= $insertlist.'<br />';
128: }
129: if ($target eq 'modified') {
130: my @options;
131: my $optchanged=0;
132: eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
133: if ($env{"form.$Apache::lonxml::curdepth.deleteopt"}) {
134: my $delopt=$env{"form.$Apache::lonxml::curdepth.deleteopt"};
135: &Apache::lonxml::debug("Deleting :$delopt:");
136: splice(@options,$delopt-1,1);
137: $optchanged=1;
138: }
139: if ($env{"form.$Apache::lonxml::curdepth.options"}) {
140: my $newopt = $env{"form.$Apache::lonxml::curdepth.options"};
141: if ($options[0]) {
142: push(@options,$newopt);
143: } else {
144: $options[0]=$newopt;
145: }
146: $optchanged=1;
147: }
148: my $rebuildtag = &Apache::edit::get_new_args($token,$parstack,$safeeval,
149: ('texoptions'));
150: if ($optchanged || $rebuildtag ) {
151: $result = "<foilgroup options=\"(";
152: foreach my $option (@options) {
153: $option=~s/\'/\\\'/g;
154: &Apache::lonxml::debug("adding option :$option:");
155: $result .="'".$option."',";
156: }
157: chop $result;
158: $result.=')" ';
159: $result .= 'texoptions="'.$token->[2]{'texoptions'}.'" ';
160: $result .= '>';
161: } # else nothing changed so just use the default mechanism
162: }
163: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
164: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}
165: \begin{enumerate} ';
166: }
167: return $result;
168: }
169:
170: sub end_foilgroup {
171: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
172:
173: my $result;
174: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
175: $target eq 'tex' || $target eq 'analyze') {
176: my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
177: my $name;
178: my @opt;
179: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
180: &Apache::lonxml::debug("options:".join(':',@opt));
181:
182: my $TeXlayout=&Apache::lonxml::get_param('TeXlayout',$parstack,$safeeval,
183: -2,0);
184: if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
185: &Apache::lonxml::debug("Options are $#opt");
186: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
187: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
188: $safeeval,'-2');
189: if ($target eq 'web' || $target eq 'tex') {
190: $result.=&displayfoils($target,$max,$randomize,$TeXlayout,@opt);
191: $Apache::lonxml::post_evaluate=0;
192: } elsif ( $target eq 'answer') {
193: $result.=&displayanswers($max,$randomize,@opt);
194:
195: } elsif ( $target eq 'analyze') {
196: my @shown = &whichfoils($max,$randomize);
197: &Apache::response::analyze_store_foilgroup(\@shown,
198: ['text','value','location']);
199: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
200: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
201: } elsif ( $target eq 'grade') {
202: if ( &Apache::response::submitted()) {
203: my @whichopt = &whichfoils($max,$randomize);
204: my $temp=1;my $name;
205: my %responsehash;
206: my %grade;
207: my $right=0;
208: my $wrong=0;
209: my $ignored=0;
210: foreach $name (@whichopt) {
211: my $response=&Apache::response::getresponse($temp);
212: if ($env{'form.submitted'} eq 'scantron' && $response=~/\S/) {
213: $response = $opt[$response];
214: }
215: if ( $response =~ /[^\s]/) {
216: $responsehash{$name}=$response;
217: my $value=$Apache::response::foilgroup{$name.'.value'};
218: &Apache::lonxml::debug("submitted a $response for $value<br />\n");
219: if ($value eq $response) {
220: $grade{$name}='1'; $right++;
221: } else {
222: $grade{$name}='0'; $wrong++;
223: }
224: } else {
225: $ignored++;
226: }
227: $temp++;
228: }
229: my $part=$Apache::inputtags::part;
230: my $id = $Apache::inputtags::response['-1'];
231: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
232: my $gradestr =&Apache::lonnet::hash2str(%grade);
233: my %previous=&Apache::response::check_for_previous($responsestr,
234: $part,$id);
235: &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
236: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
237: $responsestr;
238: $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
239:
240: if ($Apache::lonhomework::type eq 'survey') {
241: if ($ignored == 0) {
242: my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
243: &Apache::response::handle_previous(\%previous,$ad);
244: } elsif ($wrong==0 && $right==0) {
245: } else {
246: my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='MISSING_ANSWER';
247: &Apache::response::handle_previous(\%previous,$ad);
248: }
249: } elsif (!$Apache::lonhomework::scantronmode) {
250: my $ad;
251: if ($wrong==0 && $ignored==0) {
252: $ad='EXACT_ANS';
253: } elsif ($wrong==0 && $right==0) {
254: #nothing submitted
255: } else {
256: if ($ignored==0) {
257: $ad='INCORRECT';
258: } else {
259: $ad='MISSING_ANSWER';
260: }
261: }
262: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
263: &Apache::response::handle_previous(\%previous,$ad);
264: } else {
265: my $ad;
266: if ($wrong==0 && $right==0) {
267: #nothing submitted only assign a score if we
268: #need to override a previous grade
269: if (defined($Apache::lonhomework::history{"resource.$part.$id.awarddetail"})) {
270: $ad='ASSIGNED_SCORE';
271: }
272: } else {
273: $ad='ASSIGNED_SCORE';
274: }
275: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
276: $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
277: $right/(scalar(@whichopt));
278: $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
279: scalar(@whichopt);
280: }
281: }
282: }
283: my $part_id = $Apache::inputtags::part;
284: my $response_id = $Apache::inputtags::response[-1];
285: &Apache::lonxml::increment_counter(&getfoilcounts($max),
286: "$part_id.$response_id");
287: if ($target eq 'analyze') {
288: &Apache::lonhomework::set_bubble_lines();
289: }
290:
291: } elsif ($target eq 'edit') {
292: $result.=&Apache::edit::end_table();
293: }
294: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
295: $result .= '\end{enumerate}';
296: }
297: &Apache::response::poprandomnumber();
298: return $result;
299: }
300:
301: sub getfoilcounts {
302: my ($max)=@_;
303: # +1 since instructors will count from 1
304: my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
305: if (&Apache::response::showallfoils()) { $max=$count; }
306: if ($count>$max) { $count=$max }
307: &Apache::lonxml::debug("Count is $count from $max");
308: return $count;
309: }
310:
311: sub whichfoils {
312: my ($max,$randomize)=@_;
313: return &Apache::response::whichorder($max,$randomize,
314: &Apache::response::showallfoils(),
315: \%Apache::response::foilgroup);
316: }
317:
318: sub displayanswers {
319: my ($max,$randomize,@opt)=@_;
320: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
321: my @names = @{ $Apache::response::foilgroup{'names'} };
322: my @whichopt = &whichfoils($max,$randomize);
323: my $result;
324: if ($Apache::lonhomework::type eq 'exam') {
325: my $i = 0;
326: my %opt = map { ($_,$i++) } @opt;
327:
328: $i = 0;
329: my @alphabet = ('A'..'Z');
330: foreach my $name (@whichopt) {
331: $result.=&Apache::response::answer_header('optionresponse',$i++);
332: $result.=&Apache::response::answer_part('optionresponse',
333: $alphabet[$opt{$Apache::response::foilgroup{$name.'.value'}}]);
334: $result.=&Apache::response::answer_part('optionresponse',
335: $Apache::response::foilgroup{$name.'.value'});
336: $result.=&Apache::response::answer_footer('optionresponse');
337: }
338: } else {
339: $result=&Apache::response::answer_header('optionresponse');
340: foreach my $name (@whichopt) {
341: $result.=&Apache::response::answer_part('optionresponse',
342: $Apache::response::foilgroup{$name.'.value'});
343: }
344: $result.=&Apache::response::answer_footer('optionresponse');
345: }
346: return $result;
347: }
348:
349: sub check_for_invalid {
350: my ($names,$options) = @_;
351: my %bad_names;
352: foreach my $name (@{ $names }) {
353: my $value=$Apache::response::foilgroup{$name.'.value'};
354: my $found=0;
355: foreach my $option (@{ $options }) {
356: if ($value eq $option) { $found=1; }
357: }
358: if (!$found) { $bad_names{$name}=$value; }
359: }
360: if (%bad_names) {
361: my $error=&mt('The question can not be gotten correct, '.
362: 'the following foils in the <optionresponse> '.
363: 'have invalid correct options').' <br /><tt>'.
364: join('<br />',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))).
365: "</tt>";
366: &Apache::lonxml::error($error);
367: }
368: }
369:
370: sub displayfoils {
371: my ($target,$max,$randomize,$TeXlayout,@opt)=@_;
372: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
373: my @names = @{ $Apache::response::foilgroup{'names'} };
374: my @truelist;
375: my @falselist;
376: my $result;
377: my $name;
378: my $displayoptionintex=1;
379: my @alphabet = ('A'..'Z');
380: my @whichopt = &whichfoils($max,$randomize);
381: &check_for_invalid(\@whichopt,\@opt);
382: my $part=$Apache::inputtags::part;
383: my $id=$Apache::inputtags::response[-1];
384: my $break;
385: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
386: if ( ($target ne 'tex') &&
387: &Apache::response::show_answer() ) {
388: my $temp=1;
389: foreach $name (@whichopt) {
390: my $text=$Apache::response::foilgroup{$name.'.text'};
391: my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
392: my $lastopt=$lastresponse{$name};
393: if ($text!~/^\s*$/) { $break='<br />'; }
394: $result.=$break;
395: if ($target eq 'web') {
396: my $value=$Apache::response::foilgroup{$name.'.value'};
397: if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
398: if ($text=~/^\s*$/) {
399: $text=$value.$text;
400: } else {
401: $text='<b>'.$value.':</b> '.$text;
402: }
403: } else {
404: $text='•'.$text;
405: }
406: $result.=$text."\n";
407: }
408: if ($Apache::lonhomework::type eq 'exam') {
409: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
410: }
411: $temp++;
412: }
413: } else {
414: my $temp=1;
415: my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
416: my $internal_counter=$Apache::lonxml::counter;
417: foreach $name (@whichopt) {
418: my $text=$Apache::response::foilgroup{$name.'.text'};
419: if ($text!~/^\s*$/) {
420: if ($target eq 'tex') {
421: $break='\vskip 0 mm ';
422: } elsif ($target eq 'web') {
423: $break='<br />';
424: }
425: }
426: my $lastopt=$lastresponse{$name};
427: my $optionlist="<option></option>\n";
428: foreach my $option (@opt) {
429: my $escopt=&HTML::Entities::encode($option,'\'"&<>');
430: if ($option eq $lastopt) {
431: $optionlist.="<option value='".$escopt."' selected=\"selected\">$option</option>\n";
432: } else {
433: $optionlist.="<option value='".$escopt."'>$option</option>\n";
434: }
435: }
436: if ($target ne 'tex') {
437: if ($Apache::lonhomework::type ne 'exam') {
438: $optionlist='<select onchange="javascript:setSubmittedPart(\''.
439: $part.'\');" name="HWVAL_'.
440: $Apache::inputtags::response['-1'].':'.$temp.'">'.
441: $optionlist."</select>\n";
442: } else {
443: $optionlist='<u>'.(' 'x10).'</u>';
444: }
445: if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
446: if ($Apache::lonhomework::type ne 'exam') {
447: $text='•'.$text;
448: }
449: } else {
450: if ($Apache::lonhomework::type ne 'exam') {
451: $text=$optionlist.$text;
452: }
453: }
454: $result.=$break.$text."\n";
455: if ($Apache::lonhomework::type eq 'exam') {
456: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
457: }
458: $temp++;
459: } else {
460: my $texoptionlist='';
461: if ($displayoptionintex &&
462: $Apache::lonhomework::type ne 'exam') {
463: $texoptionlist = &optionlist_correction($TeXlayout,@opt);
464: }
465: if ($text=~/<drawoptionlist\s*\/>/) {
466: $text=~s|<drawoptionlist\s*\/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |g;
467: }
468:
469: if ($text=~m/\\item /) {
470: if ($Apache::lonhomework::type eq 'exam') {
471: $text=~s/\\item/\\vskip 2 mm/;
472: }
473: $result.= $texoptionlist.$text;
474: } else {
475: if ($Apache::lonhomework::type eq 'exam') {
476: $result.= $texoptionlist.' '.$text;
477: } else {
478: if ($text=~/\S/) {$result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;} else {$result.= $texoptionlist;}
479: }
480: }
481: if ($Apache::lonhomework::type eq 'exam') {
482: $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.
483: $internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).
484: '\end{enumerate} \vskip -8 mm \strut ';
485: $internal_counter++;
486: }
487: $displayoptionintex=0;
488: }
489: }
490: }
491:
492: if ($target eq 'web') {
493: &Apache::response::setup_prior_tries_hash(\&Apache::rankresponse::format_prior_answer,
494: [\@whichopt,
495: 'submissiongrading']);
496: }
497:
498: if ($target ne 'tex') {
499: return $result.$break;
500: } else {
501: return $result;
502: }
503: }
504:
505:
506: sub optionlist_correction {
507: my ($TeXlayout,@options) = @_;
508: my $texoptionlist='\\item [] '.&mt('Choices:').' ';
509: if ($TeXlayout eq 'vertical') {$texoptionlist='\\item []';}
510: if (scalar(@options) > 0) {
511: foreach my $option (@options) {
512: $texoptionlist.='{\bf '.
513: &Apache::lonxml::latex_special_symbols($option).
514: '}';
515: if ($TeXlayout eq 'vertical') {
516: $texoptionlist.=' \vskip 0 mm ',
517: } else {
518: $texoptionlist.=', ';
519: }
520: }
521: $texoptionlist=~s/, $//;
522: if ($TeXlayout ne 'vertical') {$texoptionlist.='.';}
523: } else {
524: if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';}
525: }
526: return $texoptionlist;
527: }
528:
529:
530: sub webbubbles {
531: my ($ropt,$ralphabet,$temp,$lastopt)=@_;
532: my @opt=@$ropt;
533: my @alphabet=@$ralphabet;
534: my $result='';
535: my $number_of_bubbles = $#opt + 1;
536: $result.= '<table border="1"><tr>';
537: for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
538: my $checked='';
539: if ($lastopt eq $opt[$ind]) {
540: $checked=' checked="on" ';
541: }
542: $result.='<td><input type="radio" name="HWVAL_'.
543: $Apache::inputtags::response['-1'].':'.$temp.
544: '" value="'.$opt[$ind].'" '.$checked.' />';
545: if ($alphabet[$ind]) {
546: $result.=$alphabet[$ind].': ';
547: }
548: $result.=$opt[$ind].'</td>';
549: }
550: $result.='</tr></table>';
551: return $result;
552: }
553:
554:
555: sub bubbles {
556: my ($ralphabet,$ropt,$response, $max_width) = @_;
557: my @alphabet = @$ralphabet;
558: my @opt = @$ropt;
559: my ($result,$head,$line) =('','','');
560: my $number_of_bubbles = $#opt + 1;
561: my $current_length = 0;
562: my $textwidth;
563: if (defined($max_width)) {
564: $textwidth=$max_width;
565: &Apache::lonxml::debug("Max width passed in: $max_width");
566: } elsif ($env{'form.textwidth'} ne '') {
567: $env{'form.textwidth'}=~/(\d+)/;
568: $textwidth=$1;
569: &Apache::lonxml::debug("Max width from form: $textwidth");
570: } else {
571: $env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
572: $textwidth=$1.'.'.$2;
573: &Apache::lonxml::debug("Max width defaults? $textwidth");
574: }
575: &Apache::lonxml::debug("Final maxwidth: $textwidth");
576: for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
577: my $leftmargin;
578: $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
579: if ($response eq 'rankresponse') {$opt[$ind]='Rank '.$opt[$ind];}
580: if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
581:
582: $current_length += (length($opt[$ind])+length($alphabet[$ind])+4)*2;
583: if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
584: $line.='\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
585: $head.='lr';
586: } else {
587: $line=~s/\&\s*$//;
588: $result.='\vskip -2 mm\noindent\setlength{\tabcolsep}{2 mm}\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm';
589: $line = '\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';;
590: $head ='lr';
591: $current_length = (length($opt[$ind])+length($alphabet[$ind]))*2;
592: }
593:
594: }
595: return $result;
596: }
597:
598:
599: sub start_conceptgroup {
600: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
601: $Apache::optionresponse::conceptgroup=1;
602: %Apache::response::conceptgroup=();
603: my $result;
604: if ($target eq 'edit') {
605: $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
606: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
607: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
608: }
609: if ($target eq 'modified') {
610: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
611: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
612: }
613: return $result;
614: }
615:
616: sub end_conceptgroup {
617: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
618: $Apache::optionresponse::conceptgroup=0;
619: my $result='';
620: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
621: $target eq 'tex' || $target eq 'analyze') {
622: #if not there aren't any foils to display and thus no question
623: &Apache::response::pick_foil_for_concept($target,
624: ['value','text','location'],
625: \%Apache::hint::option,
626: $parstack,$safeeval);
627: } elsif ($target eq 'edit') {
628: $result=&Apache::edit::end_table();
629: }
630: return $result;
631: }
632:
633: sub insert_conceptgroup {
634: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
635: return $result;
636: }
637:
638: sub start_foil {
639: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
640: my $result='';
641: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
642: &Apache::lonxml::startredirection;
643: if ($target eq 'analyze') {
644: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
645: }
646: } elsif ($target eq 'edit') {
647: $result=&Apache::edit::tag_start($target,$token,"Foil");
648: my $level='-2';
649: if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
650: my @opt;
651: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
652: $result.=&Apache::edit::text_arg('Name:','name',$token);
653: $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
654: ['unused',(@opt)],$token,'15');
655: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
656: $safeeval,'-3');
657: if ($randomize ne 'no') {
658: $result.=&Apache::edit::select_arg('Location:','location',
659: ['random','top','bottom'],$token);
660: }
661: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
662: } elsif ($target eq 'modified') {
663: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
664: 'value','name','location');
665: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
666: }
667: return $result;
668: }
669:
670: sub end_foil {
671: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
672: my $text ='';
673: my $result = '';
674: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
675: $text=&Apache::lonxml::endredirection;
676: if ($target eq 'tex') {$text=~s/\\strut\s*\\\\\s*\\strut/\\vskip 0 mm/;}
677: if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;}
678: }
679: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
680: || $target eq 'tex' || $target eq 'analyze') {
681: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
682: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
683: $text='\vskip 5mm $\triangleright$ '.$text;
684: }
685: if ($value ne 'unused') {
686: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
687: &Apache::lonxml::debug("Got a name of :$name:");
688: if ($name eq "") {
689: &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
690: $name=$Apache::lonxml::curdepth;
691: }
692: &Apache::lonxml::debug("Using a name of :$name:");
693: if (defined($Apache::response::foilnames{$name})) {
694: &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",'<b><tt>'.$name.'</tt></b>'));
695: }
696: $Apache::response::foilnames{$name}++;
697: my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
698: if ( $Apache::optionresponse::conceptgroup
699: && !&Apache::response::showallfoils() ) {
700: push @{ $Apache::response::conceptgroup{'names'} }, $name;
701: $Apache::response::conceptgroup{"$name.value"} = $value;
702: $Apache::response::conceptgroup{"$name.text"} = $text;
703: $Apache::response::conceptgroup{"$name.location"} = $location;
704: } else {
705: push @{ $Apache::response::foilgroup{'names'} }, $name;
706: $Apache::response::foilgroup{"$name.value"} = $value;
707: $Apache::response::foilgroup{"$name.text"} = $text;
708: $Apache::response::foilgroup{"$name.location"} = $location;
709: }
710: }
711: }
712: if ($target eq 'edit') {
713: $result.= &Apache::edit::tag_end($target,$token,'');
714: }
715: return $result;
716: }
717:
718: sub start_drawoptionlist {
719: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
720: if ($target !~ /^(?:meta|answer|modified|edit)$/) {
721: return $token->[4];
722: }
723: }
724:
725: sub end_drawoptionlist {
726: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
727: if ($target !~ /^(?:meta|answer|modified|edit)$/) {
728: return $token->[2];
729: }
730: }
731:
732: sub insert_foil {
733: return '
734: <foil name="" value="unused">
735: <startouttext />
736: <endouttext />
737: </foil>';
738: }
739:
740: sub insert_drawoptionlist {
741: return '<drawoptionlist />';
742: }
743: 1;
744: __END__
745:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>