<?php include('include/headscript.php'); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <?php include('include/seo.php'); ?>

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <link rel="shortcut icon" href="assets/images/favicon.ico">
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/icons.css" rel="stylesheet" type="text/css">
    <link href="assets/css/style.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdn.materialdesignicons.com/5.4.55/css/materialdesignicons.min.css">

</head>
<style>
    /* Visualizza il pulsante mobile anche su desktop */
    .button-menu-mobile {
        display: inline-block !important;
    }

    /* Nascondi il quadrato rosso con la X su desktop */
    @media (min-width: 992px) {
        .button-menu-mobile {
            background-color: transparent;
            border: none;
            padding: 0;
            width: auto;
            height: auto;
        }

        .button-menu-mobile i.ion-close {
            display: none;
            /* Nasconde la X rossa */
        }

        .button-menu-mobile i.mdi-menu {
            display: inline-block;
            /* Mostra sempre le tre righe orizzontali */
        }
    }

    /* Stile per mobile: Mantieni il comportamento originale */
    @media (max-width: 991.98px) {
        .button-menu-mobile {
            background-color: #ff5e5e;
            /* Questo è il colore rosso originale */
            border-radius: 50%;
            width: 50px;
            height: 50px;
        }

        .button-menu-mobile i.ion-close {
            display: inline-block;
            /* Mostra la X rossa */
        }

        .button-menu-mobile i.mdi-menu {
            display: none;
            /* Nasconde le tre righe quando la barra è aperta */
        }
    }
</style>

<body class="fixed-left">

    <!-- Begin page -->
    <div id="wrapper">
        <?php include('include/navigationbar.php'); ?>

        <!-- Start right Content here -->
        <div class="content-page">
            <!-- Start content -->
            <div class="content">
                <?php include('include/topbar.php'); ?>

                <div class="page-content-wrapper ">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="page-title-box">
                                    <div class="btn-group float-right">
                                        <ol class="breadcrumb hide-phone p-0 m-0">
                                            <li class="breadcrumb-item"><a href="#">Kering Portal</a></li>
                                            <li class="breadcrumb-item active">Dashboard</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Dashboard</h4>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-xl-12">
                                <div class="card">
                                    <div class="card-body">
                                        <h5 class="header-title pb-3 mt-0">XLS TO RSL</h5>
                                        <a class="btn btn-danger" href="importxlsrsl.php" role="button">NEW IMPORT</a>
                                        <br><br>

                                        <div class="table-responsive">
                                            <table class="table table-striped table-sm sm-0">
                                                <thead>
                                                    <tr>
                                                        <?php
                                                        $conn = new mysqli($servername, $username, $password, $database);

                                                        $sql = "SELECT hist_rslxls.id AS hist_id, hist_rslxls.importfilename, hist_rslxls.uniquecode, hist_rslxls.dateimport, 
                                                        auth_users.id AS user_id, auth_users.first_name, auth_users.last_name 
                                                        FROM hist_rslxls 
                                                        LEFT JOIN auth_users ON auth_users.id = hist_rslxls.iduser 
                                                        ORDER BY hist_rslxls.dateimport";
                                                        $result = $conn->query($sql);
                                                        ?>
                                                        <th><strong>Filename</strong></th>
                                                        <th><strong>Unique Code</strong></th>
                                                        <th><strong>Dateimport</strong></th>
                                                        <th><strong>User</strong></th>
                                                        <th width="170"></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php while ($row = $result->fetch_assoc()) { ?>
                                                        <tr>
                                                            <td><?php echo $row['importfilename']; ?></td>
                                                            <td><?php echo $row['uniquecode']; ?></td>
                                                            <td><?php echo $row['dateimport']; ?></td>
                                                            <td><?php echo $row['first_name']; ?> <?php echo $row['last_name']; ?></td>

                                                            <td>
                                                                <a class="btn btn-success" href="detailimportedrsl.php?id=<?php echo $row['hist_id']; ?>&uniquecode=<?php echo $row['uniquecode']; ?>" role="button" data-toggle="tooltip" title="Go"><i class="fas fa-angle-double-right font-size-16 align-middle"></i></a>
                                                                <a class="btn btn-primary create-word-btn" href="javascript:void(0);" onclick="confirmWordCreation('<?php echo $row['hist_id']; ?>', '<?php echo $row['uniquecode']; ?>')" role="button" data-toggle="tooltip" title="Go"><i class="fas fa-file-word font-size-16 align-middle"></i></a>

                                                                <a class="btn btn-danger canc-btn" href="javascript:void(0);" onclick="confirmDelete(<?php echo $row['hist_id']; ?>, '<?php echo $row['uniquecode']; ?>')" role="button" data-toggle="tooltip" title="Delete"><i class="fas fa-trash font-size-16 align-middle"></i></a>
                                                            </td>
                                                        </tr>
                                                    <?php } ?>
                                                </tbody>
                                            </table>
                                        </div><!--end table-responsive-->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div><!-- container -->
                </div> <!-- Page content Wrapper -->
            </div> <!-- content -->
            <?php include('include/footer.php'); ?>
        </div>
        <!-- End Right content here -->
    </div>
    <!-- END wrapper -->

    <!-- SweetAlert2 -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>

    <script>
        function confirmDelete(histId, uniquecode) {
            Swal.fire({
                title: 'Do you want to delete the import process?',
                text: "If you click Yes you cannot recover the data anymore!",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Yes, proceed!'
            }).then((result) => {
                if (result.isConfirmed) {
                    // Reindirizza alla pagina di cancellazione
                    window.location.href = 'cancel-rslxls.php?id=' + histId + '&uniquecode=' + uniquecode;
                }
            });
        }
    </script>
    <script>
        function confirmWordCreation(histId, uniquecode) {
            Swal.fire({
                title: 'Do you want to create a Word Document?',
                text: "Click Yes to proceed with the creation!",
                icon: 'question',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Yes',
                cancelButtonText: 'No'
            }).then((result) => {
                if (result.isConfirmed) {
                    // Reindirizza alla pagina di creazione del Word
                    window.location.href = 'createword.php?id=' + histId + '&uniquecode=' + uniquecode;
                }
            });
        }
    </script>

    <!-- jQuery  -->
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/popper.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/modernizr.min.js"></script>
    <script src="assets/js/detect.js"></script>
    <script src="assets/js/fastclick.js"></script>
    <script src="assets/js/jquery.slimscroll.js"></script>
    <script src="assets/js/jquery.blockUI.js"></script>
    <script src="assets/js/waves.js"></script>
    <script src="assets/js/jquery.nicescroll.js"></script>
    <script src="assets/js/jquery.scrollTo.min.js"></script>
    <script src="assets/plugins/chart.js/chart.min.js"></script>
    <script src="assets/pages/dashboard.js"></script>
    <script src="assets/js/app.js"></script>
</body>

</html>