<?php
session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone = "#tableZone" . $pageSequence;
$_SESSION['sequence']++;

$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir']."core.php");
$res = $dba->getSCCSmsDetails(0); // À créer
?>

<div id="<?php echo $toDiv; ?>" class="tab-content">
    <table width="100%">
        <tr>
            <td><div id="<?php echo $resultZoneDiv; ?>"></div></td>
        </tr>
    </table>

    <table width="100%">
        <td align="center">
            <table width="94%" border="0">
                <tr>
                    <td align="center">
                        <div class="containerIcons">
                            <div>
                                <button id="refreshPage" class="btn" onclick="getPage('<?php echo $_SERVER['PHP_SELF']; ?>','<?php echo $toDiv; ?>')">
                                    <i class="cus-page-refresh"></i> Rafraichir
                                </button>
                                <button id="addBtnSmsCampaign" class="btn" data-href="<?php echo $currentBaseDir; ?>/create_sms_campaign.php?toDiv=<?php echo $toDiv; ?>&rpage=<?php echo $_SERVER['PHP_SELF']; ?>">
                                    <i class="cus-add"></i> Créer
                                </button>
                                <button class="btn" id="sms-campaign-delete" disabled><i class="cus-delete"></i> Supprimer</button>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <table id="tblSmsMngt" class="table table-striped table-bordered" width="100%">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th></th>
                                    <th>Date de création</th>
                                    <th>Nom de la campagne</th>
                                    <th>Message</th>
                                    <th>Statut</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($res as $row): ?>
                                    <tr>
                                        <td><input type="checkbox" class="delete-campaign" value="<?= $row['campaign_id_n']; ?>"></td>
                                        <td><a href="#" class="cus-application-form-edit" data-href="<?php echo $currentBaseDir; ?>/edit_sms_campaign.php?item=<?= $row['campaign_id_n']; ?>&toDiv=<?= $toDiv; ?>&rpage=<?= $_SERVER['PHP_SELF']; ?>"></a></td>
                                        <td><?= $row['creation_date_d']; ?></td>
                                        <td><?= $row['campaign_name_v']; ?></td>
                                        <td><?= $row['message_v']; ?></td>
                                        <td><?= $row['description_v']; ?></td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </table>
</div>

<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<script>
$('#tblSmsMngt').DataTable({
    language: {
        search: "Filtrer :",
        emptyTable: "Aucune campagne",
        lengthMenu: "Afficher _MENU_ entrées",
        info: "Affichage de _START_ à _END_ sur _TOTAL_",
        paginate: {
            first: "Début", last: "Fin", next: "Suivant", previous: "Précédent"
        }
    }
});

$("#addBtnSmsCampaign").click(function() {
    var url = $(this).data("href");
    $(".modal-title").html("Créer une campagne SMS");
    $(".modal-body").load(url, function() {
        $("#myModalDesc").modal({ backdrop: 'static', keyboard: false });
    });
});

const checkBoxes = $(".delete-campaign");
checkBoxes.change(function () {
    $("#sms-campaign-delete").prop("disabled", checkBoxes.filter(":checked").length < 1);
});
</script>
