1: # LearningOnline Network with CAPA
2: # option list style responses
3: #
4: # $Id: optionresponse.pm,v 1.109 2004/05/06 07:31:32 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'));
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'));
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::setrandomnumber();
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: return $result;
261: }
262:
263: sub getfoilcounts {
264: my ($max)=@_;
265: # +1 since instructors will count from 1
266: my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
267: if (&Apache::response::showallfoils()) { $max=$count; }
268: if ($count>$max) { $count=$max }
269: &Apache::lonxml::debug("Count is $count from $max");
270: return $count;
271: }
272:
273: sub whichfoils {
274: my ($max,$randomize)=@_;
275: return &Apache::response::whichorder($max,$randomize,
276: &Apache::response::showallfoils(),
277: \%Apache::response::foilgroup);
278: }
279:
280: sub displayanswers {
281: my ($max,$randomize,@opt)=@_;
282: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
283: my @names = @{ $Apache::response::foilgroup{'names'} };
284: my @whichopt = &whichfoils($max,$randomize);
285: my $result=&Apache::response::answer_header('optionresponse');
286: foreach my $name (@whichopt) {
287: $result.=&Apache::response::answer_part('optionresponse',
288: $Apache::response::foilgroup{$name.'.value'})
289: }
290: $result.=&Apache::response::answer_footer('optionresponse');
291: return $result;
292: }
293:
294: sub check_for_invalid {
295: my ($names,$options) = @_;
296: my %bad_names;
297: foreach my $name (@{ $names }) {
298: my $value=$Apache::response::foilgroup{$name.'.value'};
299: my $found=0;
300: foreach my $option (@{ $options }) {
301: if ($value eq $option) { $found=1; }
302: }
303: if (!$found) { $bad_names{$name}=$value; }
304: }
305: if (%bad_names) {
306: my $error=&mt('The question can not be gotten correct, '.
307: 'the following foils in the <optionresponse> '.
308: 'have invalid correct options').' <br /><tt>'.
309: join('<br />',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))).
310: "</tt>";
311: &Apache::lonxml::error($error);
312: }
313: }
314:
315: sub displayfoils {
316: my ($target,$max,$randomize,$TeXlayout,@opt)=@_;
317: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
318: my @names = @{ $Apache::response::foilgroup{'names'} };
319: my @truelist;
320: my @falselist;
321: my $result;
322: my $name;
323: my $displayoptionintex=1;
324: my @alphabet = ('A'..'Z');
325: my @whichopt = &whichfoils($max,$randomize);
326: &check_for_invalid(\@whichopt,\@opt);
327: my $part=$Apache::inputtags::part;
328: my $id=$Apache::inputtags::response[-1];
329: my $break;
330: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
331: if ( ($target ne 'tex') &&
332: &Apache::response::show_answer() ) {
333: my $temp=1;
334: foreach $name (@whichopt) {
335: my $text=$Apache::response::foilgroup{$name.'.text'};
336: my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
337: my $lastopt=$lastresponse{$name};
338: if ($text!~/^\s*$/) { $break='<br />'; }
339: $result.=$break;
340: if ($target eq 'web') {
341: my $value=$Apache::response::foilgroup{$name.'.value'};
342: if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
343: if ($text=~/^\s*$/) {
344: $text=$value.$text;
345: } else {
346: $text=$value.': '.$text;
347: }
348: } else {
349: $text='•'.$text;
350: }
351: $result.=$text."\n";
352: }
353: if ($Apache::lonhomework::type eq 'exam') {
354: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
355: }
356: $temp++;
357: }
358: } else {
359: my $temp=1;
360: my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
361: my $internal_counter=$Apache::lonxml::counter;
362: foreach $name (@whichopt) {
363: my $text=$Apache::response::foilgroup{$name.'.text'};
364: if ($text!~/^\s*$/) {
365: if ($target eq 'tex') {
366: $break='\vskip 0 mm ';
367: } elsif ($target eq 'web') {
368: $break='<br />';
369: }
370: }
371: my $lastopt=$lastresponse{$name};
372: my $optionlist="<option></option>\n";
373: my $option;
374: foreach $option (@opt) {
375: if ($option eq $lastopt) {
376: $optionlist.="<option selected=\"on\">$option</option>\n";
377: } else {
378: $optionlist.="<option>$option</option>\n";
379: }
380: }
381: if ($target ne 'tex') {
382: if ($Apache::lonhomework::type ne 'exam') {
383: $optionlist='<select name="HWVAL_'.
384: $Apache::inputtags::response['-1'].':'.$temp.'">'.
385: $optionlist."</select>\n";
386: } else {
387: $optionlist='<u>'.(' 'x10).'</u>';
388: }
389: if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
390: if ($Apache::lonhomework::type ne 'exam') {
391: $text='•'.$text;
392: }
393: } else {
394: if ($Apache::lonhomework::type ne 'exam') {
395: $text=$optionlist.$text;
396: }
397: }
398: $result.=$break.$text."\n";
399: if ($Apache::lonhomework::type eq 'exam') {
400: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
401: }
402: $temp++;
403: } else {
404: my $texoptionlist='';
405: if ($displayoptionintex &&
406: $Apache::lonhomework::type ne 'exam') {
407: $texoptionlist = &optionlist_correction($TeXlayout,@opt);
408: }
409: if ($text=~/<drawoptionlist\s*\/>/) {
410: $text=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
411: }
412:
413: if ($text=~m/\\item /) {
414: if ($Apache::lonhomework::type eq 'exam') {
415: $text=~s/\\item/\\vskip 2 mm/;
416: }
417: $result.= $texoptionlist.$text;
418: } else {
419: if ($Apache::lonhomework::type eq 'exam') {
420: $result.= $texoptionlist.' '.$text;
421: } else {
422: if ($text=~/\S/) {$result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;} else {$result.= $texoptionlist;}
423: }
424: }
425: if ($Apache::lonhomework::type eq 'exam') {
426: $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.
427: $internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).
428: '\end{enumerate} \vskip -8 mm \strut ';
429: $internal_counter++;
430: }
431: $displayoptionintex=0;
432: }
433: }
434: }
435: if ($target ne 'tex') {
436: return $result.$break;
437: } else {
438: return $result;
439: }
440: }
441:
442:
443: sub optionlist_correction {
444: my ($TeXlayout,@options) = @_;
445: my $texoptionlist='\\item [] Choices: ';
446: if ($TeXlayout eq 'vertical') {$texoptionlist='\\item []';}
447: if (scalar(@options) > 0) {
448: foreach my $option (@options) {
449: $texoptionlist.='{\bf '.
450: &Apache::lonxml::latex_special_symbols($option).
451: '}';
452: if ($TeXlayout eq 'vertical') {
453: $texoptionlist.=' \vskip 0 mm ',
454: } else {
455: $texoptionlist.=',';
456: }
457: }
458: chop($texoptionlist);
459: if ($TeXlayout ne 'vertical') {$texoptionlist.='.';}
460: } else {
461: if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';}
462: }
463: return $texoptionlist;
464: }
465:
466:
467: sub webbubbles {
468: my ($ropt,$ralphabet,$temp,$lastopt)=@_;
469: my @opt=@$ropt;
470: my @alphabet=@$ralphabet;
471: my $result='';
472: my $number_of_bubbles = $#opt + 1;
473: $result.= '<table border="1"><tr>';
474: for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
475: my $checked='';
476: if ($lastopt eq $opt[$ind]) {
477: $checked=' checked="on" ';
478: }
479: $result.='<td><input type="radio" name="HWVAL_'.
480: $Apache::inputtags::response['-1'].':'.$temp.
481: '" value="'.$opt[$ind].'" '.$checked.' />'.$alphabet[$ind].': '.
482: $opt[$ind].'</td>';
483: }
484: $result.='</tr></table>';
485: return $result;
486: }
487:
488:
489: sub bubbles {
490: my ($ralphabit,$ropt) = @_;
491: my @alphabet = @$ralphabit;
492: my @opt = @$ropt;
493: my ($result,$head,$line) =('','','');
494: my $number_of_bubbles = $#opt + 1;
495: my $current_length = 0;
496: my $textwidth;
497: if ($ENV{'form.textwidth'} ne '') {
498: $ENV{'form.textwidth'}=~/(\d+)/;
499: $textwidth=$1;
500: } else {
501: $ENV{'textwidth'}=~/(\d*)\.?(\d*)/;
502: $textwidth=$1.'.'.$2;
503: }
504: for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
505: my $leftmargin;
506: $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
507: if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
508: $current_length += (length($opt[$ind])+length($alphabet[$ind])+4)*2;
509: if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
510: $line.='\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
511: $head.='lr';
512: } else {
513: $line=~s/\&\s*$//;
514: $result.='\vskip -2 mm\noindent\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm';
515: $line = '\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';;
516: $head ='lr';
517: $current_length = (length($opt[$ind])+length($alphabet[$ind]))*2;
518: }
519:
520: }
521: return $result;
522: }
523:
524:
525: sub start_conceptgroup {
526: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
527: $Apache::optionresponse::conceptgroup=1;
528: %Apache::response::conceptgroup=();
529: my $result;
530: if ($target eq 'edit') {
531: $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
532: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
533: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
534: }
535: if ($target eq 'modified') {
536: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
537: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
538: }
539: return $result;
540: }
541:
542: sub end_conceptgroup {
543: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
544: $Apache::optionresponse::conceptgroup=0;
545: my $result='';
546: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
547: $target eq 'tex' || $target eq 'analyze') {
548: #if not there aren't any foils to display and thus no question
549: &Apache::response::pick_foil_for_concept($target,
550: ['value','text','location'],
551: \%Apache::hint::option,
552: $parstack,$safeeval);
553: } elsif ($target eq 'edit') {
554: $result=&Apache::edit::end_table();
555: }
556: return $result;
557: }
558:
559: sub insert_conceptgroup {
560: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
561: return $result;
562: }
563:
564: sub start_foil {
565: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
566: my $result='';
567: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
568: &Apache::lonxml::startredirection;
569: if ($target eq 'analyze') {
570: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
571: }
572: } elsif ($target eq 'edit') {
573: $result=&Apache::edit::tag_start($target,$token,"Foil");
574: my $level='-2';
575: if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
576: my @opt;
577: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
578: $result.=&Apache::edit::text_arg('Name:','name',$token);
579: $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
580: ['unused',(@opt)],$token,'15');
581: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
582: $safeeval,'-3');
583: if ($randomize ne 'no') {
584: $result.=&Apache::edit::select_arg('Location:','location',
585: ['random','top','bottom'],$token);
586: }
587: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
588: } elsif ($target eq 'modified') {
589: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
590: 'value','name','location');
591: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
592: }
593: return $result;
594: }
595:
596: sub end_foil {
597: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
598: my $text ='';
599: my $result = '';
600: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
601: $text=&Apache::lonxml::endredirection;
602: $text=~/(\w)/;
603: if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;}
604: }
605: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
606: || $target eq 'tex' || $target eq 'analyze') {
607: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
608: if ($value ne 'unused') {
609: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
610: &Apache::lonxml::debug("Got a name of :$name:");
611: if (!$name) { $name=$Apache::lonxml::curdepth; }
612: &Apache::lonxml::debug("Using a name of :$name:");
613: if (defined($Apache::response::foilnames{$name})) {
614: &Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
615: }
616: $Apache::response::foilnames{$name}++;
617: my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
618: if ( $Apache::optionresponse::conceptgroup
619: && !&Apache::response::showallfoils() ) {
620: push @{ $Apache::response::conceptgroup{'names'} }, $name;
621: $Apache::response::conceptgroup{"$name.value"} = $value;
622: if ($target eq 'tex' and $Apache::lonhomework::type eq 'exam') {
623: $Apache::response::conceptgroup{"$name.text"} = '\vskip 4 mm $\triangleright$ '.$text;
624: } else {
625: $Apache::response::conceptgroup{"$name.text"} = $text;
626: }
627: $Apache::response::conceptgroup{"$name.location"} = $location;
628: } else {
629: push @{ $Apache::response::foilgroup{'names'} }, $name;
630: $Apache::response::foilgroup{"$name.value"} = $value;
631: if ($target eq 'tex' and $Apache::lonhomework::type eq 'exam') {
632: $Apache::response::foilgroup{"$name.text"} = '\vskip 5 mm $\triangleright$ '.$text;
633: } else {
634: $Apache::response::foilgroup{"$name.text"} = $text;
635: }
636: $Apache::response::foilgroup{"$name.location"} = $location;
637: }
638: }
639: }
640: if ($target eq 'edit') {
641: $result.= &Apache::edit::tag_end($target,$token,'');
642: }
643: return $result;
644: }
645:
646: sub insert_foil {
647: return '
648: <foil name="" value="unused">
649: <startouttext />
650: <endouttext />
651: </foil>';
652: }
653: 1;
654: __END__
655:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>