1<?php
2require_once INCLUDE_DIR . 'class.export.php';
3
4class ExportAjaxAPI extends AjaxController {
5
6    function check($id) {
7        global $thisstaff;
8
9        if (!$thisstaff)
10            Http::response(403, 'Agent login is required');
11        elseif (!($exporter=Exporter::load($id)) || !$exporter->isAvailable())
12            Http::response(404, 'No such export');
13
14        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
15            if ($exporter->isReady())
16                Http::response(201, $this->json_encode([
17                            'status' => 'ready',
18                            'href' => sprintf('export.php?id=%s',
19                                $exporter->getId()),
20                            'filename' => $exporter->getFilename()]));
21            else // Export is not ready... checkback in a few
22                Http::response(200, $this->json_encode([
23                        'status' => 'notready']));
24        }
25
26        include STAFFINC_DIR . 'templates/export.tmpl.php';
27    }
28}
29