Annotation of loncom/homework/optionresponse.pm, revision 1.172

1.46      sakharuk    1: # LearningOnline Network with CAPA
1.22      albertel    2: # option list style responses
1.27      albertel    3: #
1.172   ! www         4: # $Id: optionresponse.pm,v 1.171 2010/09/01 21:29:51 raeburn Exp $
1.27      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.154     jms        28: 
                     29: 
                     30: 
                     31: 
                     32: 
1.1       albertel   33: package Apache::optionresponse;
                     34: use strict;
1.103     albertel   35: use Apache::response();
                     36: use Apache::lonlocal;
1.125     albertel   37: use Apache::lonnet;
1.1       albertel   38: 
1.31      harris41   39: BEGIN {
1.1       albertel   40:   &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
                     41: }
                     42: 
                     43: sub start_optionresponse {
1.22      albertel   44:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     45:   my $result='';
1.29      albertel   46:   #when in a option response use these
1.112     sakharuk   47:   &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
1.22      albertel   48:   push (@Apache::lonxml::namespace,'optionresponse');
                     49:   my $id = &Apache::response::start_response($parstack,$safeeval);
1.57      albertel   50:   %Apache::hint::option=();
1.103     albertel   51:   undef(%Apache::response::foilnames);
1.22      albertel   52:   if ($target eq 'edit') {
1.153     bisitz     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";
1.48      albertel   63:     $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max',
                     64: 				     $token,'4').
1.153     bisitz     65:         &Apache::edit::select_arg('Randomize Foil Order:','randomize',
1.48      albertel   66: 				  ['yes','no'],$token).
1.108     albertel   67:         &Apache::edit::select_arg(&mt('Display of options when printed'),'TeXlayout',
1.157     raeburn    68: 				  [['horizontal','Normal list'],
                     69: 				   ['vertical','Listed in a vertical column']],$token).
1.48      albertel   70:         &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.34      albertel   71:   } elsif ($target eq 'modified') {
1.23      albertel   72:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.108     albertel   73: 						 $safeeval,'max','randomize',
                     74: 						 'TeXlayout');
1.22      albertel   75:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.34      albertel   76:   } elsif ($target eq 'meta') {
1.23      albertel   77:     $result=&Apache::response::meta_package_write('optionresponse');
1.34      albertel   78:   } elsif ($target eq 'analyze') {
1.93      albertel   79:     my $part_id="$Apache::inputtags::part.$id";
1.149     raeburn    80:     $Apache::lonhomework::analyze{"$part_id.type"} = 'optionresponse';
1.34      albertel   81:     push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.148     raeburn    82:     push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} }, 1);
1.145     foxr       83: 
1.22      albertel   84:   }
                     85:   return $result;
1.1       albertel   86: }
                     87: 
                     88: sub end_optionresponse {
1.22      albertel   89:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     90:   &Apache::response::end_response;
                     91:   pop @Apache::lonxml::namespace;
1.112     sakharuk   92:   &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
1.22      albertel   93:   my $result;
                     94:   if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
1.103     albertel   95:   undef(%Apache::response::foilnames);
1.22      albertel   96:   return $result;
1.1       albertel   97: }
                     98: 
1.44      albertel   99: %Apache::response::foilgroup=();
1.1       albertel  100: sub start_foilgroup {
1.22      albertel  101:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    102: 
                    103:   my $result='';
1.44      albertel  104:   %Apache::response::foilgroup=();
1.22      albertel  105:   $Apache::optionresponse::conceptgroup=0;
1.110     albertel  106:   &Apache::response::pushrandomnumber();
1.22      albertel  107:   if ($target eq 'edit') {
                    108:     my $optionlist="<option></option>\n";
                    109:     my $option;
                    110:     my @opt;
                    111:     eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval);
                    112:     my $count=1;
                    113:     foreach $option (@opt) {
                    114:       $optionlist.="<option value=\"$count\">$option</option>\n";
                    115:       $count++;
                    116:     }
                    117:     my $insertlist=&Apache::edit::insertlist($target,$token);
                    118:     $result.=&Apache::edit::start_table($token);
                    119:     $result.= (<<ENDTABLE);
                    120:       <tr><td>Select Options</td>
1.13      albertel  121:         <td>
                    122: 	  Add new Option: <input type="text" name="$Apache::lonxml::curdepth.options" />
                    123:         </td>
                    124:         <td>Delete an Option:
                    125: 	  <select name="$Apache::lonxml::curdepth.deleteopt">$optionlist</select>
1.162     www       126:         </td>
1.13      albertel  127: ENDTABLE
1.162     www       128:     $result.= '<td>'.&Apache::edit::checked_arg('Print options:','texoptions',
1.132     albertel  129: 					 [ ['nochoice','Don\'t show option list'] ]
1.162     www       130: 					 ,$token).'</td>';
                    131:     $result.= '<td><label>'.&mt('Two-option checkboxes for:').
                    132:               '<select name="checkboxvalue_'.$Apache::lonxml::curdepth.'">';
                    133:     foreach $option (('',@opt)) {
                    134:        $result.='<option value="'.$option.'"';
                    135:        if ($option eq &Apache::lonxml::get_param('checkboxvalue',$parstack,$safeeval)) {
                    136:           $result.=' selected="selected"';
                    137:        }
                    138:        $result.='>'.$option.'</option>';
                    139:     }
1.172   ! www       140:     $result.='</select></label>';
        !           141:     $result.=&Apache::edit::checked_arg('Checkbox options:','checkboxoptions',
        !           142:                                          [ ['nochoice','Don\'t show option list'] ]
        !           143:                                          ,$token).'</td>';
1.30      matthew   144:     $result.= &Apache::edit::end_row();
                    145:     $result.= &Apache::edit::start_spanning_row();
                    146:     $result.= $insertlist.'<br />';
1.22      albertel  147:   }
                    148:   if ($target eq 'modified') {
                    149:     my @options;
                    150:     my $optchanged=0;
                    151:     eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.125     albertel  152:     if ($env{"form.$Apache::lonxml::curdepth.deleteopt"}) {
                    153:       my $delopt=$env{"form.$Apache::lonxml::curdepth.deleteopt"};
1.22      albertel  154:       &Apache::lonxml::debug("Deleting :$delopt:");
                    155:       splice(@options,$delopt-1,1);
                    156:       $optchanged=1;
                    157:     }
1.125     albertel  158:     if ($env{"form.$Apache::lonxml::curdepth.options"}) {
                    159:       my $newopt = $env{"form.$Apache::lonxml::curdepth.options"};
1.22      albertel  160:       if ($options[0]) {
                    161: 	push(@options,$newopt);
                    162:       } else {
                    163: 	$options[0]=$newopt;
                    164:       }
                    165:       $optchanged=1;
                    166:     }
1.132     albertel  167:     my $rebuildtag = &Apache::edit::get_new_args($token,$parstack,$safeeval,
1.172   ! www       168: 						 'texoptions','checkboxvalue','checkboxoptions');
1.132     albertel  169:     if ($optchanged || $rebuildtag ) {
1.22      albertel  170:       $result = "<foilgroup options=\"(";
                    171:       foreach my $option (@options) {
1.41      albertel  172: 	$option=~s/\'/\\\'/g;
1.22      albertel  173: 	&Apache::lonxml::debug("adding option :$option:");
                    174: 	$result .="'".$option."',";
                    175:       }
                    176:       chop $result;
1.132     albertel  177:       $result.=')" ';
                    178:       $result .= 'texoptions="'.$token->[2]{'texoptions'}.'" ';
1.172   ! www       179:       $result .= 'checkboxoptions="'.$token->[2]{'checkboxoptions'}.'" ';
1.162     www       180:       $result .= 'checkboxvalue="'.$token->[2]{'checkboxvalue'}.'"';
1.132     albertel  181:       $result .= '>';
1.22      albertel  182:     } # else nothing changed so just use the default mechanism
                    183:   }
