Example #1
1
function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array, $rrd_struc = array()) {
	global $config;

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

	/* before we do anything; make sure the user has permission to view this graph,
	if not then get out */
	if ((read_config_option("global_auth") == "on") && (isset($_SESSION["sess_user_id"]))) {
		$access_denied = !(is_graph_allowed($local_graph_id));

		if ($access_denied == true) {
			return "GRAPH ACCESS DENIED";
		}
	}

	/* find the step and how often this graph is updated with new data */
	$ds_step = db_fetch_cell("select
		data_template_data.rrd_step
		from data_template_data,data_template_rrd,graph_templates_item
		where graph_templates_item.task_item_id=data_template_rrd.id
		and data_template_rrd.local_data_id=data_template_data.local_data_id
		and graph_templates_item.local_graph_id=$local_graph_id
		limit 0,1");
	$ds_step = empty($ds_step) ? 300 : $ds_step;

	/* if no rra was specified, we need to figure out which one RRDTool will choose using
	 * "best-fit" resolution fit algorithm */
	if (empty($rra_id)) {
		if ((empty($graph_data_array["graph_start"])) || (empty($graph_data_array["graph_end"]))) {
			$rra["rows"] = 600;
			$rra["steps"] = 1;
			$rra["timespan"] = 86400;
		}else{
			/* get a list of RRAs related to this graph */
			$rras = get_associated_rras($local_graph_id);

			if (sizeof($rras) > 0) {
				foreach ($rras as $unchosen_rra) {
					/* the timespan specified in the RRA "timespan" field may not be accurate */
					$real_timespan = ($ds_step * $unchosen_rra["steps"] * $unchosen_rra["rows"]);

					/* make sure the current start/end times fit within each RRA's timespan */
					if ( (($graph_data_array["graph_end"] - $graph_data_array["graph_start"]) <= $real_timespan) && ((time() - $graph_data_array["graph_start"]) <= $real_timespan) ) {
						/* is this RRA better than the already chosen one? */
						if ((isset($rra)) && ($unchosen_rra["steps"] < $rra["steps"])) {
							$rra = $unchosen_rra;
						}else if (!isset($rra)) {
							$rra = $unchosen_rra;
						}
					}
				}
			}

			if (!isset($rra)) {
				$rra["rows"] = 600;
				$rra["steps"] = 1;
			}
		}
	}else{
		$rra = db_fetch_row("select timespan,rows,steps from rra where id=$rra_id");
	}

	$seconds_between_graph_updates = ($ds_step * $rra["steps"]);

	$graph = db_fetch_row("select
		graph_local.host_id,
		graph_local.snmp_query_id,
		graph_local.snmp_index,
		graph_templates_graph.title_cache,
		graph_templates_graph.vertical_label,
		graph_templates_graph.auto_scale,
		graph_templates_graph.auto_scale_opts,
		graph_templates_graph.auto_scale_log,
		graph_templates_graph.auto_scale_rigid,
		graph_templates_graph.auto_padding,
		graph_templates_graph.base_value,
		graph_templates_graph.upper_limit,
		graph_templates_graph.lower_limit,
		graph_templates_graph.height,
		graph_templates_graph.width,
		graph_templates_graph.image_format_id,
		graph_templates_graph.unit_value,
		graph_templates_graph.unit_exponent_value,
		graph_templates_graph.export
		from graph_templates_graph,graph_local
		where graph_local.id=graph_templates_graph.local_graph_id
		and graph_templates_graph.local_graph_id=$local_graph_id");

	/* lets make that sql query... */
	$graph_items = db_fetch_assoc("select
		graph_templates_item.id as graph_templates_item_id,
		graph_templates_item.cdef_id,
		graph_templates_item.text_format,
		graph_templates_item.value,
		graph_templates_item.hard_return,
		graph_templates_item.consolidation_function_id,
		graph_templates_item.graph_type_id,
		graph_templates_gprint.gprint_text,
		colors.hex,
		data_template_rrd.id as data_template_rrd_id,
		data_template_rrd.local_data_id,
		data_template_rrd.rrd_minimum,
		data_template_rrd.rrd_maximum,
		data_template_rrd.data_source_name,
		data_template_rrd.local_data_template_rrd_id
		from graph_templates_item
		left join data_template_rrd on graph_templates_item.task_item_id=data_template_rrd.id
		left join colors on graph_templates_item.color_id=colors.id
		left join graph_templates_gprint on graph_templates_item.gprint_id=graph_templates_gprint.id
		where graph_templates_item.local_graph_id=$local_graph_id
		order by graph_templates_item.sequence");

	/* +++++++++++++++++++++++ GRAPH OPTIONS +++++++++++++++++++++++ */

	/* define some variables */
	$scale = "";
	$rigid = "";
	$unit_exponent_value = "";
	$graph_legend = "";
	$graph_defs = "";
	$txt_graph_items = "";
	$text_padding = "";
	$greatest_text_format = 0;
	$last_graph_type = "";

		if ($graph["auto_scale"] == "on") {
		if ($graph["auto_scale_opts"] == "1") {
			$scale = "--alt-autoscale" . RRD_NL;
		}elseif ($graph["auto_scale_opts"] == "2") {
			$scale = "--alt-autoscale-max" . RRD_NL;
			$scale .= "--lower-limit=" . $graph["lower_limit"] . RRD_NL;
		}

		if ($graph["auto_scale_log"] == "on") {
			$scale .= "--logarithmic" . RRD_NL;
		}
	}else{
		$scale =  "--upper-limit=" . $graph["upper_limit"] . RRD_NL;
		$scale .= "--lower-limit=" . $graph["lower_limit"] . RRD_NL;
	}

	if ($graph["auto_scale_rigid"] == "on") {
		$rigid = "--rigid" . RRD_NL;
	}

	if (!empty($graph["unit_value"])) {
		$unit_value = "--unit=" . $graph["unit_value"] . RRD_NL;
	}

	if (ereg("^[0-9]+$", $graph["unit_exponent_value"])) {
		$unit_exponent_value = "--units-exponent=" . $graph["unit_exponent_value"] . RRD_NL;
	}

	/*
	 * optionally you can specify and array that overrides some of the db's values, lets set
	 * that all up here
	 */

	/* override: graph start time */
	if ((!isset($graph_data_array["graph_start"])) || ($graph_data_array["graph_start"] == "0")) {
		$graph_start = -($rra["timespan"]);
	}else{
		$graph_start = $graph_data_array["graph_start"];
	}

	/* override: graph end time */
	if ((!isset($graph_data_array["graph_end"])) || ($graph_data_array["graph_end"] == "0")) {
		$graph_end = -($seconds_between_graph_updates);
	}else{
		$graph_end = $graph_data_array["graph_end"];
	}

	/* override: graph height (in pixels) */
	if (isset($graph_data_array["graph_height"])) {
		$graph_height = $graph_data_array["graph_height"];
	}else{
		$graph_height = $graph["height"];
	}

	/* override: graph width (in pixels) */
	if (isset($graph_data_array["graph_width"])) {
		$graph_width = $graph_data_array["graph_width"];
	}else{
		$graph_width = $graph["width"];
	}

	/* override: skip drawing the legend? */
	if (isset($graph_data_array["graph_nolegend"])) {
		$graph_legend = "--no-legend" . RRD_NL;
	}else{
		$graph_legend = "";
	}

	/* export options */
	if (isset($graph_data_array["export"])) {
		$graph_opts = read_config_option("path_html_export") . "/" . $graph_data_array["export_filename"] . RRD_NL;
	}else{
		if (empty($graph_data_array["output_filename"])) {
				$graph_opts = "-" . RRD_NL;
		}else{
			$graph_opts = $graph_data_array["output_filename"] . RRD_NL;
		}
	}

	/* setup date format */
	$date_fmt = read_graph_config_option("default_date_format");
	$datechar = read_graph_config_option("default_datechar");

	if ($datechar == GDC_HYPHEN) {
		$datechar = "-";
	}else {
		$datechar = "/";
	}

	switch ($date_fmt) {
		case GD_MO_D_Y:
			$graph_date = "m" . $datechar . "d" . $datechar . "Y H:i:s";
			break;
		case GD_MN_D_Y:
			$graph_date = "M" . $datechar . "d" . $datechar . "Y H:i:s";
			break;
		case GD_D_MO_Y:
			$graph_date = "d" . $datechar . "m" . $datechar . "Y H:i:s";
			break;
		case GD_D_MN_Y:
			$graph_date = "d" . $datechar . "M" . $datechar . "Y H:i:s";
			break;
		case GD_Y_MO_D:
			$graph_date = "Y" . $datechar . "m" . $datechar . "d H:i:s";
			break;
		case GD_Y_MN_D:
			$graph_date = "Y" . $datechar . "M" . $datechar . "d H:i:s";
			break;
	}

	/* display the timespan for zoomed graphs */
	if ((isset($graph_data_array["graph_start"])) && (isset($graph_data_array["graph_end"]))) {
		if (($graph_data_array["graph_start"] < 0) && ($graph_data_array["graph_end"] < 0)) {
			$graph_legend .= "COMMENT:\"From " . date($graph_date, time()+$graph_data_array["graph_start"]) . " To " . date($graph_date, time()+$graph_data_array["graph_end"]) . "\\c\"" . RRD_NL . "COMMENT:\"\\n\"" . RRD_NL;
		}else if (($graph_data_array["graph_start"] >= 0) && ($graph_data_array["graph_end"] >= 0)) {
			$graph_legend .= "COMMENT:\"From " . date($graph_date, $graph_data_array["graph_start"]) . " To " . date($graph_date, $graph_data_array["graph_end"]) . "\\c\"" . RRD_NL . "COMMENT:\"\\n\"" . RRD_NL;
		}
	}

	/* basic graph options */
	$graph_opts .=
		"--imgformat=" . $image_types{$graph["image_format_id"]} . RRD_NL .
		"--start=$graph_start" . RRD_NL .
		"--end=$graph_end" . RRD_NL .
		"--title=\"" . $graph["title_cache"] . "\"" . RRD_NL .
		"$rigid" .
		"--base=" . $graph["base_value"] . RRD_NL .
		"--height=$graph_height" . RRD_NL .
		"--width=$graph_width" . RRD_NL .
		"$scale" .
		"$unit_exponent_value" .
		"$graph_legend" .
		"--vertical-label=\"" . $graph["vertical_label"] . "\"" . RRD_NL;

	$i = 0;
	if (sizeof($graph_items > 0)) {
	foreach ($graph_items as $graph_item) {
		if ((ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_item["graph_type_id"]})) && ($graph_item["data_source_name"] != "")) {
			/* use a user-specified ds path if one is entered */
			$data_source_path = get_data_source_path($graph_item["local_data_id"], true);

			/* FOR WIN32: Escape all colon for drive letters (ex. D\:/path/to/rra) */
			$data_source_path = str_replace(":", "\:", $data_source_path);

			if (!empty($data_source_path)) {
				/* NOTE: (Update) Data source DEF names are created using the graph_item_id; then passed
				to a function that matches the digits with letters. rrdtool likes letters instead
				of numbers in DEF names; especially with CDEF's. cdef's are created
				the same way, except a 'cdef' is put on the beginning of the hash */
				$graph_defs .= "DEF:" . generate_graph_def_name(strval($i)) . "=\"$data_source_path\":" . $graph_item["data_source_name"] . ":" . $consolidation_functions{$graph_item["consolidation_function_id"]} . RRD_NL;

				//print "ds: " . $graph_item["data_template_rrd_id"] . "<br>";
				$cf_ds_cache{$graph_item["data_template_rrd_id"]}{$graph_item["consolidation_function_id"]} = "$i";

				$i++;
			}
		}

		/* +++++++++++++++++++++++ LEGEND: TEXT SUBSITUTION (<>'s) +++++++++++++++++++++++ */

		/* note the current item_id for easy access */
		$graph_item_id = $graph_item["graph_templates_item_id"];

		/* the following fields will be searched for graph variables */
		$variable_fields = array(
			"text_format" => array(
				"process_no_legend" => false
				),
			"value" => array(
				"process_no_legend" => true
				)
			);

		/* loop through each field that we want to substitute values for:
		currently: text format and value */
		while (list($field_name, $field_array) = each($variable_fields)) {
			/* certain fields do not require values when the legend is not to be shown */
			if (($field_array["process_no_legend"] == false) && (isset($graph_data_array["graph_nolegend"]))) {
				continue;
			}

			$graph_variables[$field_name][$graph_item_id] = $graph_item[$field_name];

			/* date/time substitution */
			if (strstr($graph_variables[$field_name][$graph_item_id], "|date_time|")) {
				$graph_variables[$field_name][$graph_item_id] = str_replace("|date_time|", date('D d M H:i:s T Y', strtotime(db_fetch_cell("select value from settings where name='date'"))), $graph_variables[$field_name][$graph_item_id]);
			}

			/* data query variables */
			if (preg_match("/\|query_[a-zA-Z0-9_]+\|/", $graph_variables[$field_name][$graph_item_id])) {
				/* default to the graph data query information from the graph */
				if (empty($graph_item["local_data_id"])) {
					$graph_variables[$field_name][$graph_item_id] = substitute_snmp_query_data($graph_variables[$field_name][$graph_item_id], $graph["host_id"], $graph["snmp_query_id"], $graph["snmp_index"]);
				/* use the data query information from the data source if possible */
				}else{
					$data_local = db_fetch_row("select snmp_index,snmp_query_id,host_id from data_local where id='" . $graph_item["local_data_id"] . "'");
					$graph_variables[$field_name][$graph_item_id] = substitute_snmp_query_data($graph_variables[$field_name][$graph_item_id], $data_local["host_id"], $data_local["snmp_query_id"], $data_local["snmp_index"]);
				}
			}

			/* 95th percentile */
			if (preg_match_all("/\|95:(bits|bytes):(\d):(current|total|max)(:(\d))?\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
				foreach ($matches as $match) {
					$graph_variables[$field_name][$graph_item_id] = str_replace($match[0], variable_ninety_fifth_percentile($match, $graph_item, $graph_items, $graph_start, $graph_end), $graph_variables[$field_name][$graph_item_id]);
				}
			}

			/* bandwidth summation */
			if (preg_match_all("/\|sum:(\d|auto):(current|total|atomic):(\d):(\d+|auto)\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
				foreach ($matches as $match) {
					$graph_variables[$field_name][$graph_item_id] = str_replace($match[0], variable_bandwidth_summation($match, $graph_item, $graph_items, $graph_start, $graph_end, $rra["steps"], $ds_step), $graph_variables[$field_name][$graph_item_id]);
				}
			}
		}

		/* if we are not displaying a legend there is no point in us even processing the auto padding,
		text format stuff. */
		if (!isset($graph_data_array["graph_nolegend"])) {
			/* set hard return variable if selected (\n) */
			if ($graph_item["hard_return"] == "on") {
				$hardreturn[$graph_item_id] = "\\n";
			}else{
				$hardreturn[$graph_item_id] = "";
			}

			/* +++++++++++++++++++++++ LEGEND: AUTO PADDING (<>'s) +++++++++++++++++++++++ */

			/* PADDING: remember this is not perfect! its main use is for the basic graph setup of:
			AREA - GPRINT-CURRENT - GPRINT-AVERAGE - GPRINT-MAXIMUM \n
			of course it can be used in other situations, however may not work as intended.
			If you have any additions to this small peice of code, feel free to send them to me. */
			if ($graph["auto_padding"] == "on") {
				/* only applies to AREA and STACK */
				if (ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_item["graph_type_id"]})) {
					$text_format_lengths{$graph_item["data_template_rrd_id"]} = strlen($graph_variables["text_format"][$graph_item_id]);

					if ((strlen($graph_variables["text_format"][$graph_item_id]) > $greatest_text_format) && ($graph_item_types{$graph_item["graph_type_id"]} != "COMMENT")) {
						$greatest_text_format = strlen($graph_variables["text_format"][$graph_item_id]);
					}
				}
			}
		}
	}
	}

	/* +++++++++++++++++++++++ GRAPH ITEMS: CDEF's +++++++++++++++++++++++ */

	$i = 0;
	reset($graph_items);

	if (sizeof($graph_items) > 0) {
	foreach ($graph_items as $graph_item) {
		/* first we need to check if there is a DEF for the current data source/cf combination. if so,
		we will use that */
		if (isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}{$graph_item["consolidation_function_id"]})) {
			$cf_id = $graph_item["consolidation_function_id"];
		}else{
		/* if there is not a DEF defined for the current data source/cf combination, then we will have to
		improvise. choose the first available cf in the following order: AVERAGE, MAX, MIN, LAST */
			if (isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[1])) {
				$cf_id = 1; /* CF: AVERAGE */
			}elseif (isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[3])) {
				$cf_id = 3; /* CF: MAX */
			}elseif (isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[2])) {
				$cf_id = 2; /* CF: MIN */
			}elseif (isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[4])) {
				$cf_id = 4; /* CF: LAST */
			}else{
				$cf_id = 1; /* CF: AVERAGE */
			}
		}

		/* make cdef string here; a note about CDEF's in cacti. A CDEF is neither unique to a
		data source of global cdef, but is unique when those two variables combine. */
		$cdef_graph_defs = ""; $cdef_total_ds = ""; $cdef_similar_ds = "";

		if ((!empty($graph_item["cdef_id"])) && (!isset($cdef_cache{$graph_item["cdef_id"]}{$graph_item["data_template_rrd_id"]}[$cf_id]))) {
			$cdef_string = get_cdef($graph_item["cdef_id"]);

			/* create cdef string for "total all data sources" if requested */
			if (ereg("ALL_DATA_SOURCES_(NO)?DUPS", $cdef_string)) {
				$item_count = 0;
				for ($t=0;($t<count($graph_items));$t++) {
					if ((ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_items[$t]["graph_type_id"]})) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
						/* if the user screws up CF settings, PHP will generate warnings if left unchecked */
						if (isset($cf_ds_cache{$graph_items[$t]["data_template_rrd_id"]}[$cf_id])) {
							$def_name = generate_graph_def_name(strval($cf_ds_cache{$graph_items[$t]["data_template_rrd_id"]}[$cf_id]));
							$cdef_total_ds .= ($item_count == 0 ? "" : ",") . "TIME," . (time() - $seconds_between_graph_updates) . ",GT,$def_name,$def_name,UN,0,$def_name,IF,IF"; /* convert unknowns to '0' first */
							$item_count++;
						}
					}
				}

				/* if there is only one item to total, don't even bother with the summation. otherwise
				cdef=a,b,c,+,+ is fine. */
				if ($item_count > 1) {
					$cdef_total_ds .= str_repeat(",+", ($item_count - 2)) . ",+";
				}
			}

			/* create cdef string for "total similar data sources" if requested */
			if (ereg("SIMILAR_DATA_SOURCES_(NO)?DUPS", $cdef_string) ) {
				$sources_seen = array();
				$item_count = 0;

				for ($t=0;($t<count($graph_items));$t++) {
					if ((ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_items[$t]["graph_type_id"]})) && (!empty($graph_items[$t]["data_template_rrd_id"])) && ($graph_item["data_source_name"] == $graph_items[$t]["data_source_name"]) && ($graph_item["graph_templates_item_id"] != $graph_items[$t]["graph_templates_item_id"])) {
						/* if the user screws up CF settings, PHP will generate warnings if left unchecked */
						if (isset($cf_ds_cache{$graph_items[$t]["data_template_rrd_id"]}[$cf_id]) && (!isset($sources_seen{$graph_items[$t]["data_template_rrd_id"]}))) {
							$def_name = generate_graph_def_name(strval($cf_ds_cache{$graph_items[$t]["data_template_rrd_id"]}[$cf_id]));
							$cdef_similar_ds .= ($item_count == 0 ? "" : ",") . "TIME," . (time() - $seconds_between_graph_updates) . ",GT,$def_name,$def_name,UN,0,$def_name,IF,IF"; /* convert unknowns to '0' first */
							$sources_seen{$graph_items[$t]["data_template_rrd_id"]} = 1;
							$item_count++;
						}
					}
				}

				/* if there is only one item to total, don't even bother with the summation. otherwise
				cdef=a,b,c,+,+ is fine. */
				if ($item_count > 1) {
					$cdef_similar_ds .= str_repeat(",+", ($item_count - 2)) . ",+";
				}
			}

			$cdef_string = str_replace("CURRENT_DATA_SOURCE", generate_graph_def_name(strval((isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id]) ? $cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id] : "0"))), $cdef_string);
			$cdef_string = str_replace("ALL_DATA_SOURCES_NODUPS", $cdef_total_ds, $cdef_string);
			$cdef_string = str_replace("SIMILAR_DATA_SOURCES_NODUPS", $cdef_similar_ds, $cdef_string);

			/* data source item variables */
			$cdef_string = str_replace("CURRENT_DS_MINIMUM_VALUE", (empty($graph_item["rrd_minimum"]) ? "0" : $graph_item["rrd_minimum"]), $cdef_string);
			$cdef_string = str_replace("CURRENT_DS_MAXIMUM_VALUE", (empty($graph_item["rrd_maximum"]) ? "0" : $graph_item["rrd_maximum"]), $cdef_string);
			$cdef_string = str_replace("CURRENT_GRAPH_MINIMUM_VALUE", (empty($graph["lower_limit"]) ? "0" : $graph["lower_limit"]), $cdef_string);
			$cdef_string = str_replace("CURRENT_GRAPH_MAXIMUM_VALUE", (empty($graph["upper_limit"]) ? "0" : $graph["upper_limit"]), $cdef_string);

			/* make the initial "virtual" cdef name: 'cdef' + [a,b,c,d...] */
			$cdef_graph_defs .= "CDEF:cdef" . generate_graph_def_name(strval($i)) . "=";
			$cdef_graph_defs .= $cdef_string;
			$cdef_graph_defs .= " \\\n";

			/* the CDEF cache is so we do not create duplicate CDEF's on a graph */
			$cdef_cache{$graph_item["cdef_id"]}{$graph_item["data_template_rrd_id"]}[$cf_id] = "$i";
		}

		/* add the cdef string to the end of the def string */
		$graph_defs .= $cdef_graph_defs;

		/* note the current item_id for easy access */
		$graph_item_id = $graph_item["graph_templates_item_id"];

		/* if we are not displaying a legend there is no point in us even processing the auto padding,
		text format stuff. */
		if ((!isset($graph_data_array["graph_nolegend"])) && ($graph["auto_padding"] == "on") && (isset($text_format_lengths{$graph_item["data_template_rrd_id"]}))) {
			/* we are basing how much to pad on area and stack text format,
			not gprint. but of course the padding has to be displayed in gprint,
			how fun! */

			$pad_number = ($greatest_text_format - $text_format_lengths{$graph_item["data_template_rrd_id"]});
			//cacti_log("MAX: $greatest_text_format, CURR: $text_format_lengths[$item_dsid], DSID: $item_dsid");
			$text_padding = str_pad("", $pad_number);

			/* two GPRINT's in a row screws up the padding, lets not do that */
			if (($graph_item_types{$graph_item["graph_type_id"]} == "GPRINT") && ($last_graph_type == "GPRINT")) {
				$text_padding = "";
			}

			$last_graph_type = $graph_item_types{$graph_item["graph_type_id"]};
		}

		/* we put this in a variable so it can be manipulated before mainly used
		if we want to skip it, like below */
		$current_graph_item_type = $graph_item_types{$graph_item["graph_type_id"]};

		/* IF this graph item has a data source... get a DEF name for it, or the cdef if that applies
		to this graph item */
		if ($graph_item["cdef_id"] == "0") {
			if (isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id])) {
				$data_source_name = generate_graph_def_name(strval($cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id]));
			}else{
				$data_source_name = "";
			}
		}else{
			$data_source_name = "cdef" . generate_graph_def_name(strval($cdef_cache{$graph_item["cdef_id"]}{$graph_item["data_template_rrd_id"]}[$cf_id]));
		}

		/* to make things easier... if there is no text format set; set blank text */
		if (!isset($graph_variables["text_format"][$graph_item_id])) {
			$graph_variables["text_format"][$graph_item_id] = "";
		}

		if (!isset($hardreturn[$graph_item_id])) {
			$hardreturn[$graph_item_id] = "";
		}

		/* +++++++++++++++++++++++ GRAPH ITEMS +++++++++++++++++++++++ */

		/* most of the calculations have been done above. now we have for print everything out
		in an RRDTool-friendly fashion */
		if (ereg("^(AREA|STACK|LINE[123])$", $graph_item_types{$graph_item["graph_type_id"]})) {
			$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
			$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . "#" . $graph_item["hex"] . ":" . "\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
		}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "COMMENT") {
			$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
		}elseif (($graph_item_types{$graph_item["graph_type_id"]} == "GPRINT") && (!isset($graph_data_array["graph_nolegend"]))) {
			$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
			$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . ":" . $consolidation_functions{$graph_item["consolidation_function_id"]} . ":\"$text_padding" . $graph_variables["text_format"][$graph_item_id] . $graph_item["gprint_text"] . $hardreturn[$graph_item_id] . "\" ";
		}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "HRULE") {
			$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */
			$graph_variables["value"][$graph_item_id] = str_replace(":", "\:", $graph_variables["value"][$graph_item_id]); /* escape colons */
			$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $graph_variables["value"][$graph_item_id] . "#" . $graph_item["hex"] . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
		}elseif ($graph_item_types{$graph_item["graph_type_id"]} == "VRULE") {
			$graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */

			$value_array = explode(":", $graph_item["value"]);

			if ($value_array[0] < 0) {
				$value = date("U") - (-3600 * $value_array[0]) - 60 * $value_array[1];
			}else{
				$value = date("U", mktime($value_array[0],$value_array[1],0));
			}

			$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $value . "#" . $graph_item["hex"] . ":\"" . $graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id] . "\" ";
		}

		$i++;

		if ($i < sizeof($graph_items)) {
			$txt_graph_items .= RRD_NL;
		}
	}
	}

	/* either print out the source or pass the source onto rrdtool to get us a nice PNG */
	if (isset($graph_data_array["print_source"])) {
		print "<PRE>" . read_config_option("path_rrdtool") . " graph $graph_opts$graph_defs$txt_graph_items</PRE>";
	}else{
		if (isset($graph_data_array["export"])) {
			rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, RRDTOOL_OUTPUT_NULL, $rrd_struc);
			return 0;
		}else{
			if (isset($graph_data_array["output_flag"])) {
				$output_flag = $graph_data_array["output_flag"];
			}else{
				$output_flag = RRDTOOL_OUTPUT_GRAPH_DATA;
			}

			return rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, $output_flag, $rrd_struc);
		}
	}
}
Example #2
0
function get_graph_tree_array($return_sql = false, $force_refresh = false) {

	/* set the tree update time if not already set */
	if (!isset($_SESSION["tree_update_time"])) {
		$_SESSION["tree_update_time"] = time();
	}

	/* build tree array */
	if (!isset($_SESSION["tree_array"]) || ($force_refresh) ||
		(($_SESSION["tree_update_time"] + read_graph_config_option("page_refresh")) < time())) {

		if (read_config_option("auth_method") != "0") {
			$current_user = db_fetch_row("select policy_trees from user_auth where id=" . $_SESSION["sess_user_id"]);

			if ($current_user["policy_trees"] == "1") {
				$sql_where = "where user_auth_perms.user_id is null";
			}elseif ($current_user["policy_trees"] == "2") {
				$sql_where = "where user_auth_perms.user_id is not null";
			}

			$sql = "select
				graph_tree.id,
				graph_tree.name,
				user_auth_perms.user_id
				from graph_tree
				left join user_auth_perms on (graph_tree.id=user_auth_perms.item_id and user_auth_perms.type=2 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")
				$sql_where
				order by graph_tree.name";
		}else{
			$sql = "select * from graph_tree order by name";
		}

		$_SESSION["tree_array"] = $sql;
		$_SESSION["tree_update_time"] = time();
	} else {
		$sql = $_SESSION["tree_array"];
	}

	if ($return_sql == true) {
		return $sql;
	}else{
		return db_fetch_assoc($sql);
	}
}
Example #3
0
function errorimage_check_graphs()
{
    global $config;
    $local_graph_id = $_GET['local_graph_id'];
    $graph_items = db_fetch_assoc("select\r\n\t\tdata_template_rrd.local_data_id\r\n\t\tfrom graph_templates_item\r\n\t\tleft join data_template_rrd on (graph_templates_item.task_item_id=data_template_rrd.id)\r\n\t\twhere graph_templates_item.local_graph_id={$local_graph_id}\r\n\t\torder by graph_templates_item.sequence");
    $ids = array();
    foreach ($graph_items as $graph) {
        if ($graph['local_data_id'] != '') {
            $ids[] = $graph['local_data_id'];
        }
    }
    $ids = array_unique($ids);
    if (!empty($_GET["graph_nolegend"])) {
        $height = read_graph_config_option("default_height") + 62;
        $width = read_graph_config_option("default_width") + 95;
    } else {
        $hw = db_fetch_row("SELECT width, height \r\n\t\t\tFROM graph_templates_graph \r\n\t\t\tWHERE local_graph_id=" . $_GET['local_graph_id']);
        $hr = db_fetch_cell("SELECT count(*) FROM graph_templates_item WHERE local_graph_id=" . $_GET['local_graph_id'] . " AND hard_return='on'");
        $height = $hw['height'] + 16 * $hr + 90;
        // # hard rules, plus room for date
        $width = $hw['width'] + 95;
    }
    foreach ($ids as $id => $local_data_id) {
        $data_source_path = get_data_source_path($local_data_id, true);
        if (!file_exists($data_source_path)) {
            $filename = $config['base_path'] . '/plugins/errorimage/images/no-datasource.png';
            if (function_exists("imagecreatefrompng")) {
                echo errorimage_resize_png($filename, $width, $height);
            } else {
                $file = fopen($filename, 'rb');
                echo fread($file, filesize($filename));
                fclose($file);
            }
            exit;
        }
    }
}
Example #4
0
function html_graph_thumbnail_area(&$graph_array, $no_graphs_message = "", $extra_url_args = "", $header = "") {
	$i = 0; $k = 0;
	if (sizeof($graph_array) > 0) {
		if ($header != "") {
			print $header;
		}

		print "<tr>";

		foreach ($graph_array as $graph) {
			?>
			<td align='center' width='<?php print (98 / read_graph_config_option("num_columns"));?>%'>
				<table width='1' cellpadding='0'>
					<tr>
						<td>
							<a href='graph.php?rra_id=all&local_graph_id=<?php print $graph["local_graph_id"];?>'><img src='graph_image.php?local_graph_id=<?php print $graph["local_graph_id"];?>&rra_id=0&graph_height=<?php print read_graph_config_option("default_height");?>&graph_width=<?php print read_graph_config_option("default_width");?>&graph_nolegend=true<?php print (($extra_url_args == "") ? "" : "&$extra_url_args");?>' border='0' alt='<?php print $graph["title_cache"];?>'></a>
						</td>
						<td valign='top' style='padding: 3px;'>
							<a href='graph.php?action=zoom&local_graph_id=<?php print $graph["local_graph_id"];?>&rra_id=0&<?php print $extra_url_args;?>'><img src='images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
						</td>
					</tr>
				</table>
			</td>
			<?php

			$i++;
			$k++;

			if (($i == read_graph_config_option("num_columns")) && ($k < count($graph_array))) {
				$i = 0;
				print "</tr><tr>";
			}
		}

		print "</tr>";
	}else{
		if ($no_graphs_message != "") {
			print "<td><em>$no_graphs_message</em></td>";
		}
	}
}
Example #5
0
			}

			/* override: graph end time (unix time) */
			if (!empty($_GET["graph_end"])) {
				$graph_data_array["graph_end"] = $_GET["graph_end"];
			}

			print trim(rrdtool_function_graph($_GET["local_graph_id"], $_GET["rra_id"], $graph_data_array));
			?>
		</td>
	</tr>
	<?php }?>

	<tr>
		<?php if ((read_graph_config_option("default_tree_view_mode") == "2") && (($_REQUEST["action"] == "tree") || ((isset($_REQUEST["view_type"]) ? $_REQUEST["view_type"] : "") == "tree"))) { ?>
		<td valign="top" style="padding: 5px; border-right: #aaaaaa 1px solid;" bgcolor='#efefef' width='<?php print read_graph_config_option("default_dual_pane_width");?>' class='noprint'>
			<table border=0 cellpadding=0 cellspacing=0><tr><td><font size=-2><a style="font-size:7pt;text-decoration:none;color:silver" href="http://www.treemenu.net/" target=_blank></a></font></td></tr></table>
			<?php grow_dhtml_trees(); ?>
			<script type="text/javascript">initializeDocument();</script>

			<?php if (isset($_GET["select_first"])) { ?>
			<script type="text/javascript">
			var obj;
			obj = findObj(1);

			if (!obj.isOpen) {
				clickOnNode(1);
			}

			clickOnLink(2,'','main');
			</script>
Example #6
0
/** date_time_format		create a format string for date/time
 * @param string returns	date time format
 */
function date_time_format() {
	require_once(CACTI_BASE_PATH . "/include/graph/graph_constants.php");
	global $config;

	$graph_date = "";

	/* setup date format */
	$date_fmt = read_graph_config_option("default_date_format");
	$datechar = read_graph_config_option("default_datechar");

	switch ($datechar) {
		case GDC_HYPHEN: 	$datechar = "-"; break;
		case GDC_SLASH: 	$datechar = "/"; break;
		case GDC_DOT:	 	$datechar = "."; break;
	}

	switch ($date_fmt) {
		case GD_MO_D_Y:
			$graph_date = "m" . $datechar . "d" . $datechar . "Y H:i:s";
			break;
		case GD_MN_D_Y:
			$graph_date = "M" . $datechar . "d" . $datechar . "Y H:i:s";
			break;
		case GD_D_MO_Y:
			$graph_date = "d" . $datechar . "m" . $datechar . "Y H:i:s";
			break;
		case GD_D_MN_Y:
			$graph_date = "d" . $datechar . "M" . $datechar . "Y H:i:s";
			break;
		case GD_Y_MO_D:
			$graph_date = "Y" . $datechar . "m" . $datechar . "d H:i:s";
			break;
		case GD_Y_MN_D:
			$graph_date = "Y" . $datechar . "M" . $datechar . "d H:i:s";
			break;
	}
	return $graph_date;
}
Example #7
0
function html_graph_thumbnail_area(&$graph_array, $no_graphs_message = "", $extra_url_args = "", $header = "")
{
    $i = 0;
    $k = 0;
    $j = 0;
    $num_graphs = sizeof($graph_array);
    if ($num_graphs > 0) {
        if ($header != "") {
            print $header;
        }
        $start = true;
        foreach ($graph_array as $graph) {
            if (isset($graph["graph_template_name"])) {
                if (isset($prev_graph_template_name)) {
                    if ($prev_graph_template_name != $graph["graph_template_name"]) {
                        $print = true;
                        $prev_graph_template_name = $graph["graph_template_name"];
                    } else {
                        $print = false;
                    }
                } else {
                    $print = true;
                    $prev_graph_template_name = $graph["graph_template_name"];
                }
                if ($print) {
                    if (!$start) {
                        while ($i % read_graph_config_option("num_columns") != 0) {
                            print "<td align='center' width='" . ceil(100 / read_graph_config_option("num_columns")) . "%'></td>";
                            $i++;
                        }
                        print "</tr>";
                    }
                    print "<tr style='background-color:#a9b7cb;'>\n\t\t\t\t\t\t<td style='background-color:#a9b7cb;' colspan='" . read_graph_config_option("num_columns") . "' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>Graph Template:</strong> " . $graph["graph_template_name"] . "\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
                    $i = 0;
                }
            } elseif (isset($graph["data_query_name"])) {
                if (isset($prev_data_query_name)) {
                    if ($prev_data_query_name != $graph["data_query_name"]) {
                        $print = true;
                        $prev_data_query_name = $graph["data_query_name"];
                    } else {
                        $print = false;
                    }
                } else {
                    $print = true;
                    $prev_data_query_name = $graph["data_query_name"];
                }
                if ($print) {
                    if (!$start) {
                        while ($i % read_graph_config_option("num_columns") != 0) {
                            print "<td align='center' width='" . ceil(100 / read_graph_config_option("num_columns")) . "%'></td>";
                            $i++;
                        }
                        print "</tr>";
                    }
                    print "<tr style='background-color:#a9b7cb;'>\n\t\t\t\t\t\t\t<td style='background-color:#a9b7cb;' colspan='" . read_graph_config_option("num_columns") . "' class='textHeaderDark'><strong>Data Query:</strong> " . $graph["data_query_name"] . "</td>\n\t\t\t\t\t\t</tr>";
                    $i = 0;
                }
                if (!isset($prev_sort_field_value) || $prev_sort_field_value != $graph["sort_field_value"]) {
                    $prev_sort_field_value = $graph["sort_field_value"];
                    print "<tr style='background-color:#a9b7cb;'>\n\t\t\t\t\t\t<td style='background-color:#a9b7cb;' colspan='" . read_graph_config_option("num_columns") . "' class='textHeaderDark'>\n\t\t\t\t\t\t\t" . $graph["sort_field_value"] . "\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
                    $i = 0;
                    $j = 0;
                }
            }
            if ($i == 0) {
                print "<tr style='background-color: #" . ($j % 2 == 0 ? "F2F2F2" : "FFFFFF") . ";'>";
                $start = false;
            }
            ?>
			<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";
            ?>
;"><a href='<?php 
            print $config['url_path'];
            ?>
graph.php?action=view&rra_id=all&local_graph_id=<?php 
            print $graph["local_graph_id"];
            ?>
'><img class='graphimage' id='graph_<?php 
            print $graph["local_graph_id"];
            ?>
' src='<?php 
            print $config['url_path'];
            ?>
graph_image.php?local_graph_id=<?php 
            print $graph["local_graph_id"];
            ?>
&rra_id=0&graph_height=<?php 
            print read_graph_config_option("default_height");
            ?>
&graph_width=<?php 
            print read_graph_config_option("default_width");
            ?>
&graph_nolegend=true<?php 
            print $extra_url_args == "" ? "" : "&{$extra_url_args}";
            ?>
' border='0' alt='<?php 
            print $graph["title_cache"];
            ?>
'></a></div>
							<?php 
            print read_graph_config_option("show_graph_title") == "on" ? "<p style='font-size: 10;' align='center'><strong>" . $graph["title_cache"] . "</strong></p>" : "";
            ?>
						</td>
						<td valign='top' style='align: left; padding: 3px;'>
							<a href='graph.php?action=zoom&local_graph_id=<?php 
            print $graph["local_graph_id"];
            ?>
&rra_id=0&<?php 
            print $extra_url_args;
            ?>
'><img src='images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
							<a href='graph_xport.php?local_graph_id=<?php 
            print $graph["local_graph_id"];
            ?>
&rra_id=0&<?php 
            print $extra_url_args;
            ?>
'><img src='images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
							<a href='graph.php?action=properties&local_graph_id=<?php 
            print $graph["local_graph_id"];
            ?>
&rra_id=0&<?php 
            print $extra_url_args;
            ?>
'><img src='images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a><br>
							<a href='#page_top'><img src='images/graph_page_top.gif' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br>
						</td>
					</tr>
				</table>
			</td>
			<?php 
            $i++;
            $k++;
            if ($i % read_graph_config_option("num_columns") == 0 && $k < $num_graphs) {
                $i = 0;
                $j++;
                print "</tr>";
                $start = true;
            }
        }
        if (!$start) {
            while ($i % read_graph_config_option("num_columns") != 0) {
                print "<td align='center' width='" . ceil(100 / read_graph_config_option("num_columns")) . "%'></td>";
                $i++;
            }
            print "</tr>";
        }
    } else {
        if ($no_graphs_message != "") {
            print "<td><em>{$no_graphs_message}</em></td>";
        }
    }
}
Example #8
0
	}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"));

	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"));
	input_validate_input_number(get_request_var_request("graph_template_id"));
	/* ==================================================== */

	/* clean up search string */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
	}
