\n";
print "[root] \n";
if (sizeof($tree) > 0) {
foreach ($tree as $leaf) {
$tier = tree_tier($leaf['order_key']);
$indent = str_repeat('---', ($tier));
if ($selected_tree_item_id == $leaf['id']) {
$html_selected = ' selected';
}else{
$html_selected = '';
}
print "$indent " . $leaf['title'] . " \n";
}
}
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;
$hierarchy = get_allowed_tree_content($tree_id, true, true);
if (sizeof($hierarchy) > 0) {
$i++;
$dhtml_tree[$i] = "\t\t\t
\n";
$last_tier = 1;
$openli = false;
$lasthost = false;
foreach ($hierarchy as $leaf) {
$tier = tree_tier($leaf['order_key']);
if ($leaf['host_id'] > 0) { //It's a host
if ($tier > $last_tier) {
$i++;
$dhtml_tree[$i] = "\t\t\t\n";
} elseif ($tier < $last_tier) {
if (!$lasthost) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\n";
}
for ($x = $tier; $x < $last_tier; $x++) {
$i++;
$dhtml_tree[$i] = "\t\t\t \n\t\t\t\t\n";
$openli = false;
}
} elseif ($openli && !$lasthost) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\n";
$openli = false;
}
$last_tier = $tier;
$lasthost = true;
$i++;
$dhtml_tree[$i] = "\t\t\t\tHost: " . htmlspecialchars($leaf['hostname']) . "\n";
$i++;
$dhtml_tree[$i] = "\t\t\t\t \n";
}elseif ($leaf['local_graph_id'] > 0) {
if ($tier > $last_tier) {
$i++;
$dhtml_tree[$i] = "\t\t\t\n";
} elseif ($tier < $last_tier) {
if (!$lasthost) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\n";
}
for ($x = $tier; $x < $last_tier; $x++) {
$i++;
$dhtml_tree[$i] = "\t\t\t \n\t\t\t\t\n";
$openli = false;
}
} elseif ($openli && !$lasthost) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\n";
$openli = false;
}
$last_tier = $tier;
$lasthost = true;
$i++;
$dhtml_tree[$i] = "\t\t\t\tGraph: " . htmlspecialchars(get_graph_title($leaf['local_graph_id'])) . "\n";
$i++;
$dhtml_tree[$i] = "\t\t\t\t \n";
}else{ //It's not a host
if ($tier > $last_tier) {
$i++;
$dhtml_tree[$i] = "\t\t\t\n";
} elseif ($tier < $last_tier) {
if (!$lasthost) {
$i++;
$dhtml_tree[$i] = "\n";
}
for ($x = $tier; $x < $last_tier; $x++) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t \n\t\t\t\t\n";
$openli = false;
}
} elseif ($openli && !$lasthost) {
$i++;
$dhtml_tree[$i] = "\n";
$openli = false;
}
$last_tier = $tier;
$i++;
$dhtml_tree[$i] = "\t\t\t\t" . htmlspecialchars($leaf['title']) . "\n";
$openli = true;
$lasthost = false;
}
}
for ($x = $last_tier; $x > 1; $x--) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\t \n\t\t\t\t\n";
}
$i++;
$dhtml_tree[$i] = "\t\t\t\n";
}
$i++;
$dhtml_tree[$i] = "\n";
return $dhtml_tree;
}
function create_dhtml_tree() {
global $config;
/* Record Start Time */
list($micro,$seconds) = explode(' ', microtime());
$start = $seconds + $micro;
$dhtml_tree = array();
$dhtml_tree[0] = $start;
$dhtml_tree[1] = read_graph_config_option('expand_hosts');
$dhtml_tree[2] = "\n\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\t\t' . htmlspecialchars($tree['name']) . " \n";
if (sizeof($hierarchy) > 0) {
$i++;
$dhtml_tree[$i] = "\t\t\t\n";
$last_tier = 1;
$openli = false;
$lasthost = false;
foreach ($hierarchy as $leaf) {
$tier = tree_tier($leaf['order_key']);
if ($leaf['host_id'] > 0) { //It's a host
if ($tier > $last_tier) {
$i++;
$dhtml_tree[$i] = "\t\t\t\n";
} elseif ($tier < $last_tier) {
if (!$lasthost) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t \n";
}
for ($x = $tier; $x < $last_tier; $x++) {
$i++;
$dhtml_tree[$i] = "\t\t\t \n\t\t\t\t\n";
$openli = false;
}
} elseif ($openli && !$lasthost) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\n";
$openli = false;
}
$last_tier = $tier;
$lasthost = true;
$i++;
$dhtml_tree[$i] = "\t\t\t\t
Host: ' . htmlspecialchars($leaf['hostname']) . " \n";
if (read_graph_config_option('expand_hosts') == 'on') {
$i++;
$dhtml_tree[$i] = "\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) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\t\t' . htmlspecialchars($graph_template['name']) . " \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');
}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' . htmlspecialchars($data_query['name']) . " \n";
}else{
$dhtml_tree[$i] = "\t\t\t\t\t\t' . htmlspecialchars($data_query['name']) . " \n";
}
if ($data_query['id'] > 0) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\t\t\t\n";
$i++;
$dhtml_tree[$i] = "\t\t\t\t\t\t \n";
}
}
}
$i++;
$dhtml_tree[$i] = "\t\t\t\t\t\t \n";
}
$i++;
$dhtml_tree[$i] = "\t\t\t\t\t\n";
}
$i++;
$dhtml_tree[$i] = "\t\t\t\t\n";
}else{ //It's not a host
if ($tier > $last_tier) {
$i++;
$dhtml_tree[$i] = "\t\t\t
\n";
} elseif ($tier < $last_tier) {
if (!$lasthost) {
$i++;
$dhtml_tree[$i] = "\n";
}
for ($x = $tier; $x < $last_tier; $x++) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t \n\t\t\t\t\n";
$openli = false;
}
} elseif ($openli && !$lasthost) {
$i++;
$dhtml_tree[$i] = "\n";
$openli = false;
}
$last_tier = $tier;
$i++;
$dhtml_tree[$i] = "\t\t\t\t
' . htmlspecialchars($leaf['title']) . " \n";
$openli = true;
$lasthost = false;
}
}
for ($x = $last_tier; $x > 1; $x--) {
$i++;
$dhtml_tree[$i] = "\t\t\t\t\t\n\t\t\t\t\n";
}
$i++;
$dhtml_tree[$i] = "\t\t\t\n";
}
$i++;
$dhtml_tree[$i] = "\t\t\n\t\n";
}
}
$i++;
$dhtml_tree[$i] = "
\n";
return $dhtml_tree;
}
function validate_tree_vars() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request('graphs'));
input_validate_input_number(get_request_var_request('columns'));
input_validate_input_number(get_request_var_request('page'));
input_validate_input_number(get_request_var_request('tree_id'));
input_validate_input_number(get_request_var_request('leaf_id'));
/* ==================================================== */
/* clean up search string */
if (isset($_REQUEST['filter'])) {
$_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
}
/* clean up search string */
if (isset($_REQUEST['thumbnails'])) {
$_REQUEST['thumbnails'] = sanitize_search_string(get_request_var_request('thumbnails'));
}
/* clean up host_group_data string */
if (isset($_REQUEST['host_group_data'])) {
$_REQUEST['host_group_data'] = sanitize_search_string(get_request_var_request('host_group_data'));
}
/* if the user pushed the 'clear' button */
if (isset($_REQUEST['clear_x'])) {
kill_session_var('sess_graph_tree_graphs');
kill_session_var('sess_graph_tree_columns');
kill_session_var('sess_graph_tree_filter');
kill_session_var('sess_graph_tree_thumbnails');
kill_session_var('sess_graph_tree_page');
unset($_REQUEST['graphs']);
unset($_REQUEST['columns']);
unset($_REQUEST['filter']);
unset($_REQUEST['page']);
unset($_REQUEST['thumbnails']);
$changed = true;
}else{
/* if any of the settings changed, reset the page number */
$changed = 0;
$changed += check_changed('graphs', 'sess_graph_tree_graphs');
$changed += check_changed('columns', 'sess_graph_tree_columns');
$changed += check_changed('filter', 'sess_graph_tree_filter');
}
if ($changed) {
$_REQUEST['page'] = 1;
}
load_current_session_value('page', 'sess_graph_tree_page', '1');
load_current_session_value('graphs', 'sess_graph_tree_graphs', '-1');
load_current_session_value('columns', 'sess_graph_tree_columns', read_graph_config_option('num_columns'));
load_current_session_value('filter', 'sess_graph_tree_filter', '');
load_current_session_value('thumbnails', 'sess_graph_tree_thumbnails', read_graph_config_option('thumbnail_section_tree_2') == 'on' ? 'true':'false');
load_current_session_value('leaf_id', 'sess_graph_tree_leaf_id', '');
load_current_session_value('tree_id', 'sess_graph_tree_tree_id', read_graph_config_option('default_tree_id'));
load_current_session_value('host_group_data', 'sess_graph_tree_host_group_data', '');
}
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'] . '/tree.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 = '';
$search_key = '';
$leaf = db_fetch_row("SELECT order_key, title, host_id, host_grouping_type
FROM graph_tree_items
WHERE id=$leaf_id");
$leaf_type = get_tree_item_type($leaf_id);
/* get the "starting leaf" if the user clicked on a specific branch */
if (!empty($leaf_id)) {
$search_key = substr($leaf['order_key'], 0, (tree_tier($leaf['order_key']) * CHARS_PER_TIER));
}
/* get information for the headers */
if (!empty($tree_id)) { $tree_name = db_fetch_cell("SELECT name FROM graph_tree WHERE id=$tree_id"); }
if (!empty($leaf_id)) { $leaf_name = $leaf['title']; }
if (!empty($leaf_id)) { $host_name = db_fetch_cell("SELECT host.description FROM (graph_tree_items,host) WHERE graph_tree_items.host_id=host.id AND graph_tree_items.id=$leaf_id"); }
$host_group_data_array = explode(':', $host_group_data);
if ($host_group_data_array[0] == 'graph_template') {
$host_group_data_name = 'Graph Template: ' . db_fetch_cell('select name from graph_templates where id=' . $host_group_data_array[1]);
$graph_template_id = $host_group_data_array[1];
}elseif ($host_group_data_array[0] == 'data_query') {
$host_group_data_name = 'Graph Template: ' . (empty($host_group_data_array[1]) ? 'Non Query Based' : db_fetch_cell('select name from snmp_query where id=' . $host_group_data_array[1]));
$data_query_id = $host_group_data_array[1];
}elseif ($host_group_data_array[0] == 'data_query_index') {
$host_group_data_name = 'Graph Template: ' . (empty($host_group_data_array[1]) ? 'Non Query Based' : db_fetch_cell('select name from snmp_query where id=' . $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); $title_delimeter = '-> '; }
if (!empty($leaf_name)) { $title .= $title_delimeter . 'Leaf: ' . htmlspecialchars($leaf_name); $title_delimeter = '-> '; }
if (!empty($host_name)) { $title .= $title_delimeter . 'Host: ' . htmlspecialchars($host_name); $title_delimeter = '-> '; }
if (!empty($host_group_data_name)) { $title .= $title_delimeter . " $host_group_data_name"; $title_delimeter = '-> '; }
validate_tree_vars($tree_id, $leaf_id, $host_group_data);
html_start_box('Graph Filters ' . (strlen(get_request_var_request('filter')) ? " [ Filter '" . htmlspecialchars(get_request_var_request('filter')) . "' Applied ]" : ''), '100%', "", '3', 'center', '');
/* include time span selector */
if (read_graph_config_option('timespan_sel') == 'on') {
?>
$tree_id,
'leafid' => $leaf_id,
'mode' => 'tree',
'timespan' => $_SESSION['sess_current_timespan'],
'starttime' => get_current_graph_start(),
'endtime' => get_current_graph_end()
)
);
html_start_box('', '100%', "", '3', 'center', '');
$graph_list = array();
/* if the number of rows is -1, set it to the default */
if ($_REQUEST['graphs'] == -1) {
$_REQUEST['graphs'] = read_graph_config_option('treeview_graphs_per_page');
}
if (($leaf_type == 'header') || (empty($leaf_id))) {
$sql_where = '';
if (strlen(get_request_var_request('filter'))) {
$sql_where = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%' OR gtg.title LIKE '%" . get_request_var_request('filter') . "%')";
}
$graph_list = get_allowed_tree_header_graphs($tree_id, $search_key, $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 gt.id=' . $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) > 0) {
foreach ($graph_templates as $graph_template) {
$sql_where = '';
if (strlen(get_request_var_request('filter'))) {
$sql_where = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%')";
}
$sql_where .= (strlen($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) > 0) {
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 (strlen(get_request_var_request('filter'))) {
$sql_where = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%')";
}
/* grab a list of all graphs for this host/data query combination */
$sql_where .= (strlen($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 */
while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
/* render each graph for the current data query index */
if (isset($snmp_index_to_graph[$snmp_index])) {
while (list($local_graph_id, $graph_title) = each($snmp_index_to_graph[$snmp_index])) {
/* 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&nodeid=" . get_request_var_request('nodeid') . '&host_group_data=' . get_request_var_request('host_group_data'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('graphs'), $total_rows, 5, 'Graphs', 'page', 'main');
print $nav;
/* start graph display */
print "";
$i = get_request_var_request('graphs') * (get_request_var_request('page') - 1);
$last_graph = $i + get_request_var_request('graphs');
$new_graph_list = array();
while ($i < $total_rows && $i < $last_graph) {
$new_graph_list[] = $graph_list[$i];
$i++;
}
if ($_REQUEST['thumbnails'] == 'true') {
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_request('columns'));
}else{
html_graph_area($new_graph_list, '', 'view_type=tree&graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', 1);
}
if (!empty($leaf_id)) {
api_plugin_hook_function('tree_after',$host_name.','.get_request_var_request('leaf_id'));
}
api_plugin_hook_function('tree_view_page_end');
if ($total_rows > 0) {
print $nav;
}
html_end_box();
}
function draw_tree_header_row($tree_id, $tree_item_id, $current_tier, $current_title, $use_expand_contract, $expand_contract_status, $show_url) {
/* start the nested table for the heading */
print "\n";
/* draw one vbar for each tier */
for ($j=0;($j<($current_tier-1));$j++) {
print " \n";
}
/* draw the '+' or '-' icons if configured to do so */
if (($use_expand_contract) && (!empty($current_title))) {
if ($expand_contract_status == '1') {
$other_status = '0';
$ec_icon = 'show';
}else{
$other_status = '1';
$ec_icon = 'hide';
}
print "
\n";
}elseif (!($use_expand_contract) && (!empty($current_title))) {
print " \n";
}
/* draw the actual cell containing the header */
if (!empty($current_title)) {
print "
" . (($show_url == true) ? "" : '') . $current_title . (($show_url == true) ? ' ' : '') . " \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";
}
}
}else{
if (read_graph_config_option('timespan_sel') == 'on') {
print " ";
print " \n";
}else{
print " ";
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']);
}
?>