<?php
include_once '../includes/config.php';
include_once '../includes/database.php';
include_once '../includes/check_session.php';
include_once '../includes/auth.php';

$auth = array('customer_admin');
$authRes = checkAuth($auth, $user);
if(!$authRes)
{
    header('Location: ' . DOMAIN . '/auth/login.php');
    exit;
}

class Add extends database
{
   
    public function GetAll($id)
    {
        $where['cl_user_id'] = $id;
        return $this->fetchAll('tb_category', $where);
    }
   
}

$cat = new Add();

$category = $cat->GetAll($user['cl_id']);

 include '../header.php';
 ?>
<div class="content-wrapper">
            <!-- Content -->

            <div class="container-xxl flex-grow-1 container-p-y">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card ">
                            <div class="card-header">

                                <h4 class="fw-bold py-3 mb-4">Add Menu Category</h4>
                            </div>
                            <div class="col-sm-12 card-body">
                                <div class="row">

                                    <form method="post" class="form" cluster-url="ajax/add_ajax.php" cluster-redirect="add.php">
                                        <div class="error-main"></div>
                                        <?php include_once 'template/form.php' ?>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                

             
											
					
                                
                        
                <div class=" col-sm-12 order-wraper mt-2">
                   <div class="card mb-4">
                        <div class="card-header">Category List</div>
                        <div class="card-body">
                            <div class="col-md-12">
                        	<div class="curent-user">
                            	<div class="row">
    								
                                    <div class="col-sm-12">
                                        <div class="curent-user-nav">
                                            <table class="table table-responsive"> 
                                                            <tr>
                                                                    <th>Name</th>
                                                                    <th>Description</th>
                                                                    <th>Actions</th>
                                                            </tr>
                                                            <?php
                                                             
                                                             foreach($category as $u)
                                                             {

                                                            ?>
                                                            <tr>
                                                                    <td><?php echo htmlspecialchars($u['cl_name']);?></td>
                                                                    <td><?php echo htmlspecialchars($u['cl_description']);?></td>
                                                                    <td><button  cluster-href="ajax/delete_ajax.php?id=<?php  echo htmlspecialchars($u['cl_id']); ?>" cluster-confirm="Are you sure you want to delete the category?" class="btn btn-danger btn-delete">REMOVE</button>
                                                                    <a  href="edit.php?id=<?php  echo htmlspecialchars($u['cl_id']); ?>" class="track-btn btn btn-primary">EDIT</a>
                                                                    <div class="error-input"></div>
                                                                    </td>
                                                            </tr>
                                                            <?php

                                                             }
                                                            ?>
                                    </table>
                                        	
                                        </div>
                                	</div>
                                    
                            	</div>                            
                            </div>
                        </div>
                        </div>
                    </div>
                  
                        
                        </div>
                </div>
                
            </div>
        </div>

<script>
    $(document).ready(function(){
       
    });
	
    </script>

    <script>
    $(document).ready(function(){
        $('.menu-item').removeClass('active');
        $('#add-category-menu').addClass('active');
    }); 
</script>
<?php include '../footer.php';