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

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

if($_REQUEST['apicall']){
	send_data_to_api($_REQUEST);
}

$details = get_details($_REQUEST['id']);
// echo "<pre>";print_r($details);exit;
/*$directors = '';
$directors = get_directors($details['licence_number']);
*/
$operat_center = '';
$operat_center = get_operat_center($details['licence_number']);

$transport_managers = '';
$transport_managers = get_transport_managers($details['licence_number']);

$licence_directors = '';
$licence_directors = get_licence_directors($details['company_id']);

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">Operators Details</h5> -->
    </div>
</div>
<!-- /Title -->
    <!-- Row -->
	<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="col-md-12">
						<div class="col-md-12">
							<h1 style="font-weight: bold; padding-bottom: 15px;"><?=$details['company_name']?></h1>
							<div class="col-md-12">
								<div class="col-md-6">
									<h3>Licence details (<?=$details['licence_number']?>)</h3>
								</div>
								<div class="col-md-6">
									<h3><?=$details['phone']?></h3>
								</div>
							</div>
						</div>
					</div>
					
					<div class="col-md-12 mt-25">
						<div class="col-md-12" style="padding-bottom: 15px; padding-top: 25px;"><h5>Directors</h5></div>
						<div class="col-md-12">
							<strong>Name</strong>
						</div>
						<?php 
						    $traffic_source = isset($_REQUEST['traffic_source']) ? $_REQUEST['traffic_source'] : '';
						   
							if ($licence_directors != '' && mysqli_num_rows($licence_directors) > 0) {
								while ($row = mysqli_fetch_assoc($licence_directors)) { ?>
									<div class="col-md-6 mt-25">
										<p>
										<?php echo $row['fullname'].'&nbsp; &nbsp; &nbsp; <a href="mailto:'.$row['email'].'">'.$row['email'].'</a></br>'; ?></p>
									</div>
									<div class="col-md-6 mt-25">
										<form action="#" method="post"> 
									    <input type="hidden" name="lead_id" value=1> 
									    <input type="hidden" name="key" value="dsiusd867906sdiyy89798798sfsfsdf98797777887sfsfsfsfsf"> 
									 
									    <input type="hidden" name="company" value="<?=$details['company_name']?>"> 
									    <input type="hidden" name="first_name" value="<?=$row['first_name']?>"> 
									    <input type="hidden" name="last_name" value="<?=$row['surname']?>"> 
									    <input type="hidden" name="email" value="<?=$row['email']?>"> 
									    <input type="hidden" name="phone" value="<?=$details['phone']?>"> 
									    <input type="hidden" name="postcode" value="<?=$details['postcode']?>"> 
									 
									    <input type="hidden" name="fleet_size" value="<?= $details['total_fleet_size'] ?>"> 
									    <input type="hidden" name="lead_notes" value=""> 
									    <input type="hidden" name="traffic_source" value="<?=$traffic_source?>"> 
									 
									    <input type="submit" name="apicall" value="Send To FF Admin" class="btn btn-primary"> 
									</form> 
									</div>
								<?php }
							}
						?>
						
					</div>

					<div class="col-md-12 mt-25">
						<div class="col-md-12" style="padding-bottom: 15px; padding-top: 25px;"><h5>Transport Managers</h5></div>
						<div class="col-md-12">
							<strong>Name</strong>
						</div>
						<?php 
						    $traffic_source = isset($_REQUEST['traffic_source']) ? $_REQUEST['traffic_source'] : '';
						   
							if ($transport_managers != '' && mysqli_num_rows($transport_managers) > 0) {
								while ($row = mysqli_fetch_assoc($transport_managers)) { ?>
									<div class="col-md-6 mt-25">
										<p>
										<?php echo $row['fullname'].'&nbsp; &nbsp; &nbsp; <a href="mailto:'.$row['email'].'">'.$row['email'].'</a></br>'; ?></p>
									</div>
									<div class="col-md-6 mt-25">
										<form action="#" method="post"> 
									    <input type="hidden" name="lead_id" value=1> 
									    <input type="hidden" name="key" value="dsiusd867906sdiyy89798798sfsfsdf98797777887sfsfsfsfsf"> 
									 
									    <input type="hidden" name="company" value="<?=$details['company_name']?>"> 
									    <input type="hidden" name="first_name" value="<?=$row['first_name']?>"> 
									    <input type="hidden" name="last_name" value="<?=$row['surname']?>"> 
									    <input type="hidden" name="email" value="<?=$row['email']?>"> 
									    <input type="hidden" name="phone" value="<?=$details['phone']?>"> 
									    <input type="hidden" name="postcode" value="<?=$details['postcode']?>"> 
									 
									    <input type="hidden" name="fleet_size" value="<?= $details['total_fleet_size'] ?>"> 
									    <input type="hidden" name="lead_notes" value=""> 
									    <input type="hidden" name="traffic_source" value="<?=$traffic_source?>"> 
									 
									    <input type="submit" name="apicall" value="Send To FF Admin" class="btn btn-primary"> 
									</form> 
									</div>
								<?php }
							}
						?>
						
					</div>

					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							URL
						</div>
						<div class="col-md-8">
							<?=$details['url']?>
						</div>
					</div> 
					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							Business Type
						</div>
						<div class="col-md-8">
							<?=$details['business_type']?>
						</div>
					</div>
					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							Trading Names
						</div>
						<div class="col-md-8">
							<?=$details['trading_names']?>
						</div>
					</div>

					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							Licence Type
						</div>
						<div class="col-md-8">
							<?=$details['licence_type']?>
						</div>
					</div>
					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							Licence Status
						</div>
						<div class="col-md-8">
							<?=$details['licence_status']?>
						</div>
					</div>
					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							Continuation Date
						</div>
						<div class="col-md-8">
							<?=$details['continuation_date']?>
						</div>
					</div>
					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							Traffic Area
						</div>
						<div class="col-md-8">
							<?=$details['traffic_area']?>
						</div>
					</div>
					<div class="col-md-12 mt-25">
						<div class="col-md-12" style="padding-bottom: 15px; padding-top: 25px;"><h5>Contact details</h5></div>
						<div class="col-md-4">
							Address
						</div>
						<div class="col-md-8">
							<?=$details['full_address']?>
						</div>
					</div>
					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							Phone
						</div>
						<div class="col-md-8">
							<?=$details['phone']?>
						</div>
					</div>
					<div class="col-md-12 mt-25">
						<div class="col-md-4">
							Fleet Size
						</div>
						<div class="col-md-8">
							<?= $details['total_fleet_size'] ?>
						</div>
					</div>
					<div class="col-md-12 mt-25">
						<div class="col-md-12" style="padding-bottom: 15px; padding-top: 25px;"><h5>Operating centres</h5></div>
						<div class="col-md-8">
							<strong>Operating centre</strong>
						</div>
						<div class="col-md-2">
							<strong>Vehicles</strong>
						</div>
						<div class="col-md-2">
							<strong>Trailers</strong>
						</div>
					</div>
					<?php 
						if ($operat_center != '' && mysqli_num_rows($operat_center) > 0) {
							while ($row = mysqli_fetch_assoc($operat_center)) { ?>
								<div class="col-md-12 mt-25">
									<div class="col-md-8">
										<?=$row['full_address']?>
									</div>
									<div class="col-md-2">
										<?=$row['vehicles']?>
									</div>
									<div class="col-md-2">
										<?=$row['trailers']?>
									</div>
								</div>			
							<?php }
						}
					?>
					
					
				</div>
			</div>
		</div>
	</div>

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