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

1.46      sakharuk    1: # LearningOnline Network with CAPA
1.22      albertel    2: # option list style responses
1.27      albertel    3: #
1.103   ! albertel    4: # $Id: optionresponse.pm,v 1.102 2004/02/19 21:55:54 sakharuk 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.1       albertel   28: package Apache::optionresponse;
                     29: use strict;
1.103   ! albertel   30: use Apache::response();
        !            31: use Apache::lonlocal;
1.1       albertel   32: 
1.31      harris41   33: BEGIN {
1.1       albertel   34:   &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
                     35: }
                     36: 
                     37: sub start_optionresponse {
1.22      albertel   38:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     39:   my $result='';
1.29      albertel   40:   #when in a option response use these
1.22      albertel   41:   &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
                     42:   push (@Apache::lonxml::namespace,'optionresponse');
                     43:   my $id = &Apache::response::start_response($parstack,$safeeval);
1.57      albertel   44:   %Apache::hint::option=();
1.103   ! albertel   45:   undef(%Apache::response::foilnames);
1.22      albertel   46:   if ($target eq 'edit') {
1.23      albertel   47:     $result.=&Apache::edit::start_table($token).
1.98      www        48: 	"<tr><td>Multiple Option Response Question ".
                     49: 	&Apache::loncommon::help_open_topic('Option_Response_Problems')."</td><td>Delete:".
1.23      albertel   50: 	&Apache::edit::deletelist($target,$token)
1.30      matthew    51: 	."</td><td>&nbsp;".
                     52:         &Apache::edit::end_row().
                     53:         &Apache::edit::start_spanning_row().
                     54:         "\n";
1.48      albertel   55:     $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max',
                     56: 				     $token,'4').
                     57:         &Apache::edit::select_arg('Randomize Foil Order','randomize',
                     58: 				  ['yes','no'],$token).
                     59:         &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.34      albertel   60:   } elsif ($target eq 'modified') {
1.23      albertel   61:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.48      albertel   62: 						 $safeeval,'max','randomize');
1.22      albertel   63:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.34      albertel   64:   } elsif ($target eq 'meta') {
1.23      albertel   65:     $result=&Apache::response::meta_package_write('optionresponse');
1.34      albertel   66:   } elsif ($target eq 'analyze') {
1.93      albertel   67:     my $part_id="$Apache::inputtags::part.$id";
1.34      albertel   68:     push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.22      albertel   69:   }
                     70:   return $result;
1.1       albertel   71: }
                     72: 
                     73: sub end_optionresponse {
1.22      albertel   74:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     75:   &Apache::response::end_response;
                     76:   pop @Apache::lonxml::namespace;
1.29      albertel   77:   &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
1.22      albertel   78:   my $result;
                     79:   if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
1.103   ! albertel   80:   undef(%Apache::response::foilnames);
1.22      albertel   81:   return $result;
1.1       albertel   82: }
                     83: 
