<?php
include_once('inc.function.php');
include_once('confdb.php');
include_once('db.functions.php');

$MESSAGE_FAILURE =   '<blockquote>
                      <h1>
                          <div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-remove-sign"></span> Please select Country / States</div>
                      </h1>
                      <br>
                      <br>
                    </blockquote>';

$MESSAGE_FAILURE2 =   '<blockquote>
                      <h1>
                          <div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-remove-sign"></span> Please fill in the information in mandatory form</div>
                      </h1>
                      <br>
                      <br>
                    </blockquote>';
					
$MESSAGE_FAILURE3 =   '<blockquote>
                      <h1>
                          <div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-remove-sign"></span> Telephone number in mandatory field </div>
                      </h1>
                      <br>
                      <br>
                    </blockquote>';

//if ($_POST['CUST_COUNTRY'] == '0' || $_POST['CUST_STATE'] == '0')
if ($_POST['CUST_COUNTRY'] == '0')
{
    $_SESSION['MESSAGE'] = $MESSAGE_FAILURE;
    header('Location: booking_address.php');
    die();
}

if ( empty($_POST['CLIENT_NAME']) || empty($_POST['CLIENT_TELEPHONE']) )
{
    $_SESSION['MESSAGE'] = $MESSAGE_FAILURE2;
    header('Location: booking_address.php');
    die();
}

if (($_POST['TELEPHONE_CCC'] == '0') || empty($_POST['CLIENT_TELEPHONE']))
{
    $_SESSION['MESSAGE'] = $MESSAGE_FAILURE3;
    header('Location: booking_address.php');
    die();
}

$_SESSION['CLIENT_NAME'] = strtoupper(filter_var($_POST['CLIENT_NAME'],FILTER_SANITIZE_STRING));
$_SESSION['TYPE_CUSTOMER'] = $_POST['TYPE_CUSTOMER'];
//$_SESSION['CLIENT_TELEPHONE'] = $_POST['CLIENT_TELEPHONE'];
$_SESSION['CLIENT_TELEPHONE'] = preg_replace('/[^0-9]/', '', $_POST['CLIENT_TELEPHONE']);
$_SESSION['CLIENT_TELEPHONE2'] = preg_replace('/[^0-9]/', '', $_POST['CLIENT_TELEPHONE2']);
//$_SESSION['CLIENT_FAX'] = $_POST['CLIENT_FAX'];
$_SESSION['CLIENT_FAX'] = preg_replace('/[^0-9]/', '', $_POST['CLIENT_FAX']);
$_SESSION['TELEPHONE_CCC'] = $_POST['TELEPHONE_CCC'];
$_SESSION['HANDPHONE_CCC'] = $_POST['HANDPHONE_CCC'];
$_SESSION['FAX_CCC'] = $_POST['FAX_CCC'];

$_SESSION['ADDRESS_1'] = ucwords(filter_var($_POST['ADDRESS_1'],FILTER_SANITIZE_STRING));
$_SESSION['ADDRESS_2'] = ucwords(filter_var($_POST['ADDRESS_2'],FILTER_SANITIZE_STRING));
$_SESSION['CUST_COUNTRY'] = $_POST['CUST_COUNTRY'];
$_SESSION['CUST_STATE'] = $_POST['CUST_STATE'];
$_SESSION['CUST_CITY'] = ucwords(filter_var($_POST['CUST_CITY'],FILTER_SANITIZE_STRING));
$_SESSION['CUST_POSTCODE'] = preg_replace('/[^0-9]/', '', $_POST['CUST_POSTCODE']);
$_SESSION['COMPANY_NAME'] = ucwords(filter_var($_POST['COMPANY_NAME'],FILTER_SANITIZE_STRING));

$CODE1 = $_SESSION['CUST_COUNTRY'];
//$result = mysqli_query($con,"SELECT * FROM config_countries WHERE COUNTRY_SHORT = '$CODE1'");
//$row = mysqli_fetch_assoc($result);
$row = DB::queryFirstRow("SELECT * FROM config_countries WHERE COUNTRY_SHORT = %s",$CODE1);
$_SESSION['CUST_COUNTRY_NAME'] = $row['COUNTRY_NAME'];
$_SESSION['CUST_COUNTRY_CALLING_CODE'] = $row['COUNTRY_CALLING_CODE'];


$CODE2 = $_SESSION['CUST_STATE'];
//$result2 = mysqli_query($con,"SELECT * FROM config_states WHERE STATES_CODE = '$CODE2'");
//$row2 = mysqli_fetch_assoc($result2);
$row2 = DB::queryFirstRow("SELECT * FROM config_states WHERE STATES_CODE = %s",$CODE2);
$_SESSION['CUST_STATES_NAME'] = $row2['STATES_NAME'];
header('Location: booking_submission.php');
?>