File:
[LON-CAPA] /
loncom /
homework /
optionresponse.pm
Revision
1.153:
download - view:
text,
annotated -
select for diffs
Fri Oct 24 16:22:54 2008 UTC (15 years, 10 months ago) by
bisitz
Branches:
MAIN
CVS tags:
HEAD
Localization, wording, nobreaks for Colorful Editor
- Added missing &mt() calls at several places (more to be done)
- Same wording "Delete?" for all Delete options
- Same wording style, e.g. added ":" after text and before optionlist
- Added nobreak style for some elements which need to stay together, e.g. help_open_topic in loncommon.pm
- Added/updated some related German translations
1: # LearningOnline Network with CAPA
2: # option list style responses
3: #
4: # $Id: optionresponse.pm,v 1.153 2008/10/24 16:22:54 bisitz 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',&mt('Normal list')],
64: ['vertical',&mt('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: if($env{'form.pdfFormFields'} ne 'yes') {
165: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}
166: \begin{enumerate} ';
167: } else {
168: $result .= "\\\\";
169: }
170: }
171: return $result;
172: }
173:
174: sub end_foilgroup {
175: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
176:
177: my $result;
178: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
179: $target eq 'tex' || $target eq 'analyze') {
180: my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
181: my $name;
182: my @opt;
183: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
184: &Apache::lonxml::debug("options:".join(':',@opt));
185:
186: my $TeXlayout=&Apache::lonxml::get_param('TeXlayout',$parstack,$safeeval,
187: -2,0);
188: if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
189: &Apache::lonxml::debug("Options are $#opt");
190: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
191: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
192: $safeeval,'-2');
193: if ($target eq 'web' || $target eq 'tex') {
194: $result.=&displayfoils($target,$max,$randomize,$TeXlayout,@opt);
195: $Apache::lonxml::post_evaluate=0;
196: } elsif ( $target eq 'answer') {
197: $result.=&displayanswers($max,$randomize,@opt);
198:
199: } elsif ( $target eq 'analyze') {
200: my @shown = &whichfoils($max,$randomize);
201: &Apache::response::analyze_store_foilgroup(\@shown,
202: ['text','value','location']);
203: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
204: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
205: } elsif ( $target eq 'grade') {
206: if ( &Apache::response::submitted()) {
207: my @whichopt = &whichfoils($max,$randomize);
208: my $temp=1;my $name;
209: my %responsehash;
210: my %grade;
211: my $right=0;
212: my $wrong=0;
213: my $ignored=0;
214: foreach $name (@whichopt) {
215: my $response=&Apache::response::getresponse($temp);
216: if ($env{'form.submitted'} eq 'scantron' && $response=~/\S/) {
217: $response = $opt[$response];
218: }
219: if ( $response =~ /[^\s]/) {
220: $responsehash{$name}=$response;
221: my $value=$Apache::response::foilgroup{$name.'.value'};
222: &Apache::lonxml::debug("submitted a $response for $value<br />\n");
223: if ($value eq $response) {
224: $grade{$name}='1'; $right++;
225: } else {
226: $grade{$name}='0'; $wrong++;
227: }
228: } else {
229: $ignored++;
230: }
231: $temp++;
232: }
233: my $part=$Apache::inputtags::part;
234: my $id = $Apache::inputtags::response['-1'];
235: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
236: my $gradestr =&Apache::lonnet::hash2str(%grade);
237: my %previous=&Apache::response::check_for_previous($responsestr,
238: $part,$id);
239: &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
240: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
241: $responsestr;
242: $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
243:
244: if ($Apache::lonhomework::type eq 'survey') {
245: if ($ignored == 0) {
246: my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
247: &Apache::response::handle_previous(\%previous,$ad);
248: } elsif ($wrong==0 && $right==0) {
249: } else {
250: my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='MISSING_ANSWER';
251: &Apache::response::handle_previous(\%previous,$ad);
252: }
253: } elsif (!$Apache::lonhomework::scantronmode) {
254: my $ad;
255: if ($wrong==0 && $ignored==0) {
256: $ad='EXACT_ANS';
257: } elsif ($wrong==0 && $right==0) {
258: #nothing submitted
259: } else {
260: if ($ignored==0) {
261: $ad='INCORRECT';
262: } else {
263: $ad='MISSING_ANSWER';
264: }
265: }
266: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
267: &Apache::response::handle_previous(\%previous,$ad);
268: } else {
269: my $ad;
270: if ($wrong==0 && $right==0) {
271: #nothing submitted only assign a score if we
272: #need to override a previous grade
273: if (defined($Apache::lonhomework::history{"resource.$part.$id.awarddetail"})) {
274: $ad='ASSIGNED_SCORE';
275: }
276: } else {
277: $ad='ASSIGNED_SCORE';
278: }
279: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
280: $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
281: $right/(scalar(@whichopt));
282: $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
283: scalar(@whichopt);
284: }
285: }
286: }
287: my $part_id = $Apache::inputtags::part;
288: my $response_id = $Apache::inputtags::response[-1];
289: &Apache::lonxml::increment_counter(&getfoilcounts($max),
290: "$part_id.$response_id");
291: if ($target eq 'analyze') {
292: &Apache::lonhomework::set_bubble_lines();
293: }
294:
295: } elsif ($target eq 'edit') {
296: $result.=&Apache::edit::end_table();
297: }
298: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
299: if($env{'form.pdfFormFields'} ne 'yes') {
300: $result .= '\end{enumerate}';
301: } else {
302: $result .= "\\\\";
303: }
304: }
305: &Apache::response::poprandomnumber();
306: return $result;
307: }
308:
309: sub getfoilcounts {
310: my ($max)=@_;
311: # +1 since instructors will count from 1
312: my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
313: if (&Apache::response::showallfoils()) { $max=$count; }
314: if ($count>$max) { $count=$max }
315: &Apache::lonxml::debug("Count is $count from $max");
316: return $count;
317: }
318:
319: sub whichfoils {
320: my ($max,$randomize)=@_;
321: return &Apache::response::whichorder($max,$randomize,
322: &Apache::response::showallfoils(),
323: \%Apache::response::foilgroup);
324: }
325:
326: sub displayanswers {
327: my ($max,$randomize,@opt)=@_;
328: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
329: my @names = @{ $Apache::response::foilgroup{'names'} };
330: my @whichopt = &whichfoils($max,$randomize);
331: my $result;
332: if ($Apache::lonhomework::type eq 'exam') {
333: my $i = 0;
334: my %opt = map { ($_,$i++) } @opt;
335:
336: $i = 0;
337: my @alphabet = ('A'..'Z');
338: foreach my $name (@whichopt) {
339: $result.=&Apache::response::answer_header('optionresponse',$i++);
340: $result.=&Apache::response::answer_part('optionresponse',
341: $alphabet[$opt{$Apache::response::foilgroup{$name.'.value'}}]);
342: $result.=&Apache::response::answer_part('optionresponse',
343: $Apache::response::foilgroup{$name.'.value'});
344: $result.=&Apache::response::answer_footer('optionresponse');
345: }
346: } else {
347: $result=&Apache::response::answer_header('optionresponse');
348: foreach my $name (@whichopt) {
349: $result.=&Apache::response::answer_part('optionresponse',
350: $Apache::response::foilgroup{$name.'.value'});
351: }
352: $result.=&Apache::response::answer_footer('optionresponse');
353: }
354: return $result;
355: }
356:
357: sub check_for_invalid {
358: my ($names,$options) = @_;
359: my %bad_names;
360: foreach my $name (@{ $names }) {
361: my $value=$Apache::response::foilgroup{$name.'.value'};
362: my $found=0;
363: foreach my $option (@{ $options }) {
364: if ($value eq $option) { $found=1; }
365: }
366: if (!$found) { $bad_names{$name}=$value; }
367: }
368: if (%bad_names) {
369: my $error=&mt('The question can not be gotten correct, '.
370: 'the following foils in the <optionresponse> '.
371: 'have invalid correct options').' <br /><tt>'.
372: join('<br />',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))).
373: "</tt>";
374: &Apache::lonxml::error($error);
375: }
376: }
377:
378: sub displayfoils {
379: my ($target,$max,$randomize,$TeXlayout,@opt)=@_;
380: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
381: my @names = @{ $Apache::response::foilgroup{'names'} };
382: my @truelist;
383: my @falselist;
384: my $result;
385: my $name;
386: my $displayoptionintex=1;
387: my @alphabet = ('A'..'Z');
388: my @whichopt = &whichfoils($max,$randomize);
389: &check_for_invalid(\@whichopt,\@opt);
390: my $part=$Apache::inputtags::part;
391: my $id=$Apache::inputtags::response[-1];
392: my $break;
393: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
394: if ( ($target ne 'tex') &&
395: &Apache::response::show_answer() ) {
396: my $temp=1;
397: foreach $name (@whichopt) {
398: my $text=$Apache::response::foilgroup{$name.'.text'};
399: my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
400: my $lastopt=$lastresponse{$name};
401: if ($text!~/^\s*$/) { $break='<br />'; }
402: $result.=$break;
403: if ($target eq 'web') {
404: my $value=$Apache::response::foilgroup{$name.'.value'};
405: if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
406: if ($text=~/^\s*$/) {
407: $text=$value.$text;
408: } else {
409: $text='<b>'.$value.':</b> '.$text;
410: }
411: } else {
412: $text='•'.$text;
413: }
414: $result.=$text."\n";
415: }
416: if ($Apache::lonhomework::type eq 'exam') {
417: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
418: }
419: $temp++;
420: }
421: } else {
422: my $temp=1;
423: my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
424: my $internal_counter=$Apache::lonxml::counter;
425: foreach $name (@whichopt) {
426: my $text=$Apache::response::foilgroup{$name.'.text'};
427: if ($text!~/^\s*$/) {
428: if ($target eq 'tex') {
429: $break='\vskip 0 mm ';
430: } elsif ($target eq 'web') {
431: $break='<br />';
432: }
433: }
434: my $lastopt=$lastresponse{$name};
435: my $optionlist="<option></option>\n";
436:
437: if($target eq 'tex' and $env{'form.pdfFormFields'} eq 'yes') {
438: my $fieldname = $env{'request.symb'}.'&part_'.$Apache::inputtags::part.'&optionresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp;
439: $optionlist = &Apache::lonxml::print_pdf_start_combobox($fieldname);
440: }
441:
442: foreach my $option (@opt) {
443: my $escopt=&HTML::Entities::encode($option,'\'"&<>');
444: if ($option eq $lastopt) {
445: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
446: $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
447: } else {
448: $optionlist.="<option value='".$escopt."' selected=\"selected\">$option</option>\n";
449: }
450: } else {
451: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
452: $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
453: } else {
454: $optionlist.="<option value='".$escopt."'>$option</option>\n";
455: }
456: }
457: }
458: if ($target ne 'tex') {
459: if ($Apache::lonhomework::type ne 'exam') {
460: $optionlist='<select onchange="javascript:setSubmittedPart(\''.
461: $part.'\');" name="HWVAL_'.
462: $Apache::inputtags::response['-1'].':'.$temp.'">'.
463: $optionlist."</select>\n";
464: } else {
465: $optionlist='<u>'.(' 'x10).'</u>';
466: }
467: if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
468: if ($Apache::lonhomework::type ne 'exam') {
469: $text='•'.$text;
470: }
471: } else {
472: if ($Apache::lonhomework::type ne 'exam') {
473: $text=$optionlist.$text;
474: }
475: }
476: $result.=$break.$text."\n";
477: if ($Apache::lonhomework::type eq 'exam') {
478: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
479: }
480: $temp++;
481: } else {
482: my $texoptionlist='';
483: if ($displayoptionintex &&
484: $Apache::lonhomework::type ne 'exam') {
485: $texoptionlist = &optionlist_correction($TeXlayout,@opt);
486: }
487: if ($text=~/<drawoptionlist\s*\/>/) {
488: $text=~s|<drawoptionlist\s*\/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |g;
489: }
490:
491: if ($text=~m/\\item /) {
492: if ($Apache::lonhomework::type eq 'exam') {
493: $text=~s/\\item/\\vskip 2 mm/;
494: } elsif ($env{'form.pdfFormFields'} ne 'yes') {
495: $result.= $texoptionlist.$text;
496: }
497: } else {
498: if ($Apache::lonhomework::type eq 'exam') {
499: $result.= $texoptionlist.' '.$text;
500: } elsif ($env{'form.pdfFormFields'} ne 'yes') {
501: if ($text=~/\S/) {
502: $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
503: } else {
504: $result.= $texoptionlist;
505: }
506: }
507: }
508: if ($Apache::lonhomework::type eq 'exam') {
509: $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.
510: $internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).
511: '\end{enumerate} \vskip -8 mm \strut ';
512: $internal_counter++;
513: }
514: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
515: $text =~ s/.*indent(.*)$/$1/;
516: $text = $1;
517: $result .= " $optionlist ". &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
518: $temp++;
519: }
520: $displayoptionintex=0;
521: }
522: }
523: }
524:
525: if ($target eq 'web') {
526: &Apache::response::setup_prior_tries_hash(\&Apache::rankresponse::format_prior_answer,
527: [\@whichopt,
528: 'submissiongrading']);
529: }
530:
531: if ($target ne 'tex') {
532: return $result.$break;
533: } else {
534: return $result;
535: }
536: }
537:
538:
539: sub optionlist_correction {
540: my ($TeXlayout,@options) = @_;
541: my $texoptionlist='\\item [] '.&mt('Choices:').' ';
542: if ($TeXlayout eq 'vertical') {$texoptionlist='\\item []';}
543: if (scalar(@options) > 0) {
544: foreach my $option (@options) {
545: $texoptionlist.='{\bf '.
546: &Apache::lonxml::latex_special_symbols($option).
547: '}';
548: if ($TeXlayout eq 'vertical') {
549: $texoptionlist.=' \vskip 0 mm ',
550: } else {
551: $texoptionlist.=', ';
552: }
553: }
554: $texoptionlist=~s/, $//;
555: if ($TeXlayout ne 'vertical') {$texoptionlist.='.';}
556: } else {
557: if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';}
558: }
559: return $texoptionlist;
560: }
561:
562:
563: sub webbubbles {
564: my ($ropt,$ralphabet,$temp,$lastopt)=@_;
565: my @opt=@$ropt;
566: my @alphabet=@$ralphabet;
567: my $result='';
568: my $number_of_bubbles = $#opt + 1;
569: $result.= '<table border="1"><tr>';
570: for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
571: my $checked='';
572: if ($lastopt eq $opt[$ind]) {
573: $checked=' checked="on" ';
574: }
575: $result.='<td><input type="radio" name="HWVAL_'.
576: $Apache::inputtags::response['-1'].':'.$temp.
577: '" value="'.$opt[$ind].'" '.$checked.' />';
578: if ($alphabet[$ind]) {
579: $result.=$alphabet[$ind].': ';
580: }
581: $result.=$opt[$ind].'</td>';
582: }
583: $result.='</tr></table>';
584: return $result;
585: }
586:
587:
588: sub bubbles {
589: my ($ralphabet,$ropt,$response, $max_width) = @_;
590: my @alphabet = @$ralphabet;
591: my @opt = @$ropt;
592: my ($result,$head,$line) =('','','');
593: my $number_of_bubbles = $#opt + 1;
594: my $current_length = 0;
595: my $textwidth;
596: if (defined($max_width)) {
597: $textwidth=$max_width;
598: &Apache::lonxml::debug("Max width passed in: $max_width");
599: } elsif ($env{'form.textwidth'} ne '') {
600: $env{'form.textwidth'}=~/(\d+)/;
601: $textwidth=$1;
602: &Apache::lonxml::debug("Max width from form: $textwidth");
603: } else {
604: $env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
605: $textwidth=$1.'.'.$2;
606: &Apache::lonxml::debug("Max width defaults? $textwidth");
607: }
608: &Apache::lonxml::debug("Final maxwidth: $textwidth");
609: for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
610: my $leftmargin;
611: $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
612: if ($response eq 'rankresponse') {$opt[$ind]='Rank '.$opt[$ind];}
613: if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
614:
615: $current_length += (length($opt[$ind])+length($alphabet[$ind])+4)*2;
616: if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
617: $line.='\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
618: $head.='lr';
619: } else {
620: $line=~s/\&\s*$//;
621: $result.='\vskip -2 mm\noindent\setlength{\tabcolsep}{2 mm}\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm';
622: $line = '\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';;
623: $head ='lr';
624: $current_length = (length($opt[$ind])+length($alphabet[$ind]))*2;
625: }
626:
627: }
628: return $result;
629: }
630:
631:
632: sub start_conceptgroup {
633: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
634: $Apache::optionresponse::conceptgroup=1;
635: %Apache::response::conceptgroup=();
636: my $result;
637: if ($target eq 'edit') {
638: $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
639: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
640: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
641: }
642: if ($target eq 'modified') {
643: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
644: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
645: }
646: return $result;
647: }
648:
649: sub end_conceptgroup {
650: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
651: $Apache::optionresponse::conceptgroup=0;
652: my $result='';
653: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
654: $target eq 'tex' || $target eq 'analyze') {
655: #if not there aren't any foils to display and thus no question
656: &Apache::response::pick_foil_for_concept($target,
657: ['value','text','location'],
658: \%Apache::hint::option,
659: $parstack,$safeeval);
660: } elsif ($target eq 'edit') {
661: $result=&Apache::edit::end_table();
662: }
663: return $result;
664: }
665:
666: sub insert_conceptgroup {
667: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
668: return $result;
669: }
670:
671: sub start_foil {
672: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
673: my $result='';
674: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
675: &Apache::lonxml::startredirection;
676: if ($target eq 'analyze') {
677: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
678: }
679: } elsif ($target eq 'edit') {
680: $result=&Apache::edit::tag_start($target,$token,"Foil");
681: my $level='-2';
682: if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
683: my @opt;
684: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
685: $result.=&Apache::edit::text_arg('Name:','name',$token);
686: $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
687: ['unused',(@opt)],$token,'15');
688: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
689: $safeeval,'-3');
690: if ($randomize ne 'no') {
691: $result.=&Apache::edit::select_arg('Location:','location',
692: ['random','top','bottom'],$token);
693: }
694: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
695: } elsif ($target eq 'modified') {
696: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
697: 'value','name','location');
698: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
699: }
700: return $result;
701: }
702:
703: sub end_foil {
704: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
705: my $text ='';
706: my $result = '';
707: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
708: $text=&Apache::lonxml::endredirection;
709: if ($target eq 'tex') {$text=~s/\\strut\s*\\\\\s*\\strut/\\vskip 0 mm/;}
710: if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;}
711: }
712: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
713: || $target eq 'tex' || $target eq 'analyze') {
714: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
715: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
716: $text='\vskip 5mm $\triangleright$ '.$text;
717: }
718: if ($value ne 'unused') {
719: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
720: &Apache::lonxml::debug("Got a name of :$name:");
721: if ($name eq "") {
722: &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
723: $name=$Apache::lonxml::curdepth;
724: }
725: &Apache::lonxml::debug("Using a name of :$name:");
726: if (defined($Apache::response::foilnames{$name})) {
727: &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",'<b><tt>'.$name.'</tt></b>'));
728: }
729: $Apache::response::foilnames{$name}++;
730: my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
731: if ( $Apache::optionresponse::conceptgroup
732: && !&Apache::response::showallfoils() ) {
733: push @{ $Apache::response::conceptgroup{'names'} }, $name;
734: $Apache::response::conceptgroup{"$name.value"} = $value;
735: $Apache::response::conceptgroup{"$name.text"} = $text;
736: $Apache::response::conceptgroup{"$name.location"} = $location;
737: } else {
738: push @{ $Apache::response::foilgroup{'names'} }, $name;
739: $Apache::response::foilgroup{"$name.value"} = $value;
740: $Apache::response::foilgroup{"$name.text"} = $text;
741: $Apache::response::foilgroup{"$name.location"} = $location;
742: }
743: }
744: }
745: if ($target eq 'edit') {
746: $result.= &Apache::edit::tag_end($target,$token,'');
747: }
748: return $result;
749: }
750:
751: sub start_drawoptionlist {
752: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
753: if ($target !~ /^(?:meta|answer|modified|edit)$/) {
754: return $token->[4];
755: }
756: }
757:
758: sub end_drawoptionlist {
759: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
760: if ($target !~ /^(?:meta|answer|modified|edit)$/) {
761: return $token->[2];
762: }
763: }
764:
765: sub insert_foil {
766: return '
767: <foil name="" value="unused">
768: <startouttext />
769: <endouttext />
770: </foil>';
771: }
772:
773: sub insert_drawoptionlist {
774: return '<drawoptionlist />';
775: }
776: 1;
777: __END__
778:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>