<?php require_once('../auth/auth.php'); ?>
<section class="content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-3">
				<div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
					<div class="card-header" style="padding: 4px 8px;">
						<h3 class="card-title"> <?php echo language(192); ?> </h3>
						<div class="card-tools">
							<button type="button" class="btn btn-tool " onclick="pagecall('../company_setup/company_add.php','#com_profile')"> <span class="right badge badge-info"> <i class="fa fa-user"></i> +</span>
							</button>
							<button type="button" class="btn btn-tool" data-card-widget="remove">
								<i class="fas fa-times"></i>
							</button>
						</div>
					</div>
					<table>
						<tr>
							<th scope="col" class="text-center">
								<button type="button" onclick="pagecall('../company_setup/compnay_index.php?status='+'run','#settingview')" class="btn btn-success btn-xs">Running </button>
							</th>
							<th scope="col" class="text-center"> <button type="button" onclick="pagecall('../company_setup/compnay_index.php?status='+'off','#settingview')" class="btn btn-success btn-xs">Off </button></th>
							<th scope="col" class="text-center"> <button type="button" onclick="pagecall('../company_setup/compnay_index.php?status='+'all','#settingview')" class="btn btn-success btn-xs" class="btn btn-success btn-xs">All </button></th>
							<th scope="col" class="text-center"> <button type="button" class="btn btn-success btn-xs">Close</button></th>
							</th>
						</tr>
					</table>

					<tr>
						<th scope="col" class="text-center">
							<input type="text" id="search" class="form-control form-control-sm search" placeholder="searching" required="true" style="border-radius:10px ;border:1px solid primary;width:100%; text-align:center; padding:5px; ">
						</th>
					</tr>
					<div id="printid" class="card-body p-1 table-responsive cscroll" style="max-height: 450px;">
						<table class="searchtable ttable " cellpadding="0" cellspacing="0" rules="groups">
							<thead>
							</thead>
							<?php
							if (@$_GET['status'] === 'run') {
								$company_query = mysqli_query($conn, "SELECT * FROM company WHERE  expiry_date >'$date'   ");
							} else if (@$_GET['status'] === 'off') {
								$company_query = mysqli_query($conn, "SELECT * FROM company WHERE   expiry_date < '$date' ");
							} else {
								$company_query = mysqli_query($conn, "SELECT * FROM company WHERE coid   ");
							}


							$i = 0;
							while ($rowcom = mysqli_fetch_array($company_query)) {
							?>
								<tbody>
									<tr>
										<td><?php echo ++$i ?> .</td>
										<td onclick="pagecall('../company_setup/company_profile.php?coid='+'<?php echo $rowcom['coid'] ?>','#com_profile')"><?php echo $rowcom['co_name'] ?> , <?php echo $rowcom['owner_phone'] ?> </td>
										<td> <?php

												$expiry_date = $rowcom['expiry_date'];

												$datetime1 = date_create($date);
												$datetime2 = date_create($expiry_date);
												$interval = date_diff($datetime1, $datetime2);
												$prev_date = date('Y-m-d', strtotime($expiry_date . ' -1 day'));
												$tt_date = date('Y-m-d', strtotime($expiry_date . ' -2 day'));
												?>
											<?php
											if ($expiry_date == $date) {
												echo " <span class='text-danger'> Expired </span> ";
											} else if ($date == $prev_date) {
												echo " <span class='bg-danger'>1 Day  </span> ";
											} else if ($date == $tt_date) {
												echo " <span class='bg-danger'>2 Day  </span> ";
											} else {
												echo $interval->format(' %R%a Days');
											}
											?>

										</td>
										<td onclick="pagecall('../company_setup/permissoin.php?getid='+'<?php echo $rowcom['coid'] ?>'+'&type=company','#com_profile')"> <i class="fa fa-cog"> </i> </td>
									</tr>
								<?php  } ?>
								</tbody>
						</table>
					</div>
				</div>
			</div>
			<div class="col-md-9" id="com_profile">
			</div>
		</div>
	</div>
</section>
<script>
	$(document).ready(function() {
		$('.search').on('keyup', function() {
			var searchTerm = $(this).val().toLowerCase();
			$('.searchtable tr').each(function() {
				var lineStr = $(this).text().toLowerCase();
				if (lineStr.indexOf(searchTerm) === -1) {
					$(this).hide();
				} else {
					$(this).show();
				}
			});
		});
	});
</script>