Esempio n. 1
0
include '../../core.php';
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");
Esempio n. 2
0
<?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) {
Esempio n. 3
0
                     } else {
                         if ($apiParam === "habitat_counts") {
                             $counts = new HabitatCountsQuery();
                             echo $counts->fetch()->asJSON();
                         } else {
                             if ($apiParam === "species_sites") {
                                 $counts = new ChartStatsQuery();
                                 echo $counts->fetch()->asJSON();
                             } else {
                                 if ($apiParam === "stats") {
                                     $db = DatabaseConnector::getPurePDO();
                                     $res = $db->query("SELECT (SELECT COUNT(*) FROM `classified`) AS classificationsCount, \n            (SELECT COUNT(DISTINCT species) FROM `classified`) AS speciesCount, \n            (SELECT COUNT(DISTINCT photo.site_id) FROM `classified` LEFT JOIN photo ON photo.photo_id = classified.photo_id) AS siteCount,\n            (SELECT COUNT(DISTINCT site.habitat_id) FROM `classified`LEFT JOIN photo ON photo.photo_id = classified.photo_id LEFT JOIN site ON photo.site_id = site.site_id) AS habitatCount")->fetch();
                                     print json_encode($res);
                                 } else {
                                     if ($apiParam === "queries") {
                                         $recentQueries = new RecentQueries();
                                         echo $recentQueries->fetch()->asJSON();
                                     } else {
                                         error("Invalid action");
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 } catch (PDOException $e) {
     error("Failure in database connection.");
 }