Esempio n. 1
0
function package_graph_template_import(&$xml_array, $package_id, $object_hash) {
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_update.php");

	$save_fields = array();

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

	/*
	 * XML Tag: <template>
	 */

	/* obtain a list of all graph template specific fields */
	$graph_template_fields = api_graph_template_form_list();

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

	/*
	 * XML Tag: <graph>
	 */

	/* obtain a list of all graph specific fields */
	$graph_fields = api_graph_form_list();

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

	/* make sure we got the required information before trying to save */
	if ((isset($xml_array["template"])) && (isset($xml_array["graph"]))) {
		/* save the graph template field to the database and register its new id */
		$graph_template_id = package_hash_update($object_hash, api_graph_template_save(0, $save_fields));
	}

	/* make sure the save completed successfully */
	if ($graph_template_id === false) {
		return;
	}

	/*
	 * XML Tag: <items>
	 */

	/* obtain a list of all graph template item specific fields */
	$graph_template_item_fields = api_graph_template_item_form_list();

	if ((isset($xml_array["items"])) && (is_array($xml_array["items"]))) {
		$save_fields = array();

		/* get the base fields from the xml */
		foreach ($xml_array["items"] as $graph_template_item_hash => $graph_template_item) {
			$save_fields = array();

			/* make sure that each field is associated with the new graph template */
			$save_fields["graph_template_id"] = $graph_template_id;

			/* get the base fields from the xml */
			foreach (array_keys($graph_template_item_fields) as $field_name) {
				if (isset($graph_template_item[$field_name])) {
					if ($field_name == "data_template_item_id") {
						$save_fields[$field_name] = package_hash_resolve($graph_template_item[$field_name]);
					}else{
						$save_fields[$field_name] = xml_character_decode($graph_template_item[$field_name]);
					}
				}
			}

			/* save the data query field to the database and register its new id */
			package_hash_update($graph_template_item_hash, api_graph_template_item_save(0, $save_fields));
		}
	}

	/*
	 * XML Tag: <suggested_values>
	 */

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

		/* get the base fields from the xml */
		foreach ($xml_array["suggested_values"] as $field_array) {
			if ((isset($field_array["field_name"])) && (isset($field_array["sequence"])) && (isset($field_array["value"]))) {
				/* build an array containing each data input field */
				$save_fields{$field_array["field_name"]}[] = array("id" => "0", "value" => xml_character_decode($field_array["value"]));
			}
		}

		/* save the suggested values to the database */
		api_graph_template_suggested_values_save($graph_template_id, $save_fields);
	}
}
Esempio n. 2
0
function api_graph_template_item_save($graph_template_item_id, $_fields_graph_item) {
	require_once(CACTI_BASE_PATH . "/lib/sys/sequence.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php");

	/* sanity checks */
	validate_id_die($graph_template_item_id, "graph_template_item_id", true);

	/* make sure that there is at least one field to save */
	if (sizeof($_fields_graph_item) == 0) {
		return false;
	}

	/* sanity check for $graph_template_id */
	if ((empty($graph_template_item_id)) && (empty($_fields_graph_item["graph_template_id"]))) {
		log_save("Required graph_template_id when graph_template_item_id = 0", SEV_ERROR);
		return false;
	} else if ((isset($_fields_graph_item["graph_template_id"])) && (!db_integer_validate($_fields_graph_item["graph_template_id"]))) {
		return false;
	}

	/* field: id */
	$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $graph_template_item_id);

	/* field: graph_template_id */
	if (!empty($_fields_graph_item["graph_template_id"])) {
		$_fields["graph_template_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_item["graph_template_id"]);
	}

	/* field: sequence */
	if (empty($graph_template_item_id)) {
		$_fields["sequence"] = array("type" => DB_TYPE_INTEGER, "value" => seq_get_current($graph_template_item_id, "sequence", "graph_template_item", "graph_template_id = " . sql_sanitize($_fields_graph_item["graph_template_id"])));
	}

	/* convert the input array into something that is compatible with db_replace() */
	$_fields += sql_get_database_field_array($_fields_graph_item, api_graph_template_item_form_list());

	if (db_replace("graph_template_item", $_fields, array("id"))) {
		if (empty($graph_template_item_id)) {
			$graph_template_item_id = db_fetch_insert_id();
		}

		return $graph_template_item_id;
	}else{
		return false;
	}
}
Esempio n. 3
0
function &package_graph_template_export($graph_template_id, $indent = 3) {
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");

	$xml = "";

	/*
	 * XML Tag: <template>
	 */

	/* obtain a list of all graph template specific fields */
	$graph_template_fields = api_graph_template_form_list();
	/* obtain a copy of this specfic graph template */
	$graph_template = api_graph_template_get($graph_template_id);

	$_xml = "";
	foreach (array_keys($graph_template_fields) as $field_name) {
		/* create an XML key for each graph template field */
		$_xml .= package_xml_tag_get($field_name, xml_character_encode($graph_template[$field_name]), $indent + 2);
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("template", $_xml, $indent + 1, true);

	/*
	 * XML Tag: <graph>
	 */

	/* obtain a list of all graph specific fields */
	$graph_fields = api_graph_form_list();

	$_xml = "";
	foreach (array_keys($graph_fields) as $field_name) {
		/* check because the 'title' column does not exist */
		if (isset($graph_template[$field_name])) {
			/* create an XML key for each graph field */
			$_xml .= package_xml_tag_get($field_name, xml_character_encode($graph_template[$field_name]), $indent + 2);
		}

		/* create an XML key for each "template" graph field */
		$_xml .= package_xml_tag_get("t_" . $field_name, xml_character_encode($graph_template{"t_" . $field_name}), $indent + 2);
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("graph", $_xml, $indent + 1, true);

	/*
	 * XML Tag: <items>
	 */

	/* obtain a list of all graph template item specific fields */
	$graph_template_items_fields = api_graph_template_item_form_list();
	/* obtain a list of all graph template items associated with this graph template */
	$graph_template_items = api_graph_template_item_list($graph_template_id);

	$_xml = "";
	if (sizeof($graph_template_items) > 0) {
		foreach ($graph_template_items as $graph_template_item) {
			$__xml = "";
			foreach (array_keys($graph_template_items_fields) as $field_name) {
				if ($field_name == "data_template_item_id") {
					/* create an XML key for the 'data_template_item_id' field, making sure to resolve internal  ID's */
					$__xml .= package_xml_tag_get($field_name, xml_character_encode(package_hash_get($graph_template_item[$field_name], "data_template_item")), $indent + 3);
				}else{
					/* create an XML key for each graph template item field */
					$__xml .= package_xml_tag_get($field_name, xml_character_encode($graph_template_item[$field_name]), $indent + 3);
				}
			}

			/* append the result onto a temporary XML string */
			$_xml .= package_xml_tag_get(package_hash_get($graph_template_item["id"], "graph_template_item"), $__xml, $indent + 2, true);
		}
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("items", $_xml, $indent + 1, true);

	/*
	 * XML Tag: <inputs>
	 */

	/* obtain a list of all graph template item input specific fields */
	$graph_template_inputs_fields = api_graph_template_item_input_form_list();
	/* obtain a list of all graph template item inputs associated with this graph template */
	$graph_template_inputs = api_graph_template_item_input_list($graph_template_id);

	$_xml = "";
	if (sizeof($graph_template_inputs) > 0) {
		foreach ($graph_template_inputs as $graph_template_input) {
			$__xml = "";
			foreach (array_keys($graph_template_inputs_fields) as $field_name) {
				/* create an XML key for each graph template item input field */
				$__xml .= package_xml_tag_get($field_name, xml_character_encode($graph_template_input[$field_name]), $indent + 3);
			}

			/* obtain a list of each item associated with this graph template item input */
			$graph_template_input_items = api_graph_template_item_input_item_list($graph_template_id);

			if (sizeof($graph_template_input_items) > 0) {
				$i = 0; $items_list = "";
				foreach ($graph_template_input_items as $graph_template_item_id) {
					/* create a delimited list of each item, making sure to resolve internal ID's */
					$items_list .= package_hash_get($graph_template_item_id, "graph_template_item") . (($i + 1) < sizeof($graph_template_input_items) ? "|" : "");

					$i++;
				}
			}

			/* add the items list that we created above */
			$__xml .= package_xml_tag_get("items", $items_list, $indent + 3);

			/* append the result onto a temporary XML string */
			$_xml .= package_xml_tag_get(package_hash_get($graph_template_input["id"], "graph_template_input"), $__xml, $indent + 2, true);
		}
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("inputs", $_xml, $indent + 1, true);

	/*
	 * XML Tag: <suggested_values>
	 */

	/* obtain a list of all suggested values associated with this graph template */
	$graph_template_suggested_values = api_graph_template_suggested_values_list($graph_template_id);

	$_xml = "";
	if (sizeof($graph_template_suggested_values) > 0) {
		$i = 0;
		foreach ($graph_template_suggested_values as $graph_template_suggested_value) {
			$__xml = "";

			/* create an XML key for each suggested value field */
			$__xml .= package_xml_tag_get("field_name", xml_character_encode($graph_template_suggested_value["field_name"]), $indent + 3);
			$__xml .= package_xml_tag_get("sequence", xml_character_encode($graph_template_suggested_value["sequence"]), $indent + 3);
			$__xml .= package_xml_tag_get("value", xml_character_encode($graph_template_suggested_value["value"]), $indent + 3);

			/* break out each row into its own key */
			$_xml .= package_xml_tag_get("item_" . str_pad($i, 5, "0", STR_PAD_LEFT), $__xml, $indent + 2, true);

			$i++;
		}
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("suggested_values", $_xml, $indent + 1, true);

	/* wrap the whole XML string into a 'graph_template' tag and return it */
	$xml = package_xml_tag_get(package_hash_get($graph_template_id, "graph_template"), $xml, $indent, true);

	return $xml;
}