Annotation of loncom/homework/radiobuttonresponse.pm, revision 1.88
1.22 albertel 1: # The LearningOnline Network with CAPA
2: # mutliple choice style responses
1.31 albertel 3: #
1.88 ! albertel 4: # $Id: radiobuttonresponse.pm,v 1.87 2004/03/31 05:23:59 albertel Exp $
1.31 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: #
1.1 albertel 28:
29: package Apache::radiobuttonresponse;
30: use strict;
1.42 albertel 31: use HTML::Entities();
1.85 albertel 32: use Apache::lonlocal;
1.1 albertel 33:
1.36 harris41 34: BEGIN {
1.83 albertel 35: &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
1.1 albertel 36: }
37:
38: sub start_radiobuttonresponse {
1.83 albertel 39: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
40: my $result;
41: #when in a radiobutton response use these
42: &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
43: push (@Apache::lonxml::namespace,'radiobuttonresponse');
44: my $id = &Apache::response::start_response($parstack,$safeeval);
45: %Apache::hint::radiobutton=();
1.85 albertel 46: undef(%Apache::response::foilnames);
1.83 albertel 47: if ($target eq 'meta') {
48: $result=&Apache::response::meta_package_write('radiobuttonresponse');
49: } elsif ($target eq 'edit' ) {
50: $result.=&Apache::edit::start_table($token).
51: '<tr><td>'.&Apache::lonxml::description($token).
52: &Apache::loncommon::help_open_topic('Radio_Response_Problems').
53: "</td><td>Delete:".
54: &Apache::edit::deletelist($target,$token)
55: ."</td><td> ".&Apache::edit::end_row()
56: .&Apache::edit::start_spanning_row();
57: $result.=
58: &Apache::edit::text_arg('Max Number Of Shown Foils:','max',
59: $token,'4').
60: &Apache::edit::select_arg('Randomize Foil Order','randomize',
61: ['yes','no'],$token).
62: &Apache::edit::end_row().
63: &Apache::edit::start_spanning_row()."\n";
64: } elsif ($target eq 'modified') {
65: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
66: $safeeval,'max',
67: 'randomize');
68: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
69: } elsif ($target eq 'tex') {
70: my $type=&Apache::lonxml::get_param('TeXtype',$parstack,$safeeval,
71: undef,0);
72: if ($type eq '1') {
73: $result .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}';
74: } elsif ($type eq 'A') {
75: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
76: } elsif ($type eq 'a') {
77: $result .= ' \renewcommand{\labelenumi}{\alph{enumi}.}';
78: } elsif ($type eq 'i') {
79: $result .= ' \renewcommand{\labelenumi}{\roman{enumi}.}';
1.88 ! albertel 80: } else {
! 81: $result .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}';
1.83 albertel 82: }
83: $result .= '\begin{enumerate}';
84: } elsif ($target eq 'analyze') {
85: my $part_id="$Apache::inputtags::part.$id";
86: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
87: }
88: return $result;
1.1 albertel 89: }
90:
91: sub end_radiobuttonresponse {
1.83 albertel 92: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
93: my $result;
94: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
95: if ($target eq 'tex') { $result .= '\end{enumerate}'; }
96: &Apache::response::end_response;
97: pop @Apache::lonxml::namespace;
98: &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
1.85 albertel 99: undef(%Apache::response::foilnames);
1.83 albertel 100: return $result;
1.1 albertel 101: }
102:
1.43 albertel 103: %Apache::response::foilgroup=();
1.1 albertel 104: sub start_foilgroup {
1.83 albertel 105: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
106: my $result;
107: %Apache::response::foilgroup=();
108: $Apache::radiobuttonresponse::conceptgroup=0;
109: &Apache::response::setrandomnumber();
110: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
111: $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
112: }
113: return $result;
1.5 albertel 114: }
115:
1.15 albertel 116: sub storesurvey {
1.83 albertel 117: if ( !defined($ENV{'form.submitted'})) { return ''; }
118: my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1']};
119: &Apache::lonxml::debug("Here I am!:$response:");
120: if ( $response !~ /[0-9]+/) { return ''; }
121: my $id = $Apache::inputtags::response['-1'];
122: my @whichfoils=@{ $Apache::response::foilgroup{'names'} };
123: my %responsehash;
124: $responsehash{$whichfoils[$response]}=$response;
125: $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=&Apache::lonnet::hash2str(%responsehash);
126: $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='SUBMITTED';
127: &Apache::lonxml::debug("submitted a $response<br />\n");
128: return '';
1.15 albertel 129: }
130:
1.32 albertel 131: sub grade_response {
1.83 albertel 132: my ($max,$randomize)=@_;
133: #keep the random numbers the same must always call this
134: my ($answer,@whichfoils)=&whichfoils($max,$randomize);
135: if (!defined($ENV{'form.submitted'})) { return; }
136: my $response;
137: if ($ENV{'form.submitted'} eq 'scantron') {
138: $response=&Apache::response::getresponse();
139: } else {
140: $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1']};
141: }
142: if ( $response !~ /[0-9]+/) { return; }
143: my $part=$Apache::inputtags::part;
144: my $id = $Apache::inputtags::response['-1'];
145: my %responsehash;
146: $responsehash{$whichfoils[$response]}=$response;
147: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
148: my %previous=&Apache::response::check_for_previous($responsestr,
149: $part,$id);
150: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
151: $responsestr;
152: &Apache::lonxml::debug("submitted a $response<br />\n");
153: my $ad;
154: if ($response == $answer) {
155: $ad='EXACT_ANS';
156: } else {
157: $ad='INCORRECT';
158: }
159: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
160: &Apache::response::handle_previous(\%previous,$ad);
1.32 albertel 161: }
162:
1.1 albertel 163: sub end_foilgroup {
1.83 albertel 164: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.29 albertel 165:
1.83 albertel 166: my $result;
167: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
168: $target eq 'tex' || $target eq 'analyze') {
169: my $style = $Apache::lonhomework::type;
170: if ( $style eq 'survey' && $target ne 'analyze') {
171: if ($target eq 'web' || $target eq 'tex') {
172: $result=&displayallfoils();
173: } elsif ( $target eq 'answer' ) {
174: $result=&displayallanswers();
175: } elsif ( $target eq 'grade' ) {
176: $result=&storesurvey();
177: }
178: } else {
179: my $name;
180: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,
181: '-2');
182: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
183: $safeeval,'-2');
184: if ($target eq 'web' || $target eq 'tex') {
185: $result=&displayfoils($target,$max,$randomize);
186: } elsif ($target eq 'answer' ) {
187: $result=&displayanswers($max,$randomize);
188: } elsif ( $target eq 'grade') {
189: &grade_response($max,$randomize);
190: } elsif ( $target eq 'analyze') {
191: my @shown = &whichfoils($max,$randomize);
192: &Apache::response::analyze_store_foilgroup(\@shown,
193: ['text','value','location']);
194: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
195: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },
196: ('true','false'));
197: }
1.81 albertel 198: }
1.83 albertel 199: }
200: &Apache::lonxml::increment_counter();
201: return $result;
1.6 albertel 202: }
203:
204: sub getfoilcounts {
1.83 albertel 205: my @names;
206: my $truecnt=0;
207: my $falsecnt=0;
208: my $name;
209: if ( $Apache::response::foilgroup{'names'} ) {
210: @names= @{ $Apache::response::foilgroup{'names'} };
1.6 albertel 211: }
1.83 albertel 212: foreach $name (@names) {
213: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
214: $truecnt++;
215: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
216: $falsecnt++;
217: }
218: }
219: return ($truecnt,$falsecnt);
1.5 albertel 220: }
221:
1.15 albertel 222: sub displayallfoils {
1.83 albertel 223: my $result;
224: &Apache::lonxml::debug("survey style display");
225: my @names = @{ $Apache::response::foilgroup{'names'} };
226: my $temp=0;
227: my $id=$Apache::inputtags::response['-1'];
228: my $part=$Apache::inputtags::part;
229: my $lastresponse=
230: $Apache::lonhomework::history{"resource.$part.$id.submission"};
231: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
232: if (&Apache::response::show_answer() ) {
233: foreach my $name (@names) {
234: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
1.84 albertel 235: $result.="<br />";
236: if (defined($lastresponse{$name})) {
1.83 albertel 237: $result.='<b>';
238: }
239: $result .= $Apache::response::foilgroup{$name.'.text'};
1.84 albertel 240: if (defined($lastresponse{$name})) {
1.83 albertel 241: $result.='</b>';
242: }
243: }
1.45 albertel 244: }
1.83 albertel 245: } else {
246: foreach my $name (@names) {
247: if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
248: $result.="<br /><input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
249: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
250: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
251: $temp++;
252: }
1.45 albertel 253: }
254: }
1.83 albertel 255: return $result;
1.15 albertel 256: }
257:
1.28 albertel 258: sub whichfoils {
1.83 albertel 259: my ($max,$randomize)=@_;
1.28 albertel 260:
1.83 albertel 261: my @truelist;
262: my @falselist;
263: my @whichfalse =();
264: my ($truecnt,$falsecnt) = &getfoilcounts();
265: my $count=0;
266: # we will add in 1 of the true statements
267: if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
268: my $answer=int(&Math::Random::random_uniform() * ($count));
269: &Apache::lonxml::debug("Count is $count, $answer is $answer");
270: my @names;
271: if ( $Apache::response::foilgroup{'names'} ) {
272: @names= @{ $Apache::response::foilgroup{'names'} };
273: }
274: if (&Apache::response::showallfoils()) {
275: @whichfalse=@names;
276: } elsif ($randomize eq 'no') {
277: &Apache::lonxml::debug("No randomization");
278: my $havetrue=0;
279: foreach my $name (@names) {
280: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
281: if (!$havetrue ) {
282: push(@whichfalse,$name); $havetrue++; $answer=$#whichfalse;
283: }
284: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
285: push (@whichfalse,$name);
286: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
287: } else {
1.87 albertel 288: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
1.83 albertel 289: }
290: }
291: } else {
292: my $current=0;
293: &Apache::lonhomework::showhash(%Apache::response::foilgroup);
294: my (%top,%bottom);
295: #first find out where everyone wants to be
296: foreach my $name (@names) {
297: $current++;
298: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
299: push (@truelist,$name);
300: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
301: $top{$name}=$current;
302: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
303: $bottom{$name}=$current;
304: }
305: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
306: push (@falselist,$name);
307: if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
308: $top{$name}=$current;
309: } elsif ($Apache::response::foilgroup{$name.'.location'} eq 'bottom') {
310: $bottom{$name}=$current;
311: }
312: } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
313: } else {
1.87 albertel 314: &Apache::lonxml::error(&HTML::Entities::encode("No valid value assigned ($Apache::response::foilgroup{$name.'.value'}) for foil $name in <foilgroup>",'<>&"'));
1.83 albertel 315: }
316: }
317: #pick a true statement
318: my $notrue=0;
319: if (scalar(@truelist) == 0) { $notrue=1; }
320: my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
321: &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
322: my (@toplist, @bottomlist);
323: my $topcount=0;
324: my $bottomcount=0;
325: # assign everyone to either toplist/bottomlist or whichfalse
326: # which false is randomized, toplist bottomlist are in order
327: while ((($#whichfalse+$topcount+$bottomcount) < $max-2) && ($#falselist > -1)) {
328: &Apache::lonxml::debug("Have $#whichfalse max is $max");
329: my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
330: &Apache::lonxml::debug("From $#falselist elms, picking $afalse");
331: $afalse=splice(@falselist,$afalse,1);
332: &Apache::lonxml::debug("Picked $afalse");
333: &Apache::lonhomework::showhash(('names'=>\@names));
334: &Apache::lonhomework::showhash(%top);
335: if ($top{$afalse}) {
336: $toplist[$top{$afalse}]=$afalse;
337: $topcount++;
338: } elsif ($bottom{$afalse}) {
339: $bottomlist[$bottom{$afalse}]=$afalse;
340: $bottomcount++;
341: } else {
342: push (@whichfalse,$afalse);
343: }
344: }
345: &Apache::lonxml::debug("Answer wants $answer");
346: my $truename=$truelist[$whichtrue];
347: my $dosplice=1;
348: if ($notrue && $Apache::lonhomework::type ne 'survey') {
349: $dosplice=0;
350: &Apache::lonxml::error("There are no true statements available.<br />");
351: }
352: #insert the true statement, keeping track of where it wants to be
353: if ($Apache::response::foilgroup{$truename.'.location'} eq 'top' && $dosplice) {
354: $toplist[$top{$truename}]=$truename;
355: $answer=-1;
356: foreach my $top (reverse(@toplist)) {
357: if ($top) { $answer++;}
358: if ($top eq $truename) { last; }
1.49 albertel 359: }
1.83 albertel 360: $dosplice=0;
361: } elsif ($Apache::response::foilgroup{$truename.'.location'} eq 'bottom' && $dosplice) {
362: $bottomlist[$bottom{$truename}]=$truename;
363: $answer=-1;
364: foreach my $bot (@bottomlist) {
365: if ($bot) { $answer++;}
366: if ($bot eq $truename) { last; }
1.49 albertel 367: }
1.83 albertel 368: $answer+=$topcount+$#whichfalse+1;
369: $dosplice=0;
1.49 albertel 370: } else {
1.83 albertel 371: if ($topcount>0 || $bottomcount>0) {
372: $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
373: + $topcount;
374: }
375: }
376: &Apache::lonxml::debug("Answer now wants $answer");
377: #add the top items to the top, bottom items to the bottom
378: for (my $i=0;$i<=$#toplist;$i++) {
379: if ($toplist[$i]) { unshift(@whichfalse,$toplist[$i]) }
1.49 albertel 380: }
1.83 albertel 381: for (my $i=0;$i<=$#bottomlist;$i++) {
382: if ($bottomlist[$i]) { push(@whichfalse,$bottomlist[$i]) }
1.49 albertel 383: }
1.83 albertel 384: #if the true statement is randomized insert it into the list
385: if ($dosplice) { splice(@whichfalse,$answer,0,$truelist[$whichtrue]); }
1.49 albertel 386: }
1.83 albertel 387: &Apache::lonxml::debug("Answer is $answer");
388: return ($answer,@whichfalse);
1.28 albertel 389: }
390:
391: sub displayfoils {
1.83 albertel 392: my ($target,$max,$randomize)=@_;
393: my $result;
1.28 albertel 394:
1.83 albertel 395: my ($answer,@whichfoils)=&whichfoils($max,$randomize);
1.22 albertel 396: my $part=$Apache::inputtags::part;
1.83 albertel 397: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
398: if ( ($target ne 'tex') &&
399: &Apache::response::show_answer() ) {
400: foreach my $name (@whichfoils) {
401: if ($target ne 'tex') {
402: $result.="<br />";
403: } else {
404: $result.='\item \vskip -2 mm ';
405: }
406: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
407: if ($target ne 'tex') { $result.='Correct:<b>'; } else { $result.='Correct: \textbf{';}
408: } else {
409: $result.='Incorrect:';
410: }
411: if ($target ne 'tex') {
412: $result.=$Apache::response::foilgroup{$name.'.text'}."</input>\n";
413: } else {
414: $result.=$Apache::response::foilgroup{$name.'.text'};
415: }
416: if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
417: if ($target ne 'tex') { $result.='</b>';} else {$result.='}';}
418: }
419: }
420: } else {
421: my @alphabet = ('A'..'Z');
422: my $i = 0;
423: my $temp=0;
424: my $id=$Apache::inputtags::response['-1'];
425: my $part=$Apache::inputtags::part;
426: my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
427: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
428: foreach my $name (@whichfoils) {
429: if ($target ne 'tex') {
430: $result.="<br /><input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
431: if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
432: $result .= '>'.$Apache::response::foilgroup{$name.'.text'}."</input>\n";
433: } else {
434: if ($Apache::lonhomework::type eq 'exam') {
435: $result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
436: $i++;
437: } else {
438: $result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
439: }
440: }
441: $temp++;
442: }
443: }
444: if ($target ne 'tex') { $result.="<br />"; } else { $result.='\vskip 0 mm '; }
445: return $result;
1.81 albertel 446: }
447:
448: sub displayallanswers {
449: my @names = @{ $Apache::response::foilgroup{'names'} };
450:
451: my $result=&Apache::response::answer_header('radiobuttonresponse');
452: foreach my $name (@names) {
453: $result.=&Apache::response::answer_part('radiobuttonresponse',
454: $Apache::response::foilgroup{$name.'.value'});
455: }
456: $result.=&Apache::response::answer_footer('radiobuttonresponse');
457: return $result;
1.14 albertel 458: }
459:
1.28 albertel 460: sub displayanswers {
1.83 albertel 461: my ($max,$randomize)=@_;
462: my ($answer,@whichopt) = &whichfoils($max,$randomize);
463: my $result=&Apache::response::answer_header('radiobuttonresponse');
464: foreach my $name (@whichopt) {
465: $result.=&Apache::response::answer_part('radiobuttonresponse',
466: $Apache::response::foilgroup{$name.'.value'})
467: }
468: $result.=&Apache::response::answer_footer('radiobuttonresponse');
469: return $result;
1.28 albertel 470: }
471:
1.14 albertel 472: sub start_conceptgroup {
1.83 albertel 473: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
474: $Apache::radiobuttonresponse::conceptgroup=1;
475: %Apache::response::conceptgroup=();
476: my $result;
477: if ($target eq 'edit') {
478: $result.=&Apache::edit::tag_start($target,$token);
479: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
480: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
481: } elsif ($target eq 'modified') {
482: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
483: $safeeval,'concept');
484: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
485: }
486: return $result;
1.14 albertel 487: }
488:
489: sub end_conceptgroup {
1.83 albertel 490: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
491: $Apache::radiobuttonresponse::conceptgroup=0;
492: my $result;
493: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
494: $target eq 'tex' || $target eq 'analyze') {
495: &Apache::response::pick_foil_for_concept($target,
496: ['value','text','location'],
497: \%Apache::hint::radiobutton,
498: $parstack,$safeeval);
499: } elsif ($target eq 'edit') {
500: $result=&Apache::edit::end_table();
501: }
502: return $result;
1.26 albertel 503: }
504:
505: sub insert_conceptgroup {
1.83 albertel 506: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
507: return $result;
1.1 albertel 508: }
509:
510: sub start_foil {
1.83 albertel 511: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
512: my $result='';
513: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
514: &Apache::lonxml::startredirection;
515: } elsif ($target eq 'edit') {
516: $result=&Apache::edit::tag_start($target,$token);
517: $result.=&Apache::edit::text_arg('Name:','name',$token);
518: $result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
519: ['unused','true','false'],
520: $token);
521: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
522: $safeeval,'-3');
523: if ($randomize ne 'no') {
524: $result.=&Apache::edit::select_arg('Location:','location',
525: ['random','top','bottom'],$token);
526: }
527: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
528: } elsif ($target eq 'modified') {
529: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
530: $safeeval,'value','name',
531: 'location');
532: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
533: }
534: return $result;
1.1 albertel 535: }
536:
537: sub end_foil {
1.83 albertel 538: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
539: my $text='';
540: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
541: $text=&Apache::lonxml::endredirection;
542: }
1.85 albertel 543: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
544: || $target eq 'tex' || $target eq 'analyze') {
1.83 albertel 545: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
546: if ($value ne 'unused') {
547: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
548: if (!$name) { $name=$Apache::lonxml::curdepth; }
1.85 albertel 549: if (defined($Apache::response::foilnames{$name})) {
550: &Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
551: }
1.86 albertel 552: $Apache::response::foilnames{$name}++;
1.85 albertel 553: my $location =&Apache::lonxml::get_param('location',$parstack,
554: $safeeval);
1.83 albertel 555: if ( $Apache::radiobuttonresponse::conceptgroup
556: && !&Apache::response::showallfoils() ) {
557: push @{ $Apache::response::conceptgroup{'names'} }, $name;
558: $Apache::response::conceptgroup{"$name.value"} = $value;
559: $Apache::response::conceptgroup{"$name.text"} = $text;
560: $Apache::response::conceptgroup{"$name.location"} = $location;
561: } else {
562: push @{ $Apache::response::foilgroup{'names'} }, $name;
563: $Apache::response::foilgroup{"$name.value"} = $value;
564: $Apache::response::foilgroup{"$name.text"} = $text;
565: $Apache::response::foilgroup{"$name.location"} = $location;
566: }
567: }
1.18 albertel 568: }
1.83 albertel 569: return '';
1.1 albertel 570: }
571:
1.27 albertel 572: sub insert_foil {
1.83 albertel 573: return '
1.27 albertel 574: <foil name="" value="unused">
575: <startouttext />
576: <endouttext />
577: </foil>';
578: }
1.1 albertel 579: 1;
580: __END__
581:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>