prepare(" SELECT can_edit_slots FROM secretaire_praticien WHERE secretaire_user_id = :u AND praticien_id = :p AND is_active = 1 LIMIT 1 "); $st->execute([ 'u' => $compteId, 'p' => $praticien_id, ]); $pivot = $st->fetch(PDO::FETCH_ASSOC); if (! $pivot || (int) $pivot['can_edit_slots'] !== 1) { http_response_code(403); exit('Forbidden'); } // --- Nom praticien $st = $pdo->prepare("SELECT nom, prenom FROM praticien WHERE id = ? LIMIT 1"); $st->execute([$praticien_id]); $prat = $st->fetch(PDO::FETCH_ASSOC); if (! $prat) { http_response_code(404); exit('Praticien introuvable'); } $currentPraticienName = trim(((string) ($prat['prenom'] ?? '')) . ' ' . ((string) ($prat['nom'] ?? ''))); $erreur = null; // ---- Ajouter une plage datée (POST + CSRF) if ( $_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'add' && isset($_POST['date_dispo'], $_POST['heure_debut'], $_POST['heure_fin']) ) { require_post_csrf(); $date = trim((string) $_POST['date_dispo']); // YYYY-MM-DD $debut = trim((string) $_POST['heure_debut']); // HH:MM $fin = trim((string) $_POST['heure_fin']); // HH:MM $tz = new DateTimeZone('Europe/Paris'); $today = (new DateTimeImmutable('now', $tz))->format('Y-m-d'); if (! preg_match('#^\d{4}-\d{2}-\d{2}$#', $date)) { $erreur = $translations['erreur_format_date'] ?? "Format de date invalide."; } elseif (! preg_match('#^\d{2}:\d{2}$#', $debut) || ! preg_match('#^\d{2}:\d{2}$#', $fin)) { $erreur = $translations['erreur_format_heure'] ?? "Format d’heure invalide."; } elseif ($date < $today) { $erreur = $translations['erreur_date_passee'] ?? "Date dans le passé."; } elseif ($debut >= $fin) { $erreur = $translations['erreur_debut_avant_fin'] ?? "Heure de début après l’heure de fin."; } if (! $erreur) { try { $stmt = $pdo->prepare(" INSERT INTO disponibilite_date (praticien_id, date_dispo, heure_debut, heure_fin) VALUES (:p, :d, :hd, :hf) "); $stmt->execute([ 'p' => $praticien_id, 'd' => $date, 'hd' => $debut . ':00', 'hf' => $fin . ':00', ]); header('Location: /public/cabinet/disponibilites_date.php?praticien_id=' . $praticien_id . '&ok=added', true, 303); exit; } catch (PDOException $e) { $erreur = $translations['erreur_enregistrement'] ?? "Impossible d’enregistrer (doublon ou erreur)."; } } } // ---- Liste $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_cabinet.php'; ?>