Example #1
0
function graph_edit() {
	global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("id"));
	/* ==================================================== */

	$use_graph_template = true;

	if (!empty($_GET["id"])) {
		$local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]);

		$graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]);
		$graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id");

		$host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]);
		$header_label = "[edit: " . get_graph_title($_GET["id"]) . "]";

		if ($graphs["graph_template_id"] == "0") {
			$use_graph_template = false;
		}
	}else{
		$header_label = "[new]";
		$use_graph_template = false;
	}

	/* 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="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php print get_graph_title($_GET["id"]);?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='graphs.php?action=graph_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><br>
					<?php
						if (!empty($graphs["graph_template_id"])) {
							?><span style="color: #c16921;">*<a href='graph_templates.php?action=template_edit&id=<?php print (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0");?>'>Edit Graph Template.</a><br><?php
						}
						if (!empty($_GET["host_id"]) || !empty($host_id)) {
							?><span style="color: #c16921;">*<a href='host.php?action=edit&id=<?php print (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id);?>'>Edit Host.</a><br><?php
						}
					?>
				</td>
			</tr>
		</table>
		<br>
		<?php
	}

	html_start_box("<strong>Graph Template Selection</strong> $header_label", "100%", $colors["header"], "3", "center", "");

	$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($graphs) ? $graphs["graph_template_id"] : "0"),
			"none_value" => "None",
			"sql" => "select graph_templates.id,graph_templates.name from graph_templates order by 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"] : $host_id),
			"none_value" => "None",
			"sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"
			),
		"graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["id"] : "0")
			),
		"local_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["local_graph_id"] : "0")
			),
		"local_graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0")
			),
		"_graph_template_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["graph_template_id"] : "0")
			),
		"_host_id" => array(
			"method" => "hidden",
			"value" => (isset($host_id) ? $host_id : "0")
			)
		);

	draw_edit_form(
		array(
			"config" => array(),
			"fields" => $form_array
			)
		);

	html_end_box();

	/* only display the "inputs" area if we are using a graph template for this graph */
	if (!empty($graphs["graph_template_id"])) {
		html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", "");

		print "<form method='post' action='graphs.php'>\n";

		draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0);
		draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true);

		html_end_box();
	}

	/* graph item list goes here */
	if ((!empty($_GET["id"])) && (empty($graphs["graph_template_id"]))) {
		item();
	}

	if (!empty($_GET["id"])) {
		?>
		<table width="100%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="graph_image.php?action=edit&local_graph_id=<?php print $_GET["id"];?>&rra_id=<?php print read_graph_config_option("default_rra_id");?>" alt="">
				</td>
				<?php
				if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) {
					$graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
					$graph_data_array["print_source"] = 1;
					?>
					<td>
						<span class="textInfo">RRDTool Command:</span><br>
						<pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre>
						<span class="textInfo">RRDTool Says:</span><br>
						<?php unset($graph_data_array["print_source"]);?>
						<pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre>
					</td>
					<?php
				}
				?>
			</tr>
		</table>
		<br>
		<?php
	}

	if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) {
		html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", "");

		$form_array = array();

		while (list($field_name, $field_array) = each($struct_graph)) {
			$form_array += array($field_name => $struct_graph[$field_name]);

			$form_array[$field_name]["value"] = (isset($graphs) ? $graphs[$field_name] : "");
			$form_array[$field_name]["form_id"] = (isset($graphs) ? $graphs["id"] : "0");

			if (!(($use_graph_template == false) || ($graphs_template{"t_" . $field_name} == "on"))) {
				$form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
				$form_array[$field_name]["description"] = "";
			}
		}

		draw_edit_form(
			array(
				"config" => array(
					"no_form_tag" => true
					),
				"fields" => $form_array
				)
			);

		html_end_box();
	}

	if ((isset($_GET["id"])) || (isset($_GET["new"]))) {
		form_hidden_box("save_component_graph","1","");
		form_hidden_box("save_component_input","1","");
	}else{
		form_hidden_box("save_component_graph_new","1","");
	}

	form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), "");
	form_save_button("graphs.php");

//Now we need some javascript to make it dynamic
?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}

