<?php
date_default_timezone_set("America/Belize"); 
    $con = mysqli_connect('localhost', 'mayabeac_wine', '3]eGo-r(Scru',"mayabeac_WineList");
        if (mysqli_connect_errno()) {
            echo"
                Failed to connect to the MySQL DB:".mysqli_connect_error();
            }
           else{

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

$today = date("Y-m-d");
$sql="SELECT * FROM HotelGuestData WHERE CheckInDate <= '".$today."' AND CheckOutDate >= '".$today."' ORDER BY LastName";
//$sql="SELECT * FROM HotelGuestData WHERE Status = 'In-House'" ;


$records = mysqli_query($con, $sql);
echo "<head>";
echo "<style>";
echo "table {font-family: arial, sans-serif; border-collapse: collapse; width: 100%;}";
echo "td, th {border: 1px solid #aaaaaa; text-align: left; padding: 20px;}";
echo "tr:nth-child(even) {background-color: #dddddd;}";
echo "</style>";
echo "</head>";

echo "<body>";

//echo "<h2>Guest List</h2>";

echo "<table style='display: inline-block; text-align: left; width:100%; line-height: 200%; font-size: 150%'>";


echo "<tr>";
echo "<th>Guest Name</th>";
echo "<th>Room</th>";
echo "<th>Check In</th>";
echo "<th>Check Out</th>";
echo "<th>Status</th>";
echo "</tr>";

while($guests=mysqli_fetch_assoc($records)){

$status = "<td style='color:Black;'>".$guests['Status']."</td>";


if($guests['Status'] != 'Checked-Out'){

$status = "<td style='color:Black;'>In-House</td>";

}

else{
$status = "<td style='color:Tomato;'>Checked Out</td>";
}

if($guests['CheckOutDate'] == $today AND $guests['Status'] != 'Checked-Out'){

$status = "<td style='color:Tomato;'>Checking Out Today</td>";

}

if($guests['CheckInDate'] == $today AND $guests['Status'] != 'In-House'){

$status = "<td style='color:Black;'>Checking In Today</td>";

}

$in_date = DateTime::createFromFormat('Y-m-d', $guests['CheckInDate'])->format('M d');
$out_date = DateTime::createFromFormat('Y-m-d', $guests['CheckOutDate'])->format('M d');

echo "<tr >";
echo "<td>".$guests['FullName']."</td>";
echo "<td>".$guests['RoomName']."</td>";
echo "<td>";
echo $in_date;
echo "</td>";
echo "<td>".$out_date."</td>";
echo $status;
echo "</tr>";

}
echo "</table>";
echo"</body>";
echo"</html>";
}