Example #9
0
        ?>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr class="noprint">
		<td bgcolor="#efefef" colspan="1" height="8" style="background-image: url(<?php 
        echo $config['url_path'];
        ?>
images/shadow_gray.gif); background-repeat: repeat-x; border-right: #aaaaaa 1px solid;">
			<img src="<?php 
        echo $config['url_path'];
        ?>
images/transparent_line.gif" width="<?php 
        print read_graph_config_option("default_dual_pane_width");
        ?>
" height="2" border="0"><br>
		</td>
		<td bgcolor="#ffffff" colspan="1" height="8" style="background-image: url(<?php 
        echo $config['url_path'];
        ?>
images/shadow.gif); background-repeat: repeat-x;">

		</td>
	</tr>
<?php 
    }
    ?>
	<tr>
		<td valign="top" style="padding: 5px; border-right: #aaaaaa 1px solid;"><div style='position:relative;' id='main'>
Example #10
0
				</tr>
			</table>
			<input type='hidden' name='graph_add' value=''>
			<input type='hidden' name='graph_remove' value=''>
			<input type='hidden' name='graph_list' value='<?php 
        print $_REQUEST['graph_list'];
        ?>
'>
		</form>
		</td>
	</tr>
	<?php 
        html_end_box();
        /* if the number of rows is -1, set it to the default */
        if ($_REQUEST['rows'] == -1) {
            $_REQUEST['rows'] = read_graph_config_option('list_graphs_per_page');
        }
        /* create filter for sql */
        $sql_filter = '';
        $sql_filter .= empty($_REQUEST['filter']) ? '' : " graph_templates_graph.title_cache like '%" . get_request_var_request('filter') . "%'";
        $sql_filter .= empty($_REQUEST['host_id']) ? '' : (empty($sql_filter) ? '' : ' and') . ' graph_local.host_id=' . get_request_var_request('host_id');
        $sql_filter .= empty($_REQUEST['graph_template_id']) ? '' : (empty($sql_filter) ? '' : ' and') . ' graph_local.graph_template_id=' . get_request_var_request('graph_template_id');
        /* graph permissions */
        if (read_config_option('auth_method') != 0) {
            /* get policy information for the sql where clause */
            $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 = '';
Example #11
0
function set_timeshift()
{
    global $config, $graph_timeshifts;
    # no current timeshift: get default timeshift
    if (!isset($_SESSION["sess_current_timeshift"]) || read_graph_config_option("timespan_sel") == "" || isset($_POST["button_clear_x"])) {
        $_SESSION["sess_current_timeshift"] = read_graph_config_option("default_timeshift");
        $_REQUEST["predefined_timeshift"] = read_graph_config_option("default_timeshift");
        $_SESSION["custom"] = 0;
    }
    return $timeshift = $graph_timeshifts[$_SESSION["sess_current_timeshift"]];
}
Example #12
0
File: rrd.php Project: MrWnn/cacti
function rrdtool_function_set_font($type, $no_legend, $themefonts)
{
    global $config;
    if (read_config_option('font_method') == 0) {
        if (read_graph_config_option("custom_fonts") == "on") {
            $font = read_graph_config_option($type . "_font");
            $size = read_graph_config_option($type . "_size");
        } else {
            $font = read_config_option($type . "_font");
            $size = read_config_option($type . "_size");
        }
    } elseif (isset($themefonts[$type]['font']) && isset($themefonts[$type]['size'])) {
        $font = $themefonts[$type]['font'];
        $size = $themefonts[$type]['size'];
    } else {
        return;
    }
    if (strlen($font)) {
        /* do some simple checks */
        if (read_config_option("rrdtool_version") == "rrd-1.2.x") {
            # rrdtool 1.2 uses font files
            if (!is_file($font)) {
                $font = "";
            }
        } else {
            # rrdtool 1.3+ use fontconfig
            /* verifying all possible pango font params is too complex to be tested here
             * so we only escape the font
             */
            $font = cacti_escapeshellarg($font);
        }
    }
    if ($type == "title") {
        if (!empty($no_legend)) {
            $size = $size * 0.7;
        } elseif ($size <= 4 || !is_numeric($size)) {
            $size = 12;
        }
    } else {
        if ($size <= 4 || !is_numeric($size)) {
            $size = 8;
        }
    }
    return "--font " . strtoupper($type) . ":" . floatval($size) . ":" . $font . RRD_NL;
}
Example #13
0
function form_actions() {
	global $colors, $graph_actions;
	/* if we are to save this form, instead of display it */
	if (isset($_POST["selected_items"])) {
		$selected_items = unserialize(stripslashes($_POST["selected_items"]));

		if ($_POST["drp_action"] == "1") { /* delete */
			for ($i=0;($i<count($selected_items));$i++) {
				if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; }

				switch ($_POST["delete_type"]) {
					case '2': /* delete all data sources referenced by this graph */
						$data_sources = db_fetch_assoc("select
							data_template_data.local_data_id
							from data_template_rrd,data_template_data,graph_templates_item
							where graph_templates_item.task_item_id=data_template_rrd.id
							and data_template_rrd.local_data_id=data_template_data.local_data_id
							and " . array_to_sql_or($selected_items, "graph_templates_item.local_graph_id") . "
							and data_template_data.local_data_id > 0
							group by data_template_data.local_data_id");

						if (sizeof($data_sources) > 0) {
							foreach ($data_sources as $data_source) {
								api_data_source_remove($data_source["local_data_id"]);
							}
						}

						break;
				}

				api_graph_remove($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "2") { /* change graph template */
			for ($i=0;($i<count($selected_items));$i++) {
				change_graph_template($selected_items[$i], $_POST["graph_template_id"], true);
			}
		}elseif ($_POST["drp_action"] == "3") { /* duplicate */
			for ($i=0;($i<count($selected_items));$i++) {
				duplicate_graph($selected_items[$i], 0, $_POST["title_format"]);
			}
		}elseif ($_POST["drp_action"] == "4") { /* graph -> graph template */
			for ($i=0;($i<count($selected_items));$i++) {
				graph_to_graph_template($selected_items[$i], $_POST["title_format"]);
			}
		}elseif (ereg("^tr_([0-9]+)$", $_POST["drp_action"], $matches)) { /* place on tree */
			for ($i=0;($i<count($selected_items));$i++) {
				api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
			}
		}elseif ($_POST["drp_action"] == "5") { /* change host */
			for ($i=0;($i<count($selected_items));$i++) {
				db_execute("update graph_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]);
				update_graph_title_cache($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "6") { /* reapply suggested naming */
			for ($i=0;($i<count($selected_items));$i++) {
				api_reapply_suggested_graph_title($selected_items[$i]);
				update_graph_title_cache($selected_items[$i]);
			}
		}

		header("Location: graphs.php");
		exit;
	}

	/* setup some variables */
	$graph_list = ""; $i = 0;

	/* loop through each of the graphs selected on the previous page and get more info about them */
	while (list($var,$val) = each($_POST)) {
		if (ereg("^chk_([0-9]+)$", $var, $matches)) {
			$graph_list .= "<li>" . get_graph_title($matches[1]) . "<br>";
			$graph_array[$i] = $matches[1];
		}

		$i++;
	}

	include_once("./include/top_header.php");

	/* add a list of tree names to the actions dropdown */
	add_tree_names_to_actions_array();

	html_start_box("<strong>" . $graph_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", "");

	print "<form action='graphs.php' method='post'>\n";

	if ($_POST["drp_action"] == "1") { /* delete */
		$graphs = array();

		/* find out which (if any) data sources are being used by this graph, so we can tell the user */
		if (isset($graph_array)) {
			$data_sources = db_fetch_assoc("select
				data_template_data.local_data_id,
				data_template_data.name_cache
				from data_template_rrd,data_template_data,graph_templates_item
				where graph_templates_item.task_item_id=data_template_rrd.id
				and data_template_rrd.local_data_id=data_template_data.local_data_id
				and " . array_to_sql_or($graph_array, "graph_templates_item.local_graph_id") . "
				and data_template_data.local_data_id > 0
				group by data_template_data.local_data_id
				order by data_template_data.name_cache");
		}

		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Are you sure you want to delete the following graphs?</p>
					<p>$graph_list</p>
					";
					if (sizeof($data_sources) > 0) {
						print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>The following data sources are in use by these graphs:</p>\n";

						foreach ($data_sources as $data_source) {
							print "<strong>" . $data_source["name_cache"] . "</strong><br>\n";
						}

						print "<br>";
						form_radio_button("delete_type", "1", "1", "Leave the data sources untouched.", "1"); print "<br>";
						form_radio_button("delete_type", "1", "2", "Delete all <strong>data sources</strong> referenced by these graphs.", "1"); print "<br>";
						print "</td></tr>";
					}
				print "
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "2") { /* change graph template */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Choose a graph template and click save to change the graph template for
					the following graphs. Be aware that all warnings will be suppressed during the
					conversion, so graph data loss is possible.</p>
					<p>$graph_list</p>
					<p><strong>New Graph Template:</strong><br>"; form_dropdown("graph_template_id",db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates"),"name","id","","","0"); print "</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "3") { /* duplicate */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be duplicated. You can
					optionally change the title format for the new graphs.</p>
					<p>$graph_list</p>
					<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<graph_title> (1)", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "4") { /* graph -> graph template */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be converted into graph templates.
					You can optionally change the title format for the new graph templates.</p>
					<p>$graph_list</p>
					<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<graph_title> Template", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}elseif (ereg("^tr_([0-9]+)$", $_POST["drp_action"], $matches)) { /* place on tree */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be placed under the branch selected
					below.</p>
					<p>$graph_list</p>
					<p><strong>Destination Branch:</strong><br>"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "</p>
				</td>
			</tr>\n
			<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n
			";
	}elseif ($_POST["drp_action"] == "5") { /* change host */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Choose a new host for these graphs:</p>
					<p>$graph_list</p>
					<p><strong>New Host:</strong><br>"; form_dropdown("host_id",db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"),"name","id","","","0"); print "</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "6") { /* reapply suggested naming to host */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will have thier suggested naming convensions
					recalculated and applies to the graphs.</p>
					<p>$graph_list</p>
				</td>
			</tr>\n
			";
	}

	if (!isset($graph_array)) {
		print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
		$save_html = "";
	}else{
		$save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>";
	}

	print "	<tr>
			<td align='right' bgcolor='#eaeaea'>
				<input type='hidden' name='action' value='actions'>
				<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>
				<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>
				<a href='graphs.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a>
				$save_html
			</td>
		</tr>
		";

	html_end_box();

	include_once("./include/bottom_footer.php");
}
Example #14
0
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/
global $config, $refresh;
$script = basename($_SERVER['SCRIPT_NAME']);
if ($script == 'graph_view.php' || $script == 'graph.php') {
    if (isset($_SESSION['custom']) && $_SESSION['custom'] == true) {
        $refreshIsLogout = 'true';
    } else {
        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'zoom') {
            $refreshIsLogout = 'true';
        } else {
            $refresh = api_plugin_hook_function('top_graph_refresh', read_graph_config_option('page_refresh'));
            $refreshIsLogout = 'false';
        }
    }
} elseif (strstr($_SERVER['SCRIPT_NAME'], 'plugins')) {
    $refresh = api_plugin_hook_function('top_graph_refresh', $refresh);
    if (empty($refresh)) {
        $refreshIsLogout = 'true';
    } else {
        $refreshIsLogout = 'false';
    }
}
if (!empty($refresh)) {
    $refreshIsLogout = 'false';
    if (!is_array($refresh)) {
        $myrefresh['seconds'] = $refresh;
	<tr bgcolor="<?php print $colors["panel"];?>">
		<form name="form_graph_id" method="post">
		<td colspan='<?php print read_graph_config_option("num_columns");?>'>
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td width="120" class="textHeader">
						Filter by host:&nbsp;
					</td>
					<td width="1">
						<select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value">
							<option value="graph_view.php?action=preview&host_id=0&filter=<?php print $_REQUEST["filter"];?>"<?php if ($_REQUEST["host_id"] == "0") {?> selected<?php }?>>None</option>

							<?php
							$hosts = get_host_array();

							if (sizeof($hosts) > 0) {
							foreach ($hosts as $host) {
								print "<option value='graph_view.php?action=preview&host_id=" . $host["id"] . "&filter=" . $_REQUEST["filter"] . "'"; if ($_REQUEST["host_id"] == $host["id"]) { print " selected"; } print ">" . $host["name"] . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td width="5"></td>
					<td width="1">
						<input type="text" name="filter" size="20" value="<?php print $_REQUEST["filter"];?>">
					</td>
					<td>
						&nbsp;<input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle">
					</td>
				</tr>
Example #16
0
function draw_tree_dropdown($current_tree_id) {
	global $colors;

	$html = "";

	$tree_list = get_graph_tree_array();

	if (isset($_GET["tree_id"])) {
		$_SESSION["sess_view_tree_id"] = $current_tree_id;
	}

	/* if there is a current tree, make sure it still exists before going on */
	if ((!empty($_SESSION["sess_view_tree_id"])) && (db_fetch_cell("select id from graph_tree where id=" . $_SESSION["sess_view_tree_id"]) == "")) {
		$_SESSION["sess_view_tree_id"] = 0;
	}

	/* set a default tree if none is already selected */
	if (empty($_SESSION["sess_view_tree_id"])) {
		if (db_fetch_cell("select id from graph_tree where id=" . read_graph_config_option("default_tree_id")) > 0) {
			$_SESSION["sess_view_tree_id"] = read_graph_config_option("default_tree_id");
		}else{
			if (sizeof($tree_list) > 0) {
				$_SESSION["sess_view_tree_id"] = $tree_list[0]["id"];
			}
		}
	}

	/* make the dropdown list of trees */
	if (sizeof($tree_list) > 1) {
		$html ="<form name='form_tree_id'>
			<td valign='middle' height='30' bgcolor='#" . $colors["panel"] . "'>\n
				<table width='100%' cellspacing='0' cellpadding='0'>\n
					<tr>\n
						<td width='200' class='textHeader'>\n
							&nbsp;&nbsp;Select a Graph Hierarchy:&nbsp;\n
						</td>\n
						<td bgcolor='#" . $colors["panel"] . "'>\n
							<select name='cbo_tree_id' onChange='window.location=document.form_tree_id.cbo_tree_id.options[document.form_tree_id.cbo_tree_id.selectedIndex].value'>\n";

		foreach ($tree_list as $tree) {
			$html .= "<option value='graph_view.php?action=tree&tree_id=" . $tree["id"] . "'";
				if ($_SESSION["sess_view_tree_id"] == $tree["id"]) { $html .= " selected"; }
				$html .= ">" . $tree["name"] . "</option>\n";
			}

		$html .= "</select>\n";
		$html .= "</td></tr></table></td></form>\n";
	}elseif (sizeof($tree_list) == 1) {
		/* there is only one tree; use it */
		//print "	<td valign='middle' height='5' colspan='3' bgcolor='#" . $colors["panel"] . "'>";
	}

	return $html;
}
Example #17
0
function form_actions()
{
    global $colors, $graph_actions;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        if ($_POST["drp_action"] == "1") {
            /* delete */
            for ($i = 0; $i < count($selected_items); $i++) {
                if (!isset($_POST["delete_type"])) {
                    $_POST["delete_type"] = 1;
                }
                switch ($_POST["delete_type"]) {
                    case '2':
                        /* delete all data sources referenced by this graph */
                        $data_sources = db_fetch_assoc("select distinct\n\t\t\t\t\t\t\tdata_source.id\n\t\t\t\t\t\t\tfrom data_source_item,data_source,graph_item\n\t\t\t\t\t\t\twhere graph_item.data_source_item_id=data_source_item.id\n\t\t\t\t\t\t\tand data_source_item.data_source_id=data_source.id\n\t\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "graph_item.graph_id") . "\n\t\t\t\t\t\t\torder by data_source.name_cache");
                        if (sizeof($data_sources) > 0) {
                            foreach ($data_sources as $data_source) {
                                api_data_source_remove($data_source["id"]);
                            }
                        }
                        break;
                }
                api_graph_remove($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                change_graph_template($selected_items[$i], $_POST["graph_template_id"], true);
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                duplicate_graph($selected_items[$i], 0, $_POST["title_format"]);
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* graph -> graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                graph_to_graph_template($selected_items[$i], $_POST["title_format"]);
            }
        } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* change host */
            for ($i = 0; $i < count($selected_items); $i++) {
                db_execute("update graph set host_id = " . $_POST["host_id"] . " where id = " . $selected_items[$i]);
                api_graph_title_cache_update($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* reapply suggested naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_reapply_suggested_graph_title($selected_items[$i]);
                api_graph_title_cache_update($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "7") {
            /* resize graphs */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_graph_resize($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
            }
        }
        header("Location: graphs.php");
        exit;
    }
    /* setup some variables */
    $graph_list = "";
    $i = 0;
    /* loop through each of the graphs selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (ereg("^chk_([0-9]+)\$", $var, $matches)) {
            $graph_list .= "<li>" . db_fetch_cell("select title_cache from graph where id = " . $matches[1]) . "<br>";
            $graph_array[$i] = $matches[1];
        }
        $i++;
    }
    require_once CACTI_BASE_PATH . "/include/top_header.php";
    html_start_box("<strong>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel_background"], "3", "center", "");
    print "<form action='graphs.php' method='post'>\n";
    if ($_POST["drp_action"] == "1") {
        /* delete */
        $graphs = array();
        /* find out which (if any) data sources are being used by this graph, so we can tell the user */
        if (isset($graph_array)) {
            $data_sources = db_fetch_assoc("select distinct\n\t\t\t\tdata_source.id,\n\t\t\t\tdata_source.name_cache\n\t\t\t\tfrom data_source_item,data_source,graph_item\n\t\t\t\twhere graph_item.data_source_item_id=data_source_item.id\n\t\t\t\tand data_source_item.data_source_id=data_source.id\n\t\t\t\tand " . array_to_sql_or($graph_array, "graph_item.graph_id") . "\n\t\t\t\torder by data_source.name_cache");
        }
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("Are you sure you want to delete the following graphs?") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t";
        if (sizeof($data_sources) > 0) {
            print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>" . _("The following data sources are in use by these graphs:") . "</p>\n";
            foreach ($data_sources as $data_source) {
                print "<strong>" . $data_source["name_cache"] . "</strong><br>\n";
            }
            print "<br>";
            form_radio_button("delete_type", "1", "1", _("Leave the data sources untouched."), "1");
            print "<br>";
            form_radio_button("delete_type", "1", "2", _("Delete all <strong>data sources</strong> referenced by these graphs."), "1");
            print "<br>";
            print "</td></tr>";
        }
        print "\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "2") {
        /* change graph template */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("Choose a graph template and click save to change the graph template for\n\t\t\t\t\tthe following graphs. Be aware that all warnings will be suppressed during the\n\t\t\t\t\tconversion, so graph data loss is possible.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("New Graph Template:") . "</strong><br>";
        form_dropdown("graph_template_id", db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates"), "name", "id", "", "", "0");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "3") {
        /* duplicate */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("When you click save, the following graphs will be duplicated. You can\n\t\t\t\t\toptionally change the title format for the new graphs.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Title Format:") . "</strong><br>";
        form_text_box("title_format", "<graph_title> (1)", "", "255", "30", "text");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "4") {
        /* graph -> graph template */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("When you click save, the following graphs will be converted into graph templates.\n\t\t\t\t\tYou can optionally change the title format for the new graph templates.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Title Format:") . "</strong><br>";
        form_text_box("title_format", "<graph_title> " . _("Template"), "", "255", "30", "text");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "5") {
        /* change device */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("Choose a new host for these graphs:") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("New Device:") . "</strong><br>";
        form_dropdown("host_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "name", "id", "", "", "0");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "6") {
        /* reapply suggested naming to host */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("When you click save, the following graphs will have thier suggested naming convensions\n\t\t\t\t\trecalculated and applies to the graphs.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "7") {
        /* reapply suggested naming to host */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click save, the following graphs will be resized per your specifications.</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>Graph Height:</strong><br>";
        form_text_box("graph_height", "", "", "255", "30", "text");
        print "</p>\n\t\t\t\t\t<p><strong>Graph Width:</strong><br>";
        form_text_box("graph_width", "", "", "255", "30", "text");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "8") {
        /* place on tree */
        $trees = db_fetch_assoc("select id,name from graph_tree order by name");
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("When you click save, the following graphs will be placed under the branch selected\n\t\t\t\t\tbelow.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Destination Branch:") . "</strong><br>";
        html_tree_dropdown_draw($matches[1], "tree_item_id", "0");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t";
    }
    if (!isset($graph_array)) {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>" . _("You must select at least one graph.") . "</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='image' src='" . html_get_theme_images_path("button_yes.gif") . "' alt='" . _("Save") . "' align='absmiddle'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' bgcolor='#" . $colors["buttonbar_background"] . "'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='graphs.php'><img src='" . html_get_theme_images_path("button_no.gif") . "' alt='" . _("Cancel") . "' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    require_once CACTI_BASE_PATH . "/include/bottom_footer.php";
}
Example #18
0
function finalize_timespan(&$timespan) {
	if (!isset($timespan["current_value_date1"])) {
		/* Default end date is now default time span */
		$timespan["current_value_date1"] = date("Y", $timespan["begin_now"]) . "-" . date("m", $timespan["begin_now"]) . "-" . date("d", $timespan["begin_now"]) . " " . date("H", $timespan["begin_now"]) . ":".date("i", $timespan["begin_now"]);
	}

	if (!isset($timespan["current_value_date2"])) {
		/* Default end date is now */
		$timespan["current_value_date2"] = date("Y", $timespan["end_now"]) . "-" . date("m", $timespan["end_now"]) . "-" . date("d", $timespan["end_now"]) . " " . date("H", $timespan["end_now"]) . ":" . date("i", $timespan["end_now"]);
	}

	/* correct bad dates on calendar */
	if ($timespan["end_now"] < $timespan["begin_now"]) {
		set_preset_timespan($timespan);
		$_SESSION["sess_current_timespan"] = read_graph_config_option("default_timespan");

		$timespan["current_value_date1"] = date("Y", $timespan["begin_now"]) . "-" . date("m", $timespan["begin_now"]) . "-" . date("d", $timespan["begin_now"]) . " " . date("H", $timespan["begin_now"]) . ":".date("i", $timespan["begin_now"]);
		$timespan["current_value_date2"] = date("Y", $timespan["end_now"]) . "-" . date("m", $timespan["end_now"]) . "-" . date("d", $timespan["end_now"]) . " " . date("H", $timespan["end_now"]) . ":" . date("i", $timespan["end_now"]);
	}

	$_SESSION["sess_current_timespan_end_now"] = $timespan["end_now"];
	$_SESSION["sess_current_timespan_begin_now"] = $timespan["begin_now"];
	$_SESSION["sess_current_date1"] = $timespan["current_value_date1"];
	$_SESSION["sess_current_date2"] = $timespan["current_value_date2"];

	$timespan_sel_pos = strpos(get_browser_query_string(),"&predefined_timespan");
	if ($timespan_sel_pos) {
		$_SESSION["urlval"] = substr(get_browser_query_string(),0,$timespan_sel_pos);
	}else {
		$_SESSION["urlval"] = get_browser_query_string();
	}
}
Example #19
0
function graph_edit()
{
    global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        // graph add
        if ($_GET["id"] == "") {
            if ($_GET["host_id"] != -1) {
                input_validate_input_number(get_request_var("host_id"));
                if (!check_host($_GET["host_id"])) {
                    access_denied();
                }
            }
            // graph edit
        } else {
            $permission = check_graph($_GET["id"]);
            if ($permission != GRAPH_PRIVATE && $permission != GRAPH_PRIVATE + GRAPH_PUBLIC) {
                access_denied();
            }
        }
    }
    /* modify for multi user end */
    $use_graph_template = true;
    if (!empty($_GET["id"])) {
        $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]);
        $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]);
        $graphs_template = db_fetch_row("select * from graph_templates_graph where id={$local_graph_template_graph_id}");
        $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]);
        $header_label = "[edit: " . htmlspecialchars(get_graph_title($_GET["id"])) . "]";
        if ($graphs["graph_template_id"] == "0") {
            $use_graph_template = false;
        }
    } else {
        $header_label = "[new]";
        $use_graph_template = false;
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($_GET["debug"]);
    }
    /* modify for multi user end */
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("graph_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["graph_debug_mode"] = true;
        }
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print htmlspecialchars(get_graph_title($_GET["id"]));
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
                    <?php 
        /* modify for multi user start */
        if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
					<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("graphs.php?action=graph_edit&id=" . (isset($_GET["id"]) ? $_GET["id"] : "0") . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1"));
            ?>
'>Turn <strong><?php 
            print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On";
            ?>
</strong> Graph Debug Mode.</a></span><br>
					<?php 
        }
        if (!empty($graphs["graph_template_id"]) && $_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("graph_templates.php?action=template_edit&id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"));
            ?>
'>Edit Graph Template.</a></span><br><?php 
        }
        /* modify for multi user end */
        if (!empty($_GET["host_id"]) || !empty($host_id)) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("host.php?action=edit&id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id));
            ?>
'>Edit Host.</a></span><br><?php 
        }
        ?>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    html_start_box("<strong>Graph Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    $form_array = array("graph_template_id" => array("method" => "drop_sql", "friendly_name" => "Selected Graph Template", "description" => "Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied.", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0", "none_value" => "None", "sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name"), "host_id" => array("method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id, "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["id"] : "0"), "local_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_id"] : "0"), "local_graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0"), "_graph_template_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0"), "_host_id" => array("method" => "hidden", "value" => isset($host_id) ? $host_id : "0"));
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($form_array["graph_template_id"]["none_value"]);
        $form_array["graph_template_id"]["sql"] = "SELECT graph_templates.id,graph_templates.name FROM graph_templates WHERE name NOT LIKE '%@system' ORDER BY name";
        unset($form_array["host_id"]["none_value"]);
        $form_array["host_id"]["sql"] = "\r\n            SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') AS name FROM host \r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n            ORDER BY host.description,host.hostname";
    }
    /* modify for multi user end */
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* only display the "inputs" area if we are using a graph template for this graph */
    if (!empty($graphs["graph_template_id"])) {
        html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", "");
        draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0);
        draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true);
        html_end_box();
    }
    /* graph item list goes here */
    if (!empty($_GET["id"]) && empty($graphs["graph_template_id"])) {
        item();
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="<?php 
        print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . $_GET["id"] . "&rra_id=" . read_graph_config_option("default_rra_id"));
        ?>
