Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2015-08-03 10:46:40 +00:00
<?php
2021-03-28 17:25:30 -05:00
$device_id = $vars['device_id'];
2015-08-03 10:46:40 +00:00
$sql = ' FROM `storage` AS `S` LEFT JOIN `devices` AS `D` ON `S`.`device_id` = `D`.`device_id` WHERE `D`.`device_id`=? AND `S`.`storage_deleted`=0';
$param[] = $device_id;
if (isset($searchPhrase) && ! empty($searchPhrase)) {
$sql .= ' AND (`D`.`hostname` LIKE ? OR `S`.`storage_descr` LIKE ? OR `S`.`storage_perc` LIKE ? OR `S`.`storage_perc_warn` LIKE ?)';
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
2015-08-03 10:46:40 +00:00
}
$count_sql = "SELECT COUNT(`storage_id`) $sql";
2016-08-18 20:28:22 -05:00
$total = dbFetchCell($count_sql, $param);
2015-08-03 10:46:40 +00:00
if (empty($total)) {
$total = 0;
}
if (! isset($sort) || empty($sort)) {
$sort = '`D`.`hostname`, `S`.`storage_descr`';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
2023-03-13 22:32:22 +01:00
$limit_low = ($current * $rowCount) - $rowCount;
2015-08-03 10:46:40 +00:00
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
//$response[] = array('storage_descr' => $sql);
2016-08-18 20:28:22 -05:00
foreach (dbFetchRows($sql, $param) as $drive) {
2021-03-28 17:25:30 -05:00
$perc = round($drive['storage_perc']);
$perc_warn = round($drive['storage_perc_warn']);
$size = \LibreNMS\Util\Number::formatBi($drive['storage_size']);
2015-08-03 10:46:40 +00:00
$response[] = [
'storage_id' => $drive['storage_id'],
'hostname' => generate_device_link($drive),
'storage_descr' => $drive['storage_descr'],
'storage_perc' => $perc . '%',
'storage_perc_warn' => $perc_warn,
'storage_size' => $size,
];
2015-08-03 10:46:40 +00:00
}
$output = ['current'=>$current, 'rowCount'=>$rowCount, 'rows'=>$response, 'total'=>$total];
2021-03-04 07:55:41 -06:00
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);