function form_actions() { global $colors, $ds_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 */ if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; } switch ($_POST["delete_type"]) { case '2': /* delete all graph items tied to this data source */ $data_template_rrds = db_fetch_assoc("select id from data_template_rrd where " . array_to_sql_or($selected_items, "local_data_id")); /* loop through each data source item */ if (sizeof($data_template_rrds) > 0) { foreach ($data_template_rrds as $item) { db_execute("delete from graph_templates_item where task_item_id=" . $item["id"] . " and local_graph_id > 0"); } } break; case '3': /* delete all graphs tied to this data source */ $graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_templates_graph.local_graph_id\n\t\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "data_template_rrd.local_data_id") . "\n\t\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\t\tgroup by graph_templates_graph.local_graph_id"); if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { api_graph_remove($graph["local_graph_id"]); } } break; } for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ api_data_source_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("data_template_id")); /* ==================================================== */ change_data_template($selected_items[$i], $_POST["data_template_id"]); } } elseif ($_POST["drp_action"] == "3") { /* 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 data_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]); push_out_host($_POST["host_id"], $selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } elseif ($_POST["drp_action"] == "4") { /* duplicate */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ duplicate_data_source($selected_items[$i], 0, $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "5") { /* data source -> data template */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ data_source_to_data_template($selected_items[$i], $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "6") { /* data source enable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_enable($selected_items[$i]); } } elseif ($_POST["drp_action"] == "7") { /* data source disable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_disable($selected_items[$i]); } } header("Location: data_sources.php"); exit; } /* setup some variables */ $ds_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]); /* ==================================================== */ $ds_list .= "<li>" . get_data_source_title($matches[1]) . "<br>"; $ds_array[$i] = $matches[1]; } $i++; } include_once "./include/top_header.php"; html_start_box("<strong>" . $ds_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", ""); print "<form action='data_sources.php' method='post'>\n"; if ($_POST["drp_action"] == "1") { /* delete */ $graphs = array(); /* find out which (if any) graphs are using this data source, so we can tell the user */ if (isset($ds_array)) { $graphs = db_fetch_assoc("select\n\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\tand " . array_to_sql_or($ds_array, "data_template_rrd.local_data_id") . "\n\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\tgroup by graph_templates_graph.local_graph_id\n\t\t\t\torder by graph_templates_graph.title_cache"); } 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 data sources?</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t"; if (sizeof($graphs) > 0) { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>The following graphs are using these data sources:</p>\n"; foreach ($graphs as $graph) { print "<strong>" . $graph["title_cache"] . "</strong><br>\n"; } print "<br>"; form_radio_button("delete_type", "3", "1", "Leave the graphs untouched.", "1"); print "<br>"; form_radio_button("delete_type", "3", "2", "Delete all <strong>graph items</strong> that reference these data sources.", "1"); print "<br>"; form_radio_button("delete_type", "3", "3", "Delete all <strong>graphs</strong> that reference these data sources.", "1"); print "<br>"; print "</td></tr>"; } print "\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "2") { /* change graph template */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Choose a data template and click save to change the data template for\n\t\t\t\t\tthe following data souces. Be aware that all warnings will be suppressed during the\n\t\t\t\t\tconversion, so graph data loss is possible.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t<p><strong>New Data Template:</strong><br>"; form_dropdown("data_template_id", db_fetch_assoc("select data_template.id,data_template.name from data_template order by data_template.name"), "name", "id", "", "", "0"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "3") { /* change host */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Choose a new host for these data sources:</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t<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>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "4") { /* duplicate */ 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 data sources will be duplicated. You can\n\t\t\t\t\toptionally change the title format for the new data sources.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<ds_title> (1)", "", "255", "30", "text"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "5") { /* data source -> data template */ 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 data sources will be converted into data templates.\n\t\t\t\t\tYou can optionally change the title format for the new data templates.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<ds_title> Template", "", "255", "30", "text"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "6") { /* data source enable */ 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 yes, the following data sources will be enabled.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "7") { /* data source disable */ 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 yes, the following data sources will be disabled.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } if (!isset($ds_array)) { print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one data source.</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 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($ds_array) ? serialize($ds_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='data_sources.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"; }
function data_source_toggle_status() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (get_request_var("newstate") == 1) { api_data_source_enable(get_request_var("id")); }else{ cacti_log("Disabling Bad DS"); api_data_source_disable(get_request_var("id")); } header("Location: " . $_SERVER["HTTP_REFERER"]); exit; }
function form_actions() { global $ds_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 = sanitize_unserialize_selected_items($_POST['selected_items']); if ($selected_items != false) { if ($_POST["drp_action"] == "1") { /* delete */ if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; } switch ($_POST["delete_type"]) { case '2': /* delete all graph items tied to this data source */ $data_template_rrds = array_rekey(db_fetch_assoc("select id from data_template_rrd where " . array_to_sql_or($selected_items, "local_data_id")), "id", "id"); /* loop through each data source item */ if (sizeof($data_template_rrds) > 0) { db_execute("delete from graph_templates_item where task_item_id IN (" . implode(",", $data_template_rrds) . ") and local_graph_id > 0"); } api_plugin_hook_function('graph_items_remove', $data_template_rrds); break; case '3': /* delete all graphs tied to this data source */ $graphs = array_rekey(db_fetch_assoc("select\n\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "data_template_rrd.local_data_id") . "\n\t\t\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\t\t\tgroup by graph_templates_graph.local_graph_id"), "local_graph_id", "local_graph_id"); if (sizeof($graphs) > 0) { api_graph_remove_multi($graphs); } api_plugin_hook_function('graphs_remove', $graphs); break; } api_data_source_remove_multi($selected_items); api_plugin_hook_function('data_source_remove', $selected_items); } elseif ($_POST["drp_action"] == "2") { /* change graph template */ input_validate_input_number(get_request_var_post("data_template_id")); for ($i = 0; $i < count($selected_items); $i++) { change_data_template($selected_items[$i], $_POST["data_template_id"]); } } elseif ($_POST["drp_action"] == "3") { /* change host */ input_validate_input_number(get_request_var_post("host_id")); for ($i = 0; $i < count($selected_items); $i++) { db_execute("update data_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]); push_out_host($_POST["host_id"], $selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } elseif ($_POST["drp_action"] == "4") { /* duplicate */ for ($i = 0; $i < count($selected_items); $i++) { duplicate_data_source($selected_items[$i], 0, $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "5") { /* data source -> data template */ for ($i = 0; $i < count($selected_items); $i++) { data_source_to_data_template($selected_items[$i], $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "6") { /* data source enable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_enable($selected_items[$i]); } } elseif ($_POST["drp_action"] == "7") { /* data source disable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_disable($selected_items[$i]); } } elseif ($_POST["drp_action"] == "8") { /* reapply suggested data source naming */ for ($i = 0; $i < count($selected_items); $i++) { api_reapply_suggested_data_source_title($selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } else { api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']); } api_plugin_hook_function('data_source_action_bottom', array($_POST['drp_action'], $selected_items)); } header("Location: data_sources.php"); exit; } /* setup some variables */ $ds_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]); /* ==================================================== */ $ds_list .= "<li>" . htmlspecialchars(get_data_source_title($matches[1])) . "</li>"; $ds_array[$i] = $matches[1]; $i++; } } include_once "./include/top_header.php"; html_start_box("<strong>" . $ds_actions[$_POST["drp_action"]] . "</strong>", "60%", "", "3", "center", ""); print "<form action='data_sources.php' method='post'>\n"; if (isset($ds_array) && sizeof($ds_array)) { if ($_POST["drp_action"] == "1") { /* delete */ $graphs = array(); /* find out which (if any) graphs are using this data source, so we can tell the user */ if (isset($ds_array)) { $graphs = db_fetch_assoc("select\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\tand " . array_to_sql_or($ds_array, "data_template_rrd.local_data_id") . "\n\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\tgroup by graph_templates_graph.local_graph_id\n\t\t\t\t\torder by graph_templates_graph.title_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 Data Source(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>"; if (sizeof($graphs) > 0) { print "<tr><td class='textArea'><p class='textArea'>The following graphs are using these data sources:</p>\n"; print "<ul>"; foreach ($graphs as $graph) { print "<li><strong>" . $graph["title_cache"] . "</strong></li>\n"; } print "</ul>"; print "<br>"; form_radio_button("delete_type", "3", "1", "Leave the Graph(s) untouched.", "1"); print "<br>"; form_radio_button("delete_type", "3", "2", "Delete all <strong>Graph Item(s)</strong> that reference these Data Source(s).", "1"); print "<br>"; form_radio_button("delete_type", "3", "3", "Delete all <strong>Graph(s)</strong> that reference these Data Source(s).", "1"); 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()'> <input type='submit' value='Continue' title='Delete Data Source(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 Data Template and click \"Continue\" to change the Data Template for\n\t\t\t\t\t\tthe following Data Source(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>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Data Template:</strong><br>"; form_dropdown("data_template_id", db_fetch_assoc("select data_template.id,data_template.name from data_template order by data_template.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()'> <input type='submit' value='Continue' title='Change Graph Template for Data Source(s)'>"; } elseif ($_POST["drp_action"] == "3") { /* 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 Data Source(s) and click \"Continue\"</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<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>\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()'> <input type='submit' value='Continue' title='Change Device'>"; } elseif ($_POST["drp_action"] == "4") { /* 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 Data Source(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Data Source(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<ds_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()'> <input type='submit' value='Continue' title='Duplicate Data Source(s)'>"; } elseif ($_POST["drp_action"] == "5") { /* data source -> data 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 Data Source(s) will be converted into Data Template(s).\n\t\t\t\t\t\tYou can optionally change the title format for the new Data Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<ds_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()'> <input type='submit' value='Continue' title='Convert Data Source(s) to Data Template(s)'>"; } elseif ($_POST["drp_action"] == "6") { /* data source enable */ 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 Data Source(s) will be enabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_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()'> <input type='submit' value='Continue' title='Enable Data Source(s)'>"; } elseif ($_POST["drp_action"] == "7") { /* data source disable */ 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 Data Source(s) will be disabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_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()'> <input type='submit' value='Continue' title='Disable Data Source(s)'>"; } elseif ($_POST["drp_action"] == "8") { /* reapply suggested data source naming */ 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 Data Source(s) will will have there suggested naming convention\n\t\t\t\t\t\trecalculated.</p>\n\t\t\t\t\t\t<p><ul>{$ds_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()'> <input type='submit' value='Continue' title='Reapply Suggested Naming to Data Source(s)'>"; } else { $save['drp_action'] = $_POST['drp_action']; $save['ds_list'] = $ds_list; $save['ds_array'] = isset($ds_array) ? $ds_array : array(); api_plugin_hook_function('data_source_action_prepare', $save); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue'>"; } } else { print "<tr><td class='even'><span class='textError'>You must select at least one data source.</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($ds_array) ? serialize($ds_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(); include_once "./include/bottom_footer.php"; }
function form_actions() { global $ds_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; } switch ($_POST['delete_type']) { case '2': /* delete all graph items tied to this data source */ $data_template_rrds = array_rekey(db_fetch_assoc('SELECT id FROM data_template_rrd WHERE ' . array_to_sql_or($selected_items, 'local_data_id')), 'id', 'id'); /* loop through each data source item */ if (sizeof($data_template_rrds) > 0) { db_execute('DELETE FROM graph_templates_item WHERE task_item_id IN (' . implode(',', $data_template_rrds) . ') and local_graph_id > 0'); } api_plugin_hook_function('graph_items_remove', $data_template_rrds); break; case '3': /* delete all graphs tied to this data source */ $graphs = array_rekey(db_fetch_assoc('SELECT graph_templates_graph.local_graph_id FROM (data_template_rrd,graph_templates_item,graph_templates_graph) WHERE graph_templates_item.task_item_id=data_template_rrd.id AND graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id AND ' . array_to_sql_or($selected_items, 'data_template_rrd.local_data_id') . ' AND graph_templates_graph.local_graph_id > 0 GROUP BY graph_templates_graph.local_graph_id'), 'local_graph_id', 'local_graph_id'); if (sizeof($graphs) > 0) { api_graph_remove_multi($graphs); } api_plugin_hook_function('graphs_remove', $graphs); break; } for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ } api_data_source_remove_multi($selected_items); api_plugin_hook_function('data_source_remove', $selected_items); } 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('data_template_id')); /* ==================================================== */ change_data_template($selected_items[$i], $_POST['data_template_id']); } } elseif ($_POST['drp_action'] == '3') { /* 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_prepared('UPDATE data_local SET host_id = ? WHERE id = ?', array($_POST['host_id'], $selected_items[$i])); push_out_host($_POST['host_id'], $selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } elseif ($_POST['drp_action'] == '4') { /* duplicate */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ duplicate_data_source($selected_items[$i], 0, $_POST['title_format']); } } elseif ($_POST['drp_action'] == '5') { /* data source -> data template */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ data_source_to_data_template($selected_items[$i], $_POST['title_format']); } } elseif ($_POST['drp_action'] == '6') { /* data source enable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_enable($selected_items[$i]); } } elseif ($_POST['drp_action'] == '7') { /* data source disable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_disable($selected_items[$i]); } } elseif ($_POST['drp_action'] == '8') { /* reapply suggested data source naming */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ api_reapply_suggested_data_source_title($selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } else { api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']); } /* update snmpcache */ snmpagent_data_source_action_bottom(array($_POST['drp_action'], $selected_items)); api_plugin_hook_function('data_source_action_bottom', array($_POST['drp_action'], $selected_items)); header('Location: data_sources.php'); exit; } /* setup some variables */ $ds_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]); /* ==================================================== */ $ds_list .= '<li>' . htmlspecialchars(get_data_source_title($matches[1])) . '<br>'; $ds_array[$i] = $matches[1]; $i++; } } top_header(); html_start_box('<strong>' . $ds_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', ''); print "<form action='data_sources.php' method='post'>\n"; if (isset($ds_array) && sizeof($ds_array)) { if ($_POST['drp_action'] == '1') { /* delete */ $graphs = array(); /* find out which (if any) graphs are using this data source, so we can tell the user */ if (isset($ds_array)) { $graphs = db_fetch_assoc('SELECT graph_templates_graph.local_graph_id, graph_templates_graph.title_cache FROM (data_template_rrd,graph_templates_item,graph_templates_graph) WHERE graph_templates_item.task_item_id=data_template_rrd.id AND graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id AND ' . array_to_sql_or($ds_array, 'data_template_rrd.local_data_id') . ' AND graph_templates_graph.local_graph_id > 0 GROUP BY graph_templates_graph.local_graph_id ORDER BY graph_templates_graph.title_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 Data Source(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>"; if (sizeof($graphs) > 0) { print "<tr><td class='textArea'><p class='textArea'>The following graphs are using these data sources:</p>\n"; print '<ul>'; foreach ($graphs as $graph) { print '<li><strong>' . $graph['title_cache'] . "</strong></li>\n"; } print '</ul>'; print '<br>'; form_radio_button('delete_type', '3', '1', 'Leave the Graph(s) untouched.', '1'); print '<br>'; form_radio_button('delete_type', '3', '2', 'Delete all <strong>Graph Item(s)</strong> that reference these Data Source(s).', '1'); print '<br>'; form_radio_button('delete_type', '3', '3', 'Delete all <strong>Graph(s)</strong> that reference these Data Source(s).', '1'); 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()'> <input type='submit' value='Continue' title='Delete Data Source(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 Data Template and click \"Continue\" to change the Data Template for\n\t\t\t\t\t\tthe following Data Source(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>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Data Template:</strong><br>"; form_dropdown('data_template_id', db_fetch_assoc('SELECT data_template.id,data_template.name FROM data_template ORDER BY data_template.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()'> <input type='submit' value='Continue' title='Change Graph Template for Data Source(s)'>"; } elseif ($_POST['drp_action'] == '3') { /* 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 Data Source(s) and click \"Continue\"</p>\n\t\t\t\t\t\t<p><ul>{$ds_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()'> <input type='submit' value='Continue' title='Change Device'>"; } elseif ($_POST['drp_action'] == '4') { /* 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 Data Source(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Data Source(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box('title_format', '<ds_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()'> <input type='submit' value='Continue' title='Duplicate Data Source(s)'>"; } elseif ($_POST['drp_action'] == '5') { /* data source -> data 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 Data Source(s) will be converted into Data Template(s).\n\t\t\t\t\t\tYou can optionally change the title format for the new Data Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box('title_format', '<ds_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()'> <input type='submit' value='Continue' title='Convert Data Source(s) to Data Template(s)'>"; } elseif ($_POST['drp_action'] == '6') { /* data source enable */ 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 Data Source(s) will be enabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_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()'> <input type='submit' value='Continue' title='Enable Data Source(s)'>"; } elseif ($_POST['drp_action'] == '7') { /* data source disable */ 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 Data Source(s) will be disabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_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()'> <input type='submit' value='Continue' title='Disable Data Source(s)'>"; } elseif ($_POST['drp_action'] == '8') { /* reapply suggested data source naming */ 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 Data Source(s) will will have there suggested naming convention\n\t\t\t\t\t\trecalculated.</p>\n\t\t\t\t\t\t<p><ul>{$ds_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()'> <input type='submit' value='Continue' title='Reapply Suggested Naming to Data Source(s)'>"; } else { $save['drp_action'] = $_POST['drp_action']; $save['ds_list'] = $ds_list; $save['ds_array'] = isset($ds_array) ? $ds_array : array(); api_plugin_hook_function('data_source_action_prepare', $save); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue'>"; } } else { print "<tr><td class='even'><span class='textError'>You must select at least one data source.</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($ds_array) ? serialize($ds_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(); }