" alt="">
				</td>
				<?php 
        if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) {
            $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
            $graph_data_array["print_source"] = 1;
            ?>
					<td>
						<span class="textInfo">RRDTool Command:</span><br>
						<pre><?php 
            print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
						<span class="textInfo">RRDTool Says:</span><br>
						<?php 
            unset($graph_data_array["print_source"]);
            ?>
						<pre><?php 
            print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
					</td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<br>
		<?php 
    }
    if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($graphs["graph_template_id"])) {
        html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", "");
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_graph)) {
            $form_array += array($field_name => $struct_graph[$field_name]);
            $form_array[$field_name]["value"] = isset($graphs) ? $graphs[$field_name] : "";
            $form_array[$field_name]["form_id"] = isset($graphs) ? $graphs["id"] : "0";
            if (!($use_graph_template == false || $graphs_template["t_" . $field_name] == "on")) {
                $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
                $form_array[$field_name]["description"] = "";
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
        html_end_box();
    }
    if (isset($_GET["id"]) || isset($_GET["new"])) {
        form_hidden_box("save_component_graph", "1", "");
        form_hidden_box("save_component_input", "1", "");
    } else {
        form_hidden_box("save_component_graph_new", "1", "");
    }
    form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), "");
    form_save_button("graphs.php");
    //Now we need some javascript to make it dynamic
    ?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}

