<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
    include('model.php');
        $sql = new model;
        include('db.php');
        
    if (empty($_SESSION['admin_id'])) {
        header('location:login.php');
    }

    $error="";


    if (isset($_POST['send'])) {
        
        $misSolde=$sql->misSolde($_POST['id']);
        if ($misSolde) {
            $infoUser=$sql->infoUser($_POST['id']);
            $pmUser=$sql->pmUser($_POST['id']);
            $inserReversement=$sql->inserReversement($_POST['id'],$_POST['mnt'],$pmUser);

            $mail = new PHPMailer(true);
        $mail->isSMTP();
        $mail->Host = 'smtp.gmail.com';
        $mail->SMTPAuth = true;
        $mail->Username = 'vision.million.inter@gmail.com';
        $mail->Password ='iwdugwoojkbobdxb';
        $mail->SMTPSecure = 'ssl';
        $mail->Port = 465;

        $mail->setFrom('vision.million.inter@gmail.com');
        $mail->addAddress($infoUser);
        $mail->isHTML(true);
        $mail->Subject = "REVERSEMMENT";
        $mail->Body = '
        <div style="padding:0;margin:0;background-color:#f7f7f7;">
    <table style="table-layout:fixed; border-spacing:0; border-collapse:collapse; background-color:#f7f7f7; width:100%; margin:0 auto; padding:0;" width="100%" cellspacing="0" cellpadding="0" bgcolor="#f7f7f7;">
        <tbody>
            <tr>
                <td align="center" style="padding:25px 0;">
                  <table style="table-layout:fixed; border-spacing:0; border-collapse:collapse; background-color:#fff; border-radius:10px; min-width: 320px; max-width:600px; margin:0 auto; box-shadow:0px 0px 14px -4px rgba(0,0,0,0.2);" width="650" cellspacing="0" cellpadding="0" bgcolor="#f7f7f7;">
                      <tbody>
                          
                          <tr>
                              <td align="center" style="padding:16px 25px 25px;">
                                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
                                      <tbody>
                                          <tr>
                                              <td align="center" style="padding:0;">
                                                  
                                                  
                                                  <p style="color:#000; font-family: Arial, Helvetica, sans-serif; font-size:25px; font-weight:normal; letter-spacing:0.5px; line-height:1.5; text-align:center; margin:0 0 15px;">Cher utilisateur, vous venez de recevoir un reversement d\'un montant de '.$_POST['mnt'].' $ USD de la part de Vision Million suite à vos affiliations.</p>
                                              </td>
                                          </tr>
                                          
                                      </tbody>
                                  </table>
                              </td>
                          </tr>

                          
                         
                          <tr>
                              <td align="center">
                                  <table width="100%" cellspacing="0" cellpadding="0" border="0" style="background-color:#1E2762; padding:25px 25px; border-radius:0 0 10px 10px;">
                                      <tbody>
                                        
                                          <tr>
                                              <td align="center" style="padding:0 0;">
                                                  <p style="color:#fff; font-family:Arial, Helvetica, sans-serif; font-size:13px; font-weight:normal; letter-spacing:0.5px; line-height:1.5; text-align:center; margin:0 0;">Powered by <a href="#" style="color:#f4f4f4; padding:0; margin:0; text-decoration:underline; display:inline-block;padding:0 5px;">Vision million</a>.</p>
                                              </td>
                                          </tr>
                                      </tbody>
                                  </table>
                              </td>
                          </tr>
                      </tbody>
                  </table>
              </td>
          </tr>
      </tbody>
    </table>
    </div>';
    $mail->send();
    $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">
            <!-- 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">Utilisateurs</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 ($error=="modifier_password") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-success mb-xl-0" role="alert">
                                                                <strong> Opération réussie. </strong> <b>Mot de passe modifié</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 ($error=="existe") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-danger mb-xl-0" role="alert">
                                                                <strong> Echec de l\'opération. </strong> <b>Le mail entré correspond à celui d\'un caissier déjà existant.</b> 
                                                            </div>
                                                        ');
                                                    }
                                                    elseif ($error=="caisse_existe") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-danger mb-xl-0" role="alert">
                                                                <strong> Echec de l\'opération. </strong> <b>Un caissier a déjà ce numéro de caisse.</b> 
                                                            </div>
                                                        ');
                                                    }
                                                    elseif ($error=="bloquer") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-success mb-xl-0" role="alert">
                                                                <strong> Opération réussie. </strong> <b>Caissier bloqué</b> 
                                                            </div>
                                                        ');
                                                    }
                                                    elseif ($error=="debloquer") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-success mb-xl-0" role="alert">
                                                                <strong> Opération réussie. </strong> <b>Caissier débloqué</b> 
                                                            </div>
                                                        ');
                                                    }
                                                    
                                                    elseif ($error=="modifier") {
                                                        # code...
                                                        echo('
                                                            <div class="alert alert-success mb-xl-0" role="alert">
                                                                <strong> Opération réussie. </strong> <b>Caissié modifié</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">Nom & Prénom</th>
                                                <th class="sort" data-sort="email">Email</th>
                                                <th class="sort" data-sort="status">Solde</th>
                                                <th class="sort" data-sort="status">Adresse PM</th>
                                                <th class="sort" data-sort="action">Action</th>
                                            </tr>
                                        </thead>
                                        <tbody class="list form-check-all">
                                            <?php 
                                            $utilisateur = $sql -> utilisateur();
                                            while ($utilisateurs = $utilisateur->fetch()) {
                                                echo('
                                                    <tr>
                                                        <td class="id" style="">'.$utilisateurs['nom'].' '.$utilisateurs['pre'].'</td>
                                                        <td class="customer_name">'.$utilisateurs['email'].'</td>
                                                        <td class="customer_name">'.$utilisateurs['solde'].' CFA</td>
                                                        <td class="customer_name">'.$utilisateurs['adresse_pm'].'</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 class="dropdown-item edit-folder-list"');?> onclick='renameFolder("<?php echo $utilisateurs['id'];?>")' <?php echo ('href="#updatefolderModal" data-bs-toggle="modal" role="button"><i class="ri-check-line text-primary"></i>Reversement</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 -->

                <!-- START UPDATE FOLDER  MODAL -->
                <div class="modal fade zoomIn" id="updatefolderModal" tabindex="-1" aria-labelledby="createFileModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered">
                        <div class="modal-content border-0">
                            <div class="modal-header p-3 bg-soft-success">
                                <h5 class="modal-title" id="createFileModalLabel">Reversement</h5>
                                <button type="button" class="btn-close" data-bs-dismiss="modal" id="addFileBtn-close" aria-label="Close"></button>
                            </div>
                            <div class="modal-body">
                                <form  method="post">
                                    <div class="mb-4">
                                        <label for="foldername-input" class="form-label">Montant envoyer ($ USD)</label>
                                        <input type="number" step="0.001" name="mnt" required class="form-control">
                                        <input type="hidden" name="id" id="renamID" class="form-control" id="foldername-input" required>
                                    </div>
                                     
                                    <div class="hstack gap-2 justify-content-end">
                                        <button type="button" class="btn btn-ghost-success" data-bs-dismiss="modal"><i class="ri-close-line align-bottom"></i> Fermer</button>
                                        <button style="background:#1E2762;" type="submit" name="send" class="btn btn-dark" >Soumettre</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- END UPDATE FOLDER MODAL -->

               
                

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

        function renameFolder(val1){
           document.getElementById('renamID').value=val1;      
        }

        
    </script>
</body>

</html>