#!/usr/local/bin/perl

# by R. Bradley (April 1996)

$MAIL = "/usr/ucb/mail -s registration algorith\@cs.sunysb.edu";
$OUTFILE = "/users/skiena.dir/algorith/reply.database";

BEGIN {
	unshift(@INC,'/users/skiena.dir/algorith/public_html/cgi-bin');
}
use CGI;

$query = new CGI ();
$host=$query->remote_host();     # remote user's host name
$ident=$query->remote_ident();   # remote user's username

print <<EOF;
Content-type:  text/html

<HTML><HEAD><TITLE>Algorithm Book Reponse</TITLE></HEAD>
<BODY BGCOLOR=#ffffff>
EOF
	;
open (OUTFILE, ">> $OUTFILE") || &fail;

sub fail
{
print <<EOX;
<H1>Unsuccessful Registration</H1><P>
<HR>
We are sorry that we were unable to 
process your information at this time.
Please try again in the near future.<P>
<HR size=3>
<A HREF="mailto:algorith\@cs.sunysb.edu">Send us Mail</A>
<BR><A HREF="http://www.cs.sunysb.edu/~algorith/index.html">Go to Main Page</A>

</BODY></HTML>
EOX
	;
	 exit(0);
}

open (MAILPIPE, "| $MAIL");  #won't error check here...

printf MAILPIPE "New registration record:\n\n";

@names= $query->param;           # form input from CGI
while (@names)
{
   $name = shift (@names);
   $val = $query->param($name);
   printf OUTFILE "$name=$val^";
   printf MAILPIPE "$name=$val^";
}

printf OUTFILE "remote-host=$host:";
printf MAILPIPE "remote-host=$host:";
printf OUTFILE "remote-ident=$ident\n";
printf MAILPIPE "remote-ident=$ident\n";


printf MAILPIPE "\n.\n"; close MAILPIPE;
close OUTFILE;

print <<EOT;
<H1>Successful Registration</H1><P>
<HR>
Your registration information has been entered into our database.
	We thank you for your interest in this site and the forthcoming book, 
	and will keep you informed of significant future developments.<P>
<HR size=3>
<A HREF="mailto:algorith\@cs.sunysb.edu">Send us Mail</A>
<BR><A HREF="http://www.cs.sunysb.edu/~algorith/index.html">Go to Main Page</A>

</BODY></HTML>
EOT
	;
exit(0);