function changeScaleLog() {
	//alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}
</script>
<?php

}
Example #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();
}
Example #3
0
function graph_edit()
{
    global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        // graph add
        if ($_GET["id"] == "") {
            if ($_GET["host_id"] != -1) {
                input_validate_input_number(get_request_var("host_id"));
                if (!check_host($_GET["host_id"])) {
                    access_denied();
                }
            }
            // graph edit
        } else {
            $permission = check_graph($_GET["id"]);
            if ($permission != GRAPH_PRIVATE && $permission != GRAPH_PRIVATE + GRAPH_PUBLIC) {
                access_denied();
            }
        }
    }
    /* modify for multi user end */
    $use_graph_template = true;
    if (!empty($_GET["id"])) {
        $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]);
        $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]);
        $graphs_template = db_fetch_row("select * from graph_templates_graph where id={$local_graph_template_graph_id}");
        $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]);
        $header_label = "[edit: " . htmlspecialchars(get_graph_title($_GET["id"])) . "]";
        if ($graphs["graph_template_id"] == "0") {
            $use_graph_template = false;
        }
    } else {
        $header_label = "[new]";
        $use_graph_template = false;
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($_GET["debug"]);
    }
    /* modify for multi user end */
    /* 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="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print htmlspecialchars(get_graph_title($_GET["id"]));
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
                    <?php 
        /* modify for multi user start */
        if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
					<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("graphs.php?action=graph_edit&id=" . (isset($_GET["id"]) ? $_GET["id"] : "0") . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1"));
            ?>
'>Turn <strong><?php 
            print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On";
            ?>
</strong> Graph Debug Mode.</a></span><br>
					<?php 
        }
        if (!empty($graphs["graph_template_id"]) && $_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("graph_templates.php?action=template_edit&id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"));
            ?>
'>Edit Graph Template.</a></span><br><?php 
        }
        /* modify for multi user end */
        if (!empty($_GET["host_id"]) || !empty($host_id)) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("host.php?action=edit&id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id));
            ?>
'>Edit Host.</a></span><br><?php 
        }
        ?>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    html_start_box("<strong>Graph Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    $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($graphs) ? $graphs["graph_template_id"] : "0", "none_value" => "None", "sql" => "select graph_templates.id,graph_templates.name from graph_templates order by 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"] : $host_id, "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["id"] : "0"), "local_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_id"] : "0"), "local_graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0"), "_graph_template_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0"), "_host_id" => array("method" => "hidden", "value" => isset($host_id) ? $host_id : "0"));
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($form_array["graph_template_id"]["none_value"]);
        $form_array["graph_template_id"]["sql"] = "SELECT graph_templates.id,graph_templates.name FROM graph_templates WHERE name NOT LIKE '%@system' ORDER BY name";
        unset($form_array["host_id"]["none_value"]);
        $form_array["host_id"]["sql"] = "\r\n            SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') AS name FROM host \r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n            ORDER BY host.description,host.hostname";
    }
    /* modify for multi user end */
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* only display the "inputs" area if we are using a graph template for this graph */
    if (!empty($graphs["graph_template_id"])) {
        html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", "");
        draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0);
        draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true);
        html_end_box();
    }
    /* graph item list goes here */
    if (!empty($_GET["id"]) && empty($graphs["graph_template_id"])) {
        item();
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="<?php 
        print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . $_GET["id"] . "&rra_id=" . read_graph_config_option("default_rra_id"));
        ?>
" alt="">
				</td>
				<?php 
        if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) {
            $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
            $graph_data_array["print_source"] = 1;
            ?>
					<td>
						<span class="textInfo">RRDTool Command:</span><br>
						<pre><?php 
            print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
						<span class="textInfo">RRDTool Says:</span><br>
						<?php 
            unset($graph_data_array["print_source"]);
            ?>
						<pre><?php 
            print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
					</td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<br>
		<?php 
    }
    if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($graphs["graph_template_id"])) {
        html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", "");
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_graph)) {
            $form_array += array($field_name => $struct_graph[$field_name]);
            $form_array[$field_name]["value"] = isset($graphs) ? $graphs[$field_name] : "";
            $form_array[$field_name]["form_id"] = isset($graphs) ? $graphs["id"] : "0";
            if (!($use_graph_template == false || $graphs_template["t_" . $field_name] == "on")) {
                $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
                $form_array[$field_name]["description"] = "";
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
        html_end_box();
    }
    if (isset($_GET["id"]) || isset($_GET["new"])) {
        form_hidden_box("save_component_graph", "1", "");
        form_hidden_box("save_component_input", "1", "");
    } else {
        form_hidden_box("save_component_graph_new", "1", "");
    }
    form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), "");
    form_save_button("graphs.php");
    //Now we need some javascript to make it dynamic
    ?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}

