Exemple #1
0
function data_source_edit() {
	global $colors;
	require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_info.php");

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

	$use_data_template = true;
	$device_id = 0;

	if (!empty($_GET["id"])) {
		$data_local 		= db_fetch_row("select device_id,data_template_id from data_local where id='" . $_GET["id"] . "'");
		$data       		= db_fetch_row("select * from data_template_data where local_data_id='" . $_GET["id"] . "'");
		$data_source_items 	= db_fetch_assoc("select * from data_template_rrd where local_data_id=" . $_GET["id"] . " order by data_source_name");

		if (isset($data_local["data_template_id"]) && $data_local["data_template_id"] >= 0) {
			$data_template      = db_fetch_row("select id,name from data_template where id='" . $data_local["data_template_id"] . "'");
			$data_template_data = db_fetch_row("select * from data_template_data where data_template_id='" . $data_local["data_template_id"] . "' and local_data_id=0");
		} else {
			$_SESSION["sess_messages"] = 'Data Source "' . $_GET["id"] . '" does not exist.';
			header ("Location: data_sources.php");
			exit;
		}

		$header_label = __("[edit: ") . get_data_source_title($_GET["id"]) . "]";

		if (empty($data_local["data_template_id"])) {
			$use_data_template = false;
		}
	}else{
		$header_label = __("[new]");

		$use_data_template = false;
	}

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

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

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

	$tip_text = "";
	if (isset($data)) {
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' id=\\'changeDSState\\' onClick=\\'changeDSState()\\' href=\\'#\\'>Unlock/Lock</a></td></tr>";
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('data_sources.php?action=data_source_toggle_status&id=' . (isset($_GET["id"]) ? $_GET["id"] : 0) . '&newstate=' . (($data["active"] == CHECKED) ? "0" : "1")) . "\\'>" . (($data["active"] == CHECKED) ? __("Disable") : __("Enable")) . "</a></td></tr>";
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('data_sources.php?action=data_source_edit&id=' . (isset($_GET["id"]) ? $_GET["id"] : 0) . '&debug=' . (isset($_SESSION["ds_debug_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["ds_debug_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("Debug Mode") . "</a></td></tr>";
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('data_sources.php?action=data_source_edit&id=' . (isset($_GET["id"]) ? $_GET["id"] : 0) . '&info=' . (isset($_SESSION["ds_info_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["ds_info_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("RRD Info Mode") . "</a><td></tr>";
	}
	if (!empty($data_template["id"])) {
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('data_templates.php?action=template_edit&id=' . (isset($data_template["id"]) ? $data_template["id"] : "0")) . "\\'>" . __("Edit Data Source Template") . "<br></a></td></td>";
	}
	if (!empty($_GET["device_id"]) || !empty($data_local["device_id"])) {
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('devices.php?action=edit&id=' . (isset($_GET["device_id"]) ? $_GET["device_id"] : $data_local["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 changeDSState() {
			if (disabled) {
				$("input").removeAttr("disabled");
				$("select").removeAttr("disabled");
				$("#cancel").removeAttr("disabled");
				disabled = false;
			}else{
				$("input").attr("disabled","disabled")
				$("select").attr("disabled","disabled")
				disabled = true;
			}
		}
		-->
		</script>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php print get_data_source_title(get_request_var("id"));?>
				</td>
				<td style="white-space:nowrap;" align="right" class="w1"><a id='tooltip' class='popup_anchor' href='#' onMouseOver="Tip('<?php print $tip_text;?>', BGCOLOR, '#EEEEEE', FIX, ['tooltip', -20, 0], STICKY, true, SHADOW, true, CLICKCLOSE, true, FADEOUT, 400, TEXTALIGN, 'right', BORDERCOLOR, '#F5F5F5')" onMouseOut="UnTip()">Data Source Options</a></td>
			</tr>
		</table>
		<?php
	}

	print "<form method='post' action='" .  basename($_SERVER["PHP_SELF"]) . "' name='data_source_edit'>\n";
	html_start_box("<strong>" . __("Data Source 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 = fields_data_source_form_list();
	$form_array["data_template_id"]["id"] = (isset($data_template["id"]) ? $data_template["id"] : "0");
	$form_array["data_template_id"]["name"] = db_fetch_cell("SELECT name FROM data_template WHERE id=" . $form_array["data_template_id"]["id"]);
	$form_array["device_id"]["id"] = (isset($_GET["device_id"]) ? $_GET["device_id"] : $data_local["device_id"]);
	$form_array["device_id"]["name"] = db_fetch_cell("SELECT CONCAT_WS('',description,' (',hostname,')') FROM device WHERE id=" . $form_array["device_id"]["id"]);

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

	print "</table></td></tr>";		/* end of html_header */
	html_end_box();
	form_hidden_box("hidden_data_template_id", (isset($data_template["id"]) ? $data_template["id"] : "0"), "");
	form_hidden_box("hidden_device_id", (empty($data_local["device_id"]) ? (isset($_GET["device_id"]) ? $_GET["device_id"] : "0") : $data_local["device_id"]), "");
	form_hidden_box("hidden_data_input_id", (isset($data["data_input_id"]) ? $data["data_input_id"] : "0"), "");
	form_hidden_box("data_template_data_id", (isset($data) ? $data["id"] : "0"), "");
	form_hidden_box("local_data_template_data_id", (isset($data) ? $data["local_data_template_data_id"] : "0"), "");
	form_hidden_box("local_data_id", (isset($data) ? $data["local_data_id"] : "0"), "");

	/* only display the "inputs" area if we are using a data template for this data source */
	if (!empty($data["data_template_id"])) {

		html_start_box("<strong>" . __("Supplemental Data Source Template Data") . "</strong>", "100", $colors["header"], 0, "center", "");

		draw_nontemplated_fields_data_source($data["data_template_id"], $data["local_data_id"], $data, "|field|", "<strong>" . __("Data Source Fields") . "</strong>", true, true, 0);
		draw_nontemplated_fields_data_source_item($data["data_template_id"], $data_source_items, "|field|_|id|", "<strong>" . __("Data Source Item Fields") . "</strong>", true, true, true, 0);
		draw_nontemplated_fields_custom_data($data["id"], "value_|id|", "<strong>" . __("Custom Data") . "</strong>", true, true, 0);

		html_end_box();

		form_hidden_box("save_component_data","1","");
	}

	if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($data["data_template_id"]))) {
		html_start_box("<strong>" . __("Data Source") . "</strong>", "100", $colors["header"], "3", "center", "");

		$form_array = array();

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

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

			if (!(($use_data_template == false) || (!empty($data_template_data{"t_" . $field_name})) || ($field_array["flags"] == "NOTEMPLATE"))) {
				$form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
			}
		}

		draw_edit_form(
			array(
				"config" => array("no_form_tag" => true),
				"fields" => inject_form_variables($form_array, (isset($data) ? $data : array()))
				)
			);

		html_end_box();


		if (!empty($_GET["id"])) {

			html_start_box("<strong>" . __("Data Source Items") . "</strong>", "100", $colors["header"], "0", "center", "data_sources_items.php?action=item_edit&local_data_id=" . $_GET["id"], true);
			draw_data_template_items_list($data_source_items, "data_sources_items.php", "local_data_id=" . $_GET["id"], $use_data_template);
			html_end_box(false);
		}

		/* data source data goes here */
		data_source_data_edit();
	}

	/* display the debug mode box if the user wants it */
	if ((isset($_SESSION["ds_debug_mode"])) && (isset($_GET["id"]))) {
		?>
		<table width="100%" align="center">
			<tr>
				<td>
					<span class="textInfo"><?php print __("Data Source Debug");?></span><br>
					<pre><?php print rrdtool_function_create(get_request_var("id"), true, array());?></pre>
				</td>
			</tr>
		</table>
		<?php
	}

	if ((isset($_SESSION["ds_info_mode"])) && (isset($_GET["id"]))) {
		$rrd_info = rrdtool_function_info($_GET["id"]);

		if (sizeof($rrd_info["rra"])) {
			$diff = rrdtool_cacti_compare($_GET["id"], $rrd_info);
			rrdtool_info2html($rrd_info, $diff);
			rrdtool_tune($rrd_info["filename"], $diff, true);
		}
	}

	if ((isset($_GET["id"])) || (isset($_GET["new"]))) {
		form_hidden_box("save_component_data_source","1","");
	}else{
		form_hidden_box("save_component_data_source_new","1","");
	}

	form_save_button_alt();

	include_once(CACTI_BASE_PATH . "/access/js/data_source_item.js");
	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}
Exemple #2
0
	case 'actions':
		data_source_form_actions();

		break;
	case 'rrd_add':
		data_source_rrd_add();

		break;
	case 'item_remove':
		data_source_rrd_remove();

		break;
	case 'data_source_data_edit':
		include_once(CACTI_BASE_PATH . "/include/top_header.php");

		data_source_data_edit();

		include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
		break;
	case 'ds_remove':
		ds_remove();

		header ("Location: data_sources.php");
		break;
	case 'data_source_edit':
		data_source_edit();

		break;

	case 'data_source_toggle_status':
		data_source_toggle_status();