Annotation of loncom/homework/imageresponse.pm, revision 1.34

1.12      albertel    1: # The LearningOnline Network with CAPA
1.14      albertel    2: # image click response style
                      3: #
1.34    ! albertel    4: # $Id: imageresponse.pm,v 1.33 2003/08/01 14:22:07 ng Exp $
1.14      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.33      ng         28: # July,August 2003 H. K. Ng
                     29: #
1.25      www        30: #FIXME LATER assumes multiple possible submissions but only one is possible 
                     31: #currently
1.3       albertel   32: 
1.1       albertel   33: package Apache::imageresponse;
1.34    ! albertel   34: use Apache::randomlylabel;
1.1       albertel   35: use strict;
1.21      harris41   36: use Image::Magick;
1.33      ng         37: use GD;
1.1       albertel   38: 
1.16      harris41   39: BEGIN {
1.12      albertel   40:   &Apache::lonxml::register('Apache::imageresponse',('imageresponse'));
1.1       albertel   41: }
                     42: 
                     43: sub start_imageresponse {
1.12      albertel   44:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.13      albertel   45:   my $result;
1.12      albertel   46:   #when in a radiobutton response use these
                     47:   &Apache::lonxml::register('Apache::imageresponse',('foilgroup','foil','text','image','rectangle','conceptgroup'));
                     48:   push (@Apache::lonxml::namespace,'imageresponse');
                     49:   my $id = &Apache::response::start_response($parstack,$safeeval);
1.13      albertel   50:   if ($target eq 'meta') {
                     51:     $result=&Apache::response::meta_package_write('imageresponse');
                     52:   }
                     53:   return $result;
1.1       albertel   54: }
                     55: 
                     56: sub end_imageresponse {
1.30      albertel   57:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     58:     &Apache::response::end_response;
                     59:     pop @Apache::lonxml::namespace;
                     60:     &Apache::lonxml::deregister('Apache::imageresponse',('foilgroup','foil','text','image','rectangle','conceptgroup'));
                     61:     my $result;
                     62:     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
                     63:     return $result;
1.1       albertel   64: }
                     65: 
1.20      albertel   66: %Apache::response::foilgroup=();
1.1       albertel   67: sub start_foilgroup {
1.20      albertel   68:   %Apache::response::foilgroup=();
1.12      albertel   69:   $Apache::imageresponse::conceptgroup=0;
                     70:   &Apache::response::setrandomnumber();
                     71:   return '';
1.1       albertel   72: }
                     73: 
