コード例 #1
0
ファイル: graphs.php プロジェクト: songchin/Cacti
function graph_edit()
{
    global $colors;
    if (!empty($_GET["id"])) {
        $graph = db_fetch_row("select * from graph where id=" . $_GET["id"]);
        if (!empty($graph["graph_template_id"])) {
            $graph_template = db_fetch_row("select * from graph_template where id=" . $graph["graph_template_id"]);
        }
        $header_label = _("[edit: ") . $graph["title_cache"] . "]";
    } else {
        $header_label = _("[new]");
    }
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("graph_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["graph_debug_mode"] = true;
        }
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="98%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        echo $graph["title_cache"];
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='graphs.php?action=edit&id=<?php 
        print isset($_GET["id"]) ? $_GET["id"] : 0;
        ?>
&debug=<?php 
        print isset($_SESSION["graph_debug_mode"]) ? "0" : "1";
        ?>
'>Turn <strong><?php 
        print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On";
        ?>
</strong> Graph Debug Mode.</a>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    /* ==================== Box: Device/Template Selection ==================== */
    $form_array = array("graph_template_id" => array("method" => "drop_sql", "friendly_name" => _("Selected Graph Template"), "description" => _("Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied."), "value" => isset($graph) ? $graph["graph_template_id"] : "0", "none_value" => _("None"), "sql" => "select graph_template.id,graph_template.template_name as name from graph_template order by template_name"), "host_id" => array("method" => "drop_sql", "friendly_name" => _("Host"), "description" => _("Choose the host that this graph belongs to."), "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $graph["host_id"], "none_value" => _("None"), "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "id" => array("method" => "hidden", "value" => isset($graph) ? $graph["id"] : "0"));
    html_start_box("<strong>" . _("Device/Template Selection") . "</strong> {$header_label}", "98%", $colors["header_background"], "3", "center", "");
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* ==================== Box: Supplemental Template Data ==================== */
    /* only display the "inputs" area if we are using a graph template for this graph */
    if (!empty($graph["graph_template_id"])) {
        ob_start();
        html_start_box("<strong>" . _("Supplemental Template Data") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
        $num_output_fields = draw_nontemplated_fields_graph($graph["graph_template_id"], $graph, "g||field|", "<strong>" . _("Graph Fields") . "</strong>", true);
        $num_output_fields += draw_nontemplated_fields_graph_item($graph["graph_template_id"], array_rekey(db_fetch_assoc("select * from graph_item where graph_id = " . $graph["id"]), "graph_template_item_id", array("id", "data_source_item_id", "color", "graph_item_type", "cdef", "consolidation_function", "gprint_format", "legend_format", "legend_value", "hard_return")), "gip||field|||id|", "<strong>" . _("Graph Item Fields") . "</strong>", true);
        html_end_box();
        if ($num_output_fields == 0) {
            ob_end_clean();
        } else {
            ob_end_flush();
        }
    }
    /* graph item list goes here */
    if (!empty($_GET["id"]) && empty($graph["graph_template_id"])) {
        $graph_items = db_fetch_assoc("select\n\t\t\tgraph_item.id\n\t\t\tfrom graph_item\n\t\t\twhere graph_item.graph_id = " . $_GET["id"] . "\n\t\t\torder by graph_item.sequence");
        /* ==================== Box: Graph Items ==================== */
        html_start_box("<strong>" . _("Graph Items") . "</strong>", "98%", $colors["header_background"], "3", "center", "graphs_items.php?action=edit&graph_id=" . $_GET["id"]);
        draw_graph_item_editor($_GET["id"], "graph", false);
        html_end_box();
    }
    /* display sample graph, or graph source in debug mode */
    if (!empty($_GET["id"])) {
        ?>
		<table width="98%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="graph_image.php?graph_id=<?php 
        print $_GET["id"];
        ?>
&rra_id=1" alt="">
				</td>
				<?php 
        if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) {
            $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
            ?>
					<td>
						<span class="textInfo"><?php 
            echo _("RRDTool Says:");
            ?>
</span><br>
						<pre><?php 
            print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
					</td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<br>
		<?php 
    }
    if (empty($graph["graph_template_id"]) && (isset($_GET["id"]) && is_numeric($_GET["id"]) || isset($_GET["host_id"]) && isset($_GET["graph_template_id"]))) {
        /* ==================== Box: Graph ==================== */
        html_start_box("<strong>" . _("Graph") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
        field_row_header("General Options");
        _graph_field__title("g|title", false, empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__vertical_label("g|vertical_label", false, isset($graph["vertical_label"]) ? $graph["vertical_label"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__image_format("g|image_format", false, isset($graph["image_format"]) ? $graph["image_format"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__export("g|export", false, isset($graph["export"]) ? $graph["export"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__force_rules_legend("g|force_rules_legend", false, isset($graph["force_rules_legend"]) ? $graph["force_rules_legend"] : "");
        field_row_header("Image Size Options");
        _graph_field__height("g|height", false, isset($graph["height"]) ? $graph["height"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__width("g|width", false, isset($graph["width"]) ? $graph["width"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        field_row_header("Grid Options");
        _graph_field__x_grid("g|x_grid", false, isset($graph["x_grid"]) ? $graph["x_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__y_grid("g|y_grid", false, isset($graph["y_grid"]) ? $graph["y_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__y_grid_alt("g|y_grid_alt", false, isset($graph["y_grid_alt"]) ? $graph["y_grid_alt"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__no_minor("g|no_minor", false, isset($graph["no_minor"]) ? $graph["no_minor"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        field_row_header("Auto Scaling Options");
        _graph_field__auto_scale("g|auto_scale", false, isset($graph["auto_scale"]) ? $graph["auto_scale"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_opts("g|auto_scale_opts", false, isset($graph["auto_scale_opts"]) ? $graph["auto_scale_opts"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_log("g|auto_scale_log", false, isset($graph["auto_scale_log"]) ? $graph["auto_scale_log"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_rigid("g|auto_scale_rigid", false, isset($graph["auto_scale_rigid"]) ? $graph["auto_scale_rigid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_padding("g|auto_padding", false, isset($graph["auto_padding"]) ? $graph["auto_padding"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_padding");
        field_row_header("Fixed Scaling Options");
        _graph_field__upper_limit("g|upper_limit", false, isset($graph["upper_limit"]) ? $graph["upper_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_upper_limit");
        _graph_field__lower_limit("g|lower_limit", false, isset($graph["lower_limit"]) ? $graph["lower_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_lower_limit");
        _graph_field__base_value("g|base_value", false, isset($graph["base_value"]) ? $graph["base_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_base_value");
        field_row_header("Units Display Options");
        _graph_field__unit_value("g|unit_value", false, isset($graph["unit_value"]) ? $graph["unit_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_value");
        _graph_field__unit_length("g|unit_length", false, isset($graph["unit_length"]) ? $graph["unit_length"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_length");
        _graph_field__unit_exponent_value("g|unit_exponent_value", false, isset($graph["unit_exponent_value"]) ? $graph["unit_exponent_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        html_end_box();
    }
    form_hidden_box("action_post", "graph_edit");
    form_save_button("graphs.php");
}
コード例 #2
0
ファイル: graph_templates.php プロジェクト: songchin/Cacti
function template_edit()
{
    global $colors;
    if (!empty($_GET["id"])) {
        $graph_template = db_fetch_row("select * from graph_template where id=" . $_GET["id"]);
        $header_label = _("[edit: ") . $graph_template["template_name"] . "]";
    } else {
        $header_label = _("[new]");
    }
    form_start("graph_templates.php", "form_graph_template");
    /* ==================== Box: Graph Template ==================== */
    html_start_box("<strong>" . _("Graph Template") . "</strong> {$header_label}", "98%", $colors["header_background"], "3", "center", "");
    _graph_template_field__template_name("template_name", isset($graph_template) ? $graph_template["template_name"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    html_end_box();
    /* graph item list goes here */
    if (!empty($_GET["id"])) {
        /* ==================== Box: Graph Items ==================== */
        html_start_box("<strong>" . _("Graph Items") . "</strong>", "98%", $colors["header_background"], "3", "center", "graph_templates_items.php?action=edit&graph_template_id=" . $_GET["id"]);
        draw_graph_item_editor($_GET["id"], "graph_template", false);
        html_end_box();
        /* ==================== Box: Graph Item Inputs ==================== */
        html_start_box("<strong>" . _("Graph Item Inputs") . "</strong>", "98%", $colors["header_background"], "3", "center", "graph_templates_inputs.php?action=edit&graph_template_id=" . $_GET["id"]);
        $display_text = array("name" => array(_("Name"), "ASC"));
        html_header_sort($display_text, $sort_column, $sort_direction, 2);
        $template_item_list = db_fetch_assoc("select id,name from graph_template_item_input where graph_template_id=" . $_GET["id"] . " order by name");
        $i = 0;
        if (sizeof($template_item_list) > 0) {
            foreach ($template_item_list as $item) {
                form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i);
                $i++;
                ?>
					<td>
						<a class="linkEditMain" href="graph_templates_inputs.php?action=edit&id=<?php 
                print $item["id"];
                ?>
&graph_template_id=<?php 
                print $_GET["id"];
                ?>
"><?php 
                print $item["name"];
                ?>
</a>
					</td>
					<td align="right">
						<a href="graph_templates_inputs.php?action=remove&id=<?php 
                print $item["id"];
                ?>
&graph_template_id=<?php 
                print $_GET["id"];
                ?>
"><img src="<?php 
                print html_get_theme_images_path('delete_icon.gif');
                ?>
" width="10" height="10" border="0" alt="Delete"></a>
					</td>
				</tr>
				<?php 
            }
        } else {
            print "<tr bgcolor='#" . $colors["form_alternate2"] . "'><td colspan='2'><em>" . _("No Inputs") . "</em></td></tr>";
        }
        html_end_box();
    }
    /* ==================== Box: Graph ==================== */
    /* the user clicked the "add item" link. we need to make sure they get redirected back to
     * this page if an error occurs */
    if ($_GET["action"] == "sv_add") {
        form_hidden_box("redirect_sv_add", "x", "");
    }
    html_start_box("<strong>" . _("Graph") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
    field_row_header("General Options");
    _graph_field__title("title", true, empty($_GET["id"]) ? 0 : $_GET["id"], "t_title", isset($graph_template["t_title"]) ? $graph_template["t_title"] : "");
    _graph_field__vertical_label("vertical_label", true, isset($graph_template["vertical_label"]) ? $graph_template["vertical_label"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_vertical_label", isset($graph_template["t_vertical_label"]) ? $graph_template["t_vertical_label"] : "");
    _graph_field__image_format("image_format", isset($graph_template["image_format"]) ? $graph_template["image_format"] : "", true, empty($_GET["id"]) ? 0 : $_GET["id"], "t_image_format", isset($graph_template["t_image_format"]) ? $graph_template["t_image_format"] : "");
    _graph_field__export("export", true, isset($graph_template["export"]) ? $graph_template["export"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_export", isset($graph_template["t_export"]) ? $graph_template["t_export"] : "");
    _graph_field__force_rules_legend("force_rules_legend", true, isset($graph_template["force_rules_legend"]) ? $graph_template["force_rules_legend"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_force_rules_legend", isset($graph_template["t_force_rules_legend"]) ? $graph_template["t_force_rules_legend"] : "");
    field_row_header("Image Size Options");
    _graph_field__height("height", true, isset($graph_template["height"]) ? $graph_template["height"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_height", isset($graph_template["t_height"]) ? $graph_template["t_height"] : "");
    _graph_field__width("width", true, isset($graph_template["width"]) ? $graph_template["width"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_width", isset($graph_template["t_width"]) ? $graph_template["t_width"] : "");
    field_row_header("Grid Options");
    _graph_field__x_grid("x_grid", true, isset($graph_template["x_grid"]) ? $graph_template["x_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_x_grid", isset($graph_template["t_x_grid"]) ? $graph_template["t_x_grid"] : "");
    _graph_field__y_grid("y_grid", true, isset($graph_template["y_grid"]) ? $graph_template["y_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_y_grid", isset($graph_template["t_y_grid"]) ? $graph_template["t_y_grid"] : "");
    _graph_field__y_grid_alt("y_grid_alt", true, isset($graph_template["y_grid_alt"]) ? $graph_template["y_grid_alt"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_y_grid_alt", isset($graph_template["t_y_grid_alt"]) ? $graph_template["t_y_grid_alt"] : "");
    _graph_field__no_minor("no_minor", true, isset($graph_template["no_minor"]) ? $graph_template["no_minor"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_no_minor", isset($graph_template["t_no_minor"]) ? $graph_template["t_no_minor"] : "");
    field_row_header("Auto Scaling Options");
    _graph_field__auto_scale("auto_scale", true, isset($graph_template["auto_scale"]) ? $graph_template["auto_scale"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_scale", isset($graph_template["t_auto_scale"]) ? $graph_template["t_auto_scale"] : "");
    _graph_field__auto_scale_opts("auto_scale_opts", true, isset($graph_template["auto_scale_opts"]) ? $graph_template["auto_scale_opts"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_scale_opts", isset($graph_template["t_auto_scale_opts"]) ? $graph_template["t_auto_scale_opts"] : "");
    _graph_field__auto_scale_log("auto_scale_log", true, isset($graph_template["auto_scale_log"]) ? $graph_template["auto_scale_log"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_scale_log", isset($graph_template["t_auto_scale_log"]) ? $graph_template["t_auto_scale_log"] : "");
    _graph_field__auto_scale_rigid("auto_scale_rigid", true, isset($graph_template["auto_scale_rigid"]) ? $graph_template["auto_scale_rigid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_scale_rigid", isset($graph_template["t_auto_scale_rigid"]) ? $graph_template["t_auto_scale_rigid"] : "");
    _graph_field__auto_padding("auto_padding", true, isset($graph_template["auto_padding"]) ? $graph_template["auto_padding"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_padding", isset($graph_template["t_auto_padding"]) ? $graph_template["t_auto_padding"] : "");
    field_row_header("Fixed Scaling Options");
    _graph_field__upper_limit("upper_limit", true, isset($graph_template["upper_limit"]) ? $graph_template["upper_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_upper_limit", isset($graph_template["t_upper_limit"]) ? $graph_template["t_upper_limit"] : "");
    _graph_field__lower_limit("lower_limit", true, isset($graph_template["lower_limit"]) ? $graph_template["lower_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_lower_limit", isset($graph_template["t_lower_limit"]) ? $graph_template["t_lower_limit"] : "");
    _graph_field__base_value("base_value", true, isset($graph_template["base_value"]) ? $graph_template["base_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_base_value", isset($graph_template["t_base_value"]) ? $graph_template["t_base_value"] : "");
    field_row_header("Units Display Options");
    _graph_field__unit_value("unit_value", true, isset($graph_template["unit_value"]) ? $graph_template["unit_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_value", isset($graph_template["t_unit_value"]) ? $graph_template["t_unit_value"] : "");
    _graph_field__unit_length("unit_length", true, isset($graph_template["unit_length"]) ? $graph_template["unit_length"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_length", isset($graph_template["t_unit_length"]) ? $graph_template["t_unit_length"] : "");
    _graph_field__unit_exponent_value("unit_exponent_value", true, isset($graph_template["unit_exponent_value"]) ? $graph_template["unit_exponent_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_exponent_value", isset($graph_template["t_unit_exponent_value"]) ? $graph_template["t_unit_exponent_value"] : "");
    html_end_box();
    form_hidden_box("graph_template_id", empty($_GET["id"]) ? 0 : $_GET["id"], "");
    form_hidden_box("action_post", "graph_template_edit");
    form_save_button("graph_templates.php");
}