Annotation of loncom/cgi/imagechoice.pl, revision 1.4

1.1       www         1: #!/usr/bin/perl
                      2: #
1.4     ! www         3: # $Id: imagechoice.pl,v 1.3 2003/05/06 11:54:08 www Exp $
1.1       www         4: #
                      5: # Copyright Michigan State University Board of Trustees
                      6: #
                      7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      8: #
                      9: # LON-CAPA is free software; you can redistribute it and/or modify
                     10: # it under the terms of the GNU General Public License as published by
                     11: # the Free Software Foundation; either version 2 of the License, or
                     12: # (at your option) any later version.
                     13: #
                     14: # LON-CAPA is distributed in the hope that it will be useful,
                     15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     17: # GNU General Public License for more details.
                     18: #
                     19: # You should have received a copy of the GNU General Public License
                     20: # along with LON-CAPA; if not, write to the Free Software
                     21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     22: #
                     23: # /home/httpd/cgi-bin/plot.gif
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: use strict;
                     28: 
                     29: $|=1;
                     30: 
                     31: my %data;
                     32: foreach (split/&/,$ENV{'QUERY_STRING'}) {
                     33:     my ($name,$value)=split/=/;
                     34:     $data{$name}=$value;
                     35: }
                     36: my $filename = $data{'file'};
                     37: my $formname = $data{'formname'};
                     38: my $formx = $data{'formx'};
                     39: my $formy = $data{'formy'};
1.4     ! www        40: my $mode=$data{'mode'};
1.1       www        41: my $formwidth = $data{'formwidth'};
                     42: my $formheight = $data{'formheight'};
1.4     ! www        43: my $formcoord=$data{'formcoord'};
1.1       www        44: # unescape filename
                     45: $filename =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                     46: 
1.4     ! www        47: #
        !            48: # Single coordinate, defined - store it
        !            49: #
        !            50: if ((defined($data{'x'})) && (defined($data{'y'})) && 
        !            51:     ($mode ne 'pairtwo') && ($mode ne 'pairthree')) {
1.2       www        52:     my $output='';
                     53:     if ($data{'formwidth'}) {
1.3       www        54: 	$output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formwidth'}.
1.2       www        55: 	    '.value=document.pickimg.width;';
                     56:     }
                     57:     if ($data{'formheight'}) {
1.3       www        58: 	$output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formheight'}.
1.2       www        59: 	    '.value=document.pickimg.height;';
                     60:     }
                     61:     if ($data{'formx'}) {
1.3       www        62: 	$output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formx'}.
1.2       www        63: 	    '.value='.$data{'x'}.';';
                     64:     }
                     65:     if ($data{'formy'}) {
1.3       www        66: 	$output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formy'}.
1.2       www        67: 	    '.value='.$data{'y'}.';';
                     68:     }
1.1       www        69:     print <<"ENDSUBM";
                     70: Content-type: text/html
                     71: 
                     72: <html>
                     73: <script>
                     74:     function submitthis() {
1.2       www        75: 	$output
1.3       www        76: 	self.close();
1.1       www        77:     }
                     78: </script>
                     79: <body bgcolor="#FFFFFF" onLoad="submitthis()">
                     80: <h3>Position Selected</h3>
                     81: <img name="pickimg" src="$filename" />
                     82: </body>
                     83: </html>
                     84: ENDSUBM
1.4     ! www        85: #
        !            86: # Coordinate Pair, Second Coordinate
        !            87: #
        !            88: } elsif ($mode eq 'pairthree') {
        !            89:     my $output='';
        !            90:     my $outputpair="($data{'selx'},$data{'sely'})-($data{'x'},$data{'y'})";
        !            91:     if ($data{'formwidth'}) {
        !            92: 	$output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formwidth'}.
        !            93: 	    '.value=document.pickimg.width;';
        !            94:     }
        !            95:     if ($data{'formheight'}) {
        !            96: 	$output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formheight'}.
        !            97: 	    '.value=document.pickimg.height;';
        !            98:     }
        !            99:     if ($data{'formcoord'}) {
        !           100: 	$output.='opener.document.forms.'.$data{'formname'}.'.'.$data{'formcoord'}.
        !           101: 	    '.value="'.$outputpair.'";';
        !           102:     }
        !           103:     print <<"ENDCOORDSUB";
        !           104: Content-type: text/html
        !           105: 
        !           106: <html>
        !           107: <script>
        !           108:     function submitthis() {
        !           109: 	$output
        !           110: 	self.close();
        !           111:     }
        !           112: </script>
        !           113: <body bgcolor="#FFFFFF" onLoad="submitthis()">
        !           114: <h3>Coordinates Selected</h3>
        !           115: <img name="pickimg" src="$filename" />
        !           116: </body>
        !           117: </html>
        !           118: ENDCOORDSUB
        !           119: #
        !           120: # First and second call
        !           121: #
1.1       www       122: } else {
1.4     ! www       123:     my $heading='Position';
        !           124:     my $nextstage='';
        !           125:     if ($mode eq 'pair') {
        !           126:        $heading='First Coordinate';
        !           127:        $nextstage='<input type="hidden" name="mode" value="pairtwo" />';
        !           128:    } elsif ($mode eq 'pairtwo') {
        !           129:        $heading='Second Coordinate';
        !           130:        $nextstage=<<ENDNEXTSTAGE;
        !           131: <input type="hidden" name="mode" value="pairthree" />
        !           132: <input type="hidden" name="selx" value="$data{'x'}" />
        !           133: <input type="hidden" name="sely" value="$data{'y'}" />
        !           134: ENDNEXTSTAGE
        !           135:    }
1.1       www       136:     print <<"END";
                    137: Content-type: text/html
                    138: 
                    139: <html>
                    140: <body bgcolor="#FFFFFF">
1.4     ! www       141: <h3>Select $heading on Image</h3>
1.1       www       142: <form>
                    143: <input type="hidden" name="formname" value="$formname" />
                    144: <input type="hidden" name="formx" value="$formx" />
                    145: <input type="hidden" name="formy" value="$formy" />
1.4     ! www       146: <input type="hidden" name="formcoord" value="$formcoord" />
1.1       www       147: <input type="hidden" name="formwidth" value="$formwidth" />
                    148: <input type="hidden" name="formheight" value="$formheight" />
                    149: <input type="hidden" name="file" value="$filename" />
1.4     ! www       150: $nextstage
1.1       www       151: <input type="image" src="$filename" />
                    152: </form>
                    153: </body>
                    154: </html>
                    155: END
                    156: }
                    157: 
                    158: 
                    159: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>