<? include("../settings.php"); ?>
<?
	if ($_REQUEST['confirm']!=""){
		if ($_REQUEST['registrant_diet']=="Other")
			$diet = $_REQUEST['diet_others'];
		else
			$diet = $_REQUEST['registrant_diet'];
		if ($_REQUEST['registrant_diet1']=="Other")
			$diet1 = $_REQUEST['diet_others1'];
		else
			$diet1 = $_REQUEST['registrant_diet1'];
		if ($_REQUEST['registrant_diet2']=="Other")
			$diet2 = $_REQUEST['diet_others2'];
		else
			$diet2 = $_REQUEST['registrant_diet2'];
		$insert = array(
			"registrant_type"=>$_REQUEST['registration_type'],
			"author_type"=>$_REQUEST['student_options'],
			"registrant_papernumber"=>$_REQUEST['author_papernum'],
			"registrant_salutation"=>$_REQUEST['registrant_salutation'],
			"registrant_firstname"=>$_REQUEST['registrant_firstname'],
			"registrant_familyname"=>$_REQUEST['registrant_lastname'],
			"registrant_organisation"=>$_REQUEST['registrant_organisation'],
			"registrant_job"=>$_REQUEST['registrant_designation'],
			"registrant_email"=>$_REQUEST['registrant_email'],
			"registrant_mobilecc"=>$_REQUEST['registrant_mobilecc'],
			"registrant_mobile"=>$_REQUEST['registrant_mobile'],
			"registrant_mailing1"=>$_REQUEST['registrant_mailing1'],
			"registrant_mailing2"=>$_REQUEST['registrant_mailing2'],
			"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_attend"=>$_REQUEST['registrant_reception'],
			"registrant_dinner_attend"=>$_REQUEST['registrant_dinner'],
			"registrant_extra_dinner"=>$_REQUEST['registrant_extra_dinner'],
			"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['total_registration'],
			"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 = "NANO2024-".$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']."/Nanoman2024/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['total_registration'],$message);
		$email = $email;
		$mail->IsHTML(true);
		$mail->SetFrom("secretariat@nanoman2024.com","Ms Nicole May");
		$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>Nanoman 2024</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['total_registration']*100;?>"
							data-name="Spark Planners"
							data-description="Nanoman 2024"
							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['total_registration'];?>">
    </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>