Exemplo n.º 1
0
     $total_rows = count(db_fetch_assoc('SELECT ' . 'graph_templates_graph.local_graph_id ' . $sql_base));
     $graphs = db_fetch_assoc('SELECT ' . 'graph_templates_graph.local_graph_id, ' . 'graph_templates_graph.height, ' . 'graph_templates_graph.width, ' . 'graph_templates_graph.title_cache ' . $sql_base . ' ' . 'GROUP BY graph_templates_graph.local_graph_id ' . 'ORDER BY graph_templates_graph.title_cache ' . 'limit ' . $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']);
     /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
     if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
         $nav_url = str_replace('&page=' . get_request_var_request('page'), '', get_browser_query_string());
     } else {
         $nav_url = get_browser_query_string() . '&host_id=' . get_request_var_request('host_id');
     }
     $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
     html_start_box('', '100%', "", '3', 'center', '');
     $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("rows"), $total_rows, get_request_var_request('columns'), "Graphs", 'page', 'main');
     print $nav;
     if (get_request_var_request('thumbnails') == 'true') {
         html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
     } else {
         html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
     }
     print $nav;
     html_end_box();
     if (!isset($_REQUEST['header']) || $_REQUEST['header'] == false) {
         include_once './include/bottom_footer.php';
     }
     break;
 case 'list':
     include_once './include/top_graph_header.php';
     if (read_config_option('auth_method') != 0 && empty($current_user['show_list'])) {
         print "<strong><font size='+1' color='FF0000'>YOU DO NOT HAVE RIGHTS FOR LIST VIEW</font></strong>";
         exit;
     }
     /* ================= input validation ================= */
     input_validate_input_number(get_request_var_request('host_id'));