1.44      albertel   84: %Apache::response::foilgroup=();
1.1       albertel   85: sub start_foilgroup {
1.22      albertel   86:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     87: 
                     88:   my $result='';
1.44      albertel   89:   %Apache::response::foilgroup=();
1.22      albertel   90:   $Apache::optionresponse::conceptgroup=0;
                     91:   &Apache::response::setrandomnumber();
                     92:   if ($target eq 'edit') {
                     93:     my $optionlist="<option></option>\n";
                     94:     my $option;
                     95:     my @opt;
                     96:     eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval);
                     97:     my $count=1;
                     98:     foreach $option (@opt) {
                     99:       $optionlist.="<option value=\"$count\">$option</option>\n";
                    100:       $count++;
                    101:     }
                    102:     my $insertlist=&Apache::edit::insertlist($target,$token);
                    103:     $result.=&Apache::edit::start_table($token);
                    104:     $result.= (<<ENDTABLE);
                    105:       <tr><td>Select Options</td>
1.13      albertel  106:         <td>
                    107: 	  Add new Option: <input type="text" name="$Apache::lonxml::curdepth.options" />
                    108:         </td>
                    109:         <td>Delete an Option:
                    110: 	  <select name="$Apache::lonxml::curdepth.deleteopt">$optionlist</select>
                    111: ENDTABLE
1.30      matthew   112:     $result.= &Apache::edit::end_row();
                    113:     $result.= &Apache::edit::start_spanning_row();
                    114:     $result.= $insertlist.'<br />';
1.22      albertel  115:   }
                    116:   if ($target eq 'modified') {
                    117:     my @options;
                    118:     my $optchanged=0;
                    119:     eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
                    120:     if ($ENV{"form.$Apache::lonxml::curdepth.deleteopt"}) {
                    121:       my $delopt=$ENV{"form.$Apache::lonxml::curdepth.deleteopt"};
                    122:       &Apache::lonxml::debug("Deleting :$delopt:");
                    123:       splice(@options,$delopt-1,1);
                    124:       $optchanged=1;
                    125:     }
                    126:     if ($ENV{"form.$Apache::lonxml::curdepth.options"}) {
                    127:       my $newopt = $ENV{"form.$Apache::lonxml::curdepth.options"};
                    128:       if ($options[0]) {
                    129: 	push(@options,$newopt);
                    130:       } else {
                    131: 	$options[0]=$newopt;
                    132:       }
                    133:       $optchanged=1;
                    134:     }
                    135:     if ($optchanged) {
                    136:       $result = "<foilgroup options=\"(";
                    137:       foreach my $option (@options) {
1.41      albertel  138: 	$option=~s/\'/\\\'/g;
1.22      albertel  139: 	&Apache::lonxml::debug("adding option :$option:");
                    140: 	$result .="'".$option."',";
                    141:       }
                    142:       chop $result;
                    143:       $result.=')">';
                    144:     } # else nothing changed so just use the default mechanism
                    145:   }
1.68      sakharuk  146:   if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.42      sakharuk  147:       $result .= ' \begin{enumerate} ';
                    148:   }
1.22      albertel  149:   return $result;
1.1       albertel  150: }
                    151: 
                    152: sub end_foilgroup {
1.22      albertel  153:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    154:   
                    155:   my $result;
1.94      albertel  156:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
                    157:       $target eq 'tex' || $target eq 'analyze') {
1.81      sakharuk  158:     my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
1.22      albertel  159:     my $name;
                    160:     my @opt;
                    161:     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.81      sakharuk  162:     if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
1.22      albertel  163:     &Apache::lonxml::debug("Options are $#opt");
1.48      albertel  164:     my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
                    165:     my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
                    166: 					       $safeeval,'-2');
