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