prepare("SELECT duree_rdv FROM praticien WHERE id = ?"); $stmt->execute([$praticien_id]); $duree_minutes = (int) ($stmt->fetchColumn() ?: 0); if ($duree_minutes <= 0) { $duree_minutes = 30; } // fallback sécurité // ---- Ajouter un créneau (POST) ---- $erreur = null; $toMin = function (string $hhmm): ?int { // input type="time" renvoie souvent HH:MM if (! preg_match('/^\d{2}:\d{2}$/', $hhmm)) { return null; } [$h, $m] = array_map('intval', explode(':', $hhmm)); if ($h < 0 || $h > 23 || $m < 0 || $m > 59) { return null; } return $h * 60 + $m; }; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['jour'], $_POST['heure_debut'], $_POST['heure_fin'])) { $jour = trim((string) $_POST['jour']); $debut = trim((string) $_POST['heure_debut']); $fin = trim((string) $_POST['heure_fin']); $md = $toMin($debut); $mf = $toMin($fin); if ($md === null || $mf === null) { $erreur = $translations['erreur_format_heure'] ?? "Format d'heure invalide."; } elseif ($md >= $mf) { $erreur = $translations['erreur_debut_avant_fin'] ?? "Heure de début après l’heure de fin."; } else { $window = $mf - $md; // minutes if ($window < $duree_minutes) { $erreur = sprintf( $translations['erreur_plage_trop_courte'] ?? "Créneau trop court (%d min). Minimum : %d min.", $window, $duree_minutes ); } elseif (($window % $duree_minutes) !== 0) { $erreur = sprintf( $translations['erreur_plage_incompatible_duree'] ?? "Créneau incompatible. La durée doit être un multiple de %d min.", $duree_minutes ); } else { $stmt = $pdo->prepare( "INSERT INTO disponibilite (praticien_id, jour_semaine, heure_debut, heure_fin) VALUES (?, ?, ?, ?)" ); $stmt->execute([$praticien_id, $jour, $debut, $fin]); header('Location: /public/praticien/disponibilites.php?ok=added', true, 303); exit; } } } // ---- Supprimer un créneau (GET) ---- // (idéalement: POST + CSRF, on garde GET pour aller vite) if (isset($_GET['supprimer'])) { $id = (int) $_GET['supprimer']; $stmt = $pdo->prepare("DELETE FROM disponibilite WHERE id = ? AND praticien_id = ?"); $stmt->execute([$id, $praticien_id]); header('Location: /public/praticien/disponibilites.php?ok=deleted', true, 303); exit; } // ---- Récupérer les créneaux ---- $stmt = $pdo->prepare( "SELECT * FROM disponibilite WHERE praticien_id = ? ORDER BY FIELD(jour_semaine,'lundi','mardi','mercredi','jeudi','vendredi','samedi','dimanche'), heure_debut" ); $stmt->execute([$praticien_id]); $dispos = $stmt->fetchAll(PDO::FETCH_ASSOC); // Prépare les traductions de jours $jourKeyMap = [ 'lundi' => 'jour_lundi', 'mardi' => 'jour_mardi', 'mercredi' => 'jour_mercredi', 'jeudi' => 'jour_jeudi', 'vendredi' => 'jour_vendredi', 'samedi' => 'jour_samedi', 'dimanche' => 'jour_dimanche', ]; // 1️⃣ Titre de la page $PAGE_TITLE = $translations['titre_disponibilites'] ?? 'Disponibilités'; // 2️⃣ Ce qui doit aller dans
EN PLUS du header global $HEAD_EXTRA = << HTML; require_once __DIR__ . '/../includes/header.php'; ?>