<?php
error_reporting(E_ALL);
ini_set ('display_error', 1);
	include"include/db_connection.php";
	if(isset($_POST['bookNow'])){
		$booking_id             = rand(11111111,99999999);
		$cName 		   		    = $_POST['cName'];
		$phoneNo 		   		= $_POST['phoneNo'];
		$emailID 		   		= $_POST['emailID'];
		$CancellaionPolicy 		= $_POST['cancellation_policy'];
		$flexibleticket    		= $_POST['flexibleticket'];
		$SeatSelection     		= $_POST['SeatSelection'];
		$cardNumber        		= $_POST['cardNumber'];
		$expiryMonth       		= $_POST['expiryMonth'];
		$expiryYear        		= $_POST['expiryYear'];
		$cvvNo			   		= $_POST['cvvNo'];
		$cardHolderName    		= $_POST['cardHolderName'];
		$country           		= $_POST['country'];
		$state             		= $_POST['state'];
		$address1          		= $_POST['address1'];
		$address2          		= $_POST['address2'];
		$city              		= $_POST['city'];
		$postalCode        		= $_POST['postalCode'];
		$billingPhoneNo    		= $_POST['billingPhoneNo'];
		$agree			   		= $_POST['agree'];
		$bookDate          		= date("Y-m-d");
		$cancellation_amount    = $_POST['cal_cancellation_amount'];
		$flexible_amount    	= $_POST['cal_flexible_amount'];
		$seats_assign_amount    = $_POST['cal_seats_assign'];
		$cal_base_fare          = $_POST['cal_base_fare'];
		$cal_taxes              = $_POST['cal_taxes'];
		$total_booking_amount   = $_POST['hftotalAmt'];
		
		$travelerType 		= $_POST['travelerType'];
		$passFirstName 		= $_POST['passFirstName'];
		$passMidName 		= $_POST['passMidName'];
		$passLastName 		= $_POST['passLastName'];
		$passGender 		= $_POST['passGender'];
		$passDobMonth 		= $_POST['passDobMonth'];
		$passDobDay 		= $_POST['passDobDay'];
		$passDobYear 		= $_POST['passDobYear'];
		
		
		
		//echo "<pre>";
		//print_r($_POST);die();
		
		$insertUser = "INSERT INTO booking_db(booking_id,cus_name,contact,email,cancellation_policy	,flexible_ticket,seat_selection,card_no,month,year,cvv,card_name, country,state,address1,address2,city,postal_code,billing_phone,agree,booking_date,status, cancellation_amount, flexible_amount, seats_assign_amount, base_fare, fee_taxes, total_booking_amount)
		VALUES
		('B$booking_id','$cName','$phoneNo','$emailID','$CancellaionPolicy','$flexibleticket','$SeatSelection','$cardNumber','$expiryMonth','$expiryYear','$cvvNo','$cardHolderName','$country','$state','$address1','$address2','$city','$postalCode','$billingPhoneNo','$agree','$bookDate','Show', $cancellation_amount, $flexible_amount, $seats_assign_amount, $cal_base_fare, $cal_taxes, $total_booking_amount)";
		
		$insertQuery = mysqli_query($conn, $insertUser);
		$bookingId = mysqli_insert_id($conn);
		
		if($insertQuery){
			if(count($travelerType)>0){
				//print_r($passDobYear);
				for($i=0; $i<count($travelerType); $i++){
					$dob 			= $passDobYear[$i].'-'.$passDobMonth[$i].'-'.$passDobDay[$i];
					$birthdate_ts 	= strtotime($dob);
					$birthdate 		= date("Y-m-d",$birthdate_ts);
					$query[] 		= "('$bookingId', '$passFirstName[$i]', '$passMidName[$i]', '$passLastName[$i]', '$travelerType[$i]', '$passGender[$i]', '$birthdate', '$emailID')";
				}
				$passSql 		= "INSERT INTO `passenger_details`(`booking_id`, `first_name`, `middle_name`, `last_name`, `traveler_type`, `gender`, `date_of_birth`, `email`) VALUES ". implode(', ', $query);
				$passQuery 		= mysqli_query($conn, $passSql);
				if($passQuery){
				echo "<script>alert('submitted All Details')</script>";
				}}
				
				for($i=0;$i<count($_POST['depCity']);$i++) {
				$carrierCode     = $_POST['carrierCode'][$i];
				$airLogo        = $_POST['airLogo'][$i];
				$airName        = $_POST['airName'][$i];
				$depIata		= $_POST['depIata'][$i];
				$arrIata		= $_POST['arrIata'][$i];
				$arrCity        = $_POST['arrCity'][$i];
				$depTime        = $_POST['depTime'][$i];
				$arrTime        = $_POST['arrTime'][$i];
				$tripTime       = $_POST['tripTime'][$i];
				$depDate        = $_POST['depDate'][$i];
				$retDate        = $_POST['retDate'][$i];
				
				
				$flightQuery = "INSERT INTO flight_details SET booking_id='$bookingId',carrierCode='$carrierCode',airLogo='$airLogo',airName='$airName',depIata='$depIata',arrIata='$arrIata',depCity='".$_POST['depCity'][$i]."',arrCity='$arrCity',depTime='$depTime',arrTime='$arrTime',tripTime='$tripTime',depDate='$depDate',retDate='$retDate'";
				
				$runFlightQuery = mysqli_query($conn, $flightQuery);
				if($runFlightQuery){
				echo "<script>alert('submitted Flight Details')</script>";
				}else{
					echo mysqli_error($conn);
					
				}
					}
						}
							} ?>
				
				
				
				
				
				
				
				
				