<?php 
session_start();
require '../config/database.php';
require 'model/model.php';
global $conn;

$saved_search = '';
$saved_search = get_saved_search();

if (isset($_SESSION['admin_id'])) {
    $name = $_SESSION['name'];
} else {
    echo "<script>window.location='index.php'</script>";
    exit;
}

include('layout/header.php');
include('layout/left_sidebar.php');

?>
<!-- Title -->
<div class="row heading-bg">
	<div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
		<h5 class="txt-dark">Saved Search</h5>
	</div>
</div>
<div class="row">
	<div class="col-sm-12">
		<div class="panel panel-default card-view">
			<div class="panel-wrapper collapse in">
				<div class="panel-body">
					<div class="table-wrap">
						<div class="table-responsive">
							<table id="companyTable" class="table table-hover display pb-30">
								<thead>
									<tr>
										<th class="text-center">Fleet Size</th>
										<th class="text-center">Post Code</th>
										<th class="text-center">Allocated To</th>
										<th class="text-center">Action</th>
									</tr>
								</thead>
								<tbody>
									<?php if ($saved_search != '' && mysqli_num_rows($saved_search) > 0) {
									while ($row = mysqli_fetch_assoc($saved_search)) {?>
									 	<tr>
											<td class="text-center"><?php 
												if($row['fleet_size'] == '1-9'){
													echo '1 – 9 vehicles';
												}else if($row['fleet_size'] == '10-19'){
													echo '10 – 19 vehicles';
												}else if($row['fleet_size'] == '20-39'){
													echo '20 – 39 vehicles';
												}else if($row['fleet_size'] == '40-99'){
													echo '40 – 99 vehicles';
												}else{
													echo '100 + vehicles';
												}
											 ?></td>
											<td class="text-center"><?=$row['postcode']?></td>
											<td class="text-center"><?=$row['sales_name']?></td>
											<td class="text-center">
												<form method="post" action="search.php">
													<input type="hidden" name="fleet_size" value="<?=$row['fleet_size']?>">
													<input type="hidden" name="postcode" value="<?=$row['postcode']?>">
													<input class="btn btn-info btn-outline btn-xs" type="submit" name="submit" value="Result">
												</form>
											</td>
										</tr>
									<?php } ?>
								<?php } ?>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>	
	</div>
</div>
<!-- /Row -->

<?php include('layout/footer.php');?>