Compare commits
6 Commits
948fce896f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| afc5229f5b | |||
| e50c53e50a | |||
| 3e9056f4a6 | |||
| ed3d202488 | |||
| e67d4843bd | |||
| fbfe46542b |
91
README.md
91
README.md
@ -6,7 +6,7 @@ BugReport je webová aplikácia na sledovanie a správu chýb (bug tracking syst
|
||||
|
||||
<br /><br /><br />
|
||||
|
||||
## Funkcie
|
||||
## 🚀 Funkcie
|
||||
|
||||
- **Kanban rozhranie** - vizuálne sledovanie stavu bug reportov v štyroch kategóriách (Nezaradené, Čakajúce, Rozpracované, Blokované)
|
||||
- **Drag-and-drop** - jednoduché presúvanie reportov medzi kategóriami
|
||||
@ -15,23 +15,23 @@ BugReport je webová aplikácia na sledovanie a správu chýb (bug tracking syst
|
||||
- **Detailný pohľad** - zobrazenie a úprava detailov reportu
|
||||
- **REST API** - prístup k dátam cez API endpoint
|
||||
|
||||
## Diagram stavov pre BUG
|
||||
## 🔷 Diagram stavov pre BUG
|
||||
|
||||
<img src="frontend/src/assets/images/FlowDiagram.drawio.svg" />
|
||||
|
||||
## Screenshot
|
||||
## 🖼️ Screenshot
|
||||
<img src="doc/Screenshot_2025-05-17_111345.png" />
|
||||
|
||||
## Technológie
|
||||
## 🖥️ Technológie
|
||||
|
||||
### Backend
|
||||
### ⚙️ Backend
|
||||
|
||||
- PHP
|
||||
- SQLite databáza
|
||||
- [TPsoft/DBmodel](https://gitea.tpsoft.org/TPsoft.org/DBmodel) - PHP databázové rozšírenie
|
||||
- [TPsoft/APIlite](https://gitea.tpsoft.org/TPsoft.org/APIlite) - Jednoduchý nástroj pre zostavenie API
|
||||
|
||||
### Frontend
|
||||
### 📺 Frontend
|
||||
|
||||
- [Vue.js 3](https://vuejs.org/) - JavaScript framework
|
||||
- [Vue Router](https://router.vuejs.org/) - smerovanie v aplikácii
|
||||
@ -40,46 +40,54 @@ BugReport je webová aplikácia na sledovanie a správu chýb (bug tracking syst
|
||||
- [Mitt](https://github.com/developit/mitt) - knižnica pre správu udalostí
|
||||
- [Vite](https://vitejs.dev/) - build nástroj
|
||||
|
||||
## Štruktúra projektu
|
||||
## 🌳 Štruktúra projektu
|
||||
|
||||
```
|
||||
BugReport/
|
||||
├── backend/ # Backend aplikácia (PHP)
|
||||
│ ├── src/ # Zdrojový kód
|
||||
│ ├── config/ # Konfigurácia aplikácie
|
||||
│ └── public/ # Vstupný bod aplikácie
|
||||
├── data/ # Dáta aplikácie
|
||||
│ ├── attachments/ # Súborové uložisko príloh
|
||||
│ └── database.db # SQLite databáza
|
||||
└── frontend/ # Frontend aplikácia (Vue.js)
|
||||
├── public/ # Statické súbory
|
||||
├── scripts/ # Skripty pre build
|
||||
└── src/ # Zdrojový kód
|
||||
├── assets/ # Assety (CSS, obrázky)
|
||||
├── components/ # Vue komponenty
|
||||
├── views/ # Vue stránky
|
||||
├── App.vue # Hlavná Vue komponenta
|
||||
├── backend.js # Komunikácia s API
|
||||
├── events.js # Správa udalostí
|
||||
├── main.js # Vstupný bod Vue aplikácie
|
||||
└── router.js # Vue Router konfigurácia
|
||||
├── backend/ # Backend aplikácia (PHP)
|
||||
│ ├── config/ # Konfigurácia aplikácie
|
||||
│ ├── public/ # Vstupný bod aplikácie, tu nasmerovat vo webserveri DOCUMENT ROOT
|
||||
│ ├── scripts/ # Skripty pre pred-spracovanie, build a ine
|
||||
│ ├── src/ # Zdrojový kód
|
||||
│ │ ├── Models/ # Classy pre jednotlive DB tabulky pouziva TPsoft\DBmodel
|
||||
│ │ ├── API.php # Logika pre API BugReport pouziva TPsoft\APIlite
|
||||
│ │ ├── Init.php # Inicializacia pripojenia k DB, kontroly a iné
|
||||
│ │ └── Maintenance.php # Údržba pre projekt, zatiaľ hlavne pre upgrade databazovej štruktúry, používa \TPsoft\DBmodel\Maintenance
|
||||
│ └── test/ # Testovacie skripty
|
||||
├── data/ # Dáta aplikácie
|
||||
│ ├── attachments/ # Súborové uložisko príloh
|
||||
│ └── database.db # SQLite databáza
|
||||
├── doc/ # Dokumentácia a iné súbory počas vývoja
|
||||
└── frontend/ # Frontend aplikácia (Vue.js)
|
||||
├── public/ # Statické súbory
|
||||
├── scripts/ # Skripty pre build
|
||||
└── src/ # Zdrojový kód
|
||||
├── assets/ # Assety (CSS, obrázky)
|
||||
├── components/ # Vue komponenty
|
||||
├── views/ # Vue stránky
|
||||
├── App.vue # Hlavná Vue komponenta
|
||||
├── backend.js # Komunikácia s API
|
||||
├── events.js # Správa udalostí
|
||||
├── main.js # Vstupný bod Vue aplikácie
|
||||
└── router.js # Vue Router konfigurácia
|
||||
```
|
||||
|
||||
## Inštalácia a spustenie
|
||||
## 🛠️ Inštalácia a spustenie
|
||||
|
||||
### Požiadavky
|
||||
### 📋 Požiadavky
|
||||
|
||||
- PHP 7.4 alebo novší
|
||||
- PHP 8.2 alebo novší
|
||||
- Webový server (Apache, Nginx)
|
||||
- Node.js a npm pre vývoj frontendu
|
||||
|
||||
### Backend
|
||||
### ⚙️ Backend
|
||||
|
||||
1. Skopírujte súbory do webového adresára
|
||||
2. Uistite sa, že adresár`data` má práva na zápis
|
||||
2. Uistite sa, že adresár `data` má práva na zápis
|
||||
3. Nastavte DOCUMENT ROOT na adresár `backend/public`
|
||||
3. Prístup k aplikácii cez webový prehliadač
|
||||
|
||||
### Frontend (pre vývoj)
|
||||
### 📺 Frontend (pre vývoj)
|
||||
|
||||
1. Prejdite do adresára`frontend`
|
||||
2. Nainštalujte závislosti:
|
||||
@ -95,11 +103,11 @@ BugReport/
|
||||
npm run build
|
||||
```
|
||||
|
||||
## API dokumentácia
|
||||
## 📖 API dokumentácia
|
||||
|
||||
API je dostupné cez `api.php` endpoint. Všetky požiadavky vracajú JSON odpoveď.
|
||||
API je dostupné cez `API.php` endpoint fyzicky umiestnený v DOCUMENT ROOT `backend/public/API.php`. Všetky požiadavky vracajú JSON odpoveď.kompletnú a aktuálnu dokumentáciu je možné získať aj HTML formáte `API.php?format=html`.
|
||||
|
||||
### Dostupné endpointy
|
||||
### 🚏 Dostupné endpointy
|
||||
|
||||
| Akcia | Popis | Parametre |
|
||||
| -------------------- | -------------------------------------- | --------------------------------------------------------------- |
|
||||
@ -116,7 +124,7 @@ API je dostupné cez `api.php` endpoint. Všetky požiadavky vracajú JSON odpov
|
||||
| `attachmentUpdate` | Aktualizuje prílohu | `attachment_id`, `attachment_content` |
|
||||
| `attachmentGetAll` | Získa všetky prílohy reportu | `report_id` |
|
||||
|
||||
### Príklad API volania
|
||||
### 🔍 Príklad API volania
|
||||
|
||||
```javascript
|
||||
// Získanie všetkých reportov
|
||||
@ -133,7 +141,7 @@ fetch('api.php?action=add', {
|
||||
.then(data => console.log(data));
|
||||
```
|
||||
|
||||
## Stavy reportov
|
||||
## 🏗️ Stavy reportov
|
||||
|
||||
| ID | Stav |
|
||||
| -- | ------------- |
|
||||
@ -143,7 +151,7 @@ fetch('api.php?action=add', {
|
||||
| 3 | Blokované |
|
||||
| 4 | Vyriešený |
|
||||
|
||||
## Priority reportov
|
||||
## 📣 Priority reportov
|
||||
|
||||
| ID | Priorita |
|
||||
| -- | --------- |
|
||||
@ -152,13 +160,16 @@ fetch('api.php?action=add', {
|
||||
| 2 | Vysoká |
|
||||
| 3 | Kritická |
|
||||
|
||||
## Skupiny reportov
|
||||
## 🕸️ Skupiny reportov
|
||||
|
||||
- `cp` - Control Panel
|
||||
- `task` - Task.Platon.sk
|
||||
- `websiteip` - WebsiteIP
|
||||
- `antispam` - Antispam
|
||||
|
||||
## Licencia
|
||||
## ✨ Plánované vylepšenia - Planned Features
|
||||
- Skupiny reportov v samostatnej tabuľke s CRUD manažmentom
|
||||
|
||||
## ⚖️ Licencia
|
||||
|
||||
Tento projekt je licencovaný pod [MIT licenciou](https://opensource.org/licenses/MIT).
|
||||
|
||||
201
api.php
201
api.php
@ -1,201 +0,0 @@
|
||||
<?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(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',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
16
backend/composer.lock
generated
16
backend/composer.lock
generated
@ -8,11 +8,11 @@
|
||||
"packages": [
|
||||
{
|
||||
"name": "tpsoft/apilite",
|
||||
"version": "v1.0.2",
|
||||
"version": "v1.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.tpsoft.org/TPsoft.org/APIlite.git",
|
||||
"reference": "2d3f8bfdd46d0d304bac44057ff8444bfb2a4a17"
|
||||
"reference": "c0fd7b3fe5270ee44a84a92e9255ada2438812b7"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.2"
|
||||
@ -49,15 +49,15 @@
|
||||
"type": "other"
|
||||
}
|
||||
],
|
||||
"time": "2025-06-12T05:54:37+00:00"
|
||||
"time": "2025-10-13T21:36:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "tpsoft/dbmodel",
|
||||
"version": "v1.0.4",
|
||||
"version": "v1.0.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.tpsoft.org/TPsoft.org/DBmodel.git",
|
||||
"reference": "ae59ffaa97094854bcd1d863c6648a5b4dada671"
|
||||
"reference": "80e889946bc4e38e987f46a13f95ee177ea934dc"
|
||||
},
|
||||
"require": {
|
||||
"ext-pdo": "*",
|
||||
@ -85,7 +85,9 @@
|
||||
"keywords": [
|
||||
"db",
|
||||
"model",
|
||||
"pdo"
|
||||
"mysql",
|
||||
"pdo",
|
||||
"sqlite"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
@ -93,7 +95,7 @@
|
||||
"type": "other"
|
||||
}
|
||||
],
|
||||
"time": "2025-06-15T17:07:42+00:00"
|
||||
"time": "2025-10-13T21:26:19+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
|
||||
@ -4,7 +4,7 @@ require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
ob_start();
|
||||
|
||||
$backend_api = new TPsoft\BugreportBackend\API('typescript', 'import.meta.env.VITE_BACKENDAPI_URL');
|
||||
$backend_api = new TPsoft\BugreportBackend\API('typescript', 'import.meta.env.VITE_BACKENDAPI_URL', 'backend');
|
||||
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
@ -187,7 +187,7 @@ class API extends APIlite
|
||||
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']);
|
||||
$filename = 'report_' . $report_id . '_' . time() . '_' . $this->sanitizeFilename($data['filename']);
|
||||
file_put_contents(UPLOAD_DIR_ATTACHMENTS . $filename, $base64_data);
|
||||
$attachment_content = $filename;
|
||||
}
|
||||
@ -201,6 +201,26 @@ class API extends APIlite
|
||||
return $suc !== false;
|
||||
}
|
||||
|
||||
private function sanitizeFilename($filename, $allowedExtensions = [])
|
||||
{
|
||||
// Rozdelenie názvu a prípony
|
||||
$pathInfo = pathinfo($filename);
|
||||
$name = $pathInfo['filename'] ?? 'file';
|
||||
$extension = strtolower($pathInfo['extension'] ?? '');
|
||||
// Odstránenie nebezpečných znakov z názvu
|
||||
$name = preg_replace('/[^a-zA-Z0-9_-]/', '_', $name);
|
||||
$name = substr($name, 0, 100); // voliteľné obmedzenie dĺžky
|
||||
// Validácia prípony, ak je zoznam povolený
|
||||
if (
|
||||
$allowedExtensions
|
||||
&& count($allowedExtensions) > 0
|
||||
&& !in_array($extension, $allowedExtensions)
|
||||
) {
|
||||
$extension = 'bin'; // fallback ak prípona nie je povolená
|
||||
}
|
||||
return $name . '.' . $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update report attachment
|
||||
*
|
||||
@ -236,7 +256,7 @@ class API extends APIlite
|
||||
->toArray();
|
||||
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'];
|
||||
$all[$key]['attachment_content'] = '?action=attachmentDownload&filename=' . $all[$key]['attachment_content'];
|
||||
}
|
||||
}
|
||||
return $all;
|
||||
@ -254,4 +274,28 @@ class API extends APIlite
|
||||
$suc = $attachments->attachment($attachment_id, null);
|
||||
return $suc !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download report attachment
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function attachmentDownload(string $filename): void {
|
||||
$filename = $this->sanitizeFilename($filename);
|
||||
$filename = UPLOAD_DIR_ATTACHMENTS . $filename;
|
||||
if (file_exists($filename)) {
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($filename));
|
||||
readfile($filename);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
46
build.bat
Normal file
46
build.bat
Normal file
@ -0,0 +1,46 @@
|
||||
@echo off
|
||||
chcp 65001
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
echo ➡️ Delete old DIST folder
|
||||
rmdir /s /q "dist"
|
||||
echo ✅ Old DIST deleted
|
||||
|
||||
echo ➡️ Build Backend
|
||||
cd backend
|
||||
call composer run build
|
||||
cd ..
|
||||
echo ✅ Backend built
|
||||
|
||||
echo ➡️ Build frontend
|
||||
cd frontend
|
||||
call npm run build
|
||||
cd ..
|
||||
echo ✅ Frontend built
|
||||
|
||||
echo ➡️ Make new DIST folder structure
|
||||
mkdir "dist"
|
||||
mkdir "dist\data"
|
||||
mkdir "dist\data\attachments"
|
||||
mkdir "dist\app"
|
||||
echo ✅ New DIST structur created
|
||||
|
||||
echo ➡️ Copy APP files
|
||||
robocopy backend dist\app /S /XD tests scripts /XF composer.*
|
||||
robocopy frontend\dist dist\app\public /S
|
||||
echo ✅ APP files copied
|
||||
|
||||
echo ➡️ Packaging build
|
||||
for /f "tokens=2 delims=:" %%a in ('findstr /c:"\"version\"" frontend\package.json') do (
|
||||
set ver=%%a
|
||||
set ver=!ver: =!
|
||||
set ver=!ver:"=!
|
||||
set ver=!ver:,=!
|
||||
)
|
||||
echo 👉 Version: %ver%
|
||||
cd dist
|
||||
tar -a -c -f ..\build\BugReport.%ver%.zip *
|
||||
cd ..
|
||||
echo ✅ Build packaged
|
||||
|
||||
echo 🚀 Done.
|
||||
31
config.php
31
config.php
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (file_exists('c:/php/includes/igor.php')) {
|
||||
require_once 'c:/php/includes/igor.php';
|
||||
}
|
||||
|
||||
require_once __DIR__.'/lib/functions.inc.php';
|
||||
require_once __DIR__.'/lib/Medoo/src/Medoo.php';
|
||||
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https://" : "http://";
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$uri = $_SERVER['REQUEST_URI']; // obsahuje aj query string
|
||||
|
||||
|
||||
define('URL_PREFIX', $protocol.$host.str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']));
|
||||
|
||||
define('UPLOAD_DIR_ATTACHMENTS', __DIR__.'/data/attachments/');
|
||||
if (!file_exists(UPLOAD_DIR_ATTACHMENTS)) {
|
||||
mkdir(UPLOAD_DIR_ATTACHMENTS, 0777, true);
|
||||
}
|
||||
define('UPLOAD_URL_ATTACHMENTS', URL_PREFIX.'data/attachments/');
|
||||
|
||||
global $db;
|
||||
$db = new Medoo\Medoo([
|
||||
'type' => 'sqlite',
|
||||
'database' => __DIR__ . '/data/database.db'
|
||||
]);
|
||||
dbCheck();
|
||||
|
||||
|
||||
?>
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "bugreport",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
* Generated by APIlite
|
||||
* https://gitea.tpsoft.org/TPsoft.org/APIlite
|
||||
*
|
||||
* 2025-10-01 00:23:37 */
|
||||
* 2025-10-16 01:38:51 */
|
||||
|
||||
class backend {
|
||||
endpont = import.meta.env.VITE_BACKENDAPI_URL;
|
||||
endpoint = import.meta.env.VITE_BACKENDAPI_URL;
|
||||
|
||||
/* ----------------------------------------------------
|
||||
* General API call
|
||||
@ -28,7 +28,7 @@ class backend {
|
||||
if (typeof val == 'object') val = JSON.stringify(val);
|
||||
form_data.append(key, val);
|
||||
});
|
||||
xhttp.open('POST', this.endpont + '?action=' + method);
|
||||
xhttp.open('POST', this.endpoint + '?action=' + method);
|
||||
xhttp.send(form_data);
|
||||
}
|
||||
|
||||
@ -107,6 +107,10 @@ class backend {
|
||||
return this.callPromise('attachmentDelete', {attachment_id: attachment_id});
|
||||
}
|
||||
|
||||
attachmentDownload(filename) {
|
||||
return this.callPromise('attachmentDownload', {filename: filename});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -89,9 +89,9 @@
|
||||
v-else-if="attachment.attachment_type == 'file'"
|
||||
class="attachment-file"
|
||||
>
|
||||
<a :href="attachment.attachment_content" target="_blank">Stiahnut {{ attachment.attachment_content.split('/').pop().split('?')[0].split('#')[0] }}</a>
|
||||
<a :href="backend.endpoint + attachment.attachment_content" target="_blank">Stiahnut {{ attachment.attachment_content.split('/').pop().split('?')[0].split('#')[0] }}</a>
|
||||
<br>
|
||||
<img :src="attachment.attachment_content" v-if="isImageUrl(attachment.attachment_content)" />
|
||||
<img :src="backend.endpoint + attachment.attachment_content" v-if="isImageUrl(attachment.attachment_content)" />
|
||||
</div>
|
||||
<div v-else class="attachment-content">
|
||||
Neznamy typ prilohy: <strong>{{ attachment.attachment_type }}</strong>
|
||||
@ -102,7 +102,7 @@
|
||||
<div class="form-group">
|
||||
<label for="description">Nový komentár:</label>
|
||||
<textarea
|
||||
ref="attachmentNewContent"
|
||||
v-model="attachmentNewContent"
|
||||
rows="5"
|
||||
class="form-control"
|
||||
placeholder="Nove zistenia alebo riesenia"
|
||||
@ -144,7 +144,9 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup>
|
||||
import { onMounted, ref } from "vue";
|
||||
import { router } from "../router";
|
||||
import backend from "../backend";
|
||||
import FullScreenLoader from "../components/FullScreenLoader.vue";
|
||||
import JSConfetti from 'js-confetti'
|
||||
@ -152,164 +154,169 @@ import JSConfetti from 'js-confetti'
|
||||
let tadas = ['/sounds/tada.mp3', '/sounds/tada2.mp3', '/sounds/crazy-phrog-short.mp3'];
|
||||
const jungle = new Audio(tadas[Math.floor(Math.random() * tadas.length)]);
|
||||
|
||||
export default {
|
||||
name: "Report",
|
||||
components: { FullScreenLoader },
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
report_id: this.$route.params.id,
|
||||
report: {
|
||||
report_id: 0,
|
||||
report_title: "Nacitavam report",
|
||||
report_description: "...",
|
||||
report_status: 4,
|
||||
report_group: "--",
|
||||
report_priority: 1,
|
||||
created_dt: "--",
|
||||
ordnum: 0,
|
||||
},
|
||||
editable: true,
|
||||
attachments: [
|
||||
{
|
||||
attachment_id: 0,
|
||||
attachment_type: "comment",
|
||||
attachment_content: "Nacitavam report",
|
||||
created_dt: "--",
|
||||
},
|
||||
],
|
||||
attachmentNewFiles: null,
|
||||
selectedFiles: [],
|
||||
selectedFilesContent: [],
|
||||
};
|
||||
const loading = ref(false);
|
||||
const report_id = router.currentRoute.value.params.id;
|
||||
const report = ref({
|
||||
report_id: 0,
|
||||
report_title: "Nacitavam report",
|
||||
report_description: "...",
|
||||
report_status: 4,
|
||||
report_group: "--",
|
||||
report_priority: 1,
|
||||
created_dt: "--",
|
||||
ordnum: 0,
|
||||
});
|
||||
const editable = ref(true);
|
||||
const attachments = ref([
|
||||
{
|
||||
attachment_id: 0,
|
||||
attachment_type: "comment",
|
||||
attachment_content: "Nacitavam report",
|
||||
created_dt: "--",
|
||||
},
|
||||
mounted() {
|
||||
// console.log(this.report_id);
|
||||
this.loadReportData();
|
||||
},
|
||||
methods: {
|
||||
loadReportData() {
|
||||
backend.get(this.report_id).then((response) => {
|
||||
this.report = response.data;
|
||||
// console.log(this.report);
|
||||
this.editable = response.data.report_status < 4;
|
||||
]);
|
||||
const attachmentNewContent = ref(null);
|
||||
const attachmentNewFiles = ref(null);
|
||||
const selectedFiles = ref([]);
|
||||
const selectedFilesContent = ref([]);
|
||||
|
||||
onMounted(() => {
|
||||
// console.log(report_id);
|
||||
loadReportData();
|
||||
});
|
||||
|
||||
function loadReportData() {
|
||||
backend.get(report_id).then((response) => {
|
||||
report.value = response.data;
|
||||
// console.log(report);
|
||||
editable.value = response.data.report_status < 4;
|
||||
});
|
||||
backend.attachmentGetAll(report_id).then((response) => {
|
||||
attachments.value = response.data;
|
||||
// console.log(attachments);
|
||||
});
|
||||
}
|
||||
|
||||
function onTitleChange(event) {
|
||||
backend.update(report_id, { report_title: event.target.innerText });
|
||||
}
|
||||
|
||||
function onDescriptionChange(event) {
|
||||
backend.update(report_id, {
|
||||
report_description: event.target.innerText,
|
||||
});
|
||||
}
|
||||
|
||||
function reportDelete() {
|
||||
if (!confirm("Naozaj chcete report zmazať?")) return;
|
||||
loading.value = true;
|
||||
backend.delete(report_id).then(() => {
|
||||
router.push("/");
|
||||
});
|
||||
}
|
||||
|
||||
function reportDone() {
|
||||
backend.update(report_id, {
|
||||
report_status: 4,
|
||||
}).then(() => {
|
||||
jungle.play();
|
||||
const confetti = new JSConfetti();
|
||||
confetti.addConfetti();
|
||||
setTimeout(() => {
|
||||
router.push("/");
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
|
||||
function attachmentAdd() {
|
||||
let comment = attachmentNewContent.value;
|
||||
if (comment.trim().length > 0) {
|
||||
loading.value = true;
|
||||
backend
|
||||
.attachmentAdd(
|
||||
report_id,
|
||||
"comment",
|
||||
attachmentNewContent.value
|
||||
)
|
||||
.then(() => {
|
||||
attachmentNewContent.value = "";
|
||||
loadReportData();
|
||||
loading.value = false;
|
||||
});
|
||||
backend.attachmentGetAll(this.report_id).then((response) => {
|
||||
this.attachments = response.data;
|
||||
// console.log(this.attachments);
|
||||
});
|
||||
},
|
||||
onTitleChange(event) {
|
||||
backend.update(this.report_id, { report_title: event.target.innerText });
|
||||
},
|
||||
onDescriptionChange(event) {
|
||||
backend.update(this.report_id, {
|
||||
report_description: event.target.innerText,
|
||||
});
|
||||
},
|
||||
reportDelete() {
|
||||
if (!confirm("Naozaj chcete report zmazať?")) return;
|
||||
this.loading = true;
|
||||
backend.delete(this.report_id).then(() => {
|
||||
this.$router.push("/");
|
||||
});
|
||||
},
|
||||
reportDone() {
|
||||
backend.update(this.report_id, {
|
||||
report_status: 4,
|
||||
}).then(() => {
|
||||
jungle.play();
|
||||
const confetti = new JSConfetti();
|
||||
confetti.addConfetti();
|
||||
setTimeout(() => {
|
||||
this.$router.push("/");
|
||||
}, 3000);
|
||||
});
|
||||
},
|
||||
attachmentAdd() {
|
||||
let comment = this.$refs.attachmentNewContent.value;
|
||||
if (comment.trim().length > 0) {
|
||||
this.loading = true;
|
||||
backend
|
||||
.attachmentAdd(
|
||||
this.report_id,
|
||||
"comment",
|
||||
this.$refs.attachmentNewContent.value
|
||||
)
|
||||
.then(() => {
|
||||
this.$refs.attachmentNewContent.value = "";
|
||||
this.loadReportData();
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
if (this.selectedFiles.length > 0) {
|
||||
let for_upload = this.selectedFiles.length;
|
||||
this.loading = true;
|
||||
for (let i = 0; i < this.selectedFiles.length; i++) {
|
||||
backend
|
||||
.attachmentAdd(this.report_id, "file", {
|
||||
'filename': this.selectedFiles[i].name,
|
||||
'base64': this.selectedFilesContent[i]
|
||||
})
|
||||
.then(() => {
|
||||
for_upload--;
|
||||
if (for_upload == 0) {
|
||||
this.selectedFiles = [];
|
||||
this.selectedFilesContent = [];
|
||||
this.$refs.attachmentNewFiles.value = null;
|
||||
this.loadReportData();
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
attachmentDelete(attachment) {
|
||||
if (!confirm("Naozaj chcete zmazať prilohu?")) return;
|
||||
this.loading = true;
|
||||
backend.attachmentDelete(attachment.attachment_id).then(() => {
|
||||
this.loadReportData();
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
updateAttachmentContent(event, attachment) {
|
||||
this.loading = true;
|
||||
}
|
||||
if (selectedFiles.value.length > 0) {
|
||||
let for_upload = selectedFiles.value.length;
|
||||
loading.value = true;
|
||||
for (let i = 0; i < selectedFiles.value.length; i++) {
|
||||
backend
|
||||
.attachmentUpdate(attachment.attachment_id, event.target.innerText)
|
||||
.attachmentAdd(report_id, "file", {
|
||||
'filename': selectedFiles.value[i].name,
|
||||
'base64': selectedFilesContent.value[i]
|
||||
})
|
||||
.then(() => {
|
||||
this.loadReportData();
|
||||
this.loading = false;
|
||||
for_upload--;
|
||||
if (for_upload == 0) {
|
||||
selectedFiles.value = [];
|
||||
selectedFilesContent.value = [];
|
||||
attachmentNewFiles.value = null;
|
||||
loadReportData();
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
handleFileUpload(event) {
|
||||
const files = event.target.files;
|
||||
if (files) {
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
this.selectedFiles.push(files[i]);
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
this.selectedFilesContent[i] = reader.result;
|
||||
};
|
||||
reader.readAsDataURL(files[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
removeFile(index) {
|
||||
this.selectedFiles.splice(index, 1);
|
||||
this.selectedFilesContent.splice(index, 1);
|
||||
},
|
||||
formatFileSize(size) {
|
||||
if (size < 1024) {
|
||||
return size + " B";
|
||||
} else if (size < 1024 * 1024) {
|
||||
return (size / 1024).toFixed(2) + " KB";
|
||||
} else {
|
||||
return (size / (1024 * 1024)).toFixed(2) + " MB";
|
||||
}
|
||||
},
|
||||
isImageUrl(url) {
|
||||
return /\.(jpg|jpeg|png|gif|svg|webp)$/.test(url);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function attachmentDelete(attachment) {
|
||||
if (!confirm("Naozaj chcete zmazať prilohu?")) return;
|
||||
loading.value = true;
|
||||
backend.attachmentDelete(attachment.attachment_id).then(() => {
|
||||
loadReportData();
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function updateAttachmentContent(event, attachment) {
|
||||
loading.value = true;
|
||||
backend
|
||||
.attachmentUpdate(attachment.attachment_id, event.target.innerText)
|
||||
.then(() => {
|
||||
loadReportData();
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function handleFileUpload(event) {
|
||||
const files = event.target.files;
|
||||
if (files) {
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
selectedFiles.value.push(files[i]);
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
selectedFilesContent.value[i] = reader.result;
|
||||
};
|
||||
reader.readAsDataURL(files[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeFile(index) {
|
||||
selectedFiles.value.splice(index, 1);
|
||||
selectedFilesContent.value.splice(index, 1);
|
||||
}
|
||||
|
||||
function formatFileSize(size) {
|
||||
if (size < 1024) {
|
||||
return size + " B";
|
||||
} else if (size < 1024 * 1024) {
|
||||
return (size / 1024).toFixed(2) + " KB";
|
||||
} else {
|
||||
return (size / (1024 * 1024)).toFixed(2) + " MB";
|
||||
}
|
||||
}
|
||||
|
||||
function isImageUrl(url) {
|
||||
return /\.(jpg|jpeg|png|gif|svg|webp)$/.test(url);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@ -8,7 +8,7 @@ const require = createRequire(import.meta.url);
|
||||
const pkg = require("./package.json");
|
||||
|
||||
const subpath = "/bugreport/";
|
||||
export const baseUrl = subpath + "webapp/dist/";
|
||||
export const baseUrl = "/"; //subpath + "frontend/dist/";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(({ command, mode }) => {
|
||||
|
||||
11
index.php
11
index.php
@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>BugReport</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -1,344 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* String functions
|
||||
*/
|
||||
function allowedChars($str, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-')
|
||||
{
|
||||
return preg_match('/^[' . $chars . ']+$/', $str);
|
||||
}
|
||||
|
||||
function sanitizeFilename($filename, $allowedExtensions = [])
|
||||
{
|
||||
// Rozdelenie názvu a prípony
|
||||
$pathInfo = pathinfo($filename);
|
||||
$name = $pathInfo['filename'] ?? 'file';
|
||||
$extension = strtolower($pathInfo['extension'] ?? '');
|
||||
// Odstránenie nebezpečných znakov z názvu
|
||||
$name = preg_replace('/[^a-zA-Z0-9_-]/', '_', $name);
|
||||
$name = substr($name, 0, 100); // voliteľné obmedzenie dĺžky
|
||||
// Validácia prípony, ak je zoznam povolený
|
||||
if (
|
||||
$allowedExtensions
|
||||
&& count($allowedExtensions) > 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;
|
||||
}
|
||||
Reference in New Issue
Block a user