Example #1
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);
}
Example #2
0
function api_graph_tree_item_remove($graph_tree_item_id) {
	require_once(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_constants.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_utility.php");

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

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

	/* find the id of the parent */
	$parent_graph_tree_item_id = api_graph_tree_item_parent_get($graph_tree_item_id);

	/* because deleting a parent branch deletes all of its children, it is very possible that
	 * the branch we are trying to delete has already been removed. */
	if (!isset($graph_tree_item["id"])) {
		return true;
	}

	/* if this item is a graph or host, it will have NO children, so we can just delete the
	 * item and exit. */
	if (($graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) || ($graph_tree_item["item_type"] == TREE_ITEM_TYPE_HOST)) {
		return db_delete("graph_tree_items",
			array(
				"id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item_id)
				));
	}

	/* make sure nothing bad happens */
	if (!api_graph_tree_item_order_key_validate($graph_tree_item["order_key"])) {
		return false;
	}

	$graph_tree_items = api_graph_tree_item_list($graph_tree_item["graph_tree_id"], "", $graph_tree_item_id, true, true);

	if (is_array($graph_tree_items) > 0) {
		/* remove all child items */
		foreach ($graph_tree_items as $_graph_tree_item) {
			db_delete("graph_tree_items",
				array(
					"id" => array("type" => DB_TYPE_INTEGER, "value" => $_graph_tree_item["id"])
					));
		}
	}

	/* CLEANUP - reorder the tier that this branch lies in */
	$base_order_key = substr($graph_tree_item["order_key"], 0, (CHARS_PER_TIER * (api_graph_tree_item_depth_get($graph_tree_item["order_key"]) - 1)));

	/* refetch the graph tree item list now that the selected item has been removed */
	$graph_tree_items = api_graph_tree_item_list($graph_tree_item["graph_tree_id"], "", $parent_graph_tree_item_id, true, true);

	if ((is_array($graph_tree_items)) && (sizeof($graph_tree_items) > 0)) {
		$old_key_part = substr($graph_tree_items[0]["order_key"], strlen($base_order_key), CHARS_PER_TIER);

		/* we key tier==0 off of '1' and tier>0 off of '0' */
		if (api_graph_tree_item_depth_get($base_order_key) == 0) {
			$i = 1;
		}else{
			$i = 0;
		}

		foreach ($graph_tree_items as $_graph_tree_item) {
			/* this is the key column we are going to 'rekey' */
			$new_key_part = substr($_graph_tree_item["order_key"], strlen($base_order_key), CHARS_PER_TIER);

			/* incriment a counter for the new key column */
			if ($old_key_part != $new_key_part) {
				$i++;
			}

			/* build the new order key string */
			$key = $base_order_key . str_pad(strval($i), CHARS_PER_TIER, '0', STR_PAD_LEFT) . substr($_graph_tree_item["order_key"], (strlen($base_order_key) + CHARS_PER_TIER));

			db_update("graph_tree_items",
				array(
					"order_key" => array("type" => DB_TYPE_STRING, "value" => $key),
					"id" => array("type" => DB_TYPE_INTEGER, "value" => $_graph_tree_item["id"])
					),
				array("id"));

			$old_key_part = $new_key_part;
		}
	}
}