Пример #1
0
function input_edit() {
	global $colors;
	require(CACTI_BASE_PATH . "/include/presets/preset_rra_arrays.php");
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php");

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

	$header_label = __("[edit graph: ") . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]";

	if (!empty($_GET["local_graph_id"])) {
		$header_label = __("[edit graph: ") . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]";
	}else{
		$header_label = __("[new]");
	}

	/* get a list of all graph item field names and populate an array for user display */
	$struct_graph_item = graph_item_form_list;
	while (list($field_name, $field_array) = each($struct_graph_item)) {
		if ($field_array["method"] != "view") {
			$graph_template_items[$field_name] = $field_array["friendly_name"];
		}
	}

	if (!empty($_GET["id"])) {
		$graph_template_input = db_fetch_row("select * from graph_template_input where id=" . $_GET["id"]);
	}

	html_start_box("<strong>" . __("Graph Item Inputs") . "</strong> $header_label", "100", $colors["header"], "3", "center", "");

	draw_edit_form(array(
		"config" => array(),
		"fields" => inject_form_variables(graph_template_input_form_list(), (isset($graph_template_input) ? $graph_template_input : array()), (isset($graph_template_items) ? $graph_template_items : array()), $_GET)
		));

	if (!(isset($_GET["id"]))) { $_GET["id"] = 0; }

	$item_list = db_fetch_assoc("select
		CONCAT_WS(' - ',data_template_data.name,data_template_rrd.data_source_name) as data_source_name,
		graph_templates_item.text_format,
		graph_templates_item.id as graph_templates_item_id,
		graph_templates_item.graph_type_id,
		graph_templates_item.consolidation_function_id,
		graph_template_input_defs.graph_template_input_id
		from graph_templates_item
		left join graph_template_input_defs on (graph_template_input_defs.graph_template_item_id=graph_templates_item.id and graph_template_input_defs.graph_template_input_id=" . $_GET["id"] . ")
		left join data_template_rrd on (graph_templates_item.task_item_id=data_template_rrd.id)
		left join data_local on (data_template_rrd.local_data_id=data_local.id)
		left join data_template_data on (data_local.id=data_template_data.local_data_id)
		where graph_templates_item.local_graph_id=0
		and graph_templates_item.graph_template_id=" . $_GET["graph_template_id"] . "
		order by graph_templates_item.sequence");

	form_alternate_row_color(); ?>
		<td width="50%">
			<font class="textEditTitle"><?php print __("Associated Graph Items");?></font><br>
			<?php print __("Select the graph items that you want to accept user input for.");?>
		</td>
		<td>
		<?php
		$i = 0; $any_selected_item = "";
		if (sizeof($item_list) > 0) {
		foreach ($item_list as $item) {
			if ($item["graph_template_input_id"] == "") {
				$old_value = "";
			}else{
				$old_value = CHECKED;
				$any_selected_item = $item["graph_templates_item_id"];
			}

			if ($item["graph_type_id"] == GRAPH_ITEM_TYPE_GPRINT_AVERAGE ||
				$item["graph_type_id"] == GRAPH_ITEM_TYPE_GPRINT_LAST ||
				$item["graph_type_id"] == GRAPH_ITEM_TYPE_GPRINT_MAX ||
				$item["graph_type_id"] == GRAPH_ITEM_TYPE_GPRINT_MIN) {
				$start_bold = "";
				$end_bold = "";
			}else{
				$start_bold = "<strong>";
				$end_bold = "</strong>";
			}

			$name = "$start_bold Item #" . ($i+1) . ": " . $graph_item_types{$item["graph_type_id"]} . " (" . $consolidation_functions{$item["consolidation_function_id"]} . ")$end_bold";
			form_checkbox("i_" . $item["graph_templates_item_id"], $old_value, $name, "", "", get_request_var("graph_template_id")); print "<br>";

			$i++;
		}
		}else{
			print "<em>" . __("No Items") . "</em>";
		}
		?>
		</td>

	<?php
	form_end_row();
	html_end_box();

	form_hidden_box("any_selected_item", $any_selected_item, "");

	form_save_button_alt("url!" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : ""));
}
Пример #2
0
function graph_template_to_xml($graph_template_id) {
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php");

	$hash["graph_template"] = get_hash_version("graph_template") . get_hash_graph_template($graph_template_id);
	$xml_text = "";

	$graph_template = db_fetch_row("select id,name,description,image from graph_templates where id=$graph_template_id");
	$graph_template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=$graph_template_id and local_graph_id=0");
	$graph_template_items = db_fetch_assoc("select * from graph_templates_item where graph_template_id=$graph_template_id and local_graph_id=0 order by sequence");
	$graph_template_inputs = db_fetch_assoc("select * from graph_template_input where graph_template_id=$graph_template_id");

	if ((empty($graph_template["id"])) || (empty($graph_template_graph["id"]))) {
		$err_msg = "Invalid graph template.";
		return $err_msg;
	}

	$xml_text .= "<hash_" . $hash["graph_template"] . ">\n\t<name>" . xml_character_encode($graph_template["name"]) . "</name>\n";
	$xml_text .= "\t\t<description>" . $graph_template["description"] . "</description>\n";
	$xml_text .= "\t\t<image>" . $graph_template["image"] . "</image>\n\t<graph>\n";

	/* XML Branch: <graph> */
	$struct_graph = graph_form_list();
	reset($struct_graph);
	while (list($field_name, $field_array) = each($struct_graph)) {
		$xml_text .= "\t\t<t_$field_name>" . xml_character_encode($graph_template_graph{"t_" . $field_name}) . "</t_$field_name>\n";
		$xml_text .= "\t\t<$field_name>" . xml_character_encode($graph_template_graph{$field_name}) . "</$field_name>\n";
	}

	$xml_text .= "\t</graph>\n";

	/* XML Branch: <items> */

	$xml_text .= "\t<items>\n";

	$i = 0;
	if (sizeof($graph_template_items) > 0) {
		$struct_graph_item = graph_item_form_list();
	foreach ($graph_template_items as $item) {
		$hash["graph_template_item"] = get_hash_version("graph_template_item") . get_hash_graph_template($item["id"], "graph_template_item");

		$xml_text .= "\t\t<hash_" . $hash["graph_template_item"] . ">\n";

		reset($struct_graph_item);
		while (list($field_name, $field_array) = each($struct_graph_item)) {
			if (($field_name == "task_item_id") && (!empty($item{$field_name}))) {
				$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version("data_template_item") . get_hash_data_template($item{$field_name}, "data_template_item") . "</$field_name>\n";
			}elseif (($field_name == "cdef_id") && (!empty($item{$field_name}))) {
				$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version("cdef") . get_hash_cdef($item{$field_name}) . "</$field_name>\n";
			}elseif (($field_name == "vdef_id") && (!empty($item{$field_name}))) {
				$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version("vdef") . get_hash_vdef($item{$field_name}) . "</$field_name>\n";
			}elseif (($field_name == "gprint_id") && (!empty($item{$field_name}))) {
				$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version("gprint_preset") . get_hash_gprint($item{$field_name}) . "</$field_name>\n";
			}elseif (($field_name == "color_id") && (!empty($item{$field_name}))) {
				$xml_text .= "\t\t\t<$field_name>" . db_fetch_cell("select hex from colors where id=" . $item{$field_name}) . "</$field_name>\n";
			}else{
				$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item{$field_name}) . "</$field_name>\n";
			}
		}

		$xml_text .= "\t\t</hash_" . $hash["graph_template_item"] . ">\n";

		$i++;
	}
	}

	$xml_text .= "\t</items>\n";

	/* XML Branch: <inputs> */

	$xml_text .= "\t<inputs>\n";

	$i = 0;
	if (sizeof($graph_template_inputs) > 0) {
		$fields_graph_template_input_edit = graph_template_input_form_list();
	foreach ($graph_template_inputs as $item) {
		$hash["graph_template_input"] = get_hash_version("graph_template_input") . get_hash_graph_template($item["id"], "graph_template_input");

		$xml_text .= "\t\t<hash_" . $hash["graph_template_input"] . ">\n";

		reset($fields_graph_template_input_edit);
		while (list($field_name, $field_array) = each($fields_graph_template_input_edit)) {
			if (($field_array["method"] != "hidden_zero") && ($field_array["method"] != "hidden") && ($field_array["method"] != "spacer")) {
				$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item{$field_name}) . "</$field_name>\n";
			}
		}

		$graph_template_input_items = db_fetch_assoc("select graph_template_item_id from graph_template_input_defs where graph_template_input_id=" . $item["id"]);

		$xml_text .= "\t\t\t<items>";

		$j = 0;
		if (sizeof($graph_template_input_items) > 0) {
		foreach ($graph_template_input_items as $item2) {
			$xml_text .= "hash_" . get_hash_version("graph_template") . get_hash_graph_template($item2["graph_template_item_id"], "graph_template_item");

			if (($j+1) < sizeof($graph_template_input_items)) {
				$xml_text .= "|";
			}

			$j++;
		}
		}

		$xml_text .= "</items>\n";
		$xml_text .= "\t\t</hash_" . $hash["graph_template_input"] . ">\n";

		$i++;
	}
	}

	$xml_text .= "\t</inputs>\n";
	$xml_text .= "</hash_" . $hash["graph_template"] . ">";

	return $xml_text;
}