Diff for /loncom/homework/optionresponse.pm between versions 1.100 and 1.101

version 1.100, 2004/02/13 21:01:11 version 1.101, 2004/02/19 19:06:35
Line 289  sub displayfoils { Line 289  sub displayfoils {
   my @falselist;    my @falselist;
   my $result;      my $result;  
   my $name;    my $name;
   my $displayoptionintex=0;    my $displayoptionintex=1;
   my @alphabet = ('A'..'Z');    my @alphabet = ('A'..'Z');
   my @whichopt = &whichfoils($max,$randomize);    my @whichopt = &whichfoils($max,$randomize);
   my $part=$Apache::inputtags::part;    my $part=$Apache::inputtags::part;
Line 303  sub displayfoils { Line 303  sub displayfoils {
  my $text=$Apache::response::foilgroup{$name.'.text'};   my $text=$Apache::response::foilgroup{$name.'.text'};
  my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});   my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
  my $lastopt=$lastresponse{$name};   my $lastopt=$lastresponse{$name};
  if ($text!~/^\s*$/) {   if ($text!~/^\s*$/) { $break='<br />'; }
     if ($target eq 'tex') {  
  $break='\vskip 0 mm ';  
     } elsif ($target eq 'web') {  
  $break='<br />';  
     }  
  }  
  $result.=$break;   $result.=$break;
  if ($target eq 'web') {   if ($target eq 'web') {
     my $value=$Apache::response::foilgroup{$name.'.value'};      my $value=$Apache::response::foilgroup{$name.'.value'};
Line 323  sub displayfoils { Line 317  sub displayfoils {
  $text='&#149;'.$text;   $text='&#149;'.$text;
     }      }
     $result.=$text."\n";      $result.=$text."\n";
       } elsif ($target eq 'tex') {  
   $Apache::response::foilgroup{$name.'.text'}=~s/\\item//;  
   if ($max>1) {$result .='\item ';}  
    $result .=' \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'.  
       ":".$Apache::response::foilgroup{$name.'.text'}."\n";  
       }        }
       if ($Apache::lonhomework::type eq 'exam') {        if ($Apache::lonhomework::type eq 'exam') {
  if ($target ne 'tex') {  
   $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);    $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
         } else {  
   $result.=&bubbles(\@alphabet,\@opt);  
         }  
       }        }
       $temp++;        $temp++;
     }      }
Line 363  sub displayfoils { Line 348  sub displayfoils {
       }        }
       if ($target ne 'tex') {        if ($target ne 'tex') {
   if ($Apache::lonhomework::type ne 'exam') {    if ($Apache::lonhomework::type ne 'exam') {
     $optionlist='<select name="HWVAL_'.        $optionlist='<select name="HWVAL_'.
       $Apache::inputtags::response['-1'].':'.$temp.'">'.    $Apache::inputtags::response['-1'].':'.$temp.'">'.
   $optionlist."</select>\n";    $optionlist."</select>\n";
     } else {
         $optionlist='<u>'.('&nbsp;'x10).'</u>';
   }    }
   my $text=$Apache::response::foilgroup{$name.'.text'};    if ($text=~s|<drawoptionlist\s*/>|$optionlist|) {
   if (!($text=~s|<drawoptionlist\s*/>|$optionlist|) && $Apache::lonhomework::type ne 'exam') {        if ($Apache::lonhomework::type ne 'exam') {
       $text=$optionlist.$text;    $text='&#149;'.$text;
         }
   } else {    } else {
       $text='&#149;'.$text;        if ($Apache::lonhomework::type ne 'exam') {
     $text=$optionlist.$text;
         }
   }    }
   $result.=$break.$text."\n";    $result.=$break.$text."\n";
   if ($Apache::lonhomework::type eq 'exam') {    if ($Apache::lonhomework::type eq 'exam') {
     $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);        $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
   }    }
   $temp++;    $temp++;
       } else {        } else {
           my $texoptionlist = &optionlist_correction($optionlist);    my $texoptionlist='';
   if ($displayoptionintex == 0) {    if ($displayoptionintex &&
       if ($Apache::lonhomework::type eq 'exam') {$texoptionlist='';} #if exam we do not need to show optionlist        $Apache::lonhomework::type ne 'exam') {
       if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {        $texoptionlist = &optionlist_correction(@opt);
  if ($Apache::lonhomework::type eq 'exam') {    }
           $Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\vskip 2 mm/;    if ($text=~/<drawoptionlist\s*\/>/) {
         }        $text=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
         if ($Apache::response::foilgroup{$name.'.text'}=~/<drawoptionlist\s*\/>/) {    }
           $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;  
         }    if ($text=~m/\\item /) {
  $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'};  
       } else {  
   if ($Apache::lonhomework::type eq 'exam') {  
       $result.= $texoptionlist.'  '.$Apache::response::foilgroup{$name.'.text'};  
   } else {  
       $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};  
   }  
       }  
       if ($Apache::lonhomework::type eq 'exam') {        if ($Apache::lonhomework::type eq 'exam') {
   $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).'\end{enumerate} \vskip -9 mm \strut ';            $text=~s/\\item/\\vskip 2 mm/;
   $internal_counter++;  
       }        }
       $displayoptionintex=1;        $result.= $texoptionlist.$text;
   } else {    } else {
       if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {  
   if ($Apache::lonhomework::type eq 'exam') {  
       $Apache::response::foilgroup{$name.'.text'}=~s/\\item//;  
   }  
         if ($Apache::response::foilgroup{$name.'.text'}=~/<drawoptionlist\s*\/>/) {  
           $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;  
         }  
  $result.= $Apache::response::foilgroup{$name.'.text'};  
       } else {  
   if ($Apache::lonhomework::type eq 'exam') {  
       $result.= '  '.$Apache::response::foilgroup{$name.'.text'};  
   } else {  
       $result.= '\item '.$Apache::response::foilgroup{$name.'.text'};  
   }  
       }  
       if ($Apache::lonhomework::type eq 'exam') {        if ($Apache::lonhomework::type eq 'exam') {
   $result.='\vskip -1 mm \noindent\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).'\end{enumerate} \vskip -9 mm \strut ';    $result.= $texoptionlist.'  '.$text;
   $internal_counter++;        } else {
     $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$text;
       }        }
   }    }
     if ($Apache::lonhomework::type eq 'exam') {
         $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.
     $internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).
     '\end{enumerate} \vskip -8 mm \strut ';
         $internal_counter++;
     }
     $displayoptionintex=0;
       }        }
     }      }
   }    }
