#!/usr/bin/perl
#################### read info for this year: ############################
do "./INFO.pl";
##########################################################################
$VerisignLink="https://payflowlink.paypal.com";
$VerisignDomain="paypal.com";
##########################################################################
$logfile="/srv/www/cgi-bin/$Year_dir/Register/LOG";	# must chmod 666
$bgcolor="bgcolor=\"#009ebe\"";		# background color of webpages
##########################################################################

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;
    $value =~ s/\"/''/g;
    $FORM{$name} = $value;
    }
} else { &TestData(); }


	$fullname = $FORM{"fullname"};
	$email = $FORM{"email"};
	if ($email) {
		$emailnotif="<tt><b>$email</b></tt>";
		} else { $emailnotif="(<i>none</i>)"; }
	$phonenum = $FORM{"phonenum"};
	$country = $FORM{"country"};
	$affiliation = $FORM{"affiliation"};
	$category = $FORM{"category"};
	$method = $FORM{"method"};
	$addrform = $FORM{"addrform"};
#-mb: 
        $dates = $FORM{"dates"};
        $banquet = $FORM{"banquet"};
        $reception = $FORM{"reception"};
        $breakfast = $FORM{"breakfast"};
        $sex = $FORM{"sex"};
#
#-mb:   07_11_04: set also current date for logging:
        @mname=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
        ($sec,$min,$hour,$mday,$mon,$year) = localtime(time());
        $mbdate = sprintf("%d %s %2d %02d:%02d:%02d", $mday, $mname[$mon], 1900+$year, $hour, $min, $sec);


$amount = $FEE{$category};
$category =  $TYPE{$category};
&RecordInLog();

if ($method eq "check") { &ResponseForCheck(); }
if ($method eq "cardother") { &ResponseForCardother(); }
if ($method eq "verisign") { &VeriSign(); }
exit 0;

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

sub TestData {
%FORM =  (	"fullname" => "Test ''monkey'' User ",
		"email" => "random@colorado.edu",
		"phonenum" => "303-492-8995",
		"country" => "USA",
		"affil" => "appm UCB",
		"category" => "nonsiam_late",
		"method" => "cardother",
		"addrform" => "123 Main St.|||Colder, CO  80099"
		);
}

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

sub ResponseForCheck { print <<EOCHECK;
Content-Type: text/html\n\n
<html>
<head><title>$Acronym Submission Results</title></head>
<body bgcolor="#afdfaf">
<table width="88%" align=center cellpadding=20><tr><th>
<table align=center cellpadding=20 border=12><tr><td bgcolor="#bfbfff">
<center><h3>Thank you.  Your form has been submitted.</h3>
A confirmation email will be sent to you at <br> $emailnotif<br>
once the payment has been processed. 
<!-- ------------------------------------------------------------------------- 
This may take a little while because our server does not allow 
automatic e-mail response.
-->
<p>
To complete your registration,<br>
be sure to send a check for \$$amount.00 (US dollars)<br>
made out to <b>Copper Mtn. Conference</b><br>
to this address:
<table cellpadding=16><tr><td bgcolor=white><pre>
<b> <!-- old:
old:
    $Acronym
    University of Colorado
    Department of Applied Math
    526 UCB
    Boulder   CO   80309-0526
newer:
    COPPER MT. CONFERENCE 
    Annette Anthony, Conference Coordinator
    Front Range Scientific Computations
    8865 E. Calle Buena Vista
    Scottsdale, AZ 85255
    USA                 -->
    $Acronym
    $ConferenceCoordinator
    $ConferenceAddress1
    $ConferenceAddress2
    $ConferenceAddress3
    $ConferenceAddress4
</b></pre>
</td></tr></table>
</center>
</td></tr></table>
</th></tr></table>
</body>
</html>
EOCHECK
}

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

