<?php
/**
 * ICS Calendar Feed
 * Outputs iCalendar format for subscription/download
 */

require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/lib/ics.php';

// Get parameters
$categoryId = isset($_GET['category_id']) ? (int)$_GET['category_id'] : null;
$download = isset($_GET['download']) && $_GET['download'] == '1';
$start = $_GET['start'] ?? null;
$end = $_GET['end'] ?? null;

// Generate ICS
$generator = new ICSGenerator();
$icsContent = $generator->generate($start, $end, $categoryId);

// Set headers
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: ' . ($download ? 'attachment' : 'inline') . '; filename="rok-calendar.ics"');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Content-Length: ' . strlen($icsContent));

echo $icsContent;

