<? include("../settings.php"); ?>
<?
	if ($_REQUEST['confirm']!=""){
		if ($_REQUEST['registrant_salutation']=="0")
			$salutation = $_REQUEST['registrant_salutation1'];
		else
			$salutation = $_REQUEST['registrant_salutation'];
		if ($_REQUEST['registrant_firstname']=="")
			$firstname = $_REQUEST['registrant_firstname1'];
		else
			$firstname = $_REQUEST['registrant_firstname'];
		if ($_REQUEST['registrant_lastname']=="")
			$lastname = $_REQUEST['registrant_lastname1'];
		else
			$lastname = $_REQUEST['registrant_lastname'];
		if ($_REQUEST['registrant_email']=="")
			$email = $_REQUEST['registrant_email1'];
		else
			$email = $_REQUEST['registrant_email'];
		
		if ($_REQUEST['registrant_diet']=="Others")
			$diet = $_REQUEST['diet_others'];
		else
			$diet = $_REQUEST['registrant_diet'];
		if ($_REQUEST['registrant_diet1']=="Others")
			$diet1 = $_REQUEST['diet_others1'];
		else
			$diet1 = $_REQUEST['registrant_diet1'];
		if ($_REQUEST['registrant_diet2']=="Others")
			$diet2 = $_REQUEST['diet_others2'];
		else
			$diet2 = $_REQUEST['registrant_diet2'];
        $insert = array(
			"registrant_type"=>$_REQUEST['registration_type'],
			"registrant_salutation"=>$salutation,
			"registrant_firstname"=>$firstname,
			"registrant_lastname"=>$lastname,
			"registrant_organisation"=>$_REQUEST['registrant_organisation'],
			"registrant_designation"=>$_REQUEST['registrant_designation'],
			"registrant_email"=>$email,
			"registrant_mobilecc"=>$_REQUEST['registrant_contactcc'],
			"registrant_mobile"=>$_REQUEST['registrant_contact'],
			"registrant_officecc"=>$_REQUEST['registrant_officecc'],
			"registrant_office"=>$_REQUEST['registrant_office'],
			"registrant_mailing"=>$_REQUEST['registrant_mailing'],
			"registrant_city"=>$_REQUEST['registrant_city'],
			"registrant_state"=>$_REQUEST['registrant_state'],
			"registrant_postal"=>$_REQUEST['registrant_postal'],
			"registrant_country"=>$_REQUEST['registrant_country'],
			"registrant_diet"=>$diet,
			"registrant_reception"=>$_REQUEST['registrant_reception'],
			"registrant_dinner"=>$_REQUEST['registrant_dinner'],
			"registrant_extra_dinner"=>$_REQUEST['registrant_additional'],
			"registrant_salutation1"=>$_REQUEST['registrant_salutation1'],
			"registrant_firstname1"=>$_REQUEST['registrant_firstname1'],
			"registrant_lastname1"=>$_REQUEST['registrant_lastname1'],
			"registrant_email1"=>$_REQUEST['registrant_email1'],
			"registrant_diet1"=>$diet1,
			"registrant_salutation2"=>$_REQUEST['registrant_salutation2'],
			"registrant_firstname2"=>$_REQUEST['registrant_firstname2'],
			"registrant_lastname2"=>$_REQUEST['registrant_lastname2'],
			"registrant_email2"=>$_REQUEST['registrant_email2'],
			"registrant_diet2"=>$diet2,
			"registrant_total"=>$_REQUEST['grand_total'],
			"registrant_paymentmode"=>$_REQUEST['payment_mode']
		);
	}
	
	//print_r($insert);
	$db->insert("tbl_registrant",$insert);
	$registrant_idarr = $db->run("SELECT LAST_INSERT_ID() as id;");
	$registrant_id = $registrant_idarr[0]['id'];
	$invoice = "SICC11-".$registrant_id;

	if (isset($_FILES['student_pass']) && $_FILES['student_pass']['name']!=""){
		$ext = substr(strrchr($_FILES['student_pass']['name'],'.'),1);
		$filename1 = $registrant_id."registrantpic.".$ext;
		move_uploaded_file($_FILES['student_pass']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/SICC11/register/student/".$filename1);
		$update = array(
			"student_pic" => $filename1
		);
		$bind = array(
			":search1" => $registrant_id
		);
		$db->update("tbl_registrant", $update, "registrant_id = :search1", $bind);        
	}        
        
        
	$update = array(
		"invoice" => $invoice
	);
	$bind = array(
		":search1" => $registrant_id
	);
	$db->update("tbl_registrant", $update, "registrant_id = :search1", $bind);        
	
	if ($_REQUEST['payment_mode']=="banktransfer"){
		$action = "banktransfer.php?id=$registrant_id";
	}
		
	if (isset($action) && $action !=""){
		$bind = array(":search1"=>"banktransfer");
		$results = $db->select("tbl_email","email_description = :search1",$bind);
		$result = $results[0];
		$subject = $result['email_subject'];
		$message = $result['email_content'];
		$message = str_replace("@registrant_salutation@",$salutation,$message);
		$message = str_replace("@registrant_firstname@",$firstname,$message);
		$message = str_replace("@registrant_lastname@",$lastname,$message);
		$message = str_replace("@registrant_total@",$_REQUEST['grand_total'],$message);
		$email = $email;
		$mail->IsHTML(true);
		$mail->SetFrom("SICC11_secretariat@events-sp.com","Ms Sylvia Chan");
		$mail->AddAddress($email);
		$mail->Subject = $subject;
		$mail->Body = $message;
		$mail->Send(); // send message
		header('Location: '.$action);
	}
        
?>
<?php require_once('./config.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SICC11</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

	<style>
		.row > div > img { width: 100%; display: block; }
	</style>
    <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">
      <link href="css/bootstrap-theme.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
		
        <noscript>
            <p>This site is best viewed with Javascript.</p>
        </noscript>
  </head>
  <body>
<div class="well">
<div class="content" bgcolor="#FFFFD0">
  <div class="col-12 feature">
 	<form class="form-horizontal" method="post" action="charge.php">
		<center>
			<img src="masthead.jpg"  width="800" class="img-responsive"/>
		</center>
		<br/>
        
		<div class="panel panel-primary">
            <div class="panel-heading  text-center">Credit Card Payment</div>
            <div class="panel-body">
                <div class="form-group">
					<label for="pemail" class="col-lg-6 control-label">Click on the button to enter in your payment details</label>
					<div class="col-lg-6">
						<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
							data-key="<?=$stripe['publishable_key'];?>"
							data-amount="<?=$_REQUEST['grand_total']*100;?>"
							data-name="Spark Planners"
							data-description="SICC11"
							data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
							data-locale="auto"
							data-currency="sgd">
						</script>
					</div>
                </div>
            </div>
        </div> 
		
        <input type="hidden" name="registrant_id" value="<?=$registrant_id;?>">
		<input type="hidden" name="total_payment" value = "<?=$_REQUEST['grand_total'];?>">
    </form>
    </div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-1.11.2.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>

  </div>
</div>
</body>
</html>