1.32      sakharuk  167:     if ($target eq 'web' || $target eq 'tex') {
1.48      albertel  168:       $result.=&displayfoils($target,$max,$randomize,@opt);
1.25      albertel  169:     } elsif ( $target eq 'answer') {
1.48      albertel  170:       $result.=&displayanswers($max,$randomize,@opt);
1.34      albertel  171:     } elsif ( $target eq 'analyze') {
1.93      albertel  172: 	my @shown = &whichfoils($max,$randomize);
1.94      albertel  173: 	&Apache::response::analyze_store_foilgroup(\@shown,
                    174: 						  ['text','value','location']);
1.93      albertel  175: 	my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
                    176: 	push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
1.22      albertel  177:     } elsif ( $target eq 'grade') {
                    178:       if ( defined $ENV{'form.submitted'}) {
1.48      albertel  179: 	my @whichopt = &whichfoils($max,$randomize);
1.22      albertel  180: 	my $temp=1;my $name;
1.26      albertel  181: 	my %responsehash;
1.57      albertel  182: 	my %grade;
1.22      albertel  183: 	my $right=0;
                    184: 	my $wrong=0;
                    185: 	my $ignored=0;
                    186: 	foreach $name (@whichopt) {
1.74      albertel  187: 	  my $response=&Apache::response::getresponse($temp);
                    188: 	  if ($ENV{'form.submitted'} eq 'scantron') {
                    189: 	      $response = $opt[$response];
                    190: 	  }
1.22      albertel  191: 	  if ( $response =~ /[^\s]/) {
1.96      albertel  192: 	    $responsehash{$name}=$response;
1.22      albertel  193: 	    my $value=$Apache::response::foilgroup{$name.'.value'};
1.34      albertel  194: 	    &Apache::lonxml::debug("submitted a $response for $value<br />\n");
1.57      albertel  195: 	    if ($value eq $response) {
                    196: 		$grade{$name}='1'; $right++;
                    197: 	    } else {
                    198: 		$grade{$name}='0'; $wrong++;
                    199: 	    }
1.22      albertel  200: 	  } else {
                    201: 	    $ignored++;
                    202: 	  }
                    203: 	  $temp++;
                    204: 	}
1.28      albertel  205: 	my $part=$Apache::inputtags::part;
1.22      albertel  206: 	my $id = $Apache::inputtags::response['-1'];
1.28      albertel  207: 	my $responsestr=&Apache::lonnet::hash2str(%responsehash);
1.57      albertel  208: 	my $gradestr   =&Apache::lonnet::hash2str(%grade);
1.28      albertel  209: 	my %previous=&Apache::response::check_for_previous($responsestr,
                    210: 							   $part,$id);
1.22      albertel  211: 	&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
1.75      albertel  212: 	$Apache::lonhomework::results{"resource.$part.$id.submission"}=
                    213: 	    $responsestr;
                    214: 	$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
                    215: 	
                    216: 	if (!$Apache::lonhomework::scantronmode) {
                    217: 	    my $ad;
                    218: 	    if ($wrong==0 && $ignored==0) {
                    219: 		$ad='EXACT_ANS';
                    220: 	    } elsif ($wrong==0 && $right==0) {
                    221: 		#nothing submitted
                    222: 	    } else {
                    223: 		if ($ignored==0) {
                    224: 		    $ad='INCORRECT';
                    225: 		} else {
                    226: 		    $ad='MISSING_ANSWER';
                    227: 		}
                    228: 	    }
                    229: 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
                    230: 	    &Apache::response::handle_previous(\%previous,$ad);
1.22      albertel  231: 	} else {
1.75      albertel  232: 	    my $ad;
                    233: 	    if ($wrong==0 && $right==0) {
                    234: 		#nothing submitted
                    235: 	    } else {
                    236: 		$ad='ASSIGNED_SCORE';
                    237: 	    }
                    238: 	    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
                    239: 	    $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
                    240: 		$right/(scalar(@whichopt));
1.76      albertel  241: 	    $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
                    242: 		scalar(@whichopt);
1.1       albertel  243: 	}
1.22      albertel  244:       }
1.1       albertel  245:     }
1.92      sakharuk  246:     &Apache::lonxml::increment_counter(&getfoilcounts($max));
1.25      albertel  247:   } elsif ($target eq 'edit') {
1.22      albertel  248:     $result.=&Apache::edit::end_table();
1.74      albertel  249:   }
                    250:   if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
                    251:       $result .= '\end{enumerate}';
                    252:   }
1.22      albertel  253:   return $result;
1.1       albertel  254: }
                    255: 
                    256: sub getfoilcounts {
1.48      albertel  257:   my ($max)=@_;
1.22      albertel  258:   # +1 since instructors will count from 1
                    259:   my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
1.39      albertel  260:   if (&Apache::response::showallfoils()) { $max=$count; }
1.48      albertel  261:   if ($count>$max) { $count=$max } 
                    262:   &Apache::lonxml::debug("Count is $count from $max");
                    263:   return $count;
1.1       albertel  264: }
                    265: 
                    266: sub whichfoils {
1.77      albertel  267:     my ($max,$randomize)=@_;
                    268:     return &Apache::response::whichorder($max,$randomize,
                    269: 					 &Apache::response::showallfoils(),
                    270: 					 \%Apache::response::foilgroup);
1.1       albertel  271: }
                    272: 
1.25      albertel  273: sub displayanswers {
1.48      albertel  274:   my ($max,$randomize,@opt)=@_;
1.67      albertel  275:   if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
1.25      albertel  276:   my @names = @{ $Apache::response::foilgroup{'names'} };
1.48      albertel  277:   my @whichopt = &whichfoils($max,$randomize);
1.25      albertel  278:   my $result=&Apache::response::answer_header('optionresponse');
                    279:   foreach my $name (@whichopt) {
                    280:     $result.=&Apache::response::answer_part('optionresponse',
                    281: 		     $Apache::response::foilgroup{$name.'.value'})
                    282:   }
                    283:   $result.=&Apache::response::answer_footer('optionresponse');
                    284:   return $result;
                    285: }
                    286: 
