Exemple #1
0
function create_dhtml_tree_export($tree_id)
{
    /* record start time */
    list($micro, $seconds) = explode(" ", microtime());
    $start = $seconds + $micro;
    $search_key = "";
    $dhtml_tree = array();
    $dhtml_tree[0] = $start;
    $dhtml_tree[1] = read_graph_config_option("expand_hosts");
    $i = 1;
    $tree_list = get_graph_tree_array_export();
    /* auth check for hosts on the trees */
    $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));
    $sql_join = "LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))";
    if ($current_user["policy_hosts"] == "1") {
        $sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.host_id>0)";
    } elseif ($current_user["policy_hosts"] == "2") {
        $sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.host_id>0)";
    }
    if (sizeof($tree_list) > 0) {
        foreach ($tree_list as $tree) {
            if (read_config_option("export_tree_isolation") == "on" && $tree_id == $tree["id"] || read_config_option("export_tree_isolation") == "off") {
                $hier_sql = "SELECT DISTINCT\n\t\t\t\t\tgraph_tree_items.id,\n\t\t\t\t\tgraph_tree_items.title,\n\t\t\t\t\tgraph_tree_items.order_key,\n\t\t\t\t\tgraph_tree_items.host_id,\n\t\t\t\t\tgraph_tree_items.host_grouping_type,\n\t\t\t\t\thost.description as hostname\n\t\t\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t\t\tLEFT JOIN host ON (host.id=graph_tree_items.host_id)\n\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates_graph.graph_template_id=graph_templates.id)\n\t\t\t\t\t{$sql_join}\n\t\t\t\t\tWHERE graph_tree_items.graph_tree_id=" . $tree["id"] . "\n\t\t\t\t\t{$sql_where}\n\t\t\t\t\tAND graph_tree_items.local_graph_id = 0\n\t\t\t\t\tORDER BY graph_tree_items.order_key";
                $hierarchy = db_fetch_assoc($hier_sql);
                $dhtml_tree_id = 0;
                if (sizeof($hierarchy) > 0) {
                    $last_tier = 1;
                    $openli = false;
                    $lasthost = false;
                    $opentree = false;
                    foreach ($hierarchy as $leaf) {
                        if ($dhtml_tree_id != $tree["id"]) {
                            if ($opentree) {
                                $i++;
                                $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n";
                            }
                            $i++;
                            $clean_id = clean_up_export_name(get_tree_name($tree["id"]) . "_" . $tree['id']);
                            $dhtml_tree[$i] = "\t<ul>\n\t\t<li id='{$clean_id}'><a href='" . $clean_id . ".html'>" . get_tree_name($tree["id"]) . "</a>\n\t\t\t<ul>\n";
                            $opentree = true;
                        }
                        $dhtml_tree_id = $tree["id"];
                        $tier = tree_tier($leaf["order_key"]);
                        if ($leaf["host_id"] > 0) {
                            //It's a host
                            if ($tier > $last_tier) {
                                $i++;
                                $dhtml_tree[$i] = "\t\t\t<ul>\n";
                            } elseif ($tier < $last_tier) {
                                if (!$lasthost) {
                                    $i++;
                                    $dhtml_tree[$i] = "\t\t\t\t</li>\n";
                                }
                                for ($x = $tier; $x < $last_tier; $x++) {
                                    $i++;
                                    $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t\t\t</li>\n";
                                    $openli = false;
                                }
                            } elseif ($openli && !$lasthost) {
                                $i++;
                                $dhtml_tree[$i] = "\t\t\t\t</li>\n";
                                $openli = false;
                            }
                            $last_tier = $tier;
                            $lasthost = true;
                            $i++;
                            $clean_id = clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]);
                            $dhtml_tree[$i] = "\t\t\t\t<li id='{$clean_id}' data-jstree='{ \"icon\" : \"./server.png\" }'><a href=\"" . $clean_id . ".html\">Host: " . htmlspecialchars($leaf["hostname"]) . "</a>\n";
                            if (read_config_option("export_tree_expand_hosts") == "on") {
                                $i++;
                                $dhtml_tree[$i] = "\t\t\t\t\t<ul>\n";
                                if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
                                    $graph_templates = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\t\t\tgraph_templates.id,\n\t\t\t\t\t\t\t\t\tgraph_templates.name,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\t\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.export='on'\n\t\t\t\t\t\t\t\t\tGROUP BY graph_templates.id\n\t\t\t\t\t\t\t\t\tORDER BY graph_templates.name");
                                    if (sizeof($graph_templates) > 0) {
                                        foreach ($graph_templates as $graph_template) {
                                            $i++;
                                            $clean_id = clean_up_export_name($leaf["hostname"] . "_gt_" . $leaf["id"] . "_" . $graph_template["id"]);
                                            $dhtml_tree[$i] = "\t\t\t\t\t\t<li id='" . $clean_id . "' data-jstree='{ \"icon\" : \"./server_chart.png\" }'><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($graph_template["name"]) . "</a></li>\n";
                                        }
                                    }
                                } else {
                                    if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
                                        $data_queries = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\t\t\t\t\tsnmp_query.name\n\t\t\t\t\t\t\t\t\tFROM (graph_local,snmp_query)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tGROUP BY snmp_query.id\n\t\t\t\t\t\t\t\t\tORDER BY snmp_query.name");
                                        array_push($data_queries, array("id" => "0", "name" => "Non Query Based"));
                                        if (sizeof($data_queries) > 0) {
                                            foreach ($data_queries as $data_query) {
                                                $i++;
                                                $clean_id = clean_up_export_name($leaf["hostname"] . "_dq_" . $leaf["title"] . "_" . $leaf["id"] . "_" . $data_query["id"]);
                                                if ($data_query['name'] != 'Non Query Based') {
                                                    $dhtml_tree[$i] = "\t\t\t\t\t\t<li id='" . $clean_id . "' data-jstree='{ \"icon\" : \"./server_dataquery.png\" }'><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($data_query["name"]) . "</a>\n";
                                                } else {
                                                    $dhtml_tree[$i] = "\t\t\t\t\t\t<li id='" . $clean_id . "' data-jstree='{ \"icon\" : \"./server_chart.png\" }'><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($data_query["name"]) . "</a>\n";
                                                }
                                                /* fetch a list of field names that are sorted by the preferred sort field */
                                                $sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);
                                                if ($data_query["id"] > 0) {
                                                    $i++;
                                                    $dhtml_tree[$i] = "\t\t\t\t\t\t\t<ul>\n";
                                                    while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
                                                        $i++;
                                                        $clean_id = clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["id"] . "_" . $data_query["id"] . "_" . $snmp_index);
                                                        $dhtml_tree[$i] = "\t\t\t\t\t\t\t\t<li id='" . $clean_id . "' data-jstree='{ \"icon\" : \"./server_chart_curve.png\" }'><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($sort_field_value) . "</a></li>\n";
                                                    }
                                                    $i++;
                                                    $dhtml_tree[$i] = "\t\t\t\t\t\t\t</ul>\n";
                                                }
                                                $i++;
                                                $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
                                            }
                                        }
                                    }
                                }
                                $i++;
                                $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n";
                            }
                            $i++;
                            $dhtml_tree[$i] = "\t\t\t\t</li>\n";
                        } else {
                            //It's not a host
                            if ($tier > $last_tier) {
                                $i++;
                                $dhtml_tree[$i] = "\t\t\t<ul>\n";
                            } elseif ($tier < $last_tier) {
                                if (!$lasthost) {
                                    $i++;
                                    $dhtml_tree[$i] = "</li>\n";
                                }
                                for ($x = $tier; $x < $last_tier; $x++) {
                                    $i++;
                                    $dhtml_tree[$i] = "\t\t\t\t</ul>\n\t\t\t\t</li>\n";
                                    $openli = false;
                                }
                            } elseif ($openli && !$lasthost) {
                                $i++;
                                $dhtml_tree[$i] = "</li>\n";
                                $openli = false;
                            }
                            $last_tier = $tier;
                            $i++;
                            $clean_id = clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]);
                            $dhtml_tree[$i] = "\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($leaf["title"]) . "</a>\n";
                            $openli = true;
                            $lasthost = false;
                        }
                    }
                    for ($x = $last_tier; $x > 1; $x--) {
                        $i++;
                        $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n\t\t\t\t</li>\n";
                    }
                    $i++;
                    $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n";
                } else {
                    if ($dhtml_tree_id != $tree["id"]) {
                        $i++;
                        $clean_id = clean_up_export_name(get_tree_name($tree["id"]) . "_" . $tree['id']);
                        $dhtml_tree[$i] = "\t<ul>\n\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">" . get_tree_name($tree["id"]) . "</a></li>\n\t</ul>";
                    }
                }
            }
        }
    }
    return $dhtml_tree;
}
Exemple #2
0
function create_dhtml_tree_export($tree_id)
{
    /* record start time */
    list($micro, $seconds) = split(" ", microtime());
    $start = $seconds + $micro;
    $search_key = "";
    $dhtml_tree = array();
    $dhtml_tree[0] = $start;
    $dhtml_tree[1] = read_graph_config_option("expand_hosts");
    $dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
    $i = 2;
    $tree_list = get_graph_tree_array_export();
    /* auth check for hosts on the trees */
    $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));
    $sql_join = "LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))";
    if ($current_user["policy_hosts"] == "1") {
        $sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.host_id>0)";
    } elseif ($current_user["policy_hosts"] == "2") {
        $sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.host_id>0)";
    }
    if (sizeof($tree_list) > 0) {
        foreach ($tree_list as $tree) {
            if (read_config_option("export_tree_isolation") == "on" && $tree_id == $tree["id"] || read_config_option("export_tree_isolation") == "off") {
                $i++;
                $hier_sql = "SELECT DISTINCT\n\t\t\t\t\tgraph_tree_items.id,\n\t\t\t\t\tgraph_tree_items.title,\n\t\t\t\t\tgraph_tree_items.order_key,\n\t\t\t\t\tgraph_tree_items.host_id,\n\t\t\t\t\tgraph_tree_items.host_grouping_type,\n\t\t\t\t\thost.description as hostname\n\t\t\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t\t\tLEFT JOIN host ON (host.id=graph_tree_items.host_id)\n\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates_graph.graph_template_id=graph_templates.id)\n\t\t\t\t\t{$sql_join}\n\t\t\t\t\tWHERE graph_tree_items.graph_tree_id=" . $tree["id"] . "\n\t\t\t\t\t{$sql_where}\n\t\t\t\t\tAND graph_tree_items.local_graph_id = 0\n\t\t\t\t\tORDER BY graph_tree_items.order_key";
                $hierarchy = db_fetch_assoc($hier_sql);
                $dhtml_tree_id = 0;
                if (sizeof($hierarchy) > 0) {
                    foreach ($hierarchy as $leaf) {
                        if ($dhtml_tree_id != $tree["id"]) {
                            $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
                        }
                        $dhtml_tree_id = $tree["id"];
                        $i++;
                        $tier = tree_tier($leaf["order_key"]);
                        if ($leaf["host_id"] > 0) {
                            //It's a host
                            $dhtml_tree[$i] = "ou" . $tier . " = insFld(ou" . ($tier - 1) . ", gFld(\"<strong>Host:</strong> " . $leaf["hostname"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]) . ".html\"))\n";
                            if (read_config_option("export_tree_expand_hosts") == "on") {
                                if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
                                    $graph_templates = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\t\t\tgraph_templates.id,\n\t\t\t\t\t\t\t\t\tgraph_templates.name,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\t\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.export='on'\n\t\t\t\t\t\t\t\t\tGROUP BY graph_templates.id\n\t\t\t\t\t\t\t\t\tORDER BY graph_templates.name");
                                    if (sizeof($graph_templates) > 0) {
                                        foreach ($graph_templates as $graph_template) {
                                            $i++;
                                            $dhtml_tree[$i] = "ou" . ($tier + 1) . " = insFld(ou" . $tier . ", gFld(\" " . $graph_template["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_gt_" . $leaf["id"]) . "_" . $graph_template["id"] . ".html\"))\n";
                                        }
                                    }
                                } else {
                                    if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
                                        $data_queries = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\t\t\t\t\tsnmp_query.name\n\t\t\t\t\t\t\t\t\tFROM (graph_local,snmp_query)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tGROUP BY snmp_query.id\n\t\t\t\t\t\t\t\t\tORDER BY snmp_query.name");
                                        array_push($data_queries, array("id" => "0", "name" => "Graph Template Based"));
                                        if (sizeof($data_queries) > 0) {
                                            foreach ($data_queries as $data_query) {
                                                $i++;
                                                $dhtml_tree[$i] = "ou" . ($tier + 1) . " = insFld(ou" . $tier . ", gFld(\" " . $data_query["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dq_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . ".html\"))\n";
                                                /* fetch a list of field names that are sorted by the preferred sort field */
                                                $sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);
                                                if ($data_query["id"] > 0) {
                                                    while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
                                                        $i++;
                                                        $dhtml_tree[$i] = "ou" . ($tier + 2) . " = insFld(ou" . ($tier + 1) . ", gFld(\" " . $sort_field_value . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . "_" . $snmp_index . ".html\"))\n";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            $dhtml_tree[$i] = "ou" . $tier . " = insFld(ou" . ($tier - 1) . ", gFld(\"" . $leaf["title"] . "\", \"" . clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]) . "_leaf.html\"))\n";
                        }
                    }
                } else {
                    if ($dhtml_tree_id != $tree["id"]) {
                        $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
                        $i++;
                    }
                }
            }
        }
    }
    return $dhtml_tree;
}
Exemple #3
0
function create_dhtml_tree_export($tree_id) {
	require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php");
	require_once(CACTI_BASE_PATH . "/include/auth/auth_constants.php");

	/* record start time */
	list($micro,$seconds) = explode(" ", microtime());
	$start = $seconds + $micro;
	$search_key = "";

	$dhtml_tree = array();
	$dhtml_tree[0] = $start;
	$dhtml_tree[1] = read_graph_config_option("expand_devices");
	$dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
	$i = 2;

	$tree_list = get_graph_tree_array_export();

	/* auth check for devices on the trees */
	$current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));

	$sql_join  = "LEFT JOIN user_auth_perms ON (device.id=user_auth_perms.item_id AND user_auth_perms.type=" . PERM_DEVICES . " AND user_auth_perms.user_id=" . $current_user["id"] . ")";

	if ($current_user["policy_devices"] == "1") {
		$sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.device_id>0)";
	}elseif ($current_user["policy_devices"] == "2") {
		$sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.device_id>0)";
	}

	if (sizeof($tree_list) > 0) {
	foreach ($tree_list as $tree) {
		if (((read_config_option("export_tree_isolation") == CHECKED) && ($tree_id == $tree["id"])) ||
			(read_config_option("export_tree_isolation") == "off")) {

			$i++;

			$hier_sql = "SELECT DISTINCT
					graph_tree_items.id,
					graph_tree_items.title,
					graph_tree_items.order_key,
					graph_tree_items.device_id,
					graph_tree_items.device_grouping_type,
					device.description as hostname
					FROM (graph_tree_items, graph_templates_graph)
					LEFT JOIN device ON (device.id=graph_tree_items.device_id)
					LEFT JOIN graph_templates ON (graph_templates_graph.graph_template_id=graph_templates.id)
					$sql_join
					WHERE graph_tree_items.graph_tree_id=" . $tree["id"] . "
					$sql_where
					AND graph_tree_items.local_graph_id = 0
					ORDER BY graph_tree_items.order_key";

			$hierarchy = db_fetch_assoc($hier_sql);

			$dhtml_tree_id = 0;

			if (sizeof($hierarchy) > 0) {
				foreach ($hierarchy as $leaf) {
					if ($dhtml_tree_id <> $tree["id"]) {
						$dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
					}
					$dhtml_tree_id = $tree["id"];

					$i++;
					$tier = tree_tier($leaf["order_key"]);

					if ($leaf["device_id"] > 0) {  //It's a device
						$dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"<strong>Host:</strong> " . $leaf["hostname"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]) . ".html\"))\n";

						if (read_config_option("export_tree_expand_devices") == CHECKED) {
							if ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_GRAPH_TEMPLATE) {
								$graph_templates = db_fetch_assoc("SELECT
									graph_templates.id,
									graph_templates.name,
									graph_templates_graph.local_graph_id,
									graph_templates_graph.title_cache
									FROM (graph_local,graph_templates,graph_templates_graph)
									WHERE graph_local.id=graph_templates_graph.local_graph_id
									AND graph_templates_graph.graph_template_id=graph_templates.id
									AND graph_local.device_id=" . $leaf["device_id"] . "
									AND graph_templates_graph.export='on'
									GROUP BY graph_templates.id
									ORDER BY graph_templates.name");

							 	if (sizeof($graph_templates) > 0) {
									foreach ($graph_templates as $graph_template) {
										$i++;
										$dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . $graph_template["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_gt_" . $leaf["id"]) . "_" . $graph_template["id"] . ".html\"))\n";
									}
								}
							}else if ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_DATA_QUERY_INDEX) {
								$data_queries = db_fetch_assoc("SELECT
									snmp_query.id,
									snmp_query.name
									FROM (graph_local,snmp_query)
									WHERE graph_local.snmp_query_id=snmp_query.id
									AND graph_local.device_id=" . $leaf["device_id"] . "
									GROUP BY snmp_query.id
									ORDER BY snmp_query.name");

								array_push($data_queries, array(
									"id" => "0",
									"name" => "Graph Template Based"
									));

								if (sizeof($data_queries) > 0) {
								foreach ($data_queries as $data_query) {
									$i++;

									$dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . $data_query["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dq_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . ".html\"))\n";

									/* fetch a list of field names that are sorted by the preferred sort field */
									$sort_field_data = get_formatted_data_query_indexes($leaf["device_id"], $data_query["id"]);

									if ($data_query["id"] > 0) {
										while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
											$i++;
											$dhtml_tree[$i] = "ou" . ($tier+2) . " = insFld(ou" . ($tier+1) . ", gFld(\" " . $sort_field_value . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . "_" . $snmp_index . ".html\"))\n";
										}
									}
								}
								}
							}
						}
					}else {
						$dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"" . $leaf["title"] . "\", \"" . clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]) . "_leaf.html\"))\n";
					}
				}
			}else{
				if ($dhtml_tree_id <> $tree["id"]) {
					$dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
					$i++;
				}
			}
		}
	}
	}

	return $dhtml_tree;
}