sub ResponseForCardother { print <<EOCO;
Content-Type: text/html\n\n
<html>
<head><title>$Acronym Submission Results</title></head>
<body bgcolor="#afdfaf">
<table width="88%" align=center cellpadding=20><tr><th>
<table align=center cellpadding=20 border=12><tr><td bgcolor="#bfbfff">
<center><h3>Thank you.  Your form has been submitted.</h3>
A confirmation email will be sent to you at <br> $emailnotif<br>
once the payment has been processed. 
<!--
This may take a little while because our server does not allow 
automatic e-mail response, so please be patient.
-->
<p>
To complete your registration,<br>
be sure to submit your credit card information<br>
(credit card type, number, and expiration date):
	<table cellpadding=12><tr><td bgcolor=white><UL>
<!--
	<p><li> fax it to <b>$Acronym &nbsp Attn: $TheMan</b>
		<br> &nbsp &nbsp fax number <b>303-492-4066</b>
	<p><li> email it to <tt>copper\@colorado.edu</tt> -->
	<p><li> phone or mail it to 
     <a href="http://grandmaster.colorado.edu/~copper/frsc.html">FRSC</a>
	<p><li> mail it in a letter to<pre>
<b>$Acronym
University of Colorado
Department of Applied Math   
526 UCB
Boulder   CO   80309-0526</b></pre>
</UL></td></tr></table>
</center>
</td></tr></table>
</th></tr></table>
</body>
</html>
EOCO
}

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

sub VeriSign { print <<EOV;
Content-Type: text/html\n\n
<html>
<head><title>$Acronym Submission Results</title></head>
<body bgcolor="#afdfaf">
<table width="88%" align=center cellpadding=20><tr><th>
<table cellpadding=20 border=12><tr><td bgcolor="#bfbfff">
<center><h3>Thank you.  Your form has been submitted.</h3>
A confirmation email will be sent to you at <br>$emailnotif
<br> once the transaction is completed and processed.
<p>
To complete your registration, you must submit your
credit card payment<br>by clicking on the following link
to a secure server ($VerisignDomain)<br>

<form method="POST" action="$VerisignLink">
    <input type="hidden" name="LOGIN" value="imacs03">
    <input type="hidden" name="PARTNER" value="VeriSign">
    <input type="hidden" name="AMOUNT" value="$amount">
    <input type="hidden" name="TYPE" value="S">
    <input type="hidden" name="DESCRIPTION"
	value="Copper Mt. $Year Conference Registration">
    <input type="submit" value="Click Here to Proceed to PayPal/VeriSign">
<p>
(<font color="red">Reminder about the cancellation policy:</font>
  No refunds will be given for cancellations after 
  $DeadlineRefund. 
<br>
  Full refunds less a \$$RefundFee service charge will be given if
  notified <b>before</b> $DeadlineRefund.)
</center>
</td></tr></table>
</th></tr></table>
</body>
</html>
EOV
}

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

sub RecordInLog {
	$addrform =~ s/\|\|\|/,   /g;

#--------------------------------------
# Try to send an email.
#--------------------------------------
open (MAIL,"| $sendmail -s \"$Acronym registration\" $eaddress") ||
	&LogError("cannot email (MAIL)");
print MAIL <<EOM;
\n=====================================================
NAME: $fullname 
EMAIL: $email
PHONE: $phonenum
COUNTRY: $country
AFFILIATION: $affiliation
ADDRESS: $addrform
CATEGORY: $category
AMOUNT:  \$$amount.00
PAYMENT METHOD:  $PayMethod{$method}
DATES OF INTENDED STAY: $dates
ATTENDING BANQUET: $banquet
ATTENDEE IS: $sex
-----------------------------------------------------\n
EOM


#--------------------------------------
# Log registration in a file.
#--------------------------------------
open (LOG,">>$logfile") || &LogError("cannot write to $logfile");
print LOG <<EOL;
\n=============================
DATE: $mbdate
NAME: $fullname
EMAIL: $email
PHONE: $phonenum
COUNTRY: $country
AFFILIATION: $affiliation
ADDRESS: $addrform
CATEGORY: $category
AMOUNT:  \$$amount.00
PAYMENT METHOD:  $PayMethod{$method}
DATES OF INTENDED STAY: $dates
ATTENDING BANQUET: $banquet
ATTENDING SUNDAY RECEPTION: $reception
DAYS ATTENDING BREAKFAST: $breakfast
ATTENDEE IS: $sex
-------------------------------------------\n
EOL
}

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

sub LogError {
	my ($problem) = @_;
	print <<EOERR;
Content-Type: text/html\n\n
<html>
<head><title>error</title></head>
<body bgcolor=red>
<table width="88%" align=center cellpadding=20><tr><th bgcolor=orange>
ERROR<p>$problem
</th></tr></table>
</body>
</html>
EOERR
exit 0;
}

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

__END__