1.1       albertel  287: sub displayfoils {
1.48      albertel  288:   my ($target,$max,$randomize,@opt)=@_;
1.67      albertel  289:   if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
1.22      albertel  290:   my @names = @{ $Apache::response::foilgroup{'names'} };
                    291:   my @truelist;
                    292:   my @falselist;
1.79      sakharuk  293:   my $result;  
1.22      albertel  294:   my $name;
1.101     albertel  295:   my $displayoptionintex=1;
1.72      sakharuk  296:   my @alphabet = ('A'..'Z');
1.48      albertel  297:   my @whichopt = &whichfoils($max,$randomize);
1.28      albertel  298:   my $part=$Apache::inputtags::part;
                    299:   my $id=$Apache::inputtags::response[-1];
1.62      albertel  300:   my $break;
1.65      albertel  301:   my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
1.86      albertel  302:   if ( ($target ne 'tex') &&
                    303:        &Apache::response::show_answer() ) {
1.90      albertel  304:     my $temp=1;
1.22      albertel  305:     foreach $name (@whichopt) {
1.62      albertel  306: 	my $text=$Apache::response::foilgroup{$name.'.text'};
1.90      albertel  307: 	my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
                    308: 	my $lastopt=$lastresponse{$name};
1.101     albertel  309: 	if ($text!~/^\s*$/) { $break='<br />'; }
1.62      albertel  310: 	$result.=$break;
                    311: 	if ($target eq 'web') {
                    312: 	    my $value=$Apache::response::foilgroup{$name.'.value'};
                    313: 	    if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
                    314: 		if ($text=~/^\s*$/) {
                    315: 		    $text=$value.$text;
                    316: 		} else {
                    317: 		    $text=$value.': '.$text;
                    318: 		}
1.95      albertel  319: 	    } else {
                    320: 		$text='&#149;'.$text;
1.62      albertel  321: 	    }
                    322: 	    $result.=$text."\n";
1.32      sakharuk  323:       }
1.58      sakharuk  324:       if ($Apache::lonhomework::type eq 'exam') {
1.90      albertel  325: 	  $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
1.58      sakharuk  326:       }
1.90      albertel  327:       $temp++;
1.22      albertel  328:     }
                    329:   } else {
                    330:     my $temp=1;
1.28      albertel  331:     my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
1.79      sakharuk  332:     my $internal_counter=$Apache::lonxml::counter;
1.22      albertel  333:     foreach $name (@whichopt) {
1.62      albertel  334:       my $text=$Apache::response::foilgroup{$name.'.text'};
                    335:       if ($text!~/^\s*$/) {
                    336: 	  if ($target eq 'tex') {
                    337: 	      $break='\vskip 0 mm ';
                    338: 	  } elsif ($target eq 'web') {
                    339: 	      $break='<br />';
                    340: 	  }
                    341:       }
1.28      albertel  342:       my $lastopt=$lastresponse{$name};
                    343:       my $optionlist="<option></option>\n";
                    344:       my $option;
                    345:       foreach $option (@opt) {
                    346: 	if ($option eq $lastopt) {
                    347: 	  $optionlist.="<option selected=\"on\">$option</option>\n";
                    348: 	} else {
                    349: 	  $optionlist.="<option>$option</option>\n";
                    350: 	}
                    351:       }
1.32      sakharuk  352:       if ($target ne 'tex') {
1.72      sakharuk  353: 	  if ($Apache::lonhomework::type ne 'exam') {
1.101     albertel  354: 	      $optionlist='<select name="HWVAL_'.
                    355: 		  $Apache::inputtags::response['-1'].':'.$temp.'">'.
1.59      albertel  356: 		  $optionlist."</select>\n";
1.101     albertel  357: 	  } else {
                    358: 	      $optionlist='<u>'.('&nbsp;'x10).'</u>';
1.72      sakharuk  359: 	  }
1.101     albertel  360: 	  if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
                    361: 	      if ($Apache::lonhomework::type ne 'exam') {
                    362: 		  $text='&#149;'.$text;
                    363: 	      }
1.95      albertel  364: 	  } else {
1.101     albertel  365: 	      if ($Apache::lonhomework::type ne 'exam') {
                    366: 		  $text=$optionlist.$text;
                    367: 	      }
1.59      albertel  368: 	  }
1.62      albertel  369: 	  $result.=$break.$text."\n";
1.49      sakharuk  370: 	  if ($Apache::lonhomework::type eq 'exam') {
1.101     albertel  371: 	      $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
1.49      sakharuk  372: 	  }
1.32      sakharuk  373: 	  $temp++;
                    374:       } else {
1.101     albertel  375: 	  my $texoptionlist='';
                    376: 	  if ($displayoptionintex &&
                    377: 	      $Apache::lonhomework::type ne 'exam') {
                    378: 	      $texoptionlist = &optionlist_correction(@opt);
                    379: 	  }
                    380: 	  if ($text=~/<drawoptionlist\s*\/>/) {
                    381: 	      $text=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
                    382: 	  }
                    383: 
                    384: 	  if ($text=~m/\\item /) {
1.50      sakharuk  385: 	      if ($Apache::lonhomework::type eq 'exam') {
1.101     albertel  386: 	          $text=~s/\\item/\\vskip 2 mm/;
1.50      sakharuk  387: 	      }
1.101     albertel  388: 	      $result.= $texoptionlist.$text;
1.32      sakharuk  389: 	  } else {
1.101     albertel  390: 	      if ($Apache::lonhomework::type eq 'exam') {
                    391: 		  $result.= $texoptionlist.'  '.$text;
1.46      sakharuk  392: 	      } else {
1.101     albertel  393: 		  $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
1.50      sakharuk  394: 	      }
1.32      sakharuk  395: 	  }
1.101     albertel  396: 	  if ($Apache::lonhomework::type eq 'exam') {
                    397: 	      $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.
                    398: 		  $internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).
                    399: 		  '\end{enumerate} \vskip -8 mm \strut ';
                    400: 	      $internal_counter++;
                    401: 	  }
                    402: 	  $displayoptionintex=0;
1.62      albertel  403:       }
1.1       albertel  404:     }
1.62      albertel  405:   }
1.32      sakharuk  406:   if ($target ne 'tex') {
1.62      albertel  407:       return $result.$break;
                    408:   } else {
1.32      sakharuk  409:       return $result;
1.22      albertel  410:   }
1.50      sakharuk  411: }
                    412: 
                    413: 
                    414: sub optionlist_correction {
1.101     albertel  415:     my @options = @_;
                    416:     my $texoptionlist='\\item [] Choices: ';
                    417:     if (scalar(@options) > 0) {
                    418: 	foreach my $option (@options) {
                    419: 	    $texoptionlist.='{\bf '.
                    420: 		&Apache::lonxml::latex_special_symbols($option).
                    421: 		'},';
                    422: 	}
                    423: 	chop($texoptionlist);
                    424: 	$texoptionlist.='.';
1.80      sakharuk  425:     } else {
1.101     albertel  426: 	$texoptionlist='\\item [] \\vskip -5 mm';
1.80      sakharuk  427:     }
1.50      sakharuk  428:     return $texoptionlist;
1.58      sakharuk  429: }
                    430: 
                    431: 
                    432: sub webbubbles {
1.90      albertel  433:     my ($ropt,$ralphabet,$temp,$lastopt)=@_;
1.58      sakharuk  434:     my @opt=@$ropt; 
                    435:     my @alphabet=@$ralphabet;
                    436:     my $result='';
1.90      albertel  437:     my $number_of_bubbles = $#opt + 1;
                    438:     $result.= '<table border="1"><tr>';
                    439:     for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
                    440: 	my $checked='';
                    441: 	if ($lastopt eq $opt[$ind]) {
                    442: 	    $checked=' checked="on" ';
1.58      sakharuk  443: 	}
1.90      albertel  444: 	$result.='<td><input type="radio" name="HWVAL_'.
                    445: 	    $Apache::inputtags::response['-1'].':'.$temp.
                    446: 	    '" value="'.$opt[$ind].'" '.$checked.' />'.$alphabet[$ind].': '.
                    447: 	    $opt[$ind].'</td>';
                    448:     }
                    449:     $result.='</tr></table>';
                    450:     return $result;
