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

        $_SESSION['nomF']="";
        $_SESSION['prixF']="";
        $_SESSION['prix_usdF']="";

    $infoFormation=$sql->infoFormation();
    while ($infoFormations=$infoFormation->fetch()) {
        $_SESSION['nomF']=$infoFormations['nom'];
        $_SESSION['prixF']=$infoFormations['prix'];
        $_SESSION['prix_usdF']=$infoFormations['prix_usd'];
    }

    if (isset($_POST['add'])) {
        $nom=htmlspecialchars($_POST['nom']);
        $prix=htmlspecialchars($_POST['prix']);
        $prix_usd=htmlspecialchars($_POST['prix_usd']);

        $modFormation=$sql->modFormation($nom,$prix,$prix_usd);

        if ($modFormation) {
            $_SESSION['nomF']=$nom;
            $_SESSION['prixF']=$prix;
            $_SESSION['prix_usdF']=$prix_usd;
            $error="ajouter";
        }

    }
?>
<!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">

<?php include('head.php'); ?>

<body>

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

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

        <div class="app-menu navbar-menu">
            

            <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">Formation</h5>
                                            </div>
                                        </div>
                                        <!--end col-->
                                    </div>
                                <!-- Bouton retour -->
                                            </div>
                                           
                                            <!--end col-->
                                            <div class="col-sm-12">
                                                <?php
                                                    if ($error=="ajouter") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-success mb-xl-0" role="alert">
                                                                <strong> Opération réussie. </strong> 
                                                            </div>
                                                        ');
                                                    }
                                                     
                                                    
                                                    elseif (empty($error)) {
                                                        # code...
                                                    }
                                                ?>

                                            </div>
                                        </div><!--end row-->
                                    </div>
                                </div>
                            </div><!--end col-->
                        </div><!--end row-->
                        <div class="row">
                            <div class="modal-content">
                                <form class="" method="post" enctype="multipart/form-data">
                                    <div class="modal-body">
                                        <div class="row g-2">
                                            <div class="col-md-4">
                                                <label for="customername-field" class="form-label">Intituler</label>
                                                <input type="text" name="nom" class="form-control" required value="<?php echo $_SESSION['nomF'] ?>">
                                                
                                            </div>
                                            <div class="col-md-4">
                                                <label for="customername-field" class="form-label">Prix (FCFA)</label>
                                                <input type="number" min="1" name="prix" class="form-control" required value="<?php echo $_SESSION['prixF'] ?>">
                                                
                                            </div>

                                            <div class="col-md-4">
                                                <label for="customername-field" class="form-label">Prix ($ USD)</label>
                                                <input type="number" min="1" name="prix_usd" class="form-control" required value="<?php echo $_SESSION['prix_usdF'] ?>">
                                                
                                            </div>
                                            
                                           
                                    </div><br>
                                    <div class="modal-footer">
                                        <div class="hstack gap-2 justify-content-end">
                                            <input style="background:#1E2762;" type="submit" class="btn btn-success" name="add" value="Définir">
                                            <!-- <button type="button" class="btn btn-success" id="edit-btn">Update</button> -->
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                        
                        <!-- end row -->
                 

                        <!-- Modal -->
                                                  
                       
                    </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>