From 1cc0e7cd6da2550672ee201953776c551d524543 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sun, 19 Nov 2017 15:54:09 -0600 Subject: [PATCH] fix: Fixed empty group query for devices (#7760) * fix: empty device group query * fix: empty device group query Optimize it a bit to use the relationship. --- html/includes/table/devices.inc.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/html/includes/table/devices.inc.php b/html/includes/table/devices.inc.php index b24e536d6f..93e301dbe8 100644 --- a/html/includes/table/devices.inc.php +++ b/html/includes/table/devices.inc.php @@ -15,6 +15,12 @@ if (!empty($_POST['location'])) { $sql .= " LEFT JOIN `devices_attribs` AS `DB` ON `DB`.`device_id`=`devices`.`device_id` AND `DB`.`attrib_type`='override_sysLocation_bool' AND `DB`.`attrib_value`='1' LEFT JOIN `devices_attribs` AS `DA` ON `devices`.`device_id`=`DA`.`device_id`"; } +if (!empty($_POST['group']) && is_numeric($_POST['group'])) { + $sql .= " LEFT JOIN `device_group_device` AS `DG` ON `DG`.`device_id`=`devices`.`device_id`"; + $where .= " AND `DG`.`device_group_id`=?"; + $param[] = $_POST['group']; +} + $sql .= " WHERE $where "; if (!empty($_POST['hostname'])) { @@ -80,24 +86,9 @@ if (!empty($_POST['location'])) { $param[] = $_POST['location']; } -if (!empty($_POST['group'])) { - include_once '../includes/device-groups.inc.php'; - $sql .= ' AND ( '; - foreach (GetDevicesFromGroup($_POST['group']) as $dev) { - $sql .= '`devices`.`device_id` = ? OR '; - $param[] = $dev; - } - - $sql = substr($sql, 0, (strlen($sql) - 3)); - $sql .= ' )'; -} - $count_sql = "SELECT COUNT(`devices`.`device_id`) $sql"; -$total = dbFetchCell($count_sql, $param); -if (empty($total)) { - $total = 0; -} +$total = (int)dbFetchCell($count_sql, $param); if (!isset($sort) || empty($sort)) { $sort = '`hostname` DESC';