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

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

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