Exemplo n.º 1
0
function grow_dropdown_tree($tree_id, $parent = 0, $form_name = '', $selected_tree_item_id = '')
{
    global $config;
    static $tier = 1;
    $branches = db_fetch_assoc("SELECT gti.id, gti.title\n\t\tFROM graph_tree_items AS gti\n\t\tWHERE gti.graph_tree_id={$tree_id}\n\t\tAND gti.host_id = 0\n\t\tAND gti.local_graph_id = 0\n\t\tAND parent={$parent}\n\t\tORDER BY position");
    if ($parent == 0) {
        print "<select name='{$form_name}'>\n";
        print "<option value='0'>[root]</option>\n";
    }
    if (sizeof($branches)) {
        foreach ($branches as $leaf) {
            $indent = str_repeat('---', $tier);
            if ($selected_tree_item_id == $leaf['id']) {
                $html_selected = ' selected';
            } else {
                $html_selected = '';
            }
            print "<option value='" . $leaf['id'] . "'{$html_selected}>{$indent} " . $leaf['title'] . "</option>\n";
            grow_dropdown_tree($tree_id, $leaf['id'], $form_name, $selected_tree_item_id);
        }
    }
    $tier++;
    if ($parent == 0) {
        print "</select>\n";
    }
}
Exemplo n.º 2
0
function form_actions() {
	global $colors, $graph_actions;
	/* if we are to save this form, instead of display it */
	if (isset($_POST["selected_items"])) {
		$selected_items = unserialize(stripslashes($_POST["selected_items"]));

		if ($_POST["drp_action"] == "1") { /* delete */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; }

				switch ($_POST["delete_type"]) {
					case '2': /* delete all data sources referenced by this graph */
						$data_sources = db_fetch_assoc("SELECT " .
								"data_template_data.local_data_id " .
							"FROM " .
								"(data_template_rrd, " .
								"data_template_data, " .
								"graph_templates_item) " .
							"WHERE " .
								"graph_templates_item.task_item_id=data_template_rrd.id " .
								"AND data_template_rrd.local_data_id=data_template_data.local_data_id " .
								"AND graph_templates_item.local_graph_id=" . $selected_items[$i] . " " .
								"AND data_template_data.local_data_id > 0");

						if (sizeof($data_sources) > 0) {
							foreach ($data_sources as $data_source) {
								api_data_source_remove($data_source["local_data_id"]);
							}
						}

						break;
				}

				api_graph_remove($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "2") { /* change graph template */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				input_validate_input_number(get_request_var_post("graph_template_id"));
				/* ==================================================== */

				change_graph_template($selected_items[$i], $_POST["graph_template_id"], true);
			}
		}elseif ($_POST["drp_action"] == "3") { /* duplicate */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				duplicate_graph($selected_items[$i], 0, $_POST["title_format"]);
			}
		}elseif ($_POST["drp_action"] == "4") { /* graph -> graph template */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				graph_to_graph_template($selected_items[$i], $_POST["title_format"]);
			}
		}elseif (ereg("^tr_([0-9]+)$", $_POST["drp_action"], $matches)) { /* place on tree */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				input_validate_input_number(get_request_var_post("tree_id"));
				input_validate_input_number(get_request_var_post("tree_item_id"));
				/* ==================================================== */

				api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
			}
		}elseif ($_POST["drp_action"] == "5") { /* change host */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				input_validate_input_number(get_request_var_post("host_id"));
				/* ==================================================== */

				db_execute("update graph_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]);
				update_graph_title_cache($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "6") { /* reapply suggested naming */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				api_reapply_suggested_graph_title($selected_items[$i]);
				update_graph_title_cache($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "7") { /* resize graphs */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				api_resize_graphs($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
			}
		}

		header("Location: graphs.php");
		exit;
	}

	/* setup some variables */
	$graph_list = ""; $i = 0;

	/* loop through each of the graphs selected on the previous page and get more info about them */
	while (list($var,$val) = each($_POST)) {
		if (ereg("^chk_([0-9]+)$", $var, $matches)) {
			/* ================= input validation ================= */
			input_validate_input_number($matches[1]);
			/* ==================================================== */

			$graph_list .= "<li>" . get_graph_title($matches[1]) . "<br>";
			$graph_array[$i] = $matches[1];
		}

		$i++;
	}

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

	/* add a list of tree names to the actions dropdown */
	add_tree_names_to_actions_array();

	html_start_box("<strong>" . $graph_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", "");

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

	if ($_POST["drp_action"] == "1") { /* delete */
		$graphs = array();

		/* find out which (if any) data sources are being used by this graph, so we can tell the user */
		if (isset($graph_array)) {
			$data_sources = db_fetch_assoc("select
				data_template_data.local_data_id,
				data_template_data.name_cache
				from (data_template_rrd,data_template_data,graph_templates_item)
				where graph_templates_item.task_item_id=data_template_rrd.id
				and data_template_rrd.local_data_id=data_template_data.local_data_id
				and " . array_to_sql_or($graph_array, "graph_templates_item.local_graph_id") . "
				and data_template_data.local_data_id > 0
				group by data_template_data.local_data_id
				order by data_template_data.name_cache");
		}

		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Are you sure you want to delete the following graphs?</p>
					<p>$graph_list</p>
					";
					if (sizeof($data_sources) > 0) {
						print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>The following data sources are in use by these graphs:</p>\n";

						foreach ($data_sources as $data_source) {
							print "<strong>" . $data_source["name_cache"] . "</strong><br>\n";
						}

						print "<br>";
						form_radio_button("delete_type", "1", "1", "Leave the data sources untouched.", "1"); print "<br>";
						form_radio_button("delete_type", "1", "2", "Delete all <strong>data sources</strong> referenced by these graphs.", "1"); print "<br>";
						print "</td></tr>";
					}
				print "
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "2") { /* change graph template */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Choose a graph template and click save to change the graph template for
					the following graphs. Be aware that all warnings will be suppressed during the
					conversion, so graph data loss is possible.</p>
					<p>$graph_list</p>
					<p><strong>New Graph Template:</strong><br>"; form_dropdown("graph_template_id",db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates order by name"),"name","id","","","0"); print "</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "3") { /* duplicate */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be duplicated. You can
					optionally change the title format for the new graphs.</p>
					<p>$graph_list</p>
					<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<graph_title> (1)", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "4") { /* graph -> graph template */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be converted into graph templates.
					You can optionally change the title format for the new graph templates.</p>
					<p>$graph_list</p>
					<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<graph_title> Template", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}elseif (ereg("^tr_([0-9]+)$", $_POST["drp_action"], $matches)) { /* place on tree */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be placed under the branch selected
					below.</p>
					<p>$graph_list</p>
					<p><strong>Destination Branch:</strong><br>"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "</p>
				</td>
			</tr>\n
			<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n
			";
	}elseif ($_POST["drp_action"] == "5") { /* change host */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Choose a new host for these graphs:</p>
					<p>$graph_list</p>
					<p><strong>New Host:</strong><br>"; form_dropdown("host_id",db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"),"name","id","","","0"); print "</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "6") { /* reapply suggested naming to host */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will have thier suggested naming convensions
					recalculated and applies to the graphs.</p>
					<p>$graph_list</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "7") { /* reapply suggested naming to host */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be resized per your specifications.</p>
					<p>$graph_list</p>
					<p><strong>Graph Height:</strong><br>"; form_text_box("graph_height", "", "", "255", "30", "text"); print "</p>
					<p><strong>Graph Width:</strong><br>"; form_text_box("graph_width", "", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}

	if (!isset($graph_array)) {
		print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
		$save_html = "";
	}else{
		$save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>";
	}

	print "	<tr>
			<td align='right' bgcolor='#eaeaea'>
				<input type='hidden' name='action' value='actions'>
				<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>
				<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>
				<a href='graphs.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a>
				$save_html
			</td>
		</tr>
		";

	html_end_box();

	include_once("./include/bottom_footer.php");
}
Exemplo n.º 3
0
Arquivo: host.php Projeto: MrWnn/cacti
function form_actions()
{
    global $device_actions, $fields_host_edit;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '2') {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled = '' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                $data_sources = db_fetch_assoc_prepared('SELECT id FROM data_local WHERE host_id = ?', array($selected_items[$i]));
                $poller_items = $local_data_ids = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source['id'];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source['id']));
                    }
                }
                if (sizeof($local_data_ids)) {
                    poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
                }
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled='on' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                db_execute_prepared('DELETE FROM poller_item WHERE host_id = ?', array($selected_items[$i]));
                db_execute_prepared('DELETE FROM poller_reindex WHERE host_id = ?', array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET min_time = '9.99999', max_time = '0', cur_time = '0', avg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = ?", array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc('SELECT
					data_local.id AS local_data_id
					FROM data_local
					WHERE ' . array_to_sql_or($selected_items, 'data_local.host_id'));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source['local_data_id'];
                    }
                }
                if ($_POST['delete_type'] == 2) {
                    $graphs = db_fetch_assoc('SELECT
						graph_local.id AS local_graph_id
						FROM graph_local
						WHERE ' . array_to_sql_or($selected_items, 'graph_local.host_id'));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph['local_graph_id'];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST['delete_type']) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    api_plugin_hook_function('data_source_remove', $data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    api_plugin_hook_function('graphs_remove', $graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
            api_plugin_hook_function('device_remove', $devices_to_act_on);
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('tree_id'));
                input_validate_input_number(get_request_var_post('tree_item_id'));
                /* ==================================================== */
                api_tree_item_save(0, $_POST['tree_id'], TREE_ITEM_TYPE_HOST, $_POST['tree_item_id'], '', 0, read_graph_config_option('default_rra_id'), $selected_items[$i], 1, 1, false);
            }
        } else {
            api_plugin_hook_function('device_action_execute', $_POST['drp_action']);
        }
        /* update snmpcache */
        snmpagent_device_action_bottom(array($_POST['drp_action'], $selected_items));
        api_plugin_hook_function('device_action_bottom', array($_POST['drp_action'], $selected_items));
        header('Location: host.php');
        exit;
    }
    /* setup some variables */
    $host_list = '';
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $host_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($matches[1]))) . '<br>';
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box('<strong>' . $device_actions[get_request_var_post('drp_action')] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='host.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_POST['drp_action'] == '2') {
            /* Enable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Device(s)'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Device(s)'>";
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/^snmp_/', $field_name) || $field_name == 'max_oids') {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) SNMP Options'>";
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/(availability_method|ping_method|ping_port)/', $field_name)) {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) Availability Options'>";
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Clear Statistics on Device(s)'>";
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>';
            form_radio_button('delete_type', '2', '1', 'Leave all Graph(s) and Data Source(s) untouched.  Data Source(s) will be disabled however.', '1');
            print '<br>';
            form_radio_button('delete_type', '2', '2', 'Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.', '1');
            print '<br>';
            print "</td></tr>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\n\t\t\t\t\t\tbelow.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
						<p><strong>Destination Branch:</strong><br>';
            grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['host_list'] = $host_list;
            $save['host_array'] = isset($host_array) ? $host_array : array();
            api_plugin_hook_function('device_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
Exemplo n.º 4
0
function draw_edit_control($field_name, &$field_array)
{
    switch ($field_array["method"]) {
        case 'textbox':
            form_text_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "text", isset($field_array["form_id"]) ? $field_array["form_id"] : "");
            break;
        case 'filepath':
            form_filepath_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "text", isset($field_array["form_id"]) ? $field_array["form_id"] : "");
            break;
        case 'dirpath':
            form_dirpath_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "text", isset($field_array["form_id"]) ? $field_array["form_id"] : "");
            break;
        case 'textbox_password':
            form_text_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "password");
            print "<br>";
            form_text_box($field_name . "_confirm", $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "password");
            break;
        case 'textarea':
            form_text_area($field_name, $field_array["value"], $field_array["textarea_rows"], $field_array["textarea_cols"], isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_array':
            form_dropdown($field_name, $field_array["array"], "", "", $field_array["value"], isset($field_array["none_value"]) ? $field_array["none_value"] : "", isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_sql':
            form_dropdown($field_name, db_fetch_assoc($field_array["sql"]), "name", "id", $field_array["value"], isset($field_array["none_value"]) ? $field_array["none_value"] : "", isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_multi':
            form_multi_dropdown($field_name, $field_array["array"], db_fetch_assoc($field_array["sql"]), "id", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_multi_rra':
            form_multi_dropdown($field_name, array_rekey(db_fetch_assoc("select id,name from rra order by timespan"), "id", "name"), empty($field_array["form_id"]) ? db_fetch_assoc($field_array["sql_all"]) : db_fetch_assoc($field_array["sql"]), "id", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'drop_tree':
            grow_dropdown_tree($field_array["tree_id"], $field_name, $field_array["value"]);
            break;
        case 'drop_color':
            form_color_dropdown($field_name, $field_array["value"], "None", isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'checkbox':
            form_checkbox($field_name, $field_array["value"], $field_array["friendly_name"], isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["form_id"]) ? $field_array["form_id"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
            break;
        case 'checkbox_group':
            while (list($check_name, $check_array) = each($field_array["items"])) {
                form_checkbox($check_name, $check_array["value"], $check_array["friendly_name"], isset($check_array["default"]) ? $check_array["default"] : "", isset($check_array["form_id"]) ? $check_array["form_id"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($check_array["on_change"]) ? $check_array["on_change"] : (isset($field_array["on_change"]) ? $field_array["on_change"] : ""));
                print "<br>";
            }
            break;
        case 'radio':
            while (list($radio_index, $radio_array) = each($field_array["items"])) {
                form_radio_button($field_name, $field_array["value"], $radio_array["radio_value"], $radio_array["radio_caption"], isset($field_array["default"]) ? $field_array["default"] : "", isset($field_array["class"]) ? $field_array["class"] : "", isset($field_array["on_change"]) ? $field_array["on_change"] : "");
                print "<br>";
            }
            break;
        case 'custom':
            print $field_array["value"];
            break;
        case 'template_checkbox':
            print "<em>" . html_boolean_friendly($field_array["value"]) . "</em>";
            form_hidden_box($field_name, $field_array["value"], "");
            break;
        case 'template_drop_array':
            print "<em>" . $field_array["array"][$field_array["value"]] . "</em>";
            form_hidden_box($field_name, $field_array["value"], "");
            break;
        case 'template_drop_multi_rra':
            $items = db_fetch_assoc($field_array["sql_print"]);
            if (sizeof($items) > 0) {
                foreach ($items as $item) {
                    print htmlspecialchars($item["name"], ENT_QUOTES) . "<br>";
                }
            }
            break;
        case 'font':
            form_font_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "", $field_array["max_length"], isset($field_array["size"]) ? $field_array["size"] : "40", "text", isset($field_array["form_id"]) ? $field_array["form_id"] : "");
            break;
        case 'file':
            form_file($field_name, isset($field_array["size"]) ? $field_array["size"] : "40");
            break;
        default:
            print "<em>" . htmlspecialchars($field_array["value"], ENT_QUOTES) . "</em>";
            form_hidden_box($field_name, $field_array["value"], "");
            break;
    }
}
Exemplo n.º 5
0
function item_edit() {
	global $colors, $tree_sort_types;

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

	$tree_item_types = array(
		TREE_ITEM_TYPE_HEADER => "Header",
		TREE_ITEM_TYPE_GRAPH => "Graph",
		TREE_ITEM_TYPE_HOST => "Host"
		);

	$host_group_types = array(
		HOST_GROUPING_GRAPH_TEMPLATE => "Graph Template",
		HOST_GROUPING_DATA_QUERY_INDEX => "Data Query Index"
		);

	if (!empty($_GET["id"])) {
		$tree_item = db_fetch_row("select * from graph_tree_items where id=" . $_GET["id"]);

		if ($tree_item["local_graph_id"] > 0) { $db_type = TREE_ITEM_TYPE_GRAPH; }
		if ($tree_item["title"] != "") { $db_type = TREE_ITEM_TYPE_HEADER; }
		if ($tree_item["host_id"] > 0) { $db_type = TREE_ITEM_TYPE_HOST; }
	}

	if (isset($_GET["type_select"])) {
		$current_type = $_GET["type_select"];
	}elseif (isset($db_type)) {
		$current_type = $db_type;
	}else{
		$current_type = TREE_ITEM_TYPE_HEADER;
	}

	$tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . $_GET["tree_id"] . "'");

	html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", "");

	print "<form method='post' action='tree.php' name='form_tree'>\n";

	form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?>
		<td width="50%">
			<font class="textEditTitle">Parent Item</font><br>
			Choose the parent for this header/graph.
		</td>
		<td>
			<?php grow_dropdown_tree($_GET["tree_id"], "parent_item_id", (isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"])));?>
		</td>
	</tr>
	<?php form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?>
		<td width="50%">
			<font class="textEditTitle">Tree Item Type</font><br>
			Choose what type of tree item this is.
		</td>
		<td>
			<select name="type_select" onChange="window.location=document.form_tree.type_select.options[document.form_tree.type_select.selectedIndex].value">
				<?php
				while (list($var, $val) = each($tree_item_types)) {
					print "<option value='tree.php?action=item_edit" . (isset($_GET["id"]) ? "&id=" . $_GET["id"] : "") . (isset($_GET["parent_id"]) ? "&parent_id=" . $_GET["parent_id"] : "") . "&tree_id=" . $_GET["tree_id"] . "&type_select=$var'"; if ($var == $current_type) { print " selected"; } print ">$val</option>\n";
				}
				?>
			</select>
		</td>
	</tr>
	<tr bgcolor='#<?php print $colors["header_panel"];?>'>
		<td colspan="2" class='textSubHeaderDark'>Tree Item Value</td>
	</tr>
	<?php
	switch ($current_type) {
	case TREE_ITEM_TYPE_HEADER:
		$i = 0;

		/* it's nice to default to the parent sorting style for new items */
		if (empty($_GET["id"])) {
			$default_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=" . $_GET["parent_id"]);
		}else{
			$default_sorting_type = TREE_ORDERING_NONE;
		}

		form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; ?>
			<td width="50%">
				<font class="textEditTitle">Title</font><br>
				If this item is a header, enter a title here.
			</td>
			<td>
				<?php form_text_box("title", (isset($tree_item["title"]) ? $tree_item["title"] : ""), "", "255", 30, "text", (isset($_GET["id"]) ? $_GET["id"] : "0"));?>
			</td>
		</tr>
		<?php
		/* don't allow the user to change the tree item ordering if a tree order has been specified */
		if ($tree_sort_type == TREE_ORDERING_NONE) {
			form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; ?>
				<td width="50%">
					<font class="textEditTitle">Sorting Type</font><br>
					Choose how children of this branch will be sorted.
				</td>
				<td>
					<?php form_dropdown("sort_children_type", $tree_sort_types, "", "", (isset($tree_item["sort_children_type"]) ? $tree_item["sort_children_type"] : $default_sorting_type), "", "");?>
				</td>
			</tr>
			<?php
		}

		if ((!empty($_GET["id"])) && ($tree_sort_type == TREE_ORDERING_NONE)) {
			form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; ?>
				<td width="50%">
					<font class="textEditTitle">Propagate Changes</font><br>
					Propagate all options on this form (except for 'Title') to all child 'Header' items.
				</td>
				<td>
					<?php form_checkbox("propagate_changes", "", "Propagate Changes", "", "", "", 0);?>
				</td>
			</tr>
			<?php
		}
		break;
	case TREE_ITEM_TYPE_GRAPH:
		form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?>
			<td width="50%">
				<font class="textEditTitle">Graph</font><br>
				Choose a graph from this list to add it to the tree.
			</td>
			<td>
				<?php form_dropdown("local_graph_id", db_fetch_assoc("select graph_templates_graph.local_graph_id as id,graph_templates_graph.title_cache as name from (graph_templates_graph CROSS JOIN graph_local) where graph_local.id=graph_templates_graph.local_graph_id and local_graph_id != 0 order by title_cache"), "name", "id", (isset($tree_item["local_graph_id"]) ? $tree_item["local_graph_id"] : ""), "", "");?>
			</td>
		</tr>
		<?php form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?>
			<td width="50%">
				<font class="textEditTitle">Round Robin Archive</font><br>
				Choose a round robin archive to control how this graph is displayed.
			</td>
			<td>
				<?php form_dropdown("rra_id", db_fetch_assoc("select id,name from rra order by timespan"), "name", "id", (isset($tree_item["rra_id"]) ? $tree_item["rra_id"] : ""), "", "");?>
			</td>
		</tr>
		<?php
		break;
	case TREE_ITEM_TYPE_HOST:
		form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?>
			<td width="50%">
				<font class="textEditTitle">Host</font><br>
				Choose a host here to add it to the tree.
			</td>
			<td>
				<?php form_dropdown("host_id", db_fetch_assoc("select id,".sql_function_concat("description","' ('","hostname","')'")." as name from host order by description,hostname"), "name", "id", (isset($tree_item["host_id"]) ? $tree_item["host_id"] : ""), "", "");?>
			</td>
		</tr>
		<?php form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?>
			<td width="50%">
				<font class="textEditTitle">Graph Grouping Style</font><br>
				Choose how graphs are grouped when drawn for this particular host on the tree.
			</td>
			<td>
				<?php form_dropdown("host_grouping_type", $host_group_types, "", "", (isset($tree_item["host_grouping_type"]) ? $tree_item["host_grouping_type"] : "1"), "", "");?>
			</td>
		</tr>
		<?php
		break;
	}
	?>
	</tr>
	<?php

	form_hidden_box("id", (isset($_GET["id"]) ? $_GET["id"] : "0"), "");
	form_hidden_box("graph_tree_id", $_GET["tree_id"], "");
	form_hidden_box("type", $current_type, "");
	form_hidden_box("save_component_tree_item", "1", "");

	html_end_box();

	form_save_button("tree.php?action=edit&id=" . $_GET["tree_id"]);
}
Exemplo n.º 6
0
function form_actions()
{
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        update_poller_cache($data_source["id"], false);
                    }
                }
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc("select\n\t\t\t\t\tdata_local.id as local_data_id\n\t\t\t\t\tfrom data_local\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id"));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source["local_data_id"];
                    }
                }
                if ($_POST["delete_type"] == 2) {
                    $graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_local.id as local_graph_id\n\t\t\t\t\t\tfrom graph_local\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id"));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph["local_graph_id"];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST["delete_type"]) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
        } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post("tree_id"));
                input_validate_input_number(get_request_var_post("tree_item_id"));
                /* ==================================================== */
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_HOST, $_POST["tree_item_id"], "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false);
            }
        }
        header("Location: host.php");
        exit;
    }
    /* setup some variables */
    $host_list = "";
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (ereg("^chk_([0-9]+)\$", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>";
            $host_array[$i] = $matches[1];
        }
        $i++;
    }
    include_once "./include/top_header.php";
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box("<strong>" . $device_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='host.php' method='post'>\n";
    if ($_POST["drp_action"] == "2") {
        /* Enable Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To enable the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "3") {
        /* Disable Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To disable the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "4") {
        /* change snmp options */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click \"yes\".</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("^snmp_", $field_name) || $field_name == "max_oids") {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "6") {
        /* change availability options */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click \"yes\".</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("(availability_method|ping_method|ping_port)", $field_name)) {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "5") {
        /* Clear Statisitics for Selected Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To clear the counters for the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "1") {
        /* delete */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Are you sure you want to delete the following devices?</p>\n\t\t\t\t\t<p>{$host_list}</p>";
        form_radio_button("delete_type", "2", "1", "Leave all graphs and data sources untouched.  Data sources will be disabled however.", "1");
        print "<br>";
        form_radio_button("delete_type", "2", "2", "Delete all associated <strong>graphs</strong> and <strong>data sources</strong>.", "1");
        print "<br>";
        print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) {
        /* place on tree */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click save, the following hosts will be placed under the branch selected\n\t\t\t\t\tbelow.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
        grow_dropdown_tree($matches[1], "tree_item_id", "0");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t";
    }
    if (!isset($host_array)) {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='host.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Exemplo n.º 7
0
function form_actions()
{
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $rows = db_fetch_assoc("\r\n            SELECT graph_local.id FROM graph_local \r\n                INNER JOIN host ON graph_local.host_id = host.id\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'");
        foreach ($rows as $row) {
            $graphs[] = $row["id"];
        }
    }
    /* modify for multi user end */
    global $colors, $graph_actions;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        /* modify for multi user start */
        if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
            for ($i = 0; $i < count($selected_items); $i++) {
                if (!in_array($selected_items[$i], $graphs)) {
                    access_denied();
                }
            }
        }
        /* modify for multi user end */
        if ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 1;
            }
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
            }
            switch ($_POST["delete_type"]) {
                case '2':
                    /* delete all data sources referenced by this graph */
                    $data_sources = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id\r\n\t\t\t\t\t\tFROM (data_template_rrd, data_template_data, graph_templates_item)\r\n\t\t\t\t\t\tWHERE graph_templates_item.task_item_id=data_template_rrd.id\r\n\t\t\t\t\t\tAND data_template_rrd.local_data_id=data_template_data.local_data_id\r\n\t\t\t\t\t\tAND " . array_to_sql_or($selected_items, "graph_templates_item.local_graph_id") . "\r\n\t\t\t\t\t\tAND data_template_data.local_data_id > 0"), "local_data_id", "local_data_id");
                    if (sizeof($data_sources)) {
                        api_data_source_remove_multi($data_sources);
                        api_plugin_hook_function('data_source_remove', $data_sources);
                    }
                    break;
            }
            api_graph_remove_multi($selected_items);
            api_plugin_hook_function('graphs_remove', $selected_items);
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            input_validate_input_number(get_request_var_post("graph_template_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                change_graph_template($selected_items[$i], $_POST["graph_template_id"], true);
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_graph($selected_items[$i], 0, $_POST["title_format"]);
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* graph -> graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                graph_to_graph_template($selected_items[$i], $_POST["title_format"]);
            }
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            input_validate_input_number(get_request_var_post("tree_id"));
            input_validate_input_number(get_request_var_post("tree_item_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* change host */
            input_validate_input_number(get_request_var_post("host_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update graph_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]);
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* reapply suggested naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_reapply_suggested_graph_title($selected_items[$i]);
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "7") {
            /* resize graphs */
            input_validate_input_number(get_request_var_post("graph_width"));
            input_validate_input_number(get_request_var_post("graph_height"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_resize_graphs($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
            }
        } else {
            api_plugin_hook_function('graphs_action_execute', $_POST['drp_action']);
        }
        header("Location: graphs.php");
        exit;
    }
    /* setup some variables */
    $graph_list = "";
    $i = 0;
    /* loop through each of the graphs selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^chk_([0-9]+)\$/", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                if (!in_array($matches[1], $graphs)) {
                    access_denied();
                }
            }
            /* modify for multi user end */
            $graph_list .= "<li>" . get_graph_title($matches[1]) . "</li>";
            $graph_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box("<strong>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='graphs.php' method='post'>\n";
    if (isset($graph_array) && sizeof($graph_array)) {
        if ($_POST["drp_action"] == "1") {
            /* delete */
            $graphs = array();
            /* find out which (if any) data sources are being used by this graph, so we can tell the user */
            if (isset($graph_array) && sizeof($graph_array)) {
                $data_sources = db_fetch_assoc("select\r\n\t\t\t\t\tdata_template_data.local_data_id,\r\n\t\t\t\t\tdata_template_data.name_cache\r\n\t\t\t\t\tfrom (data_template_rrd,data_template_data,graph_templates_item)\r\n\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\r\n\t\t\t\t\tand data_template_rrd.local_data_id=data_template_data.local_data_id\r\n\t\t\t\t\tand " . array_to_sql_or($graph_array, "graph_templates_item.local_graph_id") . "\r\n\t\t\t\t\tand data_template_data.local_data_id > 0\r\n\t\t\t\t\tgroup by data_template_data.local_data_id\r\n\t\t\t\t\torder by data_template_data.name_cache");
            }
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be deleted.  Please note, Data Source(s) should be deleted only if they are only used by these Graph(s)\r\n\t\t\t\t\t\tand not others.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>";
            if (isset($data_sources) && sizeof($data_sources)) {
                print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>The following Data Source(s) are in use by these Graph(s):</p>\n";
                print "<ul>";
                foreach ($data_sources as $data_source) {
                    print "<li><strong>" . $data_source["name_cache"] . "</strong></li>\n";
                }
                print "</ul>";
                print "<br>";
                form_radio_button("delete_type", "1", "1", "Leave the Data Source(s) untouched.", "1");
                print "<br>";
                form_radio_button("delete_type", "1", "2", "Delete all <strong>Data Source(s)</strong> referenced by these Graph(s).", "1");
                print "<br>";
                print "</td></tr>";
            }
            print "\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Graph(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            /* modify for multi user start */
            $sql_where = "";
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                $sql_where = "WHERE graph_templates.name NOT LIKE '%@system'";
            }
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>Choose a Graph Template and click \"Continue\" to change the Graph Template for\r\n\t\t\t\t\t\tthe following Graph(s). Be aware that all warnings will be suppressed during the\r\n\t\t\t\t\t\tconversion, so Graph data loss is possible.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>New Graph Template:</strong><br>";
            form_dropdown("graph_template_id", db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates {$sql_where} order by name"), "name", "id", "", "", "0");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            /* modify for multi user end */
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph Template'>";
        } elseif ($_POST["drp_action"] == "3") {
            /* duplicate */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be duplicated. You can\r\n\t\t\t\t\t\toptionally change the title format for the new Graph(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<graph_title> (1)", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Graph(s)'>";
        } elseif ($_POST["drp_action"] == "4") {
            /* graph -> graph template */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be converted into Graph Template(s).\r\n\t\t\t\t\t\tYou can optionally change the title format for the new Graph Template(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<graph_title> Template", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Convert to Graph Template'>";
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be placed under the Tree Branch selected below.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
            grow_dropdown_tree($matches[1], "tree_item_id", "0");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Graph(s) on Tree'>";
        } elseif ($_POST["drp_action"] == "5") {
            /* change host */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                $sql_join = "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'";
            }
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>Choose a new Device for these Graph(s) and click \"Continue\"</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>New Host:</strong><br>";
            form_dropdown("host_id", db_fetch_assoc("select host.id,CONCAT_WS('',host.description,' (',host.hostname,')') as name from host order by description,hostname"), "name", "id", "", "", "0");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            /* modify for multi user end */
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph(s) Associated Device'>";
        } elseif ($_POST["drp_action"] == "6") {
            /* reapply suggested naming to host */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will have thier suggested naming convensions\r\n\t\t\t\t\t\trecalculated and applied to the Graph(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Reapply Suggested Naming to Graph(s)'>";
        } elseif ($_POST["drp_action"] == "7") {
            /* resize graphs */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be resized per your specifications.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Graph Height:</strong><br>";
            form_text_box("graph_height", "", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t\t<p><strong>Graph Width:</strong><br>";
            form_text_box("graph_width", "", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Resize Selected Graph(s)'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['graph_list'] = $graph_list;
            $save['graph_array'] = isset($graph_array) ? $graph_array : array();
            api_plugin_hook_function('graphs_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\r\n\t\t\t<td align='right' bgcolor='#eaeaea'>\r\n\t\t\t\t<input type='hidden' name='action' value='actions'>\r\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>\r\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\r\n\t\t\t\t{$save_html}\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Exemplo n.º 8
0
function draw_edit_control($field_name, &$field_array) {
	require_once(CACTI_BASE_PATH . "/lib/sys/html_tree.php");

	switch ($field_array["method"]) {
	case 'textbox':
		form_text_box($field_name, $field_array["value"], ((isset($field_array["default"])) ? $field_array["default"] : ""), $field_array["max_length"], ((isset($field_array["size"])) ? $field_array["size"] : "40"), "text", ((isset($field_array["form_id"])) ? $field_array["form_id"] : ""));
		break;
	case 'textbox_password':
		form_text_box($field_name, $field_array["value"], ((isset($field_array["default"])) ? $field_array["default"] : ""), $field_array["max_length"], ((isset($field_array["size"])) ? $field_array["size"] : "40"), "password");
		print "<br>";
		form_text_box($field_name . "_confirm", $field_array["value"], ((isset($field_array["default"])) ? $field_array["default"] : ""), $field_array["max_length"], ((isset($field_array["size"])) ? $field_array["size"] : "40"), "password");
		break;
	case 'textbox_password_single':
		form_text_box($field_name, $field_array["value"], ((isset($field_array["default"])) ? $field_array["default"] : ""), $field_array["max_length"], ((isset($field_array["size"])) ? $field_array["size"] : "40"), "password");
		print "<br>";
		break;
	case 'textbox_sv':
		form_text_box_sv($field_name, $field_array["value"], $field_array["url_moveup"], $field_array["url_movedown"], $field_array["url_delete"], $field_array["url_add"], ((isset($field_array["force_blank_field"])) ? $field_array["force_blank_field"] : false), ((isset($field_array["max_length"])) ? $field_array["max_length"] : "255"), ((isset($field_array["size"])) ? $field_array["size"] : "40"));
		print "<input type='hidden' name='cacti_js_dropdown_redirect_x' value='' id='cacti_js_dropdown_redirect_x'>\n";
		break;
	case 'textarea':
		form_text_area($field_name, $field_array["value"], $field_array["textarea_rows"], $field_array["textarea_cols"], ((isset($field_array["default"])) ? $field_array["default"] : ""));
		break;
	case 'drop_array':
		form_dropdown($field_name, $field_array["array"], "", "", $field_array["value"], ((isset($field_array["none_value"])) ? $field_array["none_value"] : ""), ((isset($field_array["default"])) ? $field_array["default"] : ""), "", ((isset($field_array["trim_length"])) ? $field_array["trim_length"] : "0"), ((isset($field_array["js_onchange"])) ? $field_array["js_onchange"] : ""));
		break;
	case 'drop_array_js':
		form_dropdown($field_name, $field_array["array"], "", "", $field_array["value"], ((isset($field_array["none_value"])) ? $field_array["none_value"] : ""), ((isset($field_array["default"])) ? $field_array["default"] : ""), "", ((isset($field_array["trim_length"])) ? $field_array["trim_length"] : "0"), "submit_redirect(\"" . $field_array["form_index"] . "\", \"" . htmlspecialchars($field_array["redirect_url"]) . "\", document.forms[" . $field_array["form_index"] . "].$field_name.options[document.forms[" . $field_array["form_index"] . "].$field_name.selectedIndex].value)");
		print "<input type='hidden' name='cacti_js_dropdown_redirect_x' value='' id='cacti_js_dropdown_redirect_x'>\n";
		break;
	case 'drop_sql':
		form_dropdown($field_name, db_fetch_assoc($field_array["sql"]), "name", "id", $field_array["value"], ((isset($field_array["none_value"])) ? $field_array["none_value"] : ""), ((isset($field_array["default"])) ? $field_array["default"] : ""), "", ((isset($field_array["trim_length"])) ? $field_array["trim_length"] : "0"), ((isset($field_array["js_onchange"])) ? $field_array["js_onchange"] : ""));
		break;
	case 'drop_multi':
		form_multi_dropdown($field_name, $field_array["array"], db_fetch_assoc($field_array["sql"]), "id");
		break;
	case 'drop_multi_rra':
		form_multi_dropdown($field_name, array_rekey(db_fetch_assoc("select id,name from rra order by timespan"), "id", "name"), (empty($field_array["form_id"]) ? db_fetch_assoc($field_array["sql_all"]) : db_fetch_assoc($field_array["sql"])), "id");
		break;
	case 'drop_tree':
		grow_dropdown_tree($field_array["tree_id"], $field_name, $field_array["value"]);
		break;
	case 'drop_color':
		form_color_dropdown($field_name, $field_array["array"], $field_array["value"], ((isset($field_array["none_value"])) ? $field_array["none_value"] : ""), ((isset($field_array["default"])) ? $field_array["default"] : ""), ((isset($field_array["js_onchange"])) ? $field_array["js_onchange"] : ""));
		break;
	case 'checkbox':
		form_checkbox($field_name, $field_array["value"], $field_array["friendly_name"], ((isset($field_array["default"])) ? $field_array["default"] : ""), ((isset($field_array["form_id"])) ? $field_array["form_id"] : ""), ((isset($field_array["js_onclick"])) ? $field_array["js_onclick"] : ""));
		break;
	case 'checkbox_group':
		while (list($check_name, $check_array) = each($field_array["items"])) {
			form_checkbox($check_name, $check_array["value"], $check_array["friendly_name"], ((isset($check_array["default"])) ? $check_array["default"] : ""), ((isset($check_array["form_id"])) ? $check_array["form_id"] : ""));
			print "<br>";
		}
		break;
	case 'radio':
		while (list($radio_index, $radio_array) = each($field_array["items"])) {
			form_radio_button($field_name, $field_array["value"], $radio_array["radio_value"], $radio_array["radio_caption"], ((isset($field_array["default"])) ? $field_array["default"] : ""));
			print "<br>";
		}
		break;
	case 'custom':
		print $field_array["value"];
		break;
	case 'template_checkbox':
		print "<em>" . html_boolean_friendly($field_array["value"]) . "</em>";
		form_hidden_box($field_name, $field_array["value"], "");
		break;
	case 'template_drop_array':
		print "<em>" . $field_array["array"]{$field_array["value"]} . "</em>";
		form_hidden_box($field_name, $field_array["value"], "");
		break;
	case 'template_drop_multi_rra':
		$items = db_fetch_assoc($field_array["sql_print"]);

		if (sizeof($items) > 0) {
		foreach ($items as $item) {
			print $item["name"] . "<br>";
		}
		}
		break;
	default:
		print "<em>" . $field_array["value"] . "</em>";
		form_hidden_box($field_name, $field_array["value"], "");
		break;
	}
}
Exemplo n.º 9
0
function form_actions()
{
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $rows = db_fetch_assoc("\r\n            SELECT host.id 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'");
        foreach ($rows as $row) {
            $hosts[] = $row["id"];
        }
    }
    /* modify for multi user end */
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        /* modify for multi user start */
        if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
            for ($i = 0; $i < count($selected_items); $i++) {
                if (!in_array($selected_items[$i], $hosts)) {
                    access_denied();
                }
            }
        }
        /* modify for multi user end */
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                /* modify for multi user start */
                if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                    if (db_fetch_cell("SELECT id FROM host WHERE id = '" . $selected_items[$i] . "' AND disabled = 'ps'")) {
                        continue;
                    }
                }
                /* modify for multi user end */
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                $poller_items = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source["id"];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source["id"]));
                    }
                }
                poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                /* modify for multi user start */
                if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                    if (db_fetch_cell("SELECT id FROM host WHERE id = '" . $selected_items[$i] . "' AND disabled = 'ps'")) {
                        continue;
                    }
                }
                /* modify for multi user end */
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\r\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\r\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc("select\r\n\t\t\t\t\tdata_local.id as local_data_id\r\n\t\t\t\t\tfrom data_local\r\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id"));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source["local_data_id"];
                    }
                }
                if ($_POST["delete_type"] == 2) {
                    $graphs = db_fetch_assoc("select\r\n\t\t\t\t\t\tgraph_local.id as local_graph_id\r\n\t\t\t\t\t\tfrom graph_local\r\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id"));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph["local_graph_id"];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST["delete_type"]) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    api_plugin_hook_function('data_source_remove', $data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    api_plugin_hook_function('graphs_remove', $graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
            /* modify for multi user start */
            if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
                foreach ($devices_to_act_on as $device_id) {
                    db_execute("DELETE FROM user_auth_perms WHERE type = 3 AND user_id = '" . $_SESSION["sess_user_id"] . "' AND item_id = '{$device_id}'");
                }
            }
            /* modify for multi user end */
            api_plugin_hook_function('device_remove', $devices_to_act_on);
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                input_validate_input_number(get_request_var_post("tree_id"));
                if ($_POST["tree_id"] != $_SESSION["public_tree_id"]) {
                    access_denied();
                }
            }
            /* modify for multi user end */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post("tree_id"));
                input_validate_input_number(get_request_var_post("tree_item_id"));
                /* ==================================================== */
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_HOST, $_POST["tree_item_id"], "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false);
            }
            /* modify for multi user start */
            if (isset($_SESSION['dhtml_tree'])) {
                unset($_SESSION['dhtml_tree']);
            }
            /* modify for multi user end */
        } else {
            api_plugin_hook_function('device_action_execute', $_POST['drp_action']);
        }
        header("Location: host.php");
        exit;
    }
    /* setup some variables */
    $host_list = "";
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^chk_([0-9]+)\$/", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                if (!in_array($matches[1], $hosts)) {
                    access_denied();
                }
            }
            /* modify for multi user start */
            $host_list .= "<li>" . htmlspecialchars(db_fetch_cell("select description from host where id=" . $matches[1])) . "<br>";
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box("<strong>" . $device_actions[get_request_var_post("drp_action")] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='host.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_POST["drp_action"] == "2") {
            /* Enable Devices */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Device(s)'>";
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Devices */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Device(s)'>";
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\r\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match("/^snmp_/", $field_name) || $field_name == "max_oids") {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]["value"] = "";
                    $form_array[$field_name]["description"] = "";
                    $form_array[$field_name]["form_id"] = 0;
                    $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
                }
            }
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                $form_array["snmp_timeout"]["method"] = "hidden";
                $form_array["max_oids"]["method"] = "hidden";
            }
            /* modify for multi user end */
            draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) SNMP Options'>";
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\r\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match("/(availability_method|ping_method|ping_port)/", $field_name)) {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]["value"] = "";
                    $form_array[$field_name]["description"] = "";
                    $form_array[$field_name]["form_id"] = 0;
                    $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
                }
            }
            draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) Availability Options'>";
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Clear Statistics on Device(s)'>";
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>";
            /* modify for multi user start */
            if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
                form_radio_button("delete_type", "2", "1", "Leave all Graph(s) and Data Source(s) untouched.  Data Source(s) will be disabled however.", "1");
                print "<br>";
            }
            /* modify for multi user end */
            form_radio_button("delete_type", "2", "2", "Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.", "1");
            print "<br>";
            print "</td></tr>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\r\n\t\t\t\t\t\tbelow.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
            grow_dropdown_tree($matches[1], "tree_item_id", "0");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['host_list'] = $host_list;
            $save['host_array'] = isset($host_array) ? $host_array : array();
            api_plugin_hook_function('device_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\r\n\t\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\r\n\t\t\t\t<input type='hidden' name='action' value='actions'>\r\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\r\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\r\n\t\t\t\t{$save_html}\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Exemplo n.º 10
0
function item_edit() {
	global $colors;
	require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php");
	require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php");

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

	if (!empty($_GET["id"])) {
		$tree_item = db_fetch_row("select * from graph_tree_items where id=" . $_GET["id"]);

		if ($tree_item["local_graph_id"] > 0) { $db_type = TREE_ITEM_TYPE_GRAPH; }
		if ($tree_item["title"] != "") { $db_type = TREE_ITEM_TYPE_HEADER; }
		if ($tree_item["device_id"] > 0) { $db_type = TREE_ITEM_TYPE_DEVICE; }
	}

	if (isset($_GET["type_select"])) {
		$current_type = $_GET["type_select"];
	}elseif (isset($db_type)) {
		$current_type = $db_type;
	}else{
		$current_type = TREE_ITEM_TYPE_HEADER;
	}

	$tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . $_GET["tree_id"] . "'");

	print "<form action='tree.php' name='form_tree' method='post'>\n";

	html_start_box("<strong>" . __("Tree Items") . "</strong>", "100", $colors["header"], "3", "center", "");

	form_alternate_row_color("parent_item");
	?>
		<td width="50%">
			<font class="textEditTitle"><?php print __("Parent Item");?></font><br>
			<?php print __("Choose the parent for this header/graph.");?>
		</td>
		<td>
			<?php grow_dropdown_tree($_GET["tree_id"], "parent_item_id", (isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"])));?>
		</td>
	<?php
	form_end_row();
	form_alternate_row_color("tree_item");
	?>
		<td width="50%">
			<font class="textEditTitle"><?php print __("Tree Item Type");?></font><br>
			<?php print __("Choose what type of tree item this is.");?>
		</td>
		<td>
			<select name="type_select" onChange="window.location=document.form_tree.type_select.options[document.form_tree.type_select.selectedIndex].value">
				<?php
				while (list($var, $val) = each($tree_item_types)) {
					print "<option value='" . htmlspecialchars("tree.php?action=item_edit" . (isset($_GET["id"]) ? "&id=" . $_GET["id"] : "") . (isset($_GET["parent_id"]) ? "&parent_id=" . $_GET["parent_id"] : "") . "&tree_id=" . $_GET["tree_id"] . "&type_select=" . $var) . "'"; if ($var == $current_type) { print " selected"; } print ">$val</option>\n";
				}
				?>
			</select>
		</td>
	<?php
	form_end_row();
	?>
		<tr class='rowSubHeader'>
			<td colspan="2" class='textSubHeaderDark'><?php print __("Tree Item Value");?></td>
		</tr>
	<?php
	switch ($current_type) {
	case TREE_ITEM_TYPE_HEADER:
		$i = 0;

		/* it's nice to default to the parent sorting style for new items */
		if (empty($_GET["id"])) {
			$default_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=" . $_GET["parent_id"]);
		}else{
			$default_sorting_type = DATA_QUERY_INDEX_SORT_TYPE_NONE;
		}

		form_alternate_row_color("item_title"); ?>
			<td width="50%">
				<font class="textEditTitle"><?php print __("Title");?></font><br>
				<?php print __("If this item is a header, enter a title here.");?>
			</td>
			<td>
				<?php form_text_box("title", (isset($tree_item["title"]) ? $tree_item["title"] : ""), "", "255", 30, "text", (isset($_GET["id"]) ? $_GET["id"] : "0"));?>
			</td>
		<?php
		form_end_row();
		/* don't allow the user to change the tree item ordering if a tree order has been specified */
		if ($tree_sort_type == DATA_QUERY_INDEX_SORT_TYPE_NONE) {
			form_alternate_row_color("sorting_type"); ?>
				<td width="50%">
					<font class="textEditTitle"><?php print __("Sorting Type");?></font><br>
					<?php print __("Choose how children of this branch will be sorted.");?>
				</td>
				<td>
					<?php form_dropdown("sort_children_type", $tree_sort_types, "", "", (isset($tree_item["sort_children_type"]) ? $tree_item["sort_children_type"] : $default_sorting_type), "", "");?>
				</td>
			<?php
			form_end_row();
		}

		if ((!empty($_GET["id"])) && ($tree_sort_type == DATA_QUERY_INDEX_SORT_TYPE_NONE)) {
			form_alternate_row_color("propagate"); ?>
				<td width="50%">
					<font class="textEditTitle"><?php print __("Propagate Changes");?></font><br>
					<?php print __("Propagate all options on this form (except for 'Title') to all child 'Header' items.");?>
				</td>
				<td>
					<?php form_checkbox("propagate_changes", "", __("Propagate Changes"), "", "", "", 0);?>
				</td>
			<?php
			form_end_row();
		}
		break;
	case TREE_ITEM_TYPE_GRAPH:
		form_alternate_row_color("graph"); ?>
			<td width="50%">
				<font class="textEditTitle"><?php print __("Graph");?></font><br>
				<?php print __("Choose a graph from this list to add it to the tree.");?>
			</td>
			<td>
				<?php form_dropdown("local_graph_id", db_fetch_assoc("select graph_templates_graph.local_graph_id as id,graph_templates_graph.title_cache as name from (graph_templates_graph,graph_local) where graph_local.id=graph_templates_graph.local_graph_id and local_graph_id != 0 order by title_cache"), "name", "id", (isset($tree_item["local_graph_id"]) ? $tree_item["local_graph_id"] : ""), "", "");?>
			</td>
		<?php
		form_end_row();
		form_alternate_row_color("rra");
		?>
			<td width="50%">
				<font class="textEditTitle"><?php print __("Round Robin Archive");?></font><br>
				<?php print __("Choose a round robin archive to control how this graph is displayed.");?>
			</td>
			<td>
				<?php form_dropdown("rra_id", db_fetch_assoc("select id,name from rra order by timespan"), "name", "id", (isset($tree_item["rra_id"]) ? $tree_item["rra_id"] : ""), "", "");?>
			</td>
		<?php
		form_end_row();
		break;
	case TREE_ITEM_TYPE_DEVICE:
		form_alternate_row_color("device"); ?>
			<td width="50%">
				<font class="textEditTitle"><?php print __("Host");?></font><br>
				<?php print __("Choose a device here to add it to the tree.");?>
			</td>
			<td>
				<?php form_dropdown("device_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from device order by description,hostname"), "name", "id", (isset($tree_item["device_id"]) ? $tree_item["device_id"] : ""), "", "");?>
			</td>
		<?php
		form_end_row();
		form_alternate_row_color("graph_grouping");
		?>
			<td width="50%">
				<font class="textEditTitle"><?php print __("Graph Grouping Style");?></font><br>
				<?php print __("Choose how graphs are grouped when drawn for this particular device on the tree.");?>
			</td>
			<td>
				<?php form_dropdown("device_grouping_type", $tree_device_group_types, "", "", (isset($tree_item["device_grouping_type"]) ? $tree_item["device_grouping_type"] : "1"), "", "");?>
			</td>
		<?php
		form_end_row();
		break;
	}

	html_end_box();

	form_hidden_box("id", (isset($_GET["id"]) ? $_GET["id"] : "0"), "");
	form_hidden_box("graph_tree_id", get_request_var("tree_id"), "");
	form_hidden_box("type", $current_type, "");
	form_hidden_box("save_component_tree_item", "1", "");

	form_save_button_alt("path!tree.php|action!edit|id!" . get_request_var("tree_id"));
}
Exemplo n.º 11
0
function form_actions()
{
    global $graph_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 1;
            }
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
            }
            switch ($_POST['delete_type']) {
                case '2':
                    /* delete all data sources referenced by this graph */
                    $data_sources = array_rekey(db_fetch_assoc('SELECT data_template_data.local_data_id
						FROM (data_template_rrd, data_template_data, graph_templates_item)
						WHERE graph_templates_item.task_item_id=data_template_rrd.id
						AND data_template_rrd.local_data_id=data_template_data.local_data_id
						AND ' . array_to_sql_or($selected_items, 'graph_templates_item.local_graph_id') . '
						AND data_template_data.local_data_id > 0'), 'local_data_id', 'local_data_id');
                    if (sizeof($data_sources)) {
                        api_data_source_remove_multi($data_sources);
                        api_plugin_hook_function('data_source_remove', $data_sources);
                    }
                    break;
            }
            api_graph_remove_multi($selected_items);
            api_plugin_hook_function('graphs_remove', $selected_items);
        } elseif ($_POST['drp_action'] == '2') {
            /* change graph template */
            input_validate_input_number(get_request_var_post('graph_template_id'));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                change_graph_template($selected_items[$i], $_POST['graph_template_id'], true);
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_graph($selected_items[$i], 0, $_POST['title_format']);
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* graph -> graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                graph_to_graph_template($selected_items[$i], $_POST['title_format']);
            }
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            input_validate_input_number(get_request_var_post('tree_id'));
            input_validate_input_number(get_request_var_post('tree_item_id'));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_tree_item_save(0, $_POST['tree_id'], TREE_ITEM_TYPE_GRAPH, $_POST['tree_item_id'], '', $selected_items[$i], read_graph_config_option('default_rra_id'), 0, 0, 0, false);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* change host */
            input_validate_input_number(get_request_var_post('host_id'));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared('UPDATE graph_local SET host_id = ? WHERE id = ?', array($_POST['host_id'], $selected_items[$i]));
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* reapply suggested naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_reapply_suggested_graph_title($selected_items[$i]);
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '7') {
            /* resize graphs */
            input_validate_input_number(get_request_var_post('graph_width'));
            input_validate_input_number(get_request_var_post('graph_height'));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_resize_graphs($selected_items[$i], $_POST['graph_width'], $_POST['graph_height']);
            }
        } else {
            api_plugin_hook_function('graphs_action_execute', $_POST['drp_action']);
        }
        /* update snmpcache */
        snmpagent_graphs_action_bottom(array($_POST['drp_action'], $selected_items));
        api_plugin_hook_function('graphs_action_bottom', array($_POST['drp_action'], $selected_items));
        header('Location: graphs.php');
        exit;
    }
    /* setup some variables */
    $graph_list = '';
    $i = 0;
    /* loop through each of the graphs selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $graph_list .= '<li>' . htmlspecialchars(get_graph_title($matches[1])) . '</li>';
            $graph_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box('<strong>' . $graph_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='graphs.php' method='post'>\n";
    if (isset($graph_array) && sizeof($graph_array)) {
        if ($_POST['drp_action'] == '1') {
            /* delete */
            $graphs = array();
            /* find out which (if any) data sources are being used by this graph, so we can tell the user */
            if (isset($graph_array) && sizeof($graph_array)) {
                $data_sources = db_fetch_assoc('select
					data_template_data.local_data_id,
					data_template_data.name_cache
					from (data_template_rrd,data_template_data,graph_templates_item)
					where graph_templates_item.task_item_id=data_template_rrd.id
					and data_template_rrd.local_data_id=data_template_data.local_data_id
					and ' . array_to_sql_or($graph_array, 'graph_templates_item.local_graph_id') . '
					and data_template_data.local_data_id > 0
					group by data_template_data.local_data_id
					order by data_template_data.name_cache');
            }
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be deleted.  Please note, Data Source(s) should be deleted only if they are only used by these Graph(s)\n\t\t\t\t\t\tand not others.</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>";
            if (isset($data_sources) && sizeof($data_sources)) {
                print "<tr><td class='textArea'><p>The following Data Source(s) are in use by these Graph(s):</p>\n";
                print '<ul>';
                foreach ($data_sources as $data_source) {
                    print '<li><strong>' . $data_source['name_cache'] . "</strong></li>\n";
                }
                print '</ul>';
                print '<br>';
                form_radio_button('delete_type', '1', '2', "Leave the Data Source(s) untouched.  Not applicable for Graphs created under 'New Graphs' or WHERE the Graphs were created automatically.", '2');
                print '<br>';
                form_radio_button('delete_type', '2', '2', 'Delete all <strong>Data Source(s)</strong> referenced by these Graph(s).', '2');
                print '<br>';
                print '</td></tr>';
            }
            print "\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Graph(s)'>";
        } elseif ($_POST['drp_action'] == '2') {
            /* change graph template */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a Graph Template and click \"Continue\" to change the Graph Template for\n\t\t\t\t\t\tthe following Graph(s). Be aware that all warnings will be suppressed during the\n\t\t\t\t\t\tconversion, so Graph data loss is possible.</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Graph Template:</strong><br>";
            form_dropdown('graph_template_id', db_fetch_assoc('SELECT graph_templates.id,graph_templates.name FROM graph_templates ORDER BY name'), 'name', 'id', '', '', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph Template'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* duplicate */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Graph(s).</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box('title_format', '<graph_title> (1)', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Graph(s)'>";
        } elseif ($_POST['drp_action'] == '4') {
            /* graph -> graph template */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be converted into Graph Template(s).\n\t\t\t\t\t\tYou can optionally change the title format for the new Graph Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box('title_format', '<graph_title> Template', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Convert to Graph Template'>";
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be placed under the Tree Branch selected below.</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
            grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Graph(s) on Tree'>";
        } elseif ($_POST['drp_action'] == '5') {
            /* change host */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a new Device for these Graph(s) and click \"Continue\"</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Device:</strong><br>";
            form_dropdown('host_id', db_fetch_assoc("SELECT id,CONCAT_WS('',description,' (',hostname,')') as name FROM host ORDER BY description,hostname"), 'name', 'id', '', '', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph(s) Associated Device'>";
        } elseif ($_POST['drp_action'] == '6') {
            /* reapply suggested naming to host */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will have thier suggested naming convensions\n\t\t\t\t\t\trecalculated and applied to the Graph(s).</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Reapply Suggested Naming to Graph(s)'>";
        } elseif ($_POST['drp_action'] == '7') {
            /* resize graphs */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be resized per your specifications.</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Graph Height:</strong><br>";
            form_text_box('graph_height', '', '', '255', '30', 'text');
            print '</p>
						<p><strong>Graph Width:</strong><br>';
            form_text_box('graph_width', '', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Resize Selected Graph(s)'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['graph_list'] = $graph_list;
            $save['graph_array'] = isset($graph_array) ? $graph_array : array();
            api_plugin_hook_function('graphs_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
Exemplo n.º 12
0
function item_edit()
{
    global $colors, $tree_sort_types;
    global $tree_item_types, $host_group_types;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    input_validate_input_number(get_request_var("tree_id"));
    /* ==================================================== */
    /* modify for multi user start */
    $public_tree = FALSE;
    if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
        if ($_GET["tree_id"] == $_SESSION["public_tree_id"]) {
            $public_tree = TRUE;
        } else {
            if (!empty($_GET["id"])) {
                if (!check_tree_item($_GET["id"])) {
                    access_denied();
                }
            }
        }
    }
    /* modify for multi user end */
    if (!empty($_GET["id"])) {
        $tree_item = db_fetch_row("select * from graph_tree_items where id=" . get_request_var("id"));
        if ($tree_item["local_graph_id"] > 0) {
            $db_type = TREE_ITEM_TYPE_GRAPH;
        }
        if ($tree_item["title"] != "") {
            $db_type = TREE_ITEM_TYPE_HEADER;
        }
        if ($tree_item["host_id"] > 0) {
            $db_type = TREE_ITEM_TYPE_HOST;
        }
    }
    if (isset($_GET["type_select"])) {
        $current_type = $_GET["type_select"];
    } elseif (isset($db_type)) {
        $current_type = $db_type;
    } else {
        $current_type = TREE_ITEM_TYPE_HEADER;
    }
    $tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . get_request_var("tree_id") . "'");
    print "<form method='post' action='tree.php' name='form_tree'>\n";
    html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", "");
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
    ?>
		<td width="50%">
			<font class="textEditTitle">Parent Item</font><br>
			Choose the parent for this header/graph.
		</td>
		<td>
			<?php 
    grow_dropdown_tree($_GET["tree_id"], "parent_item_id", isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"]));
    ?>
		</td>
	</tr>
	<?php 
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1);
    ?>
		<td width="50%">
			<font class="textEditTitle">Tree Item Type</font><br>
			Choose what type of tree item this is.
		</td>
		<td>
			<select name="type_select" onChange="window.location=document.form_tree.type_select.options[document.form_tree.type_select.selectedIndex].value">
				<?php 
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        if (!db_fetch_cell("\r\n                        SELECT COUNT(graph_local.id) FROM graph_local\r\n                            INNER JOIN host ON graph_local.host_id = host.id\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'")) {
            unset($tree_item_types[2]);
            // graph
        }
        if (!db_fetch_cell("\r\n                        SELECT COUNT(host.id) 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'")) {
            unset($tree_item_types[3]);
            // host
        }
        if ($public_tree == TRUE) {
            unset($tree_item_types[1]);
            // header
            unset($tree_item_types[3]);
            // host
            $current_type = 2;
        }
    }
    /* modify for multi user end */
    while (list($var, $val) = each($tree_item_types)) {
        print "<option value='tree.php?action=item_edit" . (isset($_GET["id"]) ? "&id=" . $_GET["id"] : "") . (isset($_GET["parent_id"]) ? "&parent_id=" . $_GET["parent_id"] : "") . "&tree_id=" . $_GET["tree_id"] . "&type_select={$var}'";
        if ($var == $current_type) {
            print " selected";
        }
        print ">{$val}</option>\n";
    }
    ?>
			</select>
		</td>
	</tr>
	<tr bgcolor='#<?php 
    print $colors["header_panel"];
    ?>
'>
		<td colspan="2" class='textSubHeaderDark'>Tree Item Value</td>
	</tr>
	<?php 
    switch ($current_type) {
        case TREE_ITEM_TYPE_HEADER:
            $i = 0;
            /* it's nice to default to the parent sorting style for new items */
            if (empty($_GET["id"])) {
                $default_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=" . $_GET["parent_id"]);
            } else {
                $default_sorting_type = TREE_ORDERING_NONE;
            }
            form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i);
            $i++;
            ?>
			<td width="50%">
				<font class="textEditTitle">Title</font><br>
				If this item is a header, enter a title here.
			</td>
			<td>
				<?php 
            form_text_box("title", isset($tree_item["title"]) ? $tree_item["title"] : "", "", "255", 30, "text", isset($_GET["id"]) ? $_GET["id"] : "0");
            ?>
			</td>
		</tr>
		<?php 
            /* don't allow the user to change the tree item ordering if a tree order has been specified */
            if ($tree_sort_type == TREE_ORDERING_NONE) {
                form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i);
                $i++;
                ?>
				<td width="50%">
					<font class="textEditTitle">Sorting Type</font><br>
					Choose how children of this branch will be sorted.
				</td>
				<td>
					<?php 
                form_dropdown("sort_children_type", $tree_sort_types, "", "", isset($tree_item["sort_children_type"]) ? $tree_item["sort_children_type"] : $default_sorting_type, "", "");
                ?>
				</td>
			</tr>
			<?php 
            }
            if (!empty($_GET["id"]) && $tree_sort_type == TREE_ORDERING_NONE) {
                form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i);
                $i++;
                ?>
				<td width="50%">
					<font class="textEditTitle">Propagate Changes</font><br>
					Propagate all options on this form (except for 'Title') to all child 'Header' items.
				</td>
				<td>
					<?php 
                form_checkbox("propagate_changes", "", "Propagate Changes", "", "", "", 0);
                ?>
				</td>
			</tr>
			<?php 
            }
            break;
        case TREE_ITEM_TYPE_GRAPH:
            form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
            ?>
			<td width="50%">
				<font class="textEditTitle">Graph</font><br>
				Choose a graph from this list to add it to the tree.
			</td>
			<td>
				<?php 
            /* modify for multi user start */
            if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
                form_dropdown("local_graph_id", db_fetch_assoc("\r\n                    \tSELECT graph_templates_graph.local_graph_id as id,graph_templates_graph.title_cache as name FROM graph_templates_graph \r\n                            INNER JOIN graph_local ON graph_templates_graph.local_graph_id = graph_local.id\r\n                            INNER JOIN host ON graph_local.host_id = host.id\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                        WHERE graph_templates_graph.local_graph_id != 0 \r\n                        ORDER BY graph_templates_graph.title_cache"), "name", "id", isset($tree_item["local_graph_id"]) ? $tree_item["local_graph_id"] : "", "", "");
            } else {
                form_dropdown("local_graph_id", db_fetch_assoc("select graph_templates_graph.local_graph_id as id,graph_templates_graph.title_cache as name from (graph_templates_graph,graph_local) where graph_local.id=graph_templates_graph.local_graph_id and local_graph_id != 0 order by title_cache"), "name", "id", isset($tree_item["local_graph_id"]) ? $tree_item["local_graph_id"] : "", "", "");
            }
            /* modify for multi user end */
            ?>
			</td>
		</tr>
		<?php 
            form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1);
            ?>
			<td width="50%">
				<font class="textEditTitle">Round Robin Archive</font><br>
				Choose a round robin archive to control how the Graph Thumbnail is displayed when using Tree Export.
			</td>
			<td>
				<?php 
            form_dropdown("rra_id", db_fetch_assoc("select id,name from rra order by timespan"), "name", "id", isset($tree_item["rra_id"]) ? $tree_item["rra_id"] : "", "", "");
            ?>
			</td>
		</tr>
		<?php 
            break;
        case TREE_ITEM_TYPE_HOST:
            form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
            ?>
			<td width="50%">
				<font class="textEditTitle">Host</font><br>
				Choose a host here to add it to the tree.
			</td>
			<td>
				<?php 
            /* modify for multi user start */
            if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
                form_dropdown("host_id", db_fetch_assoc("\r\n\t\t\t\t\t\tSELECT 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"), "name", "id", isset($tree_item["host_id"]) ? $tree_item["host_id"] : "", "", "");
            } else {
                form_dropdown("host_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "name", "id", isset($tree_item["host_id"]) ? $tree_item["host_id"] : "", "", "");
            }
            /* modify for multi user end */
            ?>
			</td>
		</tr>
		<?php 
            form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1);
            ?>
			<td width="50%">
				<font class="textEditTitle">Graph Grouping Style</font><br>
				Choose how graphs are grouped when drawn for this particular host on the tree.
			</td>
			<td>
				<?php 
            form_dropdown("host_grouping_type", $host_group_types, "", "", isset($tree_item["host_grouping_type"]) ? $tree_item["host_grouping_type"] : "1", "", "");
            ?>
			</td>
		</tr>
		<?php 
            form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1);
            ?>
			<td width="50%">
				<font class="textEditTitle">Round Robin Archive</font><br>
				Choose a round robin archive to control how Graph Thumbnails are displayed when using Tree Export.
			</td>
			<td>
				<?php 
            form_dropdown("rra_id", db_fetch_assoc("select id,name from rra order by timespan"), "name", "id", isset($tree_item["rra_id"]) ? $tree_item["rra_id"] : "", "", "");
            ?>
			</td>
		</tr>
		<?php 
            break;
    }
    ?>
	</tr>
	<?php 
    form_hidden_box("id", isset($_GET["id"]) ? $_GET["id"] : "0", "");
    form_hidden_box("graph_tree_id", $_GET["tree_id"], "");
    form_hidden_box("type", $current_type, "");
    form_hidden_box("save_component_tree_item", "1", "");
    html_end_box();
    form_save_button("tree.php?action=edit&id=" . $_GET["tree_id"]);
}
Exemplo n.º 13
0
function graph_form_actions() {
	global $colors;
	require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php");
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");

	/* if we are to save this form, instead of display it */
	if (isset($_POST["selected_items"])) {
		$selected_items = unserialize(stripslashes($_POST["selected_items"]));

		if (get_request_var_post("drp_action") === GRAPH_ACTION_DELETE) { /* delete */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; }

				switch (get_request_var_post("delete_type")) {
					case '2': /* delete all data sources referenced by this graph */
						$data_sources = db_fetch_assoc("SELECT " .
								"data_template_data.local_data_id " .
							"FROM " .
								"(data_template_rrd, " .
								"data_template_data, " .
								"graph_templates_item) " .
							"WHERE " .
								"graph_templates_item.task_item_id=data_template_rrd.id " .
								"AND data_template_rrd.local_data_id=data_template_data.local_data_id " .
								"AND graph_templates_item.local_graph_id=" . $selected_items[$i] . " " .
								"AND data_template_data.local_data_id > 0");

						if (sizeof($data_sources) > 0) {
							foreach ($data_sources as $data_source) {
								api_data_source_remove($data_source["local_data_id"]);
							}
						}

						break;
				}

				api_graph_remove($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_CHANGE_TEMPLATE) { /* change graph template */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				input_validate_input_number(get_request_var_post("graph_template_id"));
				/* ==================================================== */

				change_graph_template($selected_items[$i], get_request_var_post("graph_template_id"), true);
			}
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_DUPLICATE) { /* duplicate */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				duplicate_graph($selected_items[$i], 0, get_request_var_post("title_format"));
			}
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_CONVERT_TO_TEMPLATE) { /* graph -> graph template */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				graph_to_graph_template($selected_items[$i], get_request_var_post("title_format"));
			}
		}elseif (preg_match("/^tr_([0-9]+)$/", get_request_var_post("drp_action"), $matches)) { /* place on tree */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				input_validate_input_number(get_request_var_post("tree_id"));
				input_validate_input_number(get_request_var_post("tree_item_id"));
				/* ==================================================== */

				api_tree_item_save(0, get_request_var_post("tree_id"), TREE_ITEM_TYPE_GRAPH, get_request_var_post("tree_item_id"), "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
			}
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_CHANGE_HOST) { /* change device */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				input_validate_input_number(get_request_var_post("device_id"));
				/* ==================================================== */

				db_execute("update graph_local set device_id=" . $_POST["device_id"] . " where id=" . $selected_items[$i]);
				update_graph_title_cache($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_REAPPLY_SUGGESTED_NAMES) { /* reapply suggested naming */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				api_reapply_suggested_graph_title($selected_items[$i]);
				update_graph_title_cache($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_RESIZE) { /* resize graphs */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				api_resize_graphs($selected_items[$i], get_request_var_post('graph_width'), get_request_var_post('graph_height'));
			}
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_ENABLE_EXPORT) { /* enable graph export */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */
				db_execute("UPDATE graph_templates_graph SET export='on' WHERE local_graph_id=" . $selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_DISABLE_EXPORT) { /* disable graph export */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */
				db_execute("UPDATE graph_templates_graph SET export='' WHERE local_graph_id=" . $selected_items[$i]);
			}
		} else {
			api_plugin_hook_function('graphs_action_execute', get_request_var_post('drp_action'));
		}

		header("Location: graphs.php");
		exit;
	}

	/* setup some variables */
	$graph_list = ""; $i = 0; $graph_array = array();

	/* loop through each of the graphs selected on the previous page and get more info about them */
	while (list($var,$val) = each($_POST)) {
		if (preg_match("/^chk_([0-9]+)$/", $var, $matches)) {
			/* ================= input validation ================= */
			input_validate_input_number($matches[1]);
			/* ==================================================== */

			$graph_list .= "<li>" . get_graph_title($matches[1]) . "<br>";
			$graph_array[$i++] = $matches[1];
		}
	}

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

	/* add a list of tree names to the actions dropdown */
	$graph_actions = array_merge(graph_actions_list(), api_tree_add_tree_names_to_actions_array());

	$graph_actions[ACTION_NONE] = __("None");

	html_start_box("<strong>" . $graph_actions{get_request_var_post("drp_action")} . "</strong>", "60", $colors["header_panel"], "3", "center", "");

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

	if (sizeof($graph_array)) {
		if (get_request_var_post("drp_action") === ACTION_NONE) { /* NONE */
			print "	<tr>
						<td class='textArea'>
							<p>" . __("You did not select a valid action. Please select 'Return' to return to the previous menu.") . "</p>
						</td>
					</tr>\n";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_DELETE) { /* delete */
			$graphs = array();

			/* find out which (if any) data sources are being used by this graph, so we can tell the user */
			if (isset($graph_array)) {
				$data_sources = db_fetch_assoc("select
					data_template_data.local_data_id,
					data_template_data.name_cache
					from (data_template_rrd,data_template_data,graph_templates_item)
					where graph_templates_item.task_item_id=data_template_rrd.id
					and data_template_rrd.local_data_id=data_template_data.local_data_id
					and " . array_to_sql_or($graph_array, "graph_templates_item.local_graph_id") . "
					and data_template_data.local_data_id > 0
					group by data_template_data.local_data_id
					order by data_template_data.name_cache");
			}

			print "	<tr>
					<td class='textArea'>
						<p>" . __("Are you sure you want to delete the following graphs?") . "</p>
						<p>$graph_list</p>
						";
						if (sizeof($data_sources) > 0) {
							print "<tr class='rowAlternate1'><td class='textArea'><p class='textArea'>" . __("The following data sources are in use by these graphs:") . "</p>\n";

							foreach ($data_sources as $data_source) {
								print "<strong>" . $data_source["name_cache"] . "</strong><br>\n";
							}

							print "<br>";
							form_radio_button("delete_type", "1", "1", __("Leave the data sources untouched."), "1"); print "<br>";
							form_radio_button("delete_type", "1", "2", __("Delete all <strong>data sources</strong> referenced by these graphs."), "1"); print "<br>";
							print "</td></tr>";
						}
					print "
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_CHANGE_TEMPLATE) { /* change graph template */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("Choose a graph template and click save to change the graph template for the following graphs. Be aware that all warnings will be suppressed during the conversion, so graph data loss is possible.") . "</p>
						<p>$graph_list</p>
						<p><strong>" . __("New Graph Template:") . "</strong><br>"; form_dropdown("graph_template_id",db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates order by name"),"name","id","","","0"); print "</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_DUPLICATE) { /* duplicate */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following graphs will be duplicated. You can optionally change the title format for the new graphs.") . "</p>
						<p>$graph_list</p>
						<p><strong>" . __("Title Format:") . "</strong><br>"; form_text_box("title_format", __("<graph_title> (1)"), "", "255", "30", "text"); print "</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_CONVERT_TO_TEMPLATE) { /* graph -> graph template */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following graphs will be converted into graph templates.  You can optionally change the title format for the new graph templates.") . "</p>
						<p>$graph_list</p>
						<p><strong>" . __("Title Format:") . "</strong><br>"; form_text_box("title_format", __("<graph_title> Template"), "", "255", "30", "text"); print "</p>
					</td>
				</tr>\n
				";
		}elseif (preg_match("/^tr_([0-9]+)$/", get_request_var_post("drp_action"), $matches)) { /* place on tree */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following graphs will be placed under the branch selected below.") . "</p>
						<p>$graph_list</p>
						<p><strong>" . __("Destination Branch:") . "</strong><br>"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "</p>
					</td>
				</tr>\n
				<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n
				";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_CHANGE_HOST) { /* change device */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("Choose a new device for these graphs:") . "</p>
						<p>$graph_list</p>
						<p><strong>" . __("New Host:") . "</strong><br>"; form_dropdown("device_id",db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from device order by description,hostname"),"name","id","","","0"); print "</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_REAPPLY_SUGGESTED_NAMES) { /* reapply suggested naming to device */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following graphs will have their suggested naming conventions recalculated and applied to the graphs.") . "</p>
						<p>$graph_list</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_RESIZE) { /* reapply suggested naming to device */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following graphs will be resized per your specifications.") . "</p>
						<p>$graph_list</p>
						<p><strong>" . __("Graph Height:") . "</strong><br>"; form_text_box("graph_height", "", "", "255", "30", "text"); print "</p>
						<p><strong>" . __("Graph Width:") . "</strong><br>"; form_text_box("graph_width", "", "", "255", "30", "text"); print "</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_ENABLE_EXPORT) { /* enable graph export */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following graphs will be enabled for graph export.") . "</p>
						<p>$graph_list</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === GRAPH_ACTION_DISABLE_EXPORT) { /* disable graph export */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following graphs will be disabled for graph export.") . "</p>
						<p>$graph_list</p>
					</td>
				</tr>\n
				";
		} else {
			$save['drp_action'] = $_POST['drp_action'];
			$save['graph_list'] = $graph_list;
			$save['graph_array'] = $graph_array;
			api_plugin_hook_function('graphs_action_prepare', $save);
		}
	} else {
		print "	<tr>
				<td class='textArea'>
					<p>" . __("You must first select a Graph.  Please select 'Return' to return to the previous menu.") . "</p>
				</td>
			</tr>\n";
	}

	if (!sizeof($graph_array) || get_request_var_post("drp_action") === ACTION_NONE) {
		form_return_button_alt();
	}else{
		form_yesno_button_alt(serialize($graph_array), get_request_var_post("drp_action"));
	}

	html_end_box();

	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}
