pridana API metoda getallgrouped,
implementovane nacitanie dat do Dashboard z backend
This commit is contained in:
29
api.php
29
api.php
@ -2,6 +2,8 @@
|
||||
include_once 'config.php';
|
||||
|
||||
$action = $_REQUEST['action'];
|
||||
$result = null;
|
||||
$error = null;
|
||||
|
||||
switch ($action) {
|
||||
default:
|
||||
@ -9,7 +11,9 @@ switch ($action) {
|
||||
$result = help();
|
||||
break;
|
||||
case 'add':
|
||||
$result = reportAdd($_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
||||
$report_id = reportAdd($_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
||||
if ($report_id === false) $error = 'Report add failed';
|
||||
$result = array('report_id' => $report_id);
|
||||
break;
|
||||
case 'update':
|
||||
$result = reportUpdate($_REQUEST['report_id'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['group'], $_REQUEST['priority']);
|
||||
@ -23,13 +27,26 @@ switch ($action) {
|
||||
case 'getall':
|
||||
$result = reportGetAll($_REQUEST['status']);
|
||||
break;
|
||||
case 'getallgrouped':
|
||||
$result = reportGetAllGrouped($_REQUEST['status']);
|
||||
break;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($result);
|
||||
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '*';
|
||||
header('Access-Control-Allow-Origin: ' . $origin);
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept');
|
||||
echo json_encode(
|
||||
is_null($error)
|
||||
? array('status' => 'OK', 'data' => $result)
|
||||
: array('status' => 'ERROR', 'msg' => $error),
|
||||
);
|
||||
exit;
|
||||
|
||||
function help() {
|
||||
function help()
|
||||
{
|
||||
return [
|
||||
'actions' => [
|
||||
'help' => 'Show this help',
|
||||
@ -37,10 +54,8 @@ function help() {
|
||||
'update' => 'Update report',
|
||||
'delete' => 'Delete report',
|
||||
'get' => 'Get report',
|
||||
'getall' => 'Get all reports'
|
||||
'getall' => 'Get all reports',
|
||||
'getallgrouped' => 'Get all reports grouped by group',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user