<?php
    include('model.php');
        $sql = new model;
        
    if (empty($_SESSION['admin_id'])) {
        header('location:login.php');
    }
    

$error="";

// bloquer un caissier
if(isset($_GET['blok']) && !empty($_GET['blok'])){
    $_SESSION['blok']=$_GET['blok'];
    $supprimer_offre= $sql->supprimer_offre($_SESSION['blok']);
    if($supprimer_offre){
        //echo "<script>alert(\"Filière supprimée  .\")</script>";  
        //echo '<script>window.location.href="caissiers"</script>';  
        $error="supprimer";
    }else {
        //echo "<script>alert(\"Erreur .\")</script>"; 
        $error="erreur";
    }
}



?>
<!doctype html>
<html lang="en" data-layout="horizontal" data-topbar="dark" data-sidebar-size="lg" data-sidebar="light" data-sidebar-image="none" data-preloader="disable">

<head>

    <meta charset="utf-8" />
    <title>ADMIN Agritraders</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="Minimal Admin & Dashboard Template" name="description" />
    <meta content="Themesbrand" name="author" />
    <!-- App favicon -->
    <link rel="shortcut icon" href="assets/images/LOG1_dark.png">
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
    <!-- Sweet Alert css-->
    <link href="assets/libs/sweetalert2/sweetalert2.min.css" rel="stylesheet" type="text/css" />

    <!-- Layout config Js -->
    <script src="assets/js/layout.js"></script>
    <!-- Bootstrap Css -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Icons Css -->
    <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
    <!-- App Css-->
    <link href="assets/css/app.min.css" rel="stylesheet" type="text/css" />
    <!-- custom Css-->
    <link href="assets/css/custom.min.css" rel="stylesheet" type="text/css" />
       
</head>