function changeScaleLog() {
	//alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}
</script>
<?php 
}
Example #20
0
				</tr>
			</table>
			<input type='hidden' name='graph_add' value=''>
			<input type='hidden' name='graph_remove' value=''>
			<input type='hidden' name='graph_list' value='<?php 
        print $_REQUEST["graph_list"];
        ?>
'>
		</form>
		</td>
	</tr>
	<?php 
        html_end_box();
        /* if the number of rows is -1, set it to the default */
        if ($_REQUEST["rows"] == -1) {
            $_REQUEST["rows"] = read_graph_config_option("list_graphs_per_page");
        }
        /* create filter for sql */
        $sql_filter = "";
        $sql_filter .= empty($_REQUEST["filter"]) ? "" : " graph_templates_graph.title_cache like '%" . get_request_var_request("filter") . "%'";
        $sql_filter .= empty($_REQUEST["host_id"]) ? "" : (empty($sql_filter) ? "" : " and") . " graph_local.host_id=" . get_request_var_request("host_id");
        $sql_filter .= empty($_REQUEST["graph_template_id"]) ? "" : (empty($sql_filter) ? "" : " and") . " graph_local.graph_template_id=" . get_request_var_request("graph_template_id");
        /* graph permissions */
        if (read_config_option("auth_method") != 0) {
            /* get policy information for the sql where clause */
            $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)\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"] . "))";
        } else {
            $sql_where = "";
            $sql_join = "";
        }
