From 6b0855cff80a1b6478901c0d699caf8e4c78cde2 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 26 Jun 2025 15:49:49 -0400 Subject: [PATCH] Fix Exports while in Client Overview some were failing due to missing client_id var and some were not logging the client_id if in the client section --- modals/software_export_modal.php | 2 ++ post/user/asset.php | 1 + post/user/certificate.php | 3 ++- post/user/contact.php | 3 ++- post/user/credential.php | 3 ++- post/user/domain.php | 3 ++- post/user/location.php | 3 ++- post/user/network.php | 3 ++- post/user/software.php | 18 +++++++++--------- 9 files changed, 24 insertions(+), 15 deletions(-) diff --git a/modals/software_export_modal.php b/modals/software_export_modal.php index 01ec6d6f..641fae93 100644 --- a/modals/software_export_modal.php +++ b/modals/software_export_modal.php @@ -8,7 +8,9 @@
+ + diff --git a/post/user/asset.php b/post/user/asset.php index 57e7bb3e..1debe781 100644 --- a/post/user/asset.php +++ b/post/user/asset.php @@ -975,6 +975,7 @@ if (isset($_POST['export_assets_csv'])) { $client_name = $client_row['client_name']; } else { $client_query = ''; + $client_id = 0; // for Logging } // Get records from database diff --git a/post/user/certificate.php b/post/user/certificate.php index 22292c1b..b5e9b3f3 100644 --- a/post/user/certificate.php +++ b/post/user/certificate.php @@ -225,6 +225,7 @@ if (isset($_POST['export_certificates_csv'])) { $client_query = "AND certificate_client_id = $client_id"; } else { $client_query = ''; + $client_id = 0; } $sql = mysqli_query($mysqli,"SELECT * FROM certificates WHERE certificate_archived_at IS NULL $client_query ORDER BY certificate_name ASC"); @@ -260,7 +261,7 @@ if (isset($_POST['export_certificates_csv'])) { } // Logging - logAction("Certificate", "Export", "$session_name exported $num_rows certificate(s) to a CSV file"); + logAction("Certificate", "Export", "$session_name exported $num_rows certificate(s) to a CSV file", $client_id); exit; diff --git a/post/user/contact.php b/post/user/contact.php index 1d70ef05..14975611 100644 --- a/post/user/contact.php +++ b/post/user/contact.php @@ -1216,6 +1216,7 @@ if (isset($_POST['export_contacts_csv'])) { $client_query = "AND contact_client_id = $client_id"; } else { $client_query = ''; + $client_id = 0; //Logging } //Contacts @@ -1252,7 +1253,7 @@ if (isset($_POST['export_contacts_csv'])) { } //Logging - logAction("Contact", "Export", "$session_name exported $num_rows contact(s) to a CSV file"); + logAction("Contact", "Export", "$session_name exported $num_rows contact(s) to a CSV file", $client_id); exit; diff --git a/post/user/credential.php b/post/user/credential.php index 49d07e06..7ab7d9cf 100644 --- a/post/user/credential.php +++ b/post/user/credential.php @@ -321,6 +321,7 @@ if (isset($_POST['export_credentials_csv'])) { $client_query = "AND credential_client_id = $client_id"; } else { $client_query = ''; + $client_id = 0; } //get records from database @@ -360,7 +361,7 @@ if (isset($_POST['export_credentials_csv'])) { } // Logging - logAction("Credential", "Export", "$session_name exported $num_rows credential(s) to a CSV file"); + logAction("Credential", "Export", "$session_name exported $num_rows credential(s) to a CSV file", $client_id); exit; diff --git a/post/user/domain.php b/post/user/domain.php index 8091e0f0..df741c41 100644 --- a/post/user/domain.php +++ b/post/user/domain.php @@ -336,6 +336,7 @@ if (isset($_POST['export_domains_csv'])) { $client_query = "WHERE domain_client_id = $client_id"; } else { $client_query = ''; + $client_id = 0; } $sql = mysqli_query($mysqli,"SELECT * FROM domains $client_query ORDER BY domain_name ASC"); @@ -371,7 +372,7 @@ if (isset($_POST['export_domains_csv'])) { } // Logging - logAction("Domain", "Export", "$session_name exported $num_rows domain(s)"); + logAction("Domain", "Export", "$session_name exported $num_rows domain(s)", $client_id); exit; diff --git a/post/user/location.php b/post/user/location.php index 087215b1..6413ed66 100644 --- a/post/user/location.php +++ b/post/user/location.php @@ -370,6 +370,7 @@ if(isset($_POST['export_locations_csv'])){ $client_query = "AND location_client_id = $client_id"; } else { $client_query = ''; + $client_id = 0; } //Locations @@ -406,7 +407,7 @@ if(isset($_POST['export_locations_csv'])){ } // Logging - logAction("Location", "Export", "$session_name exported $num_rows location(s) to a CSV file"); + logAction("Location", "Export", "$session_name exported $num_rows location(s) to a CSV file", $client_id); exit; diff --git a/post/user/network.php b/post/user/network.php index b4ba0c19..62d2a814 100644 --- a/post/user/network.php +++ b/post/user/network.php @@ -160,6 +160,7 @@ if (isset($_POST['export_networks_csv'])) { $client_query = "AND network_client_id = $client_id"; } else { $client_query = ''; + $client_id = 0; } $sql = mysqli_query($mysqli,"SELECT * FROM networks WHERE network_archived_at IS NULL $client_query ORDER BY network_name ASC"); @@ -195,7 +196,7 @@ if (isset($_POST['export_networks_csv'])) { } // Logging - logAction("Network", "Export", "$session_name deleted $num_rows network(s) to a CSV file"); + logAction("Network", "Export", "$session_name deleted $num_rows network(s) to a CSV file", $client_id); exit; diff --git a/post/user/software.php b/post/user/software.php index a71a4c03..589861a3 100644 --- a/post/user/software.php +++ b/post/user/software.php @@ -215,21 +215,21 @@ if (isset($_POST['export_client_software_csv'])) { enforceUserPermission('module_support'); - $client_id = intval($_POST['client_id']); + if (isset($_POST['client_id'])) { + $client_id = intval($_POST['client_id']); + $client_query = "WHERE software_client_id = $client_id"; + } else { + $client_query = ''; + $client_id = 0; //Logging + } - //get records from database - $sql = mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $client_id"); - $row = mysqli_fetch_array($sql); - - $client_name = $row['client_name']; - - $sql = mysqli_query($mysqli,"SELECT * FROM software WHERE software_client_id = $client_id ORDER BY software_name ASC"); + $sql = mysqli_query($mysqli,"SELECT * FROM software $client_query ORDER BY software_name ASC"); $num_rows = mysqli_num_rows($sql); if ($num_rows > 0) { $delimiter = ","; - $filename = $client_name . "-Software-" . date('Y-m-d') . ".csv"; + $filename = "Software-" . date('Y-m-d') . ".csv"; //create a file pointer $f = fopen('php://memory', 'w');