version 1.2, 2004/01/12 19:53:54
|
version 1.3, 2004/01/14 22:59:18
|
Line 29 use Apache::Constants qw(:common :http);
|
Line 29 use Apache::Constants qw(:common :http);
|
|
|
sub deletedata { |
sub deletedata { |
my ($id)=@_; |
my ($id)=@_; |
&Apache::lonnet::delenv("imagechoice\\.$id"); |
&Apache::lonnet::delenv("imagechoice\\.$id\\.coords"); |
} |
} |
|
|
sub closewindow { |
sub closewindow { |
Line 51 ENDSUBM
|
Line 51 ENDSUBM
|
} |
} |
|
|
sub storedata { |
sub storedata { |
my ($r,$mode,$filename,$id)=@_; |
my ($r,$type,$filename,$id)=@_; |
|
|
my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"}); |
my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"}); |
|
|
Line 65 sub storedata {
|
Line 65 sub storedata {
|
} |
} |
|
|
if ((defined($ENV{"imagechoice.$id.x"})) && (defined($ENV{"imagechoice.$id.y"})) && |
if ((defined($ENV{"imagechoice.$id.x"})) && (defined($ENV{"imagechoice.$id.y"})) && |
($mode ne 'pairtwo') && ($mode ne 'pairthree')) { |
($type ne 'pairtwo') && ($type ne 'pairthree')) { |
my $output=''; |
my $output=''; |
if ($ENV{"imagechoice.$id.formx"}) { |
if ($ENV{"imagechoice.$id.formx"}) { |
$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formx"}. |
$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formx"}. |
Line 75 sub storedata {
|
Line 75 sub storedata {
|
$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formy"}. |
$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formy"}. |
'.value='.$ENV{"imagechoice.$id.y"}.';'; |
'.value='.$ENV{"imagechoice.$id.y"}.';'; |
} |
} |
} elsif ($mode eq 'pairthree') { |
} elsif ($type eq 'polygon' or $type eq 'box') { |
my $output=''; |
|
my $outputpair='('.$ENV{"imagechoice.$id.selx"}.','.$ENV{"imagechoice.$id.sely"}.')-('.$ENV{"imagechoice.$id.x"}.','.$ENV{"imagechoice.$id.y"}.')'; |
|
|
|
if ($ENV{"imagechoice.$id.formcoord"}) { |
|
$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formcoord"}. |
|
'.value="'.$outputpair.'";'; |
|
} |
|
} elsif ($mode eq 'polygon') { |
|
my $coordstr; |
my $coordstr; |
while (@coords) { |
while (@coords) { |
$coordstr.='('.shift(@coords).','.shift(@coords).')-'; |
$coordstr.='('.shift(@coords).','.shift(@coords).')-'; |
Line 96 sub storedata {
|
Line 88 sub storedata {
|
} |
} |
|
|
sub getcoord { |
sub getcoord { |
my ($r,$mode,$filename,$id)=@_; |
my ($r,$type,$filename,$id)=@_; |
my $heading='Position'; |
my $heading='Position'; |
my $nextstage=''; |
my $nextstage=''; |
if ($mode eq 'pair') { |
if ($type eq 'box') { |
$heading='First Coordinate'; |
my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"}); |
$nextstage='<input type="hidden" name="mode" value="pairtwo" />'; |
my $step=scalar(@coords)/2; |
} elsif ($mode eq 'pairtwo') { |
if ($step == 0) { |
$heading='Second Coordinate'; |
$heading='First Coordinate'; |
$nextstage='<input type="hidden" name="mode" value="pairthree" />'; |
#$nextstage='<input type="hidden" name="type" value="pairtwo" />'; |
} elsif ($mode eq 'polygon') { |
} elsif ($step == 1) { |
|
$heading='Second Coordinate'; |
|
#$nextstage='<input type="hidden" name="type" value="pairthree" />'; |
|
} else { |
|
$heading='Finish or Cancel'; |
|
$nextstage='<input type="submit" name="finish" value="Finish" />'; |
|
} |
|
} elsif ($type eq 'polygon') { |
$heading='Enter Coordinate or click finish to close Polygon'; |
$heading='Enter Coordinate or click finish to close Polygon'; |
$nextstage='<input type="submit" name="finish" value="Finish" />'; |
$nextstage='<input type="submit" name="finish" value="Finish" />'; |
} |
} |
Line 131 sub savecoord {
|
Line 130 sub savecoord {
|
$ENV{"form.image.y"})); |
$ENV{"form.image.y"})); |
&Apache::lonnet::appenv("imagechoice.$id.coords"=>$data); |
&Apache::lonnet::appenv("imagechoice.$id.coords"=>$data); |
} |
} |
|
return int(scalar(split(':',$ENV{"imagechoice.$id.coords"}))/2); |
} |
} |
|
|
sub drawX { |
sub drawX { |
Line 175 sub drawPolygon {
|
Line 175 sub drawPolygon {
|
return %x; |
return %x; |
} |
} |
|
|
|
sub drawBox { |
|
my ($id,$imid)=@_; |
|
my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"}); |
|
my %x; |
|
if (scalar(@coords) < 4) { return %x; } |
|
my $width = 1; |
|
my $extrawidth = 2; |
|
my $i=$x{"cgi.$imid.BOXCOUNT"}++; |
|
$x{"cgi.$imid.BOX$i"}=join(':',(@coords,"FFFFFF",($width+$extrawidth))); |
|
$i=$x{"cgi.$imid.BOXCOUNT"}++; |
|
$x{"cgi.$imid.BOX$i"}=join(':',(@coords,"00FF00",$width)); |
|
return %x; |
|
} |
|
|
sub drawimage { |
sub drawimage { |
my ($r,$mode,$filename,$id)=@_; |
my ($r,$type,$filename,$id)=@_; |
my $imid=&Apache::loncommon::get_cgi_id(); |
my $imid=&Apache::loncommon::get_cgi_id(); |
my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"}); |
my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"}); |
if (scalar(@coords) < 2) { return &Apache::lonnet::hreflocation('',$filename); } |
if (scalar(@coords) < 2) { return &Apache::lonnet::hreflocation('',$filename); } |
my %data; |
my %data; |
$data{"cgi.$imid.BGIMG"}=$filename; |
$data{"cgi.$imid.BGIMG"}=$filename; |
my $x=@coords[-2]; |
my $x=$coords[-2]; |
my $y=@coords[-1]; |
my $y=$coords[-1]; |
%data=(%data,&drawX($imid,$x,$y)); |
%data=(%data,&drawX($imid,$x,$y)); |
if ($mode eq "polygon") { %data=(%data,&drawPolygon($id,$imid)); } |
if ($type eq "polygon") { %data=(%data,&drawPolygon($id,$imid)); } |
|
if ($type eq "box") { %data=(%data,&drawBox($id,$imid)); } |
&Apache::lonnet::appenv(%data); |
&Apache::lonnet::appenv(%data); |
return "/adm/randomlabel.png?token=$imid" |
return "/adm/randomlabel.png?token=$imid" |
} |
} |
Line 197 sub handler {
|
Line 212 sub handler {
|
my (undef,$id) = split(/=/,$ENV{'QUERY_STRING'}); |
my (undef,$id) = split(/=/,$ENV{'QUERY_STRING'}); |
my $filename = &Apache::lonnet::unescape($ENV{"imagechoice.$id.file"}); |
my $filename = &Apache::lonnet::unescape($ENV{"imagechoice.$id.file"}); |
my $formname = $ENV{"imagechoice.$id.formname"}; |
my $formname = $ENV{"imagechoice.$id.formname"}; |
my $mode=$ENV{"imagechoice.$id.mode"}; |
|
if ($ENV{'form.cancel'} eq 'Cancel') { |
if ($ENV{'form.cancel'} eq 'Cancel') { |
&deletedata($id); |
&deletedata($id); |
&closewindow($r,'',$filename); |
&closewindow($r,'',$filename); |
|
return OK; |
} |
} |
&savecoord($id); |
my $type=$ENV{"imagechoice.$id.type"}; |
my $imurl=&drawimage($r,$mode,$filename,$id); |
if (defined($ENV{'form.type'})) { $type=$ENV{'form.type'}; } |
if ($ENV{'form.finish'} eq 'Finish') { |
my $numcoords=&savecoord($id); |
&storedata($r,$mode,$imurl,$id); |
&Apache::lonnet::logthis("num coords is $numcoords"); |
|
my $imurl=&drawimage($r,$type,$filename,$id); |
|
if (($ENV{'form.finish'} eq 'Finish')) { |
|
&storedata($r,$type,$imurl,$id); |
|
} else { |
|
&getcoord($r,$type,$imurl,$id); |
} |
} |
&getcoord($r,$mode,$imurl,$id); |
|
return OK; |
return OK; |
} |
} |
|
|