<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Confirmation Page</title>
</head>
<body>


<?php
include_once('./class.phpmailer.php');

  



$title = $_POST['title'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$organisation = $_POST['organisation'];
$street = $_POST['street'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$regType = $_POST['regType'];
$posterpaper = $_POST['posterpaper'];
$badgeName = $_POST['badgeName'];
$dietaryRequirements = $_POST['dietaryRequirements'];
$specialNeeds=$_POST['specialNeeds'];


$okk=$_POST['ok'];




//validation

if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo "<h2>Invalid e-mail address. Please use back to change it...</h2>\n";

die ("Go back! ! ");
}

if(empty($firstName) || empty($lastName) || empty($badgeName) ) {
echo "<h2>Please use back to complete all required fields...</h2>\n";
die ("Use back! ! ");
}

//search for special characters such as , and " '
//replace them with - and ^
// " first
$bad=array('\"','\'');
$good="^";
$title = str_replace($bad,$good,$title);
$firstName = str_replace($bad,$good,$firstName);
$lastName = str_replace($bad,$good,$lastName);
$email = str_replace($bad,$good,$email);
$phone = str_replace($bad,$good,$phone);
$fax = str_replace($bad,$good,$fax);
$organisation = str_replace($bad,$good,$organisation);
$street = str_replace($bad,$good,$street);
$city = str_replace($bad,$good,$city);
$postcode = str_replace($bad,$good,$postcode);
$country = str_replace($bad,$good,$country);
$regType = str_replace($bad,$good,$regType);
$posterpaper = str_replace($bad,$good,$posterpaper);
$badgeName = str_replace($bad,$good,$badgeName);
$dietaryRequirements = str_replace($bad,$good,$dietaryRequirements);
$specialNeeds=str_replace($bad,$good,$specialNeeds);
// ,second

$title = str_replace(",","-",$title);
$firstName = str_replace(",","-",$firstName);
$lastName = str_replace(",","-",$lastName);
$email = str_replace(",","-",$email);
$phone = str_replace(",","-",$phone);
$fax = str_replace(",","-",$fax);
$organisation = str_replace(",","-",$organisation);
$street = str_replace(",","-",$street);
$city = str_replace(",","-",$city);
$postcode = str_replace(",","-",$postcode);
$country = str_replace(",","-",$country);
$regType = str_replace(",","-",$regType);
$posterpaper = str_replace(",","-",$posterpaper);
$badgeName = str_replace(",","-",$badgeName);
$dietaryRequirements = str_replace(",","-",$dietaryRequirements);
$specialNeeds=str_replace(",","-",$specialNeeds);


//check if the email already existed

//loop through the file
$CSVDIR = "./"; // directory for csv files...
$CSVFILE = "reginfo.csv"; // csv file name
$cols= "$title,$firstName,$lastName,$email,$phone,$fax,$organisation,$street,$city,$postcode,$country,$regType,$posterpaper,$badgeName,$dietaryRequirements,$specialNeeds\n";

$found = false;
$fhandle = fopen ($CSVFILE,'r');


    while (!feof($fhandle) && !$found) {

        $buffer = fgets($fhandle);

	  	      
	if (strstr($buffer, $email)) $found= true;
    }


fclose($fhandle);

if ( $found==true) 
{
echo "<h2>You have already registered using this email address. Please use back to register using different email address...</h2>\n";
die ("Use back! ! ");
}





$confirmWin="<form method=\"post\" action=\"confirm.php\">

Please review the information below and then click confirm to submit the application form or click back to update it.
<br /><input type=\"submit\" value=\"Confirm\">
<input type=\"hidden\" name = \"ok\" value=\"ok\">
<input type=\"hidden\" name = \"firstName\" value=\"$firstName\">
<input type=\"hidden\" name = \"lastName\" value=\"$lastName\">
<input type=\"hidden\" name = \"phone\" value=\"$phone\">
<input type=\"hidden\" name = \"city\" value=\"$city\">
<input type=\"hidden\" name = \"fax\" value=\"$fax\">
<input type=\"hidden\" name = \"email\" value=\"$email\">
<input type=\"hidden\" name = \"street\" value=\"$street\">
<input type=\"hidden\" name = \"country\" value=\"$country\">
<input type=\"hidden\" name = \"regType\" value=\"$regType\">
<input type=\"hidden\" name = \"posterpaper\" value=\"$posterpaper\">
<input type=\"hidden\" name = \"postcode\" value=\"$postcode\">
<input type=\"hidden\" name = \"title\" value=\"$title\">
<input type=\"hidden\" name = \"organisation\" value=\"$organisation\">
<input type=\"hidden\" name = \"badgeName\" value=\"$badgeName\">
<input type=\"hidden\" name = \"dietaryRequirements\" value=\"$dietaryRequirements\">
<input type=\"hidden\" name = \"specialNeeds\" value=\"$specialNeeds\">

</form>";

if(!empty($okk) ) {
//internal message
$message = "Title: $title \n
First Name: $firstName \n
Last Name: $lastName \n
Email address: $email\n
Phone number: $phone \n
Fax number: $fax \n
Organisation: $organisation \n
Street / P.O. Box: $street \n
City: $city \n
Postal/Zip code: $postcode \n
Country: $country \n
Registraton Type: $regType \n
Poster/Paper: $posterpaper \n
Name to appear on Badge: $badgeName \n
Special Dietary requirements: $dietaryRequirements\n
Special Needs: $specialNeeds
";

$from = "tphols@in.tum.de";

$subject="TPHOLs 2009 Registration Confirmation";




$mail = new PHPMailer();
$mail->IsSMTP(); 
$mail->Host     = "mailbroy.in.tum.de";



  
$mail->From = $from;
$mail->FromName = "TPHOLs 2009";
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AddAddress($from, "");

if(!$mail->Send()) {
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
}





//confirmation message
$message = "Thank for you registering for TPHOLs 2009. We received your information.\nIf you have not done so already, please pay your registration fee via MuenchenTicket.\n\nTPHOLs 2009 Organizing Committee";
$from = "tphols@in.tum.de";

$subject="TPHOLs 2009 Registration Confirmation";
//mail($email, $subject, $message, $from);
$mail = new PHPMailer();
$mail->IsSMTP(); 
$mail->Host     = "mailbroy.in.tum.de";

  
$mail->From = $from;
$mail->FromName = "TPHOLs 2009";
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AddAddress($email, "");

if(!$mail->Send()) {
echo 'Mailer error: '.  $mail->ErrorInfo;

} else {
}


//store information
$CSVDIR = "./"; // directory for csv files...
$CSVFILE = "reginfo.csv"; // csv file name
$cols= "$title,$firstName,$lastName,$email,$phone,$fax,$organisation,$street,$city,$postcode,$country,$regType,$posterpaper,$badgeName,$dietaryRequirements,$specialNeeds\n";

$file_handle = fopen($CSVFILE, "a");
fwrite($file_handle, $cols);


fclose($file_handle);




// print report
$res="<br />
The Registration process is completed. You will receive a confirmation e-mail in a few minutes.
<br />

<p><big>If you have not done so already, please pay your registration fee via <a href=\"http://tphols.in.tum.de/fee.html\">MuenchenTicket</a>.
Registration is not assured until payment has been received.
</big></p>

<br />
<a href=\"http://tphols.in.tum.de/\">TPHOLs 2009</a>
";
echo $res;

}
else {

$message = "Title: $title <br />
First Name: $firstName <br />
Last Name: $lastName <br />
Email address: $email<br />
Phone number: $phone <br />
Fax number: $fax <br />
Organisation: $organisation <br />
Street / P.O. Box: $street <br />
City: $city <br />
Postal/Zip code: $postcode <br />
Country: $country <br />
Registraton Type: $regType <br />
Poster/Paper: $posterpaper <br />
Name to appear on Badge: $badgeName <br />
Special Dietary requirements: $dietaryRequirements <br />
Special Needs: $specialNeeds <br /><br />

";
echo $confirmWin;
 echo $message ;

}
?>

</body>
</html>
