<?php
session_start();
include_once "../config.php";
require_once '../database1.php';
require_once "../check_admin.php";

class ProductsubCategory extends database
{
    public function index($id)
    { 
		$where['cl_cat_id'] = $id;
		return $this->fetchAll('tb_product_subcategory', $where);
	}

    public function getCurrentCategory($id)
    {
        $where['cl_id'] = $id;
        return $this->fetchRow('tb_product_category', $where);
    }
}
$id='';
if(!isset($_GET['id']))
{
	header('Location: /ACP/product_category/list');
    exit;
}

$id=$_GET['id'];

$obj = new ProductsubCategory();
$category = $obj->getCurrentCategory($id);	
$productCategories = $obj->index($id);
include '../header.php';
?>
            <!-- MAIN CONTENT-->
            <div class="main-content">
                <div class="section__content section__content--p30">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="overview-wrap">
                                    <h2 class="title-1">All Product Subcategories - Category : <?php echo htmlspecialchars($category['cl_name']) ?></h2>
                                    
                                </div>
								
                            </div>
                        </div>
                        
                        <div class="row m-t-25 m-row">
							<div class="col-lg-12">
                                <div class="card">
                                    
                                    <div class="card-body card-block">
                                        <form method="post" class="form" cluster-url="../ajax/product_subcategory/add_ajax?id=<?php echo $id;?>" cluster-redirect="list?id=<?php echo $id;?>">
                                           <?php include_once "template/category_form.php" ?>
                                       </form>
                                   </div>
                                </div>
                            </div>
                               
                                <div class="table-responsive table--no-card m-b-30 top-margin pull-left">
                                    <table class="table table-borderless table-data3 ACP_table" style="width:100%">
                                        <thead>
                                            <tr>
                                                <th>
                                                </th>
                                                <th>Name</th>
												<th>Description</th>
												<th>Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                           <?php
											foreach($productCategories AS $productCategory)
											{
											?>
											<tr class="action-container">
                                                <td><img src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo htmlspecialchars($productCategory['cl_image']);?>" style="width:50px" /></td>
												<td><?php echo htmlspecialchars($productCategory['cl_name']);?></td>
												<td><?php echo htmlspecialchars($productCategory['cl_description']);?></td>
												<td>
                                                    <a class="btn btn-success" href="filters.php?id=<?php echo htmlspecialchars($productCategory['cl_id']) ?>">Add Filters</a>
                                                    <a id="edit" href="edit.php?id=<?php  echo htmlspecialchars($productCategory['cl_id']); ?>" class="btn btn-primary"><i class="fa fa-edit"></i></a>
												    <button type="button" cluster-href="../ajax/product_subcategory/delete_ajax?id=<?php  echo htmlspecialchars($productCategory['cl_id']); ?>" class="remove btn btn-danger btn-delete"><i class="fa fa-trash"></i></button>
                                                    <div class="error-input"></div>

                                                </td>
											</tr>
											<?php
											}
											?>
                                           
                                        </tbody>
                                    </table>
									
                                </div>
                            </div>
                            
                          
                        </div>
                        
                       <script>
						$(document).ready(function(){
							$('.active').removeClass('active');
							$('#customer-menu').addClass('active');
						}); 
						</script>  

                         <script type="text/javascript">
                            jQuery(document).ready(function(){
                                $('#name').change(function(){
                                    var name = $(this).val();
                                    name = name.replace(/ /g,"-");
                                    name = name.replace("'","-");
                                    name = name.replace('"',"-");
                                    name = name.replace(',',"-");
                                    name = name.replace(';',"-");
                                    name = name.replace('/',"-");
                                    name = name.replace('?',"-");
                                    name = name.replace('#',"-");
                                    name = name.replace('&',"-");
                                    name = name.replace('+',"-");
                                    $('#slug').val(name);
                                })
                            })
                        </script>             

  <?php
  include '../footer.php';
  ?>