<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tableau interactif - Jours ouvrables</title> <style> table { width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; } th, td { border: 1px solid #ddd; text-align: left; padding: 8px; } th { background-color: #f2f2f2; text-align: center; } tr:nth-child(even) { background-color: #f9f9f9; } tr:hover { background-color: #ddd; } input[type="text"] { width: 100%; box-sizing: border-box; border: 1px solid #ccc; padding: 5px; } button { margin-top: 10px; padding: 10px 15px; background-color: #4CAF50; color: white; border: none; cursor: pointer; } button:hover { background-color: #45a049; } /* Figer la première colonne */ .sticky-col { position: sticky; left: 0; background-color: #f9f9f9; /* Assurez-vous que la couleur de fond est fixe */ z-index: 2; /* S'assurer qu'elle reste au-dessus des autres colonnes */ } /* Pour l'entête de la première colonne */ .sticky-col-header { z-index: 3; /* Priorité sur les autres lignes */ } /* Couleurs de fond alternées pour les mois */ .month-odd { background-color: #e6f7ff; } .month-even { background-color: #fff3e0; } /* Style pour les cellules cliquables */ .clickable-cell { cursor: pointer; } .clicked { background-color: #ffeb3b; /* Couleur de fond pour les cellules cliquées */ } </style> </head> <body> <h1>Tableau interactif - Jours ouvrables sur 1 an</h1> <?php $year = date("Y"); // Année en cours $dates = []; $currentDate = new DateTime("$year-01-01"); // Liste des jours fériés français pour l'année en cours $publicHolidays = [ "$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 1918 "$year-12-25", // Noël ]; // Ajouter Pâques et le lundi de Pâques $easter = new DateTime("$year-03-21"); $easter->modify('+' . easter_days($year) . ' days'); $publicHolidays[] = $easter->format('Y-m-d'); $easterMonday = clone $easter; $easterMonday->modify('+1 day'); $publicHolidays[] = $easterMonday->format('Y-m-d'); // Ajouter l'Ascension $ascension = clone $easter; $ascension->modify('+39 days'); $publicHolidays[] = $ascension->format('Y-m-d'); // Ajouter la Pentecôte et le lundi de Pentecôte $pentecote = clone $easter; $pentecote->modify('+49 days'); $publicHolidays[] = $pentecote->format('Y-m-d'); $pentecoteMonday = clone $pentecote; $pentecoteMonday->modify('+1 day'); $publicHolidays[] = $pentecoteMonday->format('Y-m-d'); // Générer les jours ouvrables (lundi-vendredi) pour l'année en excluant les jours fériés while ($currentDate->format("Y") == $year) { $dayOfWeek = $currentDate->format("N"); // 1 = Lundi, 7 = Dimanche $dateString = $currentDate->format("Y-m-d"); if ($dayOfWeek >= 1 && $dayOfWeek <= 5 && !in_array($dateString, $publicHolidays)) { $dates[] = $dateString; } $currentDate->modify("+1 day"); } $columns = $dates; // Calculer les numéros de semaines pour chaque colonne $weekNumbers = []; foreach ($columns as $date) { $weekNumbers[] = (new DateTime($date))->format("W"); } // Calculer les noms des jours de la semaine pour chaque colonne $dayNames = []; $frenchDayNames = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"]; foreach ($columns as $date) { $dayOfWeek = (new DateTime($date))->format("N"); // 1 = Lundi, 7 = Dimanche $dayName = $frenchDayNames[$dayOfWeek - 1]; $dayNames[] = ucfirst(substr($dayName, 0, 3)) . '.'; } // Si le formulaire est soumis, récupérer les données $submittedData = []; if ($_SERVER["REQUEST_METHOD"] === "POST" && !empty($_POST["cell"])) { $submittedData = $_POST["cell"]; // Sauvegarder les données dans un fichier texte $file = 'data.txt'; $dataString = ''; foreach ($submittedData as $dayIndex => $row) { foreach ($row as $colIndex => $value) { $dataString .= "cell[$dayIndex][$colIndex]=$value\n"; } } file_put_contents($file, $dataString); } // Charger les données sauvegardées si elles existent $file = 'data.txt'; if (file_exists($file)) { $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($lines as $line) { preg_match('/cell\[(\d+)\]\[(\d+)\]=([01])/', $line, $matches); if (count($matches) === 4) { $dayIndex = $matches[1]; $colIndex = $matches[2]; $value = $matches[3]; $submittedData[$dayIndex][$colIndex] = $value; } } } // Compter le nombre de jours pour chaque semaine $weekCounts = array_count_values($weekNumbers); // Déterminer le mois de chaque date $months = []; foreach ($columns as $date) { $months[] = (new DateTime($date))->format("m"); } ?> <form method="post"> <div style="overflow-x: auto;"> <table> <thead> <!-- Ligne des numéros de semaine --> <tr> <th class="sticky-col sticky-col-header">Semaine</th> <?php $currentWeek = null; $colspan = 0; foreach ($weekNumbers as $colIndex => $weekNumber): if ($currentWeek !== $weekNumber) { if ($currentWeek !== null) { echo '<th colspan="' . $colspan . '">' . $currentWeek . '</th>'; } $currentWeek = $weekNumber; $colspan = 0; } $colspan++; endforeach; if ($currentWeek !== null) { echo '<th colspan="' . $colspan . '">' . $currentWeek . '</th>'; } ?> </tr> <!-- Ligne des jours --> <tr> <th class="sticky-col sticky-col-header">Jours</th> <?php foreach ($columns as $colIndex => $date): ?> <th class="<?= ($months[$colIndex] % 2 == 0) ? 'month-even' : 'month-odd' ?>"><?= $date ?></th> <?php endforeach; ?> </tr> <!-- Ligne des noms des jours de la semaine --> <tr> <th class="sticky-col sticky-col-header">xxx</th> <?php foreach ($dayNames as $dayName): ?> <th><?= $dayName ?></th> <?php endforeach; ?> </tr> </thead> <tbody> <?php $daysOfWeek = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi"]; foreach ($daysOfWeek as $dayIndex => $dayName): ?> <tr> <td class="sticky-col"><?= $dayName ?></td> <?php foreach ($columns as $colIndex => $date): ?> <?php if ($dayName === "Lundi"): ?> <td class="<?= ($months[$colIndex] % 2 == 0) ? 'month-even' : 'month-odd' ?> clickable-cell" data-day="<?= $dayIndex ?>" data-col="<?= $colIndex ?>"> <input type="hidden" name="cell[<?= $dayIndex ?>][<?= $colIndex ?>]" value="<?= isset($submittedData[$dayIndex][$colIndex]) ? htmlspecialchars($submittedData[$dayIndex][$colIndex]) : '0' ?>"> <?= isset($submittedData[$dayIndex][$colIndex]) ? htmlspecialchars($submittedData[$dayIndex][$colIndex]) : '0' ?> </td> <?php else: ?> <td class="<?= ($months[$colIndex] % 2 == 0) ? 'month-even' : 'month-odd' ?>"> <input type="text" name="cell[<?= $dayIndex ?>][<?= $colIndex ?>]" value="<?= isset($submittedData[$dayIndex][$colIndex]) ? htmlspecialchars($submittedData[$dayIndex][$colIndex]) : '' ?>"> </td> <?php endif; ?> <?php endforeach; ?> </tr> <?php endforeach; ?> </tbody> </table> </div> <button type="submit">Enregistrer</button> </form> <?php if (!empty($submittedData)): ?> <h2>Valeurs saisies :</h2> <div style="overflow-x: auto;"> <table> <thead> <!-- Ligne des numéros de semaine --> <tr> <th class="sticky-col sticky-col-header">Semaine</th> <?php $currentWeek = null; $colspan = 0; foreach ($weekNumbers as $colIndex => $weekNumber): if ($currentWeek !== $weekNumber) { if ($currentWeek !== null) { echo '<th colspan="' . $colspan . '">' . $currentWeek . '</th>'; } $currentWeek = $weekNumber; $colspan = 0; } $colspan++; endforeach; if ($currentWeek !== null) { echo '<th colspan="' . $colspan . '">' . $currentWeek . '</th>'; } ?> </tr> <!-- Ligne des jours --> <tr> <th class="sticky-col sticky-col-header">Jours</th> <?php foreach ($columns as $colIndex => $date): ?> <th class="<?= ($months[$colIndex] % 2 == 0) ? 'month-even' : 'month-odd' ?>"><?= $date ?></th> <?php endforeach; ?> </tr> <!-- Ligne des noms des jours de la semaine --> <tr> <th class="sticky-col sticky-col-header">xxx</th> <?php foreach ($dayNames as $dayName): ?> <th><?= $dayName ?></th> <?php endforeach; ?> </tr> </thead> <tbody> <?php foreach ($daysOfWeek as $dayIndex => $dayName): ?> <tr> <td class="sticky-col"><?= $dayName ?></td> <?php foreach ($columns as $colIndex => $date): ?> <td class="<?= ($months[$colIndex] % 2 == 0) ? 'month-even' : 'month-odd' ?>"><?= isset($submittedData[$dayIndex][$colIndex]) ? htmlspecialchars($submittedData[$dayIndex][$colIndex]) : '' ?></td> <?php endforeach; ?> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> <script> document.addEventListener('DOMContentLoaded', function() { const cells = document.querySelectorAll('.clickable-cell'); cells.forEach(cell => { cell.addEventListener('click', function() { const currentValue = this.textContent.trim(); if (currentValue === '1') { this.textContent = '0'; this.classList.remove('clicked'); } else { this.textContent = '1'; this.classList.add('clicked'); } // Update the hidden input field const input = this.querySelector('input[type="hidden"]'); if (input) { input.value = this.textContent.trim(); } }); }); }); </script> </body> </html>