Exemple #1
0
function api_graph_tree_save($graph_tree_id, &$_fields_graph_tree) {
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php");

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

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

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

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

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

		if (isset($_fields_graph_tree["sort_type"])) {
			/* sort the tree using the algorithm chosen by the user */
			api_graph_tree_item_sort(SORT_TYPE_TREE, $graph_tree_id, $_fields_graph_tree["sort_type"]);
		}

		return $graph_tree_id;
	}else{
		return false;
	}
}
Exemple #2
0
function api_graph_tree_list($filter_array = "", $current_page = 0, $rows_per_page = 0) {
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_form.php");

	$sql_where = "";
	/* validation and setup for the WHERE clause */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = api_graph_tree_fields_validate(sql_filter_array_to_field_array($filter_array));

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;
		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where = sql_filter_array_to_where_string($filter_array, api_graph_tree_form_list(), true);
		}
	}

	$sql_limit = "";
	/* validation and setup for the LIMIT clause */
	if ((is_numeric($current_page)) && (is_numeric($rows_per_page)) && (!empty($current_page)) && (!empty($rows_per_page))) {
		$sql_limit = "limit " . ($rows_per_page * ($current_page - 1)) . ",$rows_per_page";
	}

	return db_fetch_assoc("select
		graph_tree.id,
		graph_tree.name,
		graph_tree.sort_type
		from graph_tree
		$sql_where
		order by name
		$sql_limit");
}
Exemple #3
0
function api_graph_tree_fields_validate(&$_fields_graph_tree, $graph_tree_field_name_format = "|field|") {
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php");

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

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

	/* get a complete field list */
	$fields_graph_tree = api_graph_tree_form_list();

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

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

	return $error_fields;
}