';
}
}
function set_tree_visibility_status() {
if (!isset($_REQUEST['subaction'])) {
$headers = db_fetch_assoc("SELECT graph_tree_id, order_key
FROM graph_tree_items
WHERE host_id='0'
AND local_graph_id='0'
AND graph_tree_id='" . get_request_var_request('id') . "'");
foreach ($headers as $header) {
$variable = 'sess_tree_leaf_expand_' . $header['graph_tree_id'] . '_' . tree_tier_string($header['order_key']);
if (!isset($_SESSION[$variable])) {
$_SESSION[$variable] = true;
}
}
}else if ((get_request_var_request('subaction') == 'expand_all') ||
(get_request_var_request('subaction') == 'collapse_all')) {
$headers = db_fetch_assoc("SELECT graph_tree_id, order_key
FROM graph_tree_items
WHERE host_id='0'
AND local_graph_id='0'
AND graph_tree_id='" . get_request_var_request('id') . "'");
foreach ($headers as $header) {
$variable = 'sess_tree_leaf_expand_' . $header['graph_tree_id'] . '_' . tree_tier_string($header['order_key']);
if (get_request_var_request('subaction') == 'expand_all') {
$_SESSION[$variable] = true;
}else{
$_SESSION[$variable] = false;
}
}
}else{
$order_key = db_fetch_cell('SELECT order_key FROM graph_tree_items WHERE id=' . get_request_var_request('leaf_id'));
$variable = 'sess_tree_leaf_expand_' . get_request_var_request('id') . '_' . tree_tier_string($order_key);
if (isset($_SESSION[$variable])) {
if ($_SESSION[$variable]) {
$_SESSION[$variable] = false;
}else{
$_SESSION[$variable] = true;
}
}else{
$_SESSION[$variable] = true;
}
}
}
function get_visibility($leaf) {
$tier = tree_tier($leaf['order_key']);
$tier_string = tree_tier_string($leaf['order_key']);
$variable = 'sess_tree_leaf_expand_' . $leaf['graph_tree_id'] . '_' . $tier_string;
/* you must always show the base tier */
if ($tier <= 1) {
return true;
}
/* get the default status */
$default = true;
if (isset($_SESSION[$variable])) {
$default = $_SESSION[$variable];
}
/* now work backwards to get the current visibility stauts */
$i = $tier;
$effective = $default;
while ($i > 1) {
$i--;
$parent_tier = tree_tier_string(substr($tier_string, 0, $i * CHARS_PER_TIER));
$parent_variable = 'sess_tree_leaf_expand_' . $leaf['graph_tree_id'] . '_' . $parent_tier;
$effective = @$_SESSION[$parent_variable];
if (!$effective) {
return $effective;
}
}
return $effective;
}
function get_icon($graph_tree_id, $order_key) {
$variable = 'sess_tree_leaf_expand_' . $graph_tree_id . '_' . tree_tier_string($order_key);
if (isset($_SESSION[$variable])) {
if ($_SESSION[$variable]) {
$icon = 'images/hide.gif';
}else{
$icon = 'images/show.gif';
}
}else{
$icon = 'images/hide.gif';
}
return $icon;
}
/* tree_tier_string - returns the tier key information to be used to determine
visibility status of the tree item.
@arg $order_key - the order key of the branch to fetch the depth for
@arg $chars_per_tier - the number of characters dedicated to each branch
depth (tier). this is typically '3' in cacti.
@returns - the string representing the leaf position
*/
function tree_tier_string($order_key, $chars_per_tier = CHARS_PER_TIER) {
$new_string = preg_replace("/0+$/",'',$order_key);
return $new_string;
}
function grow_dropdown_tree($tree_id, $form_name, $selected_tree_item_id) {
global $config;
include_once($config['library_path'] . '/tree.php');
$tree = db_fetch_assoc("SELECT gti.id, gti.title, gti.order_key
FROM graph_tree_items AS gti
WHERE gti.graph_tree_id=$tree_id
AND gti.title != ''
ORDER BY gti.order_key");
print "\n";
}
function grow_dhtml_trees() {
global $config;
include_once($config['library_path'] . '/tree.php');
include_once($config['library_path'] . '/data_query.php');
$default_tree_id = read_graph_config_option('default_tree_id');
if (empty($default_tree_id)) {
$user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']);
if ($user['policy_trees'] == 1) {
$default_tree_id = db_fetch_cell("SELECT id
FROM graph_tree
WHERE id NOT IN (SELECT item_id FROM user_auth_perms WHERE type=2 AND user_id=" . $_SESSION['sess_user_id'] . ")
ORDER BY id LIMIT 1");
}else{
$default_tree_id = db_fetch_cell("SELECT id
FROM graph_tree
WHERE id IN (SELECT item_id FROM user_auth_perms WHERE type=2 AND user_id=" . $_SESSION['sess_user_id'] . ")
ORDER BY id LIMIT 1");
}
}
$dhtml_tree = create_dhtml_tree();
$total_tree_items = sizeof($dhtml_tree) - 1;
for ($i = 2; $i <= $total_tree_items; $i++) {
print $dhtml_tree[$i];
}
?>
\n";
$i = 2;
$tree_list = get_graph_tree_array();
if (sizeof($tree_list)) {
foreach ($tree_list as $tree) {
$hierarchy = get_allowed_tree_content($tree['id']);
$i++;
$dhtml_tree[$i] = "\t
\n";
}
}
}else if ($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
AND gl.host_id=" . $leaf['host_id'] . "
GROUP BY sq.id
ORDER BY sq.name");
array_push($data_queries, array(
'id' => '0',
'name' => 'Non Query Based'
));
foreach ($data_queries as $data_query) {
/* 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) {
//$non_template_graphs = get_allowed_graphs('gl.host_id=' . $leaf['host_id'] . ' AND gl.snmp_query_id=0');
$non_template_graphs = db_fetch_cell("SELECT COUNT(*) FROM graph_local WHERE host_id='" . $leaf['host_id'] . "' AND snmp_query_id='0'");
}else{
$non_template_graphs = 0;
}
if ((($data_query['id'] == 0) && (sizeof($non_template_graphs))) ||
(($data_query['id'] > 0) && (sizeof($sort_field_data) > 0))) {
$i++;
if ($data_query['name'] != 'Non Query Based') {
$dhtml_tree[$i] = "\t\t\t\t\t\t
\n";
}
/* end the nested table for the heading */
print "
\n";
}
function draw_tree_graph_row($already_open, $graph_counter, $next_leaf_type, $current_tier, $local_graph_id, $rra_id, $graph_title) {
/* start the nested table for the graph group */
if ($already_open == false) {
print "
\n";
/* draw one vbar for each tier */
for ($j=0;($j<($current_tier-1));$j++) {
print "
\n";
}
print "
\n";
$already_open = true;
}
/* print out the actual graph html */
if (read_graph_config_option('thumbnail_section_tree_1') == 'on') {
if (read_graph_config_option('timespan_sel') == 'on') {
print "
\n";
/* if we are at the end of a row, start a new one */
if ($graph_counter % read_graph_config_option('num_columns') == 0) {
print "
\n";
}
}else{
print "
\n";
/* if we are at the end of a row, start a new one */
if ($graph_counter % read_graph_config_option('num_columns') == 0) {
print "
\n";
}
}
/* if we are at the end of the graph group, end the nested table */
if ($next_leaf_type != 'graph') {
print '
';
print "
\n";
$already_open = false;
}
return $already_open;
}
function draw_tree_dropdown($current_tree_id) {
$html = '';
$tree_list = get_graph_tree_array();
input_validate_input_number(get_request_var_request('tree_id'));
if (isset($_REQUEST['tree_id'])) {
$_SESSION['sess_view_tree_id'] = $current_tree_id;
}
/* if there is a current tree, make sure it still exists before going on */
if ((!empty($_SESSION['sess_view_tree_id'])) && (db_fetch_cell('select id from graph_tree where id=' . $_SESSION['sess_view_tree_id']) == '')) {
$_SESSION['sess_view_tree_id'] = 0;
}
/* set a default tree if none is already selected */
if (empty($_SESSION['sess_view_tree_id'])) {
if (db_fetch_cell('select id from graph_tree where id=' . read_graph_config_option('default_tree_id')) > 0) {
$_SESSION['sess_view_tree_id'] = read_graph_config_option('default_tree_id');
}else{
if (sizeof($tree_list) > 0) {
$_SESSION['sess_view_tree_id'] = $tree_list[0]['id'];
}
}
}
/* make the dropdown list of trees */
if (sizeof($tree_list) > 1) {
$html ="\n";
}elseif (sizeof($tree_list) == 1) {
/* there is only one tree; use it */
}
return $html;
}
function naturally_sort_graphs($a, $b) {
return strnatcasecmp($a['title_cache'], $b['title_cache']);
}
?>