function changeScaleLog() {
	//alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}
</script>
<?php 
}
Example #4
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";
}
Example #5
0
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");
}
Example #6
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";
}
Example #7
0
function device_new_graphs($device_id, $device_template_id, $selected_graphs_array) {
	global $colors;

	if (substr_count($_SERVER["REQUEST_URI"], "/devices.php")) {
		$file = "devices.php?action=edit&tab=newgraphs&id=" . $_REQUEST["device_id"];
		$file2 = "devices.php";
	}else{
		$file = "graphs_new.php?device_id=". $_REQUEST["device_id"];
		$file2 = "graphs_new.php";
	}

	/* we use object buffering on this page to allow redirection to another page if no
	fields are actually drawn */
	ob_start();

	include_once(CACTI_BASE_PATH . "/include/top_header.php");

	print "<form action='" . $file2 . "' method='post'>\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 '%s'", db_fetch_cell("select name from graph_templates where id=$graph_template_id")), "100", $colors["header"], "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
						snmp_query.name,
						snmp_query.xml_path
						from snmp_query
						where 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", $colors["header"], "3", "center", "");
			}

			/* ================= input validation ================= */
			input_validate_input_number($graph_template_id);
			/* ==================================================== */

			$data_templates = db_fetch_assoc("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=" . $graph_template_id . "
				group by data_template.id
				order by data_template.name");

			$graph_template = db_fetch_row("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=" . $graph_template_id . "
				and 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
					data_template_rrd.*
					from data_template_rrd
					where data_template_rrd.data_template_id=" . $data_template["data_template_id"] . "
					and 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["device_template_id"] = $device_template_id;
		$_POST["device_id"] = $device_id;
		$_POST["save_component_new_graphs"] = "1";
		$_POST["selected_graphs_array"] = serialize($selected_graphs_array);

		device_new_graphs_save();

		header("Location: " . $file);
		exit;
	}

	/* flush the current output buffer to the browser */
	ob_end_flush();

	form_hidden_box("device_template_id", $device_template_id, "0");
	form_hidden_box("device_id", $device_id, "0");
	form_hidden_box("save_component_new_graphs", "1", "");
	print "<input type='hidden' name='selected_graphs_array' value='" . serialize($selected_graphs_array) . "'>\n";

	form_save_button_alt("device_id!$device_id");

	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}
