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