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

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

class Edit extends database
{
    public function currentCategory($id)
    {
        return $this->fetchRow('tb_category', ['cl_id' => $id]);
    }
}

$cat = new Edit();

$data = $cat->currentCategory($id);
if(!$data || $data['cl_user_id'] != $user['cl_id'])
{
    header('Location: ../index.php');
    exit;
}


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

            <div class="container-xxl flex-grow-1 container-p-y">
              <h4 class="fw-bold py-3 mb-4">Update Menu Category</h4>
                

              <!-- Basic Layout -->
              <div class="row">
											
					
                                <div class="col-sm-12">
                                    <div class="row">
									
                                        <form method="post" class="form" cluster-url="ajax/edit_ajax.php?id=<?php echo $id ?>" cluster-redirect="add.php">
                                            <div class="error-main"></div>
                                            <?php include_once 'template/form.php' ?>
                                        </form>
                                    </div>
                            	</div>
                        
                
                
            </div>
        </div>
	</div>

<script>
    $(document).ready(function(){
        $('.btn-remove').click(function(){
            var parent = $(this).parents('tr').first();
            var conf = confirm("Are you sure you want to delete this category?");
            if(conf)
            {
                var href = $(this).attr('data-href');
                $.post(href, function(res){
                    alert("Deletion Successful");
                    $(parent).remove();
                },'json').fail(function(xhr){
                   alert(xhr.responseJSON);
                },'json');
            }
        });
    });
	
    </script>

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