Example #21
0
function form_actions()
{
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        update_poller_cache($data_source["id"], false);
                    }
                }
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc("select\n\t\t\t\t\tdata_local.id as local_data_id\n\t\t\t\t\tfrom data_local\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id"));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source["local_data_id"];
                    }
                }
                if ($_POST["delete_type"] == 2) {
                    $graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_local.id as local_graph_id\n\t\t\t\t\t\tfrom graph_local\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id"));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph["local_graph_id"];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST["delete_type"]) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
        } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post("tree_id"));
                input_validate_input_number(get_request_var_post("tree_item_id"));
                /* ==================================================== */
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_HOST, $_POST["tree_item_id"], "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false);
            }
        }
        header("Location: host.php");
        exit;
    }
    /* setup some variables */
    $host_list = "";
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (ereg("^chk_([0-9]+)\$", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>";
            $host_array[$i] = $matches[1];
        }
        $i++;
    }
    include_once "./include/top_header.php";
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box("<strong>" . $device_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='host.php' method='post'>\n";
    if ($_POST["drp_action"] == "2") {
        /* Enable Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To enable the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "3") {
        /* Disable Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To disable the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "4") {
        /* change snmp options */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click \"yes\".</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("^snmp_", $field_name) || $field_name == "max_oids") {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "6") {
        /* change availability options */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click \"yes\".</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("(availability_method|ping_method|ping_port)", $field_name)) {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "5") {
        /* Clear Statisitics for Selected Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To clear the counters for the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "1") {
        /* delete */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Are you sure you want to delete the following devices?</p>\n\t\t\t\t\t<p>{$host_list}</p>";
        form_radio_button("delete_type", "2", "1", "Leave all graphs and data sources untouched.  Data sources will be disabled however.", "1");
        print "<br>";
        form_radio_button("delete_type", "2", "2", "Delete all associated <strong>graphs</strong> and <strong>data sources</strong>.", "1");
        print "<br>";
        print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) {
        /* place on tree */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click save, the following hosts will be placed under the branch selected\n\t\t\t\t\tbelow.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
        grow_dropdown_tree($matches[1], "tree_item_id", "0");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t";
    }
    if (!isset($host_array)) {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='host.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Example #22
0
		graph_templates_graph.height,
		graph_templates_graph.width
		from graph_templates_graph
		where graph_templates_graph.local_graph_id=" . $_GET["local_graph_id"]);

	$graph_height = $graph["height"];
	$graph_width = $graph["width"];
	if ((read_config_option("rrdtool_version")) == "rrd-1.2.x") {
		if (read_graph_config_option("title_font") == "") {
			if (read_config_option("title_font") == "") {
				$title_font_size = 10;
			}else {
				$title_font_size = read_config_option("title_size");
			}
		}else {
			$title_font_size = read_graph_config_option("title_size");
		}
	}else {
		$title_font_size = 0;
	}

	?>
	<tr bgcolor='#<?php print $colors["header_panel"];?>'>
		<td colspan='3' class='textHeaderDark'>
			<strong>Zooming Graph</strong> '<?php print $graph_title;?>'
		</td>
	</tr>
	<div id='zoomBox' style='position:absolute; overflow:hidden; left:0px; top:0px; width:0px; height:0px; visibility:visible; background:red; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity:0.5; opacity:0.5'></div>
	<div id='zoomSensitiveZone' style='position:absolute; overflow:hidden; left:0px; top:0px; width:0px; height:0px; visibility:visible; cursor:crosshair; background:blue; filter:alpha(opacity=0); -moz-opacity:0; -khtml-opacity:0; opacity:0' oncontextmenu='return false'></div>
	<STYLE MEDIA="print">
	/*Turn off the zoomBox*/
Example #23
0
				$graph_data_array["graph_start"] = $_GET["graph_start"];
			}

			/* override: graph end time (unix time) */
			if (!empty($_GET["graph_end"])) {
				$graph_data_array["graph_end"] = $_GET["graph_end"];
			}

			print trim(rrdtool_function_graph($_GET["local_graph_id"], $_GET["rra_id"], $graph_data_array));
			?>
		</td>
	</tr>
	<?php }?>

	<tr>
		<?php if ((read_graph_config_option("default_tree_view_mode") == "2") && (($_REQUEST["action"] == "tree") || ((isset($_REQUEST["view_type"]) ? $_REQUEST["view_type"] : "") == "tree"))) { ?>
		<td valign="top" style="padding: 5px; border-right: #aaaaaa 1px solid;" bgcolor='#efefef' width='200'>
			<table border=0 cellpadding=0 cellspacing=0><tr><td><font size=-2><a style="font-size:7pt;text-decoration:none;color:silver" href="http://www.treemenu.net/" target=_blank></a></font></td></tr></table>
			<?php grow_dhtml_trees(); ?>
			<script type="text/javascript">initializeDocument();</script>

			<?php if (isset($_GET["select_first"])) { ?>
			<script type="text/javascript">
			var obj;
			obj = findObj(1);

			if (!obj.isOpen) {
				clickOnNode(1);
			}

			clickOnLink(2,'','main');
Example #24
0
function graph_edit() {
	global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("id"));
	/* ==================================================== */

	$use_graph_template = true;

	if (!empty($_GET["id"])) {
		$local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]);

		$graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]);
		$graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id");

		$host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]);
		$header_label = "[edit: " . get_graph_title($_GET["id"]) . "]";

		if ($graphs["graph_template_id"] == "0") {
			$use_graph_template = false;
		}
	}else{
		$header_label = "[new]";
		$use_graph_template = false;
	}

	/* handle debug mode */
	if (isset($_GET["debug"])) {
		if ($_GET["debug"] == "0") {
			kill_session_var("graph_debug_mode");
		}elseif ($_GET["debug"] == "1") {
			$_SESSION["graph_debug_mode"] = true;
		}
	}

	if (!empty($_GET["id"])) {
		?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php print get_graph_title($_GET["id"]);?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='graphs.php?action=graph_edit&id=<?php print (isset($_GET["id"]) ? $_GET["id"] : 0);?>&debug=<?php print (isset($_SESSION["graph_debug_mode"]) ? "0" : "1");?>'>Turn <strong><?php print (isset($_SESSION["graph_debug_mode"]) ? "Off" : "On");?></strong> Graph Debug Mode.</a><br>
					<?php
						if (!empty($graphs["graph_template_id"])) {
							?><span style="color: #c16921;">*<a href='graph_templates.php?action=template_edit&id=<?php print (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0");?>'>Edit Graph Template.</a><br><?php
						}
						if (!empty($_GET["host_id"]) || !empty($host_id)) {
							?><span style="color: #c16921;">*<a href='host.php?action=edit&id=<?php print (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id);?>'>Edit Host.</a><br><?php
						}
					?>
				</td>
			</tr>
		</table>
		<br>
		<?php
	}

	html_start_box("<strong>Graph Template Selection</strong> $header_label", "100%", $colors["header"], "3", "center", "");

	$form_array = array(
		"graph_template_id" => array(
			"method" => "drop_sql",
			"friendly_name" => "Selected Graph Template",
			"description" => "Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied.",
			"value" => (isset($graphs) ? $graphs["graph_template_id"] : "0"),
			"none_value" => "None",
			"sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name"
			),
		"host_id" => array(
			"method" => "drop_sql",
			"friendly_name" => "Host",
			"description" => "Choose the host that this graph belongs to.",
			"value" => (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id),
			"none_value" => "None",
			"sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"
			),
		"graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["id"] : "0")
			),
		"local_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["local_graph_id"] : "0")
			),
		"local_graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0")
			),
		"_graph_template_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["graph_template_id"] : "0")
			),
		"_host_id" => array(
			"method" => "hidden",
			"value" => (isset($host_id) ? $host_id : "0")
			)
		);

	draw_edit_form(
		array(
			"config" => array(),
			"fields" => $form_array
			)
		);

	html_end_box();

	/* only display the "inputs" area if we are using a graph template for this graph */
	if (!empty($graphs["graph_template_id"])) {
		html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", "");

		print "<form method='post' action='graphs.php'>\n";

		draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0);
		draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true);

		html_end_box();
	}

	/* graph item list goes here */
	if ((!empty($_GET["id"])) && (empty($graphs["graph_template_id"]))) {
		item();
	}

	if (!empty($_GET["id"])) {
		?>
		<table width="100%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="graph_image.php?action=edit&local_graph_id=<?php print $_GET["id"];?>&rra_id=<?php print read_graph_config_option("default_rra_id");?>" alt="">
				</td>
				<?php
				if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) {
					$graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
					$graph_data_array["print_source"] = 1;
					?>
					<td>
						<span class="textInfo">RRDTool Command:</span><br>
						<pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre>
						<span class="textInfo">RRDTool Says:</span><br>
						<?php unset($graph_data_array["print_source"]);?>
						<pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre>
					</td>
					<?php
				}
				?>
			</tr>
		</table>
		<br>
		<?php
	}

	if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) {
		html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", "");

		$form_array = array();

		while (list($field_name, $field_array) = each($struct_graph)) {
			$form_array += array($field_name => $struct_graph[$field_name]);

			$form_array[$field_name]["value"] = (isset($graphs) ? $graphs[$field_name] : "");
			$form_array[$field_name]["form_id"] = (isset($graphs) ? $graphs["id"] : "0");

			if (!(($use_graph_template == false) || ($graphs_template{"t_" . $field_name} == "on"))) {
				$form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
				$form_array[$field_name]["description"] = "";
			}
		}

		draw_edit_form(
			array(
				"config" => array(
					"no_form_tag" => true
					),
				"fields" => $form_array
				)
			);

		html_end_box();
	}

	if ((isset($_GET["id"])) || (isset($_GET["new"]))) {
		form_hidden_box("save_component_graph","1","");
		form_hidden_box("save_component_input","1","");
	}else{
		form_hidden_box("save_component_graph_new","1","");
	}

	form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), "");
	form_save_button("graphs.php");

