0)
left join settings_tree on (graph_tree_items.id=settings_tree.graph_tree_item_id and settings_tree.user_id=$user_id)
$sql_join
where graph_tree_items.graph_tree_id=$tree_id
and graph_tree_items.order_key like '$search_key%'
$sql_where
order by graph_tree_items.order_key");
$search_key = preg_replace("/0+$/","",$start_branch);
## First off, we walk the tree from the top to the root. We do it in that order so that we
for ($i = (sizeof($heirarchy) - 1); $i >= 0; --$i) {
$leaf = $heirarchy[$i];
## While we're walking the tree, let's go ahead and set 'hide' flags for any branches that should be hidden (status in settings_viewing_tree == 1)
if ($leaf["status"] == "1") {
$hide[$leaf["order_key"]] = "1";
}
$tier = tree_tier($leaf["order_key"], 2);
## If there's a local_graph_id, the leaf is a graph, not a heading, so we increment the parent's num_graphs
if ($leaf["local_graph_id"]) {
$parent_key = str_pad(substr($leaf["order_key"],0,(($tier - 1) * 2) ),60,'0',STR_PAD_RIGHT);
if (isset($num_graphs[$parent_key])) {
$num_graphs[$parent_key]++;
}else{
$num_graphs[$parent_key] = 1;
}
}
## We also need the max_tier to do colspans so we do this to get it:
if ($tier > $max_tier) { $max_tier = $tier; }
}
## Now that we know how many graphs each heading has and whether it's supposed to be hidden, we walk the tree again from top to root to figure
## out how many rows each vertical bar should span.
for ($i = (sizeof($heirarchy) - 1); $i >= 0; --$i) {
$leaf = $heirarchy[$i];
$tier = tree_tier($leaf["order_key"], 2);
## Step through the hidden headings to see which entries to skip.
for ($j = 1; $j < $tier; ++$j) {
$parent_key = str_pad(substr($leaf["order_key"],0,($j * 2) ),60,'0',STR_PAD_RIGHT);
if (!empty($hide[$parent_key])) {
$skip{$leaf["order_key"]} = "1";
}
}
if (empty($skip{$leaf["order_key"]})) {
if (empty($leaf["local_graph_id"])) {
if (empty($hide{$leaf["order_key"]})) {
if (!empty($num_graphs{$leaf["order_key"]})) {
if (isset($rowspans{$leaf["order_key"]})) {
$rowspans{$leaf["order_key"]}++;
}else{
$rowspans{$leaf["order_key"]} = "1";
}
}
}
$j = $tier - 1;
$parent_key = str_pad(substr($leaf["order_key"],0,$j * 2 ),60,'0',STR_PAD_RIGHT);
if (!isset($rowspans[$parent_key])) {
$rowspans[$parent_key] = "0";
}
if (!isset($rowspans{$leaf["order_key"]})) {
$rowspans{$leaf["order_key"]} = "0";
}
$rowspans[$parent_key] += ($rowspans{$leaf["order_key"]} + 1);
}
}
}
print "\n";
print "
";
print "
[root] - " . db_fetch_cell("select name from graph_tree where id=" . $_SESSION["sess_view_tree_id"]) . "
";
$already_open = false;
$heading_ct = 0;
$graph_ct = 0;
$i = 0;
## Here we go. Starting the main tree drawing loop.
if (sizeof($heirarchy) > 0) {
foreach ($heirarchy as $leaf) {
if (!empty($skip{$leaf["order_key"]})) { continue; }
$tier = tree_tier($leaf["order_key"], 2);
$current_leaf_type = $leaf["title"] ? "heading" : "graph";
if (($current_leaf_type == 'heading') || ($i == 0)) {
## If this isn't the first heading, we may have to close tables/rows.
if ($heading_ct > 0) {
if ($need_table_close) {
if ($graph_ct % 2 == 0) { print "\n"; }
print "
\n";
$already_open = false;
}
## If a heading isn't hidden and has graphs, start the vertical bar.
if ((empty($hide{$leaf["order_key"]})) && ($rowspan > 0) && (!empty($leaf["title"]))) {
print "
\n";
$already_open = true;
}
## If this heading has graphs and we're supposed to show graphs, start that table.
if ((!empty($num_graphs{$leaf["order_key"]})) && (empty($hide{$leaf["order_key"]}))) {
$need_table_close = true;
print "
";
}
function grow_edit_graph_tree($tree_id, $user_id, $options) {
global $config, $colors;
include_once ('include/form.php');
include_once ('include/tree_functions.php');
$tree = db_fetch_assoc("select
graph_tree_items.id,
graph_tree_items.title,
graph_tree_items.local_graph_id,
graph_tree_items.order_key,
graph_templates_graph.title as graph_title
from graph_tree_items
left join graph_templates_graph on (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id and graph_tree_items.local_graph_id>0)
where graph_tree_items.graph_tree_id=$tree_id
order by graph_tree_items.order_key");
print "\n";
## Here we go. Starting the main tree drawing loop.
$i = 0;
if (sizeof($tree) > 0) {
foreach ($tree as $leaf) {
$tier = tree_tier($leaf["order_key"], 2);
$transparent_indent = " ";
if ($i % 2 == 0) { $row_color = $colors["form_alternate1"]; }else{ $row_color = $colors["form_alternate2"]; } $i++;
if ($leaf["title"] == "") {
print "
\n";
}
}
}
function grow_dropdown_tree($tree_id, $form_name, $selected_tree_item_id) {
global $colors;
include_once ('include/tree_functions.php');
$tree = db_fetch_assoc("select
graph_tree_items.id,
graph_tree_items.title,
graph_tree_items.order_key
from graph_tree_items
where graph_tree_items.graph_tree_id=$tree_id
and graph_tree_items.title != ''
order by graph_tree_items.order_key");
print "\n";
}
?>