prepare(" SELECT rv.*, c.prenom, c.nom FROM rendez_vous rv JOIN client c ON rv.client_id = c.id WHERE rv.praticien_id = ? AND rv.statut IN ('confirmé', 'prévu') ORDER BY rv.date_rdv "); $stmt->execute([$praticien_id]); $rdvs = $stmt->fetchAll(); header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: inline; filename="agenda.ics"'); echo "BEGIN:VCALENDAR "; echo "VERSION:2.0 "; echo "CALSCALE:GREGORIAN "; echo "METHOD:PUBLISH "; echo "X-WR-CALNAME:Agenda Praticien "; echo "X-WR-TIMEZONE:Europe/Paris "; foreach ($rdvs as $r) { // Génération et stockage d’un UUID stable pour éviter les doublons if (empty($r['uuid_ical'])) { $uuid = bin2hex(random_bytes(16)); $update = $pdo->prepare("UPDATE rendez_vous SET uuid_ical = ? WHERE id = ?"); $update->execute([$uuid, $r['id']]); } else { $uuid = $r['uuid_ical']; } $start = new DateTime($r['date_rdv'], new DateTimeZone('Europe/Paris')); $end = clone $start; $end->modify("+" . intval($r['duree_minutes'] ?? 60) . " minutes"); $summary = "RDV avec {$r['prenom']} {$r['nom']}"; echo "BEGIN:VEVENT "; echo "UID:$uuid "; echo "DTSTAMP:" . gmdate('Ymd\THis\Z') . " "; echo "DTSTART;TZID=Europe/Paris:" . $start->format('Ymd\THis') . " "; echo "DTEND;TZID=Europe/Paris:" . $end->format('Ymd\THis') . " "; echo "SUMMARY:$summary "; echo "STATUS:CONFIRMED "; echo "END:VEVENT "; } echo "END:VCALENDAR "; exit; ?>