Files
2026-03-05 10:25:39 +01:00

75 lines
1.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../includes/bootstrap_global.php';
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
http_response_code(400);
exit('ID praticien invalide.');
}
$praticien_id = intval($_GET['id']);
$stmt = $pdo->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;
?>