Annotation of loncom/homework/radiobuttonresponse.pm, revision 1.78

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>