1.68      sakharuk  184:   if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.152     onken     185:     if($env{'form.pdfFormFields'} ne 'yes') {
1.167     raeburn   186:       $result .= ' \begin{itemize} ';
1.152     onken     187:     } else {
                    188:       $result .= "\\\\";
                    189:     }
1.42      sakharuk  190:   }
1.22      albertel  191:   return $result;
1.1       albertel  192: }
                    193: 
                    194: sub end_foilgroup {
1.22      albertel  195:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    196:   
                    197:   my $result;
1.94      albertel  198:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
                    199:       $target eq 'tex' || $target eq 'analyze') {
1.81      sakharuk  200:     my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
1.22      albertel  201:     my $name;
                    202:     my @opt;
                    203:     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.126     albertel  204:     &Apache::lonxml::debug("options:".join(':',@opt));
                    205: 
1.108     albertel  206:     my $TeXlayout=&Apache::lonxml::get_param('TeXlayout',$parstack,$safeeval,
                    207: 					     -2,0);
1.161     www       208:     my $checkboxvalue=&Apache::lonxml::get_param('checkboxvalue',$parstack,$safeeval);
1.172   ! www       209:     my $checkboxchoices=(&Apache::lonxml::get_param('checkboxoptions',$parstack,$safeeval) ne 'nochoice');
1.81      sakharuk  210:     if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
1.22      albertel  211:     &Apache::lonxml::debug("Options are $#opt");
1.48      albertel  212:     my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
                    213:     my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
                    214: 					       $safeeval,'-2');
