<?php
session_start();
ob_start();
 include "../config/config.php"; 
 include "../config/function.php"; 
 
// print_r($_REQUEST);
 $private_key=get_privatekey($_SESSION['admin_name']);
 $request_from_server=$_SERVER['HTTP_REFERER'];
$this_server=$_SERVER['HTTP_HOST'];
if($request_from_server!=''){
	check_access_url($request_from_server,$this_server);
}

// echo $_SESSION['login_status'];echo "<br>";
// echo $_SESSION['private_key'];echo "<br>";
// echo $_SESSION['admin_name'];echo "<br>";

if($_SESSION['login_status']!='YES' || $_SESSION['private_key']!=$private_key || $_SESSION['private_key']=='' || $_SESSION['admin_name']=='')
{
    echo "Blank";
	header("Location:../AppLogin");
	exit();
}
else
{
$booking_random_no=str_shuffle("0123654789");
$booking_date=date("y-m-d",strtotime($_POST['bookingDate']));
$member_user_id=RemoveSpecialChar(strtoupper(trim($_POST['member_user_id'])));
$member_name=RemoveSpecialChar(strtoupper(trim($_POST['member_name'])));
$project_id=RemoveSpecialChar(trim($_POST['project']));
$sponcer_id=RemoveSpecialChar(trim($_POST['sponcer_id']));
$sponcer_name=RemoveSpecialChar(trim($_POST['sponsor_name']));
// $plot_id=RemoveSpecialChar(trim($_POST['plotCode']);
$plot_code=RemoveSpecialChar(strtoupper(trim($_POST['plotCode'])));
$plot_size=RemoveSpecialChar(trim($_POST['plot_size']));
$plot_rate=RemoveSpecialChar(trim($_POST['plot_rate']));
$total_amount=RemoveSpecialChar($_POST['total_amount']);
$discount_amt=RemoveSpecialChar($_POST['discount_amount']);
$net_amount=RemoveSpecialChar($_POST['net_amount']);
$businessper=RemoveSpecialChar($_POST['businessPer']);
$cornorType=RemoveSpecialChar($_POST['cornorType']);
$corner_charge=RemoveSpecialChar($_POST['corner_charge']);

//  if($businessper==80 || $businessper==50 || $businessper==60 || $businessper==70)
//  {
    $ssl="Select * from tbl_memberreg where member_user_id='$member_user_id'";
    $spres=mysqli_query($connection,$ssl);
    if(mysqli_num_rows($spres)>0)
    {
        $date=date("Y-m-d");
    echo	 $sql="Insert Into tbl_plot_registry_booking(booking_random_no,booking_date,member_user_id,member_name,sponcer_id,sponcer_name,plot_id,plot_code,plot_size,plot_rate,project_id,sector_code,total_amount,discount_amt,net_amount,paid_amount,balance_amt,clossing_date,businessper,cornorType,corner_charge,booking_registred) 
    	values ('$booking_random_no','$booking_date','$member_user_id','$member_name','$sponcer_id','$sponcer_name','$plot_code','$plot_code','$plot_size','$plot_rate','$project_id','','$total_amount','$discount_amt','$net_amount',0,$net_amount,'$date','$businessper','$cornorType',$corner_charge,1)";
    	$res=mysqli_query($connection,$sql) or die(mysqli_error($connection));

        // 	 $booking_message="Congratulations! Dear ".$member_name."(".$member_user_id."), You Have  Booked A ".$plot_code."  successfully. Your Booking Transaction Id: ". $booking_random_no ." For any query please contact us...Thanks! ".$website;
        	$msg="Congratulations! Dear ".$member_name."(".$member_user_id."), Booking of Plot No : ".$plot_code." is successfully. Your Booking Transaction Id: ". $booking_random_no ;
        // 	sendmysms($contact, $booking_message);
        
        // 	echo $strP="update tbl_plot_master set booking_status=1,booking_date='$booking_date',member_user_id='$member_user_id',member_name='$member_name' where plot_id=$plot_id and plot_code='$plot_code'";
        // 	mysqli_query($connection,$strP) or die(mysqli_error($connection));
        	
        	echo $strS="update tbl_memberreg set  status=2,is_customer=1 where member_user_id='$member_user_id'";
        	mysqli_query($connection,$strS) or die(mysqli_error($connection));
        	
        	$receipt_no=$booking_random_no;
        	header("location:../PlotBookingReceipt?booking_random_no=$booking_random_no");
 
    }
    else
    {
     	$msg="Some Thing Wrong...";
    	header("location:../PlotBooking?msg=$msg");
    }
}


// }
header("location:../PlotBooking?msg=$msg");
exit();
?>