Esempio n. 1
0
function form_save() {
	if ($_POST["action_post"] == "script_field_edit") {
		/* cache all post field values */
		init_post_field_cache();

		$form_script_field["data_input_id"] = $_POST["script_id"];
		$form_script_field["name"] = $_POST["name"];
		$form_script_field["data_name"] = $_POST["data_name"];
		$form_script_field["input_output"] = ($_POST["field_type"] == SCRIPT_FIELD_TYPE_INPUT ? "in" : "out");

		if ($_POST["field_type"] == SCRIPT_FIELD_TYPE_INPUT) {
			$form_script_field["field_input_type"] = $_POST["field_input_type"];

			if ($_POST["field_input_type"] == SCRIPT_FIELD_INPUT_CUSTOM) {
				$form_script_field["field_input_value"] = $_POST["field_input_value_custom"];
			}else if ($_POST["field_input_type"] == SCRIPT_FIELD_INPUT_DEVICE) {
				$form_script_field["field_input_value"] = $_POST["field_input_value_device"];
			}

			$form_script_field["regexp_match"] = $_POST["regexp_match"];
			$form_script_field["allow_empty"] = html_boolean(isset($_POST["allow_empty"]) ? $_POST["allow_empty"] : "");
		}else if ($_POST["field_type"] == SCRIPT_FIELD_TYPE_OUTPUT) {
			$form_script_field["update_rrd"] = html_boolean(isset($_POST["update_rrd"]) ? $_POST["update_rrd"] : "");
		}

		/* obtain a list of visible script field fields on the form */
		$visible_fields = api_script_field_visible_field_list($_POST["field_type"]);

		/* all non-visible fields on the form should be discarded */
		foreach ($visible_fields as $field_name) {
			$v_form_script_field[$field_name] = $form_script_field[$field_name];
		}

		field_register_error(api_script_field_field_validate($v_form_script_field, "|field|"));

		/* if the validation passes, save the row to the database */
		if (!is_error_message()) {
			$script_field_id = api_script_field_save($_POST["id"], $form_script_field);
		}

		if (is_error_message()) {
			header("Location: scripts_fields.php?action=edit&script_id=" . $_POST["script_id"] . "&id=" . (empty($script_field_id) ? $_POST["id"] : $script_field_id) . (!empty($_POST["field_type"]) ? "&field_type=" . $_POST["field_type"] : ""));
		}else{
			header("Location: scripts.php?action=edit&id=" . $_POST["script_id"]);
		}
	/* submit button on the actions area page */
	}else if ($_POST["action_post"] == "box-1") {
		$selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]);

		if ($_POST["box-1-action-area-type"] == "remove") {
			foreach ($selected_rows as $script_field_id) {
				api_script_field_remove($script_field_id);
			}
		}

		header("Location: scripts.php?action=edit&id=" . $_POST["script_id"]);
	}
}
Esempio n. 2
0
function package_script_import(&$xml_array, $package_id, $object_hash) {
	require_once(CACTI_BASE_PATH . "/lib/script/script_info.php");
	require_once(CACTI_BASE_PATH . "/lib/script/script_update.php");

	/*
	 * XML Tag: <script>
	 */

	/* obtain a list of all script specific fields */
	$script_fields = api_script_form_list();

	if (isset($xml_array["script"])) {
		$save_fields = array();

		/* tag the script as a package member */
		$save_fields["package_id"] = $package_id;

		/* get the base fields from the xml */
		foreach (array_keys($script_fields) as $field_name) {
			if (isset($xml_array["script"][$field_name])) {
				$save_fields[$field_name] = xml_character_decode($xml_array["script"][$field_name]);
			}
		}

		/* save the script to the database and register its new id */
		$script_id = package_hash_update($object_hash, api_script_save(0, $save_fields));

		if ($script_id === false) {
			return;
		}
	}

	/*
	 * XML Tag: <fields>
	 */

	/* obtain a list of all data query field specific fields */
	$script_field_fields = api_script_field_form_list();

	if ((isset($xml_array["fields"])) && (is_array($xml_array["fields"]))) {
		/* loop through each available script field */
		foreach ($xml_array["fields"] as $script_field_hash => $script_field) {
			$save_fields = array();

			/* make sure that each field is associated with the new script */
			$save_fields["data_input_id"] = $script_id;

			/* get the base fields from the xml */
			foreach (array_keys($script_field_fields) as $field_name) {
				if (isset($script_field[$field_name])) {
					$save_fields[$field_name] = xml_character_decode($script_field[$field_name]);
				}
			}

			/* save the script field to the database and register its new id */
			api_script_field_save(0, $save_fields);
		}
	}
}