From 64843df97bdb4f61d1d8d15f6256a01e6bc49fad Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Thu, 19 Feb 2026 11:14:39 +0100 Subject: [PATCH 1/2] feat: Add task attachments management to task edit interface; implement attachment upload, delete, and rename functionalities --- .vscode/ftp-kr.sync.cache.json | 52 ++- autoload/controls/class.Tasks.php | 44 +- templates/tasks/task_edit.php | 648 +++++++++++++++++++++++++++--- 3 files changed, 678 insertions(+), 66 deletions(-) diff --git a/.vscode/ftp-kr.sync.cache.json b/.vscode/ftp-kr.sync.cache.json index 9c0673f..29d5d20 100644 --- a/.vscode/ftp-kr.sync.cache.json +++ b/.vscode/ftp-kr.sync.cache.json @@ -164,8 +164,8 @@ }, "MailToTaskImporter.php": { "type": "-", - "size": 37982, - "lmtime": 1770800891666, + "size": 43841, + "lmtime": 1771426284341, "modified": false }, "TaskAttachmentRepository.php": { @@ -251,11 +251,17 @@ ".claude": { "settings.local.json": { "type": "-", - "size": 449, - "lmtime": 1771336223831, + "size": 452, + "lmtime": 1771422306144, "modified": false } }, + "CLAUDE.md": { + "type": "-", + "size": 4572, + "lmtime": 1771422482909, + "modified": false + }, "CODE_INDEX.md": { "type": "-", "size": 16884, @@ -264,7 +270,7 @@ }, "config.php": { "type": "-", - "size": 1232, + "size": 1186, "lmtime": 1770587027872, "modified": true }, @@ -294,6 +300,12 @@ "lmtime": 1770733260000, "modified": true }, + "mail_import_debug.log": { + "type": "-", + "size": 18628, + "lmtime": 0, + "modified": false + }, "REFACTORING_PLAN.md": { "type": "-", "size": 3576, @@ -335,8 +347,8 @@ }, "task_popup.php": { "type": "-", - "size": 22706, - "lmtime": 1771336355877, + "size": 22823, + "lmtime": 1771426296050, "modified": false }, "task_single.php": { @@ -475,13 +487,37 @@ "modified": false } }, + "_tmp_db_check.php": { + "type": "-", + "size": 696, + "lmtime": 0, + "modified": false + }, "tmp_debug_mail_import.php": { "type": "-", "size": 1238, "lmtime": 0, "modified": false }, - "upload": {} + "_tmp_mail_name_check.php": { + "type": "-", + "size": 62, + "lmtime": 0, + "modified": false + }, + "TODO.md": { + "type": "-", + "size": 103, + "lmtime": 1771423099316, + "modified": false + }, + "upload": {}, + "VIDOK_Instrukcja Montażu I Uruchomienia - Wyroby Elektryczne.pdf": { + "type": "-", + "size": 230708, + "lmtime": 0, + "modified": false + } } }, "$version": 1 diff --git a/autoload/controls/class.Tasks.php b/autoload/controls/class.Tasks.php index 27d45fa..133665d 100644 --- a/autoload/controls/class.Tasks.php +++ b/autoload/controls/class.Tasks.php @@ -351,6 +351,8 @@ class Tasks } $task_id = (int)\S::get( 'task_id' ); + if ( !$task_id ) + $task_id = (int)\S::get( 'id' ); $users = \S::get( 'users' ); $status_change_mail_value = \S::get( 'status_change_mail' ); $status_change_mail = 0; @@ -421,13 +423,24 @@ class Tasks exit; } - $task = \factory\Tasks::task_details( \S::get( 'task_id' ) ); + $task_id = (int)\S::get( 'task_id' ); + if ( !$task_id ) + $task_id = (int)\S::get( 'id' ); + + $attachments_repository = new \Domain\Tasks\TaskAttachmentRepository(); + $task = \factory\Tasks::task_details( $task_id ); + if ( !is_array( $task ) ) + $task = []; + $task['status'] = \Controllers\TasksController::resolveTaskStatusForForm( $task ); + $task['id'] = isset( $task['id'] ) ? (int)$task['id'] : $task_id; + $task_id_for_attachments = (int)$task['id']; return \Tpl::view( 'tasks/task_edit', [ 'projects' => \factory\Projects::user_projects( $user['id'] ), 'priorities' => \factory\Tasks::$priorities, 'task' => $task, + 'task_attachments' => $task_id_for_attachments ? $attachments_repository -> listByTaskId( $task_id_for_attachments ) : [], 'parent_tasks' => \factory\Tasks::parent_tasks( $user['id'] ), 'users' => \factory\Users::users_list(), 'clients' => \factory\Crm::get_client_list(), @@ -605,6 +618,35 @@ class Tasks exit; } + static public function task_attachments_list() + { + global $user; + + if ( !$user ) + { + header( 'Location: /logowanie' ); + exit; + } + + $task_id = (int)\S::get( 'task_id' ); + + if ( !$task_id ) + { + echo json_encode( [ 'status' => 'error', 'msg' => 'Brak identyfikatora zadania.' ] ); + exit; + } + + $repository = new \Domain\Tasks\TaskAttachmentRepository(); + $attachments = $repository -> listByTaskId( $task_id ); + + echo json_encode( [ + 'status' => 'success', + 'attachments' => is_array( $attachments ) ? $attachments : [], + 'count' => is_array( $attachments ) ? count( $attachments ) : 0 + ] ); + exit; + } + static public function filtr_save_form() { echo json_encode( [ 'status' => 'success', diff --git a/templates/tasks/task_edit.php b/templates/tasks/task_edit.php index 604d8b8..ab7c07e 100644 --- a/templates/tasks/task_edit.php +++ b/templates/tasks/task_edit.php @@ -1,6 +1,45 @@ task['id']; +$task_attachments = ( isset( $this -> task_attachments ) and is_array( $this -> task_attachments ) ) ? $this -> task_attachments : []; +$attachments_count = count( $task_attachments ); + +$date_start = ''; +if ( $this -> task['date_start'] ) + $date_start = date( 'Y-m-d', strtotime( $this -> task['date_start'] ) ); +elseif ( !$this -> task['id'] ) + $date_start = date( 'Y-m-d' ); + +$date_end = ''; +if ( $this -> task['date_end'] ) + $date_end = date( 'Y-m-d', strtotime( $this -> task['date_end'] ) ); +elseif ( !$this -> task['id'] ) + $date_end = date( 'Y-m-d' ); + +$projects = [ 0 => '--- wybierz projekt ---' ]; +if ( is_array( $this -> projects ) ) + foreach ( $this -> projects as $project ) + { + $projects[ $project[ 'id' ] ] = $project[ 'name' ]; + if ( (int)$project['client_id'] ) + $projects[ $project['id'] ] .= ' (' . \factory\Crm::get_client_name( (int)$project[ 'client_id' ] ) . ')'; + } + +$project_id = $this -> task['project_id'] ? $this -> task[ 'project_id' ] : 0; +if ( !$this -> task['id'] and !$project_id ) + $project_id = 72; + +$clients = [ 0 => '--- wybierz klienta ---' ]; +if ( is_array( $this -> clients ) ) + foreach ( $this -> clients as $client ) + $clients[ $client[ 'id' ] ] = $client[ 'firm' ]; + +$parent_tasks = [ 0 => '--- wybierz zadanie nadrzędne ---' ]; +if ( is_array( $this -> parent_tasks ) ) + foreach ( $this -> parent_tasks as $parent_task ) + $parent_tasks[ $parent_task[ 'id' ] ] = $parent_task[ 'name' ] . ( $parent_task['client'] ? ' (' . $parent_task['client'] . ')' : '' ); + ob_start(); ?> task['date_start'] ) - $date_start = date( 'Y-m-d', strtotime( $this -> task['date_start'] ) ); -else -{ - if ( !$this -> task['id'] ) - $date_start = date( 'Y-m-d' ); -} +$tab_basic = ob_get_clean(); -if ( $this -> task['date_end'] ) - $date_end = date( 'Y-m-d', strtotime( $this -> task['date_end'] ) ); -else -{ - if ( !$this -> task['id'] ) - $date_end = date( 'Y-m-d' ); -} +ob_start(); ?> 'Data rozpoczęcia', @@ -62,25 +89,6 @@ else 'inline' => true, 'autocomplete' => 'off' ]);?> - projects ) ) - foreach ( $this -> projects as $project ) - { - $projects[ $project[ 'id' ] ] = $project[ 'name' ]; - if ( (int)$project['client_id'] ) - $projects[ $project['id'] ] .= ' (' . \factory\Crm::get_client_name( (int)$project[ 'client_id' ] ) . ')'; - } -?> - task['project_id'] ) - $project_id = $this -> task[ 'project_id' ]; -else -{ - if ( !$this -> task['id'] ) - $project_id = 72; -} -?> 'Projekt', 'name' => 'project_id', @@ -88,12 +96,6 @@ else 'value' => $project_id, 'values' => $projects ]);?> - clients ) ) - foreach ( $this -> clients as $client ) - $clients[ $client[ 'id' ] ] = $client[ 'firm' ]; -?> 'Klient', @@ -103,14 +105,7 @@ if ( is_array( $this -> clients ) ) 'values' => $clients ] ); ?> - - parent_tasks ) ) - foreach ( $this -> parent_tasks as $parent_task ) - $parent_tasks[ $parent_task[ 'id' ] ] = $parent_task[ 'name' ] . ( $parent_task['client'] ? ' (' . $parent_task['client'] . ')' : '' ); -?> - 'Zadanie nadrzędne', 'name' => 'parent_id', @@ -126,13 +121,6 @@ if ( is_array( $this -> parent_tasks ) ) 'value' => $this -> task[ 'id' ] ? $this -> task[ 'status' ] : 5, 'values' => \factory\Tasks::get_statuses() ] );?> - - priorities ) ) - foreach ( $this -> priorities as $priority ) - $priorities[ $priority[ 'id' ] ] = $priority[ 'name' ]; -?> 'Priorytet', @@ -153,6 +141,11 @@ if ( is_array( $this -> priorities ) ) 'autocomplete' => 'off' ]);?> + 'Powiadom o zmianie statusu', @@ -239,8 +232,205 @@ if ( is_array( $this -> priorities ) ) task[ 'id' ] ? $project_id = $this -> task[ 'project_id' ] : $project_id = $this -> project_id; +$tab_users_and_automation = ob_get_clean(); +ob_start(); +?> +
+
style="display: none;"> +
+ Najpierw zapisz zadanie, aby dodać załączniki. +
+
+ +
style="display: none;"> + +
    + + +
  • + + + + () + + +
  • + + +
  • Brak załączników.
  • + +
+
+
+ +
+ + +
+ +
+
+ +
+
+ +
+
+ +
+
+ + + draw();