1.32      sakharuk  215:     if ($target eq 'web' || $target eq 'tex') {
1.172   ! www       216:       $result.=&displayfoils($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,@opt);
1.137     albertel  217:       $Apache::lonxml::post_evaluate=0;
1.25      albertel  218:     } elsif ( $target eq 'answer') {
1.48      albertel  219:       $result.=&displayanswers($max,$randomize,@opt);
1.136     foxr      220:       
1.34      albertel  221:     } elsif ( $target eq 'analyze') {
1.93      albertel  222: 	my @shown = &whichfoils($max,$randomize);
1.94      albertel  223: 	&Apache::response::analyze_store_foilgroup(\@shown,
                    224: 						  ['text','value','location']);
1.93      albertel  225: 	my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
                    226: 	push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
1.22      albertel  227:     } elsif ( $target eq 'grade') {
1.124     albertel  228:       if ( &Apache::response::submitted()) {
1.48      albertel  229: 	my @whichopt = &whichfoils($max,$randomize);
1.22      albertel  230: 	my $temp=1;my $name;
1.26      albertel  231: 	my %responsehash;
1.57      albertel  232: 	my %grade;
1.22      albertel  233: 	my $right=0;
                    234: 	my $wrong=0;
                    235: 	my $ignored=0;
                    236: 	foreach $name (@whichopt) {
1.74      albertel  237: 	  my $response=&Apache::response::getresponse($temp);
1.125     albertel  238: 	  if ($env{'form.submitted'} eq 'scantron' && $response=~/\S/) {
1.74      albertel  239: 	      $response = $opt[$response];
                    240: 	  }
1.22      albertel  241: 	  if ( $response =~ /[^\s]/) {
1.96      albertel  242: 	    $responsehash{$name}=$response;
1.22      albertel  243: 	    my $value=$Apache::response::foilgroup{$name.'.value'};
1.34      albertel  244: 	    &Apache::lonxml::debug("submitted a $response for $value<br />\n");
1.57      albertel  245: 	    if ($value eq $response) {
                    246: 		$grade{$name}='1'; $right++;
                    247: 	    } else {
                    248: 		$grade{$name}='0'; $wrong++;
                    249: 	    }
1.22      albertel  250: 	  } else {
                    251: 	    $ignored++;
                    252: 	  }
                    253: 	  $temp++;
                    254: 	}
1.28      albertel  255: 	my $part=$Apache::inputtags::part;
1.22      albertel  256: 	my $id = $Apache::inputtags::response['-1'];
1.28      albertel  257: 	my $responsestr=&Apache::lonnet::hash2str(%responsehash);
1.57      albertel  258: 	my $gradestr   =&Apache::lonnet::hash2str(%grade);
1.28      albertel  259: 	my %previous=&Apache::response::check_for_previous($responsestr,
                    260: 							   $part,$id);
1.22      albertel  261: 	&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
1.75      albertel  262: 	$Apache::lonhomework::results{"resource.$part.$id.submission"}=
                    263: 	    $responsestr;
                    264: 	$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
                    265: 	
1.163     raeburn   266: 	if (($Apache::lonhomework::type eq 'survey') ||
                    267:             ($Apache::lonhomework::type eq 'surveycred') ||
                    268:             ($Apache::lonhomework::type eq 'anonsurvey') ||
                    269:             ($Apache::lonhomework::type eq 'anonsurveycred')) {
1.121     albertel  270: 	    if ($ignored == 0) {
1.163     raeburn   271:                 my $ad;
                    272:                 if ($Apache::lonhomework::type eq 'anonsurveycred') {
                    273:                     $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS_CREDIT';
                    274:                 } elsif ($Apache::lonhomework::type eq 'anonsurvey') {
                    275:                     $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='ANONYMOUS';
                    276:                 } elsif ($Apache::lonhomework::type eq 'surveycred') {
                    277:                     $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED_CREDIT';
                    278:                 } else {
                    279: 		    $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
                    280:                 }
1.121     albertel  281: 		&Apache::response::handle_previous(\%previous,$ad);
                    282: 	    } elsif ($wrong==0 && $right==0) {
                    283: 	    } else {
                    284: 		my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='MISSING_ANSWER';
                    285: 		&Apache::response::handle_previous(\%previous,$ad);
                    286: 	    }
                    287: 	} elsif (!$Apache::lonhomework::scantronmode) {
1.75      albertel  288: 	    my $ad;
                    289: 	    if ($wrong==0 && $ignored==0) {
                    290: 		$ad='EXACT_ANS';
                    291: 	    } elsif ($wrong==0 && $right==0) {
                    292: 		#nothing submitted
                    293: 	    } else {
                    294: 		if ($ignored==0) {
                    295: 		    $ad='INCORRECT';
                    296: 		} else {
                    297: 		    $ad='MISSING_ANSWER';
                    298: 		}
                    299: 	    }
                    300: 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
                    301: 	    &Apache::response::handle_previous(\%previous,$ad);
1.22      albertel  302: 	} else {
1.75      albertel  303: 	    my $ad;
                    304: 	    if ($wrong==0 && $right==0) {
1.120     albertel  305: 		#nothing submitted only assign a score if we 
                    306: 		#need to override a previous grade
                    307: 		if (defined($Apache::lonhomework::history{"resource.$part.$id.awarddetail"})) {
                    308: 		    $ad='ASSIGNED_SCORE';
                    309: 		}
1.75      albertel  310: 	    } else {
                    311: 		$ad='ASSIGNED_SCORE';
                    312: 	    }
                    313: 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
                    314: 	    $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
                    315: 		$right/(scalar(@whichopt));
1.76      albertel  316: 	    $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
                    317: 		scalar(@whichopt);
1.1       albertel  318: 	}
1.22      albertel  319:       }
1.1       albertel  320:     }
1.147     foxr      321:     my $part_id     = $Apache::inputtags::part;
                    322:     my $response_id = $Apache::inputtags::response[-1];
1.146     foxr      323:     &Apache::lonxml::increment_counter(&getfoilcounts($max),
1.147     foxr      324: 				       "$part_id.$response_id");
1.146     foxr      325:     if ($target eq 'analyze') {
                    326: 	&Apache::lonhomework::set_bubble_lines();
                    327:     }
                    328: 
1.25      albertel  329:   } elsif ($target eq 'edit') {
1.22      albertel  330:     $result.=&Apache::edit::end_table();
1.74      albertel  331:   }
                    332:   if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.152     onken     333:     if($env{'form.pdfFormFields'} ne 'yes') {
1.167     raeburn   334:       $result .= '\end{itemize}'; 
1.152     onken     335:     } else {
                    336:       $result .= "\\\\";
                    337:     }
1.74      albertel  338:   }
1.110     albertel  339:   &Apache::response::poprandomnumber();
1.22      albertel  340:   return $result;
1.1       albertel  341: }
                    342: 
                    343: sub getfoilcounts {
1.48      albertel  344:   my ($max)=@_;
1.22      albertel  345:   # +1 since instructors will count from 1
                    346:   my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
1.39      albertel  347:   if (&Apache::response::showallfoils()) { $max=$count; }
1.48      albertel  348:   if ($count>$max) { $count=$max } 
                    349:   &Apache::lonxml::debug("Count is $count from $max");
                    350:   return $count;
1.1       albertel  351: }
                    352: 
                    353: sub whichfoils {
1.77      albertel  354:     my ($max,$randomize)=@_;
                    355:     return &Apache::response::whichorder($max,$randomize,
                    356: 					 &Apache::response::showallfoils(),
                    357: 					 \%Apache::response::foilgroup);
1.1       albertel  358: }
                    359: 