Example #8
0
function graph_edit()
{
    global $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    $locked = 'false';
    $use_graph_template = true;
    if (!empty($_REQUEST['id'])) {
        $_SESSION['sess_graph_lock_id'] = $_REQUEST['id'];
        $local_graph_template_graph_id = db_fetch_cell_prepared('SELECT local_graph_template_graph_id FROM graph_templates_graph WHERE local_graph_id = ?', array($_REQUEST['id']));
        if ($_REQUEST['id'] != $_SESSION['sess_graph_lock_id'] && !empty($local_graph_template_graph_id)) {
            $locked = 'true';
            $_SESSION['sess_graph_locked'] = $locked;
        } elseif (empty($local_graph_template_graph_id)) {
            $locked = 'false';
            $_SESSION['sess_graph_locked'] = $locked;
        } elseif (isset($_SESSION['sess_graph_locked'])) {
            $locked = $_SESSION['sess_graph_locked'];
        } else {
            $locked = 'true';
            $_SESSION['sess_graph_locked'] = $locked;
        }
        $graphs = db_fetch_row_prepared('SELECT * FROM graph_templates_graph WHERE local_graph_id = ?', array($_REQUEST['id']));
        $graphs_template = db_fetch_row_prepared('SELECT * FROM graph_templates_graph WHERE id = ?', array($local_graph_template_graph_id));
        $host_id = db_fetch_cell_prepared('SELECT host_id FROM graph_local WHERE id = ?', array($_REQUEST['id']));
        $header_label = '[edit: ' . htmlspecialchars(get_graph_title($_REQUEST['id'])) . ']';
        if ($graphs['graph_template_id'] == '0') {
            $use_graph_template = 'false';
        }
    } else {
        $header_label = '[new]';
        $use_graph_template = false;
    }
    /* handle debug mode */
    if (isset($_REQUEST['debug'])) {
        if ($_REQUEST['debug'] == '0') {
            kill_session_var('graph_debug_mode');
        } elseif ($_REQUEST['debug'] == '1') {
            $_SESSION['graph_debug_mode'] = true;
        }
    }
    if (!empty($_REQUEST['id'])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print htmlspecialchars(get_graph_title($_REQUEST['id']));
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span class="linkMarker">*<a class='hyperLink' href='<?php 
        print htmlspecialchars('graphs.php?action=graph_edit&id=' . (isset($_REQUEST['id']) ? $_REQUEST['id'] : '0') . '&debug=' . (isset($_SESSION['graph_debug_mode']) ? '0' : '1'));
        ?>
'>Turn <strong><?php 
        print isset($_SESSION['graph_debug_mode']) ? 'Off' : 'On';
        ?>
</strong> Graph Debug Mode.</a></span><br>
					<?php 
        if (!empty($graphs['graph_template_id'])) {
            ?>
<span class="linkMarker">*<a class='hyperLink' href='<?php 
            print htmlspecialchars('graph_templates.php?action=template_edit&id=' . (isset($graphs['graph_template_id']) ? $graphs['graph_template_id'] : '0'));
            ?>
'>Edit Graph Template.</a></span><br><?php 
        }
        if (!empty($_REQUEST['host_id']) || !empty($host_id)) {
            ?>
<span class="linkMarker">*<a class='hyperLink' href='<?php 
            print htmlspecialchars('host.php?action=edit&id=' . (isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : $host_id));
            ?>
'>Edit Device.</a></span><br><?php 
        }
        if ($locked == 'true') {
            ?>
<span class="linkMarker">* <span class='hyperLink' id='unlockid'>Unlock Graph</span></span><?php 
        } else {
            ?>
<span class="linkMarker">* <span class='hyperLink' id='lockid'>Lock Graph</span></span><?php 
        }
        ?>
				</td>
			</tr>
		</table>
		<?php 
    }
    html_start_box("<strong>Graph Template Selection</strong> {$header_label}", '100%', '', '3', 'center', '');
    $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($graphs) ? $graphs['graph_template_id'] : '0', 'none_value' => 'None', 'sql' => 'SELECT graph_templates.id,graph_templates.name FROM graph_templates ORDER BY name'), 'host_id' => array('method' => 'drop_callback', 'friendly_name' => 'Device', 'description' => 'Choose the Device that this Graph belongs to.', 'sql' => "SELECT id,CONCAT_WS('',description,' (',hostname,')') as name FROM host ORDER BY description,hostname", 'action' => 'ajax_hosts_noany', 'id' => isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : $host_id, 'value' => db_fetch_cell_prepared('SELECT description AS name FROM host WHERE id = ?', isset($_REQUEST['host_id']) ? array($_REQUEST['host_id']) : array($host_id))), 'graph_template_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['id'] : '0'), 'local_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['local_graph_id'] : '0'), 'local_graph_template_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['local_graph_template_graph_id'] : '0'), '_graph_template_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['graph_template_id'] : '0'), '_host_id' => array('method' => 'hidden', 'value' => isset($host_id) ? $host_id : '0'));
    draw_edit_form(array('config' => array(), 'fields' => $form_array));
    html_end_box();
    /* only display the "inputs" area if we are using a graph template for this graph */
    if (!empty($graphs['graph_template_id'])) {
        html_start_box('<strong>Supplemental Graph Template Data</strong>', '100%', '', '3', 'center', '');
        draw_nontemplated_fields_graph($graphs['graph_template_id'], $graphs, '|field|', '<strong>Graph Fields</strong>', true, true, 0);
        draw_nontemplated_fields_graph_item($graphs['graph_template_id'], $_REQUEST['id'], '|field|_|id|', '<strong>Graph Item Fields</strong>', true, $locked);
        html_end_box();
    }
    /* graph item list goes here */
    if (!empty($_REQUEST['id']) && empty($graphs['graph_template_id'])) {
        item();
    }
    if (!empty($_REQUEST['id'])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="<?php 
        print htmlspecialchars('graph_image.php?action=edit&local_graph_id=' . $_REQUEST['id'] . '&rra_id=' . read_graph_config_option('default_rra_id'));
        ?>
" alt="">
				</td>
				<?php 
        if (isset($_SESSION['graph_debug_mode']) && isset($_REQUEST['id'])) {
            $graph_data_array['output_flag'] = RRDTOOL_OUTPUT_STDERR;
            $graph_data_array['print_source'] = 1;
            ?>
					<td>
						<span class="textInfo">RRDTool Command:</span><br>
						<pre><?php 
            print @rrdtool_function_graph($_REQUEST['id'], 1, $graph_data_array);
            ?>
</pre>
						<span class="textInfo">RRDTool Says:</span><br>
						<?php 
            unset($graph_data_array['print_source']);
            ?>
						<pre><?php 
            print @rrdtool_function_graph($_REQUEST['id'], 1, $graph_data_array);
            ?>
</pre>
					</td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<br>
		<?php 
    }
    if ((isset($_REQUEST['id']) || isset($_REQUEST['new'])) && empty($graphs['graph_template_id'])) {
        html_start_box('<strong>Graph Configuration</strong>', '100%', '', '3', 'center', '');
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_graph)) {
            $form_array += array($field_name => $struct_graph[$field_name]);
            $form_array[$field_name]['value'] = isset($graphs) ? $graphs[$field_name] : '';
            $form_array[$field_name]['form_id'] = isset($graphs) ? $graphs['id'] : '0';
            if (!($use_graph_template == false || $graphs_template['t_' . $field_name] == 'on')) {
                $form_array[$field_name]['method'] = 'template_' . $form_array[$field_name]['method'];
                $form_array[$field_name]['description'] = '';
            }
        }
        draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
        html_end_box();
    }
    if (isset($_REQUEST['id']) || isset($_REQUEST['new'])) {
        form_hidden_box('save_component_graph', '1', '');
        form_hidden_box('save_component_input', '1', '');
    } else {
        form_hidden_box('save_component_graph_new', '1', '');
    }
    form_hidden_box('rrdtool_version', read_config_option('rrdtool_version'), '');
    form_save_button('graphs.php');
    //Now we need some javascript to make it dynamic
    ?>
	<script type='text/javascript'>

	dynamic();

	function dynamic() {
		if ($('#scale_log_units').is(':checked')) {
			$('#scale_log_units').prop('disabled', true);
			if ($('#auto_scale_log').is(':checked')) {
				$('#scale_log_units').prop('disabled', false);
			}
		}
	}

	function changeScaleLog() {
		if ($('#scale_log_units').is(':checked')) {
			$('#scale_log_units').prop('disabled', true);
			if ($('#auto_scale_log').is(':checked')) {
				$('#scale_log_units').prop('disabled', false);
			}
		}
	}

	$(function() {
		$('#unlockid').click(function(event) {
			event.preventDefault;

			$('body').append("<div id='modal' class='ui-widget-overlay ui-front' style='z-index: 100;'><i style='position:absolute;top:50%;left:50%;' class='fa fa-spin fa-circle-o-notch'/></div>");

			$.get('graphs.php?action=unlock&header=false&id='+$('#local_graph_id').val(), function(data) {
				$('#modal').remove();
				$('#main').html(data);
				applySkin();
			});
		});

		$('#lockid').click(function(event) {
			event.preventDefault;

			$.get('graphs.php?action=lock&header=false&id='+$('#local_graph_id').val(), function(data) {
				$('#main').html(data);
				applySkin();
			});
		});
	});

	if (<?php 
    print $locked == '' ? 'true' : $locked;
    ?>
 == true) {
		$('input, select').not('input[value="Cancel"]').prop('disabled', true);
	}
	</script>
	<?php 
}
Example #9
0
function graph_edit() {
	global $colors;
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("id"));
	/* ==================================================== */

	$use_graph_template = true;

	if (!empty($_GET["id"])) {
		$local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . get_request_var("id"));

		$graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . get_request_var("id"));
		$graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id");

		$device_id = db_fetch_cell("select device_id from graph_local where id=" . get_request_var("id"));
		$header_label = __("[edit: ") . get_graph_title(get_request_var("id")) . "]";

		if ($graphs["graph_template_id"] == "0") {
			$use_graph_template = false;
		}
	}else{
		$graphs = array();
		$graphs_template = array();
		$header_label = __("[new]");
		$use_graph_template = false;
	}

	/* handle debug mode */
	if (isset($_GET["debug"])) {
		if (get_request_var("debug") == "0") {
			kill_session_var("graph_debug_mode");
		}elseif (get_request_var("debug") == "1") {
			$_SESSION["graph_debug_mode"] = true;
		}
	}

	$tip_text  = "<tr><td align=\\'right\\'><a class=\\'popup_item\\' id=\\'changeGraphState\\' onClick=\\'changeGraphState()\\' href=\\'#\\'>Unlock/Lock</a></td></tr>";
	$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graphs.php?action=graph_edit&id=' . (isset($_GET["id"]) ? get_request_var("id") : 0) . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["graph_debug_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("Debug Mode") . "</a></td></tr>";
	if (!empty($graphs["graph_template_id"])) {
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graph_templates.php?action=template_edit&id=' . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")) . "\\'>" . __("Edit Template") . "</a></td></tr>";
	}
	if (!empty($_GET["device_id"]) || !empty($device_id)) {
		$tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('devices.php?action=edit&id=' . (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id)) . "\\'>" . __("Edit Host") . "</a></td></tr>";
	}

	if (!empty($_GET["id"])) {
		?>
		<script type="text/javascript">
		<!--
		var disabled = true;

		$().ready(function() {
			$("input").attr("disabled","disabled");
			$("select").attr("disabled","disabled");
			$("#cancel").removeAttr("disabled");
		});

		function changeGraphState() {
			if (disabled) {
				$("input").removeAttr("disabled");
				$("select").removeAttr("disabled");
				disabled = false;
				rrdtool_graph_dependencies(); // even when unlocking, disable distinct rrdtool options
			}else{
				$("input").attr("disabled","disabled");
				$("select").attr("disabled","disabled");
				$("#cancel").removeAttr("disabled");
				disabled = true;
			}
		}
		//-->
		</script>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php print get_graph_title(get_request_var("id"));?>
				</td>
				<td style="white-space:nowrap;" align="right" width="1"><a id='tooltip' class='popup_anchor' href='#' onMouseOver="Tip('<?php print $tip_text;?>', BGCOLOR, '#EEEEEE', FIX, ['tooltip', -45, 0], STICKY, true, SHADOW, true, CLICKCLOSE, true, FADEOUT, 400, TEXTALIGN, 'right', BORDERCOLOR, '#F5F5F5')" onMouseOut="UnTip()">Graph Options</a></td>
			</tr>
		</table>
		<?php
	}

	print "<form method='post' action='" .  basename($_SERVER["PHP_SELF"]) . "' name='graph_edit'>\n";
	html_start_box("<strong>" . __("Graph Template Selection") . "</strong> $header_label", "100", $colors["header"], 0, "center", "");
	$header_items = array(__("Field"), __("Value"));
	print "<tr><td>";
	html_header($header_items, 1, true, 'template');

	$form_array = array(
		"graph_template_id" => array(
			"method" => "autocomplete",
			"callback_function" => "./lib/ajax/get_graph_templates.php",
			"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."),
			"id" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"),
			"name" => db_fetch_cell("SELECT name FROM graph_templates WHERE id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"))
			),
		"device_id" => array(
			"method" => "autocomplete",
			"callback_function" => "./lib/ajax/get_device_detailed.php",
			"friendly_name" => __("Host"),
			"description" => __("Choose the device that this graph belongs to."),
			"id" => (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id),
			"name" => db_fetch_cell("SELECT CONCAT_WS('',description,' (',hostname,')') FROM device WHERE id=" . (isset($_GET['device_id']) ? $_GET['device_id'] : $device_id))
			),
		"graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs["id"]) ? $graphs["id"] : "0")
			),
		"local_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs["local_graph_id"]) ? $graphs["local_graph_id"] : "0")
			),
		"local_graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs["local_graph_template_graph_id"]) ? $graphs["local_graph_template_graph_id"] : "0")
			),
		"_graph_template_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")
			),
		"_device_id" => array(
			"method" => "hidden",
			"value" => (isset($device_id) ? $device_id : "0")
			)
		);

	draw_edit_form(
		array(
			"config" => array(),
			"fields" => $form_array
			)
		);

	print "</table></td></tr>";		/* end of html_header */
	html_end_box();


