open($tmp_file, ZipArchive::CREATE | ZipArchive::OVERWRITE); foreach ($summaries as $s) { $list = get_list($cur_user['username'], $s['id']); if (!$list) continue; $slug = $list['slug'] ?? slugify($list['title']); $zip->addFromString($slug . '.csv', generate_csv($list)); $zip->addFromString($slug . '.md', generate_markdown($list)); } $zip->close(); $filename = 'taskgram-' . $cur_user['username'] . '-' . date('Ymd') . '.zip'; header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Length: ' . filesize($tmp_file)); header('Cache-Control: no-cache'); readfile($tmp_file); unlink($tmp_file); exit; } /* ───────────────────────────────────────────────────────────────── Single-list exports (CSV / MD) — guests allowed for viewable lists ───────────────────────────────────────────────────────────────── */ if (!$list_id || !$owner) { flash('error', 'No list specified.'); redirect($cur_user ? 'dashboard.php' : 'index.php'); } $slug = trim($_GET['slug'] ?? ''); $list = ($slug !== '') ? get_list_by_slug($owner, $slug) : get_list($owner, $list_id); // Grant session access via share token if provided if ($list && !empty($_GET['token']) && check_share_token($list, $_GET['token'])) { grant_list_access($list['id']); } if (!$list || !can_view_list($list, $cur_user)) { flash('error', 'List not found or access denied.'); redirect($cur_user ? 'dashboard.php' : 'index.php'); } $base = $list['slug'] ?? slugify($list['title']); $filename = $base . '-' . date('Ymd'); if ($format === 'csv') { header('Content-Type: text/csv; charset=UTF-8'); header('Content-Disposition: attachment; filename="' . $filename . '.csv"'); header('Cache-Control: no-cache'); echo generate_csv($list); exit; } if ($format === 'md') { header('Content-Type: text/plain; charset=UTF-8'); header('Content-Disposition: attachment; filename="' . $filename . '.md"'); header('Cache-Control: no-cache'); echo generate_markdown($list); exit; } flash('error', 'Unknown export format.'); redirect($cur_user ? 'dashboard.php' : 'index.php');