1.25      albertel  360: sub displayanswers {
1.130     albertel  361:     my ($max,$randomize,@opt)=@_;
                    362:     if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
                    363:     my @names = @{ $Apache::response::foilgroup{'names'} };
                    364:     my @whichopt = &whichfoils($max,$randomize);
                    365:     my $result;
                    366:     if ($Apache::lonhomework::type eq 'exam') {
                    367: 	my $i = 0;
                    368: 	my %opt = map { ($_,$i++) } @opt;
                    369: 	
                    370: 	$i = 0;
                    371: 	my @alphabet = ('A'..'Z');
                    372: 	foreach my $name (@whichopt) {
                    373: 	    $result.=&Apache::response::answer_header('optionresponse',$i++);
                    374: 	    $result.=&Apache::response::answer_part('optionresponse',
                    375: 						    $alphabet[$opt{$Apache::response::foilgroup{$name.'.value'}}]);
                    376: 	    $result.=&Apache::response::answer_part('optionresponse',
                    377: 						    $Apache::response::foilgroup{$name.'.value'});
                    378: 	    $result.=&Apache::response::answer_footer('optionresponse');
                    379: 	}
                    380:     } else {
                    381: 	$result=&Apache::response::answer_header('optionresponse');
                    382: 	foreach my $name (@whichopt) {
                    383: 	    $result.=&Apache::response::answer_part('optionresponse',
                    384: 						    $Apache::response::foilgroup{$name.'.value'});
                    385: 	}
                    386: 	$result.=&Apache::response::answer_footer('optionresponse');
                    387:     }
                    388:     return $result;
1.25      albertel  389: }
                    390: 
