#!/usr/local/mbin/perl

require "cgi-lib";

&ReadParse;

#check for existance of URL
if ($in{homepage} =~/http:\/\/$/) {
	$groupname=$in{groupname};
	}
else {
	$groupname=qq|<a href="$in{homepage}">$in{groupname}</a>|;
	}

#check to see if primary contact has an email address
if ($in{primaryemail} ne "") {
	$primecontact=qq|<a href="mailto:$in{primaryemail}">$in{primarycontactname}</a>|;
	}
else {
	$primecontact=$in{primarycontactname};
	}

#check to see if secondary contact has an email address
if ($in{secemail} ne "") {
	$seccontact=qq|<a href="mailto:$in{secemail}">$in{seccontactname}</a>|;
	}
else {
	$seccontact=$in{seccontactname};
	}

#Header
print "Content-type:text/html\n\n";
print "<title>Thank you for registering</title>";
print qq{<body background="../images/paletile.gif">};
print qq{<center><img src="../images/logo.gif"></center><br><br>};
print "<strong>$in{groupname}</strong>, thank you for registering. ";
print "Your usergroup entry will be added as soon as it has been checked.<br>";
print "A preview of your entry has been created below.<br>";
print qq{<img src="../images/amigasocsig.gif"><br><br>};
#Entry Generation
print qq|<table><tr><td colspan=8><font size="5">$groupname</font><br></td></tr>|;
print "<tr><td colspan=2><strong>MEETINGS</strong><br><hr width=100%></td><td width=5></td>";
print "<td colspan=5><strong>CONTACT INFORMATION<strong><br><hr width=100%></td></tr>";
print "<tr><td align=right valign=top><strong>Venue:</strong></td><td valign=top>$in{venue}<br>$in{location}</td>";
print "<td></td><td valign=top align=right><strong>Contact 1:</strong></td>";
print "<td valign=top>$primecontact<br>";
print "$in{primadd1}<br>$in{primadd2}<br>$in{primadd3}<br>$in{primadd4}</td>";
print "<td width=5></td><td valign=top align=right><strong>Contact 2:</strong></td>";
print "<td valign=top>$seccontact<br>";
print "$in{secadd1}<br>$in{secadd2}<br>$in{secadd3}<br>$in{secadd4}</td></tr>";
print "<tr><td colspan=6></td></tr>";
print "<tr><td valign=top align=right><strong>Time:</strong></td><td valign=top>$in{freq}";
print "<br>$in{time}</td> <td></td><td align=right valign=top><strong>Telephone:</strong></td>";
print "<td valign=top>$in{dayphone1}<br>$in{evephone1}</td>";
print "<td></td><td align=right valign=top><strong>Telephone:</strong></td>";
print "<td valign=top>$in{dayphone2}<br>$in{evephone2}</td></tr>";
print "<tr><td colspan=2><hr width=100%></td><td></td><td colspan=5><hr width=100%></td></tr></table>";
print "$in{Description}";
print "</body></html>";

#Mail the generated html and the contents of the form to me
open(MAIL,"|mail chrisl\@cursci.co.uk");
print MAIL "Subject: UserGroup Form\n";
print MAIL qq|<table><tr><td colspan=8><font size="5">$groupname</font><br></td></tr>\n|;
print MAIL "<tr><td colspan=2><strong>MEETINGS</strong><br><hr width=100%></td><td width=5></td>\n";
print MAIL "<td colspan=5><strong>CONTACT INFORMATION<strong><br><hr width=100%></td></tr>\n";
print MAIL "<tr><td align=right valign=top><strong>Venue:</strong></td><td valign=top>$in{venue}<br>$in{location}</td>\n";
print MAIL "<td></td><td valign=top align=right><strong>Contact 1:</strong></td>\n";
print MAIL "<td valign=top>$primecontact<br>\n";
print MAIL "$in{primadd1}<br>$in{primadd2}<br>$in{primadd3}<br>$in{primadd4}</td>\n";
print MAIL "<td width=5></td><td valign=top align=right><strong>Contact 2:</strong></td>\n";
print MAIL "<td valign=top>$seccontact<br>\n";
print MAIL "$in{secadd1}<br>$in{secadd2}<br>$in{secadd3}<br>$in{secadd4}</td></tr>\n";
print MAIL "<tr><td colspan=6></td></tr>\n";
print MAIL "<tr><td valign=top align=right><strong>Time:</strong></td><td valign=top>$in{freq}\n";
print MAIL "<br>$in{time}</td> <td></td><td align=right valign=top><strong>Telephone:</strong></td>\n";
print MAIL "<td valign=top>$in{dayphone1}<br>$in{evephone1}</td>\n";
print MAIL "<td></td><td align=right valign=top><strong>Telephone:</strong></td>\n";
print MAIL "<td valign=top>$in{dayphone2}<br>$in{evephone2}</td></tr>\n";
print MAIL "<tr><td colspan=2><hr width=100%></td><td></td><td colspan=5><hr width=100%></td></tr></table>\n";
print MAIL "$in{Description}\n\n\n";

foreach $i (keys(%in))
{
	print MAIL "$i = $in{$i}\n";
}
close (MAIL);
