<?php
if (!session_start()) {
    session_start();
}


?>

<!DCTYPE html>
<html>
<head>
<title></title>
<?php //session_start();?>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
</head>
<body>
<?php
    try {
        $db = new PDO('mysql:host=localhost;dbname=gdhhsxmy_monsoonvibespublica;charset=utf8', 'gdhhsxmy_monsoonvibespublica', 'monsoonvibespublica');
    } catch (Exception $e) {
        echo 'Error has Occured';
    }



$custID = $_SESSION['CustId'];


$firstname = strtoupper($_POST['fname']);
$lastname  = '';
$name      = $firstname . ' ' . $lastname;



$Address1 = $_POST['add1'];
$Address2 = $_POST['add2'];
$City     = strtoupper($_POST['city']);
$state    = strtoupper($_POST['state']);
$code     = $_POST['Zipcode'];
$country  = strtoupper($_POST['country']);
$Address  = ' <br>' . $Address1 . ' <br>' . $Address2 . '<br>' . $City . '<br> ' . $state . '<br> ZipCode:' . $code . '<br> ' . $country . ' ';

$email   = $_POST['Email'];
$mno     = $_POST['contactno'];
$contact = '<br>Mobile No: ' . $mno . '<br>Email: ' . $email;

$Amount  = $_POST['TXN_AMOUNT'];
$OrderId = $_POST['ORDER_ID'];

$_session['savedBook'] = $_POST['ORDER_ID'];


if ($_SESSION['TempCustId']) {
    $temp = $_SESSION['TempCustId'];
    $pass = password_hash($email, PASSWORD_BCRYPT);
    $stmt = $db->prepare("insert into customer values(null,'$name','$email','$pass' ,'$Address1','$Address2','$City','$state','$country','$code','$mno',now())");
    $stmt->execute();

    $last_id = $db->lastInsertId();

    $custID             = $last_id;
    $_SESSION['CustId'] = $custID;

    $queryUpdate = $db->prepare("update cart SET Cid=$custID where Cid=$temp");
    $queryUpdate->execute();
}


$stmt = $db->prepare("insert into transcationbook values('$OrderId',$custID,'$name','$Address','$contact',$Amount,NULL,NULL,NULL,NULL,NULL)");

$stmt->execute();

?>
<div class="Container text-center">
<div class="row text-center">
<div class="col-md-12">


</div></div>


 <form method="post" action="pgRedirect.php" id="yourform" > 
 
<div style="display:none;">
    
<input id="ORDER_ID"   name="ORDER_ID" value="<?php echo $_POST['ORDER_ID'];?>">					
<input id="CHANNEL_ID" name="CHANNEL_ID"  value="WEB">
<input id="CUST_ID" tabindex="2" maxlength="12" size="12" name="CUST_ID"  value="<?php echo $custID?>">  
<input id="name" tabindex="2" maxlength="12" size="12" name="name"  value="<?php echo $name?>">  
<input id="amount" tabindex="2" maxlength="12" size="12" name="amount"  value="<?php echo $Amount?>">  
<input id="MSISDN" tabindex="2" maxlength="120" size="12" name="MSISDN"  value="<?php echo $mno?>">  
<input id="EMAIL" tabindex="2" maxlength="120" size="12" name="EMAIL"  value="<?php echo $email?>">  
<input id="INDUSTRY_TYPE_ID" name="INDUSTRY_TYPE_ID"  value="Retail">
<input title="TXN_AMOUNT"  tabindex="10" type="text" name="TXN_AMOUNT" value="<?php echo $_POST['TXN_AMOUNT'] ?>">

</div>
 <br>
 <br>
 <br>
<div class="d-flex justify-content-center align-items-center h-75">
    <div class="spinner-border text-primary" style="width: 5rem;
    height: 5rem;" role="status">
  <span class="sr-only">Loading...</span>
</div>
</div>


 </form>
</div>

<script>            
    document.addEventListener("DOMContentLoaded", function(event) {
            document.createElement('form').submit.call(document.getElementById('yourform'));
            });         
</script>
</body>
</html>