Exemplo n.º 2
0
	/* do some fancy navigation url construction so we don't have to try and rebuild the url string */
	if (ereg("page=[0-9]+",basename($_SERVER["QUERY_STRING"]))) {
		$nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]);
	}else{
		$nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>&host_id=" . $_REQUEST["host_id"];
	}

	$nav_url = ereg_replace("((\?|&)host_id=[0-9]+|(\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url);

	html_graph_start_box(1, true);
	html_nav_bar($colors["header_panel"], read_graph_config_option("num_columns"), $_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);

	if (read_graph_config_option("thumbnail_section_preview") == "on") {
		html_graph_thumbnail_area($graphs, "","graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}else{
		html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}

	html_nav_bar($colors["header_panel"], read_graph_config_option("num_columns"), $_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);

	html_graph_end_box();

	print "<br><br>";

	break;



case 'list':
	define("ROWS_PER_PAGE", read_graph_config_option("list_graphs_per_page"));
Exemplo n.º 3
0
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("SELECT title, host_id, host_grouping_type\n\t\tFROM graph_tree_items\n\t\tWHERE id={$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("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 = '<strong>Graph Template:</strong> ' . 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 = '<strong>Graph Template:</strong> ' . (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 = '<strong>Graph Template:</strong> ' . (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 . '<strong>Tree:</strong>' . htmlspecialchars($tree_name);
        $title_delimeter = '-> ';
    }
    if (!empty($leaf_name)) {
        $title .= $title_delimeter . '<strong>Leaf:</strong>' . htmlspecialchars($leaf_name);
        $title_delimeter = '-> ';
    }
    if (!empty($host_name)) {
        $title .= $title_delimeter . '<strong>Device:</strong>' . 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('<strong>Graph Filters</strong>' . (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') {
        ?>
		<tr class='even noprint'>
			<td class='noprint'>
			<form name='form_timespan_selector' method='post' action='graph_view.php'>
				<table cellpadding='2' cellspacing='0'>
					<tr id='timespan'>
						<td width='50'>
							Presets
						</td>
						<td>
							<select id='predefined_timespan' name='predefined_timespan' onChange='spanTime()'>
								<?php 
        if (isset($_SESSION['custom'])) {
            $graph_timespans[GT_CUSTOM] = 'Custom';
            $start_val = 0;
            $end_val = sizeof($graph_timespans);
        } else {
            if (isset($graph_timespans[GT_CUSTOM])) {
                asort($graph_timespans);
                array_shift($graph_timespans);
            }
            $start_val = 1;
            $end_val = sizeof($graph_timespans) + 1;
        }
        if (sizeof($graph_timespans) > 0) {
            for ($value = $start_val; $value < $end_val; $value++) {
                print "<option value='{$value}'";
                if ($_SESSION['sess_current_timespan'] == $value) {
                    print ' selected';
                }
                print '>' . title_trim($graph_timespans[$value], 40) . "</option>\n";
            }
        }
        ?>
							</select>
						</td>
						<td>
							From
						</td>
						<td>
							<input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='15' value='<?php 
        print isset($_SESSION['sess_current_date1']) ? $_SESSION['sess_current_date1'] : '';
        ?>
'>
						</td>
						<td>
							<input type='image' src='images/calendar.gif' align='middle' alt='Start date selector' title='Start date selector' onclick="return showCalendar('date1');">
						</td>
						<td>
							To
						</td>
						<td>
							<input type='text' name='date2' id='date2' title='Graph End Timestamp' size='15' value='<?php 
        print isset($_SESSION['sess_current_date2']) ? $_SESSION['sess_current_date2'] : '';
        ?>
'>
						</td>
						<td>
							<input type='image' src='images/calendar.gif' align='middle' alt='End date selector' title='End date selector' onclick="return showCalendar('date2');">
						</td>
						<td>
							<img style='padding-bottom:0px;cursor:pointer;' border='0' src='images/move_left.gif' align='middle' alt='' title='Shift Left' onClick='timeshiftFilterLeft()'/>
						</td>
						<td>
							<select id='predefined_timeshift' name='predefined_timeshift' title='Define Shifting Interval'>
								<?php 
        $start_val = 1;
        $end_val = sizeof($graph_timeshifts) + 1;
        if (sizeof($graph_timeshifts) > 0) {
            for ($shift_value = $start_val; $shift_value < $end_val; $shift_value++) {
                print "<option value='{$shift_value}'";
                if ($_SESSION['sess_current_timeshift'] == $shift_value) {
                    print ' selected';
                }
                print '>' . title_trim($graph_timeshifts[$shift_value], 40) . "</option>\n";
            }
        }
        ?>
							</select>
						</td>
						<td>
							<img style='padding-bottom:0px;cursor:pointer;' name='move_right' src='images/move_right.gif' align='middle' alt='' title='Shift Right' onClick='timeshiftFilterRight()'/>
						</td>
						<td>
							<input type='button' name='button_refresh_x' value='Refresh' title='Refresh selected time span' onClick='refreshTimespanFilter()'>
						</td>
						<td>
							<input type='button' name='button_clear_x' value='Clear' title='Return to the default time span' onClick='clearTimespanFilter()'>
						</td>
					</tr>
					<tr id='realtime' style='display:none;'>
						<td width='50'> 
							Window
						</td>
						<td>
							<select name='graph_start' id='graph_start' onChange='self.imageOptionsChanged("timespan")'>
								<?php 
        foreach ($realtime_window as $interval => $text) {
            printf('<option value="%d"%s>%s</option>', $interval, $interval == $_SESSION['sess_realtime_window'] ? ' selected="selected"' : '', $text);
        }
        ?>
							</select>
						</td>
						<td>
							Refresh
						</td>
						<td>
							<select name='ds_step' id='ds_step' onChange="self.imageOptionsChanged('interval')">
								<?php 
        foreach ($realtime_refresh as $interval => $text) {
            printf('<option value="%d"%s>%s</option>', $interval, $interval == $_SESSION['sess_realtime_dsstep'] ? ' selected="selected"' : '', $text);
        }
        ?>
							</select>
						</td>
						<td>
							<input type='button' id='realtimeoff' value='Stop'>
						</td>
						<td align='center' colspan='6'>
							<span id='countdown'></span>
						</td>
					</tr>
				</table>
			</form>
			</td>
		</tr>
		<?php 
    }
    ?>
	<tr class='even noprint' id='search'>
		<td class='noprint'>
		<form name='form_graph_view' method='post' onSubmit='changeFilter();return false'>
			<table cellpadding='2' cellspacing='0'>
				<tr>
					<td width='50'>
						Search
					</td>
					<td>
						<input id='filter' size='30' name='filter' value='<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
'>
					</td>
					<td>
						Graphs
					</td>
					<td>
						<select name='graphs' id='graphs' onChange='changeFilter()'>
							<?php 
    if (sizeof($graphs_per_page) > 0) {
        foreach ($graphs_per_page as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request('graphs') == $key) {
                print ' selected';
            }
            print '>' . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						Columns
					</td>
					<td>
						<select name='columns' id='columns' onChange='changeFilter()' <?php 
    print get_request_var_request('thumbnails') == 'false' ? 'disabled' : '';
    ?>
>
							<?php 
    if (get_request_var_request('thumbnails') == 'false') {
        ?>
							<option value='<?php 
        print get_request_var_request('columns');
        ?>
' selected>N/A</option>
							<?php 
    } else {
        ?>
							<option value='1' <?php 
        print get_request_var_request('columns') == '1' ? ' selected' : '';
        ?>
>1 Column</option>
							<option value='2' <?php 
        print get_request_var_request('columns') == '2' ? ' selected' : '';
        ?>
>2 Columns</option>
							<option value='3' <?php 
        print get_request_var_request('columns') == '3' ? ' selected' : '';
        ?>
>3 Columns</option>
							<option value='4' <?php 
        print get_request_var_request('columns') == '4' ? ' selected' : '';
        ?>
>4 Columns</option>
							<option value='5' <?php 
        print get_request_var_request('columns') == '5' ? ' selected' : '';
        ?>
>5 Columns</option>
							<?php 
    }
    ?>
						</select>
					</td>
					<td>
						<label for='thumbnails'>Thumbnails:</label>
					</td>
					<td>
						<input id='thumbnails' type='checkbox' name='thumbnails' onClick='changeFilter()' <?php 
    print $_REQUEST['thumbnails'] == 'true' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<input type='button' value='Go' title='Set/Refresh Filter' onClick='changeFilter()'>
					</td>
					<td>
						<input type='button' value='Clear' title='Clear Filters' onClick='clearFilter()'>
					</td>
				</tr>
			</table>
		</form>
		</td>
	</tr>
	<script type='text/javascript'>

	$(function() {
		var navBar = "<div id='navBar' class='navBar'><?php 
    print draw_navigation_text();
    ?>
</div>";
		if (navBar != '') {
			$('#navBar').replaceWith(navBar);
		}
		setupBreadcrumbs();
	});

	function changeFilter() {
		$.get('graph_view.php?action=tree_content&tree_id=<?php 
    print $_SESSION['sess_graph_tree_tree_id'];
    ?>
&leaf_id=<?php 
    print $_SESSION['sess_graph_tree_leaf_id'];
    ?>
&host_group_data=<?php 
    print $_SESSION['sess_graph_tree_host_group_data'];
    ?>
&graphs='+$('#graphs').val()+'&filter='+$('#filter').val()+'&thumbnails='+$('#thumbnails').is(':checked')+'&columns='+$('#columns').val()+'&nodeid='+'<?php 
    print $_SESSION['sess_graph_tree_nodeid'];
    ?>
', function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function clearFilter() {
		$.get('graph_view.php?action=tree_content&tree_id=<?php 
    print $_SESSION['sess_graph_tree_tree_id'];
    ?>
&leaf_id=<?php 
    print $_SESSION['sess_graph_tree_leaf_id'];
    ?>
&host_group_data=<?php 
    print $_SESSION['sess_graph_tree_host_group_data'];
    ?>
&clear_x=1&nodeid='+'<?php 
    print $_SESSION['sess_graph_tree_nodeid'];
    ?>
', function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function spanTime() {
		$.get('graph_view.php?action=tree_content&tree_id=<?php 
    print $_SESSION['sess_graph_tree_tree_id'];
    ?>
&leaf_id=<?php 
    print $_SESSION['sess_graph_tree_leaf_id'];
    ?>
&host_group_data=<?php 
    print $_SESSION['sess_graph_tree_host_group_data'];
    ?>
&nodeid='+'<?php 
    print $_SESSION['sess_graph_tree_nodeid'];
    ?>
&predefined_timespan='+$('#predefined_timespan').val()+'&predefined_timeshift='+$('#predefined_timeshift').val(), function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function clearTimespanFilter() {
		var json = { button_clear_x: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() };
		var url  = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_SESSION['sess_graph_tree_tree_id'];
    ?>
&leaf_id=<?php 
    print $_SESSION['sess_graph_tree_leaf_id'];
    ?>
&host_group_data=<?php 
    print $_SESSION['sess_graph_tree_host_group_data'];
    ?>
&nodeid=<?php 
    print $_SESSION['sess_graph_tree_nodeid'];
    ?>
';
		$.post(url, json).done(function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function refreshTimespanFilter() {
		var json = { button_refresh_x: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() };
		var url  = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_SESSION['sess_graph_tree_tree_id'];
    ?>
&leaf_id=<?php 
    print $_SESSION['sess_graph_tree_leaf_id'];
    ?>
&host_group_data=<?php 
    print $_SESSION['sess_graph_tree_host_group_data'];
    ?>
&nodeid=<?php 
    print $_SESSION['sess_graph_tree_nodeid'];
    ?>
';
		$.post(url, json).done(function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function timeshiftFilterLeft() {
		var json = { move_left_x: 1, move_left_y: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() };
		var url  = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_SESSION['sess_graph_tree_tree_id'];
    ?>
&leaf_id=<?php 
    print $_SESSION['sess_graph_tree_leaf_id'];
    ?>
&host_group_data=<?php 
    print $_SESSION['sess_graph_tree_host_group_data'];
    ?>
&nodeid=<?php 
    print $_SESSION['sess_graph_tree_nodeid'];
    ?>
';
		$.post(url, json).done(function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function timeshiftFilterRight() {
		var json = { move_right_x: 1, move_right_y: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() };
		var url  = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_SESSION['sess_graph_tree_tree_id'];
    ?>
&leaf_id=<?php 
    print $_SESSION['sess_graph_tree_leaf_id'];
    ?>
&host_group_data=<?php 
    print $_SESSION['sess_graph_tree_host_group_data'];
    ?>
&nodeid=<?php 
    print $_SESSION['sess_graph_tree_nodeid'];
    ?>
';
		$.post(url, json).done(function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function url_graph(strNavURL) {
		return '';
	}

	</script>
	<?php 
    html_end_box();
    api_plugin_hook_function('graph_tree_page_buttons', array('treeid' => $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, $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 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\n\t\t\t\tFROM graph_local AS gl\n\t\t\t\tINNER JOIN snmp_query AS sq\n\t\t\t\tON gl.snmp_query_id=sq.id\n\t\t\t\tWHERE gl.host_id=" . $leaf['host_id'] . "\n\t\t\t\t" . (!isset($data_query_id) ? '' : "AND sq.id={$data_query_id}") . "\n\t\t\t\tGROUP BY sq.id\n\t\t\t\tORDER 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'] . "\n                                        " . (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 "<tr class='tableHeader'><td width='390' colspan='11' class='graphSubHeaderColumn textHeaderDark'>{$title}</td></tr>";
    $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();
}
Exemplo n.º 4
0
function draw_tree_graph_row($already_open, $graph_counter, $next_leaf_type, $current_tier, $local_graph_id, $rra_id, $graph_title) {
	global $colors;

	/* start the nested table for the graph group */
	if ($already_open == false) {
		print "<tr><td><table width='100%' cellpadding='2' cellspacing='1'><tr>\n";

		/* draw one vbar for each tier */
		for ($j=0;($j<($current_tier-1));$j++) {
			print "<td width='10' bgcolor='#" . $colors["panel"] . "'></td>\n";
		}

		print "<td><table width='100%' cellspacing='0' cellpadding='2'><tr>\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 "<td><a href='graph.php?local_graph_id=$local_graph_id&rra_id=all'><img align='middle' alt='$graph_title'
				src='graph_image.php?local_graph_id=$local_graph_id&rra_id=0&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end() . '&graph_height=' .
				read_graph_config_option("default_height") . '&graph_width=' . read_graph_config_option("default_width") . "&graph_nolegend=true' border='0'></a></td>\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 "</tr><tr>\n";
			}
		}else{
			print "<td><a href='graph.php?local_graph_id=$local_graph_id&rra_id=all'><img align='middle' alt='$graph_title'
				src='graph_image.php?local_graph_id=$local_graph_id&rra_id=$rra_id&graph_start=" . -(db_fetch_cell("select timespan from rra where id=$rra_id")) . '&graph_height=' .
				read_graph_config_option("default_height") . '&graph_width=' . read_graph_config_option("default_width") . "&graph_nolegend=true' border='0'></a></td>\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 "</tr><tr>\n";
			}
		}
	}else{
		if (read_graph_config_option("timespan_sel") == "on") {
			print "<td><a href='graph.php?local_graph_id=$local_graph_id&rra_id=all'><img src='graph_image.php?local_graph_id=$local_graph_id&rra_id=0&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end() . "' border='0' alt='$graph_title'></a></td>";
			print "</tr><tr>\n";
		}else{
			print "<td><a href='graph.php?local_graph_id=$local_graph_id&rra_id=all'><img src='graph_image.php?local_graph_id=$local_graph_id&rra_id=$rra_id' border='0' alt='$graph_title'></a></td>";
			print "</tr><tr>\n";
		}
	}

	/* if we are at the end of the graph group, end the nested table */
	if ($next_leaf_type != "graph") {
		print "</tr></table></td>";
		print "</tr></table></td></tr>\n";

		$already_open = false;
	}

	return $already_open;
}
Exemplo n.º 5
0
function mikrotik_view_graphs()
{
    global $current_user, $colors, $config;
    if (file_exists("./lib/timespan_settings.php")) {
        include "./lib/timespan_settings.php";
    } else {
        include "./include/html/inc_timespan_settings.php";
    }
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("rra_id"));
    input_validate_input_number(get_request_var("host"));
    input_validate_input_number(get_request_var("cols"));
    input_validate_input_regex(get_request_var_request('graph_list'), "^([\\,0-9]+)\$");
    input_validate_input_regex(get_request_var_request('graph_add'), "^([\\,0-9]+)\$");
    input_validate_input_regex(get_request_var_request('graph_remove'), "^([\\,0-9]+)\$");
    /* ==================================================== */
    define("ROWS_PER_PAGE", read_graph_config_option("preview_graphs_per_page"));
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("graph_template_id"));
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
    }
    /* clean up styl string */
    if (isset($_REQUEST["style"])) {
        $_REQUEST["style"] = sanitize_search_string(get_request_var_request("style"));
    }
    /* clean up styl string */
    if (isset($_REQUEST["thumb"])) {
        $_REQUEST["thumb"] = sanitize_search_string(get_request_var_request("thumb"));
    }
    $sql_or = "";
    $sql_where = "";
    $sql_join = "";
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["reset"])) {
        kill_session_var("sess_mikrotik_graph_current_page");
        kill_session_var("sess_mikrotik_graph_filter");
        kill_session_var("sess_mikrotik_graph_host");
        kill_session_var("sess_mikrotik_graph_cols");
        kill_session_var("sess_mikrotik_graph_thumb");
        kill_session_var("sess_mikrotik_graph_add");
        kill_session_var("sess_mikrotik_graph_style");
        kill_session_var("sess_mikrotik_graph_graph_template");
    } elseif (isset($_REQUEST["clear"])) {
        kill_session_var("sess_mikrotik_graph_current_page");
        kill_session_var("sess_mikrotik_graph_filter");
        kill_session_var("sess_mikrotik_graph_host");
        kill_session_var("sess_mikrotik_graph_cols");
        kill_session_var("sess_mikrotik_graph_thumb");
        kill_session_var("sess_mikrotik_graph_add");
        kill_session_var("sess_mikrotik_graph_style");
        kill_session_var("sess_mikrotik_graph_graph_template");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host"]);
        unset($_REQUEST["cols"]);
        unset($_REQUEST["thumb"]);
        unset($_REQUEST["graph_template_id"]);
        unset($_REQUEST["graph_list"]);
        unset($_REQUEST["graph_add"]);
        unset($_REQUEST["style"]);
        unset($_REQUEST["graph_remove"]);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += mikrotik_check_changed("fitler", "sess_mikrotik_graph_filter");
        $changed += mikrotik_check_changed("host", "sess_mikrotik_graph_host");
        $changed += mikrotik_check_changed("style", "sess_mikrotik_graph_style");
        $changed += mikrotik_check_changed("graph_add", "sess_mikrotik_graph_add");
        $changed += mikrotik_check_changed("graph_template_id", "sess_mikrotik_graph_graph_template");
        if ($changed) {
            $_REQUEST["page"] = "1";
            $_REQUEST["style"] = "";
            $_REQUEST["graph_add"] = "";
        }
    }
    load_current_session_value("graph_template_id", "sess_mikrotik_graph_graph_template", "0");
    load_current_session_value("host", "sess_mikrotik_graph_host", "0");
    load_current_session_value("cols", "sess_mikrotik_graph_cols", "2");
    load_current_session_value("thumb", "sess_mikrotik_graph_thumb", "true");
    load_current_session_value("graph_add", "sess_mikrotik_graph_add", "");
    load_current_session_value("style", "sess_mikrotik_graph_style", "");
    load_current_session_value("filter", "sess_mikrotik_graph_filter", "");
    load_current_session_value("page", "sess_mikrotik_graph_current_page", "1");
    if ($_REQUEST["graph_add"] != "") {
        $_REQUEST["style"] = "selective";
    }
    /* graph permissions */
    if (read_config_option("auth_method") != 0) {
        $sql_where = "WHERE " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
        $sql_join = "LEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\tLEFT JOIN graph_templates\n\t\t\tON (graph_templates.id=graph_local.graph_template_id)\n\t\t\tLEFT JOIN user_auth_perms\n\t\t\tON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id\n\t\t\tAND user_auth_perms.type=1\n\t\t\tAND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
    } else {
        $sql_where = "";
        $sql_join = "";
    }
    /* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
    if (isset($_REQUEST["style"])) {
        if ($_REQUEST["style"] == "selective") {
            /* process selected graphs */
            if (!empty($_REQUEST["graph_list"])) {
                foreach (explode(",", $_REQUEST["graph_list"]) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!empty($_REQUEST["graph_add"])) {
                foreach (explode(",", $_REQUEST["graph_add"]) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!empty($_REQUEST["graph_remove"])) {
                foreach (explode(",", $_REQUEST["graph_remove"]) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $i = 0;
            foreach ($graph_list as $item => $value) {
                $graph_array[$i] = $item;
                $i++;
            }
            if (isset($graph_array) && sizeof($graph_array) > 0) {
                /* build sql string including each graph the user checked */
                $sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");
                /* clear the filter vars so they don't affect our results */
                $_REQUEST["filter"] = "";
                $set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
            }
        }
    }
    $sql_base = "FROM (graph_templates_graph,graph_local)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\t" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0\n\t\tAND graph_templates_graph.local_graph_id=graph_local.id\n\t\t" . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" : "") . "\n\t\t" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "\n\t\t" . (empty($_REQUEST["host"]) ? "" : " and graph_local.host_id=" . $_REQUEST["host"]) . "\n\t\t{$sql_or}";
    $total_rows = count(db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id\n\t\t{$sql_base}"));
    /* reset the page if you have changed some settings */
    if (ROWS_PER_PAGE * ($_REQUEST["page"] - 1) >= $total_rows) {
        $_REQUEST["page"] = "1";
    }
    $graphs = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.title_cache\n\t\t{$sql_base}\n\t\tGROUP BY graph_templates_graph.local_graph_id\n\t\tORDER BY graph_templates_graph.title_cache\n\t\tLIMIT " . ROWS_PER_PAGE * ($_REQUEST["page"] - 1) . "," . ROWS_PER_PAGE);
    ?>
	<script type="text/javascript">
	<!--
	function applyGraphWReset(objForm) {
		strURL = '?action=graphs&reset=1&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&host=' + objForm.host.value;
		strURL = strURL + '&cols=' + objForm.cols.value;
		strURL = strURL + '&thumb=' + objForm.thumb.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	function applyGraphWOReset(objForm) {
		strURL = '?action=graphs&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&host=' + objForm.host.value;
		strURL = strURL + '&cols=' + objForm.cols.value;
		strURL = strURL + '&thumb=' + objForm.thumb.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box("<strong>Host MIB Graphs" . ($_REQUEST["style"] == "selective" ? " (Custom Selective Filter)" : "") . "</strong>", "100%", $colors["header"], "1", "center", "");
    mikrotik_graph_view_filter();
    /* include time span selector */
    if (read_graph_config_option("timespan_sel") == "on") {
        mikrotik_timespan_selector();
    }
    html_end_box();
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (ereg("page=[0-9]+", basename($_SERVER["QUERY_STRING"]))) {
        $nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]);
    } else {
        $nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>";
    }
    $nav_url = ereg_replace("((\\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url);
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
    mikrotik_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "", $_REQUEST["cols"], $_REQUEST["thumb"]);
    if ($total_rows) {
        mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
    }
    html_end_box();
}
Exemplo n.º 6
0
function mikrotik_view_graphs()
{
    global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes;
    include './lib/timespan_settings.php';
    include './lib/html_graph.php';
    html_graph_validate_preview_request_vars();
    /* include graph view filter selector */
    html_start_box('<strong>Graph Preview Filters</strong>' . (isset($_REQUEST['style']) && strlen($_REQUEST['style']) ? ' [ Custom Graph List Applied - Filtering from List ]' : ''), '100%', '', '3', 'center', '');
    html_graph_preview_filter('mikrotik.php', 'graphs', 'ht.hash IN ("' . implode('","', $host_template_hashes) . '")', 'gt.hash IN ("' . implode('","', $graph_template_hashes) . '")');
    html_end_box();
    /* the user select a bunch of graphs of the 'list' view and wants them displayed here */
    $sql_or = '';
    if (isset($_REQUEST['style'])) {
        if (get_request_var_request('style') == 'selective') {
            /* process selected graphs */
            if (!empty($_REQUEST['graph_list'])) {
                foreach (explode(',', $_REQUEST['graph_list']) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!empty($_REQUEST['graph_add'])) {
                foreach (explode(',', $_REQUEST['graph_add']) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!empty($_REQUEST['graph_remove'])) {
                foreach (explode(',', $_REQUEST['graph_remove']) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $i = 0;
            foreach ($graph_list as $item => $value) {
                $graph_array[$i] = $item;
                $i++;
            }
            if (isset($graph_array) && sizeof($graph_array) > 0) {
                /* build sql string including each graph the user checked */
                $sql_or = array_to_sql_or($graph_array, 'gtg.local_graph_id');
                $set_rra_id = empty($rra_id) ? read_graph_config_option('default_rra_id') : get_request_var_request('rra_id');
            }
        }
    }
    $total_graphs = 0;
    // Filter sql_where
    $sql_where = strlen($_REQUEST['filter']) ? "gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%'" : '';
    $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or;
    // Host Id sql_where
    if ($_REQUEST['host_id'] > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . $_REQUEST['host_id'];
    } else {
        $host_ids = mikrotik_host_ids_from_hashes($host_template_hashes);
        if (sizeof($host_ids)) {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id IN (' . implode(',', $host_ids) . ')';
        } else {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
        }
    }
    // Graph Template Id sql_where
    if ($_REQUEST['graph_template_id'] > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . $_REQUEST['graph_template_id'];
    } else {
        $graph_template_ids = mikrotik_graph_templates_from_hashes($graph_template_hashes);
        if (sizeof($graph_template_ids)) {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN (' . implode(',', $graph_template_ids) . ')';
        } else {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
        }
    }
    $limit = $_REQUEST['graphs'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['graphs'];
    $order = 'gtg.title_cache';
    $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs);
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
        $nav_url = str_replace('&page=' . get_request_var_request('page'), '', get_browser_query_string());
    } else {
        $nav_url = get_browser_query_string() . '&host_id=' . get_request_var_request('host_id');
    }
    $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
    html_start_box('', '100%', '', '3', 'center', '');
    $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('graphs'), $total_graphs, get_request_var_request('columns'), 'Graphs', 'page', 'main');
    print $nav;
    if (get_request_var_request('thumbnails') == 'true') {
        html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
    } else {
        html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
    }
    if ($total_graphs > 0) {
        print $nav;
    }
    html_end_box();
    bottom_footer();
}
Exemplo n.º 7
0
function nmidSmokeping_tree_after ( $param )
{
	global $config, $database_default;
	preg_match( "/^(.+),(\d+)$/", $param, $hit );
	include_once( $config[ "library_path" ] . "/adodb/adodb.inc.php" );
	include_once( $config[ "library_path" ] . "/database.php" );
	if ( api_user_realm_auth( 'getSmokePingImage.php' ) ) {
        if ( nmidSmokeping_readPluginStatus( 'nmidWeb2' ) ) {
            print "<div class='sidebarBox portlet' id='item-sp01'>\n";
            print "<div class='portlet-header'>Graph Template:</strong> Availability Chart</div>\n";
            print "<div class='guideListing portlet-content'><center>\n";
        }
        else {
            ?>
            <tr bgcolor='#6d88ad'>
            <tr bgcolor='#a9b7cb'>
                <td colspan='3' class='textHeaderDark'>
                    <strong>Graph Template:</strong> SmokePing (external)
                </td>
            </tr>
            <tr align='center' style='background-color: #f9f9f9;'>
            <td align='center'>
            <?php
        }

        $tree_id = $_REQUEST[ 'tree_id' ];
        $host_leaf_id = $_REQUEST[ 'leaf_id' ];

        $host_list = db_fetch_assoc('select * from graph_tree_items where order_key like ( select Concat(replace(order_key,"000",""),"%") from graph_tree_items where id='.$host_leaf_id.' ) and host_id > 0');
        $column_count = 0;
        foreach ($host_list as $host_item ) {
            $host_id = $host_item['host_id'];
            $host_ip = db_fetch_cell( "select hostname from host where id=" . $host_id );
            $current_nwmgmt_settings = db_fetch_cell( "select nwmgmt_settings from host where id=" . $host_id );
            $nwmgmt_smokeping_path = db_fetch_cell( "select nwmgmt_smokeping_path from host where id=" . $host_id );
            $nwmgmt_smokeping_server = db_fetch_cell( "select nwmgmt_smokeping_server from host where id=" . $host_id );
            $nmid_server = '';
            if ( $nwmgmt_smokeping_server == read_config_option( "nmid_spserver1" ) ) {
                $nmid_server = "nmid_spserver1";
            }
            elseif ( $nwmgmt_smokeping_server == read_config_option( "nmid_spserver2" ) ) {
                $nmid_server = "nmid_spserver2";
            }
            elseif ( $nwmgmt_smokeping_server == read_config_option( "nmid_spserver3" ) ) {
                $nmid_server = "nmid_spserver3";
            }
            elseif ( $nwmgmt_smokeping_server == read_config_option( "nmid_spserver4" ) ) {
                $nmid_server = "nmid_spserver4";
            }
            /* Retrieve Smokeping Config Settings */
            $nmid_sp_url = $nwmgmt_smokeping_server . read_config_option( "nmid_spurl" );
            $nmid_sp_userid = read_config_option( "nmid_spuser" );
            $nmid_sp_password = read_config_option( "nmid_sppwd" );

            if ($_SESSION["sess_graph_view_thumbnails"] == "on") {

                /* Display Smokeping Graph if configured for this device */
                if ( preg_match( "/^s1/", $current_nwmgmt_settings ) > 0 ) {
                    if ( $column_count < 1 ) {
                        ?>
                        <tr align='center' style='background-color: #f9f9f9;'>
                        <?php
                    }
                    $column_count++;

                    ?>
                    <td align='center'>
                    <table width='1' cellpadding='0'>
                        <tr>
                            <td align='center' width='<?php print ceil(100 / read_graph_config_option("num_columns"));?>%'>
                            <table align='center' cellpadding='0'>
                                <tr>
                                    <td align='center'>
                                        <div style="min-height: <?php echo (1.6 * read_graph_config_option("default_height")) . "px"?>;">
                                        <?php
                                            print "<a target='_blank' href='" . $nmid_sp_url . "?target=" . $nwmgmt_smokeping_path . "'><img src='" . $config[ 'url_path' ] . "plugins/nmidSmokeping/getSmokePingImage.php?start=" . get_current_graph_start() . "&end=" . get_current_graph_end() . "&target=" . $nwmgmt_smokeping_path . "&server=" . $nmid_server . "&graphtype=detail&height=".read_graph_config_option("default_height")."&width=".read_graph_config_option("default_width") ."&hide=1' border='0'></a>\n";
                                        ?>
                                        </div>
                                    </td>
                                    <td valign='top' style='align: left; padding: 3px;'>
                                        <a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=zoom&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
                                        <a href='<?php print htmlspecialchars($config['url_path'] . "graph_xport.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
                                        <a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=properties&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a><br>
                                        <?php api_plugin_hook('graph_buttons_thumbnails', array('hook' => 'graphs_thumbnails', 'local_graph_id' => $graph['local_graph_id'], 'rra' =>  0, 'view_type' => '')); ?>
                                        <a href='#page_top'><img src='<?php print $config['url_path'] . "images/graph_page_top.gif";?>' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br>
                                    </td>
                                </tr>
                            </table>
                            </td>
                        </tr>
                    </table>
                    </td>
                    <?php
                    if ( $column_count > (read_graph_config_option('num_columns')-1) ) {
                        $column_count = 0;
                        ?>
                        </tr>
                        <?php
                    }
                }
            }
            else {
                /* Display Smokeping Graph if configured for this device */
                if ( preg_match( "/^s1/", $current_nwmgmt_settings ) > 0 )
                {


                    print "	<table width='1' cellpadding='0'>\n";
                    print "		<tr>\n";
                    print "			<td valign='top' style='padding: 3px;' class='noprint'>\n";
                    if ( read_config_option( "nmid_spgraphtype" ) == "detail" ) {
                        print "				<a target='_blank' href='" . $nmid_sp_url . "?target=" . $nwmgmt_smokeping_path . "'><img src='" . $config[ 'url_path' ] . "plugins/nmidSmokeping/getSmokePingImage.php?start=" . get_current_graph_start() . "&end=" . get_current_graph_end() . "&target=" . $nwmgmt_smokeping_path . "&server=" . $nmid_server . "&graphtype=detail' border='0'></a>\n";
                    }
                    else {
                        print "				<a target='_blank' href='" . $nmid_sp_url . "?target=" . $nwmgmt_smokeping_path . "'><img src='" . $config[ 'url_path' ] . "plugins/nmidSmokeping/getSmokePingImage.php?start=" . get_current_graph_start() . "&end=" . get_current_graph_end() . "&target=" . $nwmgmt_smokeping_path . "&server=" . $nmid_server . "&graphtype=overview' border='0'></a>\n";
                    }

                    print "			</td>\n";
                    print "			<td valign='top' style='padding: 3px;' class='noprint'>";
                    if ( read_config_option( "nmid_spshowlink" ) ) {
                        print "             <a target='_blank' href='" . $nmid_sp_url . "?target=" . $nwmgmt_smokeping_path . "'><img src='" . $config[ 'url_path' ] . "images/graph_zoom.gif' border='0' alt='Go to Smokeping' title='Go to Smokeping' style='padding: 3px;'></a>";
                    }
                    else {
                        print "             <img src='" . $config[ 'url_path' ] . "images/graph_zoom.gif' border='0' alt='placeholder' title='placeholder' style='padding: 3px;'>";
                    }

                    if ( nmidSmokeping_readPluginStatus( 'nmidCreatePDF' ) ) {
                        print " 	     <input onClick=\"setData('sp_" . $host_id . "');\" type=checkbox id='sp_" . $host_id . "' name='sp_" . $host_id . "' value='" . $host_id . "'><br>";
                    }

                    print "         </td>";
                    print "		</tr>\n";
                    print "</table>\n";


                }
            }
        }
        if ( $column_count > 0 && $column_count < read_graph_config_option('num_columns') ) {
            print "</tr>";
        }
        if ($_SESSION["sess_graph_view_thumbnails"] <> "on") {
            if ( nmidSmokeping_readPluginStatus( 'nmidWeb2' ) ) {
                print "</center></div></div>";
            }
            else {
                print "</td></tr></tr>";
            }
        }
    }
	return $param;
}
Exemplo n.º 8
0
function hmib_view_graphs()
{
    global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes;
    include './lib/timespan_settings.php';
    include './lib/html_graph.php';
    html_graph_validate_preview_request_vars();
    if (!isset($_SESSION['sess_hmib_gt'])) {
        $_SESSION['sess_hmib_gt'] = implode(',', array_rekey(db_fetch_assoc('SELECT DISTINCT gl.graph_template_id 
			FROM graph_local AS gl 
			WHERE gl.host_id IN(
				SELECT host_id 
				FROM plugin_hmib_hrSystem
			)'), 'graph_template_id', 'graph_template_id'));
    }
    $gt = $_SESSION['sess_hmib_gt'];
    if (!isset($_SESSION['sess_hmib_hosts'])) {
        $_SESSION['sess_hmib_hosts'] = implode(',', array_rekey(db_fetch_assoc('SELECT h.id 
			FROM host AS h 
			WHERE h.id IN (
				SELECT host_id 
				FROM plugin_hmib_hrSystem
			) 
			UNION 
			SELECT h.id 
			FROM host AS h
			INNER JOIN host_template AS ht
			ON h.host_template_id=ht.id
			WHERE hash="7c13344910097cc599f0d0485305361d" ORDER BY id DESC'), 'id', 'id'));
    }
    $hosts = $_SESSION['sess_hmib_hosts'];
    /* include graph view filter selector */
    html_start_box(__('Graph Preview Filters') . (isset_request_var('style') && strlen(get_request_var('style')) ? ' [ ' . __('Custom Graph List Applied - Filtering from List') . ' ]' : ''), '100%', '', '3', 'center', '');
    html_graph_preview_filter('hmib.php', 'graphs', "h.id IN ({$hosts})", "gt.id IN ({$gt})");
    html_end_box();
    /* the user select a bunch of graphs of the 'list' view and wants them displayed here */
    $sql_or = '';
    if (isset_request_var('style')) {
        if (get_request_var('style') == 'selective') {
            /* process selected graphs */
            if (!isempty_request_var('graph_list')) {
                foreach (explode(',', get_request_var('graph_list')) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!isempty_request_var('graph_add')) {
                foreach (explode(',', get_request_var('graph_add')) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!isempty_request_var('graph_remove')) {
                foreach (explode(',', get_request_var('graph_remove')) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $graph_array = array_keys($graph_list);
            if (sizeof($graph_array)) {
                $sql_or = array_to_sql_or($graph_array, 'gl.id');
            }
        }
    }
    $total_graphs = 0;
    // Filter sql_where
    $sql_where = strlen(get_request_var('filter')) ? "gtg.title_cache LIKE '%" . get_request_var('filter') . "%'" : '';
    $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or;
    // Host Id sql_where
    if (get_request_var('host_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . get_request_var('host_id');
    }
    // Graph Template Id sql_where
    if (get_request_var('graph_template_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . get_request_var('graph_template_id');
    }
    $limit = get_request_var('graphs') * (get_request_var('page') - 1) . ',' . get_request_var('graphs');
    $order = 'gtg.title_cache';
    $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs);
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
        $nav_url = str_replace('&page=' . get_request_var('page'), '', get_browser_query_string());
    } else {
        $nav_url = get_browser_query_string() . '&host_id=' . get_request_var('host_id');
    }
    $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
    $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var('page'), get_request_var('graphs'), $total_graphs, get_request_var('columns'), 'Graphs', 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    if (get_request_var('thumbnails') == 'true') {
        html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    } else {
        html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    }
    html_end_box();
    if ($total_graphs > 0) {
        print $nav;
    }
    bottom_footer();
}
Exemplo n.º 9
0
function mactrack_view_graphs() {
	global $current_user, $colors, $config;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("rra_id"));
	input_validate_input_regex(get_request_var_request('graph_list'), "^([\,0-9]+)$");
	input_validate_input_regex(get_request_var_request('graph_add'), "^([\,0-9]+)$");
	input_validate_input_regex(get_request_var_request('graph_remove'), "^([\,0-9]+)$");
	/* ==================================================== */

	define("ROWS_PER_PAGE", read_graph_config_option("preview_graphs_per_page"));

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("graph_template_id"));
	input_validate_input_number(get_request_var_request("page"));
	/* ==================================================== */

	/* clean up search string */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
	}

	$sql_or = ""; $sql_where = ""; $sql_join = "";

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_graph_view_current_page");
		kill_session_var("sess_graph_view_filter");
		kill_session_var("sess_graph_view_graph_template");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["graph_template_id"]);
		unset($_REQUEST["graph_list"]);
		unset($_REQUEST["graph_add"]);
		unset($_REQUEST["graph_remove"]);
	}

	/* reset the page counter to '1' if a search in initiated */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["page"] = "1";
	}

	load_current_session_value("graph_template_id", "sess_graph_view_graph_template", "0");
	load_current_session_value("filter", "sess_graph_view_filter", "");
	load_current_session_value("page", "sess_graph_view_current_page", "1");

	/* graph permissions */
	if (read_config_option("auth_method") != 0) {
		$sql_where = "WHERE " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);

		$sql_join = "LEFT JOIN host ON (host.id=graph_local.host_id)
			LEFT JOIN graph_templates
			ON (graph_templates.id=graph_local.graph_template_id)
			LEFT JOIN user_auth_perms
			ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id
			AND user_auth_perms.type=1
			AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")
			OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")
			OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}else{
		$sql_where = "";
		$sql_join = "";
	}
	/* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
	if (isset($_REQUEST["style"])) {
		if ($_REQUEST["style"] == "selective") {

			/* process selected graphs */
			if (! empty($_REQUEST["graph_list"])) {
				foreach (explode(",",$_REQUEST["graph_list"]) as $item) {
					$graph_list[$item] = 1;
				}
			}else{
				$graph_list = array();
			}
			if (! empty($_REQUEST["graph_add"])) {
				foreach (explode(",",$_REQUEST["graph_add"]) as $item) {
					$graph_list[$item] = 1;
				}
			}
			/* remove items */
			if (! empty($_REQUEST["graph_remove"])) {
				foreach (explode(",",$_REQUEST["graph_remove"]) as $item) {
					unset($graph_list[$item]);
				}
			}

			$i = 0;
			foreach ($graph_list as $item => $value) {
				$graph_array[$i] = $item;
				$i++;
			}

			if ((isset($graph_array)) && (sizeof($graph_array) > 0)) {
				/* build sql string including each graph the user checked */
				$sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");

				/* clear the filter vars so they don't affect our results */
				$_REQUEST["filter"]  = "";

				$set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
			}
		}
	}

	$sql_base = "FROM (graph_templates_graph,graph_local)
		$sql_join
		$sql_where
		" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0
		AND graph_templates_graph.local_graph_id=graph_local.id
		" . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'":"") . "
		" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "
		$sql_or";

	$total_rows = count(db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id
		$sql_base"));

	/* reset the page if you have changed some settings */
	if (ROWS_PER_PAGE * ($_REQUEST["page"]-1) >= $total_rows) {
		$_REQUEST["page"] = "1";
	}

	$graphs = db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id,
		graph_templates_graph.title_cache
		$sql_base
		GROUP BY graph_templates_graph.local_graph_id
		ORDER BY graph_templates_graph.title_cache
		LIMIT " . (ROWS_PER_PAGE*($_REQUEST["page"]-1)) . "," . ROWS_PER_PAGE);

	?>
	<script type="text/javascript">
	<!--
	function applyGraphPreviewFilterChange(objForm) {
		strURL = '?report=graphs&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php

	/* include graph view filter selector */
	display_output_messages();
	mactrack_tabs();
	html_start_box("<strong>Network Device Graphs</strong>", "100%", $colors["header"], "1", "center", "");
	mactrack_graph_view_filter();

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {
		mactrack_timespan_selector();
	}
	html_end_box();

	/* do some fancy navigation url construction so we don't have to try and rebuild the url string */
	if (ereg("page=[0-9]+",basename($_SERVER["QUERY_STRING"]))) {
		$nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]);
	}else{
		$nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>";
	}

	$nav_url = ereg_replace("((\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url);

	html_start_box("", "100%", $colors["header"], "3", "center", "");
	mactrack_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
	if (read_graph_config_option("thumbnail_section_preview") == "on") {
		html_graph_thumbnail_area($graphs, "","graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}else{
		html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}

	if ($total_rows) {
		mactrack_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
	}
	html_end_box();
}
Exemplo n.º 10
0
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) {
	global $current_user, $colors;

	require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_utility.php");

	if (empty($tree_id)) { return; }

	$sql_where = "";
	$sql_join = "";
	$title = "";
	$title_delimiter = "";
	$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, (api_graph_tree_item_depth_get($leaf["order_key"]) * CHARS_PER_TIER));
	}

	/* graph permissions */
	if (read_config_option("auth_method") != "0") {
		/* get policy information for the sql where clause */
		$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
		$sql_where = (empty($sql_where) ? "" : "and $sql_where");
		$sql_join = "
			left join host on (host.id=graph.host_id)
			left join graph_template on (graph_template.id=graph.graph_template_id)
			left join user_auth_perms on ((graph.id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_template.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}

	/* 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 = "<strong>" . _("Graph Template:") . "</strong> " . db_fetch_cell("select template_name from graph_template 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 = "<strong>" . _("Data Query:") . "</strong> " . (empty($host_group_data_array[1]) ? _("(Non Indexed)") : 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 = "<strong>" . _("Data Query:") . "</strong> " . (empty($host_group_data_array[1]) ? _("(Non Indexed)") : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1])) . "-> " . (empty($host_group_data_array[2]) ? "Unknown Index" : 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_delimiter . "<strong>" . _("Tree:") . "</strong> $tree_name"; $title_delimiter = "-> "; }
	if (!empty($leaf_name)) { $title .= $title_delimiter . "<strong>" . _("Leaf:") . "</strong> $leaf_name"; $title_delimiter = "-> "; }
	if (!empty($host_name)) { $title .= $title_delimiter . "<strong>" . _("Device:") . "</strong> $host_name"; $title_delimiter = "-> "; }
	if (!empty($host_group_data_name)) { $title .= $title_delimiter . " $host_group_data_name"; $title_delimiter = "-> "; }

	print "<table width='98%' align='center' cellpadding='3'>";

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {
		html_graph_start_box(3, false);
		require(CACTI_BASE_PATH . "/include/html/inc_timespan_selector.php");
		html_graph_end_box();
		print "<br>";
	}

	/* start graph display */
	html_graph_start_box(3, false);
	print "<tr bgcolor='#" . $colors["header_panel_background"] . "'><td width='390' colspan='3' class='textHeaderDark'>$title</td></tr>";

	if (($leaf_type == "header") || (empty($leaf_id))) {
		$heirarchy = db_fetch_assoc("select
			graph_tree_items.id,
			graph_tree_items.title,
			graph_tree_items.local_graph_id,
			graph_tree_items.rra_id,
			graph_tree_items.order_key,
			graph.title_cache
			from (graph_tree_items,graph)
			left join graph on (graph_tree_items.local_graph_id=graph.id)
			$sql_join
			where graph_tree_items.graph_tree_id=$tree_id
			and graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'
			and graph_tree_items.local_graph_id>0
			$sql_where
			group by graph_tree_items.id
			order by graph_tree_items.order_key");

		if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
			html_graph_thumbnail_area($heirarchy, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
		}else{
			html_graph_area($heirarchy, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
		}
	}elseif ($leaf_type == "host") {
		/* graph template grouping */
		if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
			$graph_templates = db_fetch_assoc("select
				graph_template.id,
				graph_template.template_name
				from graph,graph_template
				where graph.graph_template_id=graph_template.id
				and graph.host_id=" . $leaf["host_id"] . "
				" . (empty($graph_template_id) ? "" : "and graph_template.id=$graph_template_id") . "
				group by graph_template.id
				order by graph_template.template_name");

			/* for graphs without a template */
			array_push($graph_templates, array(
				"id" => "0",
				"template_name" => _("(No Graph Template)")
				));

			if (sizeof($graph_templates) > 0) {
				foreach ($graph_templates as $item) {
					$graphs = db_fetch_assoc("select
						graph.title_cache,
						graph.id as graph_id
						from graph
						$sql_join
						where graph.graph_template_id=" . $item["id"] . "
						and graph.host_id=" . $leaf["host_id"] . "
						$sql_where
						order by graph.title_cache");

					if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
						html_graph_thumbnail_area($graphs, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'><strong>" . _("Graph Template:") . "</strong> " . $item["template_name"] . "</td></tr>");
					}else{
						html_graph_area($graphs, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'><strong>" . _("Graph Template:") . "</strong> " . $item["template_name"] . "</td></tr>");
					}
				}
			}
		/* data query index grouping */
		}elseif ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
			$data_sources = db_fetch_assoc("select
				graph.id as graph_id,
				graph.title_cache as graph_title,
				data_source.data_input_type,
				data_source.id as data_source_id
				from graph,graph_item,data_source_item,data_source
				where graph.id=graph_item.graph_id
				and graph_item.data_source_item_id=data_source_item.id
				and data_source_item.data_source_id=data_source.id
				and graph.host_id = " . $leaf["host_id"] . "");

			$index_list = array();

			if (sizeof($data_sources) > 0) {
				foreach ($data_sources as $item) {
					if ($item["data_input_type"] == DATA_INPUT_TYPE_DATA_QUERY) {
						$field_list = array_rekey(db_fetch_assoc("select name,value from data_source_field where data_source_id = ". $item["data_source_id"] . " and (name = 'data_query_id' or name = 'data_query_index' or name = 'data_query_field_name' or name = 'data_query_field_value')"), "name", "value");

						if ((isset($field_list["data_query_id"])) && (isset($field_list["data_query_index"]))) {
							if ( !(((isset($data_query_id)) && ($data_query_id != $field_list["data_query_id"])) || ((isset($data_query_index)) && ($data_query_index != $field_list["data_query_index"]))) ) {
								$index_list{$field_list["data_query_id"]}{$field_list["data_query_index"]}{$item["graph_id"]} = $item["graph_title"];
							}
						}
					}else{
						$index_list[0][0]{$item["graph_id"]} = $item["graph_title"];
					}
				}
			}

			while (list($data_query_id, $graph_list) = each($index_list)) {
				if (empty($data_query_id)) {
					print "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'><strong>" . _("(Non Indexed)") . "</strong></td></tr>";

					$index_graph_list = array();

					while (list($graph_id, $graph_title) = each($graph_list[0])) {
						/* reformat the array so it's compatable with the html_graph* area functions */
						array_push($index_graph_list, array("graph_id" => $graph_id, "title_cache" => $graph_title));
					}

					if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
						html_graph_thumbnail_area($index_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "");
					}else{
						html_graph_area($index_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "");
					}
				}else{
					/* 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);

					/* re-key the results on data query index */
					if (sizeof($graph_list) > 0) {
						print "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'><strong>" . _("Data Query:") . "</strong> " . db_fetch_cell("select name from snmp_query where id = $data_query_id") . "</td></tr>";
					}

					/* using the sorted data as they key; grab each snmp index from the master list */
					while (list($data_query_index, $sort_field_value) = each($sort_field_data)) {
						/* render each graph for the current data query index */
						if (isset($graph_list[$data_query_index])) {
							$index_graph_list = array();

							while (list($graph_id, $graph_title) = each($graph_list[$data_query_index])) {
								/* reformat the array so it's compatable with the html_graph* area functions */
								array_push($index_graph_list, array("graph_id" => $graph_id, "title_cache" => $graph_title));
							}

							if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
								html_graph_thumbnail_area($index_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'>$sort_field_value</td></tr>");
							}else{
								html_graph_area($index_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'>$sort_field_value</td></tr>");
							}
						}
					}
				}
			}
		}
	}

	print "</table>";
}
Exemplo n.º 11
0
function get_graph_preview_content () {
	global $colors;
	require_once(CACTI_BASE_PATH . "/include/auth/auth_constants.php");

	/* Make sure nothing is cached */
	header("Cache-Control: must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header("Expires: ". gmdate("D, d M Y H:i:s", mktime(date("H"), date("i"), date("s"), date("m")-1, date("d"), date("Y")))." GMT");
	header("Last-Modified: ". gmdate("D, d M Y H:i:s")." GMT");

	$current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . $_SESSION["sess_user_id"]);

	define("MAX_DISPLAY_PAGES", 21);

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("graphs"));
	input_validate_input_number(get_request_var_request("device_id"));
	input_validate_input_number(get_request_var_request("graph_template_id"));
	input_validate_input_number(get_request_var_request("page"));
	/* ==================================================== */

	/* 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"));
	}

	$sql_or = ""; $sql_where = ""; $sql_join = "";

	if ((read_config_option("auth_method") != 0) && (empty($current_user["show_preview"]))) {
		print "<strong><font size='+1' color='FF0000'>" . __("YOU DO NOT HAVE RIGHTS FOR PREVIEW VIEW") . "</font></strong>"; exit;
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_filter"])) {
		kill_session_var("sess_graph_view_current_page");
		kill_session_var("sess_graph_view_filter");
		kill_session_var("sess_graph_view_graph_template");
		kill_session_var("sess_graph_view_device");
		kill_session_var("sess_graph_view_graphs");
		kill_session_var("sess_graph_view_thumbnails");
		kill_session_var("sess_graph_view_list_graph_list");
		kill_session_var("sess_graph_view_list_graph_add");
		kill_session_var("sess_graph_view_list_graph_remove");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["device_id"]);
		unset($_REQUEST["graphs"]);
		unset($_REQUEST["thumbnails"]);
		unset($_REQUEST["graph_template_id"]);
		unset($_REQUEST["graph_list"]);
		unset($_REQUEST["graph_add"]);
		unset($_REQUEST["graph_remove"]);
	}

	/* save selected graphs into url, for backward compatibility */
	if (!empty($_REQUEST["graph_list"])) {
		foreach (explode(",",get_request_var_request("graph_list")) as $item) {
			$graph_list[$item] = 1;
		}
	}else{
		$graph_list = array();
	}

	load_current_session_value("device_id", "sess_graph_view_device", "0");
	load_current_session_value("graph_template_id", "sess_graph_view_graph_template", "0");
	load_current_session_value("filter", "sess_graph_view_filter", "");
	load_current_session_value("page", "sess_graph_view_current_page", "1");
	load_current_session_value("thumbnails", "sess_graph_view_thumbnails", CHECKED);
	load_current_session_value("graphs", "sess_graph_view_graphs", read_graph_config_option("preview_graphs_per_page"));
	load_current_session_value("graph_list", "sess_graph_view_list_graph_list", "");
	load_current_session_value("graph_add", "sess_graph_view_list_graph_add", "");
	load_current_session_value("graph_remove", "sess_graph_view_list_graph_remove", "");

	/* graph permissions */
	if (read_config_option("auth_method") != 0) {
		$sql_where = "where " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_devices"], $current_user["policy_graph_templates"]);

		$sql_join = "left join device on (device.id=graph_local.device_id)
			left join graph_templates on (graph_templates.id=graph_local.graph_template_id)
			left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPHS . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_DEVICES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPH_TEMPLATES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}else{
		$sql_where = "";
		$sql_join = "";
	}
	/* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
	if (isset($_REQUEST["list"])) {
		if (is_array(get_request_var_request("graph_list"))) {
			$graph_list = $_REQUEST["graph_list"];
		}

		if (!empty($_REQUEST["graph_add"])) {
			foreach (explode(",",get_request_var_request("graph_add")) as $item) {
				$graph_list[$item] = 1;
			}
		}
		/* remove items */
		if (!empty($_REQUEST["graph_remove"])) {
			foreach (explode(",",get_request_var_request("graph_remove")) as $item) {
				unset($graph_list[$item]);
			}
		}
		$_SESSION["sess_graph_view_list_graph_list"] = $graph_list;

		$i = 0;
		foreach ($graph_list as $item => $value) {
			$graph_array[$i] = $item;
			$i++;
		}

		if ((isset($graph_array)) && (sizeof($graph_array) > 0)) {
			/* build sql string including each graph the user checked */
			$sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");

			/* clear the filter vars so they don't affect our results */
			$_REQUEST["filter"]  = "";
			$_REQUEST["device_id"] = "0";

			/* Fix to avoid error in 'preview' after selection in 'list' : Notice: Undefined index: rra_id in C:\apache2\htdocs\cacti\graph_view.php on line 142 */
			$set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
		}
	}

	$sql_base = "FROM (graph_templates_graph,graph_local)
		$sql_join
		$sql_where
		" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0
		AND graph_templates_graph.local_graph_id=graph_local.id
		AND graph_templates_graph.title_cache like '%%" . get_request_var_request("filter") . "%%'
		" . (empty($_REQUEST["device_id"]) ? "" : " and graph_local.device_id=" . $_REQUEST["device_id"]) . "
		" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "
		$sql_or";

	$total_rows = count(db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id
		$sql_base"));

	/* reset the page if you have changed some settings */
	if ($_REQUEST["graphs"] * ($_REQUEST["page"]-1) >= $total_rows) {
		$_REQUEST["page"] = "1";
	}

	$graphs = db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id,
		graph_templates_graph.title_cache,
		graph_templates_graph.image_format_id
		$sql_base
		GROUP BY graph_templates_graph.local_graph_id
		ORDER BY graph_templates_graph.title_cache
		LIMIT " . (get_request_var_request("graphs")*(get_request_var_request("page")-1)) . "," . get_request_var_request("graphs"));

	/* include graph view filter selector */
	graph_view_filter_table("preview");

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == CHECKED) {
		graph_view_timespan_selector("preview");
	}

	?>
	<script type='text/javascript'>
	<!--
	function pageChange(page) {
		strURL = '?action=ajax_preview&page=' + page;
		$.get("graph_view.php" + strURL, function (data) {
			$("#graph_content").html(data);
		});
	}
	//-->
	</script>
	<?php

	html_start_box("", "100", $colors["header"], "0", "center", "");

	print "<table cellpadding='0' cellspacing='0' style='width:100%;border:1px solid #BEBEBE;'>\n";
	/* generate page list */

	if ($total_rows > get_request_var_request("graphs")) {
		$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["graphs"], $total_rows, "pageChange");

		$nav = "\t\t\t<tr class='rowHeader'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='left' style='width:100px;' class='textHeaderDark'>";
		if ($_REQUEST["page"] > 1) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]-1) . ")'>&lt;&lt;&nbsp;" . __("Previous") . "</a></strong>"; }
		$nav .= "</td>\n
							<td align='center' class='textHeaderDark'>
								" . __("Showing Graphs") . ((get_request_var_request("graphs")*(get_request_var_request("page")-1))+1) . " " . __("to") . " " . ((($total_rows < get_request_var_request("graphs")) || ($total_rows < (get_request_var_request("graphs")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graphs")*get_request_var_request("page"))) . " " . __("of") . " $total_rows [$url_page_select]
							</td>\n
							<td align='right' style='width:100px;' class='textHeaderDark'>";
		if (($_REQUEST["page"] * $_REQUEST["graphs"]) < $total_rows) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]+1) . ")'>" . __("Next") . "&gt;&gt;</a></strong>"; }
		$nav .= "</td>\n
						</tr>
					</table>
				</td>
			</tr>\n";
	}else{
		$nav = "<tr class='rowHeader'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='center' class='textHeaderDark'>
								" . __("Showing All Graphs") . (strlen(get_request_var_request("filter")) ? " [ " . __("Filter") . " '" . get_request_var_request("filter") . "' " . __("Applied") . " ]" : "") . "
							</td>
						</tr>
					</table>
				</td>
			</tr>\n";
	}

	print $nav;

	if (read_graph_config_option("thumbnail_section_preview") == CHECKED) {
		html_graph_thumbnail_area($graphs, "","graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}else{
		html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}

	print $nav;

	html_graph_end_box();
}
Exemplo n.º 12
0
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 "<tr><td><table width='100%' cellpadding='2' cellspacing='1'><tr>\n";
        /* draw one vbar for each tier */
        for ($j = 0; $j < $current_tier - 1; $j++) {
            print "<td width='10' class='even'></td>\n";
        }
        print "<td><table width='100%' cellspacing='0' cellpadding='2'><tr>\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 "<td><a href='" . htmlspecialchars("graph.php?local_graph_id={$local_graph_id}&rra_id=all") . "'><img align='absmiddle' alt='" . htmlspecialchars($graph_title, ENT_QUOTES) . "' class='graphimage' id='graph_{$local_graph_id}'\n\t\t\t\tsrc='" . htmlspecialchars("graph_image.php?action=view&local_graph_id={$local_graph_id}&rra_id=0&graph_start=" . get_current_graph_start() . '&graph_end=' . get_current_graph_end() . '&graph_height=' . read_graph_config_option('default_height') . '&graph_width=' . read_graph_config_option('default_width') . '&graph_nolegend=true') . "' border='0'></a></td>\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 "</tr><tr>\n";
            }
        } else {
            print "<td><a href='" . htmlspecialchars("graph.php?local_graph_id={$local_graph_id}&rra_id=all") . "'><img align='absmiddle' alt='" . htmlspecialchars($graph_title, ENT_QUOTES) . "' class='graphimage' id='graph_{$local_graph_id}'\n\t\t\t\tsrc='" . htmlspecialchars("graph_image.php?action=view&local_graph_id={$local_graph_id}&rra_id={$rra_id}&graph_start=" . -db_fetch_cell("select timespan from rra where id={$rra_id}") . '&graph_height=' . read_graph_config_option('default_height') . '&graph_width=' . read_graph_config_option('default_width') . '&graph_nolegend=true') . "' border='0'></a></td>\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 "</tr><tr>\n";
            }
        }
    } else {
        if (read_graph_config_option('timespan_sel') == 'on') {
            print "<td><a href='" . htmlspecialchars("graph.php?local_graph_id={$local_graph_id}&rra_id=all") . "'><img class='graphimage' id='graph_{$local_graph_id}' src='graph_image.php?action=view&local_graph_id={$local_graph_id}&rra_id=0&graph_start=" . get_current_graph_start() . '&graph_end=' . get_current_graph_end() . "' border='0' alt='" . htmlspecialchars($graph_title, ENT_QUOTES) . "'></a></td>";
            print "</tr><tr>\n";
        } else {
            print "<td><a href='" . htmlspecialchars("graph.php?local_graph_id={$local_graph_id}&rra_id=all") . "'><img class='graphimage' id='graph_{$local_graph_id}' src='graph_image.php?action=view&local_graph_id={$local_graph_id}&rra_id={$rra_id}' border='0' alt='" . htmlspecialchars($graph_title, ENT_QUOTES) . "'></a></td>";
            print "</tr><tr>\n";
        }
    }
    /* if we are at the end of the graph group, end the nested table */
    if ($next_leaf_type != 'graph') {
        print '</tr></table></td>';
        print "</tr></table></td></tr>\n";
        $already_open = false;
    }
    return $already_open;
}
Exemplo n.º 13
0
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) {
	global $current_user, $colors, $config;

	include($config["include_path"] . "/config_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; }

	$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));
	}

	/* graph permissions */
	if (read_config_option("global_auth") == "on") {
		/* get policy information for the sql where clause */
		$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
		$sql_where = (empty($sql_where) ? "" : "and $sql_where");
		$sql_join = "
			left join host on host.id=graph_local.host_id
			left join graph_templates on graph_templates.id=graph_local.graph_template_id
			left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}

	/* 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 = "<strong>Graph Template:</strong> " . 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 = "<strong>Data Query:</strong> " . (empty($host_group_data_array[1]) ? "(Non Indexed)" : 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 = "<strong>Data Query:</strong> " . (empty($host_group_data_array[1]) ? "(Non Indexed) " : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1])) . "-> " . (empty($host_group_data_array[2]) ? "Unknown Index" : 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 . "<strong>Tree:</strong> $tree_name"; $title_delimeter = "-> "; }
	if (!empty($leaf_name)) { $title .= $title_delimeter . "<strong>Leaf:</strong> $leaf_name"; $title_delimeter = "-> "; }
	if (!empty($host_name)) { $title .= $title_delimeter . "<strong>Host:</strong> $host_name"; $title_delimeter = "-> "; }
	if (!empty($host_group_data_name)) { $title .= $title_delimeter . " $host_group_data_name"; $title_delimeter = "-> "; }

	print "<table width='98%' align='center' cellpadding='3'>";

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {
		html_graph_start_box(3, false);
		include("./include/html/inc_timespan_selector.php");
		html_graph_end_box();
		print "<br>";
	}

	/* start graph display */
	html_graph_start_box(3, false);
	print "<tr bgcolor='#" . $colors["header_panel"] . "'><td width='390' colspan='3' class='textHeaderDark'>$title</td></tr>";

	if (($leaf_type == "header") || (empty($leaf_id))) {
		$heirarchy = db_fetch_assoc("select
			graph_tree_items.id,
			graph_tree_items.title,
			graph_tree_items.local_graph_id,
			graph_tree_items.rra_id,
			graph_tree_items.order_key,
			graph_templates_graph.title_cache as title_cache
			from graph_tree_items,graph_local
			left join graph_templates_graph on (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id and graph_tree_items.local_graph_id>0)
			$sql_join
			where graph_tree_items.graph_tree_id=$tree_id
			and graph_local.id=graph_templates_graph.local_graph_id
			and graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'
			and graph_tree_items.local_graph_id>0
			$sql_where
			group by graph_tree_items.id
			order by graph_tree_items.order_key");

		if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
			html_graph_thumbnail_area($heirarchy, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
		}else{
			html_graph_area($heirarchy, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
		}
	}elseif ($leaf_type == "host") {
		/* graph template grouping */
		if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
			$graph_templates = db_fetch_assoc("select
				graph_templates.id,
				graph_templates.name
				from graph_local,graph_templates,graph_templates_graph
				where graph_local.id=graph_templates_graph.local_graph_id
				and graph_templates_graph.graph_template_id=graph_templates.id
				and graph_local.host_id=" . $leaf["host_id"] . "
				" . (empty($graph_template_id) ? "" : "and graph_templates.id=$graph_template_id") . "
				group by graph_templates.id
				order by graph_templates.name");

			/* 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) {
				$graphs = db_fetch_assoc("select
					graph_templates_graph.title_cache,
					graph_templates_graph.local_graph_id
					from graph_local,graph_templates_graph
					$sql_join
					where graph_local.id=graph_templates_graph.local_graph_id
					and graph_local.graph_template_id=" . $graph_template["id"] . "
					and graph_local.host_id=" . $leaf["host_id"] . "
					$sql_where
					order by graph_templates_graph.title_cache");

				if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
					html_graph_thumbnail_area($graphs, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'><strong>Graph Template:</strong> " . $graph_template["name"] . "</td></tr>");
				}else{
					html_graph_area($graphs, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'><strong>Graph Template:</strong> " . $graph_template["name"] . "</td></tr>");
				}
			}
			}
		/* data query index grouping */
		}elseif ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
			$data_queries = db_fetch_assoc("select
				snmp_query.id,
				snmp_query.name
				from graph_local,snmp_query
				where graph_local.snmp_query_id=snmp_query.id
				and graph_local.host_id=" . $leaf["host_id"] . "
				" . (!isset($data_query_id) ? "" : "and snmp_query.id=$data_query_id") . "
				group by snmp_query.id
				order by snmp_query.name");

			/* for graphs without a data query */
			if (empty($data_query_id)) {
				array_push($data_queries, array(
					"id" => "0",
					"name" => "(Non Indexed)"
					));
			}

			if (sizeof($data_queries) > 0) {
			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"]);

				/* grab a list of all graphs for this host/data query combination */
				$graphs = db_fetch_assoc("select
					graph_templates_graph.title_cache,
					graph_templates_graph.local_graph_id,
					graph_local.snmp_index
					from graph_local,graph_templates_graph
					$sql_join
					where graph_local.id=graph_templates_graph.local_graph_id
					and graph_local.snmp_query_id=" . $data_query["id"] . "
					and graph_local.host_id=" . $leaf["host_id"] . "
					" . (empty($data_query_index) ? "" : "and graph_local.snmp_index='$data_query_index'") . "
					$sql_where
					group by graph_templates_graph.local_graph_id
					order by graph_templates_graph.title_cache");

				/* re-key the results on data query index */
				if (sizeof($graphs) > 0) {
					print "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'><strong>Data Query:</strong> " . $data_query["name"] . "</td></tr>";

					foreach ($graphs as $graph) {
						$snmp_index_to_graph{$graph["snmp_index"]}{$graph["local_graph_id"]} = $graph["title_cache"];
					}
				}

				/* 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])) {
						$graph_list = array();

						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("local_graph_id" => $local_graph_id, "title_cache" => $graph_title));
						}

						if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
							html_graph_thumbnail_area($graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'>$sort_field_value</td></tr>");
						}else{
							html_graph_area($graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'>$sort_field_value</td></tr>");
						}
					}
				}
			}
			}
		}
	}

	print "</table>";
}