| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /polana/ |
Upload File : |
<?php
declare(strict_types=1);
// Read-only private-link ICS subscription. No guest names, phones, email or notes.
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/reservation_integrations.php';
header('Cache-Control: private, no-store, max-age=0');
header('X-Robots-Tag: noindex, nofollow, noarchive');
header('Referrer-Policy: no-referrer');
header('X-Content-Type-Options: nosniff');
$given = (string)($_GET['token'] ?? '');
$expected = polana_calendar_feed_token();
if (!preg_match('/^[a-f0-9]{64}$/D', $given) || strlen($expected) !== 64
|| !hash_equals($expected, $given)) {
http_response_code(404);
exit('Nie znaleziono kalendarza.');
}
ensure_reservations_schema();
$timezone = new DateTimeZone('Europe/Warsaw');
$start = new DateTimeImmutable('today', $timezone);
$from = $start->modify('-30 days')->format('Y-m-d');
$to = $start->modify('+370 days')->format('Y-m-d');
$stmt = db()->prepare(
"SELECT id, reservation_code, reservation_date, reservation_time, guests, status, updated_at
FROM reservations WHERE reservation_date BETWEEN ? AND ?
AND status IN ('new', 'confirmed')
ORDER BY reservation_date, reservation_time, id"
);
$stmt->execute([$from, $to]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename="mojapolana-rezerwacje.ics"');
if (session_status() === PHP_SESSION_ACTIVE) session_write_close();
$ical = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//TKLM//Moja Polana Smakow Rezerwacje//PL\r\nCALSCALE:GREGORIAN\r\nMETHOD:PUBLISH\r\nX-WR-CALNAME:Moja Polana - rezerwacje\r\nX-WR-TIMEZONE:Europe/Warsaw\r\n";
$now = gmdate('Ymd\THis\Z');
foreach ($rows as $r) {
$dateTime = DateTimeImmutable::createFromFormat('!Y-m-d H:i:s',
(string)$r['reservation_date'] . ' ' . substr((string)$r['reservation_time'], 0, 8), $timezone);
if (!$dateTime) continue;
$startUtc = $dateTime->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z');
$endUtc = $dateTime->modify('+2 hours')->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z');
$status = $r['status'] === 'confirmed' ? 'Potwierdzona' : 'Nowa - do potwierdzenia';
$guests = max(0, (int)$r['guests']);
$ical .= "BEGIN:VEVENT\r\n";
$ical .= polana_ics_fold('UID:polana-res-' . (int)$r['id'] . '@polanasmakow.pl');
$ical .= polana_ics_fold('DTSTAMP:' . $now);
$ical .= polana_ics_fold('DTSTART:' . $startUtc);
$ical .= polana_ics_fold('DTEND:' . $endUtc);
$ical .= polana_ics_fold('SUMMARY:' . polana_ics_escape('Rezerwacja – ' . $guests . ' os.'));
$ical .= polana_ics_fold('DESCRIPTION:' . polana_ics_escape($status . ' · ' . (string)$r['reservation_code']));
$ical .= polana_ics_fold('STATUS:' . ($r['status'] === 'confirmed' ? 'CONFIRMED' : 'TENTATIVE'));
$ical .= "END:VEVENT\r\n";
}
$ical .= "END:VCALENDAR\r\n";
echo $ical;