1.160     www       391: sub check_box_opt {
1.161     www       392:     my ($target,$checkboxvalue,@opt)=@_;
                    393: # Check if we are in checkbox mode: checkboxvalue specified, on web, only two options.
                    394: # If so, return "checked" value
                    395:     if ($#opt!=1) { return ''; }
                    396:     if ($target ne 'web') { return ''; }
                    397:     return $checkboxvalue;
1.160     www       398: }
                    399: 
1.106     albertel  400: sub check_for_invalid {
                    401:     my ($names,$options) = @_;
                    402:     my %bad_names;
                    403:     foreach my $name (@{ $names }) {
                    404: 	my $value=$Apache::response::foilgroup{$name.'.value'};
                    405: 	my $found=0;
                    406: 	foreach my $option (@{ $options }) {
                    407: 	    if ($value eq $option) { $found=1; }
                    408: 	}
                    409: 	if (!$found) { $bad_names{$name}=$value; }
                    410:     }
                    411:     if (%bad_names) {
                    412: 	my $error=&mt('The question can not be gotten correct, '.
                    413: 	    'the following foils in the &lt;optionresponse&gt; '.
                    414: 	    'have invalid correct options').' <br /><tt>'.
                    415: 	    join('<br />',(map { $_=&mt("[_1] with value [_2]",$_,$bad_names{$_}) } (keys(%bad_names)))).
                    416: 	    "</tt>";
                    417: 	&Apache::lonxml::error($error);
                    418:     }
                    419: }
                    420: 
1.1       albertel  421: sub displayfoils {
1.172   ! www       422:   my ($target,$max,$randomize,$TeXlayout,$checkboxvalue,$checkboxchoices,@opt)=@_;
1.67      albertel  423:   if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
1.22      albertel  424:   my @names = @{ $Apache::response::foilgroup{'names'} };
                    425:   my @truelist;
                    426:   my @falselist;
1.79      sakharuk  427:   my $result;  
1.22      albertel  428:   my $name;
1.101     albertel  429:   my $displayoptionintex=1;
1.72      sakharuk  430:   my @alphabet = ('A'..'Z');
1.48      albertel  431:   my @whichopt = &whichfoils($max,$randomize);
1.106     albertel  432:   &check_for_invalid(\@whichopt,\@opt);
1.28      albertel  433:   my $part=$Apache::inputtags::part;
                    434:   my $id=$Apache::inputtags::response[-1];
1.62      albertel  435:   my $break;
1.65      albertel  436:   my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
1.86      albertel  437:   if ( ($target ne 'tex') &&
                    438:        &Apache::response::show_answer() ) {
1.90      albertel  439:     my $temp=1;
1.22      albertel  440:     foreach $name (@whichopt) {
1.62      albertel  441: 	my $text=$Apache::response::foilgroup{$name.'.text'};
1.163     raeburn   442:         my $lastresp;
                    443:         unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) {
                    444:             $lastresp = $Apache::lonhomework::history{"resource.$part.$id.submission"};
                    445:         }
                    446: 	my %lastresponse=&Apache::lonnet::str2hash($lastresp);
1.90      albertel  447: 	my $lastopt=$lastresponse{$name};
1.101     albertel  448: 	if ($text!~/^\s*$/) { $break='<br />'; }
1.62      albertel  449: 	$result.=$break;
1.113     sakharuk  450: 	if ($target eq 'web') {
1.62      albertel  451: 	    my $value=$Apache::response::foilgroup{$name.'.value'};
                    452: 	    if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
                    453: 		if ($text=~/^\s*$/) {
                    454: 		    $text=$value.$text;
                    455: 		} else {
1.127     albertel  456: 		    $text='<b>'.$value.':</b> '.$text;
1.62      albertel  457: 		}
1.95      albertel  458: 	    } else {
1.170     raeburn   459:                 if (@whichopt > 1) {
                    460:                     $text='&#149;'.$text;
                    461:                 }
1.62      albertel  462: 	    }
                    463: 	    $result.=$text."\n";
1.112     sakharuk  464: 	}
1.58      sakharuk  465:       if ($Apache::lonhomework::type eq 'exam') {
1.90      albertel  466: 	  $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
1.58      sakharuk  467:       }
1.90      albertel  468:       $temp++;
1.22      albertel  469:     }
                    470:   } else {
                    471:     my $temp=1;
1.28      albertel  472:     my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
1.79      sakharuk  473:     my $internal_counter=$Apache::lonxml::counter;
1.161     www       474:     my $checkboxopt=&check_box_opt($target,$checkboxvalue,@opt);
1.160     www       475:     if ($checkboxopt) {
1.172   ! www       476:        $result.='<br />'.
        !           477:                 ($checkboxchoices?&mt('Choices: ').'<b>'.$opt[0].','.$opt[1].'</b>. ':'').
1.168     www       478:                  &mt('Select all that are <b>[_1]</b>.',$checkboxopt);
1.160     www       479:     }
1.22      albertel  480:     foreach $name (@whichopt) {
1.62      albertel  481:       my $text=$Apache::response::foilgroup{$name.'.text'};
                    482:       if ($text!~/^\s*$/) {
                    483: 	  if ($target eq 'tex') {
                    484: 	      $break='\vskip 0 mm ';
                    485: 	  } elsif ($target eq 'web') {
                    486: 	      $break='<br />';
                    487: 	  }
                    488:       }
1.28      albertel  489:       my $lastopt=$lastresponse{$name};
                    490:       my $optionlist="<option></option>\n";
1.152     onken     491: 
1.158     onken     492:       if($target eq 'tex' and $env{'form.pdfFormFields'} eq 'yes'
                    493:          && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.152     onken     494:           my $fieldname = $env{'request.symb'}.'&part_'.$Apache::inputtags::part.'&optionresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp;
                    495:           $optionlist =  &Apache::lonxml::print_pdf_start_combobox($fieldname);
                    496:       }
                    497: 
1.126     albertel  498:       foreach my $option (@opt) {
                    499: 	  my $escopt=&HTML::Entities::encode($option,'\'"&<>');
1.152     onken     500:           if ($option eq $lastopt) {
1.158     onken     501:               if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
1.164     onken     502:                   && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
                    503:                   && $Apache::lonhomework::type ne 'exam') {
1.152     onken     504:                   $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
                    505:               } else {
                    506:                   $optionlist.="<option value='".$escopt."' selected=\"selected\">$option</option>\n";
                    507:               }
                    508:           } else {
1.158     onken     509:               if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
1.164     onken     510:                   && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
                    511:                   && $Apache::lonhomework::type ne 'exam') {
1.152     onken     512:                   $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
                    513:               } else {
                    514:                   $optionlist.="<option value='".$escopt."'>$option</option>\n";
                    515:               }
                    516:           }
1.28      albertel  517:       }
1.32      sakharuk  518:       if ($target ne 'tex') {
1.72      sakharuk  519: 	  if ($Apache::lonhomework::type ne 'exam') {
1.159     www       520: # we are on the web, this is not an exam, and the problem can be answered
                    521:               if ($checkboxopt) {
                    522: # generate checkboxes
                    523:                   my $fieldname=$Apache::inputtags::response['-1'].':'.$temp;
                    524:                   my $altopt=$opt[0];
                    525:                   if ($opt[0] eq $checkboxopt) {
                    526:                      $altopt=$opt[1];
                    527:                   }
                    528:                   my $defopt=$lastopt;
                    529:                   unless ($defopt) { $defopt=$altopt; }
                    530:                   my $escdefopt=&HTML::Entities::encode($defopt,'\'"&<>');
                    531:                   my $esccheckboxopt=&HTML::Entities::encode($checkboxopt,'\'"&<>');
                    532:                   my $escaltopt=&HTML::Entities::encode($altopt,'\'"&<>');
                    533: # checkboxopt is how the box is labelled
                    534: # altopt is the alternative option
                    535: # lastopt is what the user submitted before
                    536: # defopt is what the field is going to start out with: either previous choice or altopt
                    537: # fieldname is this input field's name after HWVAL_
                    538:                   $optionlist='<input type="hidden" name="HWVAL_'.$fieldname.'" value="'.$escdefopt.'" />'.
1.160     www       539:                   '<input type="checkbox" name="HWCHK_'.$fieldname.'" onclick="javascript:if (this.form.elements[\'HWCHK_'.
                    540:                   $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";
1.159     www       541:               } else {
                    542: # classic selection list
                    543: 	          $optionlist='<select onchange="javascript:setSubmittedPart(\''.
1.139     albertel  544: 		  $part.'\');" name="HWVAL_'.
1.101     albertel  545: 		  $Apache::inputtags::response['-1'].':'.$temp.'">'.
1.59      albertel  546: 		  $optionlist."</select>\n";
1.159     www       547:               }
1.101     albertel  548: 	  } else {
                    549: 	      $optionlist='<u>'.('&nbsp;'x10).'</u>';
1.72      sakharuk  550: 	  }
1.101     albertel  551: 	  if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
                    552: 	      if ($Apache::lonhomework::type ne 'exam') {
1.170     raeburn   553:                   if (@whichopt > 1) {  
                    554:                       $text='&#149;'.$text;
                    555:                   }
1.101     albertel  556: 	      }
1.95      albertel  557: 	  } else {
1.101     albertel  558: 	      if ($Apache::lonhomework::type ne 'exam') {
                    559: 		  $text=$optionlist.$text;
                    560: 	      }
1.59      albertel  561: 	  }
1.62      albertel  562: 	  $result.=$break.$text."\n";
1.49      sakharuk  563: 	  if ($Apache::lonhomework::type eq 'exam') {
1.101     albertel  564: 	      $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
1.49      sakharuk  565: 	  }
1.32      sakharuk  566: 	  $temp++;
                    567:       } else {
1.101     albertel  568: 	  my $texoptionlist='';
                    569: 	  if ($displayoptionintex &&
                    570: 	      $Apache::lonhomework::type ne 'exam') {
1.107     sakharuk  571: 	      $texoptionlist = &optionlist_correction($TeXlayout,@opt);
1.101     albertel  572: 	  }
                    573: 	  if ($text=~/<drawoptionlist\s*\/>/) {
1.136     foxr      574: 	      $text=~s|<drawoptionlist\s*\/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |g;
1.101     albertel  575: 	  }
                    576: 
                    577: 	  if ($text=~m/\\item /) {
1.50      sakharuk  578: 	      if ($Apache::lonhomework::type eq 'exam') {
1.101     albertel  579: 	          $text=~s/\\item/\\vskip 2 mm/;
1.152     onken     580: 	      } elsif ($env{'form.pdfFormFields'} ne 'yes') {
                    581:                   $result.= $texoptionlist.$text;
                    582:               }
                    583:           } else {
1.101     albertel  584: 	      if ($Apache::lonhomework::type eq 'exam') {
                    585: 		  $result.= $texoptionlist.'  '.$text;
1.152     onken     586: 	      } elsif ($env{'form.pdfFormFields'} ne 'yes') {
                    587: 		  if ($text=~/\S/) {
                    588:                       $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
                    589:                   } else {
                    590:                       $result.= $texoptionlist;
                    591:                   }
1.50      sakharuk  592: 	      }
1.32      sakharuk  593: 	  }
1.101     albertel  594: 	  if ($Apache::lonhomework::type eq 'exam') {
1.165     foxr      595: 	      $result.='\vskip -1 mm\noindent';
                    596:               $result.= '\textbf{'. $internal_counter.'}. \vskip -3mm'.&bubbles(\@alphabet,\@opt).
                    597: 		                 ' \strut ';
1.101     albertel  598: 	      $internal_counter++;
                    599: 	  }
1.158     onken     600:           if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes'
1.164     onken     601:               && $Apache::inputtags::status[-1] eq 'CAN_ANSWER'
                    602:               && $Apache::lonhomework::type ne 'exam') {
1.158     onken     603:               $text =~ s/\\item//m;
1.152     onken     604:               $result .= " $optionlist ". &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
                    605:               $temp++;
                    606:           }
