From 77fce6a69d3e871a31320f1170ca850588333026 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 28 Oct 2024 17:53:44 -0400 Subject: [PATCH] FEATURE: Implemented SubFolders within Documents UI --- client_document_add_modal.php | 43 ++++++-- client_document_details.php | 43 +++++++- client_document_move_modal.php | 33 ++++-- client_documents.php | 193 +++++++++++++++++++++++++-------- folder_sub_create.php | 34 ++++++ folder_sub_create_modal.php | 34 ++++++ post/user/folder.php | 22 ++++ 7 files changed, 335 insertions(+), 67 deletions(-) create mode 100644 folder_sub_create.php create mode 100644 folder_sub_create_modal.php diff --git a/client_document_add_modal.php b/client_document_add_modal.php index 9476da66..1b8683ef 100644 --- a/client_document_add_modal.php +++ b/client_document_add_modal.php @@ -29,36 +29,55 @@ +
+
- - - $indentation$folder_name"; + + // Recursively display subfolders + display_folder_options($folder_id, $client_id, $indent + 1); + } } - ?> + // Start displaying folder options from the root (parent_folder = 0) + display_folder_options(0, $client_id); + ?>
-
+
- +
@@ -69,4 +88,4 @@ - \ No newline at end of file + diff --git a/client_document_details.php b/client_document_details.php index b484ae9a..ed5221ba 100644 --- a/client_document_details.php +++ b/client_document_details.php @@ -46,12 +46,45 @@ $document_client_visible = intval($row['document_client_visible']); - 0) { ?> - + + - -
diff --git a/client_document_move_modal.php b/client_document_move_modal.php index cc978b4d..07047315 100644 --- a/client_document_move_modal.php +++ b/client_document_move_modal.php @@ -21,14 +21,33 @@
diff --git a/client_documents.php b/client_documents.php index 7f6d0cca..22d0b0a3 100644 --- a/client_documents.php +++ b/client_documents.php @@ -89,6 +89,53 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); + + + 0) { + $sql_folder = mysqli_query($mysqli, "SELECT folder_name, parent_folder FROM folders WHERE folder_id = $folder_id"); + if ($row_folder = mysqli_fetch_assoc($sql_folder)) { + $folder_name = nullable_htmlentities($row_folder['folder_name']); + $parent_folder = intval($row_folder['parent_folder']); + + // Prepend the folder to the beginning of the array + array_unshift($folder_path, array('folder_id' => $folder_id, 'folder_name' => $folder_name)); + + // Move up to the parent folder + $folder_id = $parent_folder; + } else { + // If the folder is not found, break the loop + break; + } + } + ?> + + +
@@ -98,73 +145,133 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); + // Get the parent folder of the current folder + $result = mysqli_query($mysqli, "SELECT parent_folder FROM folders WHERE folder_id = $current_folder_id AND folder_client_id = $client_id"); + if ($row = mysqli_fetch_assoc($result)) { + $parent_folder_id = intval($row['parent_folder']); + // Recursive call to check the parent folder + return is_ancestor_folder($folder_id, $parent_folder_id, $client_id); + } else { + // Folder not found + return false; + } + } - + '; + echo '
'; - 0) { + // Display subfolders + echo ''; + } + echo ''; + } } + + // Start displaying folders from the root (parent_folder = 0) + display_folders(0, $client_id); ?> - +
diff --git a/folder_sub_create.php b/folder_sub_create.php new file mode 100644 index 00000000..2adf6879 --- /dev/null +++ b/folder_sub_create.php @@ -0,0 +1,34 @@ + diff --git a/folder_sub_create_modal.php b/folder_sub_create_modal.php new file mode 100644 index 00000000..b3b0a6d0 --- /dev/null +++ b/folder_sub_create_modal.php @@ -0,0 +1,34 @@ + diff --git a/post/user/folder.php b/post/user/folder.php index d1ac8e05..2b81e48d 100644 --- a/post/user/folder.php +++ b/post/user/folder.php @@ -25,6 +25,28 @@ if (isset($_POST['create_folder'])) { } +if (isset($_POST['create_sub_folder'])) { + + validateTechRole(); + + $client_id = intval($_POST['client_id']); + $folder_location = intval($_POST['folder_location']); + $folder_name = sanitizeInput($_POST['folder_name']); + $parent_folder = intval($_POST['parent_folder']); + + // Document folder add query + $add_folder = mysqli_query($mysqli,"INSERT INTO folders SET folder_name = '$folder_name', parent_folder = $parent_folder, folder_location = $folder_location, folder_client_id = $client_id"); + $folder_id = mysqli_insert_id($mysqli); + + // Logging + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Folder', log_action = 'Create', log_description = '$session_name created sub folder $folder_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $folder_id"); + + $_SESSION['alert_message'] = "Folder $folder_name created"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + if (isset($_POST['rename_folder'])) { validateTechRole();