コード例 #1
0
ファイル: graph_form.php プロジェクト: songchin/Cacti
function api_graph_item_fields_validate(&$_fields_graph_item, $graph_item_field_name_format) {
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");
	require_once(CACTI_BASE_PATH . "/include/graph/graph_constants.php");

	if (sizeof($_fields_graph_item) == 0) {
		return array();
	}

	/* array containing errored fields */
	$error_fields = array();

	/* get a complete field list */
	$fields_graph_item = api_graph_item_form_list();

	/* do not allow empty gprint format when the item type is GPRINT */
	if ((isset($_fields_graph_item["graph_item_type"])) && ($_fields_graph_item["graph_item_type"] == GRAPH_ITEM_TYPE_GPRINT)) {
		$fields_graph_item["gprint_format"]["validate_empty"] = false;
	}

	/* base fields */
	while (list($_field_name, $_field_array) = each($fields_graph_item)) {
		if ((isset($_fields_graph_item[$_field_name])) && (isset($_field_array["validate_regexp"])) && (isset($_field_array["validate_empty"]))) {
			$form_field_name = str_replace("|field|", $_field_name, $graph_item_field_name_format);

			if (!form_input_validate($_fields_graph_item[$_field_name], $form_field_name, $_field_array["validate_regexp"], $_field_array["validate_empty"])) {
				$error_fields[] = $form_field_name;
			}
		}
	}

	return $error_fields;
}
コード例 #2
0
function api_graph_template_item_input_propagate($graph_template_item_input_id, $value) {
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");

	if ((empty($graph_template_item_input_id)) || (!is_numeric($graph_template_item_input_id))) {
		return false;
	}

	/* retrieve a list of graph item fields */
	$graph_item_fields = api_graph_item_form_list();

	/* get the db field name for this graph item input */
	$input_field_name = db_fetch_cell("select field_name from graph_template_item_input where id = " . sql_sanitize($graph_template_item_input_id));

	if ($input_field_name != "") {
		$graph_template_items = db_fetch_assoc("select graph_template_item_id from graph_template_item_input_item where graph_template_item_input_id = " . sql_sanitize($graph_template_item_input_id));

		if (sizeof($graph_template_items) > 0) {
			foreach ($graph_template_items as $graph_template_item) {
				db_update("graph_item",
					array(
						"graph_template_item_id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_template_item["graph_template_item_id"]),
						$input_field_name => array("type" => $graph_item_fields[$input_field_name]["data_type"], "value" => $value)
						),
					array("graph_template_item_id"));
			}
		}

		return true;
	}else{
		return false;
	}
}
コード例 #3
0
ファイル: graph_update.php プロジェクト: songchin/Cacti
function api_graph_item_save($graph_item_id, &$_fields_graph_item) {
	require_once(CACTI_BASE_PATH . "/lib/sys/sequence.php");
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");

	/* sanity check for $graph_item_id */
	if (!is_numeric($graph_item_id)) {
		return false;
	}

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

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

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

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

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

	/* check for an empty field list */
	if (sizeof($_fields) == 1) {
		return true;
	}

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

	if (db_replace("graph_item", $_fields, array("id"))) {
		return true;
	}else{
		return false;
	}
}