File:  [LON-CAPA] / loncom / homework / optionresponse.pm
Revision 1.192: download - view: text, annotated - select for diffs
Tue Dec 3 14:54:29 2013 UTC (10 years, 5 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Do not translate twice

    1: # LearningOnline Network with CAPA
    2: # option list style responses
    3: #
    4: # $Id: optionresponse.pm,v 1.192 2013/12/03 14:54:29 bisitz Exp $
    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: #
   28: 
   29: 
   30: 
   31: 
   32: 
   33: package Apache::optionresponse;
   34: use strict;
   35: use Apache::response();
   36: use Apache::lonlocal;
   37: use Apache::lonnet;
   38: 
   39: BEGIN {
   40:   &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
   41: }
   42: 
   43: sub start_optionresponse {
   44:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   45:   my $result='';
   46:   #when in a option response use these
   47:   &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
   48:   push (@Apache::lonxml::namespace,'optionresponse');
   49:   my $id = &Apache::response::start_response($parstack,$safeeval);
   50:   %Apache::hint::option=();
   51:   undef(%Apache::response::foilnames);
   52:   if ($target eq 'edit') {
   53:     $result.=&Apache::edit::start_table($token)
   54:        .'<tr><td><span class="LC_nobreak">'.&mt('Multiple Option Response Question').'</span> '
   55:        .&Apache::loncommon::help_open_topic('Option_Response_Problems')."</td>"
   56:        .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
   57:        .&Apache::edit::deletelist($target,$token)
   58:        .'</span></td>'
   59:        ."<td>&nbsp;"
   60:        .&Apache::edit::end_row()
   61:        .&Apache::edit::start_spanning_row()
   62:        ."\n";
   63:     $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max',
   64: 				     $token,'4').
   65:         &Apache::edit::select_arg('Randomize Foil Order:','randomize',
   66: 				  ['yes','no'],$token).
   67:         &Apache::edit::select_arg('Display of options when printed','TeXlayout',
   68: 				  [['horizontal','Normal list'],
   69: 				   ['vertical','Listed in a vertical column']],$token).
   70:         &Apache::edit::end_row().&Apache::edit::start_spanning_row();
   71:   } elsif ($target eq 'modified') {
   72:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
   73: 						 $safeeval,'max','randomize',
   74: 						 'TeXlayout');
   75:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
   76:   } elsif ($target eq 'meta') {
   77:     $result=&Apache::response::meta_package_write('optionresponse');
   78:   } elsif ($target eq 'analyze') {
   79:     my $part_id="$Apache::inputtags::part.$id";
   80:     $Apache::lonhomework::analyze{"$part_id.type"} = 'optionresponse';
   81:     push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
   82:     push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} }, 1);
   83: 
   84:   }
   85:   return $result;
   86: }
   87: 
   88: sub end_optionresponse {
   89:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   90:   &Apache::response::end_response;
   91:   pop @Apache::lonxml::namespace;
   92:   &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
   93:   my $result;
   94:   if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
   95:   undef(%Apache::response::foilnames);
   96:   return $result;
   97: }
   98: 
   99: %Apache::response::foilgroup=();
  100: sub start_foilgroup {
  101:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  102: 
  103:   my $result='';
  104:   %Apache::response::foilgroup=();
  105:   $Apache::optionresponse::conceptgroup=0;
  106:   &Apache::response::pushrandomnumber(undef,$target);
  107:   if ($target eq 'edit') {
  108:     my $optionlist="<option></option>\n";
  109:     my $option;
  110:     my @opt;
  111:     my @raw_options = &Apache::lonxml::get_param('options', $parstack, $safeeval, 0,  0, 1);
  112: 
  113: 
  114:     eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval, 0, 0, 1);
  115: 
  116:     my $count=1;
  117:     foreach $option (@opt) {
  118:       $optionlist.="<option value=\"$count\">$option</option>\n";
  119:       $count++;
  120:     }
  121:     my $insertlist=&Apache::edit::insertlist($target,$token);
  122:     $result.=&Apache::edit::start_table($token);
  123:     $result.= (<<ENDTABLE);
  124:       <tr><td>Select Options</td>
  125:         <td>
  126: 	  Add new Option: <input type="text" name="$Apache::lonxml::curdepth.options" />
  127:         </td>
  128:         <td>Delete an Option:
  129: 	  <select name="$Apache::lonxml::curdepth.deleteopt">$optionlist</select>
  130:         </td>
  131: ENDTABLE
  132:     $result.= '<td>'.&Apache::edit::checked_arg('Print options:','texoptions',
  133: 					 [ ['nochoice','Don\'t show option list'] ]
  134: 					 ,$token).'</td>';
  135:     $result.= '<td><label>'.&mt('Two-option checkboxes for:').
  136:               '<select name="checkboxvalue_'.$Apache::lonxml::curdepth.'">';
  137:     foreach $option (('',@opt)) {
  138:        $result.='<option value="'.$option.'"';
  139:        if ($option eq &Apache::lonxml::get_param('checkboxvalue',$parstack,$safeeval)) {
  140:           $result.=' selected="selected"';
  141:        }
  142:        $result.='>'.$option.'</option>';
  143:     }
  144:     $result.='</select></label>';
  145:     $result.=&Apache::edit::checked_arg('Checkbox options:','checkboxoptions',
  146:                                          [ ['nochoice','Don\'t show option list'] ]
  147:                                          ,$token).'</td>';
  148:     $result.= &Apache::edit::end_row();
  149:     $result.= &Apache::edit::start_spanning_row();
  150:     $result.= $insertlist.'<br />';
  151:   }
  152:   if ($target eq 'modified') {
  153:     my @options;
  154:     my $optchanged=0;
  155: 
  156: 
  157:     eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval, 0, 0, 1);
  158: 
  159:     if ($env{"form.$Apache::lonxml::curdepth.deleteopt"}) {
  160:       my $delopt=$env{"form.$Apache::lonxml::curdepth.deleteopt"};
  161:       &Apache::lonxml::debug("Deleting :$delopt:");
  162:       splice(@options,$delopt-1,1);
  163:       $optchanged=1;
  164:     }
  165:     if ($env{"form.$Apache::lonxml::curdepth.options"} ne '') {
  166:       my $newopt = $env{"form.$Apache::lonxml::curdepth.options"};
  167:       push(@options,$newopt);
  168:       $optchanged=1;
  169:     }
  170:     my $rebuildtag = &Apache::edit::get_new_args($token,$parstack,$safeeval,
  171: 						 'texoptions','checkboxvalue','checkboxoptions');
  172:     if ($optchanged || $rebuildtag ) {
  173:       $result = "<foilgroup options=\"(";
  174:       foreach my $option (@options) {
  175: 	$option=~s/\'/\\\'/g;
  176: 	&Apache::lonxml::debug("adding option :$option:");
  177: 	$result .="'".$option."',";
  178:       }
  179:       chop $result;
  180:       $result.=')" ';
  181:       $result .= 'texoptions="'.$token->[2]{'texoptions'}.'" ';
  182:       $result .= 'checkboxoptions="'.$token->[2]{'checkboxoptions'}.'" ';
  183:       $result .= 'checkboxvalue="'.$token->[2]{'checkboxvalue'}.'"';
  184:       $result .= '>';
  185:     } # else nothing changed so just use the default mechanism
  186:   }
  187:   if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
  188:     if($env{'form.pdfFormFields'} ne 'yes') {
  189:       $result .= ' \begin{itemize} ';
  190:     } else {
  191:       $result .= "\\\\";
  192:     }
  193:   }
  194:   return $result;
  195: }
  196: 
  197: sub end_foilgroup {
  198:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  199:   
  200:   my $result;
  201:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
  202:       $target eq 'tex' || $target eq 'analyze') {
  203:     my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
  204:     my $name;
  205:     my @opt;
  206:     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
  207:     &Apache::lonxml::debug("options:".join(':',@opt));
  208: 
  209:     my $TeXlayout=&Apache::lonxml::get_param('TeXlayout',$parstack,$safeeval,
  210: 					     -2,0);
  211:     my $checkboxvalue=&Apache::lonxml::get_param('checkboxvalue',$parstack,$safeeval);
  212:     my $checkboxchoices=(&Apache::lonxml::get_param('checkboxoptions',$parstack,$safeeval) ne 'nochoice');
  213:     my $noprompt       =&Apache::lonxml::get_param('noprompt', $parstack, $safeeval);
  214: 
  215:     if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
  216:     &Apache::lonxml::debug("Options are $#opt");
  217:     my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
  218:     my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
  219: 					       $safeeval,'-2');
  220:     if ($target eq 'web' || $target eq 'tex') {
  221:       $result.=&displayfoils($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,$tex_option_switch, $noprompt, @opt);
  222:       $Apache::lonxml::post_evaluate=0;
  223:     } elsif ( $target eq 'answer') {
  224:       $result.=&displayanswers($max,$randomize,@opt);
  225:       
  226:     } elsif ( $target eq 'analyze') {
  227: 	my @shown = &whichfoils($max,$randomize);
  228: 	&Apache::response::analyze_store_foilgroup(\@shown,
  229: 						  ['text','value','location']);
  230: 	my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
  231: 	push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
  232:     } elsif ( $target eq 'grade') {
  233: 
  234:       if ( &Apache::response::submitted()) {
  235: 
  236: 	my @whichopt = &whichfoils($max,$randomize);
  237: 	my $temp=1;my $name;
  238: 	my %responsehash;
  239: 	my %grade;
  240: 	my $right=0;
  241: 	my $wrong=0;
  242: 	my $ignored=0;
  243:         my ($numrows,$bubbles_per_row);
  244:         if ($Apache::lonhomework::scantronmode) {
  245:             my $numitems = scalar(@opt);
  246:             ($numrows,$bubbles_per_row) =
  247:                 &Apache::optionresponse::getnumrows($numitems);
  248:         }
  249:         if ($numrows < 1) {
  250:             $numrows = 1;
  251:         }
  252: 	foreach $name (@whichopt) {
  253: 	  my $response;
  254:           if ($env{'form.submitted'} eq 'scantron') {
  255:               if ($numrows > 1) {
  256:                   my $num = $temp;
  257:                   my $totalnum;
  258:                   for (my $i=0; $i<$numrows; $i++) {
  259:                       my $item = &Apache::response::getresponse($num);
  260:                       if ($item =~ /^\d+$/) {
  261:                           $totalnum = $i*$bubbles_per_row + $item;
  262:                       }
  263:                       $num ++;
  264:                   }
  265:                   if ($totalnum =~ /^\d+$/) {
  266:                       $response = $opt[$totalnum];
  267:                   }
  268:                   $temp += $numrows;
  269:               } else {
  270:                   $response=&Apache::response::getresponse($temp);
  271:                   if ($response=~/\S/) {
  272:                       $response = $opt[$response];
  273:                   }
  274:                   $temp ++;
  275:               }
  276: 	  } else {
  277:               $response=&Apache::response::getresponse($temp);
  278:               $temp ++;
  279:           }
  280: 	  if ( $response =~ /[^\s]/) {
  281: 	    $responsehash{$name}=$response;
  282: 	    my $value=$Apache::response::foilgroup{$name.'.value'};
  283: 	    &Apache::lonxml::debug("submitted a $response for $value<br />\n");
  284: 	    if ($value eq $response) {
  285: 		$grade{$name}='1'; $right++;
  286: 	    } else {
  287: 		$grade{$name}='0'; $wrong++;
  288: 	    }
  289: 	  } else {
  290: 	    $ignored++;
  291: 	  }
  292: 	}
  293: 	my $part=$Apache::inputtags::part;
  294:         my $nonlenient=&grading_is_nonlenient($part);
  295: 	my $id = $Apache::inputtags::response['-1'];
  296: 	my $responsestr=&Apache::lonnet::hash2str(%responsehash);
  297: 	my $gradestr   =&Apache::lonnet::hash2str(%grade);
  298: 	my %previous=&Apache::response::check_for_previous($responsestr,
  299: 							   $part,$id);
  300: 	&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
  301: 	$Apache::lonhomework::results{"resource.$part.$id.submission"}=
  302: 	    $responsestr;
  303: 	$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
  304:         if ($Apache::lonhomework::type eq 'randomizetry') {
  305:             $Apache::lonhomework::results{"resource.$part.$id.foilorder"} = &Apache::lonnet::array2str(@whichopt);
  306:         }
  307: 	if (($Apache::lonhomework::type eq 'survey') ||
  308:             ($Apache::lonhomework::type eq 'surveycred') ||
  309:             ($Apache::lonhomework::type eq 'anonsurvey') ||
  310:             ($Apache::lonhomework::type eq 'anonsurveycred')) {
  311: 	    if ($ignored == 0) {
  312:                 my $ad;
  313:                 if ($Apache::lonhomework::type eq 'anonsurveycred') {
  314:                     $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CREDIT';
  315:                 } elsif ($Apache::lonhomework::type eq 'anonsurvey') {
  316:                     $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
  317:                 } elsif ($Apache::lonhomework::type eq 'surveycred') {
  318:                     $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
  319:                 } else {
  320: 		    $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
  321:                 }
  322: 		&Apache::response::handle_previous(\%previous,$ad);
  323: 	    } elsif ($wrong==0 && $right==0) {
  324: 	    } else {
  325: 		my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='MISSING_ANSWER';
  326: 		&Apache::response::handle_previous(\%previous,$ad);
  327: 	    }
  328: 	} elsif ($nonlenient) {
  329: #
  330: # Non-lenient mode. All right or all wrong
  331: #
  332: 	    my $ad;
  333: 	    if ($wrong==0 && $ignored==0) {
  334: 		$ad='EXACT_ANS';
  335: 	    } elsif ($wrong==0 && $right==0) {
  336: 		#nothing submitted
  337: 	    } else {
  338: 		if ($ignored==0) {
  339: 		    $ad='INCORRECT';
  340: 		} else {
  341: 		    $ad='MISSING_ANSWER';
  342: 		}
  343: 	    }
  344: 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
  345: 	    &Apache::response::handle_previous(\%previous,$ad);
  346: 	} else {
  347: #
  348: # This is lenient mode
  349: #
  350: 	    my $ad;
  351: 	    if ($wrong==0 && $right==0) {
  352: 		#nothing submitted only assign a score if we 
  353: 		#need to override a previous grade
  354: 		if (defined($Apache::lonhomework::history{"resource.$part.$id.awarddetail"})) {
  355: 		    $ad='ASSIGNED_SCORE';
  356: 		}
  357: 	    } else {
  358: 		$ad='ASSIGNED_SCORE';
  359: 	    }
  360: 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
  361: 	    $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
  362: 		$right/(scalar(@whichopt));
  363: 	    $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
  364: 		scalar(@whichopt);
  365: 	}
  366:       }
  367:     }
  368:     my $part_id     = $Apache::inputtags::part;
  369:     my $response_id = $Apache::inputtags::response[-1];
  370:     my ($numrows,$bubbles_per_row);
  371:     if (($target eq 'tex') && ($Apache::lonhomework::type eq 'exam')) {
  372:         ($numrows,$bubbles_per_row) =
  373:             &Apache::optionresponse::getnumrows(scalar(@opt));
  374:     }
  375:     if ($numrows < 1) {
  376:         $numrows = 1;
  377:     }
  378:     my $increment = &getfoilcounts($max) * $numrows;
  379:     &Apache::lonxml::increment_counter($increment,"$part_id.$response_id");
  380:     if ($target eq 'analyze') {
  381: 	&Apache::lonhomework::set_bubble_lines();
  382:     }
  383: 
  384:   } elsif ($target eq 'edit') {
  385:     $result.=&Apache::edit::end_table();
  386:   }
  387:   if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
  388:     if($env{'form.pdfFormFields'} ne 'yes') {
  389:       $result .= '\end{itemize}'; 
  390:     } else {
  391:       $result .= "\\\\";
  392:     }
  393:   }
  394:   &Apache::response::poprandomnumber();
  395:   return $result;
  396: }
  397: 
  398: sub grading_is_nonlenient {
  399:     my ($part) = @_;
  400: # Web mode: we are non-lenient unless told otherwise
  401:     my $defaultparm = 'off';
  402:     my $nonlenient = 0;
  403: # Grading a bubblesheet exam: we are grading lenient unless told otherwise
  404:     if ($Apache::lonhomework::scantronmode) {
  405:         $defaultparm = 'on';
  406:         $nonlenient = 1;
  407:     }
  408:     my $lenientparm =
  409:         &Apache::response::get_response_param($part,'lenient',$defaultparm);
  410:     if ($lenientparm=~/^0|off|no$/i) {
  411:         $nonlenient = 1;
  412:     } elsif ($lenientparm=~/^1|on|yes$/i) {
  413:         $nonlenient = 0;
  414:     }
  415:     return $nonlenient;
  416: }
  417: 
  418: sub getfoilcounts {
  419:   my ($max)=@_;
  420:   # +1 since instructors will count from 1
  421:   my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
  422:   if (&Apache::response::showallfoils()) { $max=$count; }
  423:   if ($count>$max) { $count=$max } 
  424:   &Apache::lonxml::debug("Count is $count from $max");
  425:   return $count;
  426: }
  427: 
  428: sub whichfoils {
  429:     my ($max,$randomize)=@_;
  430:     return &Apache::response::whichorder($max,$randomize,
  431: 					 &Apache::response::showallfoils(),
  432: 					 \%Apache::response::foilgroup);
  433: }
  434: 
  435: sub displayanswers {
  436:     my ($max,$randomize,@opt)=@_;
  437:     my @names;
  438:     if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
  439:         @names = @{ $Apache::response::foilgroup{'names'} };
  440:     }
  441:     return if (!@names);
  442:     my @whichopt = &whichfoils($max,$randomize);
  443:     my $result;
  444:     if ($Apache::lonhomework::type eq 'exam') {
  445: 	my $i = 0;
  446: 	my %opt = map { ($_,$i++) } @opt;
  447: 	
  448: 	$i = 0;
  449: 	my @alphabet = ('A'..'Z');
  450: 	foreach my $name (@whichopt) {
  451: 	    $result.=&Apache::response::answer_header('optionresponse',$i++);
  452: 	    $result.=&Apache::response::answer_part('optionresponse',
  453: 						    $alphabet[$opt{$Apache::response::foilgroup{$name.'.value'}}]);
  454: 	    $result.=&Apache::response::answer_part('optionresponse',
  455: 						    $Apache::response::foilgroup{$name.'.value'});
  456: 	    $result.=&Apache::response::answer_footer('optionresponse');
  457: 	}
  458:     } else {
  459: 	$result=&Apache::response::answer_header('optionresponse');
  460: 	foreach my $name (@whichopt) {
  461: 	    $result.=&Apache::response::answer_part('optionresponse',
  462: 						    $Apache::response::foilgroup{$name.'.value'});
  463: 	}
  464: 	$result.=&Apache::response::answer_footer('optionresponse');
  465:     }
  466:     return $result;
  467: }
  468: 
  469: sub check_box_opt {
  470:     my ($target,$checkboxvalue,@opt)=@_;
  471: # Check if we are in checkbox mode: checkboxvalue specified, on web, only two options.
  472: # If so, return "checked" value
  473:     if ($#opt!=1) { return ''; }
  474:     if ($target ne 'web') { return ''; }
  475:     return $checkboxvalue;
  476: }
  477: 
  478: sub check_for_invalid {
  479:     my ($names,$options) = @_;
  480:     my %bad_names;
  481:     foreach my $name (@{ $names }) {
  482: 	my $value=$Apache::response::foilgroup{$name.'.value'};
  483: 	my $found=0;
  484: 	foreach my $option (@{ $options }) {
  485: 	    if ($value eq $option) { $found=1; }
  486: 	}
  487: 	if (!$found) { $bad_names{$name}=$value; }
  488:     }
  489:     if (%bad_names) {
  490: 	my $error=&mt('The question can not be gotten correct, '.
  491: 	    'the following foils in the &lt;optionresponse&gt; '.
  492: 	    'have invalid correct options').' <br /><tt>'.
  493: 	    join('<br />',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))).
  494: 	    "</tt>";
  495: 	&Apache::lonxml::error($error);
  496:     }
  497: }
  498: 
  499: sub displayfoils {
  500:   my ($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,
  501:       $tex_option_switch, $no_tfprompt, @opt)=@_;
  502:   my @names; 
  503:   if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
  504:       @names = @{ $Apache::response::foilgroup{'names'} };
  505:   }
  506:   unless (@names > 0) { return;}
  507:   my @truelist;
  508:   my @falselist;
  509:   my $result;  
  510:   my $name;
  511:   my $displayoptionintex=1;
  512:   my @alphabet = ('A'..'Z');
  513:   my @whichopt = &whichfoils($max,$randomize);
  514:   unless (($target eq 'tex') && ($tex_option_switch eq 'nochoice')) {
  515:       &check_for_invalid(\@whichopt,\@opt);
  516:   }
  517:   my $part=$Apache::inputtags::part;
  518:   my $id=$Apache::inputtags::response[-1];
  519:   my $break;
  520:   if ( ($target ne 'tex') &&
  521:        &Apache::response::show_answer() ) {
  522:     my $temp=1;
  523:     foreach $name (@whichopt) {
  524: 	my $text=$Apache::response::foilgroup{$name.'.text'};
  525:         my $lastresp;
  526:         if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
  527:             (($env{'form.grade_username'} eq $env{'user.name'}) &&
  528:              ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
  529:             $lastresp = $Apache::lonhomework::history{"resource.$part.$id.submission"};
  530:         } else {
  531:             unless (($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') ||
  532:                     ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) {
  533:                 $lastresp = $Apache::lonhomework::history{"resource.$part.$id.submission"};
  534:             }
  535:         }
  536: 	my %lastresponse=&Apache::lonnet::str2hash($lastresp);
  537: 	my $lastopt=$lastresponse{$name};
  538: 	if ($text!~/^\s*$/) { $break='<br />'; }
  539: 	$result.=$break;
  540: 	if ($target eq 'web') {
  541: 	    my $value=$Apache::response::foilgroup{$name.'.value'};
  542: 	    if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
  543: 		if ($text=~/^\s*$/) {
  544: 		    $text=$value.$text;
  545: 		} else {
  546: 		    $text='<b>'.$value.':</b> '.$text;
  547: 		}
  548: 	    } else {
  549:                 if (@whichopt > 1) {
  550:                     $text='&#149;'.$text;
  551:                 }
  552: 	    }
  553: 	    $result.=$text."\n";
  554: 	}
  555:       if ($Apache::lonhomework::type eq 'exam') {
  556: 	  $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
  557:       }
  558:       $temp++;
  559:     }
  560:   } else {
  561:     my $temp=1;
  562:     my %lastresponse;
  563:     my $newvariation;
  564:     if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
  565:         ($Apache::lonhomework::type eq 'randomizetry')) &&
  566:         ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
  567:         if ($env{'form.'.$part.'.rndseed'} ne
  568:             $Apache::lonhomework::history{"resource.$part.rndseed"}) {
  569:             $newvariation = 1;
  570:         }
  571:     }
  572:     unless ($newvariation) {
  573:         if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
  574:             (($env{'form.grade_username'} eq $env{'user.name'}) &&
  575:              ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
  576:                  %lastresponse =
  577:                      &Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
  578:         } else {
  579:             unless (($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') ||
  580:                     ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) {
  581:                 %lastresponse =
  582:                     &Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
  583:             }
  584:         }
  585:     }
  586:     my $internal_counter=$Apache::lonxml::counter;
  587:     my $checkboxopt=&check_box_opt($target,$checkboxvalue,@opt);
  588:     if ($checkboxopt && (!$no_tfprompt)) {
  589:        $result.='<br />'.
  590:                 ($checkboxchoices?&mt('Choices: ').'<b>'.$opt[0].','.$opt[1].'</b>. ':'').
  591:                  &mt('Select all that are [_1].','<b>'.$checkboxopt.'</b>');
  592:     }
  593:     foreach $name (@whichopt) {
  594:       my $text=$Apache::response::foilgroup{$name.'.text'};
  595:       if ($text!~/^\s*$/) {
  596: 	  if ($target eq 'tex') {
  597: 	      $break='\vskip 0 mm ';
  598: 	  } elsif ($target eq 'web') {
  599: 	      $break='<br />';
  600: 	  }
  601:       }
  602:       my $lastopt=$lastresponse{$name};
  603:       my $optionlist="<option></option>\n";
  604: 
  605:       if($target eq 'tex' and $env{'form.pdfFormFields'} eq 'yes'
  606:          && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  607:           my $fieldname = $env{'request.symb'}.'&part_'.$Apache::inputtags::part.'&optionresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp;
  608:           $optionlist =  &Apache::lonxml::print_pdf_start_combobox($fieldname);
  609:       }
  610: 
  611:       foreach my $option (@opt) {
  612: 	  my $escopt=&HTML::Entities::encode($option,'\'"&<>');
  613:           if ($option eq $lastopt) {
  614:               if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
  615:                   && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
  616:                   && $Apache::lonhomework::type ne 'exam') {
  617:                   $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
  618:               } else {
  619:                   $optionlist.="<option value='".$escopt."' selected=\"selected\">$option</option>\n";
  620:               }
  621:           } else {
  622:               if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
  623:                   && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
  624:                   && $Apache::lonhomework::type ne 'exam') {
  625:                   $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
  626:               } else {
  627:                   $optionlist.="<option value='".$escopt."'>$option</option>\n";
  628:               }
  629:           }
  630:       }
  631:       if ($target ne 'tex') {
  632: 	  if ($Apache::lonhomework::type ne 'exam') {
  633: # we are on the web, this is not an exam, and the problem can be answered
  634:               if ($checkboxopt) {
  635: # generate checkboxes
  636:                   my $fieldname=$Apache::inputtags::response['-1'].':'.$temp;
  637:                   my $altopt=$opt[0];
  638:                   if ($opt[0] eq $checkboxopt) {
  639:                      $altopt=$opt[1];
  640:                   }
  641:                   my $defopt=$lastopt;
  642:                   unless ($defopt) { $defopt=$altopt; }
  643:                   my $escdefopt=&HTML::Entities::encode($defopt,'\'"&<>');
  644:                   my $esccheckboxopt=&HTML::Entities::encode($checkboxopt,'\'"&<>');
  645:                   my $escaltopt=&HTML::Entities::encode($altopt,'\'"&<>');
  646: # checkboxopt is how the box is labelled
  647: # altopt is the alternative option
  648: # lastopt is what the user submitted before
  649: # defopt is what the field is going to start out with: either previous choice or altopt
  650: # fieldname is this input field's name after HWVAL_
  651:                   $optionlist='<input type="hidden" name="HWVAL_'.$fieldname.'" value="'.$escdefopt.'" />'.
  652:                   '<input type="checkbox" name="HWCHK_'.$fieldname.'" onclick="javascript:if (this.form.elements[\'HWCHK_'.
  653:                   $fieldname.'\'].checked) { this.form.elements[\'HWVAL_'.$fieldname.'\'].value=\''.$esccheckboxopt.'\'; } else { this.form.elements[\'HWVAL_'.$fieldname.'\'].value=\''.$escaltopt.'\'; };setSubmittedPart(\''.$part.'\');"'.($defopt eq $checkboxopt?' checked="checked"':'')." />\n";
  654:               } else {
  655: # classic selection list
  656: 	          $optionlist='<select onchange="javascript:setSubmittedPart(\''.
  657: 		  $part.'\');" name="HWVAL_'.
  658: 		  $Apache::inputtags::response['-1'].':'.$temp.'">'.
  659: 		  $optionlist."</select>\n";
  660:               }
  661: 	  } else {
  662: 	      $optionlist='<u>'.('&nbsp;'x10).'</u>';
  663: 	  }
  664: 	  if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
  665: 	      if ($Apache::lonhomework::type ne 'exam') {
  666:                   if (@whichopt > 1) {  
  667:                       $text='&#149;'.$text;
  668:                   }
  669: 	      }
  670: 	  } else {
  671: 	      if ($Apache::lonhomework::type ne 'exam') {
  672: 		  $text=$optionlist.$text;
  673: 	      }
  674: 	  }
  675: 	  $result.=$break.$text."\n";
  676: 	  if ($Apache::lonhomework::type eq 'exam') {
  677: 	      $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
  678: 	  }
  679: 	  $temp++;
  680:       } else {
  681: 	  my $texoptionlist='';
  682: 	  if ($displayoptionintex &&
  683: 	      $Apache::lonhomework::type ne 'exam') {
  684: 	      $texoptionlist = &optionlist_correction($TeXlayout,@opt);
  685: 	  }
  686: 	  if ($text=~/<drawoptionlist\s*\/>/) {
  687: 	      $text=~s|<drawoptionlist\s*\/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |g;
  688: 	  }
  689: 
  690: 	  if ($text=~m/\\item /) {
  691: 	      if ($Apache::lonhomework::type eq 'exam') {
  692: 	          $text=~s/\\item/\\vskip 2 mm/;
  693: 	      } elsif ($env{'form.pdfFormFields'} ne 'yes') {
  694:                   $result.= $texoptionlist.$text;
  695:               }
  696:           } else {
  697: 	      if ($Apache::lonhomework::type eq 'exam') {
  698: 		  $result.= $texoptionlist.'  '.$text;
  699: 	      } elsif ($env{'form.pdfFormFields'} ne 'yes') {
  700: 		  if ($text=~/\S/) {
  701:                       $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
  702:                   } else {
  703:                       $result.= $texoptionlist;
  704:                   }
  705: 	      }
  706: 	  }
  707: 	  if ($Apache::lonhomework::type eq 'exam') {
  708: 	      $result.='\vskip -1 mm\noindent';
  709:               my ($numrows,$bubbles_per_row) = &getnumrows(scalar(@opt)); 
  710:               if ($numrows == 1) {  
  711:                   $result .= '\textbf{'.$internal_counter.'}. \vskip -3mm';
  712:               } else {
  713:                   my $linetext;
  714:                   for (my $i=0; $i<$numrows; $i++) {
  715:                       $linetext .= $internal_counter+$i.', ';
  716:                   }
  717:                   $linetext =~ s/,\s$//;
  718:                   $result .= '\small {\textbf{'.$linetext.'}} '.
  719:                              '\hskip 2 mm {\footnotesize '.
  720:                              &mt('(Bubble once in [_1] lines)',$numrows).
  721:                              '} \vskip 1 mm';
  722:               }
  723:               $result.= &bubbles(\@alphabet,\@opt,undef,undef,$numrows,
  724:                                  $bubbles_per_row,$internal_counter).
  725:                         ' \strut ';
  726: 	      $internal_counter += $numrows;
  727: 	  }
  728:           if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
  729:               && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
  730:               && $Apache::lonhomework::type ne 'exam') {
  731:               $text =~ s/\\item//m;
  732:               $result .= " $optionlist ". &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
  733:               $temp++;
  734:           }
  735: 	  $displayoptionintex=0;
  736:       }
  737:     }
  738:   }
  739: 
  740:   if ($target eq 'web') {
  741:       my $data = [\@whichopt,'submissiongrading'];
  742:       my $questiontype;
  743:       if ($Apache::lonhomework::type eq 'randomizetry') {
  744:           $questiontype = $Apache::lonhomework::type,
  745:       }
  746:       &Apache::response::setup_prior_tries_hash(\&Apache::rankresponse::format_prior_answer,$data,$questiontype);
  747:   }
  748: 
  749:   if ($target ne 'tex') {
  750:       return $result.$break;
  751:   } else {
  752:       return $result;
  753:   }
  754: }
  755: 
  756: 
  757: sub optionlist_correction {
  758:     my ($TeXlayout,@options) = @_;
  759:     my $texoptionlist='\\item [] '.&mt('Choices:').' ';
  760:     if ($TeXlayout eq 'vertical') {$texoptionlist='\\item []';}
  761:     if (scalar(@options) > 0) {
  762: 	foreach my $option (@options) {
  763: 	    $texoptionlist.='{\bf '.
  764: 		&Apache::lonxml::latex_special_symbols($option).
  765: 		'}';
  766: 	    if ($TeXlayout eq 'vertical') {
  767: 		$texoptionlist.=' \vskip 0 mm ',
  768: 	    } else {
  769: 		$texoptionlist.=', ';
  770: 	    }
  771: 	}
  772: 	$texoptionlist=~s/, $//;
  773: 	if ($TeXlayout ne 'vertical') {$texoptionlist.='.';}
  774:     } else {
  775: 	if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';}
  776:     }
  777:     return $texoptionlist;
  778: }
  779: 
  780: 
  781: sub webbubbles {
  782:     my ($ropt,$ralphabet,$temp,$lastopt)=@_;
  783:     my @opt=@$ropt; 
  784:     my @alphabet=@$ralphabet;
  785:     my $result='';
  786:     my $number_of_bubbles = $#opt + 1;
  787:     $result.= '<table border="1"><tr>';
  788:     for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
  789: 	my $checked='';
  790: 	if ($lastopt eq $opt[$ind]) {
  791: 	    $checked=' checked="on" ';
  792: 	}
  793: 	$result.='<td><input type="radio" name="HWVAL_'.
  794: 	    $Apache::inputtags::response['-1'].':'.$temp.
  795: 	    '" value="'.$opt[$ind].'" '.$checked.' />';
  796: 	if ($alphabet[$ind]) {
  797: 	    $result.=$alphabet[$ind].': ';
  798: 	}
  799: 	$result.=$opt[$ind].'</td>';
  800:     }
  801:     $result.='</tr></table>';
  802:     return $result;
  803: }
  804: 
  805: 
  806: sub bubbles {
  807:     my ($ralphabet,$ropt,$response,$max_width,$numrows,$bubbles_per_row,
  808:         $internal_counter) = @_;
  809:     my @alphabet = @$ralphabet;
  810:     my @opt = @$ropt;
  811:     my ($result,$head,$line) =('','','');
  812:     my $number_of_bubbles = $#opt + 1;
  813:     my $current_length = 0;
  814:     my $textwidth;
  815:     if (defined($max_width)) {
  816: 	$textwidth=$max_width;
  817: 	&Apache::lonxml::debug("Max width passed in: $max_width");
  818:     } elsif ($env{'form.textwidth'} ne '') {
  819: 	$env{'form.textwidth'}=~/(\d+)/;
  820: 	$textwidth=$1;
  821: 	&Apache::lonxml::debug("Max width from form: $textwidth");
  822:     } else {
  823: 	$env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
  824: 	$textwidth=$1.'.'.$2;
  825: 	&Apache::lonxml::debug("Max width defaults? $textwidth");
  826:     }
  827:     &Apache::lonxml::debug("Final maxwidth: $textwidth");
  828:     for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
  829:         my $item;
  830:         if ($numrows > 1) {
  831:             my $num = $internal_counter+int($ind/$bubbles_per_row);
  832:             my $idx = int($ind % $bubbles_per_row);
  833:             $item = $num.$alphabet[$idx];
  834:         } else {
  835:             $item = $alphabet[$ind];
  836:         }
  837: 	my $leftmargin;
  838: 	$opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
  839: 	if ($response eq 'rankresponse') {$opt[$ind]='Rank '.$opt[$ind];}
  840: 	if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
  841: 
  842: 	$current_length += (length($opt[$ind])+length($item)+5)*2;
  843:         
  844: 	if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
  845:             
  846: 	    $line.='\hskip 4 mm {\small \textbf{'.$item.'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
  847: 	    $head.='lr';
  848: 	} else {
  849: 	    $line=~s/\&\s*$//;
  850: 	    $result.='\vskip -1 mm\noindent\setlength{\tabcolsep}{2 mm}\renewcommand{\arraystretch}{1.25}\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm';
  851: 	    $line = '\hskip 4 mm {\small \textbf{'.$item.'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
  852: 	    $head ='lr';
  853: 	    $current_length = (length($opt[$ind])+length($item))*2;
  854: 	}
  855: 
  856:     }
  857:     return $result;
  858: }
  859: 
  860: sub start_conceptgroup {
  861:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  862:   $Apache::optionresponse::conceptgroup=1;
  863:   %Apache::response::conceptgroup=();
  864:   my $result;
  865:   if ($target eq 'edit') {
  866:     $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
  867:     $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
  868:         &Apache::edit::end_row().&Apache::edit::start_spanning_row();
  869:   }
  870:   if ($target eq 'modified') {
  871:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
  872:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  873:   }
  874:   return $result;
  875: }
  876: 
  877: sub end_conceptgroup {
  878:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  879:   $Apache::optionresponse::conceptgroup=0;
  880:   my $result='';
  881:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  882:       $target eq 'tex' || $target eq 'analyze') {
  883:     #if not there aren't any foils to display and thus no question
  884:       &Apache::response::pick_foil_for_concept($target,
  885: 					       ['value','text','location'],
  886: 					       \%Apache::hint::option,
  887: 					       $parstack,$safeeval);
  888:   } elsif ($target eq 'edit') {
  889:     $result=&Apache::edit::end_table();
  890:   }
  891:   return $result;
  892: }
  893: 
  894: sub insert_conceptgroup {
  895:   my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
  896:   return $result;
  897: }
  898: 
  899: sub start_foil {
  900:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  901:   my $result='';
  902:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
  903:       &Apache::lonxml::startredirection;
  904:       if ($target eq 'analyze') {
  905: 	  &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
  906:       }
  907:   } elsif ($target eq 'edit') {
  908:     $result=&Apache::edit::tag_start($target,$token,"Foil");
  909:     my $level='-2';
  910:     if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
  911:     my @opt;
  912:     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
  913:     $result.=&Apache::edit::text_arg('Name:','name',$token);
  914:     $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
  915: 					       ['unused',(@opt)],$token,'15');
  916:     my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
  917: 					     $safeeval,'-3');
  918:     if ($randomize ne 'no') {
  919: 	$result.=&Apache::edit::select_arg('Location:','location',
  920: 					   ['random','top','bottom'],$token);
  921:     }
  922:     $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  923:   } elsif ($target eq 'modified') {
  924:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
  925: 						 'value','name','location');
  926:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  927:   } 
  928:   return $result;
  929: }
  930: 
  931: sub end_foil {
  932:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  933:   my $text ='';
  934:   my $result = '';
  935:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') { 
  936:       $text=&Apache::lonxml::endredirection;
  937:       if ($target eq 'tex') {$text=~s/\\strut\s*\\\\\s*\\strut/\\vskip 0 mm/;}
  938:       if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;} 
  939:   }
  940:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' 
  941:       || $target eq 'tex' || $target eq 'analyze') {
  942:     my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
  943:     if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
  944: 	$text='\vskip 5mm $\triangleright$ '.$text;
  945:     }
  946:     if ($value ne 'unused') {
  947:       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  948:       &Apache::lonxml::debug("Got a name of :$name:");
  949:       if ($name eq "") {
  950: 	  &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
  951: 	  $name=$Apache::lonxml::curdepth;
  952:       }
  953:       &Apache::lonxml::debug("Using a name of :$name:");
  954:       if (defined($Apache::response::foilnames{$name})) {
  955: 	  &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",'<b><tt>'.$name.'</tt></b>'));
  956:       }
  957:       $Apache::response::foilnames{$name}++;
  958:       my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
  959:       if ( $Apache::optionresponse::conceptgroup
  960: 	   && !&Apache::response::showallfoils() ) {
  961: 	push @{ $Apache::response::conceptgroup{'names'} }, $name;
  962: 	$Apache::response::conceptgroup{"$name.value"} = $value;
  963: 	$Apache::response::conceptgroup{"$name.text"} = $text;
  964: 	$Apache::response::conceptgroup{"$name.location"} = $location;
  965:       } else {
  966: 	push @{ $Apache::response::foilgroup{'names'} }, $name;
  967: 	$Apache::response::foilgroup{"$name.value"} = $value;
  968: 	$Apache::response::foilgroup{"$name.text"} = $text;
  969: 	$Apache::response::foilgroup{"$name.location"} = $location;
  970:       }
  971:     }
  972:   }
  973:   if ($target eq 'edit') {
  974:     $result.= &Apache::edit::tag_end($target,$token,'');
  975:   }
  976:   return $result;
  977: }
  978: 
  979: sub start_drawoptionlist {
  980:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  981:     if ($target !~ /^(?:meta|answer|modified|edit)$/) {
  982: 	return $token->[4];
  983:     }
  984: }
  985: 
  986: sub end_drawoptionlist {
  987:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  988:     if ($target !~ /^(?:meta|answer|modified|edit)$/) {
  989: 	return $token->[2];
  990:     }
  991: }
  992: 
  993: sub insert_foil {
  994:     return '
  995: <foil name="" value="unused">
  996: <startouttext />
  997: <endouttext />
  998: </foil>';
  999: }
 1000: 
 1001: sub insert_drawoptionlist {
 1002:     return '<drawoptionlist />';
 1003: }
 1004: 
 1005: sub getnumrows {
 1006:     my ($numitems) = @_;
 1007:     my $bubbles_per_row;
 1008:     my $default_numbubbles = 10;
 1009:     if (($env{'form.bubbles_per_row'} =~ /^\d+$/) &&
 1010:         ($env{'form.bubbles_per_row'} > 0)) {
 1011:         $bubbles_per_row = $env{'form.bubbles_per_row'};
 1012:     } else {
 1013:         $bubbles_per_row = $default_numbubbles;
 1014:     }
 1015:     my $numrows = int ($numitems/$bubbles_per_row);
 1016:     if (($numitems % $bubbles_per_row) != 0) {
 1017:         $numrows ++;
 1018:     }
 1019:     return ($numrows,$bubbles_per_row);
 1020: }
 1021: 
 1022: 1;
 1023: __END__
 1024:  
 1025: =head1 NAME
 1026: 
 1027: Apache::optionresponse.pm;
 1028: 
 1029: =head1 SYNOPSIS
 1030: 
 1031: Handles tags associated with showing a list of
 1032: options.
 1033: 
 1034: This is part of the LearningOnline Network with CAPA project
 1035: described at http://www.lon-capa.org.
 1036: 
 1037: =head1 HANDLER SUBROUTINE
 1038: 
 1039: start_optionresponse()
 1040: 
 1041: =head1 OTHER SUBROUTINES
 1042: 
 1043: =over
 1044: 
 1045: =item end_optionresponse()
 1046: 
 1047: =item start_foilgroup()
 1048: 
 1049: =item end_foilgroup()
 1050: 
 1051: =item getfoilcounts()
 1052: 
 1053: =item displayanswers()
 1054: 
 1055: =item check_for_invalid()
 1056: 
 1057: =item displayfoils()
 1058: 
 1059: =item optionlist_correction()
 1060: 
 1061: =item webbubbles()
 1062: 
 1063: =item bubbles()
 1064: 
 1065: =item start_conceptgroup()
 1066: 
 1067: =item end_conceptgroup()
 1068: 
 1069: =item insert_conceptgroup()
 1070: 
 1071: =item start_foil()
 1072: 
 1073: =item end_foil()
 1074: 
 1075: =item start_drawoptionlist()
 1076: 
 1077: =item end_drawoptionlist()
 1078: 
 1079: =item insert_foil()
 1080: 
 1081: =item insert_drawoptionlist()
 1082: 
 1083: =back
 1084: 
 1085: =cut

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