Files

87 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2015-04-02 18:05:24 +01:00
<?php
2015-07-13 20:10:26 +02:00
$where = '1';
2020-09-21 15:40:17 +02:00
$param = [];
2015-04-02 18:05:24 +01:00
2020-09-21 15:40:17 +02:00
if (! Auth::user()->hasGlobalRead()) {
2019-12-30 12:11:26 +01:00
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
2020-09-21 15:59:34 +02:00
$where .= ' AND `D`.`device_id` IN ' . dbGenPlaceholders(count($device_ids));
2019-12-30 12:11:26 +01:00
$param = array_merge($param, $device_ids);
2015-04-02 18:05:24 +01:00
}
2019-12-30 12:11:26 +01:00
$sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id";
2020-09-21 15:40:17 +02:00
if (isset($searchPhrase) && ! empty($searchPhrase)) {
2020-09-21 15:59:34 +02:00
$sql .= ' AND (`D`.`hostname` LIKE ? OR `E`.`entPhysicalDescr` LIKE ? OR `E`.`entPhysicalModelName` LIKE ? OR `E`.`entPhysicalSerialNum` LIKE ?)';
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
2015-04-02 18:05:24 +01:00
}
if (isset($vars['string']) && strlen($vars['string'])) {
2020-09-21 15:40:17 +02:00
$sql .= ' AND E.entPhysicalDescr LIKE ?';
$param[] = '%' . $vars['string'] . '%';
2015-04-02 18:05:24 +01:00
}
if (isset($vars['device_string']) && strlen($vars['device_string'])) {
2020-09-21 15:40:17 +02:00
$sql .= ' AND D.hostname LIKE ?';
$param[] = '%' . $vars['device_string'] . '%';
2015-04-02 18:05:24 +01:00
}
if (isset($vars['part']) && strlen($vars['part'])) {
2020-09-21 15:40:17 +02:00
$sql .= ' AND E.entPhysicalModelName = ?';
$param[] = $vars['part'];
2015-04-02 18:05:24 +01:00
}
if (isset($vars['serial']) && strlen($vars['serial'])) {
2020-09-21 15:40:17 +02:00
$sql .= ' AND E.entPhysicalSerialNum LIKE ?';
$param[] = '%' . $vars['serial'] . '%';
2015-04-02 18:05:24 +01:00
}
if (isset($vars['device']) && is_numeric($vars['device'])) {
2020-09-21 15:40:17 +02:00
$sql .= ' AND D.device_id = ?';
$param[] = $vars['device'];
2015-04-02 18:05:24 +01:00
}
$count_sql = "SELECT COUNT(`entPhysical_id`) $sql";
2020-09-21 15:40:17 +02:00
$total = dbFetchCell($count_sql, $param);
if (empty($total)) {
$total = 0;
}
2015-04-02 18:05:24 +01:00
2020-09-21 15:40:17 +02:00
if (! isset($sort) || empty($sort)) {
2015-04-02 18:05:24 +01:00
$sort = '`hostname` DESC';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
2020-09-21 15:40:17 +02:00
$limit_low = (($current * $rowCount) - ($rowCount));
2015-04-02 18:05:24 +01:00
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
2020-05-05 01:59:44 +02:00
$sql = "SELECT `D`.`device_id` AS `device_id`, `D`.`os` AS `os`, `D`.`hostname` AS `hostname`, `D`.`sysName` AS `sysName`,`entPhysicalDescr` AS `description`, `entPhysicalName` AS `name`, `entPhysicalModelName` AS `model`, `entPhysicalSerialNum` AS `serial` $sql";
2015-04-02 18:05:24 +01:00
foreach (dbFetchRows($sql, $param) as $invent) {
2020-09-21 15:40:17 +02:00
$response[] = [
'hostname' => generate_device_link($invent),
'description' => $invent['description'],
'name' => $invent['name'],
'model' => $invent['model'],
'serial' => $invent['serial'],
];
2015-04-02 18:05:24 +01:00
}
2020-09-21 15:40:17 +02:00
$output = [
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
];
2015-04-02 18:05:24 +01:00
echo _json_encode($output);