Updated customers page to use bootgrid

This commit is contained in:
laf
2015-08-11 10:38:25 +00:00
parent e8a74e17a6
commit 53c15fc7df
2 changed files with 132 additions and 80 deletions

View File

@ -0,0 +1,105 @@
<?php
if (!is_array($config['customers_descr'])) {
$config['customers_descr'] = array($config['customers_descr']);
}
$descr_type = "'".implode("', '", $config['customers_descr'])."'";
$i = 0;
$sql = ' FROM `ports` LEFT JOIN `devices` AS `D` ON `ports`.`device_id` = `D`.`device_id` WHERE `port_descr_type` IN (?)';
$param[] = array($descr_type);
if (isset($searchPhrase) && !empty($searchPhrase)) {
$sql .= " AND (`port_descr_descr` LIKE '%$searchPhrase%' OR `ifName` LIKE '%$searchPhrase%' OR `ifDescr` LIKE '%$searchPhrase%' OR `ifAlias` LIKE '%$searchPhrase%' OR `D`.`hostname` LIKE '%$searchPhrase%' OR `port_descr_speed` LIKE '%$searchPhrase%' OR `port_descr_notes` LIKE '%$searchPhrase%')";
}
$count_sql = "SELECT COUNT(DISTINCT(`port_descr_descr`)) $sql";
$sql .= ' GROUP BY `port_descr_descr`';
$total = dbFetchCell($count_sql,$param);
if (empty($total)) {
$total = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = '`port_descr_descr`';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = ($current * $rowCount) - ($rowCount);
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
foreach (dbFetchRows($sql, $param) as $customer) {
$i++;
$customer_name = $customer['port_descr_descr'];
foreach (dbFetchRows('SELECT * FROM `ports` WHERE `port_descr_type` IN (?) AND `port_descr_descr` = ?', array(array($descr_type), $customer['port_descr_descr'])) as $port) {
$device = device_by_id_cache($port['device_id']);
$ifname = fixifname($device['ifDescr']);
$ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
if ($device['os'] == 'ios') {
if ($port['ifTrunk']) {
$vlan = '<span class=box-desc><span class=red>'.$port['ifTrunk'].'</span></span>';
}
else if ($port['ifVlan']) {
$vlan = '<span class=box-desc><span class=blue>VLAN '.$port['ifVlan'].'</span></span>';
}
else {
$vlan = '';
}
}
$response[] = array(
'port_descr_descr' => $customer_name,
'device_id' => generate_device_link($device),
'ifDescr' => generate_port_link($port, makeshortif($port['ifDescr'])),
'port_descr_speed' => $port['port_descr_speed'],
'port_descr_circuit' => $port['port_descr_circuit'],
'port_descr_notes' => $port['port_descr_notes'],
);
unset($customer_name);
}
$graph_array['type'] = 'customer_bits';
$graph_array['height'] = '100';
$graph_array['width'] = '220';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $customer['port_descr_descr'];
$return_data = true;
include 'includes/print-graphrow.inc.php';
$response[] = array(
'port_descr_descr' => $graph_data[0],
'device_id' => $graph_data[1],
'ifDescr' => '',
'port_descr_speed' => '',
'port_descr_circuit' => $graph_data[2],
'port_descr_notes' => $graph_data[3],
);
}
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
);
echo _json_encode($output);

View File

@ -1,87 +1,34 @@
<?php <?php
echo '<table border=0 cellspacing=0 cellpadding=2 class=devicetable width=100%>';
echo "
<tr bgcolor='$list_colour_a'>
<th width='7'></th>
<th width='250'><span style='font-weight: bold;' class=interface>Customer</span></th>
<th width='150'>Device</th>
<th width='100'>Interface</th>
<th width='100'>Speed</th>
<th width='100'>Circuit</th>
<th>Notes</th>
</tr>
";
$i = 1;
$pagetitle[] = 'Customers'; $pagetitle[] = 'Customers';
if (!is_array($config['customers_descr'])) { ?>
$config['customers_descr'] = array($config['customers_descr']);
}
$descr_type = "'".implode("', '", $config['customers_descr'])."'"; <div class="table-responsive">
<table id="customers" class="table table-hover table-condensed table-striped">
<thead>
<tr>
<th data-column-id="port_descr_descr" data-order="asc">Customer</th>
<th data-column-id="device_id">Device</th>
<th data-column-id="ifDescr">Interface</th>
<th data-column-id="port_descr_speed">Speed</th>
<th data-column-id="port_descr_circuit">Circuit</th>
<th data-column-id="port_descr_notes">Notes</th>
</tr>
</thead>
</table>
</div>
foreach (dbFetchRows('SELECT * FROM `ports` WHERE `port_descr_type` IN (?) GROUP BY `port_descr_descr` ORDER BY `port_descr_descr`', array(array($descr_type))) as $customer) { <script>
$i++;
$customer_name = $customer['port_descr_descr']; var grid = $("#customers").bootgrid({
ajax: true,
if (!is_integer($i / 2)) { post: function ()
$bg_colour = $list_colour_a; {
} return {
else { id: "customers",
$bg_colour = $list_colour_b; };
} },
url: "/ajax_table.php"
foreach (dbFetchRows('SELECT * FROM `ports` WHERE `port_descr_type` IN (?) AND `port_descr_descr` = ?', array(array($descr_type), $customer['port_descr_descr'])) as $port) { });
$device = device_by_id_cache($port['device_id']); </script>
unset($class);
$ifname = fixifname($device['ifDescr']);
$ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
if ($device['os'] == 'ios') {
if ($port['ifTrunk']) {
$vlan = '<span class=box-desc><span class=red>'.$port['ifTrunk'].'</span></span>';
}
else if ($port['ifVlan']) {
$vlan = '<span class=box-desc><span class=blue>VLAN '.$port['ifVlan'].'</span></span>';
}
else {
$vlan = '';
}
}
echo "
<tr bgcolor='$bg_colour'>
<td width='7'></td>
<td width='250'><span style='font-weight: bold;' class=interface>".$customer_name."</span></td>
<td width='150'>".generate_device_link($device)."</td>
<td width='100'>".generate_port_link($port, makeshortif($port['ifDescr']))."</td>
<td width='100'>".$port['port_descr_speed']."</td>
<td width='100'>".$port['port_descr_circuit'].'</td>
<td>'.$port['port_descr_notes'].'</td>
</tr>
';
unset($customer_name);
}
echo "<tr bgcolor='$bg_colour'><td></td><td colspan=6>";
$graph_array['type'] = 'customer_bits';
$graph_array['height'] = '100';
$graph_array['width'] = '220';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $customer['port_descr_descr'];
include 'includes/print-graphrow.inc.php';
echo '</tr>';
}
echo '</table>';