#!/usr/local/bin/perl
#----------------- STmail.pl ------------------------------------
#
#----------------------------------------------------------------
# Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
# Edited for use by
# Steve Snyder 7/24/95
# G J Perkins 1995.07.26 - some minor refinements
# C P Wilkinson 1996.01.05 - more refinements
# Mouse 1996.07.30 - shrink to fit for graduate homepage
# David Tomanek 1998.07.24 - modified and updated for conferences
# J R Bowes 2004.04.07 - copied to /h0/brock/www/file_sharing as reg.cgi
# Chip Brock 2004.04.08 - working on Jeff's version -> my email 
#----------------------------------------------------------------

# Define fairly-constants
$mailprog = '/usr/bin/mail';
$recipient = 'neuman@pa.msu.edu, brock@pa.msu.edu, weerts@pa.msu.edu';
#$recipient = 'brock@pa.msu.edu';
#$recipient = 'weerts@pa.msu.edu';
#$recipient = 'brock@fnal.gov';
#$recipient = 'brockr@msu.eduš';

# Print out what we need
print "Content-type: text/html\n\n";
print "<Head>";
print "<title> Registration</title>";
print "</Head>";
print "Your registration information has been received";
print " and will be processed within 48 hours.<BR>";
#print "If you have questions, please contact Ms. Lorie Neuman:<br>";
#print "<a href='mailto:neuman@pa.msu.edu'>'neuman@pa.msu.edu' .</a><p>";
print "<a href=http://www.pa.msu.edu/hep/conf/hcp2004/reg_b1.html>";
print "back: HCP2004 Registration Page</a><br><br>";
print "<a href=http://www.pa.msu.edu/hep/conf/hcp2004/>";
print "HCP2004 Home Page</a><br><br>";

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@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;

    # Stop people from using subshells to execute commands
    $value =~ s/~!/ ~!/g;

    # Uncomment for debugging purposes
    # print "Setting $name to $value<P>";

    $FORM{$name} = $value;
}

# Now send mail to $recipient

 if ($FORM{'interest'} eq "")    {$FORM{'interest'}    = '?';}
 if ($FORM{'present'} eq "")     {$FORM{'present'}     = '?';}
 if ($FORM{'presenttitle'} eq ""){$FORM{'presenttitle'}= ' ';}

 if ($FORM{'title'} eq "")       {$FORM{'title'}       = '?';}
 if ($FORM{'firstname'} eq "")   {$FORM{'firstname'}   = '';}
 if ($FORM{'midname'} eq "")     {$FORM{'midname'}     = '';}
 if ($FORM{'famname'} eq "")     {$FORM{'famname'}     = '?';}
 if ($FORM{'org'} eq "")         {$FORM{'org'}         = '?';}
 if ($FORM{'address1'} eq "")    {$FORM{'address1'}    = '';}
 if ($FORM{'address2'} eq "")    {$FORM{'address2'}    = '';}
 if ($FORM{'city'} eq "")        {$FORM{'city'}        = '';}
 if ($FORM{'state'} eq "")       {$FORM{'state'}       = '';}
 if ($FORM{'zip'} eq "")         {$FORM{'zip'}         = '';}
 if ($FORM{'country'} eq "")     {$FORM{'country'}     = '';}

 if ($FORM{'email'} eq "")       {$FORM{'email'}       = 'unknown';}
# if ($FORM{'url'} eq "")         {$FORM{'url'}         = 'http://www.pa.msu.edu/cmp/csc/NANOTUBE-99/';}
 if ($FORM{'faxnum'} eq "")      {$FORM{'faxnum'}      = '';}
 if ($FORM{'phonum'} eq "")      {$FORM{'phonum'}      = '';}

 if ($FORM{'arrivedate'} eq "")  {$FORM{'arrivedate'}  = '';}
 if ($FORM{'departdate'} eq "")  {$FORM{'departdate'}  = '';}
 if ($FORM{'arrivetime'} eq "")  {$FORM{'arrivetime'}  = '';}
 if ($FORM{'arrivemeans'} eq "") {$FORM{'arrivemeans'} = '';}

 if ($FORM{'lodging'} eq "")     {$FORM{'lodging'}     = '';}

 if ($FORM{'details'} eq "")     {$FORM{'details'}     = '';}

 if ($FORM{'Subject'} eq "")     {$FORM{'Subject'}     = "HCP2004 Reg: $FORM{'famname'}";}

