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

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

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.