[LON-CAPA-cvs] cvs: loncom /homework imagechoice.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 17 Feb 2004 22:02:05 -0000
albertel Tue Feb 17 17:02:05 2004 EDT
Modified files:
/loncom/homework imagechoice.pm
Log:
- BUG#2710, <randomlabel> nows uses imagechoice.pm
Index: loncom/homework/imagechoice.pm
diff -u loncom/homework/imagechoice.pm:1.3 loncom/homework/imagechoice.pm:1.4
--- loncom/homework/imagechoice.pm:1.3 Wed Jan 14 17:59:18 2004
+++ loncom/homework/imagechoice.pm Tue Feb 17 17:02:05 2004
@@ -1,4 +1,4 @@
-# $Id: imagechoice.pm,v 1.3 2004/01/14 22:59:18 albertel Exp $
+# $Id: imagechoice.pm,v 1.4 2004/02/17 22:02:05 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,7 +33,10 @@
}
sub closewindow {
- my ($r,$output,$filename)=@_;
+ my ($r,$output,$filename,$needimage)=@_;
+ if ($needimage) {
+ $needimage="<img name=\"pickimg\" src=\"$filename\" />";
+ }
$r->print(<<"ENDSUBM");
<html>
<script>
@@ -44,7 +47,7 @@
</script>
<body bgcolor="#FFFFFF" onLoad="submitthis()">
<h3>Position Selected</h3>
-<!--<img name="pickimg" src="$filename" />-->
+$needimage
</body>
</html>
ENDSUBM
@@ -55,25 +58,24 @@
my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
- my $output;
+ my ($output,$needimage);
if ($ENV{"imagechoice.$id.formwidth"}) {
$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formwidth"}.'.value=document.pickimg.width;';
+ $needimage=1;
}
if ($ENV{"imagechoice.$id.formheight"}) {
$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formheight"}.'.value=document.pickimg.height;';
+ $needimage=1;
}
- if ((defined($ENV{"imagechoice.$id.x"})) && (defined($ENV{"imagechoice.$id.y"})) &&
- ($type ne 'pairtwo') && ($type ne 'pairthree')) {
- my $output='';
+ if ($type eq 'point') {
+ my (undef,$x,$y)=split(':',$ENV{"imagechoice.$id.coords"});
if ($ENV{"imagechoice.$id.formx"}) {
- $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formx"}.
- '.value='.$ENV{"imagechoice.$id.x"}.';';
+ $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formx"}.'.value='.$x.';';
}
if ($ENV{"imagechoice.$id.formy"}) {
- $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formy"}.
- '.value='.$ENV{"imagechoice.$id.y"}.';';
+ $output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formy"}.'.value='.$y.';';
}
} elsif ($type eq 'polygon' or $type eq 'box') {
my $coordstr;
@@ -83,35 +85,39 @@
chop($coordstr);
$output.='opener.document.forms.'.$ENV{"imagechoice.$id.formname"}.'.'.$ENV{"imagechoice.$id.formcoord"}.'.value="'.$coordstr.'";';
}
+
&deletedata($id);
- &closewindow($r,$output,$filename);
+ &closewindow($r,$output,$filename,$needimage);
}
sub getcoord {
my ($r,$type,$filename,$id)=@_;
- my $heading='Position';
+ my $heading='Select Position on Image';
my $nextstage='';
if ($type eq 'box') {
my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
my $step=scalar(@coords)/2;
if ($step == 0) {
- $heading='First Coordinate';
+ $heading='Select First Coordinate on Image';
#$nextstage='<input type="hidden" name="type" value="pairtwo" />';
} elsif ($step == 1) {
- $heading='Second Coordinate';
+ $heading='Select Second Coordinate on Image';
#$nextstage='<input type="hidden" name="type" value="pairthree" />';
} else {
- $heading='Finish or Cancel';
+ $heading='Select Finish to store selection.';
$nextstage='<input type="submit" name="finish" value="Finish" />';
}
} elsif ($type eq 'polygon') {
$heading='Enter Coordinate or click finish to close Polygon';
$nextstage='<input type="submit" name="finish" value="Finish" />';
+ } elsif ($type eq 'point') {
+ $heading='Click to select a Coordinate or click Finish to store current selection.';
+ $nextstage='<input type="submit" name="finish" value="Finish" />';
}
$r->print(<<"END");
<html>
<body bgcolor="#FFFFFF">
-<h3>Select $heading on Image</h3>
+<h3>$heading</h3>
<form method="POST" action="/adm/imagechoice?token=$id">
$nextstage
<input type="submit" name="cancel" value="Cancel" />
@@ -124,10 +130,15 @@
}
sub savecoord {
- my ($id)=@_;
+ my ($id,$type)=@_;
if (defined($ENV{"form.image.x"}) && defined($ENV{"form.image.y"})) {
- my $data=join(':',($ENV{"imagechoice.$id.coords"},$ENV{"form.image.x"},
- $ENV{"form.image.y"}));
+ my $data;
+ if ($type eq 'point') {
+ $data=join(':',(undef,$ENV{"form.image.x"},$ENV{"form.image.y"}));
+ } else {
+ $data=join(':',($ENV{"imagechoice.$id.coords"},
+ $ENV{"form.image.x"},$ENV{"form.image.y"}));
+ }
&Apache::lonnet::appenv("imagechoice.$id.coords"=>$data);
}
return int(scalar(split(':',$ENV{"imagechoice.$id.coords"}))/2);
@@ -219,7 +230,7 @@
}
my $type=$ENV{"imagechoice.$id.type"};
if (defined($ENV{'form.type'})) { $type=$ENV{'form.type'}; }
- my $numcoords=&savecoord($id);
+ my $numcoords=&savecoord($id,$type);
&Apache::lonnet::logthis("num coords is $numcoords");
my $imurl=&drawimage($r,$type,$filename,$id);
if (($ENV{'form.finish'} eq 'Finish')) {