From fc24bcb24fa529587272c3dd650c22d00f0ba849 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 10 Feb 2025 16:58:39 -0500 Subject: [PATCH] Moved Transfer Asset to Client to a Bulk Action and create Primary Interface when moving with MAC address --- client_assets.php | 14 +- client_contacts.php | 2 +- clients.php | 3 - expenses.php | 3 - includes/filter_header.php | 2 + ...lient_asset_bulk_transfer_client_modal.php | 48 +++++++ modals/client_asset_transfer_modal.php | 48 ------- modals/notifications_modal.php | 4 +- post/user/asset.php | 133 ++++++++++-------- 9 files changed, 136 insertions(+), 121 deletions(-) create mode 100644 modals/client_asset_bulk_transfer_client_modal.php delete mode 100644 modals/client_asset_transfer_modal.php diff --git a/client_assets.php b/client_assets.php index 9029e776..795cbdd6 100644 --- a/client_assets.php +++ b/client_assets.php @@ -208,6 +208,10 @@ if (mysqli_num_rows($os_sql) > 0) { Assign Contact + + Transfer to Client + + Assign Location @@ -579,9 +583,6 @@ if (mysqli_num_rows($os_sql) > 0) { Delete - - Transfer - Archive @@ -597,11 +598,8 @@ if (mysqli_num_rows($os_sql) > 0) { @@ -611,6 +609,7 @@ if (mysqli_num_rows($os_sql) > 0) { + @@ -622,11 +621,8 @@ if (mysqli_num_rows($os_sql) > 0) { diff --git a/client_contacts.php b/client_contacts.php index d110d6b3..8cd0f36b 100644 --- a/client_contacts.php +++ b/client_contacts.php @@ -33,7 +33,7 @@ if (isset($_GET['location']) & !empty($_GET['location'])) { } //Rebuild URL -$url_query_strings_sort = http_build_query($get_copy); +//$url_query_strings_sort = http_build_query($get_copy); $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contacts.*, locations.*, users.*, GROUP_CONCAT(tags.tag_name) FROM contacts LEFT JOIN locations ON location_id = contact_location_id diff --git a/clients.php b/clients.php index 92e33f52..a1da892f 100644 --- a/clients.php +++ b/clients.php @@ -54,9 +54,6 @@ if (isset($_GET['referral']) & !empty($_GET['referral'])) { $referral_filter = ''; } -//Rebuild URL -$url_query_strings_sort = http_build_query($get_copy); - $sql = mysqli_query( $mysqli, " diff --git a/expenses.php b/expenses.php index dffee9da..0c0d8035 100644 --- a/expenses.php +++ b/expenses.php @@ -39,9 +39,6 @@ if (isset($_GET['category']) & !empty($_GET['category'])) { $category_filter = ''; } -//Rebuild URL -$url_query_strings_sort = http_build_query($get_copy); - $sql = mysqli_query( $mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM expenses diff --git a/includes/filter_header.php b/includes/filter_header.php index f8be8453..077fa95d 100644 --- a/includes/filter_header.php +++ b/includes/filter_header.php @@ -12,6 +12,8 @@ $get_copy = $_GET; // create a copy of the $_GET array //unset($get_copy['page']); unset($get_copy['sort']); unset($get_copy['order']); +//Rebuild URL +$url_query_strings_sort = http_build_query($get_copy); // Paging if (isset($_GET['page'])) { diff --git a/modals/client_asset_bulk_transfer_client_modal.php b/modals/client_asset_bulk_transfer_client_modal.php new file mode 100644 index 00000000..c469d395 --- /dev/null +++ b/modals/client_asset_bulk_transfer_client_modal.php @@ -0,0 +1,48 @@ + diff --git a/modals/client_asset_transfer_modal.php b/modals/client_asset_transfer_modal.php deleted file mode 100644 index 76ecb451..00000000 --- a/modals/client_asset_transfer_modal.php +++ /dev/null @@ -1,48 +0,0 @@ - diff --git a/modals/notifications_modal.php b/modals/notifications_modal.php index 4340788c..182ec337 100644 --- a/modals/notifications_modal.php +++ b/modals/notifications_modal.php @@ -22,7 +22,7 @@ $notification_type = nullable_htmlentities($row['notification_type']); $notification_details = nullable_htmlentities($row['notification']); $notification_action = nullable_htmlentities($row['notification_action']); - $notification_created_at_formated = date('M d g:ia',strtotime($row['notification_created_at'])); + $notification_timestamp_formated = date('M d g:ia',strtotime($row['notification_timestamp'])); $notification_client_id = intval($row['notification_client_id']); if(empty($notification_action)) { $notification_action = "#"; } ?> @@ -34,7 +34,7 @@ - + diff --git a/post/user/asset.php b/post/user/asset.php index 11e20411..372438ec 100644 --- a/post/user/asset.php +++ b/post/user/asset.php @@ -120,61 +120,6 @@ if (isset($_POST['edit_asset'])) { } -if (isset($_POST['change_client_asset'])) { - - enforceUserPermission('module_support', 2); - - validateCSRFToken($_POST['csrf_token']); - - $current_asset_id = intval($_POST['current_asset_id']); - $new_client_id = intval($_POST['new_client_id']); - - // Get Asset details and current client ID/Name for logging - $row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT asset_name, asset_notes, asset_client_id, client_name FROM assets LEFT JOIN clients ON client_id = asset_client_id WHERE asset_id = $current_asset_id")); - $asset_name = sanitizeInput($row['asset_name']); - $asset_notes = sanitizeInput($row['asset_notes']); - $current_client_id = intval($row['asset_client_id']); - $current_client_name = sanitizeInput($row['client_name']); - - // Get new client name for logging - $row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $new_client_id")); - $new_client_name = sanitizeInput($row['client_name']); - - // Create new asset - mysqli_query($mysqli, " - INSERT INTO assets (asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important) - SELECT asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important - FROM assets - WHERE asset_id = $current_asset_id - "); - $new_asset_id = mysqli_insert_id($mysqli); - mysqli_query($mysqli, "UPDATE assets SET asset_client_id = $new_client_id WHERE asset_id = $new_asset_id"); - - // Archive/log the current asset - $notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)"; - mysqli_query($mysqli,"UPDATE assets SET asset_archived_at = NOW() WHERE asset_id = $current_asset_id"); - - // Log Archive - logAction("Asset", "Archive", "$session_name archived asset $asset_name (via transfer)", $current_client_id, $current_asset_id); - - // Log Transfer - logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $current_client_id, $current_asset_id); - mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $current_asset_id"); - - // Log the new asset - $notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)"; - logAction("Asset", "Create", "$session_name created asset $name (via transfer)", $new_client_id, $new_asset_id); - - logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $new_client_id, $new_asset_id); - - mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $new_asset_id"); - - $_SESSION['alert_message'] = "Asset $name transferred"; - - header("Location: client_assets.php?client_id=$new_client_id&asset_id=$new_asset_id"); - -} - if (isset($_GET['archive_asset'])) { enforceUserPermission('module_support', 2); @@ -303,6 +248,84 @@ if (isset($_POST['bulk_assign_asset_location'])) { } +if (isset($_POST['bulk_transfer_client_asset'])) { + + enforceUserPermission('module_support', 2); + + validateCSRFToken($_POST['csrf_token']); + + $new_client_id = intval($_POST['bulk_client_id']); + + // Transfer selected asset to new client + if (isset($_POST['asset_ids'])) { + + // Get Count + $asset_count = count($_POST['asset_ids']); + + foreach($_POST['asset_ids'] as $current_asset_id) { + $current_asset_id = intval($current_asset_id); + + // Get Asset details and current client ID/Name for logging + $row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT asset_name, asset_notes, asset_client_id, client_name, interface_mac + FROM assets + LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 + LEFT JOIN clients ON client_id = asset_client_id + WHERE asset_id = $current_asset_id") + ); + $asset_name = sanitizeInput($row['asset_name']); + $asset_notes = sanitizeInput($row['asset_notes']); + $interface_mac = sanitizeInput($row['interface_mac']); + $current_client_id = intval($row['asset_client_id']); + $current_client_name = sanitizeInput($row['client_name']); + + // Get new client name for logging + $row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $new_client_id")); + $new_client_name = sanitizeInput($row['client_name']); + + // Create new asset + mysqli_query($mysqli, " + INSERT INTO assets (asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important) + SELECT asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important + FROM assets + WHERE asset_id = $current_asset_id + "); + $new_asset_id = mysqli_insert_id($mysqli); + + // Add Primary Interface + mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = 'Primary', interface_mac = '$interface_mac', interface_port = 'eth0', interface_primary = 1, interface_asset_id = $new_asset_id"); + + mysqli_query($mysqli, "UPDATE assets SET asset_client_id = $new_client_id WHERE asset_id = $new_asset_id"); + + // Archive/log the current asset + $notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)"; + mysqli_query($mysqli,"UPDATE assets SET asset_archived_at = NOW() WHERE asset_id = $current_asset_id"); + + // Log Archive + logAction("Asset", "Archive", "$session_name archived asset $asset_name (via transfer)", $current_client_id, $current_asset_id); + + // Log Transfer + logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $current_client_id, $current_asset_id); + mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $current_asset_id"); + + // Log the new asset + $notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)"; + logAction("Asset", "Create", "$session_name created asset $name (via transfer)", $new_client_id, $new_asset_id); + + logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $new_client_id, $new_asset_id); + + mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $new_asset_id"); + + } // End Transfer to Client Loop + + // Bulk Logging + logAction("Asset", "Bulk Transfer", "$session_name transferred $asset_count assets to $new_client_name", $new_client_id); + + $_SESSION['alert_message'] = "Transferred $asset_count assets to $new_client_name."; + } + + header("Location: client_assets.php?client_id=$new_client_id&asset_id=$new_asset_id"); +} + if (isset($_POST['bulk_assign_asset_contact'])) { enforceUserPermission('module_support', 2);