[LON-CAPA-cvs] cvs: loncom /cgi imagechoice.pl
www
lon-capa-cvs@mail.lon-capa.org
Sat, 10 May 2003 22:59:04 -0000
www Sat May 10 18:59:04 2003 EDT
Modified files:
/loncom/cgi imagechoice.pl
Log:
Does coordinate pairs now.
Index: loncom/cgi/imagechoice.pl
diff -u loncom/cgi/imagechoice.pl:1.3 loncom/cgi/imagechoice.pl:1.4
--- loncom/cgi/imagechoice.pl:1.3 Tue May 6 07:54:08 2003
+++ loncom/cgi/imagechoice.pl Sat May 10 18:59:04 2003
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
-# $Id: imagechoice.pl,v 1.3 2003/05/06 11:54:08 www Exp $
+# $Id: imagechoice.pl,v 1.4 2003/05/10 22:59:04 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,13 +37,18 @@
my $formname = $data{'formname'};
my $formx = $data{'formx'};
my $formy = $data{'formy'};
+my $mode=$data{'mode'};
my $formwidth = $data{'formwidth'};
my $formheight = $data{'formheight'};
+my $formcoord=$data{'formcoord'};
# unescape filename
$filename =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
-
-if ((defined($data{'x'})) && (defined($data{'y'}))) {
+#
+# Single coordinate, defined - store it
+#
+if ((defined($data{'x'})) && (defined($data{'y'})) &&
+ ($mode ne 'pairtwo') && ($mode ne 'pairthree')) {
my $output='';
if ($data{'formwidth'}) {
$output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formwidth'}.
@@ -77,20 +82,72 @@
</body>
</html>
ENDSUBM
+#
+# Coordinate Pair, Second Coordinate
+#
+} elsif ($mode eq 'pairthree') {
+ my $output='';
+ my $outputpair="($data{'selx'},$data{'sely'})-($data{'x'},$data{'y'})";
+ if ($data{'formwidth'}) {
+ $output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formwidth'}.
+ '.value=document.pickimg.width;';
+ }
+ if ($data{'formheight'}) {
+ $output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formheight'}.
+ '.value=document.pickimg.height;';
+ }
+ if ($data{'formcoord'}) {
+ $output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formcoord'}.
+ '.value="'.$outputpair.'";';
+ }
+ print <<"ENDCOORDSUB";
+Content-type: text/html
+
+<html>
+<script>
+ function submitthis() {
+ $output
+ self.close();
+ }
+</script>
+<body bgcolor="#FFFFFF" onLoad="submitthis()">
+<h3>Coordinates Selected</h3>
+<img name="pickimg" src="$filename" />
+</body>
+</html>
+ENDCOORDSUB
+#
+# First and second call
+#
} else {
+ my $heading='Position';
+ my $nextstage='';
+ if ($mode eq 'pair') {
+ $heading='First Coordinate';
+ $nextstage='<input type="hidden" name="mode" value="pairtwo" />';
+ } elsif ($mode eq 'pairtwo') {
+ $heading='Second Coordinate';
+ $nextstage=<<ENDNEXTSTAGE;
+<input type="hidden" name="mode" value="pairthree" />
+<input type="hidden" name="selx" value="$data{'x'}" />
+<input type="hidden" name="sely" value="$data{'y'}" />
+ENDNEXTSTAGE
+ }
print <<"END";
Content-type: text/html
<html>
<body bgcolor="#FFFFFF">
-<h3>Select Position on Image</h3>
+<h3>Select $heading on Image</h3>
<form>
<input type="hidden" name="formname" value="$formname" />
<input type="hidden" name="formx" value="$formx" />
<input type="hidden" name="formy" value="$formy" />
+<input type="hidden" name="formcoord" value="$formcoord" />
<input type="hidden" name="formwidth" value="$formwidth" />
<input type="hidden" name="formheight" value="$formheight" />
<input type="hidden" name="file" value="$filename" />
+$nextstage
<input type="image" src="$filename" />
</form>
</body>