Switch device and port ARP tables to ajax

Allow sorting, filtering and paging of device and port ARP tables.
This commit is contained in:
Tony Murray
2015-12-24 10:58:12 -06:00
parent 1ea0e4f710
commit fe86b998bf
3 changed files with 56 additions and 91 deletions

View File

@@ -26,6 +26,11 @@ if (is_numeric($_POST['device_id'])) {
$param[] = $_POST['device_id'];
}
if (is_numeric($_POST['port_id'])) {
$sql .= ' AND P.port_id = ?';
$param[] = $_POST['port_id'];
}
$count_sql = "SELECT COUNT(`M`.`port_id`) $sql";
$total = dbFetchCell($count_sql, $param);

View File

@@ -1,48 +1,29 @@
<?php
$no_refresh = true;
?>
<table id="port-arp" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="mac_address">MAC address</th>
<th data-column-id="ipv4_address">IPv4 address</th>
<th data-column-id="remote_device" data-sortable="false">Remote device</th>
<th data-column-id="remote_interface" data-sortable="false">Remote interface</th>
</tr>
</thead>
</table>
echo '<table border="0" cellspacing="0" cellpadding="5" width="100%">';
$i = '1';
<script>
foreach (dbFetchRows('SELECT * FROM ipv4_mac WHERE port_id = ?', array($port['port_id'])) as $arp) {
if (!is_integer($i / 2)) {
$bg_colour = $list_colour_a;
}
else {
$bg_colour = $list_colour_b;
}
var grid = $("#port-arp").bootgrid({
ajax: true,
post: function ()
{
return {
id: "arp-search",
port_id: "<?php echo $port['port_id']; ?>"
};
},
url: "ajax_table.php"
});
</script>
$arp_host = dbFetchRow('SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($arp['ipv4_address']));
if ($arp_host) {
$arp_name = generate_device_link($arp_host);
}
else {
unset($arp_name);
}
if ($arp_host) {
$arp_if = generate_port_link($arp_host);
}
else {
unset($arp_if);
}
if ($arp_host['device_id'] == $device['device_id']) {
$arp_name = 'Localhost';
}
if ($arp_host['port_id'] == $arp['port_id']) {
$arp_if = 'Local Port';
}
echo '
<tr bgcolor="'.$bg_colour.'">
<td width="160">'.formatmac($arp['mac_address']).'</td>
<td width="140">'.$arp['ipv4_address'].'</td>
<td width="200">'.$arp_name.'</td>
<td>'.$arp_if.'</td>
</tr>';
$i++;
}//end foreach
echo '</table>';

View File

@@ -1,51 +1,30 @@
<?php
$no_refresh = true;
?>
<table id="ports-arp" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="interface">Port</th>
<th data-column-id="mac_address">MAC address</th>
<th data-column-id="ipv4_address">IPv4 address</th>
<th data-column-id="remote_device" data-sortable="false">Remote device</th>
<th data-column-id="remote_interface" data-sortable="false">Remote interface</th>
</tr>
</thead>
</table>
echo '<table class="table table-condensed">';
echo '<tr><th>Port</th><th>MAC address</th><th>IPv4 address</th><th>Remote device</th><th>Remote port</th></tr>';
<script>
$i = '1';
var grid = $("#ports-arp").bootgrid({
ajax: true,
post: function ()
{
return {
id: "arp-search",
device_id: "<?php echo $device['device_id']; ?>"
};
},
url: "ajax_table.php"
});
</script>
foreach (dbFetchRows('SELECT * FROM ipv4_mac AS M, ports AS I WHERE I.port_id = M.port_id AND I.device_id = ?', array($device['device_id'])) as $arp) {
if (!is_integer($i / 2)) {
$bg_colour = $list_colour_a;
}
else {
$bg_colour = $list_colour_b;
}
$arp_host = dbFetchRow('SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($arp['ipv4_address']));
if ($arp_host) {
$arp_name = generate_device_link($arp_host);
}
else {
unset($arp_name);
}
if ($arp_host) {
$arp_if = generate_port_link($arp_host);
}
else {
unset($arp_if);
}
if ($arp_host['device_id'] == $device['device_id']) {
$arp_name = 'Localhost';
}
if ($arp_host['port_id'] == $arp['port_id']) {
$arp_if = 'Local Port';
}
echo "
<tr bgcolor=$bg_colour>
<td width=200><b>".generate_port_link(array_merge($arp, $device)).'</b></td>
<td width=160>'.formatmac($arp['mac_address']).'</td>
<td width=160>'.$arp['ipv4_address']."</td>
<td width=280>$arp_name</td>
<td>$arp_if</td>
</tr>";
$i++;
}//end foreach
echo '</table>';