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

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

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