예제 #1
0
function grow_graph_tree($tree_id, $start_branch, $user_id, $options) {
	global $colors, $current_user, $config;

	include($config["include_path"] . "/config_arrays.php");
	include_once($config["library_path"] . "/tree.php");

	$search_key = "";
	$already_open = false;
	$hide_until_tier = false;
	$graph_ct = 0;
	$sql_where = "";
	$sql_join = "";

	/* get the "starting leaf" if the user clicked on a specific branch */
	if (($start_branch != "") && ($start_branch != "0")) {
		$order_key = db_fetch_cell("select order_key from graph_tree_items where id=$start_branch");

		$search_key = substr($order_key, 0, (tree_tier($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 . " OR graph_tree_items.local_graph_id=0)");
		$sql_join = "left join graph_local on (graph_templates_graph.local_graph_id=graph_local.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"] . "))";
	}

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

	$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.host_id,
		graph_tree_items.order_key,
		graph_templates_graph.title_cache as graph_title,
		CONCAT_WS('',host.description,' (',host.hostname,')') as hostname,
		settings_tree.status
		from graph_tree_items
		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)
		left join settings_tree on (graph_tree_items.id=settings_tree.graph_tree_item_id and settings_tree.user_id=$user_id)
		left join host on (graph_tree_items.host_id=host.id)
		$sql_join
		where graph_tree_items.graph_tree_id=$tree_id
		and graph_tree_items.order_key like '$search_key%'
		$sql_where
		order by graph_tree_items.order_key");

	print "<!-- <P>Building Heirarchy w/ " . sizeof($heirarchy) . " leaves</P>  -->\n";

	html_graph_start_box(0, true);

	print "<tr bgcolor='#" . $colors["header_panel"] . "'><td colspan='30'><table cellspacing='0' cellpadding='3' width='100%'><tr><td class='textHeaderDark'><strong><a class='linkOverDark' href='graph_view.php?action=tree&tree_id=" . $_SESSION["sess_view_tree_id"] . "'>[root]</a> - " . db_fetch_cell("select name from graph_tree where id=" . $_SESSION["sess_view_tree_id"]) . "</strong></td></tr></table></td></tr>";

	$i = 0;

	/* loop through each tree item */
	if (sizeof($heirarchy) > 0) {
	foreach ($heirarchy as $leaf) {
		/* find out how 'deep' this item is */
		$tier = tree_tier($leaf["order_key"]);

		/* find the type of the current branch */
		if ($leaf["title"] != "") { $current_leaf_type = "heading"; }elseif (!empty($leaf["local_graph_id"])) { $current_leaf_type = "graph"; }else{ $current_leaf_type = "host"; }

		/* find the type of the next branch. make sure the next item exists first */
		if (isset($heirarchy{$i+1})) {
			if ($heirarchy{$i+1}["title"] != "") { $next_leaf_type = "heading"; }elseif (!empty($heirarchy{$i+1}["local_graph_id"])) { $next_leaf_type = "graph"; }else{ $next_leaf_type = "host"; }
		}else{
			$next_leaf_type = "";
		}

		if ((($current_leaf_type == 'heading') || ($current_leaf_type == 'host')) && (($tier <= $hide_until_tier) || ($hide_until_tier == false))) {
			$current_title = (($current_leaf_type == "heading") ? $leaf["title"] : $leaf["hostname"]);

			/* draw heading */
			draw_tree_header_row($tree_id, $leaf["id"], $tier, $current_title, true, $leaf["status"], true);

			/* this is an open host, lets expand a bit */
			if (($current_leaf_type == "host") && (empty($leaf["status"]))) {
				/* get a list of all graph templates in use by this host */
				$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"] . "
					group by graph_templates.id
					order by graph_templates.name");

				if (sizeof($graph_templates) > 0) {
				foreach ($graph_templates as $graph_template) {
					draw_tree_header_row($tree_id, $leaf["id"], ($tier+1), $graph_template["name"], false, $leaf["status"], false);

					/* get a list of each graph using this graph template for this particular host */
					$graphs = db_fetch_assoc("select
						graph_templates_graph.title_cache,
						graph_templates_graph.local_graph_id
						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.graph_template_id=" . $graph_template["id"] . "
						and graph_local.host_id=" . $leaf["host_id"] . "
						order by graph_templates_graph.title_cache");

					$graph_ct = 0;
					if (sizeof($graphs) > 0) {
					foreach ($graphs as $graph) {
						/* incriment graph counter so we know when to start a new row or not */
						$graph_ct++;

						if (!isset($graphs[$graph_ct])) { $next_leaf_type = "heading"; }else{ $next_leaf_type = "graph"; }

						/* draw graph */
						$already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, ($tier+2), $graph["local_graph_id"], 1, $graph["title_cache"]);
					}
					}
				}
				}
			}

			$graph_ct = 0;
		}elseif (($current_leaf_type == 'graph') && (($tier <= $hide_until_tier) || ($hide_until_tier == false))) {
			/* incriment graph counter so we know when to start a new row or not */
			$graph_ct++;

			/* draw graph */
			$already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, $tier, $leaf["local_graph_id"], $leaf["rra_id"], $leaf["graph_title"]);
		}

		/* if we have come back to the tier that was origionally flagged, then take away the flag */
		if (($tier <= $hide_until_tier) && ($hide_until_tier != false)) {
			$hide_until_tier = false;
		}

		/* if we are supposed to hide this branch, flag it */
		if (($leaf["status"] == "1") && ($hide_until_tier == false)) {
			$hide_until_tier = $tier;
		}

		$i++;
	}
	}

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

	html_graph_end_box();
}
예제 #2
0
function grow_graph_tree($tree_id, $start_branch, $user_id, $options) {
	global $colors, $current_user, $config, $graph_timeshifts;

	include($config["include_path"] . "/global_arrays.php");
	include_once($config["library_path"] . "/tree.php");

	$search_key = "";
	$already_open = false;
	$hide_until_tier = false;
	$graph_ct = 0;
	$sql_where = "";
	$sql_join  = "";

	/* get the "starting leaf" if the user clicked on a specific branch */
	if (($start_branch != "") && ($start_branch != "0")) {
		$order_key = db_fetch_cell("select order_key from graph_tree_items where id=$start_branch");

		$search_key = substr($order_key, 0, (tree_tier($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 . " OR graph_tree_items.local_graph_id=0)");
		$sql_join = "left join graph_local on (graph_templates_graph.local_graph_id=graph_local.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"] . "))";
	}

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {
		html_graph_start_box(3, false);

		?>

			<script type='text/javascript'>
			// Initialize the calendar
			calendar=null;

			// This function displays the calendar associated to the input field 'id'
			function showCalendar(id) {
				var el = document.getElementById(id);
				if (calendar != null) {
					// we already have some calendar created
					calendar.hide();  // so we hide it first.
				} else {
					// first-time call, create the calendar.
					var cal = new Calendar(true, null, selected, closeHandler);
					cal.weekNumbers = false;  // Do not display the week number
					cal.showsTime = true;     // Display the time
					cal.time24 = true;        // Hours have a 24 hours format
					cal.showsOtherMonths = false;    // Just the current month is displayed
					calendar = cal;                  // remember it in the global var
					cal.setRange(1900, 2070);        // min/max year allowed.
					cal.create();
				}

				calendar.setDateFormat('%Y-%m-%d %H:%M');    // set the specified date format
				calendar.parseDate(el.value);                // try to parse the text in field
				calendar.sel = el;                           // inform it what input field we use

				// Display the calendar below the input field
				calendar.showAtElement(el, "Br");        // show the calendar

				return false;
			}

			// This function update the date in the input field when selected
			function selected(cal, date) {
				cal.sel.value = date;      // just update the date in the input field.
			}

			// This function gets called when the end-user clicks on the 'Close' button.
			// It just hides the calendar without destroying it.
			function closeHandler(cal) {
				cal.hide();                        // hide the calendar
				calendar = null;
			}
		</script>
		<script type="text/javascript">
		<!--

			function applyTimespanFilterChange(objForm) {
				strURL = '?predefined_timespan=' + objForm.predefined_timespan.value;
				strURL = strURL + '&predefined_timeshift=' + objForm.predefined_timeshift.value;
				document.location = strURL;
			}

		-->
		</script>

			<tr bgcolor="<?php print $colors["panel"];?>" class="noprint">
				<form name="form_timespan_selector" method="post">
				<td class="noprint">
					<table width="100%" cellpadding="0" cellspacing="0">
						<tr>
							<td nowrap style='white-space: nowrap;' width='55'>
								&nbsp;<strong>Presets:</strong>&nbsp;
							</td>
							<td nowrap style='white-space: nowrap;' width='130'>
								<select name='predefined_timespan' onChange="applyTimespanFilterChange(document.form_timespan_selector)">
									<?php
									if ($_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 nowrap style='white-space: nowrap;' width='30'>
								&nbsp;<strong>From:</strong>&nbsp;
							</td>
							<td width='150' nowrap style='white-space: nowrap;'>
								<input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='14' value='<?php print (isset($_SESSION["sess_current_date1"]) ? $_SESSION["sess_current_date1"] : "");?>'>
								&nbsp;<input style='padding-bottom: 4px;' type='image' src='images/calendar.gif' alt='Start date selector' title='Start date selector' border='0' align='absmiddle' onclick="return showCalendar('date1');">&nbsp;
							</td>
							<td nowrap style='white-space: nowrap;' width='20'>
								&nbsp;<strong>To:</strong>&nbsp;
							</td>
							<td width='150' nowrap style='white-space: nowrap;'>
								<input type='text' name='date2' id='date2' title='Graph End Timestamp' size='14' value='<?php print (isset($_SESSION["sess_current_date2"]) ? $_SESSION["sess_current_date2"] : "");?>'>
								&nbsp;<input style='padding-bottom: 4px;' type='image' src='images/calendar.gif' alt='End date selector' title='End date selector' border='0' align='absmiddle' onclick="return showCalendar('date2');">
							</td>
							<td width='130' nowrap style='white-space: nowrap;'>
								&nbsp;&nbsp;<input style='padding-bottom: 4px;' type='image' name='move_left' src='images/move_left.gif' alt='Left' border='0' align='absmiddle' title='Shift Left'>
								<select name='predefined_timeshift' title='Define Shifting Interval' onChange="applyTimespanFilterChange(document.form_timespan_selector)">
									<?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>
								<input style='padding-bottom: 4px;' type='image' name='move_right' src='images/move_right.gif' alt='Right' border='0' align='absmiddle' title='Shift Right'>
							</td>
							<td nowrap style='white-space: nowrap;'>
								&nbsp;&nbsp;<input type='image' name='button_refresh' src='images/button_refresh.gif' alt='Refresh selected time span' border='0' align='absmiddle' value='refresh'>
								<input type='image' name='button_clear' src='images/button_clear.gif' alt='Return to the default time span' border='0' align='absmiddle'>
							</td>
						</tr>
					</table>
				</td>
				</form>
			</tr>
		<?php

		html_graph_end_box();
		print "<br>";
	}

	$hier_sql = "select
		graph_tree_items.id,
		graph_tree_items.title,
		graph_tree_items.local_graph_id,
		graph_tree_items.rra_id,
		graph_tree_items.host_id,
		graph_tree_items.order_key,
		graph_templates_graph.title_cache as graph_title,
		CONCAT_WS('',host.description,' (',host.hostname,')') as hostname,
		settings_tree.status
		from graph_tree_items
		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)
		left join settings_tree on (graph_tree_items.id=settings_tree.graph_tree_item_id and settings_tree.user_id=$user_id)
		left join host on (graph_tree_items.host_id=host.id)
		$sql_join
		where graph_tree_items.graph_tree_id=$tree_id
		and graph_tree_items.order_key like '$search_key%'
		$sql_where
		order by graph_tree_items.order_key";

	$hierarchy = db_fetch_assoc($hier_sql);

	print "<!-- <P>Building Hierarchy w/ " . sizeof($hierarchy) . " leaves</P>  -->\n";

	html_graph_start_box(0, true);

	print "<tr bgcolor='#" . $colors["header_panel"] . "'><td colspan='30'><table cellspacing='0' cellpadding='3' width='100%'><tr><td class='textHeaderDark'><strong><a class='linkOverDark' href='graph_view.php?action=tree&tree_id=" . $_SESSION["sess_view_tree_id"] . "'>[root]</a> - " . db_fetch_cell("select name from graph_tree where id=" . $_SESSION["sess_view_tree_id"]) . "</strong></td></tr></table></td></tr>";

	$i = 0;

	/* loop through each tree item */
	if (sizeof($hierarchy) > 0) {
	foreach ($hierarchy as $leaf) {
		/* find out how 'deep' this item is */
		$tier = tree_tier($leaf["order_key"]);

		/* find the type of the current branch */
		if ($leaf["title"] != "") { $current_leaf_type = "heading"; }elseif (!empty($leaf["local_graph_id"])) { $current_leaf_type = "graph"; }else{ $current_leaf_type = "host"; }

		/* find the type of the next branch. make sure the next item exists first */
		if (isset($hierarchy{$i+1})) {
			if ($hierarchy{$i+1}["title"] != "") { $next_leaf_type = "heading"; }elseif (!empty($hierarchy{$i+1}["local_graph_id"])) { $next_leaf_type = "graph"; }else{ $next_leaf_type = "host"; }
		}else{
			$next_leaf_type = "";
		}

		if ((($current_leaf_type == 'heading') || ($current_leaf_type == 'host')) && (($tier <= $hide_until_tier) || ($hide_until_tier == false))) {
			$current_title = (($current_leaf_type == "heading") ? $leaf["title"] : $leaf["hostname"]);

			/* draw heading */
			draw_tree_header_row($tree_id, $leaf["id"], $tier, $current_title, true, $leaf["status"], true);

			/* this is an open host, lets expand a bit */
			if (($current_leaf_type == "host") && (empty($leaf["status"]))) {
				/* get a list of all graph templates in use by this host */
				$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"] . "
					group by graph_templates.id
					order by graph_templates.name");

				if (sizeof($graph_templates) > 0) {
				foreach ($graph_templates as $graph_template) {
					draw_tree_header_row($tree_id, $leaf["id"], ($tier+1), $graph_template["name"], false, $leaf["status"], false);

					/* get a list of each graph using this graph template for this particular host */
					$graphs = db_fetch_assoc("select
						graph_templates_graph.title_cache,
						graph_templates_graph.local_graph_id
						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.graph_template_id=" . $graph_template["id"] . "
						and graph_local.host_id=" . $leaf["host_id"] . "
						order by graph_templates_graph.title_cache");

					$graph_ct = 0;
					if (sizeof($graphs) > 0) {
					foreach ($graphs as $graph) {
						/* incriment graph counter so we know when to start a new row or not */
						$graph_ct++;

						if (!isset($graphs[$graph_ct])) { $next_leaf_type = "heading"; }else{ $next_leaf_type = "graph"; }

						/* draw graph */
						$already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, ($tier+2), $graph["local_graph_id"], 1, $graph["title_cache"]);
					}
					}
				}
				}
			}

			$graph_ct = 0;
		}elseif (($current_leaf_type == 'graph') && (($tier <= $hide_until_tier) || ($hide_until_tier == false))) {
			/* incriment graph counter so we know when to start a new row or not */
			$graph_ct++;

			/* draw graph */
			$already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, $tier, $leaf["local_graph_id"], $leaf["rra_id"], $leaf["graph_title"]);
		}

		/* if we have come back to the tier that was origionally flagged, then take away the flag */
		if (($tier <= $hide_until_tier) && ($hide_until_tier != false)) {
			$hide_until_tier = false;
		}

		/* if we are supposed to hide this branch, flag it */
		if (($leaf["status"] == "1") && ($hide_until_tier == false)) {
			$hide_until_tier = $tier;
		}

		$i++;
	}
	}

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

	html_graph_end_box();
}
예제 #3
0
function grow_graph_tree($tree_id, $start_branch, $user_id, $options)
{
    global $colors, $current_user, $config, $graph_timeshifts;
    include $config["include_path"] . "/global_arrays.php";
    include_once $config["library_path"] . "/tree.php";
    $search_key = "";
    $already_open = false;
    $hide_until_tier = false;
    $graph_ct = 0;
    $sql_where = "";
    $sql_join = "";
    /* get the "starting leaf" if the user clicked on a specific branch */
    if ($start_branch != "" && $start_branch != "0") {
        $order_key = db_fetch_cell("select order_key from graph_tree_items where id={$start_branch}");
        $search_key = substr($order_key, 0, tree_tier($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 . " OR graph_tree_items.local_graph_id=0)";
        $sql_join = "left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id)\r\n\t\t\tleft join graph_templates on (graph_templates.id=graph_local.graph_template_id)\r\n\t\t\tleft 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"] . "))";
    }
    /* include time span selector */
    html_start_box("<strong>Graph Filters</strong>", "100%", $colors["header"], "3", "center", "");
    if (read_graph_config_option("timespan_sel") == "on") {
        ?>
		<tr bgcolor="#<?php 
        print $colors["panel"];
        ?>
" class="noprint">
			<td class="noprint">
			<form style="margin:0px;padding:0px;" name="form_timespan_selector" method="post" action="graph_view.php">
				<table width="100%" cellpadding="0" cellspacing="0">
					<tr>
						<td nowrap style='white-space: nowrap;' width='55'>
							&nbsp;<strong>Presets:</strong>&nbsp;
						</td>
						<td nowrap style='white-space: nowrap;' width='130'>
							<select name='predefined_timespan' onChange="applyTimespanFilterChange(document.form_timespan_selector)">
								<?php 
        if ($_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 nowrap style='white-space: nowrap;' width='30'>
							&nbsp;<strong>From:</strong>&nbsp;
						</td>
						<td width='150' nowrap style='white-space: nowrap;'>
							<input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='14' value='<?php 
        print isset($_SESSION["sess_current_date1"]) ? $_SESSION["sess_current_date1"] : "";
        ?>
'>
							&nbsp;<input style='padding-bottom:8px;' type='image' src='images/calendar.gif' align='middle' alt='Start date selector' title='Start date selector' onclick="return showCalendar('date1');">&nbsp;
						</td>
						<td nowrap style='white-space: nowrap;' width='20'>
							&nbsp;<strong>To:</strong>&nbsp;
						</td>
						<td width='150' nowrap style='white-space: nowrap;'>
							<input type='text' name='date2' id='date2' title='Graph End Timestamp' size='14' value='<?php 
        print isset($_SESSION["sess_current_date2"]) ? $_SESSION["sess_current_date2"] : "";
        ?>
'>
							&nbsp;<input style='padding-bottom:8px;' type='image' src='images/calendar.gif' align='middle' alt='End date selector' title='End date selector' onclick="return showCalendar('date2');">
						</td>
						<td width='130' nowrap style='white-space: nowrap;'>
							&nbsp;&nbsp;<input style='padding-bottom:8px;' type='image' name='move_left' src='images/move_left.gif' align='middle' alt='Left' title='Shift Left'>
							<select name='predefined_timeshift' title='Define Shifting Interval' onChange="applyTimespanFilterChange(document.form_timespan_selector)">
								<?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>
							<input style='padding-bottom:8px;' type='image' name='move_right' src='images/move_right.gif' align='middle' alt='Right' title='Shift Right'>
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;&nbsp;<input type='submit' name='button_refresh_x' value='Refresh' title='Refresh selected time span'>
							<input type='submit' name='button_clear_x' value='Clear' title='Return to the default time span'>
						</td>
					</tr>
				</table>
			</form>
			</td>
		</tr>
		<?php 
        html_end_box();
    }
    $hier_sql = "select\r\n\t\tgraph_tree_items.id,\r\n\t\tgraph_tree_items.title,\r\n\t\tgraph_tree_items.local_graph_id,\r\n\t\tgraph_tree_items.rra_id,\r\n\t\tgraph_tree_items.host_id,\r\n\t\tgraph_tree_items.order_key,\r\n\t\tgraph_templates_graph.title_cache as graph_title,\r\n\t\tCONCAT_WS('',host.description,' (',host.hostname,')') as hostname,\r\n\t\tsettings_tree.status\r\n\t\tfrom graph_tree_items\r\n\t\tleft 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)\r\n\t\tleft join settings_tree on (graph_tree_items.id=settings_tree.graph_tree_item_id and settings_tree.user_id={$user_id})\r\n\t\tleft join host on (graph_tree_items.host_id=host.id)\r\n\t\t{$sql_join}\r\n\t\twhere graph_tree_items.graph_tree_id={$tree_id}\r\n\t\tand graph_tree_items.order_key like '{$search_key}%'\r\n\t\t{$sql_where}\r\n\t\torder by graph_tree_items.order_key";
    $hierarchy = db_fetch_assoc($hier_sql);
    print "<!-- <P>Building Hierarchy w/ " . sizeof($hierarchy) . " leaves</P>  -->\n";
    /* include graph view filter selector */
    html_start_box("", "100%", $colors["header"], "1", "center", "");
    print "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t<td colspan='30'>\r\n\t\t\t<table cellspacing='0' cellpadding='3' width='100%'>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td class='textHeaderDark'>\r\n\t\t\t\t\t\t<strong><a class='linkOverDark' href='" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $_SESSION["sess_view_tree_id"]) . "'>[root]</a> - " . db_fetch_cell("select name from graph_tree where id=" . $_SESSION["sess_view_tree_id"]) . "</strong>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\r\n\t\t\t</table>\r\n\t\t</td>\r\n\t</tr>";
    $i = 0;
    /* loop through each tree item */
    if (sizeof($hierarchy) > 0) {
        foreach ($hierarchy as $leaf) {
            /* find out how 'deep' this item is */
            $tier = tree_tier($leaf["order_key"]);
            /* find the type of the current branch */
            if ($leaf["title"] != "") {
                $current_leaf_type = "heading";
            } elseif (!empty($leaf["local_graph_id"])) {
                $current_leaf_type = "graph";
            } else {
                $current_leaf_type = "host";
            }
            /* find the type of the next branch. make sure the next item exists first */
            if (isset($hierarchy[$i + 1])) {
                if ($hierarchy[$i + 1]["title"] != "") {
                    $next_leaf_type = "heading";
                } elseif (!empty($hierarchy[$i + 1]["local_graph_id"])) {
                    $next_leaf_type = "graph";
                } else {
                    $next_leaf_type = "host";
                }
            } else {
                $next_leaf_type = "";
            }
            if (($current_leaf_type == 'heading' || $current_leaf_type == 'host') && ($tier <= $hide_until_tier || $hide_until_tier == false)) {
                $current_title = $current_leaf_type == "heading" ? $leaf["title"] : $leaf["hostname"];
                /* draw heading */
                draw_tree_header_row($tree_id, $leaf["id"], $tier, $current_title, true, $leaf["status"], true);
                /* this is an open host, lets expand a bit */
                if ($current_leaf_type == "host" && empty($leaf["status"])) {
                    /* get a list of all graph templates in use by this host */
                    $graph_templates = db_fetch_assoc("select\r\n\t\t\t\t\tgraph_templates.id,\r\n\t\t\t\t\tgraph_templates.name\r\n\t\t\t\t\tfrom (graph_local,graph_templates,graph_templates_graph)\r\n\t\t\t\t\twhere graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\t\t\tand graph_templates_graph.graph_template_id=graph_templates.id\r\n\t\t\t\t\tand graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t\tgroup by graph_templates.id\r\n\t\t\t\t\torder by graph_templates.name");
                    if (sizeof($graph_templates) > 0) {
                        foreach ($graph_templates as $graph_template) {
                            draw_tree_header_row($tree_id, $leaf["id"], $tier + 1, $graph_template["name"], false, $leaf["status"], false);
                            /* get a list of each graph using this graph template for this particular host */
                            $graphs = db_fetch_assoc("select\r\n\t\t\t\t\t\tgraph_templates_graph.title_cache,\r\n\t\t\t\t\t\tgraph_templates_graph.local_graph_id\r\n\t\t\t\t\t\tfrom (graph_local,graph_templates,graph_templates_graph)\r\n\t\t\t\t\t\twhere graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\t\t\t\tand graph_templates_graph.graph_template_id=graph_templates.id\r\n\t\t\t\t\t\tand graph_local.graph_template_id=" . $graph_template["id"] . "\r\n\t\t\t\t\t\tand graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t\t\torder by graph_templates_graph.title_cache");
                            $graph_ct = 0;
                            if (sizeof($graphs) > 0) {
                                foreach ($graphs as $graph) {
                                    /* incriment graph counter so we know when to start a new row or not */
                                    $graph_ct++;
                                    if (!isset($graphs[$graph_ct])) {
                                        $next_leaf_type = "heading";
                                    } else {
                                        $next_leaf_type = "graph";
                                    }
                                    /* draw graph */
                                    $already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, $tier + 2, $graph["local_graph_id"], 1, $graph["title_cache"]);
                                }
                            }
                        }
                    }
                }
                $graph_ct = 0;
            } elseif ($current_leaf_type == 'graph' && ($tier <= $hide_until_tier || $hide_until_tier == false)) {
                /* incriment graph counter so we know when to start a new row or not */
                $graph_ct++;
                /* draw graph */
                $already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, $tier, $leaf["local_graph_id"], $leaf["rra_id"], $leaf["graph_title"]);
            }
            /* if we have come back to the tier that was origionally flagged, then take away the flag */
            if ($tier <= $hide_until_tier && $hide_until_tier != false) {
                $hide_until_tier = false;
            }
            /* if we are supposed to hide this branch, flag it */
            if ($leaf["status"] == "1" && $hide_until_tier == false) {
                $hide_until_tier = $tier;
            }
            $i++;
        }
    }
    print "</tr></table></td></tr>";
    html_end_box();
}
예제 #4
0
function grow_graph_tree($tree_id, $start_branch, $user_id, $options)
{
    global $current_user, $config, $graph_timeshifts;
    include $config['include_path'] . '/global_arrays.php';
    include_once $config['library_path'] . '/tree.php';
    $search_key = '';
    $already_open = false;
    $hide_until_tier = false;
    $graph_ct = 0;
    $sql_where = '';
    $sql_join = '';
    /* get the "starting leaf" if the user clicked on a specific branch */
    if ($start_branch != '' && $start_branch != '0') {
        $order_key = db_fetch_cell("select order_key from graph_tree_items where id={$start_branch}");
        $search_key = substr($order_key, 0, tree_tier($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 . ' OR graph_tree_items.local_graph_id=0)';
        $sql_join = 'left join graph_local on (graph_templates_graph.local_graph_id=graph_local.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'] . '))';
    }
    /* include time span selector */
    html_start_box('<strong>Graph Filters</strong>' . (strlen(get_request_var_request('filter')) ? " [ Filter '" . htmlspecialchars(get_request_var_request('filter')) . "' Applied ]" : ''), '100%', "", '2', 'center', '');
    if (read_graph_config_option('timespan_sel') == 'on') {
        ?>
		<tr class='even noprint'>
			<td class='noprint'>
			<form style='margin:0px;padding:0px;' name='form_timespan_selector' method='post' action='graph_view.php'>
				<table cellpadding='2' cellspacing='0'>
					<tr>
						<td width='55'>
							Presets:
						</td>
						<td>
							<select name='predefined_timespan' onChange='spanTime()'>
								<?php 
        if ($_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='14' value='<?php 
        print isset($_SESSION['sess_current_date1']) ? $_SESSION['sess_current_date1'] : '';
        ?>
'>
						</td>
						<td>
							<input type='image' src='images/calendar.gif' align='absmiddle' 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='14' value='<?php 
        print isset($_SESSION['sess_current_date2']) ? $_SESSION['sess_current_date2'] : '';
        ?>
'>
						</td>
						<td>
							<input type='image' src='images/calendar.gif' align='absmiddle' 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='absmiddle' alt='' title='Shift Left' onClick='timeshiftFilterLeft()'/>
						</td>
						<td>
							<select 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='absmiddle' alt='' title='Shift Right' onClick='timeshiftFilterRight()'/>
						</td>
						<td>
							<input type='button' value='Refresh' title='Refresh selected time span' onClick='refreshTimespanFilter()'>
						</td>
						<td>
							<input type='button' value='Clear' title='Return to the default time span' onClick='clearTimespanFilter()'>
						</td>
					</tr>
				</table>
			</form>
			</td>
		</tr>
		<?php 
        html_end_box();
    }
    $hier_sql = "select\n\t\tgraph_tree_items.id,\n\t\tgraph_tree_items.title,\n\t\tgraph_tree_items.local_graph_id,\n\t\tgraph_tree_items.rra_id,\n\t\tgraph_tree_items.host_id,\n\t\tgraph_tree_items.order_key,\n\t\tgraph_templates_graph.title_cache as graph_title,\n\t\tCONCAT_WS('',host.description,' (',host.hostname,')') as hostname,\n\t\tsettings_tree.status\n\t\tfrom graph_tree_items\n\t\tleft 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)\n\t\tleft join settings_tree on (graph_tree_items.id=settings_tree.graph_tree_item_id and settings_tree.user_id={$user_id})\n\t\tleft join host on (graph_tree_items.host_id=host.id)\n\t\t{$sql_join}\n\t\twhere graph_tree_items.graph_tree_id={$tree_id}\n\t\tand graph_tree_items.order_key like '{$search_key}%'\n\t\t{$sql_where}\n\t\torder by graph_tree_items.order_key";
    $hierarchy = db_fetch_assoc($hier_sql);
    print "<!-- <P>Building Hierarchy w/ " . sizeof($hierarchy) . " leaves</P>  -->\n";
    /* include graph view filter selector */
    html_start_box('', '100%', "", '1', 'center', '');
    print "<tr class='tableHeader'>\n\t\t<td colspan='30'>\n\t\t\t<table cellspacing='0' cellpadding='3' width='100%'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t<strong><a class='linkOverDark' href='" . htmlspecialchars('graph_view.php?action=tree&tree_id=' . $_SESSION['sess_view_tree_id']) . "'>[root]</a> - " . db_fetch_cell('select name from graph_tree where id=' . $_SESSION['sess_view_tree_id']) . '</strong>
					</td>
				</tr>
			</table>
		</td>
	</tr>';
    $i = 0;
    /* loop through each tree item */
    if (sizeof($hierarchy) > 0) {
        foreach ($hierarchy as $leaf) {
            /* find out how 'deep' this item is */
            $tier = tree_tier($leaf['order_key']);
            /* find the type of the current branch */
            if ($leaf['title'] != '') {
                $current_leaf_type = 'heading';
            } elseif (!empty($leaf['local_graph_id'])) {
                $current_leaf_type = 'graph';
            } else {
                $current_leaf_type = 'host';
            }
            /* find the type of the next branch. make sure the next item exists first */
            if (isset($hierarchy[$i + 1])) {
                if ($hierarchy[$i + 1]['title'] != '') {
                    $next_leaf_type = 'heading';
                } elseif (!empty($hierarchy[$i + 1]['local_graph_id'])) {
                    $next_leaf_type = 'graph';
                } else {
                    $next_leaf_type = 'host';
                }
            } else {
                $next_leaf_type = '';
            }
            if (($current_leaf_type == 'heading' || $current_leaf_type == 'host') && ($tier <= $hide_until_tier || $hide_until_tier == false)) {
                $current_title = $current_leaf_type == 'heading' ? $leaf['title'] : $leaf['hostname'];
                /* draw heading */
                draw_tree_header_row($tree_id, $leaf['id'], $tier, $current_title, true, $leaf['status'], true);
                /* this is an open host, lets expand a bit */
                if ($current_leaf_type == 'host' && empty($leaf['status'])) {
                    /* get a list of all graph templates in use by this host */
                    $graph_templates = db_fetch_assoc("select\n\t\t\t\t\tgraph_templates.id,\n\t\t\t\t\tgraph_templates.name\n\t\t\t\t\tfrom (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\t\twhere graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\tand graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\t\tand graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\tgroup by graph_templates.id\n\t\t\t\t\torder by graph_templates.name");
                    if (sizeof($graph_templates) > 0) {
                        foreach ($graph_templates as $graph_template) {
                            draw_tree_header_row($tree_id, $leaf['id'], $tier + 1, $graph_template['name'], false, $leaf['status'], false);
                            /* get a list of each graph using this graph template for this particular host */
                            $graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_templates_graph.title_cache,\n\t\t\t\t\t\tgraph_templates_graph.local_graph_id\n\t\t\t\t\t\tfrom (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\t\t\twhere graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\tand graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\t\t\tand graph_local.graph_template_id=" . $graph_template["id"] . "\n\t\t\t\t\t\tand graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\torder by graph_templates_graph.title_cache");
                            $graph_ct = 0;
                            if (sizeof($graphs) > 0) {
                                foreach ($graphs as $graph) {
                                    /* incriment graph counter so we know when to start a new row or not */
                                    $graph_ct++;
                                    if (!isset($graphs[$graph_ct])) {
                                        $next_leaf_type = 'heading';
                                    } else {
                                        $next_leaf_type = 'graph';
                                    }
                                    /* draw graph */
                                    $already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, $tier + 2, $graph['local_graph_id'], 1, $graph['title_cache']);
                                }
                            }
                        }
                    }
                }
                $graph_ct = 0;
            } elseif ($current_leaf_type == 'graph' && ($tier <= $hide_until_tier || $hide_until_tier == false)) {
                /* incriment graph counter so we know when to start a new row or not */
                $graph_ct++;
                /* draw graph */
                $already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, $tier, $leaf['local_graph_id'], $leaf['rra_id'], $leaf['graph_title']);
            }
            /* if we have come back to the tier that was origionally flagged, then take away the flag */
            if ($tier <= $hide_until_tier && $hide_until_tier != false) {
                $hide_until_tier = false;
            }
            /* if we are supposed to hide this branch, flag it */
            if ($leaf['status'] == '1' && $hide_until_tier == false) {
                $hide_until_tier = $tier;
            }
            $i++;
        }
    }
    print '</tr></table></td></tr>';
    html_end_box();
}