1.101     albertel  607: 	  $displayoptionintex=0;
1.62      albertel  608:       }
1.1       albertel  609:     }
1.62      albertel  610:   }
1.138     albertel  611: 
                    612:   if ($target eq 'web') {
1.143     albertel  613:       &Apache::response::setup_prior_tries_hash(\&Apache::rankresponse::format_prior_answer,
                    614: 						[\@whichopt,
                    615: 						 'submissiongrading']);
1.138     albertel  616:   }
                    617: 
1.32      sakharuk  618:   if ($target ne 'tex') {
1.62      albertel  619:       return $result.$break;
                    620:   } else {
1.32      sakharuk  621:       return $result;
1.22      albertel  622:   }
1.50      sakharuk  623: }
                    624: 
                    625: 
                    626: sub optionlist_correction {
1.107     sakharuk  627:     my ($TeXlayout,@options) = @_;
1.150     bisitz    628:     my $texoptionlist='\\item [] '.&mt('Choices:').' ';
1.107     sakharuk  629:     if ($TeXlayout eq 'vertical') {$texoptionlist='\\item []';}
1.101     albertel  630:     if (scalar(@options) > 0) {
                    631: 	foreach my $option (@options) {
                    632: 	    $texoptionlist.='{\bf '.
1.135     albertel  633: 		&Apache::lonxml::latex_special_symbols($option).
1.107     sakharuk  634: 		'}';
                    635: 	    if ($TeXlayout eq 'vertical') {
                    636: 		$texoptionlist.=' \vskip 0 mm ',
                    637: 	    } else {
1.115     sakharuk  638: 		$texoptionlist.=', ';
1.107     sakharuk  639: 	    }
1.101     albertel  640: 	}
1.116     albertel  641: 	$texoptionlist=~s/, $//;
1.107     sakharuk  642: 	if ($TeXlayout ne 'vertical') {$texoptionlist.='.';}
1.80      sakharuk  643:     } else {
1.107     sakharuk  644: 	if ($TeXlayout ne 'vertical') {$texoptionlist='\\item [] \\vskip -5 mm';}
1.80      sakharuk  645:     }
1.50      sakharuk  646:     return $texoptionlist;
1.58      sakharuk  647: }
                    648: 
                    649: 
                    650: sub webbubbles {
1.90      albertel  651:     my ($ropt,$ralphabet,$temp,$lastopt)=@_;
1.58      sakharuk  652:     my @opt=@$ropt; 
                    653:     my @alphabet=@$ralphabet;
                    654:     my $result='';
1.90      albertel  655:     my $number_of_bubbles = $#opt + 1;
                    656:     $result.= '<table border="1"><tr>';
                    657:     for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
                    658: 	my $checked='';
                    659: 	if ($lastopt eq $opt[$ind]) {
                    660: 	    $checked=' checked="on" ';
1.58      sakharuk  661: 	}
1.90      albertel  662: 	$result.='<td><input type="radio" name="HWVAL_'.
                    663: 	    $Apache::inputtags::response['-1'].':'.$temp.
1.111     albertel  664: 	    '" value="'.$opt[$ind].'" '.$checked.' />';
                    665: 	if ($alphabet[$ind]) {
                    666: 	    $result.=$alphabet[$ind].': ';
                    667: 	}
                    668: 	$result.=$opt[$ind].'</td>';
1.90      albertel  669:     }
                    670:     $result.='</tr></table>';
                    671:     return $result;
