<?php require '../../core.php'; $csv = Utils::getValue($_GET['id']); if ($csv) { $q = new RecentQueries(); try { $json = $q->with(["id" => $csv])->fetch(); if ($json instanceof QueryResults) { $json->asArray()[0]["json"]; } else { throw new Exception(); } $params = json_decode($json, true); if (isset($params["page"])) { unset($params["page"]); } if (isset($params["limit"])) { unset($params["limit"]); } $filterQuery = new FilterQuery(); header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename=output.csv"); header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 header("Pragma: no-cache"); // HTTP 1.0 header("Expires: 0"); // Proxies $queryResults = $filterQuery->with($params)->fetch()->asCSV(); } catch (Exception $e) {
header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST'); header("Access-Control-Allow-Headers: X-Requested-With"); if (isset($_POST['params'])) { try { $params = json_decode($_POST['params'], true); if (is_null($params)) { error("Invalid JSON input"); return; } $lastId = null; /* store as recent query */ if (Utils::getValue($params["query"], false) === true) { $recentQueries = new RecentQueries(); $lastId = $recentQueries->with(["json" => $_POST['params']])->store(); } $filterQuery = new FilterQuery(); $queryResults = $filterQuery->with($params)->fetch(); echo json_encode(["id" => $lastId, "results" => $queryResults->asArray()], JSON_PRETTY_PRINT); } catch (PDOException $e) { error("Failure in database connection."); } } else { if (isset($_GET['csv'])) { $csvPath = SettingsStorage::settings()["csv_file_locations"]; $filename = Utils::sanitizeFilename($_GET['csv']); FileStorage::downloadFile($filename, $csvPath); } else { error("No params provided"); }