1.2       albertel   74: sub getfoilcounts {
1.12      albertel   75:   my ($parstack,$safeeval)=@_;
                     76: 
                     77:   my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
                     78:   # +1 since instructors will count from 1
                     79:   my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
1.18      albertel   80:   if (&Apache::response::showallfoils()) { $max=$count; }
1.12      albertel   81:   return ($count,$max);
1.2       albertel   82: }
                     83: 
                     84: sub whichfoils {
1.12      albertel   85:   my ($max)=@_;
                     86:   if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
                     87:   my @names = @{ $Apache::response::foilgroup{'names'} };
                     88:   my @whichopt =();
                     89:   while ((($#whichopt+1) < $max) && ($#names > -1)) {
                     90:     &Apache::lonxml::debug("Have $#whichopt max is $max");
1.18      albertel   91:     my $aopt;
                     92:     if (&Apache::response::showallfoils()) {
                     93:       $aopt=0;
                     94:     } else {
1.22      albertel   95:       $aopt=int(&Math::Random::random_uniform() * ($#names+1));
1.18      albertel   96:     }
1.12      albertel   97:     &Apache::lonxml::debug("From $#names elms, picking $aopt");
                     98:     $aopt=splice(@names,$aopt,1);
                     99:     &Apache::lonxml::debug("Picked $aopt");
                    100:     push (@whichopt,$aopt);
                    101:   }
                    102:   return @whichopt;
1.2       albertel  103: }
                    104: 
                    105: sub displayfoils {
1.24      sakharuk  106:   my ($target,@whichopt) = @_;
1.12      albertel  107:   my $result ='';
                    108:   my $name;
                    109:   my $temp=1;
                    110:   foreach $name (@whichopt) {
1.24      sakharuk  111:     $result.=$Apache::response::foilgroup{"$name.text"};
1.28      albertel  112:     &Apache::lonxml::debug("Text is $result");
1.24      sakharuk  113:     if ($target eq 'tex') {$result.="\\vskip 0 mm \n";} else {$result.="<br />\n";}
1.12      albertel  114:     my $image=$Apache::response::foilgroup{"$name.image"};
1.28      albertel  115:     &Apache::lonxml::debug("image is $image");
1.12      albertel  116:     if ($Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"} =~ /^correct/ ) {
1.24      sakharuk  117:       if ($target eq 'tex') {
                    118: 	$result.=$Apache::response::foilgroup{"$name.image"}."\\vskip 0 mm \n";
                    119:       } else {
                    120:         $result.="<img src=\"$image\"/> <br />\n";
                    121:       }
1.12      albertel  122:     } else {
1.24      sakharuk  123:       if ($target eq 'tex') {
                    124: 	$result.=$Apache::response::foilgroup{"$name.image"}."\\vskip 0 mm \n";
                    125:       } else {
                    126:         $result.="<input type=\"image\" name=\"HWVAL_$Apache::inputtags::response['-1']:$temp\" src=\"$image\"/> <br />\n";
                    127:       }
1.12      albertel  128:     }
                    129:     $temp++;
                    130:   }
                    131:   return $result;
1.2       albertel  132: }
                    133: 
1.3       albertel  134: sub gradefoils {
1.12      albertel  135:   my (@whichopt) = @_;
                    136:   my $x;
                    137:   my $y;
                    138:   my $result;
                    139:   my $id=$Apache::inputtags::response['-1'];
                    140:   my $temp=1;
                    141:   foreach my $name (@whichopt) {
                    142:     $x=$ENV{"form.HWVAL_$id:$temp.x"};
                    143:     $y=$ENV{"form.HWVAL_$id:$temp.y"};
                    144:     &Apache::lonxml::debug("Got a x of $x and a y of $y for $name");
1.29      albertel  145:     if (defined($x) && defined($y) &&
                    146: 	defined(@{ $Apache::response::foilgroup{"$name.area"} })) {
1.12      albertel  147:       my @areas = @{ $Apache::response::foilgroup{"$name.area"} };
                    148:       my $grade="INCORRECT";
                    149:       foreach my $area (@areas) {
                    150: 	&Apache::lonxml::debug("Area is $area for $name");
                    151: 	$area =~ m/([a-z]*):/;
                    152: 	&Apache::lonxml::debug("Area of type $1");
                    153: 	if ($1 eq 'rectangle') {
                    154: 	  $grade=&grade_rectangle($area,$x,$y);
                    155: 	} else {
                    156: 	  &Apache::lonxml::error("Unknown area style $area");
1.9       albertel  157: 	}
1.12      albertel  158: 	&Apache::lonxml::debug("Area said $grade");
                    159: 	if ($grade eq 'APPROX_ANS') { last; }
                    160:       }
                    161:       &Apache::lonxml::debug("Foil was $grade");
                    162:       if ($grade eq 'INCORRECT') { $result= 'INCORRECT'; }
                    163:       if (($grade eq 'APPROX_ANS') && ($result ne 'APPROX_ANS')) { $result=$grade; }
                    164:       &Apache::lonxml::debug("Question is $result");
                    165:       $temp++;
                    166:     }
                    167:   }
                    168:   $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}="$x:$y";
                    169:   $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}=$result;
                    170:   return '';
1.3       albertel  171: }
                    172: 
1.1       albertel  173: sub end_foilgroup {
1.12      albertel  174:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    175:   my $result='';
                    176:   my @whichopt;
1.24      sakharuk  177:   if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
1.12      albertel  178:     my ($count,$max) = &getfoilcounts($parstack,$safeeval);
                    179:     if ($count>$max) { $count=$max }
                    180:     &Apache::lonxml::debug("Count is $count from $max");
                    181:     @whichopt = &whichfoils($max);
1.28      albertel  182:     if ($target eq 'web' || $target eq 'tex') {
                    183: 	$result=&displayfoils($target,@whichopt);
                    184:     } elsif ($target eq 'grade') {
                    185: 	if ( defined $ENV{'form.submitted'}) { &gradefoils(@whichopt); }
                    186:     } 
1.26      albertel  187:   } elsif ($target eq 'edit') {
                    188:       $result=&Apache::edit::end_table();
1.12      albertel  189:   }
                    190:   return $result;
1.1       albertel  191: }
                    192: 
                    193: sub start_conceptgroup {
1.12      albertel  194:   $Apache::imageresponse::conceptgroup=1;
1.20      albertel  195:   %Apache::response::conceptgroup=();
1.12      albertel  196:   return '';
1.1       albertel  197: }
                    198: 
                    199: sub end_conceptgroup {
1.12      albertel  200:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.26      albertel  201:   $Apache::imageresponse::conceptgroup=0;
                    202:   my $result;
1.24      sakharuk  203:   if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
1.12      albertel  204:     if (defined(@{ $Apache::response::conceptgroup{'names'} })) {
                    205:       my @names = @{ $Apache::response::conceptgroup{'names'} };
1.22      albertel  206:       my $pick=int(&Math::Random::random_uniform() * ($#names+1));
1.12      albertel  207:       my $name=$names[$pick];
                    208:       if (defined(@{ $Apache::response::conceptgroup{"$name.area"} })) {
                    209: 	push @{ $Apache::response::foilgroup{'names'} }, $name;
                    210: 	$Apache::response::foilgroup{"$name.text"} = $Apache::response::conceptgroup{"$name.text"};
                    211: 	$Apache::response::foilgroup{"$name.image"} = $Apache::response::conceptgroup{"$name.image"};
                    212: 	push(@{ $Apache::response::foilgroup{"$name.area"} }, @{ $Apache::response::conceptgroup{"$name.area"} });
                    213: 	my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval);
                    214: 	$Apache::response::foilgroup{"$name.concept"} = $concept;
                    215: 	&Apache::lonxml::debug("Selecting $name in $concept");
                    216:       }
1.9       albertel  217:     }
1.26      albertel  218:   } elsif ($target eq 'edit') {
                    219:       $result=&Apache::edit::end_table();
1.12      albertel  220:   }
1.26      albertel  221:   return $result;
1.31      albertel  222: }
                    223: 
                    224: sub insert_foil {
                    225:     return '
                    226:        <foil>
                    227:            <image></image>
                    228:            <text></text>
                    229:            <rectangle></rectangle>
                    230:        </foil>
                    231: ';
1.1       albertel  232: }
                    233: 
1.12      albertel  234: $Apache::imageresponse::curname='';
1.1       albertel  235: sub start_foil {
1.12      albertel  236:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.24      sakharuk  237:   if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
1.12      albertel  238:     my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    239:     if ($name eq '') { $name=$Apache::lonxml::curdepth; }
1.18      albertel  240:     if ( $Apache::imageresponse::conceptgroup
                    241: 	 && !&Apache::response::showallfoils()) {
1.12      albertel  242:       push(@{ $Apache::response::conceptgroup{'names'} }, $name);
                    243:     } else {
                    244:       push(@{ $Apache::response::foilgroup{'names'} }, $name);
                    245:     }
                    246:     $Apache::imageresponse::curname=$name;
                    247:   }
                    248:   return '';
1.1       albertel  249: }
                    250: 
                    251: sub end_foil {
1.26      albertel  252:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    253:     my $result;
                    254:     if ($target eq 'edit') {
                    255: 	$result=&Apache::edit::end_table();
                    256:     }
                    257:     return $result;
1.1       albertel  258: }
                    259: 
                    260: sub start_text {
1.12      albertel  261:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.25      www       262:   my $result='';
                    263:   if ($target eq 'web' || $target eq 'tex') { 
                    264:      &Apache::lonxml::startredirection; 
                    265:   } elsif ($target eq 'edit') {
1.26      albertel  266:     my $descr=&Apache::lonxml::get_all_text('/text',$parser);
1.25      www       267:     $result=&Apache::edit::tag_start($target,$token,'Task Description').
                    268: 	&Apache::edit::editfield($token->[1],$descr,'Text',60,2).
1.26      albertel  269:         &Apache::edit::end_row();
1.25      www       270:   } elsif ($target eq "modified") {
1.26      albertel  271:     my $descr=&Apache::lonxml::get_all_text('/text',$parser);
1.25      www       272:     $result=$token->[4].&Apache::edit::modifiedfield($token);
                    273:     &Apache::lonxml::debug($result);
                    274:   }
                    275:   return $result;
1.1       albertel  276: }
                    277: 
                    278: sub end_text {
1.12      albertel  279:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.26      albertel  280:   my $result;
1.24      sakharuk  281:   if ($target eq 'web' || $target eq 'tex') {
1.12      albertel  282:     my $name = $Apache::imageresponse::curname;
1.18      albertel  283:     if ( $Apache::imageresponse::conceptgroup
                    284:        && !&Apache::response::showallfoils() ) {
1.12      albertel  285:       $Apache::response::conceptgroup{"$name.text"} = &Apache::lonxml::endredirection;
                    286:     } else {
                    287:       $Apache::response::foilgroup{"$name.text"} = &Apache::lonxml::endredirection;
1.7       albertel  288:     }
1.26      albertel  289:   } elsif ($target eq 'edit') {
                    290:       $result=&Apache::edit::end_table();
1.12      albertel  291:   }
1.26      albertel  292:   return $result;
1.1       albertel  293: }
                    294: 
                    295: sub start_image {
1.12      albertel  296:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.25      www       297:   my $result='';
                    298:   if ($target eq 'web' || $target eq 'tex') { 
                    299:       &Apache::lonxml::startredirection; 
                    300:   } elsif ($target eq 'edit') {
1.26      albertel  301:     my $bgimg=&Apache::lonxml::get_all_text('/image',$parser);
1.27      www       302:     $Apache::edit::bgimgsrc=$bgimg;
                    303:     $Apache::edit::bgimgsrcdepth=$Apache::lonxml::curdepth;
                    304: 
1.25      www       305:     $result=&Apache::edit::tag_start($target,$token,'Clickable Image').
                    306: 	&Apache::edit::editline($token->[1],$bgimg,'Image Source File',40);
                    307:     $result.=&Apache::edit::browse(undef,'textnode').' ';
                    308:     $result.=&Apache::edit::search(undef,'textnode').
1.26      albertel  309:         &Apache::edit::end_row();
1.25      www       310:   } elsif ($target eq "modified") {
1.26      albertel  311:     my $bgimg=&Apache::lonxml::get_all_text('/image',$parser);
1.25      www       312:     $result=$token->[4].&Apache::edit::modifiedfield($token);
                    313:     &Apache::lonxml::debug($result);
                    314:   }
                    315:   return $result;
1.1       albertel  316: }
                    317: 
                    318: sub end_image {
1.26      albertel  319:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    320:   my $result;
1.24      sakharuk  321:   my $name = $Apache::imageresponse::curname;
1.12      albertel  322:   if ($target eq 'web') {
                    323:     my $image = &Apache::lonxml::endredirection;
1.32      ng        324:     &Apache::lonxml::debug("original image is $image");
                    325:     my $id=$Apache::inputtags::response['-1'];
                    326:     my $temp=1;
                    327:     my $x=$ENV{"form.HWVAL_$id:$temp.x"};
                    328:     my $y=$ENV{"form.HWVAL_$id:$temp.y"};
                    329:     if (defined ($x) && defined ($y)) {
                    330: 	&Apache::lonxml::debug("x and y defined as $x,$y");
1.34    ! albertel  331: 	my $currentImage = &Apache::randomlylabel::get_image('/home/httpd/html'.$image,1);
1.33      ng        332: 	if (! defined($currentImage)) {
                    333: 	    &Apache::lonnet::logthis('Unable to create image object for '.$image);
                    334: 	    return '';
                    335: 	}
                    336: 	my $red;
                    337: 	if (!($red = $currentImage->colorResolve(255,0,0))) {
                    338: 	    $red = $currentImage->colorClosestHWB(255,0,0);
                    339: 	}
1.32      ng        340: 	my $length = 6;
1.33      ng        341: 	$currentImage->line($x-$length,$y-$length,$x+$length,$y+$length,$red);
                    342: 	$currentImage->line($x-$length,$y+$length,$x+$length,$y-$length,$red);
                    343: 
                    344: 	my ($nameWOext) = ($image =~ /^.*\/(.*)\..*$/);
                    345: 	&Apache::lonxml::debug("graph name $nameWOext");
                    346: 	my $webImageName = "/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_".
                    347: 	    $nameWOext.'.png'; #needs to be more random or specific
1.32      ng        348: 	my $newImageName = '/home/httpd'.$webImageName;
                    349: 
1.33      ng        350: 	my $imgfh = Apache::File->new('>'.$newImageName); 
                    351: 	print $imgfh $currentImage->png;
1.32      ng        352: 	$image = $webImageName;
                    353:     }
                    354:     &Apache::lonxml::debug("out image is $image");
1.18      albertel  355:     if ( $Apache::imageresponse::conceptgroup
                    356: 	 && !&Apache::response::showallfoils()) {
1.12      albertel  357:       $Apache::response::conceptgroup{"$name.image"} = $image;
                    358:     } else {
                    359:       $Apache::response::foilgroup{"$name.image"} = $image;
1.7       albertel  360:     }
1.26      albertel  361:   } elsif ($target eq 'edit') {
                    362:       $result=&Apache::edit::end_table();
1.19      sakharuk  363:   } elsif ($target eq 'tex') {
                    364:     my $src = &Apache::lonxml::endredirection;
                    365:     $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
                    366:     my $width_param = '';
                    367:     my $height_param = '';
                    368:     my $scaling = .3;
                    369:     my $image = Image::Magick->new;
                    370:     my $current_figure = $image->Read($src);
                    371:     $width_param = $image->Get('width') * $scaling;;
                    372:     $height_param = $image->Get('height') * $scaling;;
                    373:     undef $image;
                    374:     my $epssrc = $src;
                    375:     $epssrc =~ s/(\.gif|\.jpg)$/\.eps/i;
                    376:     if (not -e $epssrc) {
                    377: 	my $localfile = $epssrc;
                    378: 	$localfile =~ s/.*(\/res)/$1/;	
                    379: 	my $file;
                    380: 	my $path;	
                    381: 	if ($localfile =~ m!(.*)/([^/]*)$!) {
                    382: 	    $file = $2;
                    383: 	    $path = $1.'/'; 
                    384: 	}	
                    385: 	my $signal_eps = 0;
                    386: 	my @content_directory = &Apache::lonnet::dirlist($path);
                    387: 	for (my $iy=0;$iy<=$#content_directory;$iy++) {
                    388: 	    my @tempo_array = split(/&/,$content_directory[$iy]);
                    389: 	    $content_directory[$iy] = $tempo_array[0];
                    390: 	    if ($file eq $tempo_array[0]) {
                    391: 		$signal_eps = 1;
                    392: 		last;
                    393: 	    }
                    394: 	}
                    395: 	if ($signal_eps) {
                    396: 	    my $eps_file = &Apache::lonnet::getfile($localfile);
                    397: 	} else {
                    398: 	    $localfile = $src;
                    399: 	    $localfile =~ s/.*(\/res)/$1/;	
                    400: 	    my $as = &Apache::lonnet::getfile($src);		      
                    401: 	}
                    402:     }
                    403:     my $file;
                    404:     my $path;	
                    405:     if ($src =~ m!(.*)/([^/]*)$!) {
                    406: 	$file = $2;
                    407: 	$path = $1.'/'; 
                    408:     }
                    409:     my $newsrc = $src;
1.27      www       410:     $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
                    411:     $file=~s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
1.19      sakharuk  412:     #do we have any specified size of the picture?
                    413:     my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); 
                    414:     my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); 
                    415:     my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
                    416:     if ($TeXwidth ne '') { 
                    417: 	$width_param = $TeXwidth; 
                    418:     } elsif ($TeXheight ne '') { 
                    419: 	$width_param = $TeXheight/$height_param*$width_param;
                    420:     } elsif ($width ne '') {
                    421: 	$width_param = $width*$scaling;      
                    422:     }
                    423:     #where can we find the picture?
                    424:     if (-e $newsrc) {
                    425: 	if ($path) {
1.24      sakharuk  426: 	  $Apache::response::foilgroup{"$name.image"} ='\vskip 0 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
1.19      sakharuk  427: 	}
                    428:     } else {
                    429: 	my $temp_file;
                    430: 	my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
                    431: 	$temp_file = Apache::File->new('>>'.$filename); 
                    432: 	print $temp_file "$src\n";
1.24      sakharuk  433: $Apache::response::foilgroup{"$name.image"} ='\vskip 0 mm \graphicspath{{/home/httpd/prtspool/}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
1.19      sakharuk  434:     }
1.24      sakharuk  435:   } 
1.26      albertel  436:   return $result;
1.1       albertel  437: }
                    438: 
                    439: sub start_rectangle {
1.12      albertel  440:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.25      www       441:   my $result='';
                    442:   if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') { 
                    443:      &Apache::lonxml::startredirection; 
                    444:   } elsif ($target eq 'edit') {
1.26      albertel  445:     my $coords=&Apache::lonxml::get_all_text('/rectangle',$parser);
1.25      www       446:     $result=&Apache::edit::tag_start($target,$token,'Rectangle').
                    447: 	&Apache::edit::editline($token->[1],$coords,'Coordinate Pairs',40).
1.27      www       448:         &Apache::edit::entercoordpair(undef,'textnode').
1.26      albertel  449:         &Apache::edit::end_row();
1.25      www       450:   } elsif ($target eq "modified") {
1.26      albertel  451:     my $coords=&Apache::lonxml::get_all_text('/rectangle',$parser);
1.25      www       452:     $result=$token->[4].&Apache::edit::modifiedfield($token);
                    453:     &Apache::lonxml::debug($result);
                    454:   }
                    455:   return $result;
