File:  [LON-CAPA] / loncom / homework / optionresponse.pm
Revision 1.193: download - view: text, annotated - select for diffs
Tue Dec 3 17:22:08 2013 UTC (10 years, 5 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0, HEAD
Internationalization of colorful editor - added missing &mt() calls

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

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