From 55a31865d075d3b564d2c9b2163ba3619ba8f91b Mon Sep 17 00:00:00 2001 From: johnnyq Date: Fri, 30 May 2025 16:15:12 -0400 Subject: [PATCH] Updated Client Overview Entities to not show Archived client's Entities even though the entity may not be archived, also added Archive Searching to network and certificates also added unarchive capabilities to them as well --- assets.php | 20 ++++++++++++++++++-- certificates.php | 36 +++++++++++++++++++++++++++++++++--- contacts.php | 18 +++++++++++++++++- credentials.php | 20 +++++++++++++++++++- locations.php | 18 +++++++++++++++++- networks.php | 35 ++++++++++++++++++++++++++++++++--- post/user/certificate.php | 23 +++++++++++++++++++++++ post/user/network.php | 23 +++++++++++++++++++++++ software.php | 18 +++++++++++++++++- 9 files changed, 199 insertions(+), 12 deletions(-) diff --git a/assets.php b/assets.php index f6d0f1cb..bdbb6112 100644 --- a/assets.php +++ b/assets.php @@ -9,10 +9,26 @@ if (isset($_GET['client_id'])) { require_once "includes/inc_all_client.php"; $client_query = "AND asset_client_id = $client_id"; $client_url = "client_id=$client_id&"; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "asset_archived_at IS NOT NULL"; + } else { + $archived = 0; + $archive_query = "asset_archived_at IS NULL"; + } } else { require_once "includes/inc_client_overview_all.php"; $client_query = ''; $client_url = ''; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "(client_archived_at IS NOT NULL OR asset_archived_at IS NOT NULL)"; + } else { + $archived = 0; + $archive_query = "(client_archived_at IS NULL AND asset_archived_at IS NULL)"; + } } // Perms @@ -71,7 +87,7 @@ $row = mysqli_fetch_assoc(mysqli_query($mysqli, " LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 - WHERE asset_$archive_query + WHERE $archive_query $access_permission_query $client_query ) AS filtered_assets; @@ -105,7 +121,7 @@ $sql = mysqli_query( LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 - WHERE asset_$archive_query + WHERE $archive_query AND (asset_name LIKE '%$q%' OR asset_description LIKE '%$q%' OR asset_type LIKE '%$q%' OR interface_ip LIKE '%$q%' OR interface_ipv6 LIKE '%$q%' OR asset_make LIKE '%$q%' OR asset_model LIKE '%$q%' OR asset_serial LIKE '%$q%' OR asset_os LIKE '%$q%' OR contact_name LIKE '%$q%' OR location_name LIKE '%$q%' OR client_name LIKE '%$q%') AND ($type_query) $access_permission_query diff --git a/certificates.php b/certificates.php index 7e7bfc04..97d80525 100644 --- a/certificates.php +++ b/certificates.php @@ -9,10 +9,26 @@ if (isset($_GET['client_id'])) { require_once "includes/inc_all_client.php"; $client_query = "AND certificate_client_id = $client_id"; $client_url = "client_id=$client_id&"; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "certificate_archived_at IS NOT NULL"; + } else { + $archived = 0; + $archive_query = "certificate_archived_at IS NULL"; + } } else { require_once "includes/inc_client_overview_all.php"; $client_query = ''; $client_url = ''; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "(client_archived_at IS NOT NULL OR certificate_archived_at IS NOT NULL)"; + } else { + $archived = 0; + $archive_query = "(client_archived_at IS NULL AND certificate_archived_at IS NULL)"; + } } // Perms @@ -32,7 +48,7 @@ if (!$client_url) { $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM certificates LEFT JOIN clients ON client_id = certificate_client_id - WHERE certificate_archived_at IS NULL + WHERE $archive_query AND (certificate_name LIKE '%$q%' OR certificate_domain LIKE '%$q%' OR certificate_issued_by LIKE '%$q%' OR client_name LIKE '%$q%') $access_permission_query $client_query @@ -65,6 +81,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); +
@@ -109,6 +126,10 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
+ "> + Archived +
diff --git a/contacts.php b/contacts.php index 9da09fe4..65fbda07 100644 --- a/contacts.php +++ b/contacts.php @@ -9,10 +9,26 @@ if (isset($_GET['client_id'])) { require_once "includes/inc_all_client.php"; $client_query = "AND contact_client_id = $client_id"; $client_url = "client_id=$client_id&"; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "contact_archived_at IS NOT NULL"; + } else { + $archived = 0; + $archive_query = "contact_archived_at IS NULL"; + } } else { require_once "includes/inc_client_overview_all.php"; $client_query = ''; $client_url = ''; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "(client_archived_at IS NOT NULL OR contact_archived_at IS NOT NULL)"; + } else { + $archived = 0; + $archive_query = "(client_archived_at IS NULL AND contact_archived_at IS NULL)"; + } } // Tags Filter @@ -55,7 +71,7 @@ $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contacts.*, clients.*, LEFT JOIN users ON user_id = contact_user_id LEFT JOIN contact_tags ON contact_tags.contact_id = contacts.contact_id LEFT JOIN tags ON tags.tag_id = contact_tags.tag_id - WHERE contact_$archive_query + WHERE $archive_query $tag_query AND (contact_name LIKE '%$q%' OR contact_title LIKE '%$q%' OR location_name LIKE '%$q%' OR contact_email LIKE '%$q%' OR contact_department LIKE '%$q%' OR contact_phone LIKE '%$phone_query%' OR contact_extension LIKE '%$q%' OR contact_mobile LIKE '%$phone_query%' OR tag_name LIKE '%$q%' OR client_name LIKE '%$q%') $access_permission_query diff --git a/credentials.php b/credentials.php index ebad77b1..5a88e058 100644 --- a/credentials.php +++ b/credentials.php @@ -9,12 +9,30 @@ if (isset($_GET['client_id'])) { require_once "includes/inc_all_client.php"; $client_query = "AND credential_client_id = $client_id"; $client_url = "client_id=$client_id&"; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "c.credential_archived_at IS NOT NULL"; + } else { + $archived = 0; + $archive_query = "c.credential_archived_at IS NULL"; + } + // Log when users load the Credentials page logAction("Credential", "View", "$session_name viewed the Credentials page for client", $client_id); + } else { require_once "includes/inc_client_overview_all.php"; $client_query = ''; $client_url = ''; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "(client_archived_at IS NOT NULL OR c.credential_archived_at IS NOT NULL)"; + } else { + $archived = 0; + $archive_query = "(client_archived_at IS NULL AND c.credential_archived_at IS NULL)"; + } // Log when users load the Credentials page logAction("Credential", "View", "$session_name viewed the All Credentials page"); } @@ -68,7 +86,7 @@ $sql = mysqli_query( LEFT JOIN contacts ON contact_id = credential_contact_id LEFT JOIN assets ON asset_id = credential_asset_id $location_query_innerjoin - WHERE c.credential_$archive_query + WHERE $archive_query $tag_query AND (c.credential_name LIKE '%$q%' OR c.credential_description LIKE '%$q%' OR c.credential_uri LIKE '%$q%' OR tag_name LIKE '%$q%' OR client_name LIKE '%$q%') $location_query diff --git a/locations.php b/locations.php index dbdf2dc3..165245d2 100644 --- a/locations.php +++ b/locations.php @@ -9,6 +9,14 @@ if (isset($_GET['client_id'])) { require_once "includes/inc_all_client.php"; $client_query = "AND location_client_id = $client_id"; $client_url = "client_id=$client_id&"; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "location_archived_at IS NOT NULL"; + } else { + $archived = 0; + $archive_query = "location_archived_at IS NULL"; + } } else { require_once "includes/inc_client_overview_all.php"; $client_query = ''; @@ -25,6 +33,14 @@ if (!$client_url) { $client_query = ''; $client = ''; } + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "(client_archived_at IS NOT NULL OR location_archived_at IS NOT NULL)"; + } else { + $archived = 0; + $archive_query = "(client_archived_at IS NULL AND location_archived_at IS NULL)"; + } } // Tags Filter @@ -45,7 +61,7 @@ $sql = mysqli_query( LEFT JOIN clients ON client_id = location_client_id LEFT JOIN location_tags ON location_tags.location_id = locations.location_id LEFT JOIN tags ON tags.tag_id = location_tags.tag_id - WHERE location_$archive_query + WHERE $archive_query $tag_query AND (location_name LIKE '%$q%' OR location_description LIKE '%$q%' OR location_address LIKE '%$q%' OR location_city LIKE '%$q%' OR location_state LIKE '%$q%' OR location_zip LIKE '%$q%' OR location_country LIKE '%$q%' OR location_phone LIKE '%$phone_query%' OR tag_name LIKE '%$q%' OR client_name LIKE '%$q%') $access_permission_query diff --git a/networks.php b/networks.php index 416e3f3b..96437c38 100644 --- a/networks.php +++ b/networks.php @@ -9,10 +9,26 @@ if (isset($_GET['client_id'])) { require_once "includes/inc_all_client.php"; $client_query = "AND network_client_id = $client_id"; $client_url = "client_id=$client_id&"; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "network_archived_at IS NOT NULL"; + } else { + $archived = 0; + $archive_query = "network_archived_at IS NULL"; + } } else { require_once "includes/inc_client_overview_all.php"; $client_query = ''; $client_url = ''; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "(client_archived_at IS NOT NULL OR network_archived_at IS NOT NULL)"; + } else { + $archived = 0; + $archive_query = "(client_archived_at IS NULL AND network_archived_at IS NULL)"; + } } // Perms @@ -45,7 +61,7 @@ $sql = mysqli_query( "SELECT SQL_CALC_FOUND_ROWS * FROM networks LEFT JOIN clients ON client_id = network_client_id LEFT JOIN locations ON location_id = network_location_id - WHERE network_$archive_query + WHERE $archive_query AND (network_name LIKE '%$q%' OR network_description LIKE '%$q%' OR network_vlan LIKE '%$q%' OR network LIKE '%$q%' OR network_gateway LIKE '%$q%' OR network_subnet LIKE '%$q%' OR network_primary_dns LIKE '%$q%' OR network_secondary_dns LIKE '%$q%' OR network_dhcp_range LIKE '%$q%' OR location_name LIKE '%$q%' OR client_name LIKE '%$q%') $access_permission_query $location_query @@ -80,6 +96,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); +
@@ -150,6 +167,10 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
+ "> + Archived +
diff --git a/post/user/certificate.php b/post/user/certificate.php index f2960904..22292c1b 100644 --- a/post/user/certificate.php +++ b/post/user/certificate.php @@ -132,6 +132,29 @@ if (isset($_GET['archive_certificate'])) { } +if (isset($_GET['unarchive_certificate'])) { + + enforceUserPermission('module_support', 2); + + $certificate_id = intval($_GET['unarchive_certificate']); + + // Get Certificate Name and Client ID for logging and alert message + $sql = mysqli_query($mysqli,"SELECT certificate_name, certificate_client_id FROM certificates WHERE certificate_id = $certificate_id"); + $row = mysqli_fetch_array($sql); + $certificate_name = sanitizeInput($row['certificate_name']); + $client_id = intval($row['certificate_client_id']); + + mysqli_query($mysqli,"UPDATE certificates SET certificate_archived_at = NULL WHERE certificate_id = $certificate_id"); + + // logging + logAction("Certificate", "Unarchive", "$session_name restored certificate $certificate_name", $client_id, $certificate_id); + + $_SESSION['alert_message'] = "Certificate $certificate_name restored"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + if (isset($_GET['delete_certificate'])) { enforceUserPermission('module_support', 3); diff --git a/post/user/network.php b/post/user/network.php index 661753a3..b4ba0c19 100644 --- a/post/user/network.php +++ b/post/user/network.php @@ -67,6 +67,29 @@ if (isset($_GET['archive_network'])) { } +if (isset($_GET['unarchive_network'])) { + + enforceUserPermission('module_support', 2); + + $network_id = intval($_GET['unarchive_network']); + + // Get Network Name and Client ID for logging and alert message + $sql = mysqli_query($mysqli,"SELECT network_name, network_client_id FROM networks WHERE network_id = $network_id"); + $row = mysqli_fetch_array($sql); + $network_name = sanitizeInput($row['network_name']); + $client_id = intval($row['network_client_id']); + + mysqli_query($mysqli,"UPDATE networks SET network_archived_at = NULL WHERE network_id = $network_id"); + + // logging + logAction("Network", "Unarchive", "$session_name restored contact $contact_name", $client_id, $network_id); + + $_SESSION['alert_message'] = "Network $network_name restored"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + if (isset($_GET['delete_network'])) { enforceUserPermission('module_support', 3); diff --git a/software.php b/software.php index 56d6d57c..653d99e7 100644 --- a/software.php +++ b/software.php @@ -9,10 +9,26 @@ if (isset($_GET['client_id'])) { require_once "includes/inc_all_client.php"; $client_query = "AND software_client_id = $client_id"; $client_url = "client_id=$client_id&"; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "software_archived_at IS NOT NULL"; + } else { + $archived = 0; + $archive_query = "software_archived_at IS NULL"; + } } else { require_once "includes/inc_client_overview_all.php"; $client_query = ''; $client_url = ''; + // Overide Filter Header Archived + if (isset($_GET['archived']) && $_GET['archived'] == 1) { + $archived = 1; + $archive_query = "(client_archived_at IS NOT NULL OR software_archived_at IS NOT NULL)"; + } else { + $archived = 0; + $archive_query = "(client_archived_at IS NULL AND software_archived_at IS NULL)"; + } } // Perms @@ -36,7 +52,7 @@ $sql = mysqli_query( LEFT JOIN clients ON client_id = software_client_id LEFT JOIN vendors ON vendor_id = software_vendor_id WHERE software_template = 0 - AND software_$archive_query + AND $archive_query AND (software_name LIKE '%$q%' OR software_type LIKE '%$q%' OR software_key LIKE '%$q%' OR client_name LIKE '%$q%') $access_permission_query $client_query