From 8c8de5ec347da470c9482fa8d834f3b4c31f9bf2 Mon Sep 17 00:00:00 2001 From: tp_dhu Date: Mon, 24 Mar 2025 11:14:13 +0000 Subject: [PATCH] enabled uploading images from clipboard on ticket edit. --- app/controllers/AttachmentController.php | 37 ++++++++++ ui/parts/clipboard.html | 89 ++++++++++++++++++++++++ ui/views/attachment/index.html | 6 ++ ui/views/ticket/create.html | 3 +- ui/views/ticket/edit.html | 2 + 5 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 ui/parts/clipboard.html diff --git a/app/controllers/AttachmentController.php b/app/controllers/AttachmentController.php index 3aabb48..6a8f3b6 100644 --- a/app/controllers/AttachmentController.php +++ b/app/controllers/AttachmentController.php @@ -145,4 +145,41 @@ class AttachmentController { // remove DB row $db->exec('DELETE FROM attachments WHERE id =?', [$attachment_id]); } + + // view attachment + public function view($f3){ + $this->check_access($f3); + + $attachment_id = (int) $f3->get('PARAMS.id'); + $db = $f3->get('DB'); + + $rows = $db->exec('SELECt * FROM attachments WHERE id = ?', [$attachment_id]); + + if(!$rows){ + $f3->error(404, "File not found"); + return; + } + + $attachment = $rows[0]; + $file_path = $attachment['path']; + $file_name = $attachment['file_name']; + + if(!file_exists($file_path)){ + $f3->error(404, "File not found"); + return; + } + + // detect mime type + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $mime_type = finfo_file($finfo, $file_path); + finfo_close($finfo); + + header('Content-Type: ' . $mime_type); + header('Content-Disposition: inline; filename="' . basename($file_name) . '"'); + header('Content-Length: ' . filesize($file_path)); + + flush(); + readfile($file_path); + exit; + } } \ No newline at end of file diff --git a/ui/parts/clipboard.html b/ui/parts/clipboard.html new file mode 100644 index 0000000..e399501 --- /dev/null +++ b/ui/parts/clipboard.html @@ -0,0 +1,89 @@ +
+ + +
+ Paste or drag an image here +
+ +

+ + +
\ No newline at end of file diff --git a/ui/views/attachment/index.html b/ui/views/attachment/index.html index 750d657..de6588f 100644 --- a/ui/views/attachment/index.html +++ b/ui/views/attachment/index.html @@ -28,6 +28,12 @@ +
+
+ + + +
diff --git a/ui/views/ticket/create.html b/ui/views/ticket/create.html index f9caba1..b8c1263 100644 --- a/ui/views/ticket/create.html +++ b/ui/views/ticket/create.html @@ -4,9 +4,10 @@
+ - + diff --git a/ui/views/ticket/edit.html b/ui/views/ticket/edit.html index 9215576..588961f 100644 --- a/ui/views/ticket/edit.html +++ b/ui/views/ticket/edit.html @@ -3,12 +3,14 @@ + +

Custom Fields