#!/usr/bin/perl -w

# Image Rotator for forums. Version 1.0
# For use with AnyMail version 1.23 and above.
# 
# This script is used to rotate images in an AnyMail form to require users to
# enter a valid key in order to submit though the program.
#
#


$|=1;

# the first variable is the full system path to the fimages directory,
# which should be uploaded somewhere in your web files space:

my $img_path = '/home2/symbio/genuinewinner.com/fimages/';

# Next is the full URL to that same directory which contains your images.

my $img_url = 'http://www.genuinewinner.com/fimages/';

# Set the width of height of your images. If you are not using SSI this will have
# no effect. You can however set it in your forms like so:
#  <img src="/cgi-share/img.cgi?nonssi" width="181" height="60">

my $img_width = '181';
my $img_height = '60';

# No More Confiurations

#temporary hack until I have time to write this. Use a hash to test
# against the imputed text. If it exists, let them post. If not, then
# tell the to go away... This script just prints the images to location.

my $IIS = 1 if ($ENV{'SERVER_SOFTWARE'} =~ m!IIS!i);
chdir($1) if (($IIS) && ($0 =~ m!(.*)(\\|\/)!));

opendir(CHKDIR,"$img_path") or die "can't open the image files directory $!";
my @images = grep(/\.gif$/,readdir(CHKDIR));
closedir(CHKDIR) or die "Can't close images directory $!\n";

my $random = int(rand(@images));
$image = $images[$random];

my $full_url = $img_url . $image;
unless ((defined $ENV{'QUERY_STRING'}) &&($ENV{'QUERY_STRING'} !~ /^\s*$/)){
                print "Content-Type: text/html\r\n\r\n";
                my $string = qq~ <img src="$full_url" width="$img_width" height="$img_height">~;
                print $string;
                exit;
}


if ($ENV{'QUERY_STRING'} eq 'nonssi') {
                                       print_image($full_url);
                                       exit;
}
else {
      print "Content-Type: text/html\r\n\r\n";
      print "Invalid Call!!! $ENV{'QUERY_STRING'}";
      exit;

}




sub print_image {
                 my $full_url = $_[0];

	         print "HTTP/1.0 200 OK\r\n" if ($IIS);
	         print "Pragma: no-cache\r\n";
	         print "Expires: Saturday, February 15, 1997 10:10:10 GMT\r\n";
		 print "Location: $full_url\r\n\r\n";
		 exit;


}


