Fix network vlan duplicating

This commit is contained in:
Marcus Hill
2022-01-28 22:46:19 +00:00
parent 1db6582a4e
commit e4db480855

View File

@@ -43,34 +43,31 @@
<?php <?php
if($sql_assets){ if($sql_assets){
$network_names = []; $networks = [];
$network_vlans = [];
// Reset the $sql_assets pointer to the start // Reset the $sql_assets pointer to the start
mysqli_data_seek($sql_assets, 0); mysqli_data_seek($sql_assets, 0);
// Get networks linked to assets - push their name and vlan to arrays // Get networks linked to assets - push name to array
while($row = mysqli_fetch_array($sql_assets)){ while($row = mysqli_fetch_array($sql_assets)){
if(!empty($row['network_name'])){ if(!empty($row['network_name'])){
array_push($network_names, $row['network_name']); $network_data = "$row[network_name]:$row[network_vlan]";
array_push($network_vlans, $row['network_vlan']); array_push($networks, $network_data);
} }
} }
// Remove duplicates // Remove duplicates
$network_names = array_unique($network_names); $networks = array_unique($networks);
$network_vlans = array_unique($network_vlans);
// Display // Display
if(!empty($network_names)){ ?> if(!empty($networks)){ ?>
<h5><i class="nav-icon fas fa-network-wired"></i> Networks</h5> <h5><i class="nav-icon fas fa-network-wired"></i> Networks</h5>
<ul> <ul>
<?php <?php
} }
foreach($network_names as $network){ foreach($networks as $network){
foreach($network_vlans as $vlan){ $network = explode(":", $network);
echo "<li><a href=\"client.php?client_id=$client_id&tab=networks&q=$network\">$network (VLAN: $vlan)</a></li>"; echo "<li><a href=\"client.php?client_id=$client_id&tab=networks&q=$network[0]\">$network[0] (VLAN $network[1])</a></li>";
}
} }
// Not showing/haven't added explicitly linked networks - can't see a need for a network that doesn't have an asset on it? // Not showing/haven't added explicitly linked networks - can't see a need for a network that doesn't have an asset on it?