1.1       albertel  456: }
                    457: 
1.3       albertel  458: sub grade_rectangle {
1.12      albertel  459:   my ($spec,$x,$y) = @_;
                    460:   &Apache::lonxml::debug("Spec is $spec");
                    461:   $spec=~m/rectangle:\(([0-9]+),([0-9]+)\)\-\(([0-9]+),([0-9]+)\)/;
                    462:   my $x1=$1;
                    463:   my $y1=$2;
                    464:   my $x2=$3;
                    465:   my $y2=$4;
                    466:   &Apache::lonxml::debug("Point $x1,$y1,$x2,$y2");
                    467:   if ($x1 > $x2) { my $temp=$x1;$x1=$x2;$x2=$temp; }
                    468:   if ($y1 > $y2) { my $temp=$y1;$y1=$y2;$y2=$temp; }
1.17      albertel  469:   if (($x >= $x1) && ($x <= $x2) && ($y >= $y1) && ($y <= $y2)) {
                    470:     return 'APPROX_ANS';
                    471:   }
1.12      albertel  472:   return 'INCORRECT';
1.3       albertel  473: }
                    474: 
1.1       albertel  475: sub end_rectangle {
1.12      albertel  476:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.26      albertel  477:   my $result;
1.24      sakharuk  478:   if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
1.12      albertel  479:     my $name = $Apache::imageresponse::curname;
                    480:     my $area = &Apache::lonxml::endredirection;
                    481:     &Apache::lonxml::debug("out is $area for $name");
1.18      albertel  482:     if ( $Apache::imageresponse::conceptgroup
                    483: 	 && !&Apache::response::showallfoils()) {
1.12      albertel  484:       push @{ $Apache::response::conceptgroup{"$name.area"} },"rectangle:$area";
                    485:     } else {
                    486:       push @{ $Apache::response::foilgroup{"$name.area"} },"rectangle:$area";
1.7       albertel  487:     }
1.26      albertel  488:   } elsif ($target eq 'edit') {
                    489:       $result=&Apache::edit::end_table();
1.12      albertel  490:   }
1.26      albertel  491:   return $result;
1.1       albertel  492: }
                    493: 1;
                    494: __END__
                    495:  

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.