<body>

    <!-- Begin page -->
    <div id="layout-wrapper">

       <?php include('header.php'); ?>
       <br>

        <div class="app-menu navbar-menu">
            <!-- LOGO -->
            <!-- <div class="navbar-brand-box">
                
                <a href="index.html" class="logo logo-dark">
                    <span class="logo-sm">
                        <img src="assets/images/logo-sm.png" alt="" height="22">
                    </span>
                    <span class="logo-lg">
                        <img src="assets/images/logo-dark.png" alt="" height="17">
                    </span>
                </a>
                
                <a href="index.html" class="logo logo-light">
                    <span class="logo-sm">
                        <img src="assets/images/logo-sm.png" alt="" height="22">
                    </span>
                    <span class="logo-lg">
                        <img src="assets/images/logo-light.png" alt="" height="17">
                    </span>
                </a>
                <button type="button" class="btn btn-sm p-0 fs-20 header-item float-end btn-vertical-sm-hover" id="vertical-hover">
                    <i class="ri-record-circle-line"></i>
                </button>
            </div> -->

            <div id="scrollbar">
                <div class="container-fluid">

                    <div id="two-column-menu">
                    </div>
                    <ul class="navbar-nav" id="navbar-nav">
                        <?php include('nav.php'); ?>
                    </ul>
                </div>
                <!-- Sidebar -->
            </div>

            <div class="sidebar-background"></div>
        </div>
        <!-- Left Sidebar End -->
        <!-- Vertical Overlay-->
        <div class="vertical-overlay"></div>
            <div class="main-content">
                <div class="page-content">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="card">
                                    <div class="card-body">
                                        <div class="row g-2">
                                            <div class="col-sm-9">
                                                <!-- Bouton retour -->
                                    <div class="row justify-content-beetwen g-2 mb-3">

                                        <div class="col-auto">
                                            <div class="d-flex gap-2 align-items-start">
                                                <h5 class="mb-sm-0">Gestion des demandes</h5>
                                            </div>
                                        </div>
                                        <!--end col-->
                                    </div>
                                <!-- Bouton retour -->
                                            </div>
                                         
                                            <!--end col-->
                                            <div class="col-sm-12">
                                                <?php
                                                    if ($error=="supprimer") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-success mb-xl-0" role="alert">
                                                                <strong> Opération réussie. </strong> <b>Demande supprimée</b> 
                                                            </div>
                                                        ');
                                                    }
                                                    
                                                    elseif ($error=="erreur") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-danger mb-xl-0" role="alert">
                                                                <strong> Echec de l\'opération </strong> <b>Veuillez réessayer.</b> 
                                                            </div>
                                                        ');
                                                    }
                                                    elseif (empty($error)) {
                                                        # code...
                                                    }
                                                ?>

                                            </div>
                                        </div><!--end row-->
                                    </div>
                                </div>
                            </div><!--end col-->
                        </div><!--end row-->
                        
                        <!-- end row -->
                 

                        <!-- Modal -->
                                                  
                        <div class="card-body"><br>
                            <div id="customerList">
                                <div class="row g-4 mb-3">
                                    <div class="col-sm-auto"></div>
                                    <div class="col-sm">
                                        <div class="d-flex justify-content-sm-end">
                                            <div class="search-box ms-2">
                                                <input type="text" class="form-control search" placeholder="Rechercher...">
                                                <i class="ri-search-line search-icon"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>  
                                <div class="table-responsive table-card mt-3 mb-1">
                                    <table class="table align-middle table-nowrap" id="customerTable">
                                        <thead class="table-light">
                                            <tr>
                                                <th class="sort" data-sort="customer_name">Référence</th>
                                                <th class="sort" data-sort="email">Produit</th>
                                                <th class="sort" data-sort="status">Quantité</th>
                                                <th class="sort" data-sort="status">Pays</th>
                                                <th class="sort" data-sort="action">Action</th>
                                            </tr>
                                        </thead>
                                        <tbody class="list form-check-all">
                                            <?php 
                                            $demande = $sql -> demande();
                                            while ($demandes = $demande->fetch()) {
                                                echo('
                                                    <tr>
                                                        <td class="id" style="">'.$demandes['reference'].'</td>
                                                        <td class="customer_name">'.$demandes['produit'].'</td>
                                                        <td class="customer_name">'.$demandes['qte'].'</td>
                                                        <td class="customer_name">'.$demandes['pays'].'</td>
                                                        <td>
                                                        <div class="">
                                                            <button class="btn btn-ghost-primary btn-icon btn-sm dropdown" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                                                <i class="bx bx-dots-horizontal-rounded fs-16 align-bottom"></i>
                                                            </button>
                                                            <ul class="dropdown-menu dropdown-menu-end">
                                                                
                                                                <li><a onclick="return confirmsup()" class="dropdown-item" href="?blok='.$demandes['id'].'"><i class="ri-close-line text-danger"></i>Supprimer</a></li>
                                                                <li><a class="dropdown-item" href="detail_demande.php?det='.$demandes['id'].'"><i class="ri-close-line text-danger"></i>Détail</a></li>
                                                                
                                                            </ul>
                                                        </div>
                                                        </td>
                                                        
                                                    </tr>
                                                ');
                                            }
                                            ?>
                                        </tbody>
                                    </table>
                                    <div class="noresult" style="display: none">
                                        <div class="text-center">
                                            <lord-icon src="https://cdn.lordicon.com/msoeawqm.json" trigger="loop" colors="primary:#121331,secondary:#08a88a" style="width:75px;height:75px"></lord-icon>
                                            <h5 class="mt-2">Aucun résultat</h5>
                                            <p class="text-muted mb-0"></p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div><!-- end card -->
                    </div>
                    <!-- container-fluid -->
                </div>
                <!-- End Page-content -->

                

                <?php include ('footer.php'); ?>
            </div>
        <!-- end main content-->
    </div>
    <!-- END layout-wrapper -->



    <!--start back-to-top-->
    <button onclick="topFunction()" class="btn btn-danger btn-icon" id="back-to-top">
        <i class="ri-arrow-up-line"></i>
    </button>
    <!--end back-to-top-->

    <!--preloader-->
    <div id="preloader">
        <div id="status">
            <div class="spinner-border text-primary avatar-sm" role="status">
                <span class="visually-hidden">Loading...</span>
            </div>
        </div>
    </div>

    

    <!-- JAVASCRIPT -->
    <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="assets/libs/simplebar/simplebar.min.js"></script>
    <script src="assets/libs/node-waves/waves.min.js"></script>
    <script src="assets/libs/feather-icons/feather.min.js"></script>
    <script src="assets/js/pages/plugins/lord-icon-2.1.0.js"></script>
    <script src="assets/js/plugins.js"></script>
    <!-- prismjs plugin -->
    <script src="assets/libs/prismjs/prism.js"></script>
    <script src="assets/libs/list.js/list.min.js"></script>
    <script src="assets/libs/list.pagination.js/list.pagination.min.js"></script>

    <!-- listjs init -->
    <script src="assets/js/pages/listjs.init.js"></script>

    <!-- Sweet Alerts js -->
    <script src="assets/libs/sweetalert2/sweetalert2.min.js"></script>

    <!-- App js -->
    <script src="assets/js/app.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
    <script>
        $(document).ready(function() {
        $('select').select2();
        });
    </script>
    <script>
        function confirmsup(){
            return confirm("Etes-vous sur de vouloir effectuer cette action ? ")
        }

      
    </script>
</body>

</html>