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; } $erreur = null; $toMin = function (string $hhmm): ?int { 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; }; // ---- Ajouter une dispo ponctuelle (POST + CSRF) if ( $_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'add' && isset($_POST['date_dispo'], $_POST['heure_debut'], $_POST['heure_fin']) ) { require_post_csrf(); $date_dispo = trim((string) $_POST['date_dispo']); // YYYY-MM-DD $debut = trim((string) $_POST['heure_debut']); // HH:MM $fin = trim((string) $_POST['heure_fin']); // HH:MM $dt = DateTimeImmutable::createFromFormat('Y-m-d', $date_dispo); if (! $dt || $dt->format('Y-m-d') !== $date_dispo) { $erreur = $translations['erreur_format_date'] ?? "Format de date invalide."; } else { $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; 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_date (praticien_id, date_dispo, heure_debut, heure_fin) VALUES (?, ?, ?, ?) "); $stmt->execute([$praticien_id, $date_dispo, $debut, $fin]); header('Location: /public/praticien/disponibilites_date.php?ok=added', true, 303); exit; } } } } // ---- Récupérer les plages datées $stmt = $pdo->prepare(" SELECT id, date_dispo, heure_debut, heure_fin FROM disponibilite_date WHERE praticien_id = ? ORDER BY date_dispo ASC, heure_debut ASC "); $stmt->execute([$praticien_id]); $dates = $stmt->fetchAll(PDO::FETCH_ASSOC); $PAGE_TITLE = $translations['titre_disponibilites_date'] ?? 'Disponibilités (dates)'; $HEAD_EXTRA = << HTML; require_once __DIR__ . '/../includes/header.php'; ?>