open (MAIL, "|$mailprog $recipient ") || die "Can't open $mailprog!\n";
print MAIL "Subject:  $FORM{'Subject'}\n";
print MAIL "Reply-To: $FORM{'email'}\n";
print MAIL " \n";
print MAIL "$FORM{'Subject'}\n";
print MAIL "\n------------------------------------------------------------\n";
print MAIL "        Registration Form#:  3 \n";
print MAIL "\n------------------------------------------------------------\n";
#print MAIL " Workshop Related Information.\n";
#print MAIL "         Level of interest: $FORM{'interest'}\n";
#print MAIL " Will present contribution: $FORM{'present'}\n";
#print MAIL "     Title of contribution: $FORM{'presenttitle'}\n";
#print MAIL " \n";
print MAIL "\n------------------------------------------------------------\n";
print MAIL " Registration Information.\n";
print MAIL "            Title: $FORM{'title'}.\n";
print MAIL "       First Name: $FORM{'firstname'}\n";
print MAIL "      Middle Name: $FORM{'midname'}\n";
print MAIL "      Family Name: $FORM{'famname'}\n";
print MAIL "      Institution: $FORM{'org'}\n";
print MAIL " Address (line 1): $FORM{'address1'}\n";
print MAIL " Address (line 2): $FORM{'address2'}\n";
print MAIL "             City: $FORM{'city'}\n";
print MAIL "   State/Province: $FORM{'state'}\n";
print MAIL "         ZIP Code: $FORM{'zip'}\n";
print MAIL "          Country: $FORM{'country'}\n";
print MAIL "   E-Mail Address: $FORM{'email'}\n";
print MAIL "    Home Page URL: $FORM{'url'}\n";
print MAIL "       FAX Number: $FORM{'faxnum'}\n";
print MAIL "     Phone Number: $FORM{'phonum'}\n";
print MAIL "\n------------------------------------------------------------\n";
print MAIL " Travel and Accommodation.\n";
print MAIL "      Date of Arrival: $FORM{'arrivedate'}\n";
print MAIL "      Time of Arrival: $FORM{'arrivetime'}\n";
print MAIL "  Further Information: $FORM{'arrivemeans'}\n";
print MAIL "    Date of Departure: $FORM{'departdate'}\n";
print MAIL "  Hotel Accommodation: $FORM{'lodging'}\n";
print MAIL "\n------------------------------------------------------------\n";
print MAIL " Additional Information.\n";
print MAIL "$FORM{'details'}\n";
print MAIL "\n------------------------------------------------------------\n";
print MAIL " Listing in file hcp2004RegList.html : $FORM{'listing'} \n\n";
print MAIL "<LI><P>\n";
print MAIL " <A HREF=$FORM{'url'}>\n";
print MAIL " $FORM{'title'}. $FORM{'firstname'} $FORM{'midname'} $FORM{'famname'}</A><BR>\n";
print MAIL " $FORM{'org'} <BR>\n";
print MAIL " $FORM{'address1'} <BR>\n";
print MAIL " $FORM{'address2'} <BR>\n";
print MAIL " $FORM{'city'}, $FORM{'state'} $FORM{'zip'} <BR>\n";
print MAIL " $FORM{'country'} <BR>\n";
print MAIL " $FORM{'phonum'} (phone) <BR>\n";
print MAIL " $FORM{'faxnum'} (fax) <BR>\n";
print MAIL " <A HREF=mailto:$FORM{'email'}>\n";
print MAIL "                $FORM{'email'}\n";
print MAIL " </A></P>\n";
print MAIL "\n------------------------------------------------------------\n";
#print MAIL " Listing in file nt99-titles-chron.html : \n\n";
#print MAIL "<LI>\n";
#print MAIL "<B>&quot;$FORM{'presenttitle'}&quot;</B><BR>\n";
#print MAIL "$FORM{'firstname'} $FORM{'famname'}\n";
#print MAIL "</LI>\n\n";
#print MAIL "\n------------------------------------------------------------\n";
close (MAIL);
