Files drag and drop: files and documents drag from the list or grid onto a folder in the tree or the path above the list to move there, ticked ones together, and folders drag onto other folders or Top level; a closed folder held over opens, files from the computer dropped on a tree folder upload into it, folder moves use the new move_folder handler, and Bulk Action Move now leaves items already in the folder alone

This commit is contained in:
johnnyq
2026-11-19 14:19:38 -05:00
parent c20acc9ac1
commit 3cb42eaaa2
6 changed files with 373 additions and 43 deletions

View File

@@ -84,6 +84,59 @@ if (isset($_POST['rename_folder'])) {
}
/*
* A folder dragged onto another on the Files page (agent/js/files.js), or onto the top level.
* What is in it goes with it.
*/
if (isset($_POST['move_folder'])) {
validateCSRFToken();
enforceUserPermission('module_support', 2);
$folder_id = intval($_POST['folder_id']);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT folder_name, folder_client_id FROM folders WHERE folder_id = $folder_id"));
if (!$row) {
flashAlert('That folder no longer exists.', 'error');
redirect();
}
$folder_name = $row['folder_name'];
$client_id = intval($row['folder_client_id']);
enforceClientAccess();
// Only under one of this client's folders - one that has gone isn't taken as the top level
$wanted = intval($_POST['parent_folder'] ?? 0);
$parent_folder = folderOwnedId($wanted, $client_id);
if ($parent_folder !== $wanted) {
flashAlert('The folder you dropped it on no longer exists.', 'error');
redirect();
}
// Never into itself or below itself
$tree = folderTree($client_id);
if (in_array($parent_folder, folderSubtree($tree, $folder_id), true)) {
flashAlert("A folder can't go inside itself or one of its own folders.", 'error');
redirect();
}
if ($parent_folder === intval($tree[$folder_id]['parent_folder'] ?? -1)) {
redirect();
}
$parent_name = folderDisplayName($parent_folder);
mysqli_query($mysqli, "UPDATE folders SET parent_folder = $parent_folder WHERE folder_id = $folder_id");
logAudit("Folder", "Move", "$session_name moved folder " . escapeSql($folder_name) . " into " . escapeSql($parent_name), $client_id, $folder_id);
flashAlert("Folder <strong>$folder_name</strong> moved into <strong>$parent_name</strong>");
redirect();
}
/*
* Deleting a folder never deletes what is in it: files, documents and
* subfolders move up to the folder it sat in. (Only documents used to be