<?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 getAllMenus($userID)
    {
        $sql = ' SELECT m.*, c.cl_name AS category FROM tb_menu m INNER JOIN tb_category c ON m.cl_cat_id=c.cl_id WHERE m.cl_user_id=?';
        return $this->callQuery($sql, [$userID]);
    }
    
    public function getAllCategory($userID)
    {
        $where['cl_user_id'] = $userID;
        return $this->fetchAll('tb_category', $where);
    }
    
}

$obj = new Add();
$categories = $obj->getAllCategory($user['cl_id']);
$menus = $obj->getAllMenus($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 Item</h4>
              </div>
                <div class="col-sm-12 card-body">
                    <div class="row">
                   
                        <div class="col-sm-12">
                            <div class="order-contact">
                                    <div class="row edit-user-box">
                                    <div class="col-sm-12">
                                        <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>
                    
                        <div class="col-sm-12  order-wraper mt-2">
                            <div class="card mb-4">
                                <div class="card-header">Menu List</div>
                                <div class="card-body">
                                    <div class="col-sm-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>Price</th>
                                                                    <th>Category</th>
                                                                    <th>
                                                                        Type
                                                                    </th>
                                                                    <th>Actions</th>
                                                            </tr>
                                                            <?php

                                                             foreach($menus as $u)
                                                             {
                                                            ?>
                                                            <tr>
                                                                    <td><?php echo htmlspecialchars($u['cl_name']);?></td>
                                                                    <td><?php echo htmlspecialchars($u['cl_price']);?></td>
                                                                    <td><?php echo htmlspecialchars($u['category']);?></td>
                                                                    <td><?php echo htmlspecialchars($u['cl_type']);?></td>
                                                                    <td><button class="btn  btn-danger btn-delete" cluster-href="ajax/delete_ajax.php?id=<?php  echo htmlspecialchars($u['cl_id']); ?>" class=" btn btn-danger btn-delete" cluster-confirm="Are you sure you want to delte this menu?">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>

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

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