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