Esempio n. 1
0
function graph_template_display_general($graph_template, $header_label) {
	global $colors;
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php");

	# fetch all settings for this graph template
	if (isset($graph_template["id"])) {
		$template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=" . $graph_template["id"] . " and local_graph_id=0");
	}else {
		$template_graph = array();
	}

	print "<form method='post' action='" .  basename($_SERVER["PHP_SELF"]) . "' name='graph_template_edit'>\n";

	# the template header
	html_start_box("<strong>" . __("Graph Template") . "</strong> $header_label", "100", $colors["header"], "0", "center", "", true);
	$header_items = array(__("Field"), __("Value"));
	print "<tr><td>";
	html_header($header_items, 1, true, 'header_template');

	draw_edit_form(array(
		"config" => array("no_form_tag" => true),
		"fields" => inject_form_variables(graph_template_form_list(), (isset($graph_template) ? $graph_template : array()), (isset($template_graph) ? $template_graph : array()))
	));

	print "</table></td></tr>";		/* end of html_header */
	html_end_box(false);
	form_hidden_box("graph_template_id", (isset($template_graph["graph_template_id"]) ? $template_graph["graph_template_id"] : "0"), "");
	form_hidden_box("graph_template_graph_id", (isset($template_graph["id"]) ? $template_graph["id"] : "0"), "");
	form_hidden_box("save_component_template", 1, "");


	# the global graph template fields go here
	#	html_start_box("<strong>" . __("Graph Template") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template");

	/* id tags of tables (set via html_start_box) required for initial js on load */
	html_start_box("<strong>" . __("Graph Template Labels") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_labels");
	draw_template_edit_form('header_graph_labels', graph_labels_form_list(), $template_graph, false);
	html_end_box(false);
	/* TODO: we should not use rrd version in the code, when going data-driven */
	if ( read_config_option("rrdtool_version") != RRD_VERSION_1_0 && read_config_option("rrdtool_version") != RRD_VERSION_1_2) {
		html_start_box("<strong>" . __("Graph Template Right Axis Settings") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_right_axis");
		draw_template_edit_form('header_graph_right_axis', graph_right_axis_form_list(), $template_graph, false);
	}
	html_end_box(false);
	html_start_box("<strong>" . __("Graph Template Size") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_size");
	draw_template_edit_form('header_graph_size', graph_size_form_list(), $template_graph, false);
	html_end_box(false);
	html_start_box("<strong>" . __("Graph Template Limits") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_limits");
	draw_template_edit_form('header_graph_limits', graph_limits_form_list(), $template_graph, false);
	html_end_box(false);
	html_start_box("<strong>" . __("Graph Template Grid") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_grid");
	draw_template_edit_form('header_graph_grid', graph_grid_form_list(), $template_graph, false);
	html_end_box(false);
	html_start_box("<strong>" . __("Graph Template Color") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_color");
	draw_template_edit_form('header_graph_color', graph_color_form_list(), $template_graph, false);
	html_end_box(false);
	html_start_box("<strong>" . __("Graph Template Legend") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_legend");
	draw_template_edit_form('header_graph_legend', graph_legend_form_list(), $template_graph, false);
	html_end_box(false);
	html_start_box("<strong>" . __("Graph Template Misc") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc");
	draw_template_edit_form('header_graph_misc', graph_misc_form_list(), $template_graph, false);
	html_end_box(false);
	html_start_box("<strong>" . __("Graph Template Cacti Specifics") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_cacti");
	draw_template_edit_form('header_graph_cacti', graph_cacti_form_list(), $template_graph, false);
	html_end_box(false);

	# the id tag is required for our js code!
	form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), "");
	#	html_end_box(false);

	form_save_button_alt("url!graph_templates.php");

	include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js");
	include_once(CACTI_BASE_PATH . "/access/js/graph_template_options.js");

}
Esempio n. 2
0
function graph_edit() {
	global $colors;
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");

	/* ================= 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_request_var("id"));

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

		$device_id = db_fetch_cell("select device_id from graph_local where id=" . get_request_var("id"));
		$header_label = __("[edit: ") . get_graph_title(get_request_var("id")) . "]";

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

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

	$tip_text  = "<tr><td align=\\'right\\'><a class=\\'popup_item\\' id=\\'changeGraphState\\' onClick=\\'changeGraphState()\\' href=\\'#\\'>Unlock/Lock</a></td></tr>";
	$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graphs.php?action=graph_edit&id=' . (isset($_GET["id"]) ? get_request_var("id") : 0) . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["graph_debug_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("Debug Mode") . "</a></td></tr>";
	if (!empty($graphs["graph_template_id"])) {
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graph_templates.php?action=template_edit&id=' . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")) . "\\'>" . __("Edit Template") . "</a></td></tr>";
	}
	if (!empty($_GET["device_id"]) || !empty($device_id)) {
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('devices.php?action=edit&id=' . (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id)) . "\\'>" . __("Edit Host") . "</a></td></tr>";
	}

	if (!empty($_GET["id"])) {
		?>
		<script type="text/javascript">
		<!--
		var disabled = true;

		$().ready(function() {
			$("input").attr("disabled","disabled");
			$("select").attr("disabled","disabled");
			$("#cancel").removeAttr("disabled");
		});

		function changeGraphState() {
			if (disabled) {
				$("input").removeAttr("disabled");
				$("select").removeAttr("disabled");
				disabled = false;
				rrdtool_graph_dependencies(); // even when unlocking, disable distinct rrdtool options
			}else{
				$("input").attr("disabled","disabled");
				$("select").attr("disabled","disabled");
				$("#cancel").removeAttr("disabled");
				disabled = true;
			}
		}
		//-->
		</script>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php print get_graph_title(get_request_var("id"));?>
				</td>
				<td style="white-space:nowrap;" align="right" width="1"><a id='tooltip' class='popup_anchor' href='#' onMouseOver="Tip('<?php print $tip_text;?>', BGCOLOR, '#EEEEEE', FIX, ['tooltip', -45, 0], STICKY, true, SHADOW, true, CLICKCLOSE, true, FADEOUT, 400, TEXTALIGN, 'right', BORDERCOLOR, '#F5F5F5')" onMouseOut="UnTip()">Graph Options</a></td>
			</tr>
		</table>
		<?php
	}

	print "<form method='post' action='" .  basename($_SERVER["PHP_SELF"]) . "' name='graph_edit'>\n";
	html_start_box("<strong>" . __("Graph Template Selection") . "</strong> $header_label", "100", $colors["header"], 0, "center", "");
	$header_items = array(__("Field"), __("Value"));
	print "<tr><td>";
	html_header($header_items, 1, true, 'template');

	$form_array = array(
		"graph_template_id" => array(
			"method" => "autocomplete",
			"callback_function" => "./lib/ajax/get_graph_templates.php",
			"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."),
			"id" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"),
			"name" => db_fetch_cell("SELECT name FROM graph_templates WHERE id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"))
			),
		"device_id" => array(
			"method" => "autocomplete",
			"callback_function" => "./lib/ajax/get_device_detailed.php",
			"friendly_name" => __("Host"),
			"description" => __("Choose the device that this graph belongs to."),
			"id" => (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id),
			"name" => db_fetch_cell("SELECT CONCAT_WS('',description,' (',hostname,')') FROM device WHERE id=" . (isset($_GET['device_id']) ? $_GET['device_id'] : $device_id))
			),
		"graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs["id"]) ? $graphs["id"] : "0")
			),
		"local_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs["local_graph_id"]) ? $graphs["local_graph_id"] : "0")
			),
		"local_graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs["local_graph_template_graph_id"]) ? $graphs["local_graph_template_graph_id"] : "0")
			),
		"_graph_template_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")
			),
		"_device_id" => array(
			"method" => "hidden",
			"value" => (isset($device_id) ? $device_id : "0")
			)
		);

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

	print "</table></td></tr>";		/* end of html_header */
	html_end_box();


#	print "<form method='post' action='graphs.php'>\n";
	/* 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"], "0", "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_request_var("id"), "|field|_|id|", "<strong>" . __("Graph Item Fields") ."</strong>", true);

		html_end_box();
	}

	/* graph item list goes here */
	if ((!empty($_GET["id"])) && (!array_key_exists("graph_template_id", $graphs))) {
		graph_template_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_request_var("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 = array();
					$graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
					/* make rrdtool_function_graph to only print the command without executing it */
					$graph_data_array["print_source"] = 1;
					?>
					<td>
						<span class="textInfo"><?php print __("RRDTool Command:");?></span><br>
						<pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre>
						<span class="textInfo"><?php print __("RRDTool Says:");?></span><br>
						<?php /* make rrdtool_function_graph to generate AND execute the rrd command, but only for fetching the "return code" */
						unset($graph_data_array["print_source"]);?>
						<pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre>
					</td>
					<?php
				}
				?>
			</tr>
		</table>
		<?php
	}

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

		############
		html_start_box("<strong>" . __("Labels") . "</strong>", "100", $colors["header"], "0", "center", "", true);
		draw_template_edit_form('header_graph_labels', graph_labels_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		/* TODO: we should not use rrd version in the code, when going data-driven */
		if ( read_config_option("rrdtool_version") != RRD_VERSION_1_0 && read_config_option("rrdtool_version") != RRD_VERSION_1_2) {
			html_start_box("<strong>" . __("Right Axis Settings") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_right_axis");
			draw_template_edit_form('header_graph_right_axis', graph_right_axis_form_list(), $graphs, $use_graph_template);
		}
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Size") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_size");
		draw_template_edit_form('header_graph_size', graph_size_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Limits") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_limits");
		draw_template_edit_form('header_graph_limits', graph_limits_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Grid") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_grid");
		draw_template_edit_form('header_graph_grid', graph_grid_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Color") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_color");
		draw_template_edit_form('header_graph_color', graph_color_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Legend") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc");
		draw_template_edit_form('header_graph_legend', graph_legend_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Misc") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc");
		draw_template_edit_form('header_graph_misc', graph_misc_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Cacti Specifics") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_cacti");
		draw_template_edit_form('header_graph_cacti', graph_cacti_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
	}

	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("hidden_rrdtool_version", read_config_option("rrdtool_version"), "");
	form_save_button_alt();

	include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js");
	include_once(CACTI_BASE_PATH . "/access/js/graph_template_options.js");

?>
<script type="text/javascript">
	$('#graph_item').tableDnD({
		onDrop: function(table, row) {
			$('#AjaxResult').load("lib/ajax/jquery.tablednd/graphs_item.ajax.php?id=<?php isset($_GET["id"]) ? print get_request_var("id") : print "";?>&"+$.tableDnD.serialize());
//			location.reload();
		}
	});
</script>
<?php
}