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