//Now we need some javascript to make it dynamic
?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}

function changeScaleLog() {
	//alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}
</script>
<?php

}
Example #25
0
File: host.php Project: MrWnn/cacti
function form_actions()
{
    global $device_actions, $fields_host_edit;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '2') {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled = '' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                $data_sources = db_fetch_assoc_prepared('SELECT id FROM data_local WHERE host_id = ?', array($selected_items[$i]));
                $poller_items = $local_data_ids = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source['id'];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source['id']));
                    }
                }
                if (sizeof($local_data_ids)) {
                    poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
                }
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled='on' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                db_execute_prepared('DELETE FROM poller_item WHERE host_id = ?', array($selected_items[$i]));
                db_execute_prepared('DELETE FROM poller_reindex WHERE host_id = ?', array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET min_time = '9.99999', max_time = '0', cur_time = '0', avg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = ?", array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc('SELECT
					data_local.id AS local_data_id
					FROM data_local
					WHERE ' . array_to_sql_or($selected_items, 'data_local.host_id'));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source['local_data_id'];
                    }
                }
                if ($_POST['delete_type'] == 2) {
                    $graphs = db_fetch_assoc('SELECT
						graph_local.id AS local_graph_id
						FROM graph_local
						WHERE ' . array_to_sql_or($selected_items, 'graph_local.host_id'));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph['local_graph_id'];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST['delete_type']) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    api_plugin_hook_function('data_source_remove', $data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    api_plugin_hook_function('graphs_remove', $graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
            api_plugin_hook_function('device_remove', $devices_to_act_on);
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('tree_id'));
                input_validate_input_number(get_request_var_post('tree_item_id'));
                /* ==================================================== */
                api_tree_item_save(0, $_POST['tree_id'], TREE_ITEM_TYPE_HOST, $_POST['tree_item_id'], '', 0, read_graph_config_option('default_rra_id'), $selected_items[$i], 1, 1, false);
            }
        } else {
            api_plugin_hook_function('device_action_execute', $_POST['drp_action']);
        }
        /* update snmpcache */
        snmpagent_device_action_bottom(array($_POST['drp_action'], $selected_items));
        api_plugin_hook_function('device_action_bottom', array($_POST['drp_action'], $selected_items));
        header('Location: host.php');
        exit;
    }
    /* setup some variables */
    $host_list = '';
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $host_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($matches[1]))) . '<br>';
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box('<strong>' . $device_actions[get_request_var_post('drp_action')] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='host.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_POST['drp_action'] == '2') {
            /* Enable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Device(s)'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Device(s)'>";
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/^snmp_/', $field_name) || $field_name == 'max_oids') {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) SNMP Options'>";
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/(availability_method|ping_method|ping_port)/', $field_name)) {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) Availability Options'>";
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Clear Statistics on Device(s)'>";
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>';
            form_radio_button('delete_type', '2', '1', 'Leave all Graph(s) and Data Source(s) untouched.  Data Source(s) will be disabled however.', '1');
            print '<br>';
            form_radio_button('delete_type', '2', '2', 'Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.', '1');
            print '<br>';
            print "</td></tr>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\n\t\t\t\t\t\tbelow.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
						<p><strong>Destination Branch:</strong><br>';
            grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['host_list'] = $host_list;
            $save['host_array'] = isset($host_array) ? $host_array : array();
            api_plugin_hook_function('device_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
Example #26
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();
}
Example #27
0
function rrdtool_set_font($type, $no_legend = "") {
	global $config;

	if (read_graph_config_option("custom_fonts") == "on") {
		$font = read_graph_config_option($type . "_font");
		$size = read_graph_config_option($type . "_size");
	}else{
		$font = read_config_option($type . "_font");
		$size = read_config_option($type . "_size");
	}

	/* do some simple checks */
	if (!file_exists($font)) {
		$font = "";
	}

	if ($type == "title") {
		if (!empty($no_legend)) {
			$size = $size * .70;
		}elseif (($size <= 4) || ($size == "")) {
			$size = 12;
		}
	}else if (($size <= 4) || ($size == "")) {
		$size = 8;
	}

	return "--font " . strtoupper($type) . ":" . $size . ":" . $font . RRD_NL;
}
Example #28
0
function get_timespan(&$span, $curr_time, $timespan_given, $first_weekdayid)
{
    # unless changed later, $span["end_now"] is always $curr_time
    $span["begin_now"] = $curr_time;
    # initialization only!
    $span["end_now"] = $curr_time;
    switch ($timespan_given) {
        case GT_LAST_HALF_HOUR:
            $span["begin_now"] = strtotime("-30 minutes", $curr_time);
            break;
        case GT_LAST_HOUR:
            $span["begin_now"] = strtotime("-1 hour", $curr_time);
            break;
        case GT_LAST_2_HOURS:
            $span["begin_now"] = strtotime("-2 hours", $curr_time);
            break;
        case GT_LAST_4_HOURS:
            $span["begin_now"] = strtotime("-4 hours", $curr_time);
            break;
        case GT_LAST_6_HOURS:
            $span["begin_now"] = strtotime("-6 hours", $curr_time);
            break;
        case GT_LAST_12_HOURS:
            $span["begin_now"] = strtotime("-12 hours", $curr_time);
            break;
        case GT_LAST_DAY:
            $span["begin_now"] = strtotime("-1 day", $curr_time);
            break;
        case GT_LAST_2_DAYS:
            $span["begin_now"] = strtotime("-2 days", $curr_time);
            break;
        case GT_LAST_3_DAYS:
            $span["begin_now"] = strtotime("-3 days", $curr_time);
            break;
        case GT_LAST_4_DAYS:
            $span["begin_now"] = strtotime("-4 days", $curr_time);
            break;
        case GT_LAST_WEEK:
            $span["begin_now"] = strtotime("-1 week", $curr_time);
            break;
        case GT_LAST_2_WEEKS:
            $span["begin_now"] = strtotime("-2 weeks", $curr_time);
            break;
        case GT_LAST_MONTH:
            $span["begin_now"] = strtotime("-1 month", $curr_time);
            break;
        case GT_LAST_2_MONTHS:
            $span["begin_now"] = strtotime("-2 months", $curr_time);
            break;
        case GT_LAST_3_MONTHS:
            $span["begin_now"] = strtotime("-3 months", $curr_time);
            break;
        case GT_LAST_4_MONTHS:
            $span["begin_now"] = strtotime("-4 months", $curr_time);
            break;
        case GT_LAST_6_MONTHS:
            $span["begin_now"] = strtotime("-6 months", $curr_time);
            break;
        case GT_LAST_YEAR:
            $span["begin_now"] = strtotime("-1 year", $curr_time);
            break;
        case GT_LAST_2_YEARS:
            $span["begin_now"] = strtotime("-2 years", $curr_time);
            break;
        case GT_DAY_SHIFT:
            # take this day, start and end time fetched from config_settings
            $span["begin_now"] = strtotime(date("Y-m-d", $curr_time) . " " . read_graph_config_option("day_shift_start"));
            $span["end_now"] = strtotime(date("Y-m-d", $curr_time) . " " . read_graph_config_option("day_shift_end"));
            break;
        case GT_THIS_DAY:
            # return Year-Month-Day for given 'time since epoch'
            # and convert this to 'time since epoch' (Hour:Minute:Second set to 00:00:00)
            $span["begin_now"] = strtotime(date("Y-m-d", $curr_time));
            $span["end_now"] = strtotime("+1 day", $span["begin_now"]) - 1;
            break;
        case GT_THIS_WEEK:
            # compute offset to start-of-week
            # remember: start-of-week may be > current-weekday, so do modulo calc
            $offset = (date("w", $curr_time) - $first_weekdayid + 7) % 7;
            $span["begin_now"] = strtotime("-" . $offset . " days" . date("Y-m-d", $curr_time));
            $span["end_now"] = strtotime("+1 week", $span["begin_now"]) - 1;
            break;
        case GT_THIS_MONTH:
            # this date format set day-of-month to 01
            $span["begin_now"] = strtotime(date("Y-m-01", $curr_time));
            $span["end_now"] = strtotime("+1 month", $span["begin_now"]) - 1;
            break;
        case GT_THIS_YEAR:
            # this date format set day-of-month to 01 and month-of-year to 01
            $span["begin_now"] = strtotime(date("Y-01-01", $curr_time));
            $span["end_now"] = strtotime("+1 year", $span["begin_now"]) - 1;
            break;
        case GT_PREV_DAY:
            $span["begin_now"] = strtotime("-1 day" . date("Y-m-d", $curr_time));
            $span["end_now"] = strtotime("+1 day", $span["begin_now"]) - 1;
            break;
        case GT_PREV_WEEK:
            # compute offset to start-of-week
            # remember: start-of-week may be > current-weekday, so do modulo calc
            $offset = (date("w", $curr_time) - $first_weekdayid + 7) % 7;
            $span["begin_now"] = strtotime("-1 week -" . $offset . " days" . date("Y-m-d", $curr_time));
            $span["end_now"] = strtotime("+1 week", $span["begin_now"]) - 1;
            break;
        case GT_PREV_MONTH:
            $span["begin_now"] = strtotime("-1 month" . date("Y-m-01", $curr_time));
            $span["end_now"] = strtotime("+1 month", $span["begin_now"]) - 1;
            break;
        case GT_PREV_YEAR:
            $span["begin_now"] = strtotime("-1 year" . date("Y-01-01", $curr_time));
            $span["end_now"] = strtotime("+1 year", $span["begin_now"]) - 1;
            break;
        default:
            $span["begin_now"] = $curr_time - DEFAULT_TIMESPAN;
            break;
    }
    # reformat time-since-epoch start/end times to human readable format
    $span["current_value_date1"] = date("Y-m-d H:i", $span["begin_now"]);
    $span["current_value_date2"] = date("Y-m-d H:i", $span["end_now"]);
}
Example #29
0
function create_dhtml_tree_export($tree_id) {
	/* record start time */
	list($micro,$seconds) = split(" ", microtime());
	$start = $seconds + $micro;

	$dhtml_tree = array();
	$dhtml_tree[0] = $start;
	$dhtml_tree[1] = read_graph_config_option("expand_hosts");
	$dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
	$i = 2;

    $i++;
	$heirarchy = db_fetch_assoc("select
		graph_tree_items.id,
		graph_tree_items.title,
		graph_tree_items.order_key,
		graph_tree_items.host_id,
		graph_tree_items.host_grouping_type,
		host.description as hostname
		from graph_tree_items
		left join host on (host.id=graph_tree_items.host_id)
		where graph_tree_items.graph_tree_id=" . $tree_id . "
		and graph_tree_items.local_graph_id = 0
		order by graph_tree_items.order_key");

	$dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree_id) . "\", \"index.html\"))\n";

    if (sizeof($heirarchy) > 0) {
	foreach ($heirarchy as $leaf) {
		$i++;
		$tier = tree_tier($leaf["order_key"]);

		if ($leaf["host_id"] > 0) {  //It's a host
			$dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"<strong>Host:</strong> " . $leaf["hostname"] . "\", \"".$leaf["hostname"]."_".$leaf["id"]. ".html\"))\n";

			if (read_graph_config_option("expand_hosts") == "on") {
				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"] . "
						group by graph_templates.id
						order by graph_templates.name");

				 	if (sizeof($graph_templates) > 0) {
						foreach ($graph_templates as $graph_template) {
							$i++;
							$dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . $graph_template["name"] . "\", \"".$leaf["title"]."_".$leaf["id"]. ".html\"))\n";
						}
					}
				}else if ($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"] . "
						group by snmp_query.id
						order by snmp_query.name");

					array_push($data_queries, array(
						"id" => "0",
						"name" => "(Non Indexed)"
						));

					if (sizeof($data_queries) > 0) {
					foreach ($data_queries as $data_query) {
						$i++;
						$dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . $data_query["name"] . "\"".$leaf["title"]."_".$leaf["id"]. ".html\"))\n";

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

						while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
							$i++;
							$dhtml_tree[$i] = "ou" . ($tier+2) . " = insFld(ou" . ($tier+1) . ", gFld(\" " . $sort_field_value . "\"".$leaf["title"]."_".$leaf["id"]. ".html\"))\n";
						}
					}
					}
				}
			}
		}else {
			$dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"" . $leaf["title"] . "\", \"".$leaf["title"]."_".$leaf["id"]. ".html\"))\n";
		}
	}
	}

	return $dhtml_tree;
}
Example #30
0
function create_dhtml_tree_export($tree_id)
{
    /* record start time */
    list($micro, $seconds) = split(" ", microtime());
    $start = $seconds + $micro;
    $search_key = "";
    $dhtml_tree = array();
    $dhtml_tree[0] = $start;
    $dhtml_tree[1] = read_graph_config_option("expand_hosts");
    $dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
    $i = 2;
    $tree_list = get_graph_tree_array_export();
    /* auth check for hosts on the trees */
    $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));
    $sql_join = "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=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))";
    if ($current_user["policy_hosts"] == "1") {
        $sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.host_id>0)";
    } elseif ($current_user["policy_hosts"] == "2") {
        $sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.host_id>0)";
    }
    if (sizeof($tree_list) > 0) {
        foreach ($tree_list as $tree) {
            if (read_config_option("export_tree_isolation") == "on" && $tree_id == $tree["id"] || read_config_option("export_tree_isolation") == "off") {
                $i++;
                $hier_sql = "SELECT DISTINCT\n\t\t\t\t\tgraph_tree_items.id,\n\t\t\t\t\tgraph_tree_items.title,\n\t\t\t\t\tgraph_tree_items.order_key,\n\t\t\t\t\tgraph_tree_items.host_id,\n\t\t\t\t\tgraph_tree_items.host_grouping_type,\n\t\t\t\t\thost.description as hostname\n\t\t\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t\t\tLEFT JOIN host ON (host.id=graph_tree_items.host_id)\n\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates_graph.graph_template_id=graph_templates.id)\n\t\t\t\t\t{$sql_join}\n\t\t\t\t\tWHERE graph_tree_items.graph_tree_id=" . $tree["id"] . "\n\t\t\t\t\t{$sql_where}\n\t\t\t\t\tAND graph_tree_items.local_graph_id = 0\n\t\t\t\t\tORDER BY graph_tree_items.order_key";
                $hierarchy = db_fetch_assoc($hier_sql);
                $dhtml_tree_id = 0;
                if (sizeof($hierarchy) > 0) {
                    foreach ($hierarchy as $leaf) {
                        if ($dhtml_tree_id != $tree["id"]) {
                            $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
                        }
                        $dhtml_tree_id = $tree["id"];
                        $i++;
                        $tier = tree_tier($leaf["order_key"]);
                        if ($leaf["host_id"] > 0) {
                            //It's a host
                            $dhtml_tree[$i] = "ou" . $tier . " = insFld(ou" . ($tier - 1) . ", gFld(\"<strong>Host:</strong> " . $leaf["hostname"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]) . ".html\"))\n";
                            if (read_config_option("export_tree_expand_hosts") == "on") {
                                if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
                                    $graph_templates = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\t\t\tgraph_templates.id,\n\t\t\t\t\t\t\t\t\tgraph_templates.name,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\t\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.export='on'\n\t\t\t\t\t\t\t\t\tGROUP BY graph_templates.id\n\t\t\t\t\t\t\t\t\tORDER BY graph_templates.name");
                                    if (sizeof($graph_templates) > 0) {
                                        foreach ($graph_templates as $graph_template) {
                                            $i++;
                                            $dhtml_tree[$i] = "ou" . ($tier + 1) . " = insFld(ou" . $tier . ", gFld(\" " . $graph_template["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_gt_" . $leaf["id"]) . "_" . $graph_template["id"] . ".html\"))\n";
                                        }
                                    }
                                } else {
                                    if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
                                        $data_queries = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\t\t\t\t\tsnmp_query.name\n\t\t\t\t\t\t\t\t\tFROM (graph_local,snmp_query)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tGROUP BY snmp_query.id\n\t\t\t\t\t\t\t\t\tORDER BY snmp_query.name");
                                        array_push($data_queries, array("id" => "0", "name" => "Graph Template Based"));
                                        if (sizeof($data_queries) > 0) {
                                            foreach ($data_queries as $data_query) {
                                                $i++;
                                                $dhtml_tree[$i] = "ou" . ($tier + 1) . " = insFld(ou" . $tier . ", gFld(\" " . $data_query["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dq_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . ".html\"))\n";
                                                /* fetch a list of field names that are sorted by the preferred sort field */
                                                $sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);
                                                if ($data_query["id"] > 0) {
                                                    while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
                                                        $i++;
                                                        $dhtml_tree[$i] = "ou" . ($tier + 2) . " = insFld(ou" . ($tier + 1) . ", gFld(\" " . $sort_field_value . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . "_" . $snmp_index . ".html\"))\n";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            $dhtml_tree[$i] = "ou" . $tier . " = insFld(ou" . ($tier - 1) . ", gFld(\"" . $leaf["title"] . "\", \"" . clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]) . "_leaf.html\"))\n";
                        }
                    }
                } else {
                    if ($dhtml_tree_id != $tree["id"]) {
                        $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
                        $i++;
                    }
                }
            }
        }
    }
    return $dhtml_tree;
}