if (isset($_REQUEST['filter_with_triggers']) && !zbx_empty($_REQUEST['filter_with_triggers']) && $_REQUEST['filter_with_triggers'] != -1) { $options['with_triggers'] = $_REQUEST['filter_with_triggers']; } if (isset($_REQUEST['filter_ipmi_sensor']) && !zbx_empty($_REQUEST['filter_ipmi_sensor'])) { $options['filter']['ipmi_sensor'] = $_REQUEST['filter_ipmi_sensor']; } $afterFilter = count($options, COUNT_RECURSIVE); if ($preFilter == $afterFilter) { $data['items'] = array(); } else { $data['items'] = API::Item()->get($options); } // set values for subfilters, if any of subfilters = false then item shouldnt be shown if (!empty($data['items'])) { // fill template host fillItemsWithChildTemplates($data['items']); $dbHostItems = DBselect('SELECT i.itemid,h.name,h.hostid' . ' FROM hosts h,items i' . ' WHERE i.hostid=h.hostid' . ' AND ' . dbConditionInt('i.itemid', zbx_objectValues($data['items'], 'templateid'))); while ($dbHostItem = DBfetch($dbHostItems)) { foreach ($data['items'] as $itemid => $item) { if ($item['templateid'] == $dbHostItem['itemid']) { $data['items'][$itemid]['template_host'] = $dbHostItem; } } } foreach ($data['items'] as &$item) { $item['hostids'] = zbx_objectValues($item['hosts'], 'hostid'); $item['name_expanded'] = itemName($item); if (empty($data['filter_hostname'])) { $host = reset($item['hosts']); $item['host'] = $host['name']; }
function fillItemsWithChildTemplates(&$items) { $processSecondLevel = false; $dbItems = DBselect('SELECT i.itemid,i.templateid FROM items i WHERE ' . dbConditionInt('i.itemid', zbx_objectValues($items, 'templateid'))); while ($dbItem = DBfetch($dbItems)) { foreach ($items as $itemid => $item) { if ($item['templateid'] == $dbItem['itemid'] && !empty($dbItem['templateid'])) { $items[$itemid]['templateid'] = $dbItem['templateid']; $processSecondLevel = true; } } } if ($processSecondLevel) { fillItemsWithChildTemplates($items); // attention recursion! } }