1.50      sakharuk  451: }
                    452: 
                    453: 
                    454: sub bubbles {
                    455:     my ($ralphabit,$ropt) = @_;
                    456:     my @alphabet = @$ralphabit;
                    457:     my @opt = @$ropt;
1.51      sakharuk  458:     my ($result,$head,$line) =('','','');
1.50      sakharuk  459:     my $number_of_bubbles = $#opt + 1;
1.51      sakharuk  460:     my $current_length = 0;
1.100     sakharuk  461:     my $textwidth;
                    462:     if ($ENV{'form.textwidth'} ne '') {
                    463: 	$ENV{'form.textwidth'}=~/(\d+)/;
                    464: 	$textwidth=$1;
                    465:     } else {
1.102     sakharuk  466: 	$ENV{'textwidth'}=~/(\d*)\.?(\d*)/;
                    467: 	$textwidth=$1.'.'.$2;
1.100     sakharuk  468:     }
1.51      sakharuk  469:     for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
1.99      sakharuk  470: 	my $leftmargin;
1.101     albertel  471: 	$opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
1.99      sakharuk  472: 	if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
1.102     sakharuk  473: 	$current_length += (length($opt[$ind])+length($alphabet[$ind])+4)*2;
1.99      sakharuk  474: 	if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
1.51      sakharuk  475: 	    $line.='\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
                    476: 	    $head.='lr';
                    477: 	} else {
                    478: 	    $line=~s/\&\s*$//;
1.99      sakharuk  479: 	    $result.='\vskip -2 mm\noindent\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}';
1.51      sakharuk  480: 	    $line = '\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';;
                    481: 	    $head ='lr';
                    482: 	    $current_length = (length($opt[$ind])+length($alphabet[$ind]))*2;
                    483: 	}
                    484: 