1.50      sakharuk  672: }
                    673: 
                    674: 
                    675: sub bubbles {
1.140     foxr      676:     my ($ralphabet,$ropt,$response, $max_width) = @_;
1.119     albertel  677:     my @alphabet = @$ralphabet;
1.50      sakharuk  678:     my @opt = @$ropt;
1.51      sakharuk  679:     my ($result,$head,$line) =('','','');
1.50      sakharuk  680:     my $number_of_bubbles = $#opt + 1;
1.51      sakharuk  681:     my $current_length = 0;
1.100     sakharuk  682:     my $textwidth;
1.141     albertel  683:     if (defined($max_width)) {
1.140     foxr      684: 	$textwidth=$max_width;
1.141     albertel  685: 	&Apache::lonxml::debug("Max width passed in: $max_width");
                    686:     } elsif ($env{'form.textwidth'} ne '') {
1.125     albertel  687: 	$env{'form.textwidth'}=~/(\d+)/;
1.100     sakharuk  688: 	$textwidth=$1;
1.141     albertel  689: 	&Apache::lonxml::debug("Max width from form: $textwidth");
1.100     sakharuk  690:     } else {
1.125     albertel  691: 	$env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
1.102     sakharuk  692: 	$textwidth=$1.'.'.$2;
1.141     albertel  693: 	&Apache::lonxml::debug("Max width defaults? $textwidth");
1.100     sakharuk  694:     }
1.141     albertel  695:     &Apache::lonxml::debug("Final maxwidth: $textwidth");
1.51      sakharuk  696:     for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
1.99      sakharuk  697: 	my $leftmargin;
1.101     albertel  698: 	$opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
1.119     albertel  699: 	if ($response eq 'rankresponse') {$opt[$ind]='Rank '.$opt[$ind];}
1.99      sakharuk  700: 	if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
1.140     foxr      701: 
1.102     sakharuk  702: 	$current_length += (length($opt[$ind])+length($alphabet[$ind])+4)*2;
1.99      sakharuk  703: 	if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
1.171     raeburn   704: 	    $line.='\hskip 4 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
1.51      sakharuk  705: 	    $head.='lr';
                    706: 	} else {
                    707: 	    $line=~s/\&\s*$//;
1.171     raeburn   708: 	    $result.='\vskip -1 mm\noindent\setlength{\tabcolsep}{2 mm}\renewcommand{\arraystretch}{1.25}\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm';
                    709: 	    $line = '\hskip 4 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';;
1.51      sakharuk  710: 	    $head ='lr';
                    711: 	    $current_length = (length($opt[$ind])+length($alphabet[$ind]))*2;
                    712: 	}
                    713: 
1.50      sakharuk  714:     }
                    715:     return $result;
1.1       albertel  716: }
                    717: 
1.22      albertel  718: 
1.2       albertel  719: sub start_conceptgroup {
1.22      albertel  720:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    721:   $Apache::optionresponse::conceptgroup=1;
1.44      albertel  722:   %Apache::response::conceptgroup=();
1.22      albertel  723:   my $result;
                    724:   if ($target eq 'edit') {
                    725:     $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
1.30      matthew   726:     $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
                    727:         &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.22      albertel  728:   }
                    729:   if ($target eq 'modified') {
                    730:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
                    731:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    732:   }
                    733:   return $result;
1.2       albertel  734: }
                    735: 
                    736: sub end_conceptgroup {
1.22      albertel  737:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    738:   $Apache::optionresponse::conceptgroup=0;
                    739:   my $result='';
1.93      albertel  740:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    741:       $target eq 'tex' || $target eq 'analyze') {
1.22      albertel  742:     #if not there aren't any foils to display and thus no question
1.93      albertel  743:       &Apache::response::pick_foil_for_concept($target,
                    744: 					       ['value','text','location'],
                    745: 					       \%Apache::hint::option,
                    746: 					       $parstack,$safeeval);
1.34      albertel  747:   } elsif ($target eq 'edit') {
1.22      albertel  748:     $result=&Apache::edit::end_table();
                    749:   }
                    750:   return $result;
1.2       albertel  751: }
                    752: 
1.16      albertel  753: sub insert_conceptgroup {
1.22      albertel  754:   my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
                    755:   return $result;
1.16      albertel  756: }
                    757: 
1.1       albertel  758: sub start_foil {
1.22      albertel  759:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    760:   my $result='';
1.34      albertel  761:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
1.105     albertel  762:       &Apache::lonxml::startredirection;
                    763:       if ($target eq 'analyze') {
                    764: 	  &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
                    765:       }
1.25      albertel  766:   } elsif ($target eq 'edit') {
1.22      albertel  767:     $result=&Apache::edit::tag_start($target,$token,"Foil");
                    768:     my $level='-2';
                    769:     if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
                    770:     my @opt;
                    771:     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
                    772:     $result.=&Apache::edit::text_arg('Name:','name',$token);
1.48      albertel  773:     $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
                    774: 					       ['unused',(@opt)],$token,'15');
                    775:     my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
                    776: 					     $safeeval,'-3');
                    777:     if ($randomize ne 'no') {
                    778: 	$result.=&Apache::edit::select_arg('Location:','location',
                    779: 					   ['random','top','bottom'],$token);
                    780:     }