#	print "<form method='post' action='graphs.php'>\n";
	/* only display the "inputs" area if we are using a graph template for this graph */
	if (!empty($graphs["graph_template_id"])) {
		html_start_box("<strong>" . __("Supplemental Graph Template Data") . "</strong>", "100", $colors["header"], "0", "center", "");

		draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>" . __("Graph Fields") . "</strong>", true, true, 0);
		draw_nontemplated_fields_graph_item($graphs["graph_template_id"], get_request_var("id"), "|field|_|id|", "<strong>" . __("Graph Item Fields") ."</strong>", true);

		html_end_box();
	}

	/* graph item list goes here */
	if ((!empty($_GET["id"])) && (!array_key_exists("graph_template_id", $graphs))) {
		graph_template_item();
	}

	if (!empty($_GET["id"])) {
		?>
		<table width="100%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="<?php print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . get_request_var("id") . "&rra_id=" . read_graph_config_option("default_rra_id"));?>" alt="">
				</td>
				<?php
				if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) {
					$graph_data_array = array();
					$graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
					/* make rrdtool_function_graph to only print the command without executing it */
					$graph_data_array["print_source"] = 1;
					?>
					<td>
						<span class="textInfo"><?php print __("RRDTool Command:");?></span><br>
						<pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre>
						<span class="textInfo"><?php print __("RRDTool Says:");?></span><br>
						<?php /* make rrdtool_function_graph to generate AND execute the rrd command, but only for fetching the "return code" */
						unset($graph_data_array["print_source"]);?>
						<pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre>
					</td>
					<?php
				}
				?>
			</tr>
		</table>
		<?php
	}

	if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) {
		html_start_box("<strong>" . __("Graph Configuration") . "</strong>", "100", $colors["header"], "0", "center", "");

		############
		html_start_box("<strong>" . __("Labels") . "</strong>", "100", $colors["header"], "0", "center", "", true);
		draw_template_edit_form('header_graph_labels', graph_labels_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		/* TODO: we should not use rrd version in the code, when going data-driven */
		if ( read_config_option("rrdtool_version") != RRD_VERSION_1_0 && read_config_option("rrdtool_version") != RRD_VERSION_1_2) {
			html_start_box("<strong>" . __("Right Axis Settings") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_right_axis");
			draw_template_edit_form('header_graph_right_axis', graph_right_axis_form_list(), $graphs, $use_graph_template);
		}
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Size") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_size");
		draw_template_edit_form('header_graph_size', graph_size_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Limits") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_limits");
		draw_template_edit_form('header_graph_limits', graph_limits_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Grid") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_grid");
		draw_template_edit_form('header_graph_grid', graph_grid_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Color") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_color");
		draw_template_edit_form('header_graph_color', graph_color_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Legend") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc");
		draw_template_edit_form('header_graph_legend', graph_legend_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Misc") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc");
		draw_template_edit_form('header_graph_misc', graph_misc_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
		html_start_box("<strong>" . __("Graph Template Cacti Specifics") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_cacti");
		draw_template_edit_form('header_graph_cacti', graph_cacti_form_list(), $graphs, $use_graph_template);
		html_end_box(false);
	}

	if ((isset($_GET["id"])) || (isset($_GET["new"]))) {
		form_hidden_box("save_component_graph","1","");
		form_hidden_box("save_component_input","1","");
	}else{
		form_hidden_box("save_component_graph_new","1","");
	}

	form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), "");
	form_save_button_alt();

	include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js");
	include_once(CACTI_BASE_PATH . "/access/js/graph_template_options.js");

?>
<script type="text/javascript">
	$('#graph_item').tableDnD({
		onDrop: function(table, row) {
			$('#AjaxResult').load("lib/ajax/jquery.tablednd/graphs_item.ajax.php?id=<?php isset($_GET["id"]) ? print get_request_var("id") : print "";?>&"+$.tableDnD.serialize());
//			location.reload();
		}
	});
</script>
<?php
}