Exemplo n.º 14
0
function api_device_form_actions() {
	global $colors;
	require_once(CACTI_BASE_PATH . "/lib/device/device_info.php");
	require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php");

	$fields_device_edit = device_form_list();
	$fields_device_edit_availability = device_availability_form_list();
	/* if we are to save this form, instead of display it */
	if (isset($_POST["selected_items"])) {
		$selected_items = unserialize(stripslashes($_POST["selected_items"]));

		if (get_request_var_post("drp_action") === DEVICE_ACTION_ENABLE) { /* Enable Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				db_execute("update device set disabled='' where id='" . $selected_items[$i] . "'");

				/* update poller cache */
				$data_sources = db_fetch_assoc("select id from data_local where device_id='" . $selected_items[$i] . "'");
				$poller_items = array();

				if (sizeof($data_sources) > 0) {
					foreach ($data_sources as $data_source) {
						$local_data_ids[] = $data_source["id"];
						$poller_items     = array_merge($poller_items, update_poller_cache($data_source["id"]));
					}
				}

				poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_DISABLE) { /* Disable Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				db_execute("update device set disabled='on' where id='" . $selected_items[$i] . "'");

				/* update poller cache */
				db_execute("delete from poller_item where device_id='" . $selected_items[$i] . "'");
				db_execute("delete from poller_reindex where device_id='" . $selected_items[$i] . "'");
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_SNMP_OPTIONS) { /* change snmp options */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				reset($fields_device_edit);
				while (list($field_name, $field_array) = each($fields_device_edit)) {
					if (isset($_POST["t_$field_name"])) {
						db_execute("update device set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_device($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CLEAR_STATISTICS) { /* Clear Statisitics for Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				db_execute("update device set min_time = '9.99999', max_time = '0', cur_time = '0',	avg_time = '0',
						total_polls = '0', failed_polls = '0',	availability = '100.00'
						where id = '" . $selected_items[$i] . "'");
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_AVAILABILITY_OPTIONS) { /* change availability options */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				reset($fields_device_edit);
				while (list($field_name, $field_array) = each($fields_device_edit)) {
					if (isset($_POST["t_$field_name"])) {
						db_execute("update device set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_device($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_POLLER) { /* change poller */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				reset($fields_device_edit);
				while (list($field_name, $field_array) = each($fields_device_edit)) {
					if (isset($_POST["$field_name"])) {
						db_execute("update device set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_device($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_SITE) { /* change site */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				reset($fields_device_edit);
				while (list($field_name, $field_array) = each($fields_device_edit)) {
					if (isset($_POST["$field_name"])) {
						db_execute("update device set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_device($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_DELETE) { /* delete */
			if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; }

			$data_sources_to_act_on = array();
			$graphs_to_act_on       = array();
			$devices_to_act_on      = array();

			for ($i=0; $i<count($selected_items); $i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				$data_sources = db_fetch_assoc("select
					data_local.id as local_data_id
					from data_local
					where " . array_to_sql_or($selected_items, "data_local.device_id"));

				if (sizeof($data_sources) > 0) {
				foreach ($data_sources as $data_source) {
					$data_sources_to_act_on[] = $data_source["local_data_id"];
				}
				}

				if (get_request_var_post("delete_type") == 2) {
					$graphs = db_fetch_assoc("select
						graph_local.id as local_graph_id
						from graph_local
						where " . array_to_sql_or($selected_items, "graph_local.device_id"));

					if (sizeof($graphs) > 0) {
					foreach ($graphs as $graph) {
						$graphs_to_act_on[] = $graph["local_graph_id"];
					}
					}
				}

				$devices_to_act_on[] = $selected_items[$i];
			}

			switch (get_request_var_post("delete_type")) {
				case '1': /* leave graphs and data_sources in place, but disable the data sources */
					api_data_source_disable_multi($data_sources_to_act_on);

					break;
				case '2': /* delete graphs/data sources tied to this device */
					api_data_source_remove_multi($data_sources_to_act_on);

					api_graph_remove_multi($graphs_to_act_on);

					break;
			}

			api_device_remove_multi($devices_to_act_on);
		}elseif (preg_match("/^tr_([0-9]+)$/", get_request_var_post("drp_action"), $matches)) { /* place on tree */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				input_validate_input_number(get_request_var_post("tree_id"));
				input_validate_input_number(get_request_var_post("tree_item_id"));
				/* ==================================================== */

				api_tree_item_save(0, get_request_var_post("tree_id"), TREE_ITEM_TYPE_DEVICE, get_request_var_post("tree_item_id"), "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false);
			}
		} else {
			api_plugin_hook_function('device_action_execute', get_request_var_post('drp_action'));
		}

		header("Location: devices.php");
		exit;
	}

	/* setup some variables */
	$device_list = ""; $i = 0; $device_array = array();

	/* loop through each of the device templates selected on the previous page and get more info about them */
	while (list($var,$val) = each($_POST)) {
		if (preg_match("/^chk_([0-9]+)$/", $var, $matches)) {
			/* ================= input validation ================= */
			input_validate_input_number($matches[1]);
			/* ==================================================== */

			$device_list .= "<li>" . db_fetch_cell("select description from device where id=" . $matches[1]) . "<br>";
			$device_array[$i] = $matches[1];
		}

		$i++;
	}

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

	/* add a list of tree names to the actions dropdown */
	$device_actions = array_merge($device_actions, api_tree_add_tree_names_to_actions_array());

	$device_actions[ACTION_NONE] = __("None");

	print "<form method='post' action='" .  basename($_SERVER["PHP_SELF"]) . "' name='device_edit_actions'>\n";
	html_start_box("<strong>" . $device_actions{get_request_var_post("drp_action")} . "</strong>", "60", $colors["header_panel"], "3", "center", "");

	if (sizeof($device_array)) {
		if (get_request_var_post("drp_action") === ACTION_NONE) { /* NONE */
			print "	<tr>
						<td class='textArea'>
							<p>" . __("You did not select a valid action. Please select 'Return' to return to the previous menu.") . "</p>
						</td>
					</tr>\n";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_ENABLE) { /* Enable Devices */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To enable the following devices, press the \"yes\" button below.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_DISABLE) { /* Disable Devices */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To disable the following devices, press the \"yes\" button below.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_SNMP_OPTIONS) { /* change snmp options */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To change SNMP parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click \"yes\".") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";

			$form_array = array();
			while (list($field_name, $field_array) = each($fields_device_edit_availability)) {
				if (preg_match("/(^snmp_|max_oids)/", $field_name)) {
					$form_array += array($field_name => $fields_device_edit_availability[$field_name]);

					$form_array[$field_name]["value"] = "";
					$form_array[$field_name]["form_id"] = 0;
					$form_array[$field_name]["sub_checkbox"] = array(
						"name" => "t_" . $field_name,
						"friendly_name" => __("Update this Field"),
						"value" => ""
						);
				}
			}

			draw_edit_form(
				array(
					"config" => array("no_form_tag" => true),
					"fields" => $form_array
					)
				);
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_AVAILABILITY_OPTIONS) { /* change availability options */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To change availability parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click yes.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";

			$form_array = array();
			while (list($field_name, $field_array) = each($fields_device_edit_availability)) {
				if (!preg_match("/(^snmp_|max_oids)/", $field_name)) {
					$form_array += array($field_name => $fields_device_edit_availability[$field_name]);

					$form_array[$field_name]["value"] = "";
					$form_array[$field_name]["form_id"] = 0;
					$form_array[$field_name]["sub_checkbox"] = array(
						"name" => "t_" . $field_name,
						"friendly_name" => __("Update this Field"),
						"value" => ""
						);
				}
			}

			draw_edit_form(
				array(
					"config" => array("no_form_tag" => true),
					"fields" => $form_array
					)
				);
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CLEAR_STATISTICS) { /* Clear Statisitics for Selected Devices */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To clear the counters for the following devices, press the \"yes\" button below.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_DELETE) { /* delete */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("Are you sure you want to delete the following devices?") . "</p>
						<p>$device_list</p>";
						form_radio_button("delete_type", "2", "1", __("Leave all graphs and data sources untouched.  Data sources will be disabled however."), "1"); print "<br>";
						form_radio_button("delete_type", "2", "2", __("Delete all associated <strong>graphs</strong> and <strong>data sources</strong>."), "1"); print "<br>";
						print "</td></tr>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_POLLER) { /* Change Poller */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("Select the new poller below for the devices(s) below and select 'yes' to continue, or 'no' to return.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";

			$form_array = array();
			$field_name = "poller_id";
			$form_array += array($field_name => $fields_device_edit["poller_id"]);
			$form_array[$field_name]["description"] = __("Please select the new poller for the selected device(s).");

			draw_edit_form(
				array(
					"config" => array("no_form_tag" => true),
					"fields" => $form_array
					)
				);
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_SITE) { /* Change Site */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("Select the new site for the devices(s) below and select 'yes' to continue, or 'no' to return.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";

			$form_array = array();
			$field_name = "site_id";
			$form_array += array($field_name => $fields_device_edit["site_id"]);
			$form_array[$field_name]["description"] = __("Please select the new site for the selected device(s).");

			draw_edit_form(
				array(
					"config" => array("no_form_tag" => true),
					"fields" => $form_array
					)
				);
		}elseif (preg_match("/^tr_([0-9]+)$/", get_request_var_post("drp_action"), $matches)) { /* place on tree */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following devices will be placed under the branch selected below.") . "</p>
						<p>$device_list</p>
						<p><strong>" . __("Destination Branch:") . "</strong><br>"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "</p>
					</td>
				</tr>\n
				<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n
				";
		} else {
			$save['drp_action'] = $_POST['drp_action'];
			$save['device_list'] = $device_list;
			$save['device_array'] = (isset($device_array)? $device_array : array());
			api_plugin_hook_function('device_action_prepare', $save);
		}
	} else {
		print "	<tr>
				<td class='textArea'>
					<p>" . __("You must first select a Device.  Please select 'Return' to return to the previous menu.") . "</p>
				</td>
			</tr>\n";
	}

	if (!sizeof($device_array) || get_request_var_post("drp_action") === ACTION_NONE) {
		form_return_button_alt();
	}else{
		form_yesno_button_alt(serialize($device_array), get_request_var_post("drp_action"));
	}

	html_end_box();

	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}