. */ namespace Liuch\DmarcSrg; use Liuch\DmarcSrg\ErrorHandler; use Liuch\DmarcSrg\Report\ReportList; use Liuch\DmarcSrg\Exception\RuntimeException; require 'init.php'; if (Core::method() == 'GET') { if (Core::isJson() && isset($_GET['list'])) { try { Core::instance()->auth()->isAllowed(); $lst = explode(',', $_GET['list']); $res = []; if (array_search('reports', $lst) !== false) { $pos = isset($_GET['position']) ? intval($_GET['position']) : 0; $dir = isset($_GET['direction']) ? $_GET['direction'] : 'ascent'; $order = isset($_GET['order']) ? $_GET['order'] : 'begin_time'; $filter = null; if (isset($_GET['filter'])) { $filter = []; $pa = gettype($_GET['filter']) == 'array' ? $_GET['filter'] : [ $_GET['filter'] ]; foreach ($pa as $it) { $ia = explode(':', $it, 2); if (count($ia) == 2) { $filter[$ia[0]] = $ia[1]; } } } $list = new ReportList(); if ($filter) { $list->setFilter($filter); } $n_dir = $dir === 'ascent' ? ReportList::ORDER_ASCENT : ReportList::ORDER_DESCENT; $n_order = $order === 'begin_time' ? ReportList::ORDER_BEGIN_TIME : ReportList::ORDER_NONE; $list->setOrder($n_order, $n_dir); $res = $list->getList($pos); } if (array_search('filters', $lst) !== false) { $res['filters'] = (new ReportList())->getFilterList(); } Core::sendJson($res); } catch (RuntimeException $e) { Core::sendJson(ErrorHandler::exceptionResult($e)); } return; } Core::sendHtml(); return; } Core::sendBad();