mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #716 from laf/bootgrid-inventory
Updated inventory table to use bootgrid
This commit is contained in:
73
html/includes/table/inventory.inc.php
Normal file
73
html/includes/table/inventory.inc.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
$where = "1";
|
||||
$param = array();
|
||||
|
||||
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
$sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id";
|
||||
} else {
|
||||
$sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `E`.`entPhysicalDescr` LIKE '%$searchPhrase%' OR `E`.`entPhysicalModelName` LIKE '%$searchPhrase%' OR `E`.`entPhysicalSerialNum` LIKE '%$searchPhrase%')";
|
||||
}
|
||||
|
||||
if (isset($_POST['string']) && strlen($_POST['string'])) {
|
||||
$sql .= " AND E.entPhysicalDescr LIKE ?";
|
||||
$param[] = "%".$_POST['string']."%";
|
||||
}
|
||||
|
||||
if (isset($_POST['device_string']) && strlen($_POST['device_string'])) {
|
||||
$sql .= " AND D.hostname LIKE ?";
|
||||
$param[] = "%".$_POST['device_string']."%";
|
||||
}
|
||||
|
||||
if (isset($_POST['part']) && strlen($_POST['part'])) {
|
||||
$sql .= " AND E.entPhysicalModelName = ?";
|
||||
$param[] = $_POST['part'];
|
||||
}
|
||||
|
||||
if (isset($_POST['serial']) && strlen($_POST['serial'])) {
|
||||
$sql .= " AND E.entPhysicalSerialNum LIKE ?";
|
||||
$param[] = "%".$_POST['serial']."%";
|
||||
}
|
||||
|
||||
if (isset($_POST['device']) && is_numeric($_POST['device'])) {
|
||||
$sql .= " AND D.device_id = ?";
|
||||
$param[] = $_POST['device'];
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`entPhysical_id`) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`hostname` DESC';
|
||||
}
|
||||
|
||||
$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 `D`.`device_id` AS `device_id`, `D`.`hostname` AS `hostname`,`entPhysicalDescr` AS `description`, `entPhysicalName` AS `name`, `entPhysicalModelName` AS `model`, `entPhysicalSerialNum` AS `serial` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $invent) {
|
||||
$response[] = array('hostname'=>generate_device_link($invent, shortHost($invent['hostname'])),
|
||||
'description'=>$invent['description'],
|
||||
'name'=>$invent['name'],
|
||||
'model'=>$invent['model'],
|
||||
'serial'=>$invent['serial']);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
echo _json_encode($output);
|
@@ -1,105 +1,89 @@
|
||||
<?php print_optionbar_start('25'); ?>
|
||||
|
||||
<form method="post" action="" class="form-inline" role="form">
|
||||
<div class="form-group">
|
||||
<input type="text" name="string" id="string" value="<?php echo($_POST['string']); ?>" placeholder="Description" class="form-control input-sm" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<strong>Part No</strong>
|
||||
<select name="part" id="part" class="form-control input-sm">
|
||||
<option value="">All Parts</option>
|
||||
<?php
|
||||
foreach (dbFetchRows("SELECT `entPhysicalModelName` FROM `entPhysical` GROUP BY `entPhysicalModelName` ORDER BY `entPhysicalModelName`") as $data)
|
||||
{
|
||||
echo("<option value='".$data['entPhysicalModelName']."'");
|
||||
if ($data['entPhysicalModelName'] == $_POST['part']) { echo("selected"); }
|
||||
echo(">".$data['entPhysicalModelName']."</option>");
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="serial" id="serial" value="<?php echo($_POST['serial']); ?>" placeholder="Serial" class="form-control input-sm"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<strong>Device</strong>
|
||||
<select name="device" id="device" class="form-control input-sm">
|
||||
<option value="">All Devices</option>
|
||||
<?php
|
||||
foreach (dbFetchRows("SELECT * FROM `devices` ORDER BY `hostname`") as $data)
|
||||
{
|
||||
echo("<option value='".$data['device_id']."'");
|
||||
|
||||
if ($data['device_id'] == $_POST['device']) { echo("selected"); }
|
||||
|
||||
echo(">".$data['hostname']."</option>");
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" size=24 name="device_string" id="device_string" value="<?php if ($_POST['device_string']) { echo($_POST['device_string']); } ?>" placeholder="Description" class="form-control input-sm"/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default input-sm">Search</button>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
$pagetitle[] = "Inventory";
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
$param = array();
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5')
|
||||
{
|
||||
$sql = "SELECT * from entPhysical AS E, devices AS D WHERE D.device_id = E.device_id";
|
||||
} else {
|
||||
$sql = "SELECT * from entPhysical AS E, devices AS D, devices_perms AS P WHERE D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
if (isset($_POST['string']) && strlen($_POST['string']))
|
||||
{
|
||||
$sql .= " AND E.entPhysicalDescr LIKE ?";
|
||||
$param[] = "%".$_POST['string']."%";
|
||||
}
|
||||
|
||||
if (isset($_POST['device_string']) && strlen($_POST['device_string']))
|
||||
{
|
||||
$sql .= " AND D.hostname LIKE ?";
|
||||
$param[] = "%".$_POST['device_string']."%";
|
||||
}
|
||||
|
||||
if (isset($_POST['part']) && strlen($_POST['part']))
|
||||
{
|
||||
$sql .= " AND E.entPhysicalModelName = ?";
|
||||
$param[] = $_POST['part'];
|
||||
}
|
||||
|
||||
if (isset($_POST['serial']) && strlen($_POST['serial']))
|
||||
{
|
||||
$sql .= " AND E.entPhysicalSerialNum LIKE ?";
|
||||
$param[] = "%".$_POST['serial']."%";
|
||||
}
|
||||
|
||||
if (isset($_POST['device']) && is_numeric($_POST['device']))
|
||||
{
|
||||
$sql .= " AND D.device_id = ?";
|
||||
$param[] = $_POST['device'];
|
||||
}
|
||||
|
||||
echo('<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>Inventory</strong>
|
||||
</div>
|
||||
<table class="table table-hover table-condensed table-striped">');
|
||||
echo("<tr><th>Hostname</th><th>Description</th><th>Name</th><th>Part No</th><th>Serial No</th></tr>");
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $entry)
|
||||
{
|
||||
echo('<tr><td>' . generate_device_link($entry, shortHost($entry['hostname'])) . '</td><td>' . $entry['entPhysicalDescr'] .
|
||||
'</td><td>' . $entry['entPhysicalName'] . '</td><td>' . $entry['entPhysicalModelName'] . '</td><td>' . $entry['entPhysicalSerialNum'] . '</td></tr>');
|
||||
}
|
||||
echo("</table>");
|
||||
echo('</div>');
|
||||
?>
|
||||
|
||||
<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>Inventory</strong>
|
||||
</div>
|
||||
<table id="inventory" class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="hostname" data-order="asc">Hostname</th>
|
||||
<th data-column-id="description">Description</th>
|
||||
<th data-column-id="name">Name</th>
|
||||
<th data-column-id="model">Part No</th>
|
||||
<th data-column-id="serial">Serial No</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
var grid = $("#inventory").bootgrid({
|
||||
ajax: true,
|
||||
templates: {
|
||||
header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+
|
||||
"<div class=\"col-sm-9 actionBar\"><span class=\"pull-left\"><form method=\"post\" action=\"\" class=\"form-inline\" role=\"form\">"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<input type=\"text\" name=\"string\" id=\"string\" value=\"<?php echo($_POST['string']); ?>\" placeholder=\"Description\" class=\"form-control input-sm\" />"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<strong> Part No </strong>"+
|
||||
"<select name=\"part\" id=\"part\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Parts</option>"+
|
||||
<?php
|
||||
foreach (dbFetchRows("SELECT `entPhysicalModelName` FROM `entPhysical` GROUP BY `entPhysicalModelName` ORDER BY `entPhysicalModelName`") as $data) {
|
||||
echo('"<option value=\"'.$data['entPhysicalModelName'].'\""+');
|
||||
if ($data['entPhysicalModelName'] == $_POST['part']) {
|
||||
echo('" selected"+');
|
||||
}
|
||||
echo('">'.$data['entPhysicalModelName'].'</option>"+');
|
||||
}
|
||||
?>
|
||||
"</select>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<input type=\"text\" name=\"serial\" id=\"serial\" value=\"<?php echo($_POST['serial']); ?>\" placeholder=\"Serial\" class=\"form-control input-sm\"/>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<strong> Device </strong>"+
|
||||
"<select name=\"device\" id=\"device\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Devices</option>"+
|
||||
<?php
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `devices` ORDER BY `hostname`") as $data) {
|
||||
echo('"<option value=\"'.$data['device_id'].'\""+');
|
||||
if ($data['device_id'] == $_POST['device']) {
|
||||
echo('" selected"+');
|
||||
}
|
||||
echo('">'.$data['hostname'].'</option>"+');
|
||||
}
|
||||
?>
|
||||
"</select>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<input type=\"text\" size=24 name=\"device_string\" id=\"device_string\" value=\"<?php if ($_POST['device_string']) { echo($_POST['device_string']); } ?>\" placeholder=\"Description\" class=\"form-control input-sm\"/>"+
|
||||
"</div>"+
|
||||
"<button type=\"submit\" class=\"btn btn-default input-sm\">Search</button>"+
|
||||
"</form></span></div>"+
|
||||
"<div class=\"col-sm-3 actionBar\"><p class=\"{{css.actions}}\"></p></div></div></div>"
|
||||
},
|
||||
post: function ()
|
||||
{
|
||||
return {
|
||||
id: "inventory",
|
||||
device: '<?php echo htmlspecialchars($_POST['device']); ?>',
|
||||
string: '<?php echo mres($_POST['string']); ?>',
|
||||
device_string: '<?php echo mres($_POST['device_string']); ?>',
|
||||
part: '<?php echo mres($_POST['part']); ?>',
|
||||
serial: '<?php echo mres($_POST['serial']); ?>'
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php"
|
||||
});
|
||||
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user