1.50      sakharuk  485:     }
                    486:     return $result;
1.1       albertel  487: }
                    488: 
1.22      albertel  489: 
1.2       albertel  490: sub start_conceptgroup {
1.22      albertel  491:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    492:   $Apache::optionresponse::conceptgroup=1;
1.44      albertel  493:   %Apache::response::conceptgroup=();
1.22      albertel  494:   my $result;
                    495:   if ($target eq 'edit') {
                    496:     $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
1.30      matthew   497:     $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
                    498:         &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.22      albertel  499:   }
                    500:   if ($target eq 'modified') {
                    501:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
                    502:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    503:   }
                    504:   return $result;
1.2       albertel  505: }
                    506: 
                    507: sub end_conceptgroup {
1.22      albertel  508:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    509:   $Apache::optionresponse::conceptgroup=0;
                    510:   my $result='';
1.93      albertel  511:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    512:       $target eq 'tex' || $target eq 'analyze') {
1.22      albertel  513:     #if not there aren't any foils to display and thus no question
1.93      albertel  514:       &Apache::response::pick_foil_for_concept($target,
                    515: 					       ['value','text','location'],
                    516: 					       \%Apache::hint::option,
                    517: 					       $parstack,$safeeval);
1.34      albertel  518:   } elsif ($target eq 'edit') {
1.22      albertel  519:     $result=&Apache::edit::end_table();
                    520:   }
                    521:   return $result;
1.2       albertel  522: }
                    523: 
1.16      albertel  524: sub insert_conceptgroup {
1.22      albertel  525:   my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
                    526:   return $result;
1.16      albertel  527: }
                    528: 
