<?php
	session_start();
	include('../../includes/config.php');
	require_once("../../includes/dbcontroller.php");
	require_once("../../includes/perpage.php");
	if(!isset($_SESSION['uid']) && empty($_SESSION['uid'])){
		header("location:$website_url/");
		exit();
	}
	$role= $_SESSION['role'];
	if($role!='Admin'){
		header("location:$website_url/");
		exit();
	}

	$db_handle = new DBController();
	$trucks_query="SELECT * FROM trucks";
	$trucks_data = $db_handle->runQuery($trucks_query);

	include('../../includes/header.php');
	include('../../includes/menu.php');
?>

<div class="container main-cont"><h2 class="page-title">Trucks</h2>
     <div class="container">
        <ul class="nav navbar-nav navbar-right">
           <li><a href="<?php echo $website_url.$add_truck_url; ?>"><i class="fa fa-plus"></i> Add Truck</a></li>
        </ul>
    </div>

	<div class="table-responsive">
		<table class="table table-striped table-hover table-reflow">
			<thead>
				<tr>
					<th>#</th><th>#Truck</th><th>Truck Name</th><th></th>
				</tr>
			</thead>
			<tbody>
			<?php foreach ($trucks_data as $truck){ ?>
				<tr>
					<td><?php echo $truck['Truck_id']; ?></td>
					<td><?php echo $truck['TruckNumber']; ?></td>
					<td><?php echo $truck['TruckName']; ?></td>
					<td><span class="admin-links"> <a href="<?php echo $website_url.$delete_truck_url; ?>?id=<?php echo $truck['Truck_id']; ?>" class="link delete-link"><i class="fa fa-trash" aria-hidden="true"></i>delete truck </a></span></td>
				</tr>
			<?php } ?>
			</tbody>
		</table>
	</div> 
</div>
<?php
	include('../../includes/webfooter.php');
	include('../../includes/footer.php');
?>