diff --git a/includes/html/pages/device/vlans.inc.php b/includes/html/pages/device/vlans.inc.php
index 7675891fdc..8d714a8628 100644
--- a/includes/html/pages/device/vlans.inc.php
+++ b/includes/html/pages/device/vlans.inc.php
@@ -75,13 +75,7 @@ print_optionbar_end();
echo '
';
-$i = '1';
-
-foreach (dbFetchRows("SELECT * FROM `vlans` WHERE `device_id` = ? ORDER BY 'vlan_vlan'", array($device['device_id'])) as $vlan) {
- include 'includes/html/print-vlan.inc.php';
-
- $i++;
-}
+include 'includes/html/print-vlan.inc.php';
echo '
';
diff --git a/includes/html/print-vlan.inc.php b/includes/html/print-vlan.inc.php
index e4d5a4abce..5aed0940ca 100644
--- a/includes/html/print-vlan.inc.php
+++ b/includes/html/print-vlan.inc.php
@@ -1,56 +1,61 @@
";
-
-echo ' Vlan '.$vlan['vlan_vlan'].' | ';
-echo ''.$vlan['vlan_name'].' | ';
-echo '';
-
$vlan_ports = array();
-$traverse_ifvlan = true;
-$otherports = dbFetchRows('SELECT * FROM `ports_vlans` AS V, `ports` as P WHERE V.`device_id` = ? AND V.`vlan` = ? AND P.port_id = V.port_id', array($device['device_id'], $vlan['vlan_vlan']));
-foreach ($otherports as $otherport) {
- if ($otherport['untagged']) {
- $traverse_ifvlan = false;
+$vlans_data = array();
+
+foreach (dbFetchRows('SELECT * FROM `vlans` WHERE `device_id` = ? GROUP BY `vlan_vlan` ORDER BY `vlan_vlan`', array($device['device_id'])) as $vlan) {
+ foreach ($vlan as $k => $v) {
+ if ($k != "vlan_vlan") {
+ $vlans_data[$vlan['vlan_vlan']][$k]=$v;
+ }
}
- $vlan_ports[$otherport['ifIndex']] = $otherport;
}
-if ($traverse_ifvlan) {
- $otherports = dbFetchRows('SELECT * FROM ports WHERE `device_id` = ? AND `ifVlan` = ?', array($device['device_id'], $vlan['vlan_vlan']));
- foreach ($otherports as $otherport) {
- $vlan_ports[$otherport['ifIndex']] = array_merge($otherport, array('untagged' => '1'));
+$otherports = dbFetchRows('SELECT * FROM `ports_vlans` AS V, `ports` AS P WHERE V.`device_id` = ? AND P.port_id = V.port_id', array($device['device_id']));
+foreach ($otherports as $n => $otherport) {
+ if (!$otherport['untagged']) {
+ if ($otherport['ifvlan'] == $otherport['vlan']) {
+ $otherport['untagged'] = 1;
+ }
}
+ $vlan_ports[$otherport['vlan']][$otherport['ifIndex']] = $otherport;
}
ksort($vlan_ports);
-foreach ($vlan_ports as $port) {
- $port = cleanPort($port, $device);
- if ($vars['view'] == 'graphs') {
- echo "\
- '.display($port['ifAlias'])." \
- \
- ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >" . "
-
- ".substr(short_port_descr($port['ifAlias']), 0, 22).'
- ';
- } else {
- echo $vlan['port_sep'].generate_port_link($port, makeshortif($port['label']));
- $vlan['port_sep'] = ', ';
- if ($port['untagged']) {
- echo '(U)';
+$i=0;
+foreach ($vlan_ports as $vlan => $ports) {
+ $bg_colour = \LibreNMS\Config::get('list_colour.odd');
+ if (!is_integer($i / 2)) {
+ $bg_colour = \LibreNMS\Config::get('list_colour.even');
+ }
+
+ echo " | ";
+ echo ' Vlan '.$vlan.' | ';
+ echo ''.$vlans_data[$vlan]['vlan_name'].' | ';
+ echo '';
+
+ foreach ($ports as $port_id => $port) {
+ $port = cleanPort($port, $device);
+ if ($vars['view'] == 'graphs') {
+ echo "\
+ '.display($port['ifAlias'])." \
+ \
+ ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >" . "
+
+ ".substr(short_port_descr($port['ifAlias']), 0, 22).'
+ ';
+ } else {
+ echo $vlans_data[$vlan]['port_sep'].generate_port_link($port, makeshortif($port['label']));
+ $vlans_data[$vlan]['port_sep'] = ', ';
+ if ($port['untagged']) {
+ echo '(U)';
+ }
}
}
-}//end foreach
-
-echo ' |
';
+ echo '';
+ $i++;
+}