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

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

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