<?php 
include 'dheader.php'; 
?>
	<div class="modal fade hidden-print" id="myModal" tabindex="-1" role="dialog" aria-hidden="true"></div>
	<div class="wrapper ">
		<?php include 'leftbar.php'; ?>
		<!-- left-bar -->
		<?php include 'topbar.php'; ?>
			<!-- top-bar -->
			<div class="main-content">


<div class="manage_buttons">
	<div class="row">
		<div class="col-md-8">
			<form action="" id="search_form" autocomplete="off" class="" method="get" accept-charset="utf-8">
				<div class="search search-items no-left-border">
					<ul class="list-inline">
						<li>
							<span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span><input type="text" list="listItems" class="form-control ui-autocomplete-input" name="kit" id="search" value="" placeholder="Search Kits" autocomplete="off">
							<datalist id="listItems">
							<?php
								$listItems = $db->query("SELECT DISTINCT kit_name FROM kitsetup");
								while($listrow = $listItems->fetchArray()){
							?>
								<option value="<?php echo $listrow['kit_name']; ?>"><?php echo $listrow['kit_name']; ?></option>
							<?php } ?>	
						</datalist>
						</li>
					
						<li><input type="submit" name="submitf" value="Search" class="btn btn-primary btn-lg">
						</li>
					</ul>
				</div>
			</form>
		</div>


		<div class="col-md-4">
			<div class="buttons-list items-buttons">
				<div class="pull-right-btn">
						<a href="newkit.php" class="btn btn-primary btn-lg" title="New Kit"><span class="" <?php echo (@$_SESSION['item_kitsadd'] == '') ? 'style="display:none;"': ''; ?>>New Kit</span></a>
				</div>
			</div>
		</div>
	</div>
</div>

	<div class="container-fluid">
		<div class="row manage-table">
			<div class="panel panel-piluku">
				<div class="panel-heading">
				<h3 class="panel-title">
				<?php
					$countKit = $db->query("SELECT count(*) AS totalKits FROM kitsetup");
					$count = $countKit->fetchArray();
				?>
					List of Kits					<span title="<?php echo $count['totalKits']; ?> total Kits" class="badge bg-primary tip-left"><?php echo $count['totalKits']; ?></span>
					<span class="panel-options custom">
											</span>
				</h3>
			</div>
				<div class="panel-body nopadding table_holder table-responsive" >
					<table class="tablesorter table  table-hover" id="sortable_table">
						<thead>
							<tr>
								<th>KIT ID</th>
								<th>Name</th>
								<th>Unit</th>
								<th>Edit</th>
							</tr>
						</thead>
						<tbody>
						<?php
							if(!isset($_GET['kit']) || $_GET['kit'] == ""){
                        		$items = "SELECT DISTINCT kit_code, kit_name, unit FROM kitsetup ORDER BY kit_name";
							}else{
								$items  = "SELECT DISTINCT kit_code, kit_name, unit FROM kitsetup  WHERE kit_name = '".$_GET['kit']."' ORDER BY kit_name";
							}
							$items = $db->query($items);
							while($row = $items->fetchArray()){
						?>
							<tr>
								<td><?php echo $row['kit_code']; ?></td>
								<td><a href="#" class="underline"><?php echo $row['kit_name']; ?></a></td>
								<?php
								$units = $db->query("SELECT * FROM units WHERE id = '".$row['unit']."'");
								$row3 = $units->fetchArray();
								?>	
								<td><?php echo $row3['unit']; ?></td>
								<td><a href="editkit.php?edit=<?php echo $row['kit_code']; ?>" class="update-kit" title="Update" <?php echo (@$_SESSION['item_kitsedit'] == '') ? 'style="display:none;"': ''; ?>>Edit</a></td>
							</tr>
						<?php } ?>		
							</tbody>
						</table>			
				</div>	
		</div>	
				</div>
	</div>
</div>

			
<?php include 'dfooter.php'; ?>