pridany page pre Report, zobrazenie info o reporte s dynamickou editaciou nadpisu a popisu
142 lines
3.6 KiB
PHP
142 lines
3.6 KiB
PHP
<?php
|
|
include_once 'config.php';
|
|
|
|
$action = $_REQUEST['action'];
|
|
$result = null;
|
|
$error = null;
|
|
|
|
switch ($action) {
|
|
default:
|
|
case 'help':
|
|
$result = help();
|
|
break;
|
|
case 'add':
|
|
$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':
|
|
$suc = reportUpdate($_REQUEST['report_id'], json_decode($_REQUEST['report_data'], true));
|
|
if ($suc === false) $error = 'Update failed';
|
|
$result = array('processed' => $suc);
|
|
break;
|
|
case 'delete':
|
|
$suc = reportDelete($_REQUEST['report_id']);
|
|
if ($suc === false) $error = 'Update failed';
|
|
$result = array('processed' => $suc);
|
|
break;
|
|
case 'get':
|
|
$result = reportGet($_REQUEST['report_id']);
|
|
break;
|
|
case 'getall':
|
|
$result = reportGetAll($_REQUEST['status']);
|
|
break;
|
|
case 'getallgrouped':
|
|
$result = reportGetAllGrouped($_REQUEST['status']);
|
|
break;
|
|
case 'updateordnum':
|
|
$suc = reportUpdateOrdnum($_REQUEST['ordnums']);
|
|
if ($suc === false) $error = 'Update Ordnum failed';
|
|
$result = array('processed' => $suc);
|
|
break;
|
|
case 'updatestatus':
|
|
$suc = reportUpdateStatus($_REQUEST['report_id'], $_REQUEST['status']);
|
|
if ($suc === false) $error = 'Update Status failed';
|
|
$result = array('processed' => $suc);
|
|
break;
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
$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()
|
|
{
|
|
return [
|
|
'actions' => [
|
|
'help' => [
|
|
'name' => 'help',
|
|
'description' => 'Show this help',
|
|
'params' => []
|
|
],
|
|
'add' => [
|
|
'name' => 'add',
|
|
'description' => 'Add report',
|
|
'params' => [
|
|
'title' => 'Report title',
|
|
'description' => 'Report description',
|
|
'status' => 'Report status',
|
|
'group' => 'Report group',
|
|
'priority' => 'Report priority',
|
|
]
|
|
],
|
|
'update' => [
|
|
'name' => 'update',
|
|
'description' => 'Update report',
|
|
'params' => [
|
|
'report_id' => 'Report id',
|
|
'report_data' => [
|
|
'title' => 'Report title',
|
|
'description' => 'Report description',
|
|
'status' => 'Report status',
|
|
'group' => 'Report group',
|
|
'priority' => 'Report priority',
|
|
]
|
|
]
|
|
],
|
|
'delete' => [
|
|
'name' => 'delete',
|
|
'description' => 'Delete report',
|
|
'params' => [
|
|
'report_id' => 'Report id',
|
|
]
|
|
],
|
|
'get' => [
|
|
'name' => 'get',
|
|
'description' => 'Get report',
|
|
'params' => [
|
|
'report_id' => 'Report id',
|
|
]
|
|
],
|
|
'getall' => [
|
|
'name' => 'getall',
|
|
'description' => 'Get all reports',
|
|
'params' => [
|
|
'status' => '(ptional) Report status, default: 0,1,2,3',
|
|
]
|
|
],
|
|
'getallgrouped' => [
|
|
'name' => 'getallgrouped',
|
|
'description' => 'Get all reports grouped by group',
|
|
'params' => [
|
|
'status' => '(ptional) Report status, default: 0,1,2,3',
|
|
]
|
|
],
|
|
'updateordnum' => [
|
|
'name' => 'updateordnum',
|
|
'description' => 'Update report ordnum',
|
|
'params' => [
|
|
'ordnums' => 'Report ordnums in json format {report_id: ordnum, ...}',
|
|
]
|
|
],
|
|
'updatestatus' => [
|
|
'name' => 'updatestatus',
|
|
'description' => 'Update report status',
|
|
'params' => [
|
|
'report_id' => 'Report id',
|
|
'status' => 'Report status',
|
|
]
|
|
],
|
|
]
|
|
];
|
|
}
|