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

$MESSAGE_FAILURE_PAX =   '<blockquote>
                      <h1>
                          <div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-remove-sign"></span> PAX must be in numeric format</div>
                      </h1>
                      <br>
                      <br>
                    </blockquote>';

$MESSAGE_FAILURE_DATE =   '<blockquote>
                      <h1>
                          <div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-remove-sign"></span> Date must be later than today</div>
                      </h1>
                      <br>
                      <br>
                    </blockquote>';

//$DISPLAY_DATE = $_POST['reservation'];
$DISPLAY_DATE = preg_replace("([^0-9-])", "", $_POST['reservation']);

$PAX = filter_var($_POST['PAX'], FILTER_SANITIZE_NUMBER_INT);

if (!is_numeric($PAX))
{
    $_SESSION['MESSAGE'] = $MESSAGE_FAILURE_PAX;
    header('Location: index.php');
    die();
}

//$START_DATE = substr($DISPLAY_DATE, 0, -13);
$START_DATE = substr($DISPLAY_DATE, 0, -11);
//$END_DATE = substr($DISPLAY_DATE, -10);
$END_DATE = substr($DISPLAY_DATE, -10);

$today = date('d-m-Y');

$curdate=strtotime($today);
$mydate=strtotime($START_DATE);

if($curdate >= $mydate)
{
    $_SESSION['MESSAGE'] = $MESSAGE_FAILURE_DATE;
    header('Location: index.php');
    die();
}

$_SESSION['PAX'] = $_POST['PAX'];
$_SESSION['START_DATE'] = date("Y-m-d", strtotime($START_DATE));
$_SESSION['END_DATE'] = date("Y-m-d", strtotime($END_DATE));

header('Location: booking.php');

?>