Added the Ability Set which interface is primary under add / edit interface section

This commit is contained in:
johnnyq
2025-02-13 16:26:21 -05:00
parent c81b430318
commit 2e9e49a203
5 changed files with 64 additions and 6 deletions

View File

@@ -745,6 +745,12 @@ if (isset($_POST['add_asset_interface'])) {
$new_interface_id = mysqli_insert_id($mysqli);
// If Primary Interface Checked set all interfaces primary to 0 then set the new interface as primary with a 1
if ($primary_interface) {
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_primary = 0 WHERE interface_asset_id = $asset_id");
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_primary = 1 WHERE interface_id = $new_interface_id");
}
// 5) If user selected a connected interface, insert row in asset_interface_links
if (!empty($connected_to) && intval($connected_to) > 0) {
$sql_link = "
@@ -849,6 +855,12 @@ if (isset($_POST['edit_asset_interface'])) {
";
mysqli_query($mysqli, $sql_update);
// If Primary Interface Checked set all interfaces primary to 0 then set the new interface as primary with a 1
if ($primary_interface) {
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_primary = 0 WHERE interface_asset_id = $asset_id");
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_primary = 1 WHERE interface_id = $interface_id");
}
// 3) Remove any existing link for this interface (one-to-one)
$sql_delete_link = "
DELETE FROM asset_interface_links

View File

@@ -2,6 +2,7 @@
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
$name = sanitizeInput($_POST['name']);
$primary_interface = sanitizeInput($_POST['primary_interface']) ?? 0;
$description = sanitizeInput($_POST['description']);
$type = sanitizeInput($_POST['type']);
$mac = sanitizeInput($_POST['mac']);