Esempio n. 1
0
function host_new_graphs($selected_graphs = "", $map_id_to_index = "")
{
    global $colors;
    if (!is_array($selected_graphs)) {
        $selected_graphs = array();
        $map_id_to_index = array();
        /* summarize the 'create graph from host template/snmp index' stuff into an array */
        while (list($name, $value) = each($_POST)) {
            if (substr($name, 0, 3) == "cg_" && $name != "cg_g") {
                $matches = explode("_", $name);
                /* uniquely identify this yet to be created graph */
                $uniq_id = md5("gt" . $matches[1]);
                $map_id_to_index["gt"][$matches[1]][] = $uniq_id;
                $selected_graphs[$uniq_id]["graph_template_id"] = $matches[1];
            } else {
                if (substr($name, 0, 3) == "sg_") {
                    $matches = explode("_", $name);
                    /* uniquely identify this yet to be created graph */
                    $uniq_id = md5("dq" . $matches[1] . $matches[2]);
                    $map_id_to_index["dq"][$matches[1]][] = $uniq_id;
                    $selected_graphs[$uniq_id]["graph_template_id"] = $_POST["sgg_" . $matches[1]];
                    $selected_graphs[$uniq_id]["custom_data"]["all_dq"]["data_query_id"] = $matches[1];
                    $selected_graphs[$uniq_id]["custom_data"]["all_dq"]["data_query_index"] = $matches[2];
                } else {
                    if ($name == "cg_g" && !empty($value)) {
                        /* uniquely identify this yet to be created graph */
                        $uniq_id = md5("gt" . $_POST["cg_g"]);
                        $map_id_to_index["gt"][$_POST["cg_g"]][] = $uniq_id;
                        $selected_graphs[$uniq_id]["graph_template_id"] = $_POST["cg_g"];
                    }
                }
            }
        }
    }
    /* we use object buffering on this page to allow redirection to another page if no
    	fields are actually drawn */
    ob_start();
    require_once CACTI_BASE_PATH . "/include/top_header.php";
    print "<form method='post' action='graphs_new.php'>\n";
    $num_output_fields = 0;
    $data_query_id = 0;
    $graph_template_id = 0;
    foreach ($map_id_to_index as $form_type => $form_type_array) {
        foreach ($form_type_array as $form_type_index => $form_type_index_array) {
            if ($form_type == "gt") {
                $graph_template_id = $form_type_index;
                $data_query_id = 0;
                html_start_box("<strong>Create Graph from '" . db_fetch_cell("select template_name from graph_template where id = {$graph_template_id}") . "'", "98%", $colors["header_background"], "3", "center", "");
            } else {
                if ($form_type == "dq") {
                    /* one graph_template_id per data query, at a time */
                    $arr_values = array_values($form_type_index_array);
                    $graph_template_id = $selected_graphs[$arr_values[0]]["graph_template_id"];
                    $data_query_id = $form_type_index;
                    $num_graphs = sizeof($form_type_index_array);
                    /* DRAW: Data Query */
                    html_start_box("<strong>" . _("Create") . " {$num_graphs} " . _("Graph") . ($num_graphs > 1 ? "s" : "") . " from '" . api_data_query_name_get($data_query_id) . "'", "98%", $colors["header_background"], "3", "center", "");
                }
            }
            /* get information about this graph template */
            $graph_template = db_fetch_row("select * from graph_template where id = {$graph_template_id}");
            $num_output_fields += draw_nontemplated_fields_graph($graph_template_id, $graph_template, "g_{$data_query_id}" . "_" . $graph_template_id . "_|field|", "<strong>Graph</strong> [Template: " . $graph_template["template_name"] . "]", false);
            $num_output_fields += draw_nontemplated_fields_graph_item($graph_template_id, array_rekey(db_fetch_assoc("select * from graph_template_item where graph_template_id = {$graph_template_id}"), "id", array("id", "data_template_item_id", "color", "graph_item_type", "cdef", "consolidation_function", "gprint_format", "legend_format", "legend_value", "hard_return")), "gi_" . $data_query_id . "_" . $graph_template_id . "_|id|_|field|", "<strong>" . _("Graph Items") . "</strong> [" . _("Template: ") . $graph_template["template_name"] . "]", false);
            /* get information about each data template referenced by this graph template */
            $data_templates = db_fetch_assoc("select distinct\n\t\t\t\tdata_template.*\n\t\t\t\tfrom data_template,data_template_item,graph_template_item\n\t\t\t\twhere graph_template_item.data_template_item_id=data_template_item.id\n\t\t\t\tand data_template_item.data_template_id=data_template.id\n\t\t\t\tand graph_template_item.graph_template_id = {$graph_template_id}");
            /* DRAW: Data Sources */
            if (sizeof($data_templates) > 0) {
                foreach ($data_templates as $data_template) {
                    $num_output_fields += draw_nontemplated_fields_data_source($data_template["id"], $data_template, "d_" . $data_query_id . "_" . $graph_template_id . "_" . $data_template["id"] . "_|field|", true);
                    $num_output_fields += draw_nontemplated_fields_data_source_item($data_template["id"], db_fetch_assoc("select * from data_template_item where data_template_id = " . $data_template["id"] . " order by data_source_name"), "di_" . $data_query_id . "_" . $graph_template_id . "_" . $data_template["id"] . "_|id|_|field|", true);
                    $num_output_fields += draw_nontemplated_fields_data_input($data_template["id"], array_rekey(db_fetch_assoc("select name,value from data_template_field where data_template_id = " . $data_template["id"]), "name", array("value")), "c_" . $data_query_id . "_" . $graph_template_id . "_" . $data_template["id"] . "_|field|", "<strong>" . _("Custom Data") . "</strong> [" . _("Template: ") . $data_template["template_name"] . "]", false);
                }
            }
            html_end_box();
        }
    }
    /* no fields were actually drawn on the form; just save without prompting the user */
    if ($num_output_fields == 0) {
        ob_end_clean();
        /* since the user didn't actually click "Create" to POST the data; we have to
        		pretend like they did here */
        $_POST["host_id"] = $_POST["host_id"];
        $_POST["save_component_new_graphs"] = "1";
        $_POST["selected_graphs_array"] = addslashes(serialize($selected_graphs));
        $_POST["map_id_to_index_array"] = addslashes(serialize($map_id_to_index));
        host_new_graphs_save();
        header("Location: graphs_new.php?host_id=" . $_POST["host_id"]);
        exit;
    }
    /* flush the current output buffer to the browser */
    ob_end_flush();
    form_hidden_box("host_id", $_POST["host_id"], "0");
    form_hidden_box("save_component_new_graphs", "1", "");
    form_hidden_box("selected_graphs_array", serialize($selected_graphs), "");
    form_hidden_box("map_id_to_index_array", serialize($map_id_to_index), "");
    form_save_button("graphs_new.php?host_id=" . $_POST["host_id"]);
    require_once CACTI_BASE_PATH . "/include/bottom_footer.php";
}
Esempio n. 2
0
function host_new_graphs($host_id, $host_template_id, $selected_graphs_array)
{
    /* we use object buffering on this page to allow redirection to another page if no
    	fields are actually drawn */
    ob_start();
    top_header();
    print "<form method='post' action='graphs_new.php'>\n";
    $snmp_query_id = 0;
    $num_output_fields = array();
    while (list($form_type, $form_array) = each($selected_graphs_array)) {
        while (list($form_id1, $form_array2) = each($form_array)) {
            if ($form_type == 'cg') {
                $graph_template_id = $form_id1;
                html_start_box("<strong>Create Graph from '" . db_fetch_cell_prepared('SELECT name FROM graph_templates WHERE id = ?', array($graph_template_id)) . "'", '100%', '', '3', 'center', '');
            } elseif ($form_type == 'sg') {
                while (list($form_id2, $form_array3) = each($form_array2)) {
                    /* ================= input validation ================= */
                    input_validate_input_number($snmp_query_id);
                    /* ==================================================== */
                    $snmp_query_id = $form_id1;
                    $snmp_query_graph_id = $form_id2;
                    $num_graphs = sizeof($form_array3);
                    $snmp_query = db_fetch_row_prepared('SELECT
						snmp_query.name,
						snmp_query.xml_path
						FROM snmp_query
						WHERE snmp_query.id = ?', array($snmp_query_id));
                    $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM snmp_query_graph WHERE id = ?', array($snmp_query_graph_id));
                }
                /* DRAW: Data Query */
                html_start_box("<strong>Create {$num_graphs} Graph" . ($num_graphs > 1 ? 's' : '') . " from '" . db_fetch_cell_prepared('SELECT name FROM snmp_query WHERE id = ?', array($snmp_query_id)) . "'", '100%', '', '3', 'center', '');
            }
            /* ================= input validation ================= */
            input_validate_input_number($graph_template_id);
            /* ==================================================== */
            $data_templates = db_fetch_assoc_prepared('SELECT
				data_template.name AS data_template_name,
				data_template_rrd.data_source_name,
				data_template_data.*
				FROM (data_template, data_template_rrd, data_template_data, graph_templates_item)
				WHERE graph_templates_item.task_item_id = data_template_rrd.id
				AND data_template_rrd.data_template_id = data_template.id
				AND data_template_data.data_template_id = data_template.id
				AND data_template_rrd.local_data_id = 0
				AND data_template_data.local_data_id = 0
				AND graph_templates_item.local_graph_id = 0
				AND graph_templates_item.graph_template_id = ?
				GROUP BY data_template.id
				ORDER BY data_template.name', array($graph_template_id));
            $graph_template = db_fetch_row_prepared('SELECT
				graph_templates.name AS graph_template_name,
				graph_templates_graph.*
				FROM (graph_templates, graph_templates_graph)
				WHERE graph_templates.id = graph_templates_graph.graph_template_id
				AND graph_templates.id = ?
				AND graph_templates_graph.local_graph_id = 0', array($graph_template_id));
            $graph_template_name = db_fetch_cell_prepared('SELECT name FROM graph_templates WHERE id = ?', array($graph_template_id));
            array_push($num_output_fields, draw_nontemplated_fields_graph($graph_template_id, $graph_template, "g_{$snmp_query_id}" . '_' . $graph_template_id . '_|field|', '<strong>Graph</strong> [Template: ' . $graph_template['graph_template_name'] . ']', false, false, isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0));
            array_push($num_output_fields, draw_nontemplated_fields_graph_item($graph_template_id, 0, 'gi_' . $snmp_query_id . '_' . $graph_template_id . '_|id|_|field|', '<strong>Graph Items</strong> [Template: ' . $graph_template_name . ']', false));
            /* DRAW: Data Sources */
            if (sizeof($data_templates) > 0) {
                foreach ($data_templates as $data_template) {
                    array_push($num_output_fields, draw_nontemplated_fields_data_source($data_template['data_template_id'], 0, $data_template, 'd_' . $snmp_query_id . '_' . $graph_template_id . '_' . $data_template['data_template_id'] . '_|field|', '<strong>Data Source</strong> [Template: ' . $data_template['data_template_name'] . ']', false, false, isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0));
                    $data_template_items = db_fetch_assoc_prepared('SELECT
					data_template_rrd.*
					FROM data_template_rrd
					WHERE data_template_rrd.data_template_id = ?
					AND local_data_id = 0', array($data_template['data_template_id']));
                    array_push($num_output_fields, draw_nontemplated_fields_data_source_item($data_template['data_template_id'], $data_template_items, 'di_' . $snmp_query_id . '_' . $graph_template_id . '_' . $data_template['data_template_id'] . '_|id|_|field|', '', false, false, false, isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0));
                    array_push($num_output_fields, draw_nontemplated_fields_custom_data($data_template['id'], 'c_' . $snmp_query_id . '_' . $graph_template_id . '_' . $data_template['data_template_id'] . '_|id|', '<strong>Custom Data</strong> [Template: ' . $data_template['data_template_name'] . ']', false, false, $snmp_query_id));
                }
            }
            html_end_box();
        }
    }
    /* no fields were actually drawn on the form; just save without prompting the user */
    if (array_sum($num_output_fields) == 0) {
        ob_end_clean();
        /* since the user didn't actually click "Create" to POST the data; we have to
        		pretend like they did here */
        $_POST['host_template_id'] = $host_template_id;
        $_POST['host_id'] = $host_id;
        $_POST['save_component_new_graphs'] = '1';
        $_POST['selected_graphs_array'] = serialize($selected_graphs_array);
        host_new_graphs_save();
        header('Location: graphs_new.php?host_id=' . $_POST['host_id']);
        exit;
    }
    /* flush the current output buffer to the browser */
    ob_end_flush();
    form_hidden_box('host_template_id', $host_template_id, '0');
    form_hidden_box('host_id', $host_id, '0');
    form_hidden_box('save_component_new_graphs', '1', '');
    print "<input type='hidden' name='selected_graphs_array' value='" . serialize($selected_graphs_array) . "'>\n";
    if (!substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) {
        $_REQUEST['returnto'] = basename($_SERVER['HTTP_REFERER']);
    }
    load_current_session_value('returnto', 'sess_graphs_new_returnto', '');
    form_save_button($_REQUEST['returnto']);
    bottom_footer();
}
Esempio n. 3
0
function host_new_graphs($host_id, $host_template_id, $selected_graphs_array)
{
    /* we use object buffering on this page to allow redirection to another page if no
    	fields are actually drawn */
    ob_start();
    include_once "./include/top_header.php";
    print "<form method='post' action='graphs_new.php'>\n";
    $snmp_query_id = 0;
    $num_output_fields = array();
    while (list($form_type, $form_array) = each($selected_graphs_array)) {
        while (list($form_id1, $form_array2) = each($form_array)) {
            if ($form_type == "cg") {
                $graph_template_id = $form_id1;
                html_start_box("<strong>Create Graph from '" . db_fetch_cell("select name from graph_templates where id={$graph_template_id}") . "'", "100%", "", "3", "center", "");
            } elseif ($form_type == "sg") {
                while (list($form_id2, $form_array3) = each($form_array2)) {
                    /* ================= input validation ================= */
                    input_validate_input_number($snmp_query_id);
                    /* ==================================================== */
                    $snmp_query_id = $form_id1;
                    $snmp_query_graph_id = $form_id2;
                    $num_graphs = sizeof($form_array3);
                    $snmp_query = db_fetch_row("select\n\t\t\t\t\t\tsnmp_query.name,\n\t\t\t\t\t\tsnmp_query.xml_path\n\t\t\t\t\t\tfrom snmp_query\n\t\t\t\t\t\twhere snmp_query.id={$snmp_query_id}");
                    $graph_template_id = db_fetch_cell("select graph_template_id from snmp_query_graph where id={$snmp_query_graph_id}");
                }
                /* DRAW: Data Query */
                html_start_box("<strong>Create {$num_graphs} Graph" . ($num_graphs > 1 ? "s" : "") . " from '" . db_fetch_cell("select name from snmp_query where id={$snmp_query_id}") . "'", "100%", "", "3", "center", "");
            }
            /* ================= input validation ================= */
            input_validate_input_number($graph_template_id);
            /* ==================================================== */
            $data_templates = db_fetch_assoc("select\n\t\t\t\tdata_template.name as data_template_name,\n\t\t\t\tdata_template_rrd.data_source_name,\n\t\t\t\tdata_template_data.*\n\t\t\t\tfrom (data_template, data_template_rrd, data_template_data, graph_templates_item)\n\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\tand data_template_rrd.data_template_id=data_template.id\n\t\t\t\tand data_template_data.data_template_id=data_template.id\n\t\t\t\tand data_template_rrd.local_data_id=0\n\t\t\t\tand data_template_data.local_data_id=0\n\t\t\t\tand graph_templates_item.local_graph_id=0\n\t\t\t\tand graph_templates_item.graph_template_id=" . $graph_template_id . "\n\t\t\t\tgroup by data_template.id\n\t\t\t\torder by data_template.name");
            $graph_template = db_fetch_row("select\n\t\t\t\tgraph_templates.name as graph_template_name,\n\t\t\t\tgraph_templates_graph.*\n\t\t\t\tfrom (graph_templates, graph_templates_graph)\n\t\t\t\twhere graph_templates.id=graph_templates_graph.graph_template_id\n\t\t\t\tand graph_templates.id=" . $graph_template_id . "\n\t\t\t\tand graph_templates_graph.local_graph_id=0");
            $graph_template_name = db_fetch_cell("select name from graph_templates where id=" . $graph_template_id);
            array_push($num_output_fields, draw_nontemplated_fields_graph($graph_template_id, $graph_template, "g_{$snmp_query_id}" . "_" . $graph_template_id . "_|field|", "<strong>Graph</strong> [Template: " . $graph_template["graph_template_name"] . "]", false, false, isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0));
            array_push($num_output_fields, draw_nontemplated_fields_graph_item($graph_template_id, 0, "gi_" . $snmp_query_id . "_" . $graph_template_id . "_|id|_|field|", "<strong>Graph Items</strong> [Template: " . $graph_template_name . "]", false));
            /* DRAW: Data Sources */
            if (sizeof($data_templates) > 0) {
                foreach ($data_templates as $data_template) {
                    array_push($num_output_fields, draw_nontemplated_fields_data_source($data_template["data_template_id"], 0, $data_template, "d_" . $snmp_query_id . "_" . $graph_template_id . "_" . $data_template["data_template_id"] . "_|field|", "<strong>Data Source</strong> [Template: " . $data_template["data_template_name"] . "]", false, false, isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0));
                    $data_template_items = db_fetch_assoc("select\n\t\t\t\t\tdata_template_rrd.*\n\t\t\t\t\tfrom data_template_rrd\n\t\t\t\t\twhere data_template_rrd.data_template_id=" . $data_template["data_template_id"] . "\n\t\t\t\t\tand local_data_id=0");
                    array_push($num_output_fields, draw_nontemplated_fields_data_source_item($data_template["data_template_id"], $data_template_items, "di_" . $snmp_query_id . "_" . $graph_template_id . "_" . $data_template["data_template_id"] . "_|id|_|field|", "", false, false, false, isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0));
                    array_push($num_output_fields, draw_nontemplated_fields_custom_data($data_template["id"], "c_" . $snmp_query_id . "_" . $graph_template_id . "_" . $data_template["data_template_id"] . "_|id|", "<strong>Custom Data</strong> [Template: " . $data_template["data_template_name"] . "]", false, false, $snmp_query_id));
                }
            }
            html_end_box();
        }
    }
    /* no fields were actually drawn on the form; just save without prompting the user */
    if (array_sum($num_output_fields) == 0) {
        ob_end_clean();
        /* since the user didn't actually click "Create" to POST the data; we have to
        		pretend like they did here */
        $_POST["host_template_id"] = $host_template_id;
        $_POST["host_id"] = $host_id;
        $_POST["save_component_new_graphs"] = "1";
        $_POST["selected_graphs_array"] = serialize($selected_graphs_array);
        host_new_graphs_save();
        header("Location: graphs_new.php?host_id=" . $_POST["host_id"]);
        exit;
    }
    /* flush the current output buffer to the browser */
    ob_end_flush();
    form_hidden_box("host_template_id", $host_template_id, "0");
    form_hidden_box("host_id", $host_id, "0");
    form_hidden_box("save_component_new_graphs", "1", "");
    print "<input type='hidden' name='selected_graphs_array' value='" . serialize($selected_graphs_array) . "'>\n";
    if (!substr_count($_SERVER["HTTP_REFERER"], "graphs_new")) {
        $_REQUEST["returnto"] = basename($_SERVER["HTTP_REFERER"]);
    }
    load_current_session_value("returnto", "sess_graphs_new_returnto", "");
    form_save_button($_REQUEST["returnto"]);
    include_once "./include/bottom_footer.php";
}