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