<?php
	include_once(SABLE_WORKING_PATH.'almanac/almanac_func.php');

	function getClientsOverview()
	{
		global $sableDB;
		
		$bgcol	= '#eee';
		$pdng	= '8px';
		$sqldt	= '"2021-07-16"'; //'CURDATE()';
		
		$sql = 'select booking_schedule.booking_time, concat(client_name, " ", client_surname) as client_full_name, address, 
				COALESCE(client_cell, client_phone) as client_cell
				from booking_schedule 
				inner join booking on booking.booking_id = booking_schedule.booking_id 
				inner join client on client.client_id = booking.client_id 
				inner join address on address.address_id = client.address_id 
				where (DATE(booking_schedule.booking_time) = '.$sqldt.') 
				order by booking_schedule.booking_time';
		$rows = $sableDB->getRows($sql);

		if (empty($rows))
		{
			$html = '
			<div class="col-sm-12 text-center" style="width:100%; background:'.$bgcol.'; padding:'.$pdng.';">
				<p><i class="fa fa-2x fa-ban error" style="color:red;"></i></p>
				<h3>No bookings scheduled for today.</h3>
            	<div class="row forms-grid">
					<div class="col-sm-4">
					</div>
					<div class="col-sm-4">
            			<button onClick="window.location.reload();">Retry</button>				
					</div>
					<div class="col-sm-4">
					</div>
				</div>
			</div>';
		}
		else
		{
			$html = '';
			foreach($rows as $row)
			{
				$sched = new DateTime($row['booking_time']);
				$html .= '
					<div class="col-sm-12" style="display: inline-flex;  width:100%; background:'.$bgcol.'; padding:'.$pdng.';">
						<a href="#">
							<div style="transform: translateY(-50%) translateX(10%); top: 50%; left: -65px; position: absolute; width: 100px; height: 100px; background-color: white; border-radius:100%;">
								<i class="fa fa-users fa-2x" style="top: 33%; right: 8%; position: absolute;"></i>
							</div>
							<div style="margin-left: 40px;">
								<h3>'.$sched->format('H:i').'&nbsp;<i class="fa fa-arrow-right"></i>&nbsp;'.$row['client_full_name'].'</h3>
								<h4>'.$row['address'].'</h4>
							</div>	
							<div style="transform: translateY(-50%) translateX(-10%); top: 50%; right: 0; position: absolute; height: 40px; width: 40px; border-radius: 100%; background-color: white;">
								<i class="fa fa-chevron-right fa-2x" style="top: 14%; left: 32%; position: absolute;"></i>
							</div>
						</a>
					</div>';
				unset($sched);
			}
		}
		return $html;
	}
	
	function printClientsOverview()
	{
		$html = getClientsOverview();
		echo($html);
	}
?>
<div class="container no-padding" style="margin-top:-25px;">
	<div class="row">
		<div class="col-sm-12">
			<div class="navbar section no-padding" role="navigation" style="background-color:#3cced6;">
				<div class="heading" style="margin:10px;">
					<div class="container no-padding">
						<div class="row">
							<div class="col-sm-2">
								<a class="navbar-minimalize" title="Menu" href="<?php SableSystem::printSableLinkPath('login/logout.php'); ?>">
									<span class="fa fa-2x fa-sign-out-alt">&nbsp;</span>
								</a>
							</div>
							<div class="col-sm-10">
							</div>							
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<div class="container no-padding">
	<div class="row-fluid">
		<?php printClientsOverview(); ?>
	</div>
</div>
<script src="/themes/sable/dashboard/dashboard.js"></script>