Annotation of loncom/homework/matchresponse.pm, revision 1.28
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Full matching style response
3: #
1.28 ! albertel 4: # $Id: matchresponse.pm,v 1.27 2003/10/15 19:40:42 albertel Exp $
1.1 albertel 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:
29: package Apache::matchresponse;
30: use strict;
31: use HTML::Entities();
32: use Math::Random();
1.6 sakharuk 33: use Apache::optionresponse;
34:
1.1 albertel 35: BEGIN {
36: &Apache::lonxml::register('Apache::matchresponse',('matchresponse'));
37: }
38:
39: sub start_matchresponse {
40: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
41: my $result;
42: #when in a matchresponse use these
43: &Apache::lonxml::register('Apache::matchresponse',
44: ('foilgroup','foil','conceptgroup','item',
45: 'itemgroup'));
46: push (@Apache::lonxml::namespace,'matchresponse');
47: my $id = &Apache::response::start_response($parstack,$safeeval);
48: %Apache::hint::match=();
49: if ($target eq 'meta') {
50: $result=&Apache::response::meta_package_write('matchresponse');
51: } elsif ($target eq 'edit' ) {
52: $result.=&Apache::edit::start_table($token).
53: '<tr><td>'.&Apache::lonxml::description($token)."</td><td>Delete:".
54: &Apache::edit::deletelist($target,$token)
55: ."</td><td> ".&Apache::edit::end_row()
56: .&Apache::edit::start_spanning_row();
57:
58: $result.=
59: &Apache::edit::text_arg('Max Number Of Shown Foils:','max',$token,'4').
60: &Apache::edit::select_arg('Randomize Foil Order','randomize',
61: ['yes','no'],$token).
62: &Apache::edit::end_row().&Apache::edit::start_spanning_row()."\n";
63: } elsif ($target eq 'modified') {
64: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
65: $safeeval,'max',
66: 'randomize');
67: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.28 ! albertel 68: } elsif ($target eq 'analyze') {
! 69: my $part_id="$Apache::inputtags::part.$id";
! 70: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.1 albertel 71: }
72: return $result;
73: }
74:
75: sub end_matchresponse {
76: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
77: my $result;
78: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
79: &Apache::response::end_response;
80: pop @Apache::lonxml::namespace;
81: &Apache::lonxml::deregister('Apache::matchresponse',
82: ('foilgroup','foil','conceptgroup'));
83: return $result;
84: }
85:
86: %Apache::response::itemgroup=();
87: sub start_itemgroup {
88: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
89: my $result;
90: %Apache::response::itemgroup=();
1.4 albertel 91: %Apache::matchresponse::itemtable=();
1.15 albertel 92:
1.1 albertel 93: if ($target eq 'edit') {
94: $result=&Apache::edit::tag_start($target,$token);
95: $result.=&Apache::edit::select_arg('Randomize Order:','randomize',
96: ['yes','no'],$token);
1.4 albertel 97: $result.=&Apache::edit::select_arg('Items Display Location:',
98: 'location',
99: ['top','bottom','left','right'],
100: $token);
1.1 albertel 101: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.4 albertel 102: } elsif ($target eq 'modified') {
103: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
104: $safeeval,'randomize',
105: 'location');
106: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.21 sakharuk 107: } elsif ($target eq 'web' or $target eq 'tex') {
1.4 albertel 108: $Apache::matchresponse::itemtable{'location'}=
109: &Apache::lonxml::get_param('location',$parstack,$safeeval);
1.1 albertel 110: }
111: return $result;
112: }
113:
114: sub end_itemgroup {
115: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
116: my $result;
117:
1.17 albertel 118: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
1.1 albertel 119: if (!defined(@{ $Apache::response::itemgroup{'names'} })) { return; }
120: my @names=@{ $Apache::response::itemgroup{'names'} };
121: my $randomize =&Apache::lonxml::get_param('randomize',$parstack,$safeeval);
1.2 albertel 122: if ($randomize ne 'no' ) {
1.18 albertel 123: @names=&Apache::response::whichorder($#names+1,$randomize,0,
124: \%Apache::response::itemgroup);
1.1 albertel 125: }
126: my %letter_name_map;
127: my %name_letter_map;
128: my @alphabet=('A'..'Z');
129: my $i=0;
130: foreach my $name (@names) {
131: $letter_name_map{$alphabet[$i]}=$name;
132: $name_letter_map{$name}=$alphabet[$i];
133: $i++;
134: }
1.15 albertel 135: $Apache::response::itemgroup{'letter_name_map'}=\%letter_name_map;
1.1 albertel 136: $Apache::response::itemgroup{'name_letter_map'}=\%name_letter_map;
137: if ($target eq 'web') {
1.4 albertel 138: my $table='<table>';
1.1 albertel 139: my $i=0;
140: foreach my $name (@names) {
1.4 albertel 141: $table.='<tr><td>'.$alphabet[$i].'</td><td>'.
1.1 albertel 142: $Apache::response::itemgroup{$name.'.text'}.
143: '</td></tr>';
144: $i++;
145: }
1.4 albertel 146: $table.='</table>';
147: $Apache::matchresponse::itemtable{'display'}=$table;
1.5 sakharuk 148: } elsif ($target eq 'tex') {
1.22 sakharuk 149: my $table=' \begin{description} ';
1.5 sakharuk 150: my $i=0;
151: foreach my $name (@names) {
1.11 sakharuk 152: $Apache::response::itemgroup{$name.'.text'}=~s/\$\$/\$/g;
1.19 sakharuk 153: $table.='\item['.$alphabet[$i].'] '.
1.21 sakharuk 154: $Apache::response::itemgroup{$name.'.text'};
1.5 sakharuk 155: $i++;
156: }
1.22 sakharuk 157: $table.=' \end{description} \strut ';
1.5 sakharuk 158: $Apache::matchresponse::itemtable{'display'}=$table;
1.17 albertel 159: }
1.1 albertel 160: return $result;
161: }
162:
163: sub start_item {
164: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
165: my $result='';
1.5 sakharuk 166: if ($target eq 'web' || $target eq 'tex') {
1.1 albertel 167: &Apache::lonxml::startredirection;
168: } elsif ($target eq 'edit') {
1.3 albertel 169: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
170: $safeeval,'-2');
1.1 albertel 171: $result=&Apache::edit::tag_start($target,$token,"Item");
172: $result.=&Apache::edit::text_arg('Name:','name',$token);
1.3 albertel 173: if ($randomize ne 'no') {
174: $result.=&Apache::edit::select_arg('Location:','location',
175: ['random','top','bottom'],
176: $token);
177: }
178: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.1 albertel 179: } elsif ($target eq 'modified') {
180: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.3 albertel 181: $safeeval,'name',
182: 'location');
1.1 albertel 183: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
184: }
185: return $result;
186: }
187:
188: sub end_item {
189: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
190: my $text ='';
191: my $result = '';
1.5 sakharuk 192: if ($target eq 'web' || $target eq 'tex') {
1.1 albertel 193: $text=&Apache::lonxml::endredirection;
194: }
195: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.5 sakharuk 196: $target eq 'edit' || $target eq 'tex') {
1.1 albertel 197: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.3 albertel 198: my $location=&Apache::lonxml::get_param('location',$parstack,
199: $safeeval);
1.1 albertel 200: &Apache::lonxml::debug("Got a name of :$name:");
201: if (!$name) { $name=$Apache::lonxml::curdepth; }
202: &Apache::lonxml::debug("Using a name of :$name:");
203: push @{ $Apache::response::itemgroup{'names'} }, $name;
204: $Apache::response::itemgroup{"$name.text"} = $text;
1.3 albertel 205: $Apache::response::itemgroup{"$name.location"} = $location;
1.1 albertel 206: }
207: if ($target eq 'edit') {
208: $result.= &Apache::edit::tag_end($target,$token,'');
209: }
210: return $result;
211: }
212:
213: sub insert_item {
214: return '
215: <item name="">
216: <startouttext />
217: <endouttext />
218: </item>';
219: }
220:
221: %Apache::response::foilgroup=();
222: sub start_foilgroup {
223: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
224: my $result;
225: %Apache::response::foilgroup=();
226: $Apache::matchresponse::conceptgroup=0;
227: &Apache::response::setrandomnumber();
228: if ($target eq 'edit') {
229: $result.=&Apache::edit::start_table($token)
230: ."<tr><td>Collection Of Foils</td><td>Delete:"
231: .&Apache::edit::deletelist($target,$token)
232: ."</td><td> ".&Apache::edit::end_row()
233: .&Apache::edit::start_spanning_row()."\n";
234: }
235: return $result;
236: }
237:
238: sub end_foilgroup {
239: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
240: my $result;
1.28 ! albertel 241: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 242: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
243: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
244: $safeeval,'-2');
1.5 sakharuk 245: if ($target eq 'web' || $target eq 'tex') {
1.1 albertel 246: $result=&displayfoils($target,$max,$randomize);
247: } elsif ($target eq 'answer' ) {
248: $result=&displayanswers($max,$randomize);
249: } elsif ( $target eq 'grade') {
250: &grade_response($max,$randomize);
1.28 ! albertel 251: } elsif ( $target eq 'analyze') {
! 252: my @shown=&whichfoils($max,$randomize);
! 253: &Apache::response::analyze_store_foilgroup(\@shown,
! 254: ['text','value']);
! 255: #FIXME need to store options in some way
1.1 albertel 256: }
1.20 sakharuk 257: &Apache::lonxml::increment_counter(&getfoilcounts($max));
1.1 albertel 258: } elsif ($target eq 'edit') {
259: $result=&Apache::edit::end_table();
260: }
261: return $result;
262: }
263:
264: sub displayanswers {
265: my ($max,$randomize,@opt)=@_;
266: if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
267: my @names = @{ $Apache::response::foilgroup{'names'} };
1.18 albertel 268: my @whichfoils = &Apache::response::whichorder(&getfoilcounts($max),
269: $randomize,
270: &Apache::response::showallfoils(),
271: \%Apache::response::foilgroup);
1.1 albertel 272: my $result=&Apache::response::answer_header('matchresponse');
273: my %name_letter_map;
274: if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
275: %name_letter_map=
276: %{ $Apache::response::itemgroup{'name_letter_map'} };
277: }
278: foreach my $name (@whichfoils) {
279: my $value_name=$Apache::response::foilgroup{$name.'.value'};
280: my $letter=$name_letter_map{$value_name};
281: $result.=&Apache::response::answer_part('matchresponse',$letter);
282: }
283: $result.=&Apache::response::answer_footer('matchresponse');
284: return $result;
285: }
286:
287:
288: sub grade_response {
289: my ($max,$randomize)=@_;
1.18 albertel 290: my (@whichfoils)=&Apache::response::whichorder(&getfoilcounts($max),
291: $randomize,
292: &Apache::response::showallfoils(),
293: \%Apache::response::foilgroup);
1.1 albertel 294: if (!defined($ENV{'form.submitted'})) { return; }
295: my %responsehash;
296: my %grade;
297: my ($temp,$right,$wrong,$ignored)=(0,0,0,0);
298: my %letter_name_map;
299: if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
300: %letter_name_map=
301: %{ $Apache::response::itemgroup{'letter_name_map'} };
302: }
303: foreach my $name (@whichfoils) {
1.27 albertel 304: my $response = &Apache::response::getresponse($temp);
1.1 albertel 305: my $responsename = $letter_name_map{$response};
306: $responsehash{$name}=$responsename;
307: my $value=$Apache::response::foilgroup{$name.'.value'};
308: if ( $response =~ /[^\s]/) {
309: &Apache::lonxml::debug("submitted a $response for $value<br />\n");
310: if ($value eq $responsename) {
311: $grade{$name}='1'; $right++;
312: } else {
313: $grade{$name}='0'; $wrong++;
314: }
315: } else {
316: $ignored++;
317: }
318: $temp++;
319: }
320: my $part=$Apache::inputtags::part;
321: my $id = $Apache::inputtags::response['-1'];
322: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
323: my $gradestr =&Apache::lonnet::hash2str(%grade);
324: my %previous =&Apache::response::check_for_previous($responsestr,
325: $part,$id);
326: &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored ");
327: my $ad;
328: if ($wrong==0 && $ignored==0) {
329: $ad='EXACT_ANS';
330: } elsif ($wrong==0 && $right==0) {
331: #nothing submitted
332: } else {
333: if ($ignored==0) {
334: $ad='INCORRECT';
335: } else {
336: $ad='MISSING_ANSWER';
337: }
338: }
339: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
340: $responsestr;
341: $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=
342: $gradestr;
343: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
344: &Apache::response::handle_previous(\%previous,$ad);
345: }
346:
1.4 albertel 347: sub itemdisplay {
348: my ($location)=@_;
349: if ($location eq 'top' &&
350: !defined($Apache::matchresponse::itemtable{'location'})) {
351: return $Apache::matchresponse::itemtable{'display'};
352: }
353: if ($Apache::matchresponse::itemtable{'location'} eq $location) {
354: return $Apache::matchresponse::itemtable{'display'};
355: }
356: return undef;
357: }
1.1 albertel 358: sub displayfoils {
359: my ($target,$max,$randomize)=@_;
360: my $result;
1.4 albertel 361: my $question;
1.18 albertel 362: my (@whichfoils)=&Apache::response::whichorder(&getfoilcounts($max),
363: $randomize,
364: &Apache::response::showallfoils(),
365: \%Apache::response::foilgroup);
1.1 albertel 366: my $part=$Apache::inputtags::part;
367: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
368: my %letter_name_map;
369: if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
370: %letter_name_map=
371: %{ $Apache::response::itemgroup{'letter_name_map'} };
372: }
373: my %name_letter_map;
374: if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
375: %name_letter_map=
376: %{ $Apache::response::itemgroup{'name_letter_map'} };
377: }
1.25 albertel 378: if ( &Apache::response::show_answer() && ($target ne 'tex')) {
1.1 albertel 379: foreach my $name (@whichfoils) {
380: my $text=$Apache::response::foilgroup{$name.'.text'};
381: my $value=$Apache::response::foilgroup{$name.'.value'};
382: my $letter=$name_letter_map{$value};
1.5 sakharuk 383: if ($target eq 'tex') {
384: $question.=' \\\\ '.$letter.':'.$text;
385: } else {
386: $question.='<br />'.$letter.':'.$text;
387: }
1.1 albertel 388: }
389: } else {
390: my $i = 0;
391: my $temp=0;
392: my $id=$Apache::inputtags::response[-1];
393: my $part=$Apache::inputtags::part;
394: my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
1.9 sakharuk 395: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
396: my @alphabet=('A'..'Z');
1.15 albertel 397: my @used_letters=sort(keys(%letter_name_map));
1.20 sakharuk 398: my $internal_counter=$Apache::lonxml::counter;
1.1 albertel 399: foreach my $name (@whichfoils) {
400: my $lastopt=$lastresponse{$name};
401: my $last_letter=$name_letter_map{$lastopt};
1.5 sakharuk 402: my $optionlist = '';
1.7 sakharuk 403: if ($target ne 'tex') {
404: $optionlist="<option></option>\n";
405: } else {
406: if ($Apache::lonhomework::type ne 'exam') {
407: $optionlist='\framebox[5 mm][s]{\tiny\strut}';
408: }
409: }
1.1 albertel 410: my $option;
1.15 albertel 411: foreach $option (@used_letters) {
1.1 albertel 412: if ($option eq $last_letter) {
1.6 sakharuk 413: if ($target ne 'tex') {$optionlist.="<option selected=\"on\">$option</option>\n";}
1.1 albertel 414: } else {
1.6 sakharuk 415: if ($target ne 'tex') {$optionlist.="<option>$option</option>\n";}
1.1 albertel 416: }
417: }
1.19 sakharuk 418: if ($target ne 'tex' && $Apache::lonhomework::type ne 'exam') {
1.5 sakharuk 419: $optionlist='<select name="HWVAL_'.
420: $Apache::inputtags::response[-1].':'.$temp.'">'.
421: $optionlist."</select>\n";
422: }
1.1 albertel 423: my $text=$Apache::response::foilgroup{$name.'.text'};
1.5 sakharuk 424: if ($target ne 'tex') {
1.19 sakharuk 425: if ($Apache::lonhomework::type ne 'exam') {
426: $question.='<br />'.$optionlist.$text."\n";
427: } else {
428: $question.='<br />'.$text."\n";
429: }
1.6 sakharuk 430: if ($Apache::lonhomework::type eq 'exam') {
1.27 albertel 431: $question.=&Apache::optionresponse::webbubbles(\@used_letters,\@used_letters,$temp,$last_letter);
1.6 sakharuk 432: }
433: } else {
434: if ($Apache::lonhomework::type eq 'exam') {
435: $question.=' '.$optionlist.$text."\n";
1.13 sakharuk 436: my @emptyItems = ();
1.16 albertel 437: for (my $i=0;$i<=$#used_letters;$i++) {push @emptyItems, ' ';}
1.20 sakharuk 438: $question.='\vskip -2 mm\parbox{\textwidth}{\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]\parbox{\textwidth - 5 mm}{'.&Apache::optionresponse::bubbles(\@used_letters,\@emptyItems).'}\end{enumerate}} \vskip -10 mm \strut ';
439: $internal_counter++;
1.6 sakharuk 440: } else {
1.22 sakharuk 441: $question.=' '.$optionlist.$text.'\strut\\\\\strut '."\n";
1.6 sakharuk 442: }
1.5 sakharuk 443: }
1.1 albertel 444: $temp++;
445: }
1.4 albertel 446: }
447: if ($result=&itemdisplay('top')) {
448: $result.=$question;
449: } elsif ($result=&itemdisplay('bottom')) {
450: $result=$question.$result;
451: } elsif ($result=&itemdisplay('right')) {
452: $result='<table><tr><td>'.$question.'</td><td>'.$result.
453: '</td></tr></table>';
454: } elsif ($result=&itemdisplay('left')) {
455: $result='<table><tr><td>'.$result.'</td><td>'.$question.
456: '</td></tr></table>';
1.1 albertel 457: }
1.5 sakharuk 458: if ($target ne 'tex') {$result.="<br />";} else {$result.=' \\\\ ';}
1.1 albertel 459: return $result;
460: }
461:
462: sub getfoilcounts {
463: my ($max)=@_;
464: # +1 since instructors will count from 1
465: my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
466: if (&Apache::response::showallfoils()) { $max=$count; }
467: if ($count>$max) { $count=$max }
468: &Apache::lonxml::debug("Count is $count from $max");
469: return $count;
470: }
471:
472:
473: sub start_conceptgroup {
474: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
475: $Apache::matchresponse::conceptgroup=1;
476: %Apache::response::conceptgroup=();
477: my $result;
478: if ($target eq 'edit') {
479: $result.=&Apache::edit::tag_start($target,$token,
480: "Concept Grouped Foils");
481: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
482: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
483: }
484: if ($target eq 'modified') {
485: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
486: $safeeval,'concept');
487: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
488: }
489: return $result;
490: }
491:
492: sub end_conceptgroup {
493: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
494: $Apache::matchresponse::conceptgroup=0;
495: my $result='';
1.28 ! albertel 496: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
! 497: $target eq 'tex' || $target eq 'analyze') {
! 498: &Apache::response::pick_foil_for_concept($target,
! 499: ['value','text','location'],
! 500: \%Apache::hint::match,
! 501: $parstack,$safeeval);
1.1 albertel 502: } elsif ($target eq 'edit') {
503: $result=&Apache::edit::end_table();
504: }
505: return $result;
506: }
507:
508: sub insert_conceptgroup {
509: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
510: return $result;
511: }
512:
513: sub start_foil {
514: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
515: my $result='';
1.28 ! albertel 516: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 517: &Apache::lonxml::startredirection;
518: } elsif ($target eq 'edit') {
519: $result=&Apache::edit::tag_start($target,$token,"Foil");
520: my $level='-2';
521: if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
522: $result.=&Apache::edit::text_arg('Name:','name',$token);
523: my @names;
524: if (defined(@{ $Apache::response::itemgroup{'names'} })) {
525: @names=@{ $Apache::response::itemgroup{'names'} };
526: }
527: $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',['unused',@names],$token,'15');
528: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
529: $safeeval,'-3');
530: if ($randomize ne 'no') {
531: $result.=&Apache::edit::select_arg('Location:','location',
532: ['random','top','bottom'],$token);
533: }
534: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
535: } elsif ($target eq 'modified') {
536: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
537: $safeeval,'value',
538: 'name','location');
539: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
540: }
541: return $result;
542: }
543:
544: sub end_foil {
545: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
546: my $text ='';
547: my $result = '';
1.28 ! albertel 548: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 549: $text=&Apache::lonxml::endredirection;
550: }
1.28 ! albertel 551: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
! 552: $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 553: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
554: if ($value ne 'unused') {
555: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
556: my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
557: &Apache::lonxml::debug("Got a name of :$name:");
558: if (!$name) { $name=$Apache::lonxml::curdepth; }
559: &Apache::lonxml::debug("Using a name of :$name:");
560: if ( $Apache::matchresponse::conceptgroup
561: && !&Apache::response::showallfoils() ) {
562: push @{ $Apache::response::conceptgroup{'names'} }, $name;
563: $Apache::response::conceptgroup{"$name.value"} = $value;
1.19 sakharuk 564: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
1.14 sakharuk 565: $Apache::response::conceptgroup{"$name.text"} = ' $\triangleright$ '.$text;
566: } else {
567: $Apache::response::conceptgroup{"$name.text"} = $text;
568: }
1.1 albertel 569: $Apache::response::conceptgroup{"$name.location"} = $location;
570: } else {
571: push @{ $Apache::response::foilgroup{'names'} }, $name;
572: $Apache::response::foilgroup{"$name.value"} = $value;
1.16 albertel 573: if ($Apache::lonhomework::type eq 'exam') {
1.19 sakharuk 574: if ($target eq 'tex') {
575: $Apache::response::foilgroup{"$name.text"} = '\vskip 5 mm $\triangleright$ '.$text;
576: } else {
577: $Apache::response::foilgroup{"$name.text"} = $text;
578: }
1.14 sakharuk 579: } else {
580: if ($target eq 'tex') {
1.24 sakharuk 581: $Apache::response::foilgroup{"$name.text"} = $text;
1.14 sakharuk 582: } else {
583: $Apache::response::foilgroup{"$name.text"} = $text;
584: }
585: }
1.1 albertel 586: $Apache::response::foilgroup{"$name.location"} = $location;
587: }
588: }
589: }
590: if ($target eq 'edit') {
591: $result.= &Apache::edit::tag_end($target,$token,'');
592: }
593: return $result;
594: }
595:
596: sub insert_foil {
597: return '
598: <foil name="" value="unused">
599: <startouttext />
600: <endouttext />
601: </foil>';
602: }
603: 1;
604: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>