Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
ONSEMI
/
New folder
:
code_001.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php function getHolidays($year) { $holidays = [ "$year-01-01", // Jour de l'An "$year-05-01", // Fête du Travail "$year-05-08", // Victoire 1945 "$year-07-14", // Fête Nationale "$year-08-15", // Assomption "$year-11-01", // Toussaint "$year-11-11", // Armistice "$year-12-25", // Noël ]; // Ajouter Ascension (39 jours après Pâques) et Pentecôte (49 jours après Pâques) $easterDate = easter_date($year); $ascension = date('Y-m-d', strtotime('+39 days', $easterDate)); $pentecost = date('Y-m-d', strtotime('+49 days', $easterDate)); $holidays[] = $ascension; $holidays[] = $pentecost; return $holidays; } function isBusinessDay($date, $holidays) { $dayOfWeek = date('N', $date); // 1 (lundi) à 7 (dimanche) return $dayOfWeek < 6 && !in_array(date('Y-m-d', $date), $holidays); } function generateTable($startDate, $endDate) { setlocale(LC_TIME, 'fr_FR.UTF-8'); // S'assurer que les noms des jours sont en français $currentDate = strtotime($startDate); $endDate = strtotime($endDate); $holidays = getHolidays(date('Y', $currentDate)); $monthColors = [ "#FFCCCC", "#FFE5CC", "#FFFFCC", "#E5FFCC", "#CCFFCC", "#CCFFE5", "#CCFFFF", "#CCE5FF", "#CCCCFF", "#E5CCFF", "#FFCCFF", "#FFCCE5", ]; $weekOddColor = "#D6EAF8"; $weekEvenColor = "#AED6F1"; echo '<div class="table-responsive">'; echo '<table class="table table-bordered text-center">'; // Première ligne : en-têtes echo '<thead><tr><th>Date</th>'; while ($currentDate <= $endDate) { if (isBusinessDay($currentDate, $holidays)) { $formattedDate = date('d/m/Y', $currentDate); echo '<th style="background-color: ' . $monthColors[date('n', $currentDate) - 1] . ';">' . $formattedDate . '</th>'; } $currentDate = strtotime('+1 day', $currentDate); } echo '</tr>'; // Réinitialiser la date pour la deuxième ligne (numéros de semaine) $currentDate = strtotime($startDate); echo '<tr><td>Semaine</td>'; $lastWeekNumber = null; $weekCellCount = 0; while ($currentDate <= $endDate) { if (isBusinessDay($currentDate, $holidays)) { $weekNumber = date('W', $currentDate); if ($weekNumber === $lastWeekNumber) { $weekCellCount++; } else { if ($lastWeekNumber !== null) { $color = ($lastWeekNumber % 2 === 0) ? $weekEvenColor : $weekOddColor; echo '<td colspan="' . $weekCellCount . '" style="background-color: ' . $color . ';">' . $lastWeekNumber . '</td>'; } $lastWeekNumber = $weekNumber; $weekCellCount = 1; } } $currentDate = strtotime('+1 day', $currentDate); } // Dernière cellule pour le dernier numéro de semaine if ($lastWeekNumber !== null) { $color = ($lastWeekNumber % 2 === 0) ? $weekEvenColor : $weekOddColor; echo '<td colspan="' . $weekCellCount . '" style="background-color: ' . $color . ';">' . $lastWeekNumber . '</td>'; } echo '</tr>'; // Réinitialiser la date pour la troisième ligne (jours de la semaine) $currentDate = strtotime($startDate); echo '<tr><td>Jours</td>'; while ($currentDate <= $endDate) { if (isBusinessDay($currentDate, $holidays)) { $dayName = mb_substr(ucfirst(strftime('%A', $currentDate)), 0, 3) . '.'; echo '<td>' . $dayName . '</td>'; } $currentDate = strtotime('+1 day', $currentDate); } echo '</tr></thead>'; // Réinitialiser la date pour la quatrième ligne (données) $currentDate = strtotime($startDate); echo '<tbody><tr><td class="titre_nom" contenteditable="true">toto</td>'; while ($currentDate <= $endDate) { if (isBusinessDay($currentDate, $holidays)) { echo '<td class="table_date" data-status="0" style="cursor: pointer;">0</td>'; } $currentDate = strtotime('+1 day', $currentDate); } echo '</tr></tbody>'; echo '</table>'; echo '</div>'; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tableau Dynamique</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <style> .table_date[data-status="1"] { background-color: #007BFF; color: #fff; } .titre_nom[contenteditable="true"] { border: 1px dashed #000; padding: 5px; } </style> </head> <body> <div class="container my-5"> <h1 class="text-center mb-4">Tableau Dynamique</h1> <?php generateTable('2025-01-01', '2025-12-31'); ?> </div> <script> document.addEventListener('DOMContentLoaded', () => { // Gestion du clic sur les cellules de la ligne "données" document.querySelectorAll('.table_date').forEach(cell => { cell.addEventListener('click', () => { if (cell.dataset.status === '0') { cell.dataset.status = '1'; cell.textContent = '1'; } else { cell.dataset.status = '0'; cell.textContent = '0'; } }); }); // Gestion de l'édition de la cellule titre_nom const titreNomCell = document.querySelector('.titre_nom'); titreNomCell.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); titreNomCell.blur(); } }); }); </script> </body> </html>