File "test002.php"

Full Path: /home/analogde/www/Resize_Quashai/New folder/test002.php
File size: 4.25 KB
MIME-type: text/x-php
Charset: utf-8

<?php

// Liste des jours fériés à exclure (exemple simplifié)

$jours_feries = [

    '2025-01-01', '2025-04-06', '2025-05-01', '2025-05-08', '2025-05-29', 

    '2025-06-08', '2025-07-14', '2025-08-15', '2025-11-01', '2025-12-25'

];



// Générer les dates de janvier à décembre 2025

$startDate = strtotime("2025-01-01");

$endDate = strtotime("2025-12-31");

$dates = [];

for ($date = $startDate; $date <= $endDate; $date = strtotime("+1 day", $date)) {

    $dateStr = date("Y-m-d", $date);

    if (!in_array($dateStr, $jours_feries)) {

        $dates[] = $dateStr;

    }

}



// Diviser les dates par mois pour appliquer une couleur de fond différente

$dates_par_mois = [];

foreach ($dates as $date) {

    $mois = date("m", strtotime($date));

    $dates_par_mois[$mois][] = $date;

}



// Affichage du tableau

?>

<!DOCTYPE html>

<html lang="fr">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Tableau des dates de 2025</title>

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">

    <style>

        .month-color-1 { background-color: #f0f8ff; }

        .month-color-2 { background-color: #faebd7; }

        .month-color-3 { background-color: #f5f5dc; }

        /* Ajoutez plus de couleurs si nécessaire pour chaque mois */

    </style>

</head>

<body>

    <div class="container mt-5">

        <button id="addRowBtn" class="btn btn-primary mb-3">Add</button> <!-- Bouton Add -->

        <table class="table table-bordered" id="datesTable">

            <thead>

                <tr>

                    <th>Titre</th>

                    <?php foreach ($dates_par_mois as $mois => $mois_dates): ?>

                        <?php foreach ($mois_dates as $date): ?>

                            <th><?= date("d/m/Y", strtotime($date)) ?></th>

                        <?php endforeach; ?>

                    <?php endforeach; ?>

                </tr>

            </thead>

            <tbody>

                <tr>

                    <td>Jours</td>

                    <?php foreach ($dates_par_mois as $mois => $mois_dates): ?>

                        <?php foreach ($mois_dates as $date): ?>

                            <td class="table_date month-color-<?= $mois ?>" data-date="<?= $date ?>" data-value="0" style="cursor: pointer;">0</td>

                        <?php endforeach; ?>

                    <?php endforeach; ?>

                </tr>

            </tbody>

        </table>

    </div>



    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <script>

        $(document).ready(function(){

            // Action de clic sur les cellules pour modifier leur valeur

            $(".table_date").click(function(){

                var currentValue = $(this).data("value");

                if (currentValue == "0") {

                    $(this).data("value", "1");

                    $(this).text("1");

                    $(this).css("background-color", "#90EE90"); // Couleur pour '1'

                } else {

                    $(this).data("value", "0");

                    $(this).text("0");

                    $(this).css("background-color", ""); // Réinitialiser la couleur de fond

                }

            });



            // Ajouter une nouvelle ligne lors du clic sur le bouton Add

            $("#addRowBtn").click(function(){

                var newRow = "<tr>";

                newRow += "<td>Jours</td>"; // Colonne 'Jours'



                // Ajouter une cellule pour chaque date

                <?php foreach ($dates_par_mois as $mois => $mois_dates): ?>

                    <?php foreach ($mois_dates as $date): ?>

                        newRow += '<td class="table_date month-color-<?= $mois ?>" data-date="<?= $date ?>" data-value="0" style="cursor: pointer;">0</td>';

                    <?php endforeach; ?>

                <?php endforeach; ?>



                newRow += "</tr>";

                // Ajouter la nouvelle ligne à la fin du tableau

                $("#datesTable tbody").append(newRow);

            });

        });

    </script>

</body>

</html>