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'); } // --- Optionnel: récupérer nom praticien pour titre $st = $pdo->prepare("SELECT nom, prenom FROM praticien WHERE id = ? LIMIT 1"); $st->execute([$praticien_id]); $prat = $st->fetch(PDO::FETCH_ASSOC); $currentPraticienName = trim(($prat['prenom'] ?? '').' '.($prat['nom'] ?? '')); $erreur = null; // ---- Ajouter une plage datée (POST) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['date_dispo'], $_POST['heure_debut'], $_POST['heure_fin'])) { $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)."; } } } // ---- Supprimer une plage datée (GET) if (isset($_GET['supprimer'])) { $id = (int)$_GET['supprimer']; // Vérifier appartenance $own = $pdo->prepare("SELECT 1 FROM disponibilite_date WHERE id = :id AND praticien_id = :p LIMIT 1"); $own->execute(['id'=>$id,'p'=>$praticien_id]); if ($own->fetchColumn()) { $stmt = $pdo->prepare("DELETE FROM disponibilite_date WHERE id = :id AND praticien_id = :p"); $stmt->execute(['id'=>$id,'p'=>$praticien_id]); header('Location: /public/cabinet/disponibilites_date.php?praticien_id='.$praticien_id.'&ok=deleted', true, 303); exit; } else { http_response_code(403); exit('Forbidden'); } } // ---- 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); // Header cabinet $PAGE_TITRE = $translations['titre_disponibilites_date'] ?? 'Disponibilités (dates)'; $HEAD_EXTRA = << HTML; require_once __DIR__ . '/../includes/header_cabinet.php'; ?>

-