1.1       albertel  529: sub start_foil {
1.22      albertel  530:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    531:   my $result='';
1.34      albertel  532:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
1.25      albertel  533:     &Apache::lonxml::startredirection;
                    534:   } elsif ($target eq 'edit') {
1.22      albertel  535:     $result=&Apache::edit::tag_start($target,$token,"Foil");
                    536:     my $level='-2';
                    537:     if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
                    538:     my @opt;
                    539:     eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
                    540:     $result.=&Apache::edit::text_arg('Name:','name',$token);
1.48      albertel  541:     $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
                    542: 					       ['unused',(@opt)],$token,'15');
                    543:     my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
                    544: 					     $safeeval,'-3');
                    545:     if ($randomize ne 'no') {
                    546: 	$result.=&Apache::edit::select_arg('Location:','location',
                    547: 					   ['random','top','bottom'],$token);
                    548:     }
1.30      matthew   549:     $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.25      albertel  550:   } elsif ($target eq 'modified') {
1.48      albertel  551:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
                    552: 						 'value','name','location');
1.22      albertel  553:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.32      sakharuk  554:   } 
1.22      albertel  555:   return $result;
1.1       albertel  556: }
                    557: 
                    558: sub end_foil {
1.22      albertel  559:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    560:   my $text ='';
                    561:   my $result = '';
1.88      albertel  562:   if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') { 
1.48      albertel  563:       $text=&Apache::lonxml::endredirection;
1.68      sakharuk  564:       if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') { $text = '\vspace*{-2 mm}\item '.$text; }
1.32      sakharuk  565:   }
                    566:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' 
1.34      albertel  567:       || $target eq 'tex' || $target eq 'analyze') {
1.22      albertel  568:     my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
                    569:     if ($value ne 'unused') {
                    570:       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.103   ! albertel  571:       $Apache::response::foilnames{$name}++;
1.22      albertel  572:       &Apache::lonxml::debug("Got a name of :$name:");
                    573:       if (!$name) { $name=$Apache::lonxml::curdepth; }
                    574:       &Apache::lonxml::debug("Using a name of :$name:");
1.103   ! albertel  575:       if (defined($Apache::response::foilnames{$name})) {
        !           576: 	  &Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
        !           577:       }
        !           578:       my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
1.39      albertel  579:       if ( $Apache::optionresponse::conceptgroup
                    580: 	   && !&Apache::response::showallfoils() ) {
1.22      albertel  581: 	push @{ $Apache::response::conceptgroup{'names'} }, $name;
                    582: 	$Apache::response::conceptgroup{"$name.value"} = $value;
1.70      albertel  583: 	if ($target eq 'tex' and $Apache::lonhomework::type eq 'exam') {
1.69      sakharuk  584: 	    $Apache::response::conceptgroup{"$name.text"} = '\vskip 4 mm $\triangleright$ '.$text;
                    585: 	} else {
1.87      sakharuk  586: 	    $Apache::response::conceptgroup{"$name.text"} = $text;
1.69      sakharuk  587: 	}
1.48      albertel  588: 	$Apache::response::conceptgroup{"$name.location"} = $location;
1.22      albertel  589:       } else {
                    590: 	push @{ $Apache::response::foilgroup{'names'} }, $name;
1.48      albertel  591: 	$Apache::response::foilgroup{"$name.value"} = $value;
1.78      sakharuk  592: 	if ($target eq 'tex' and $Apache::lonhomework::type eq 'exam') {
1.69      sakharuk  593: 	    $Apache::response::foilgroup{"$name.text"} = '\vskip 5 mm $\triangleright$ '.$text;
                    594: 	} else {
1.87      sakharuk  595: 	    $Apache::response::foilgroup{"$name.text"} = $text;
1.69      sakharuk  596: 	}
1.48      albertel  597: 	$Apache::response::foilgroup{"$name.location"} = $location;
1.22      albertel  598:       }
                    599:     }
                    600:   }
                    601:   if ($target eq 'edit') {
                    602:     $result.= &Apache::edit::tag_end($target,$token,'');
                    603:   }
                    604:   return $result;
1.1       albertel  605: }
                    606: 
1.7       albertel  607: sub insert_foil {
1.22      albertel  608:   return '
1.15      albertel  609: <foil name="" value="unused">
1.14      albertel  610: <startouttext />
                    611: <endouttext />
1.7       albertel  612: </foil>';
                    613: }
1.1       albertel  614: 1;
                    615: __END__
                    616:  

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