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