1.30      matthew   781:     $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.25      albertel  782:   } elsif ($target eq 'modified') {
1.48      albertel  783:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
                    784: 						 'value','name','location');
1.22      albertel  785:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.32      sakharuk  786:   } 
1.22      albertel  787:   return $result;
1.1       albertel  788: }
                    789: 
                    790: sub end_foil {
1.22      albertel  791:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    792:   my $text ='';
                    793:   my $result = '';
1.88      albertel  794:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') { 
1.48      albertel  795:       $text=&Apache::lonxml::endredirection;
1.114     sakharuk  796:       if ($target eq 'tex') {$text=~s/\\strut\s*\\\\\s*\\strut/\\vskip 0 mm/;}
1.107     sakharuk  797:       if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;} 
1.32      sakharuk  798:   }
                    799:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' 
1.34      albertel  800:       || $target eq 'tex' || $target eq 'analyze') {
1.22      albertel  801:     my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
1.122     albertel  802:     if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
                    803: 	$text='\vskip 5mm $\triangleright$ '.$text;
                    804:     }
1.22      albertel  805:     if ($value ne 'unused') {
                    806:       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    807:       &Apache::lonxml::debug("Got a name of :$name:");
1.129     albertel  808:       if ($name eq "") {
1.151     bisitz    809: 	  &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
1.123     albertel  810: 	  $name=$Apache::lonxml::curdepth;
                    811:       }
1.22      albertel  812:       &Apache::lonxml::debug("Using a name of :$name:");
1.103     albertel  813:       if (defined($Apache::response::foilnames{$name})) {
1.151     bisitz    814: 	  &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",'<b><tt>'.$name.'</tt></b>'));
1.103     albertel  815:       }
1.104     albertel  816:       $Apache::response::foilnames{$name}++;
1.103     albertel  817:       my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
1.39      albertel  818:       if ( $Apache::optionresponse::conceptgroup
                    819: 	   && !&Apache::response::showallfoils() ) {
1.22      albertel  820: 	push @{ $Apache::response::conceptgroup{'names'} }, $name;
                    821: 	$Apache::response::conceptgroup{"$name.value"} = $value;
1.122     albertel  822: 	$Apache::response::conceptgroup{"$name.text"} = $text;
1.48      albertel  823: 	$Apache::response::conceptgroup{"$name.location"} = $location;
1.22      albertel  824:       } else {
                    825: 	push @{ $Apache::response::foilgroup{'names'} }, $name;
1.48      albertel  826: 	$Apache::response::foilgroup{"$name.value"} = $value;
1.122     albertel  827: 	$Apache::response::foilgroup{"$name.text"} = $text;
1.48      albertel  828: 	$Apache::response::foilgroup{"$name.location"} = $location;
1.22      albertel  829:       }
                    830:     }
                    831:   }
                    832:   if ($target eq 'edit') {
                    833:     $result.= &Apache::edit::tag_end($target,$token,'');
                    834:   }
                    835:   return $result;
1.1       albertel  836: }
                    837: 
1.112     sakharuk  838: sub start_drawoptionlist {
                    839:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.144     albertel  840:     if ($target !~ /^(?:meta|answer|modified|edit)$/) {
1.117     albertel  841: 	return $token->[4];
                    842:     }
1.112     sakharuk  843: }
                    844: 
                    845: sub end_drawoptionlist {
                    846:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.144     albertel  847:     if ($target !~ /^(?:meta|answer|modified|edit)$/) {
1.117     albertel  848: 	return $token->[2];
                    849:     }
1.112     sakharuk  850: }
                    851: 
1.7       albertel  852: sub insert_foil {
1.144     albertel  853:     return '
1.15      albertel  854: <foil name="" value="unused">
1.14      albertel  855: <startouttext />
                    856: <endouttext />
1.7       albertel  857: </foil>';
                    858: }
1.144     albertel  859: 
                    860: sub insert_drawoptionlist {
                    861:     return '<drawoptionlist />';
                    862: }
1.1       albertel  863: 1;
                    864: __END__
                    865:  
1.156     jms       866: =head1 NAME
                    867: 
                    868: Apache::optionresponse.pm;
                    869: 
                    870: =head1 SYNOPSIS
                    871: 
                    872: Handles tags associated with showing a list of
                    873: options.
                    874: 
                    875: This is part of the LearningOnline Network with CAPA project
                    876: described at http://www.lon-capa.org.
                    877: 
                    878: =head1 HANDLER SUBROUTINE
                    879: 
                    880: start_optionresponse()
                    881: 
                    882: =head1 OTHER SUBROUTINES
                    883: 
                    884: =over
                    885: 
                    886: =item end_optionresponse()
                    887: 
                    888: =item start_foilgroup()
                    889: 
                    890: =item end_foilgroup()
                    891: 
                    892: =item getfoilcounts()
                    893: 
                    894: =item displayanswers()
                    895: 
                    896: =item check_for_invalid()
                    897: 
                    898: =item displayfoils()
                    899: 
                    900: =item optionlist_correction()
                    901: 
                    902: =item webbubbles()
                    903: 
                    904: =item bubbles()
                    905: 
                    906: =item start_conceptgroup()
                    907: 
                    908: =item end_conceptgroup()
                    909: 
                    910: =item insert_conceptgroup()
                    911: 
                    912: =item start_foil()
                    913: 
                    914: =item end_foil()
                    915: 
                    916: =item start_drawoptionlist()
                    917: 
                    918: =item end_drawoptionlist()
                    919: 
                    920: =item insert_foil()
                    921: 
                    922: =item insert_drawoptionlist()
                    923: 
                    924: =back
                    925: 
1.157     raeburn   926: =cut

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