Line 435  sub displayfoils { Line 409  sub displayfoils {
   
   
 sub optionlist_correction {  sub optionlist_correction {
       my @options = @_;
     my $texoptionlist = shift;      my $texoptionlist='\\item [] Choices: ';
     if ($texoptionlist=~/<option selected/ or $texoptionlist=~/<option>[^<]+<\/option>/) {      if (scalar(@options) > 0) {
  $texoptionlist =~ s/<option><\/option>/\\item \[\] Choices: /;   foreach my $option (@options) {
  $texoptionlist =~ s/<option>/\{\\bf /g;      $texoptionlist.='{\bf '.
  $texoptionlist =~ s/<option selected="on">/\{\\bf /g;   &Apache::lonxml::latex_special_symbols($option).
  $texoptionlist =~ s/<\/option>/\},/g;   '},';
  $texoptionlist =~ s/,$/\./g;   }
  $texoptionlist =~ s/>/\$>\$/g;   chop($texoptionlist);
  $texoptionlist =~ s/</\$<\$/g;   $texoptionlist.='.';
  $texoptionlist =~ s/=/\$=\$/g;  
  $texoptionlist =~ s/\^(\d+)/\$^{$1}\$/g;  
     } else {      } else {
  $texoptionlist =~ s/<option><\/option>/\\item \[\] \\vskip -5 mm/;   $texoptionlist='\\item [] \\vskip -5 mm';
     }      }
     return $texoptionlist;      return $texoptionlist;
 }  }
   
   
 sub webbubbles {  sub webbubbles {
   
     my ($ropt,$ralphabet,$temp,$lastopt)=@_;      my ($ropt,$ralphabet,$temp,$lastopt)=@_;
     my @opt=@$ropt;       my @opt=@$ropt; 
     my @alphabet=@$ralphabet;      my @alphabet=@$ralphabet;
Line 478  sub webbubbles { Line 449  sub webbubbles {
   
   
 sub bubbles {  sub bubbles {
   
     my ($ralphabit,$ropt) = @_;      my ($ralphabit,$ropt) = @_;
     my @alphabet = @$ralphabit;      my @alphabet = @$ralphabit;
     my @opt = @$ropt;      my @opt = @$ropt;
Line 495  sub bubbles { Line 465  sub bubbles {
     }      }
     for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {      for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
  my $leftmargin;   my $leftmargin;
    $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
  if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}   if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
  $current_length += (length($opt[$ind])+length($alphabet[$ind])+3)*2;   $current_length += (length($opt[$ind])+length($alphabet[$ind])+3)*2;
  if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {   if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {

Removed from v.1.100  
changed lines
  Added in v.1.101


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