function reparent_branch($new_parent_id, $tree_item_id)
{
if (empty($tree_item_id)) {
return 0;
}
/* get the current tree_id */
$graph_tree_id = db_fetch_cell("select graph_tree_id from graph_tree_items where id={$tree_item_id}");
/* make sure the parent id actually changed */
if (get_parent_id($tree_item_id, "graph_tree_items", "graph_tree_id={$graph_tree_id}") == $new_parent_id) {
return 0;
}
/* get current key so we can do a sql select on it */
$old_order_key = db_fetch_cell("select order_key from graph_tree_items where id={$tree_item_id}");
$new_order_key = get_next_tree_id(db_fetch_cell("select order_key from graph_tree_items where id={$new_parent_id}"), "graph_tree_items", "order_key", "graph_tree_id={$graph_tree_id}");
/* yeah, this would be really bad */
if (empty($old_order_key)) {
return 0;
}
$old_starting_tier = tree_tier($old_order_key);
$new_starting_tier = tree_tier($new_order_key);
$new_base_tier = substr($new_order_key, 0, $new_starting_tier * CHARS_PER_TIER);
$old_base_tier = substr($old_order_key, 0, $old_starting_tier * CHARS_PER_TIER);
/* prevent possible collisions */
db_execute("update graph_tree_items set order_key = CONCAT('x',order_key) where order_key like '{$old_base_tier}%%' and graph_tree_id={$graph_tree_id}");
/* truncate */
if ($new_starting_tier >= $old_starting_tier) {
db_execute("update graph_tree_items set order_key = SUBSTRING(REPLACE(order_key, 'x{$old_base_tier}', '{$new_base_tier}'), 1, " . MAX_TREE_DEPTH * CHARS_PER_TIER . ") where order_key like 'x{$old_base_tier}%%' and graph_tree_id={$graph_tree_id}");
/* append */
} else {
db_execute("update graph_tree_items set order_key = CONCAT(REPLACE(order_key, 'x{$old_base_tier}', '{$new_base_tier}'), '" . str_repeat('0', strlen($old_base_tier) - strlen($new_base_tier)) . "') where order_key like 'x{$old_base_tier}%%' and graph_tree_id={$graph_tree_id}");
}
}
开发者ID:songchin,项目名称:Cacti,代码行数:32,代码来源:tree.php
示例3: explore_tree
function explore_tree($path, $tree_id, $parent_tree_item_id)
{
/* seek graph_tree_items of the tree_id which are NOT graphs but headers */
$links = db_fetch_assoc("SELECT\n\t\tid,\n\t\ttitle,\n\t\thost_id\n\t\tFROM graph_tree_items\n\t\tWHERE rra_id = 0\n\t\tAND graph_tree_id = " . $tree_id);
$total_graphs_created = 0;
foreach ($links as $link) {
/* this test gives us the parent of the curent graph_tree_item */
if (get_parent_id($link["id"], "graph_tree_items", "graph_tree_id = " . $tree_id) == $parent_tree_item_id) {
if (get_tree_item_type($link["id"]) == "host") {
if (read_config_option("export_tree_isolation") == "off") {
$total_graphs_created += export_build_tree_single(clean_up_export_name($path), clean_up_export_name(get_host_description($link["host_id"]) . "_" . $link["id"] . ".html"), $tree_id, $link["id"]);
} else {
$total_graphs_created += export_build_tree_isolated(clean_up_export_name($path), clean_up_export_name(get_host_description($link["host_id"]) . "_" . $link["id"] . ".html"), $tree_id, $link["id"]);
}
} else {
/*now, this graph_tree_item is the parent of others graph_tree_items*/
if (read_config_option("export_tree_isolation") == "off") {
$total_graphs_created += export_build_tree_single(clean_up_export_name($path), clean_up_export_name($link["title"] . "_" . $link["id"] . ".html"), $tree_id, $link["id"]);
} else {
$total_graphs_created += export_build_tree_isolated(clean_up_export_name($path), clean_up_export_name($link["title"] . "_" . $link["id"] . ".html"), $tree_id, $link["id"]);
}
}
}
}
return $total_graphs_created;
}
function item_edit() {
global $colors;
require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php");
require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php");
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("tree_id"));
/* ==================================================== */
if (!empty($_GET["id"])) {
$tree_item = db_fetch_row("select * from graph_tree_items where id=" . $_GET["id"]);
if ($tree_item["local_graph_id"] > 0) { $db_type = TREE_ITEM_TYPE_GRAPH; }
if ($tree_item["title"] != "") { $db_type = TREE_ITEM_TYPE_HEADER; }
if ($tree_item["device_id"] > 0) { $db_type = TREE_ITEM_TYPE_DEVICE; }
}
if (isset($_GET["type_select"])) {
$current_type = $_GET["type_select"];
}elseif (isset($db_type)) {
$current_type = $db_type;
}else{
$current_type = TREE_ITEM_TYPE_HEADER;
}
$tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . $_GET["tree_id"] . "'");
print "<form action='tree.php' name='form_tree' method='post'>\n";
html_start_box("<strong>" . __("Tree Items") . "</strong>", "100", $colors["header"], "3", "center", "");
form_alternate_row_color("parent_item");
?>
<td width="50%">
<font class="textEditTitle"><?php print __("Parent Item");?></font><br>
<?php print __("Choose the parent for this header/graph.");?>
</td>
<td>
<?php grow_dropdown_tree($_GET["tree_id"], "parent_item_id", (isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"])));?>
</td>
<?php
form_end_row();
form_alternate_row_color("tree_item");
?>
<td width="50%">
<font class="textEditTitle"><?php print __("Tree Item Type");?></font><br>
<?php print __("Choose what type of tree item this is.");?>
</td>
<td>
<select name="type_select" onChange="window.location=document.form_tree.type_select.options[document.form_tree.type_select.selectedIndex].value">
<?php
while (list($var, $val) = each($tree_item_types)) {
print "<option value='" . htmlspecialchars("tree.php?action=item_edit" . (isset($_GET["id"]) ? "&id=" . $_GET["id"] : "") . (isset($_GET["parent_id"]) ? "&parent_id=" . $_GET["parent_id"] : "") . "&tree_id=" . $_GET["tree_id"] . "&type_select=" . $var) . "'"; if ($var == $current_type) { print " selected"; } print ">$val</option>\n";
}
?>
</select>
</td>
<?php
form_end_row();
?>
<tr class='rowSubHeader'>
<td colspan="2" class='textSubHeaderDark'><?php print __("Tree Item Value");?></td>
</tr>
<?php
switch ($current_type) {
case TREE_ITEM_TYPE_HEADER:
$i = 0;
/* it's nice to default to the parent sorting style for new items */
if (empty($_GET["id"])) {
$default_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=" . $_GET["parent_id"]);
}else{
$default_sorting_type = DATA_QUERY_INDEX_SORT_TYPE_NONE;
}
form_alternate_row_color("item_title"); ?>
<td width="50%">
<font class="textEditTitle"><?php print __("Title");?></font><br>
<?php print __("If this item is a header, enter a title here.");?>
</td>
<td>
<?php form_text_box("title", (isset($tree_item["title"]) ? $tree_item["title"] : ""), "", "255", 30, "text", (isset($_GET["id"]) ? $_GET["id"] : "0"));?>
</td>
<?php
form_end_row();
/* don't allow the user to change the tree item ordering if a tree order has been specified */
if ($tree_sort_type == DATA_QUERY_INDEX_SORT_TYPE_NONE) {
form_alternate_row_color("sorting_type"); ?>
<td width="50%">
<font class="textEditTitle"><?php print __("Sorting Type");?></font><br>
<?php print __("Choose how children of this branch will be sorted.");?>
</td>
<td>
<?php form_dropdown("sort_children_type", $tree_sort_types, "", "", (isset($tree_item["sort_children_type"]) ? $tree_item["sort_children_type"] : $default_sorting_type), "", "");?>
</td>
<?php
form_end_row();
}
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:tree.php
示例11: explode
// Teams
$team_ids = explode(',', $_POST['teams']);
$teamsCount = count($team_ids);
// Shortcut booleans:
$mkNewFFA = $_POST['type'] == 'FFA_TOUR';
$addMatchToFFA = $_POST['type'] == 'FFA_SINGLE';
$nameSet = isset($_POST['name']) && !empty($_POST['name']) && !ctype_space($_POST['name']);
/* Error condition definitions. */
/*
Here we test for illegal pair-ups due to league and division relations.
Normally Match::create() does this too, but we don't want to end up creating a long list of matches first, but
then have to abort because (for example) the last pair of teams are an illegal paring.
*/
$teams_OK['l'] = $teams_OK['d'] = true;
$lid = ($GOT_DID = $_POST['type'] == 'RR_TOUR' || $mkNewFFA) ? get_parent_id(T_NODE_DIVISION, $_POST['did'], T_NODE_LEAGUE) : get_parent_id(T_NODE_TOURNAMENT, $_POST['existTour'], T_NODE_LEAGUE);
$did = $GOT_DID ? $_POST['did'] : get_parent_id(T_NODE_TOURNAMENT, $_POST['existTour'], T_NODE_DIVISION);
$TIE_TEAMS = get_alt_col('leagues', 'lid', $lid, 'tie_teams');
foreach ($team_ids as $tid) {
$query = "SELECT (t.f_did = {$did}) AS 'in_did', (t.f_lid = {$lid}) AS 'in_lid' FROM teams AS t WHERE t.team_id = {$tid}";
$result = mysql_query($query);
if ($result) {
$state = mysql_fetch_assoc($result);
if (!$state['in_lid']) {
$teams_OK['l'] = false;
break;
}
if ($TIE_TEAMS && !$state['in_did']) {
$teams_OK['d'] = false;
break;
}
}
function reparent_branch($new_parent_id, $tree_item_id) {
if (empty($tree_item_id)) { return 0; }
/* get the current tree_id */
$graph_tree_id = db_fetch_cell("select graph_tree_id from graph_tree_items where id=$tree_item_id");
/* make sure the parent id actually changed */
if (get_parent_id($tree_item_id, "graph_tree_items", "graph_tree_id=$graph_tree_id") == $new_parent_id) {
return 0;
}
/* get current key so we can do a sql select on it */
$old_order_key = db_fetch_cell("select order_key from graph_tree_items where id=$tree_item_id");
$new_order_key = get_next_tree_id(db_fetch_cell("select order_key from graph_tree_items where id=$new_parent_id"), "graph_tree_items", "order_key", "graph_tree_id=$graph_tree_id");
/* yeah, this would be really bad */
if (empty($old_order_key)) { return 0; }
$old_starting_tier = tree_tier($old_order_key);
$new_starting_tier = tree_tier($new_order_key);
$new_base_tier = substr($new_order_key, 0, ($new_starting_tier * CHARS_PER_TIER));
$old_base_tier = substr($old_order_key, 0, ($old_starting_tier * CHARS_PER_TIER));
/* prevent possible collisions */
db_execute("update graph_tree_items set order_key = ".sql_function_concat("'x'","order_key")." where order_key like '$old_base_tier%%' and graph_tree_id=$graph_tree_id");
/* truncate */
if ($new_starting_tier >= $old_starting_tier) {
db_execute("update graph_tree_items set order_key = ".sql_function_substr()."(".sql_function_replace()."(order_key, 'x$old_base_tier', '$new_base_tier'), 1, " . (MAX_TREE_DEPTH * CHARS_PER_TIER) . ") where order_key like 'x$old_base_tier%%' and graph_tree_id=$graph_tree_id");
/* append */
}else{
db_execute("update graph_tree_items set order_key = ".sql_function_concat(sql_function_replace()."(order_key, 'x$old_base_tier', '$new_base_tier')"," '" . str_repeat('0', (strlen($old_base_tier) - strlen($new_base_tier))) . "'")." where order_key like 'x$old_base_tier%%' and graph_tree_id=$graph_tree_id");
}
}
开发者ID:songchin,项目名称:Cacti,代码行数:35,代码来源:tree.php
示例14: item_edit
function item_edit()
{
global $colors, $tree_sort_types;
global $tree_item_types, $host_group_types;
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("tree_id"));
/* ==================================================== */
/* modify for multi user start */
$public_tree = FALSE;
if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
if ($_GET["tree_id"] == $_SESSION["public_tree_id"]) {
$public_tree = TRUE;
} else {
if (!empty($_GET["id"])) {
if (!check_tree_item($_GET["id"])) {
access_denied();
}
}
}
}
/* modify for multi user end */
if (!empty($_GET["id"])) {
$tree_item = db_fetch_row("select * from graph_tree_items where id=" . get_request_var("id"));
if ($tree_item["local_graph_id"] > 0) {
$db_type = TREE_ITEM_TYPE_GRAPH;
}
if ($tree_item["title"] != "") {
$db_type = TREE_ITEM_TYPE_HEADER;
}
if ($tree_item["host_id"] > 0) {
$db_type = TREE_ITEM_TYPE_HOST;
}
}
if (isset($_GET["type_select"])) {
$current_type = $_GET["type_select"];
} elseif (isset($db_type)) {
$current_type = $db_type;
} else {
$current_type = TREE_ITEM_TYPE_HEADER;
}
$tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . get_request_var("tree_id") . "'");
print "<form method='post' action='tree.php' name='form_tree'>\n";
html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", "");
form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
?>
<td width="50%">
<font class="textEditTitle">Parent Item</font><br>
Choose the parent for this header/graph.
</td>
<td>
<?php
grow_dropdown_tree($_GET["tree_id"], "parent_item_id", isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"]));
?>
</td>
</tr>
<?php
form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1);
?>
<td width="50%">
<font class="textEditTitle">Tree Item Type</font><br>
Choose what type of tree item this is.
</td>
<td>
<select name="type_select" onChange="window.location=document.form_tree.type_select.options[document.form_tree.type_select.selectedIndex].value">
<?php
/* modify for multi user start */
if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
if (!db_fetch_cell("\r\n SELECT COUNT(graph_local.id) FROM graph_local\r\n INNER JOIN host ON graph_local.host_id = host.id\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'")) {
unset($tree_item_types[2]);
// graph
}
if (!db_fetch_cell("\r\n SELECT COUNT(host.id) FROM host\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'")) {
unset($tree_item_types[3]);
// host
}
if ($public_tree == TRUE) {
unset($tree_item_types[1]);
// header
unset($tree_item_types[3]);
// host
$current_type = 2;
}
}
/* modify for multi user end */
while (list($var, $val) = each($tree_item_types)) {
print "<option value='tree.php?action=item_edit" . (isset($_GET["id"]) ? "&id=" . $_GET["id"] : "") . (isset($_GET["parent_id"]) ? "&parent_id=" . $_GET["parent_id"] : "") . "&tree_id=" . $_GET["tree_id"] . "&type_select={$var}'";
if ($var == $current_type) {
print " selected";
}
print ">{$val}</option>\n";
}
?>
</select>
</td>
</tr>
<tr bgcolor='#<?php
print $colors["header_panel"];
?>
'>
//.........这里部分代码省略.........
请发表评论