<?php ob_start(); include ("header1.php");
 $querylogin = "select * from  mst_users where user_name = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_name = $row['user_name'];
$user_id = $row['user_id'];
$first_name = $row['first_name'];
 $login_type_admin=$row['login_type'];
}
 


?>
<?php
	require_once("perpage.php");	
	require_once("dbcontroller.php");
	$db_handle = new DBController();
	
	
	$category_name = "";
	
	$queryCondition = "";
	if(!empty($_POST["search"])) {
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

$queryCases = array("category_name");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
					
						
						
						case "category_name":
						$category_name = $v;
						$queryCondition .= "category_name LIKE '%" . $v . "%'";
						break;
						
						
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY category_name  "; 
	$sql = "SELECT * FROM  category_master   " . $queryCondition ."  " ;
	}else{
	 $sql= "SELECT * FROM  category_master order by category_name ASC";
	}
	 $sql ;
	$href = 'view_all_category.php';					
	
	$perPage = 5000; 
	$page = 1;
	if(isset($_POST['page'])){
		$page = $_POST['page'];
	}
	$start = ($page-1)*$perPage;
	if($start < 0) $start = 0;
		
	$query =  $sql . $orderby .  " limit " . $start . "," . $perPage; 
	$result = $db_handle->runQuery($query);
	
	if(empty($result)) {
		
	$result["perpage"] = showperpage($sql, $perPage, $href);
	}
	else{ 
	$result["perpage"] = showperpage($sql, $perPage, $href); }
	
?>

<div class="content-page">
<div class="content">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="page-header-title">
<button type="button" class="btn btn-dark  waves-effect waves-light" onclick="location.href='master_dashboard.php'">BACK</button>
<button type="button" class="btn btn-danger  waves-effect waves-light" onclick="location.href='add_category.php'">ADD CATEGORY</button>
<div class="clearfix"></div>
</div>
</div>
</div>
<form name="chkForm" id="chkForm" action="view_all_category.php"  method="post" >
<div class="row">
<div class="col-sm-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Search Machines</h3>
</div>
<div class="panel-body">
<div class="row">

<div class="col-sm-3 col-xs-12">
<div class="form-group">
<label>Category Name</label>
<input type="text" class="form-control"  name="search[category_name]" value="<?php echo $category_name?>"/>
</div>
</div>


<div class="col-sm-12 col-xs-12">
<div class="m-t-20">
<div class="form-group">
<div>
<button type="submit" class="btn btn-primary waves-effect waves-light"> Submit </button>
<input type="reset" class="btn btn-primary " value="Reset" onClick="window.location='view_all_category.php'">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"> View all Category</h3>
</div>
<div class="panel-body">
<table  id="datatable-buttons" class="table table-striped table-bordered">
<thead>
<tr>
<th>Sr No</th>
<th>Category Name</th>
<th>Action</th>
<TH>Action</TH>
</tr>
</thead>
<tbody>
<?php 
foreach($result as $k=>$v) {
if(is_numeric($k)) {

$category_name = $result[$k]["category_name"];
$category_id = $result[$k]["category_id"];

?>
<tr>
<td><?php echo $k + 1; ?></td>
<td><?php echo $category_name; ?></td>
<td>
        <a href="category_edit.php?category_id=<?= $category_id ?>" 
           class="btn btn-primary btn-xs">EDIT</a>
</td>
<td>
        <a href="category_delete.php?category_id=<?= $category_id ?>" 
           class="btn btn-danger btn-xs"
           onclick="return confirm('Are you sure you want to delete this category?');">
           DELETE
        </a>
    </td>
</tr>
<?php }}?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer1.php';?>
