function display_hosts() { if ($_REQUEST['filter'] != '') { $sql_where = "WHERE hostname LIKE '%" . $_REQUEST['filter'] . "%' OR description LIKE '%" . $_REQUEST['filter'] . "%'"; } else { $sql_where = ''; } $hosts = db_fetch_assoc("SELECT h.id, CONCAT_WS('', \n\t\th.description, ' (', h.hostname, ')') AS host, \n\t\tht.name AS template_name \n\t\tFROM host AS h \n\t\tLEFT JOIN host_template AS ht \n\t\tON ht.id=h.host_template_id \n\t\t{$sql_where} \n\t\tORDER BY description \n\t\tLIMIT 20"); if (sizeof($hosts)) { foreach ($hosts as $h) { if (is_device_allowed($h['id'])) { echo "<ul><li id='thost:" . $h['id'] . "' data-jstree='{ \"type\" : \"device\"}'>" . $h['host'] . "</li></ul>\n"; } } } }
function get_allowed_tree_content($tree_id, $parent = 0, $sql_where = '', $order_by = '', $limit = '', &$total_rows = 0, $user = 0) { if ($limit != '') { $limit = "LIMIT {$limit}"; } if ($order_by != '') { $order_by = "ORDER BY {$order_by}"; } if ($sql_where != '') { $sql_where = "WHERE gti.local_graph_id = 0 AND gti.parent = {$parent} AND gti.graph_tree_id = {$tree_id} AND (" . $sql_where . ')'; } else { $sql_where = "WHERE gti.local_graph_id = 0 AND gti.parent = {$parent} AND gti.graph_tree_id = {$tree_id}"; } if ($tree_id > 0) { $heirarchy = db_fetch_assoc("SELECT gti.graph_tree_id AS tree_id, gti.id, gti.title, gti.host_id, \n\t\t\tgti.local_graph_id, gti.host_grouping_type, h.description AS hostname\n\t\t\tFROM graph_tree_items AS gti\n\t\t\tINNER JOIN graph_tree AS gt\n\t\t\tON gt.id = gti.graph_tree_id\n\t\t\tLEFT JOIN host AS h\n\t\t\tON h.id = gti.host_id\n\t\t\t{$sql_where}\n\t\t\tORDER BY gti.position"); } else { $heirarchy = db_fetch_assoc("SELECT gt.id AS tree_id, '0' AS id, gt.name AS title, '0' AS host_id, \n\t\t\t'0' AS local_graph_id, '1' AS host_grouping_type, '' AS hostname\n\t\t\tFROM graph_tree AS gt\n\t\t\tORDER BY gt.name"); } if (read_config_option('auth_method') != 0) { $new_heirarchy = array(); if (sizeof($heirarchy)) { foreach ($heirarchy as $h) { if ($h['host_id'] > 0) { if (is_device_allowed($h['host_id'])) { $new_heirarchy[] = $h; } } elseif ($h['id'] == 0) { if (is_tree_allowed($h['tree_id'])) { $new_heirarchy[] = $h; } } else { $new_heirarchy[] = $h; } } } return $new_heirarchy; } else { return $heirarchy; } }
function get_tree_graphs($tree_id, $leaf_id) { if (is_tree_allowed($tree_id)) { if ($leaf_id == -2) { $sql_leaf = 'parent=0 AND'; } elseif ($leaf_id > 0) { $sql_leaf = 'parent=' . $leaf_id . ' AND'; } else { $sql_leaf = ''; } $items = db_fetch_assoc('SELECT * FROM graph_tree_items AS gti WHERE ' . $sql_leaf . ' graph_tree_id=' . $tree_id); $graphs = array(); $hosts = array(); $outArray = array(); if (sizeof($items)) { foreach ($items as $i) { if (empty($i['title']) && $i['local_graph_id'] > 0) { $graphs[$i['local_graph_id']] = $i['local_graph_id']; } elseif ($i['host_id'] > 0 && is_device_allowed($i['host_id'])) { $hosts[$i['host_id']] = $i['host_id']; } elseif ($leaf_id > -2) { $outArray += get_tree_graphs($tree_id, $i['id']); } } } if (sizeof($hosts) && sizeof($graphs)) { $graphs = get_allowed_graphs('(h.id IN(' . implode(',', $hosts) . ') OR gl.id IN(' . implode(',', $graphs) . '))'); } elseif (sizeof($hosts)) { $graphs = get_allowed_graphs('(h.id IN(' . implode(',', $hosts) . '))'); } elseif (sizeof($graphs)) { $graphs = get_allowed_graphs('(gl.id IN(' . implode(',', $graphs) . '))'); } } if (sizeof($graphs)) { foreach ($graphs as $i) { $outArray[$i['local_graph_id']] = $i['title_cache']; } } return $outArray; }