0) where graph_tree_items.graph_tree_id=$tree_id and graph_tree_items.order_key like '$search_key%' 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); ++$num_graphs[$parent_key]; } ## 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. if (!$hide[$leaf["order_key"]]) { for ($j = 1; $j < $tier; ++$j) { $parent_key = str_pad(substr($leaf["order_key"],0,($j * 2) ),60,'0',STR_PAD_RIGHT); if ($hide[$parent_key]) { $skip[$leaf["order_key"]] = 1; } } } if (! $skip[$leaf["order_key"]]) { if (!$leaf["local_graph_id"]) { if (! $hide[$leaf["order_key"]]) { if ($num_graphs[$leaf["order_key"]] > 0) { ++$rowspans[$leaf["order_key"]]; } } $j = $tier - 1; $parent_key = str_pad(substr($leaf["order_key"],0,$j * 2 ),60,'0',STR_PAD_RIGHT); $rowspans[$parent_key] += ($rowspans[$leaf["order_key"]] + 1); } } } $indent = " "; print "\n"; print ""; print ""; $already_open = false; ## Here we go. Starting the main tree drawing loop. if (sizeof($heirarchy) > 0) { foreach ($heirarchy as $leaf) { if ($skip{$leaf["order_key"]}) { continue; } $tier = tree_tier($leaf["order_key"], 2); $current_leaf_type = $leaf["local_graph_id"] ? "graph" : "heading"; if ($current_leaf_type == 'heading') { ## 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 "
[root] - " . db_fetch_cell("select name from graph_tree where id=" . $_SESSION["sess_view_tree_id"]) . "
\n"; $already_open = false; } } $colspan = (($max_tier - $tier) * 2); $rowspan = $rowspans{$leaf["order_key"]}; if (! $already_open) { print "\n"; $already_open = true; } if ($options["use_expand_contract"]) { if ($hide[$leaf["order_key"]] == 1) { $other_status = '0'; $ec_icon = 'show'; }else{ $other_status = '1'; $ec_icon = 'hide'; ++$heading_ct; } print " \n"; }else{ print "$indent\n"; } print " " . $leaf["title"] . "\n"; $already_open = false; ## If a heading isn't hidden and has graphs, start the vertical bar. if (! $hide{$leaf["order_key"]} && $rowspan > 0) { print " \n"; $already_open = true; } ## If this heading has graphs and we're supposed to show graphs, start that table. if ($num_graphs{$leaf["order_key"]} > 0 && ! $hide{$leaf["order_key"]}) { $need_table_close = true; print "\n"; }else{ $need_table_close = false; } $graph_ct = 0; }else{ ++$graph_ct; print "\n"; } } } } print "
" . $leaf["graph_title"] . "\n"; if ($graph_ct % 2 == 0) { 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. 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 "$transparent_indent" . $leaf["graph_title"] . "\n"; print "Graph"; }else{ print "$transparent_indent" . $leaf["title"] . " (Add)\n"; print "Heading"; } print "\n Move Down\n Move Up\n \n"; print "\n Delete \n \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"; } ?>