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

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

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