diff --git a/api.php b/api.php
deleted file mode 100644
index b0d2e90..0000000
--- a/api.php
+++ /dev/null
@@ -1,201 +0,0 @@
- $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(json_decode($_REQUEST['status'], true), $_REQUEST['page'] == 'null' ? null : $_REQUEST['page']);
- break;
- case 'getArchived':
- $result = reportGetArchived($_REQUEST['page'] == 'null' ? null : $_REQUEST['page']);
- 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;
- case 'attachmentAdd':
- $suc = attachmentAdd($_REQUEST['report_id'], $_REQUEST['attachment_type'], $_REQUEST['attachment_content']);
- if ($suc === false) $error = 'Attachment add failed';
- $result = array('processed' => $suc);
- break;
- case 'attachmentUpdate':
- $suc = attachmentUpdate($_REQUEST['attachment_id'], $_REQUEST['attachment_content']);
- if ($suc === false) $error = 'Attachment update failed';
- $result = array('processed' => $suc);
- break;
- case 'attachmentGetAll':
- $result = attachmentGetAll($_REQUEST['report_id']);
- break;
- case 'attachmentDelete':
- $suc = attachmentDelete($_REQUEST['attachment_id']);
- if ($suc === false) $error = 'Attachment delete 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',
- 'page' => '(ptional) Page number, default: null = vsetky',
- ]
- ],
- 'getArchived' => [
- 'name' => 'getArchived',
- 'description' => 'Get archived reports',
- 'params' => [
- 'page' => '(ptional) Page number, default: null = vsetky',
- ]
- ],
- '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',
- ]
- ],
- 'attachmentAdd' => [
- 'name' => 'attachmentAdd',
- 'description' => 'Add attachment to report',
- 'params' => [
- 'report_id' => 'Report id',
- 'content_type' => 'Attachment content type',
- 'content' => 'Attachment content',
- ]
- ],
- 'attachmentUpdate' => [
- 'name' => 'attachmentUpdate',
- 'description' => 'Update attachment',
- 'params' => [
- 'attachment_id' => 'Attachment id',
- 'content' => 'Attachment content; if empty, attachment will be deleted',
- ]
- ],
- 'attachmentGetAll' => [
- 'name' => 'attachmentGetAll',
- 'description' => 'Get all attachments for report',
- 'params' => [
- 'report_id' => 'Report id',
- ]
- ],
- 'attachmentGet' => [
- 'name' => 'attachmentGet',
- 'description' => 'Get attachment',
- 'params' => [
- 'attachment_id' => 'Attachment id',
- ]
- ]
- ]
- ];
-}
diff --git a/config.php b/config.php
deleted file mode 100644
index 4768e73..0000000
--- a/config.php
+++ /dev/null
@@ -1,31 +0,0 @@
- 'sqlite',
- 'database' => __DIR__ . '/data/database.db'
-]);
-dbCheck();
-
-
-?>
\ No newline at end of file
diff --git a/index.php b/index.php
deleted file mode 100644
index ad9c2b4..0000000
--- a/index.php
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
- BugReport
-
-
-
-
-
\ No newline at end of file
diff --git a/lib/functions.inc.php b/lib/functions.inc.php
deleted file mode 100644
index f0bec4b..0000000
--- a/lib/functions.inc.php
+++ /dev/null
@@ -1,344 +0,0 @@
- 0
- && !in_array($extension, $allowedExtensions)
- ) {
- $extension = 'bin'; // fallback ak prípona nie je povolená
- }
- return $name . '.' . $extension;
-}
-
-/**
- * Check database
- */
-function dbCheck()
-{
- global $db;
- $db_version = option('version');
- if ($db_version === null) {
- $db->create('options', [
- 'key' => [
- 'VARCHAR(64)',
- 'NOT NULL',
- 'UNIQUE'
- ],
- 'value' => [
- 'TEXT',
- 'NOT NULL'
- ],
- 'created_at' => [
- 'DATETIME',
- 'DEFAULT CURRENT_TIMESTAMP'
- ]
- ]);
- option('version', '0');
- $db_version = '0';
- }
- if ($db_version === '0') {
- $db->create('reports', [
- 'report_id' => [
- 'INTEGER',
- 'PRIMARY KEY',
- 'AUTOINCREMENT'
- ],
- 'report_title' => [
- 'VARCHAR(255)',
- 'DEFAULT NULL'
- ],
- 'report_description' => [
- 'TEXT',
- 'DEFAULT NULL'
- ],
- 'report_status' => [
- 'INTEGER',
- 'DEFAULT 0'
- ],
- 'report_group' => [
- 'VARCHAR(255)',
- 'DEFAULT NULL'
- ],
- 'report_priority' => [
- 'INTEGER',
- 'DEFAULT 0'
- ],
- 'created_dt' => [
- 'DATETIME',
- 'DEFAULT NULL'
- ],
- ]);
- option('version', '1');
- $db_version = '1';
- }
- if ($db_version === '1') {
- $db->create('attachments', [
- 'attachment_id' => [
- 'INTEGER',
- 'PRIMARY KEY',
- 'AUTOINCREMENT'
- ],
- 'report_id' => [
- 'INTEGER',
- 'NOT NULL'
- ],
- 'attachment_type' => [
- 'VARCHAR(255)',
- 'DEFAULT NULL'
- ],
- 'attachment_content' => [
- 'TEXT',
- 'DEFAULT NULL'
- ],
- 'created_dt' => [
- 'DATETIME',
- 'DEFAULT NULL'
- ],
- 'updated_dt' => [
- 'DATETIME',
- 'DEFAULT NULL'
- ],
- ]);
- option('version', '2');
- $db_version = '2';
- }
- if ($db_version === '2') {
- $db->query("ALTER TABLE reports ADD COLUMN ordnum INTEGER DEFAULT 0");
- option('version', '3');
- $db_version = '3';
- }
-}
-
-function option($key, $value = null)
-{
- global $db;
- if (tableExits('options') === null) {
- return null;
- }
- if ($value === null) {
- return $db->get('options', 'value', [
- 'key' => $key
- ]);
- }
- $exits = $db->get('options', 'value', [
- 'key' => $key
- ]);
- if ($exits !== null) {
- return $db->update('options', [
- 'value' => $value
- ], [
- 'key' => $key
- ]);
- }
- return $db->insert('options', [
- 'key' => $key,
- 'value' => $value
- ]);
-}
-
-function tableExits($table)
-{
- global $db;
- return $db->get('sqlite_master', 'name', [
- 'type' => 'table',
- 'name' => $table
- ]);
-}
-
-/**
- * Reports
- */
-function reportAdd($title, $description, $status = 0, $group = null, $priority = 0)
-{
- global $db;
- $status = intval($status);
- $priority = intval($priority);
- $db->insert('reports', [
- 'report_title' => $title,
- 'report_description' => $description,
- 'report_status' => $status,
- 'report_group' => $group,
- 'report_priority' => $priority,
- 'created_dt' => date('Y-m-d H:i:s')
- ]);
- return $db->id();
-}
-
-function reportUpdate($report_id, $report_data)
-{
- global $db;
- $stm = $db->update('reports', $report_data, [
- 'report_id' => $report_id
- ]);
- return ($stm->rowCount() > 0);
-}
-
-function reportUpdateStatus($report_id, $status)
-{
- global $db;
- $stm = $db->update('reports', [
- 'report_status' => $status
- ], [
- 'report_id' => $report_id
- ]);
- return ($stm->rowCount() > 0);
-}
-
-function reportUpdateOrdnum($ordnums)
-{
- global $db;
- $ordnums = json_decode($ordnums, true);
- $suc = true;
- foreach ($ordnums as $report_id => $ordnum) {
- $stm = $db->update('reports', [
- 'ordnum' => $ordnum
- ], [
- 'report_id' => $report_id
- ]);
- $suc &= ($stm->rowCount() > 0);
- }
- return $suc;
-}
-
-function reportDelete($report_id)
-{
- global $db;
- $stm = $db->delete('reports', [
- 'report_id' => $report_id
- ]);
- return ($stm->rowCount() > 0);
-}
-
-function reportGet($report_id)
-{
- global $db;
- return $db->get('reports', '*', [
- 'report_id' => $report_id
- ]);
-}
-
-function reportGetAll($status = null, $page = null)
-{
- global $db;
- if ($status === null) $status = array(0, 1, 2, 3);
- $params = [
- 'ORDER' => ['report_priority' => 'DESC', 'ordnum' => 'ASC'],
- 'report_status' => $status
- ];
- if ($page !== null) $params['LIMIT'] = [$page * 10, 10];
- return $db->select('reports', '*', $params);
-}
-
-function reportGetAllGrouped($status = null, $page = null)
-{
- $all = reportGetAll($status, $page);
- $groups = [];
- foreach ($all as $report) {
- $groups[$report['report_status']][] = $report;
- }
- return $groups;
-}
-
-function reportGetArchived($page = null)
-{
- global $db;
- $params = [
- 'ORDER' => ['created_dt' => 'DESC'],
- 'report_status' => '4'
- ];
- if ($page !== null) $params['LIMIT'] = [$page * 10, 10];
- return $db->select('reports', '*', $params);
-}
-
-/**
- * Attachments
- */
-function attachmentGet($attachment_id)
-{
- global $db;
- return $db->get('attachments', '*', [
- 'attachment_id' => $attachment_id
- ]);
-}
-function attachmentAdd($report_id, $attachment_type, $attachment_content)
-{
- global $db;
- if ($attachment_type == 'file') {
- $data = json_decode($attachment_content, true);
- if (!is_array($data)) return false;
- $base64 = preg_replace('/^data:.*?;base64,/', '', $data['base64']);
- $base64_data = base64_decode($base64);
- $filename = 'report_' . $report_id . '_' . time() . '_' . sanitizeFilename($data['filename']);
- file_put_contents(UPLOAD_DIR_ATTACHMENTS . $filename, $base64_data);
- $attachment_content = $filename;
- }
-
- $stm = $db->insert('attachments', [
- 'report_id' => $report_id,
- 'attachment_type' => $attachment_type,
- 'attachment_content' => $attachment_content,
- 'created_dt' => date('Y-m-d H:i:s')
- ]);
- return ($stm->rowCount() > 0);
-}
-
-function attachmentUpdate($attachment_id, $attachment_content)
-{
- global $db;
- if (strlen(trim($attachment_content)) <= 0) return attachmentDelete($attachment_id);
- $stm = $db->update('attachments', [
- 'attachment_content' => $attachment_content,
- 'updated_dt' => date('Y-m-d H:i:s')
- ], [
- 'attachment_id' => $attachment_id
- ]);
- return ($stm->rowCount() > 0);
-}
-
-function attachmentDelete($attachment_id)
-{
- global $db;
- $attachment = attachmentGet($attachment_id);
- if ($attachment['attachment_type'] == 'file'
- && file_exists(UPLOAD_DIR_ATTACHMENTS . $attachment['attachment_content']))
- {
- unlink(UPLOAD_DIR_ATTACHMENTS . $attachment['attachment_content']);
- }
- $stm = $db->delete('attachments', [
- 'attachment_id' => $attachment_id
- ]);
- return ($stm->rowCount() > 0);
-}
-
-function attachmentGetAll($report_id)
-{
- global $db;
- $all = $db->select('attachments', '*', [
- 'ORDER' => ['created_dt' => 'ASC'],
- 'report_id' => $report_id
- ]);
- if (is_array($all)) foreach ($all as $key => $row) {
- if ($all[$key]['attachment_type'] == 'file') {
- $all[$key]['attachment_content'] = UPLOAD_URL_ATTACHMENTS . $all[$key]['attachment_content'];
- }
- }
- return $all;
-}