#! /usr/local/bin/perl

# leifform.cgi
# 
# Written by Leif M. Wright
# leif@conservatives.net
#
#************************************************************************
# I got really ticked when the form response programs I wanted to use
# all wanted to send me an e-mail. I don't want an email.
# So I wrote this VERY simply program to post the data to a logfile and
# redirect the user to a "form successful" page. That's all it does. Period.
# If you want a fancy form handler, go somewheres else, but I just
# wanted a simple script to post form data to a logfile
# Your form should have action=post
# For every input name on your form, you'll have to add it to the
# script below, and decide whether to make it required or not.
# Enjoy
# I'm not guilty or responsible if this screws up your system. It works 
# fine on mine.
##################################################################
#

# this tells the program where to place a link for the user
# once they are done.
$link ="http://www.clan-xs.co.uk";

# this is where the info will be written to - you need to specify a real directory
$file ="/usr/local/webs/pq3net/demohq/cgi-bin/fixturelist.txt"; #must be read/writable

#
##################################################################

if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs)
	{
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$contents{$name} = $value;
	     
	}
}

chop($date = `date`);

# Now with the program
###########################################################
# Has to output a Content-type
print "Content-type: text/html\n\n ";

# Check to see if all required information was entered
# If you want a field to be required, add it here.

sub no_cigar
{
print <<"HTML";
<HTML><HEAD><TITLE>Form Incomplete</TITLE></HEAD>
<BODY>
<H1>Form Incomplete</H1>
I'm sorry, the form was not filled completely.<br>
Please Return to the form and fill it out completely.<p>
Thank you.
<HR>
<a href=\"$contents{'url'}\">Return to the $contents{'formname'} page</a>
</BODY></HTML>
HTML
exit;
}



# They go here if the form was submitted 
# successfully. Now this page will send them
# off to where ever specify in the "link" field above.

print <<"HTML";
<HTML><HEAD><TITLE>Entry successful</TITLE></HEAD>
<BODY>
<H1>Entry successful!</H1>
<p>
<hr noshade>
<p>
<H2>I have received your fixture!</H2>
Your information will be processed immediately, 
Thank you.

<p>
<HR noshade>
<A HREF=\"$link\">Back To Clan[Xs] Webbeh</A>.
<a href="http://www.demohq.com/fixtures.shtml">View Fixtures Page</a>.
</BODY>
</HTML>
HTML
#print "Content-type: text/plain\n\n ";
open(OUTPUT, ">>$file");
print OUTPUT "<td>\n";
print OUTPUT "<a class=cavlinkcenter>\n";
print OUTPUT "<center>\n";
print OUTPUT "$contents{'dateadded'}\n";
print OUTPUT "<td>\n";
print OUTPUT "<a class=cavlinkcenter>\n";
print OUTPUT "<center>\n";
print OUTPUT "$contents{'timeadded'}\n";
print OUTPUT "<td>\n";
print OUTPUT "<a class=cavlinkcenter>\n";
print OUTPUT "<center>\n";
print OUTPUT "$contents{'opponent'}\n";
print OUTPUT "<td>\n";
print OUTPUT "<a class=cavlinkcenter>\n";
print OUTPUT "<center>\n";
print OUTPUT "$contents{'map'}\n";
print OUTPUT "<td>\n";
print OUTPUT "<a class=cavlinkcenter>\n";
print OUTPUT "<center>\n";
print OUTPUT "$contents{'gametype'}\n";
print OUTPUT "<tr>\n";

close (OUTPUT);
exit;
