File:  [LON-CAPA] / loncom / homework / optionresponse.pm
Revision 1.194: download - view: text, annotated - select for diffs
Thu Nov 27 17:37:09 2014 UTC (9 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6597
  - Attributes for foilgroup in optionresponse now include checkbox for
    omit "Select all that are ..." in colorful editor (displayed by default
    when reponse uses checkboxes for binary options instead of dropdown lists).

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

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