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