Diff for /loncom/homework/imageresponse.pm between versions 1.28 and 1.34

version 1.28, 2003/05/06 15:48:55 version 1.34, 2003/08/01 15:50:43
Line 25 Line 25
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   # July,August 2003 H. K. Ng
   #
 #FIXME LATER assumes multiple possible submissions but only one is possible   #FIXME LATER assumes multiple possible submissions but only one is possible 
 #currently  #currently
   
 package Apache::imageresponse;  package Apache::imageresponse;
   use Apache::randomlylabel;
 use strict;  use strict;
 use Image::Magick;  use Image::Magick;
   use GD;
   
 BEGIN {  BEGIN {
   &Apache::lonxml::register('Apache::imageresponse',('imageresponse'));    &Apache::lonxml::register('Apache::imageresponse',('imageresponse'));
Line 51  sub start_imageresponse { Line 54  sub start_imageresponse {
 }  }
   
 sub end_imageresponse {  sub end_imageresponse {
   &Apache::response::end_response;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   pop @Apache::lonxml::namespace;      &Apache::response::end_response;
   &Apache::lonxml::deregister('Apache::imageresponse',('foilgroup','foil','text','image','rectangle','conceptgroup'));      pop @Apache::lonxml::namespace;
   return '';      &Apache::lonxml::deregister('Apache::imageresponse',('foilgroup','foil','text','image','rectangle','conceptgroup'));
       my $result;
       if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
       return $result;
 }  }
   
 %Apache::response::foilgroup=();  %Apache::response::foilgroup=();
Line 136  sub gradefoils { Line 142  sub gradefoils {
     $x=$ENV{"form.HWVAL_$id:$temp.x"};      $x=$ENV{"form.HWVAL_$id:$temp.x"};
     $y=$ENV{"form.HWVAL_$id:$temp.y"};      $y=$ENV{"form.HWVAL_$id:$temp.y"};
     &Apache::lonxml::debug("Got a x of $x and a y of $y for $name");      &Apache::lonxml::debug("Got a x of $x and a y of $y for $name");
     if (defined(@{ $Apache::response::foilgroup{"$name.area"} })) {      if (defined($x) && defined($y) &&
    defined(@{ $Apache::response::foilgroup{"$name.area"} })) {
       my @areas = @{ $Apache::response::foilgroup{"$name.area"} };        my @areas = @{ $Apache::response::foilgroup{"$name.area"} };
       my $grade="INCORRECT";        my $grade="INCORRECT";
       foreach my $area (@areas) {        foreach my $area (@areas) {
Line 214  sub end_conceptgroup { Line 221  sub end_conceptgroup {
   return $result;    return $result;
 }  }
   
   sub insert_foil {
       return '
          <foil>
              <image></image>
              <text></text>
              <rectangle></rectangle>
          </foil>
   ';
   }
   
 $Apache::imageresponse::curname='';  $Apache::imageresponse::curname='';
 sub start_foil {  sub start_foil {
   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
Line 304  sub end_image { Line 321  sub end_image {
   my $name = $Apache::imageresponse::curname;    my $name = $Apache::imageresponse::curname;
   if ($target eq 'web') {    if ($target eq 'web') {
     my $image = &Apache::lonxml::endredirection;      my $image = &Apache::lonxml::endredirection;
     &Apache::lonxml::debug("out is $image");      &Apache::lonxml::debug("original image is $image");
       my $id=$Apache::inputtags::response['-1'];
       my $temp=1;
       my $x=$ENV{"form.HWVAL_$id:$temp.x"};
       my $y=$ENV{"form.HWVAL_$id:$temp.y"};
       if (defined ($x) && defined ($y)) {
    &Apache::lonxml::debug("x and y defined as $x,$y");
    my $currentImage = &Apache::randomlylabel::get_image('/home/httpd/html'.$image,1);
    if (! defined($currentImage)) {
       &Apache::lonnet::logthis('Unable to create image object for '.$image);
       return '';
    }
    my $red;
    if (!($red = $currentImage->colorResolve(255,0,0))) {
       $red = $currentImage->colorClosestHWB(255,0,0);
    }
    my $length = 6;
    $currentImage->line($x-$length,$y-$length,$x+$length,$y+$length,$red);
    $currentImage->line($x-$length,$y+$length,$x+$length,$y-$length,$red);
   
    my ($nameWOext) = ($image =~ /^.*\/(.*)\..*$/);
    &Apache::lonxml::debug("graph name $nameWOext");
    my $webImageName = "/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_".
       $nameWOext.'.png'; #needs to be more random or specific
    my $newImageName = '/home/httpd'.$webImageName;
   
    my $imgfh = Apache::File->new('>'.$newImageName); 
    print $imgfh $currentImage->png;
    $image = $webImageName;
       }
       &Apache::lonxml::debug("out image is $image");
     if ( $Apache::imageresponse::conceptgroup      if ( $Apache::imageresponse::conceptgroup
  && !&Apache::response::showallfoils()) {   && !&Apache::response::showallfoils()) {
       $Apache::response::conceptgroup{"$name.image"} = $image;        $Apache::response::conceptgroup{"$name.image"} = $image;

Removed from v.1.28  
changed lines
  Added in v.1.34


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