function api_graph_tree_item_parent_get($graph_tree_item_id) {
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php");

	/* sanity checks */
	validate_id_die($graph_tree_item_id, "graph_tree_item_id");

	/* get a copy of the current graph tree item */
	$graph_tree_item = api_graph_tree_item_get($graph_tree_item_id);

	return api_graph_tree_item_parent_get_bykey($graph_tree_item["order_key"], $graph_tree_item["graph_tree_id"]);
}
Exemple #2
0
function api_graph_tree_item_list($graph_tree_id, $filter_array = "", $limit_sub_tree_id = "", $show_sub_tree_parent = false, $show_sub_tree_children = true, $current_page = 0, $rows_per_page = 0) {
	/* sanity checks */
	validate_id_die($graph_tree_id, "graph_tree_id");

	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_item_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_item_form_list(), false);
		}
	}

	$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";
	}

	/* only show tree items under this item if specified */
	if (db_integer_validate($limit_sub_tree_id, false, false)) {
		$graph_tree_item = api_graph_tree_item_get($limit_sub_tree_id);
		$search_key = substr($graph_tree_item["order_key"], 0, (api_graph_tree_item_depth_get($graph_tree_item["order_key"]) * CHARS_PER_TIER));

		if ($show_sub_tree_children == true) {
			$sql_where .= "and graph_tree_items.order_key like '$search_key%%'";
		}else{
			$sql_where .= " and graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'";
		}

		if ($show_sub_tree_parent == false) {
			$sql_where .= "and graph_tree_items.id != $limit_sub_tree_id";
		}
	}

	return db_fetch_assoc("select
		graph_tree_items.id,
		graph_tree_items.order_key,
		graph_tree_items.sort_children_type,
		graph_tree_items.device_grouping_type,
		graph_tree_items.item_type,
		graph_tree_items.item_value,
		graph.title_cache as graph_title,
		host.description as host_description,
		host.hostname as host_hostname
		from graph_tree_items
		left join graph on (graph_tree_items.item_value = graph.id and graph_tree_items.item_type = " . TREE_ITEM_TYPE_GRAPH . ")
		left join host on (graph_tree_items.item_value = host.id and graph_tree_items.item_type = " . TREE_ITEM_TYPE_HOST . ")
		where graph_tree_items.graph_tree_id = " . sql_sanitize($graph_tree_id) . "
		$sql_where
		order by graph_tree_items.order_key
		$sql_limit");
}
Exemple #3
0
function tree_item_edit()
{
    $_graph_tree_item_id = get_get_var_number("id");
    $_graph_tree_id = get_get_var_number("tree_id");
    if (isset_get_var("parent_id")) {
        $_graph_tree_item_parent_id = get_get_var_number("parent_id");
    }
    if (empty($_graph_tree_item_id)) {
        $header_label = "[new]";
    } else {
        $graph_tree_item = api_graph_tree_item_get($_graph_tree_item_id);
        $header_label = "[edit]";
    }
    $tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . $_GET["tree_id"] . "'");
    form_start("graph_trees_items.php", "form_graph_tree_item");
    html_start_box("<strong>Tree Items</strong> {$header_label}");
    _graph_tree_item_field__parent_item_id($_graph_tree_id, "parent_item_id", isset($_graph_tree_item_parent_id) ? $_graph_tree_item_parent_id : api_graph_tree_item_parent_get($_graph_tree_item_id), empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    _graph_tree_item_field__item_type("item_type", isset($graph_tree_item) ? $graph_tree_item["item_type"] : "", empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    _graph_tree_item_field__title("item_value_title", isset($graph_tree_item) ? $graph_tree_item["item_value"] : "", empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    _graph_tree_item_field__sort_children_type("sort_children_type", isset($graph_tree_item) ? $graph_tree_item["sort_children_type"] : "", empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    _graph_tree_item_field__propagate_changes("propagate_changes", "", empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    _graph_tree_item_field__graph("item_value_graph", isset($graph_tree_item) ? $graph_tree_item["item_value"] : "", empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    _graph_tree_item_field__device("item_value_device", isset($graph_tree_item) ? $graph_tree_item["item_value"] : "", empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    _graph_tree_item_field__device_grouping_type("device_grouping_type", isset($graph_tree_item) ? $graph_tree_item["device_grouping_type"] : "", empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    _graph_tree_item_field__item_type_js_update(isset($graph_tree_item) ? $graph_tree_item["item_type"] : TREE_ITEM_TYPE_HEADER, empty($_graph_tree_item_id) ? 0 : $_graph_tree_item_id);
    form_hidden_box("id", $_graph_tree_item_id, "");
    form_hidden_box("graph_tree_id", $_graph_tree_id, "");
    form_hidden_box("action_post", "graph_tree_item_edit");
    html_end_box();
    form_save_button("graph_trees.php?action=edit&id=" . $_graph_tree_id);
}
Exemple #4
0
function api_graph_tree_item_move($graph_tree_item_id, $direction) {
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php");

	/* sanity checks */
	validate_id_die($graph_tree_item_id, "graph_tree_item_id");

	if (($direction != "up") && ($direction != "down")) {
		return false;
	}

	/* obtain a copy of the current graph tree item */
	$graph_tree_item = api_graph_tree_item_get($graph_tree_item_id);

	/* find out where in the tree this item is located */
	$current_depth = api_graph_tree_item_depth_get($graph_tree_item["order_key"]);

	$displaced_row = db_fetch_row("select
		order_key
		from graph_tree_items
		where order_key " . ($direction == "up" ? "<" : ">") . " " . sql_sanitize($graph_tree_item["order_key"]) . "
		and order_key like '%" . sql_sanitize(substr($graph_tree_item["order_key"], ($current_depth * CHARS_PER_TIER))) . "'
		and order_key not like '%" . sql_sanitize(str_repeat('0', CHARS_PER_TIER) . substr($graph_tree_item["order_key"], ($current_depth * CHARS_PER_TIER))) . "'
		and graph_tree_id = " . $graph_tree_item["graph_tree_id"] . "
		order by order_key " .  ($direction == "up" ? "DESC" : "ASC"));

	if ((is_array($displaced_row)) && (isset($displaced_row["order_key"]))) {
		$old_root = sql_sanitize(substr($graph_tree_item["order_key"], 0, ($current_depth * CHARS_PER_TIER)));
		$new_root = sql_sanitize(substr($displaced_row["order_key"], 0, ($current_depth * CHARS_PER_TIER)));

		db_execute("UPDATE graph_tree_items SET order_key = CONCAT('" . str_pad('', ($current_depth * CHARS_PER_TIER), 'Z') . "',SUBSTRING(order_key," . (($current_depth * CHARS_PER_TIER) + 1).")) WHERE order_key LIKE '$new_root%' AND graph_tree_id = " . $graph_tree_item["graph_tree_id"]);
		db_execute("UPDATE graph_tree_items SET order_key = CONCAT('$new_root',SUBSTRING(order_key," . (($current_depth * CHARS_PER_TIER) + 1) . ")) WHERE order_key LIKE '$old_root%' AND graph_tree_id = " . $graph_tree_item["graph_tree_id"]);
		db_execute("UPDATE graph_tree_items SET order_key = CONCAT('$old_root',SUBSTRING(order_key," . (($current_depth * CHARS_PER_TIER) + 1) . ")) WHERE order_key LIKE '" . str_pad('', ($current_depth * CHARS_PER_TIER), 'Z') . "%' AND graph_tree_id = " . $graph_tree_item["graph_tree_id"]);
	}
}