\n";
print "\n";
}
if (sizeof($branches)) {
foreach ($branches as $leaf) {
if ($leaf['parent'] == 0) {
$tier = 1;
}
$indent = str_repeat('-', $tier);
if ($selected_tree_item_id == $leaf['id']) {
$html_selected = ' selected';
} else {
$html_selected = '';
}
print "\n";
grow_dropdown_tree($tree_id, $leaf['id'], $form_name, $selected_tree_item_id, $tier);
}
}
if ($parent == 0) {
print "\n";
}
}
function grow_dhtml_trees() {
global $config;
include_once($config['library_path'] . '/data_query.php');
html_validate_tree_vars();
$default_tree_id = read_user_setting('default_tree_id');
if (empty($default_tree_id)) {
if (read_config_option('auth_method') != 0) {
$user = db_fetch_row_prepared('SELECT policy_trees
FROM user_auth
WHERE id = ?',
array($_SESSION['sess_user_id']));
if ($user['policy_trees'] == 1) {
$default_tree_id = db_fetch_cell_prepared('SELECT graph_tree.id
FROM graph_tree
LEFT JOIN user_auth_perms ON user_auth_perms.item_id = graph_tree.id
AND user_auth_perms.type = 2
AND user_auth_perms.user_id = ?
WHERE user_auth_perms.item_id IS NULL
AND graph_tree.enabled = "on"
ORDER BY graph_tree.id
LIMIT 1',
array($_SESSION['sess_user_id']));
} else {
$default_tree_id = db_fetch_cell('SELECT graph_tree.id
FROM graph_tree
INNER JOIN user_auth_perms ON user_auth_perms.item_id = graph_tree.id
AND user_auth_perms.type = 2
AND user_auth_perms.user_id = ?
WHERE graph_tree.enabled = "on"
ORDER BY graph_tree.id
LIMIT 1',
array($_SESSION['sess_user_id']));
}
}
} else {
$default_tree_id = db_fetch_cell('SELECT id FROM graph_tree ORDER BY sequence LIMIT 1');
}
print "
" . __('Search') . "
\n";
$dhtml_tree = create_dhtml_tree();
if (sizeof($dhtml_tree)) {
print "\n";
}
?>
0) {
$rnodes[] = 'tbranch-' . $linknode['parent'];
$linknode = db_fetch_row_prepared('SELECT *
FROM graph_tree_items
WHERE id = ?',
array($linknode['parent']));
} else {
break;
}
}
$rnodes = array_reverse($rnodes);
$nodes = array_merge($nodes, $rnodes);
}
} elseif (strpos(get_request_var('node'), 'tree_anchor') !== false) {
$parts = explode('-', get_request_var('node'));
$nodes[] = 'tree_anchor-' . $parts[1] . '_anchor';
}
return $nodes;
} else {
return array();
}
}
function draw_dhtml_tree_level($tree_id, $parent = 0, $editing = false) {
$dhtml_tree = array();
$heirarchy = get_allowed_tree_level($tree_id, $parent, $editing);
if (sizeof($heirarchy)) {
$dhtml_tree[] = "\t\t\t\n";
foreach ($heirarchy as $leaf) {
if ($leaf['host_id'] > 0) { //It's a host
$dhtml_tree[] = "\t\t\t\t- " . htmlspecialchars($leaf['hostname']) . "
\n";
} elseif ($leaf['local_graph_id'] > 0) {
$dhtml_tree[] = "\t\t\t\t- " . htmlspecialchars(get_graph_title($leaf['local_graph_id'])) . "
\n";
} else { //It's not a host
$dhtml_tree[] = "\t\t\t\t- " . htmlspecialchars($leaf['title']) . "
\n";
}
}
$dhtml_tree[] = "\t\t\t
\n";
}
return $dhtml_tree;
}
function draw_dhtml_tree_level_graphing($tree_id, $parent = 0) {
global $config;
include_once($config['base_path'] . '/lib/data_query.php');
$heirarchy = get_allowed_tree_content($tree_id, $parent);
$dhtml_tree = array();
if (sizeof($heirarchy)) {
if ($tree_id > 0) {
$dhtml_tree[] = "\t\t\t\n";
foreach ($heirarchy as $leaf) {
if ($leaf['host_id'] > 0) { //It's a host
$dhtml_tree[] = "\t\t\t\t- ' . htmlspecialchars($leaf['hostname']) . "\n";
if (read_user_setting('expand_hosts') == 'on') {
$dhtml_tree[] = "\t\t\t\t\t
\n";
if ($leaf['host_grouping_type'] == HOST_GROUPING_GRAPH_TEMPLATE) {
$graph_templates = get_allowed_graph_templates('gl.host_id=' . $leaf['host_id']);
if (sizeof($graph_templates) > 0) {
foreach ($graph_templates as $graph_template) {
$dhtml_tree[] = "\t\t\t\t\t\t- " . htmlspecialchars($graph_template['name']) . "
\n";
}
}
} elseif ($leaf['host_grouping_type'] == HOST_GROUPING_DATA_QUERY_INDEX) {
$data_queries = db_fetch_assoc_prepared('SELECT sq.id, sq.name
FROM graph_local AS gl
INNER JOIN snmp_query AS sq
ON gl.snmp_query_id=sq.id
AND gl.host_id = ?
GROUP BY sq.id
ORDER BY sq.name', array($leaf['host_id']));
array_push($data_queries, array(
'id' => '0',
'name' => 'Non Query Based'
));
if (sizeof($data_queries)) {
$ntg = get_allowed_graphs('gl.host_id=' . $leaf['host_id'] . ' AND gl.snmp_query_id=0');
foreach ($data_queries as $data_query) {
if ($data_query['id'] == 0) {
$non_template_graphs = $ntg;
$sort_field_data = array();
} else {
$non_template_graphs = array();
/* fetch a list of field names that are sorted by the preferred sort field */
$sort_field_data = get_formatted_data_query_indexes($leaf['host_id'], $data_query['id']);
}
if (($data_query['id'] == 0 && sizeof($non_template_graphs)) ||
($data_query['id'] > 0 && sizeof($sort_field_data) > 0)
) {
if ($data_query['name'] != 'Non Query Based') {
$dhtml_tree[] = "\t\t\t\t\t\t- ' . htmlspecialchars($data_query['name']) . "\n";
} else {
$dhtml_tree[] = "\t\t\t\t\t\t
- ' . htmlspecialchars($data_query['name']) . "\n";
}
if ($data_query['id'] > 0) {
$dhtml_tree[] = "\t\t\t\t\t\t\t\n";
$dhtml_tree[] = "\t\t\t\t\t\t
\n";
}
}
}
}
$dhtml_tree[] = "\t\t\t\t\t\t
\n";
}
$dhtml_tree[] = "\t\t\t\t\t
\n";
}
$dhtml_tree[] = "\t\t\t\t\n";
} else { //It's not a host
$children = db_fetch_cell_prepared('SELECT COUNT(*)
FROM graph_tree_items
WHERE parent = ?
AND local_graph_id=0',
array($leaf['id']));
$dhtml_tree[] = "\t\t\t\t 0 ? "class='jstree-closed'":"") . ">' . htmlspecialchars($leaf['title']) . "\n";
}
}
$dhtml_tree[] = "\t\t\t\n";
} else {
$dhtml_tree[] = "\n";
}
}
return $dhtml_tree;
}
function create_dhtml_tree() {
$dhtml_tree = array();
$tree_list = get_allowed_trees();
if (sizeof($tree_list)) {
foreach ($tree_list as $tree) {
$dhtml_tree['tree:'.$tree['id']] = true;
}
}
return $dhtml_tree;
}
function html_validate_tree_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'graphs' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_user_setting('treeview_graphs_per_page')
),
'graph_template_id' => array(
'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST,
'pageset' => true,
'default' => read_user_setting('graph_template_id', '0')
),
'columns' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_user_setting('num_columns_tree')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'predefined_timeshift' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_user_setting('default_timeshift')
),
'predefined_timespan' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_user_setting('default_timespan')
),
'node' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '/([_\-a-z:0-9#]+)/')),
'pageset' => true,
'default' => ''
),
'hgd' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'rfilter' => array(
'filter' => FILTER_VALIDATE_IS_REGEX,
'pageset' => true,
'default' => '',
),
'thumbnails' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => read_user_setting('thumbnail_section_tree_2')
)
);
validate_store_request_vars($filters, 'sess_grt');
/* ================= input validation ================= */
}
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) {
global $current_user, $config, $graphs_per_page, $graph_timeshifts;
include($config['include_path'] . '/global_arrays.php');
include_once($config['library_path'] . '/data_query.php');
include_once($config['library_path'] . '/html_utility.php');
if (empty($tree_id)) { return; }
if (empty($leaf_id)) { $leaf_id = 0; }
$sql_where = '';
$sql_join = '';
$title = '';
$title_delimeter = '';
$leaf = db_fetch_row_prepared('SELECT
title, host_id, host_grouping_type
FROM graph_tree_items
WHERE id = ?',
array($leaf_id));
$leaf_type = api_tree_get_item_type($leaf_id);
/* get information for the headers */
if (!empty($tree_id)) {
$tree_name = db_fetch_cell_prepared('SELECT name
FROM graph_tree
WHERE id = ?',
array($tree_id));
}
if (!empty($leaf_id)) {
$leaf_name = $leaf['title'];
}
if (!empty($leaf_id)) {
$host_name = db_fetch_cell_prepared('SELECT host.description
FROM (graph_tree_items,host)
WHERE graph_tree_items.host_id=host.id
AND graph_tree_items.id = ?',
array($leaf_id));
}
$host_group_data_array = explode(':', $host_group_data);
if ($host_group_data_array[0] == 'gt') {
$host_group_data_name = '' . __('Graph Template:'). ' ' . db_fetch_cell_prepared('SELECT name FROM graph_templates WHERE id = ?', array($host_group_data_array[1]));
$graph_template_id = $host_group_data_array[1];
} elseif ($host_group_data_array[0] == 'dq') {
$host_group_data_name = '' . __('Graph Template:') . ' ' . (empty($host_group_data_array[1]) ? __('Non Query Based') : db_fetch_cell_prepared('SELECT name FROM snmp_query WHERE id = ?', array($host_group_data_array[1])));
$data_query_id = $host_group_data_array[1];
} elseif ($host_group_data_array[0] == 'dqi') {
$host_group_data_name = '' . __('Graph Template:') . ' ' . (empty($host_group_data_array[1]) ? __('Non Query Based') : db_fetch_cell_prepared('SELECT name FROM snmp_query WHERE id = ?', array($host_group_data_array[1]))) . '-> ' . (empty($host_group_data_array[2]) ? 'Template Based' : get_formatted_data_query_index($leaf['host_id'], $host_group_data_array[1], $host_group_data_array[2]));
$data_query_id = $host_group_data_array[1];
$data_query_index = $host_group_data_array[2];
}
if (!empty($tree_name)) { $title .= $title_delimeter . '' . __('Tree:') . ' ' . htmlspecialchars($tree_name, ENT_QUOTES); $title_delimeter = '-> '; }
if (!empty($leaf_name)) { $title .= $title_delimeter . '' . __('Leaf:') . ' ' . htmlspecialchars($leaf_name, ENT_QUOTES); $title_delimeter = '-> '; }
if (!empty($host_name)) { $title .= $title_delimeter . '' . __('Device:') . ' ' . htmlspecialchars($host_name, ENT_QUOTES); $title_delimeter = '-> '; }
if (!empty($host_group_data_name)) { $title .= $title_delimeter . " $host_group_data_name"; $title_delimeter = '-> '; }
html_start_box(__('Graph Filters') . (get_request_var('rfilter') != '' ? " [ " . __('Filter') . " '" . htmlspecialchars(get_request_var('rfilter')) . "' " . __('Applied') . " ]" : ''), '100%', "", '3', 'center', '');
?>
|
|
|
|
$tree_id,
'leafid' => $leaf_id,
'mode' => 'tree',
'timespan' => $_SESSION['sess_current_timespan'],
'starttime' => get_current_graph_start(),
'endtime' => get_current_graph_end()
)
);
$graph_list = array();
if (($leaf_type == 'header') || (empty($leaf_id))) {
$sql_where = '';
if (get_request_var('rfilter') != '') {
$sql_where .= " (gtg.title_cache RLIKE '" . get_request_var('rfilter') . "' OR gtg.title RLIKE '" . get_request_var('rfilter') . "')";
}
if (get_request_var('graph_template_id') != '' && get_request_var('graph_template_id') != '0') {
$sql_where .= ($sql_where != '' ? ' AND ':'') . ' (gl.graph_template_id IN (' . get_request_var('graph_template_id') . '))';
}
$graph_list = get_allowed_tree_header_graphs($tree_id, $leaf_id, $sql_where);
} elseif ($leaf_type == 'host') {
/* graph template grouping */
if ($leaf['host_grouping_type'] == HOST_GROUPING_GRAPH_TEMPLATE) {
$sql_where = 'gl.host_id=' . $leaf['host_id'] . (empty($graph_template_id) ? '' : ' AND gl.graph_template_id=' . $graph_template_id);
if (get_request_var('graph_template_id') != '' && get_request_var('graph_template_id') != '0') {
$sql_where .= ($sql_where != '' ? ' AND ':'') . ' (gl.graph_template_id IN (' . get_request_var('graph_template_id') . '))';
}
$graph_templates = get_allowed_graph_templates($sql_where);
/* for graphs without a template */
array_push(
$graph_templates, array(
'id' => '0',
'name' => __('(No Graph Template)')
)
);
if (sizeof($graph_templates)) {
foreach ($graph_templates as $graph_template) {
$sql_where = '';
if (get_request_var('rfilter') != '') {
$sql_where = " (gtg.title_cache RLIKE '" . get_request_var('rfilter') . "')";
}
$sql_where .= ($sql_where != '' ? 'AND':'') . ' gl.graph_template_id=' . $graph_template['id'] . ' AND gl.host_id=' . $leaf['host_id'];
$graphs = get_allowed_graphs($sql_where);
/* let's sort the graphs naturally */
usort($graphs, 'naturally_sort_graphs');
if (sizeof($graphs)) {
foreach ($graphs as $graph) {
$graph['graph_template_name'] = $graph_template['name'];
array_push($graph_list, $graph);
}
}
}
}
/* data query index grouping */
} elseif ($leaf['host_grouping_type'] == HOST_GROUPING_DATA_QUERY_INDEX) {
$data_queries = db_fetch_assoc("SELECT sq.id, sq.name
FROM graph_local AS gl
INNER JOIN snmp_query AS sq
ON gl.snmp_query_id=sq.id
WHERE gl.host_id=" . $leaf['host_id'] . "
" . (!isset($data_query_id) ? '' : "AND sq.id=$data_query_id") . "
GROUP BY sq.id
ORDER BY sq.name");
/* for graphs without a data query */
if (empty($data_query_id)) {
array_push($data_queries,
array(
'id' => '0',
'name' => 'Non Query Based'
)
);
}
if (sizeof($data_queries)) {
foreach ($data_queries as $data_query) {
$sql_where = '';
/* fetch a list of field names that are sorted by the preferred sort field */
$sort_field_data = get_formatted_data_query_indexes($leaf['host_id'], $data_query['id']);
if (get_request_var('rfilter') != '') {
$sql_where = " (gtg.title_cache RLIKE '" . get_request_var('rfilter') . "')";
}
/* grab a list of all graphs for this host/data query combination */
$sql_where .= ($sql_where != '' ? ' AND ':'') .
' gl.snmp_query_id=' . $data_query['id'] . ' AND gl.host_id=' . $leaf['host_id'] .
' ' . (empty($data_query_index) ? '' : " AND gl.snmp_index='$data_query_index'");
$graphs = get_allowed_graphs($sql_where);
/* re-key the results on data query index */
$snmp_index_to_graph = array();
if (sizeof($graphs) > 0) {
/* let's sort the graphs naturally */
usort($graphs, 'naturally_sort_graphs');
foreach ($graphs as $graph) {
$snmp_index_to_graph[$graph['snmp_index']][$graph['local_graph_id']] = $graph['title_cache'];
$graphs_height[$graph['local_graph_id']] = $graph['height'];
$graphs_width[$graph['local_graph_id']] = $graph['width'];
}
}
/* using the sorted data as they key; grab each snmp index from the master list */
foreach ($sort_field_data as $snmp_index => $sort_field_value) {
/* render each graph for the current data query index */
if (isset($snmp_index_to_graph[$snmp_index])) {
foreach ($snmp_index_to_graph[$snmp_index] as $local_graph_id => $graph_title) {
/* reformat the array so it's compatable with the html_graph* area functions */
array_push($graph_list, array('data_query_name' => $data_query['name'], 'sort_field_value' => $sort_field_value, 'local_graph_id' => $local_graph_id, 'title_cache' => $graph_title, 'height' => $graphs_height[$graph['local_graph_id']], 'width' => $graphs_width[$graph['local_graph_id']]));
}
}
}
}
}
}
}
$total_rows = sizeof($graph_list);
/* generate page list */
$nav = html_nav_bar("graph_view.php?action=tree_content&tree_id=$tree_id&leaf_id=$leaf_id&node=" . get_request_var('node') . '&hgd=' . $host_group_data, MAX_DISPLAY_PAGES, get_request_var('page'), get_request_var('graphs'), $total_rows, get_request_var('columns'), __('Graphs'), 'page', 'main');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
/* start graph display */
print "";
$i = get_request_var('graphs') * (get_request_var('page') - 1);
$last_graph = $i + get_request_var('graphs');
$new_graph_list = array();
while ($i < $total_rows && $i < $last_graph) {
$new_graph_list[] = $graph_list[$i];
$i++;
}
if (get_request_var('thumbnails') == 'true' || get_request_var('thumbnails') == 'on') {
html_graph_thumbnail_area($new_graph_list, '', 'view_type=tree&graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
} else {
html_graph_area($new_graph_list, '', 'view_type=tree&graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
}
if (!empty($leaf_id)) {
api_plugin_hook_function('tree_after',$host_name.','.get_request_var('leaf_id'));
}
api_plugin_hook_function('tree_view_page_end');
html_end_box();
if ($total_rows) {
print $nav;
}
}