本文整理汇总了PHP中array_to_sql_or函数的典型用法代码示例。如果您正苦于以下问题:PHP array_to_sql_or函数的具体用法?PHP array_to_sql_or怎么用?PHP array_to_sql_or使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_to_sql_or函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mikrotik_view_graphs
//.........这里部分代码省略.........
load_current_session_value("filter", "sess_mikrotik_graph_filter", "");
load_current_session_value("page", "sess_mikrotik_graph_current_page", "1");
if ($_REQUEST["graph_add"] != "") {
$_REQUEST["style"] = "selective";
}
/* graph permissions */
if (read_config_option("auth_method") != 0) {
$sql_where = "WHERE " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
$sql_join = "LEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\tLEFT JOIN graph_templates\n\t\t\tON (graph_templates.id=graph_local.graph_template_id)\n\t\t\tLEFT JOIN user_auth_perms\n\t\t\tON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id\n\t\t\tAND user_auth_perms.type=1\n\t\t\tAND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
} else {
$sql_where = "";
$sql_join = "";
}
/* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
if (isset($_REQUEST["style"])) {
if ($_REQUEST["style"] == "selective") {
/* process selected graphs */
if (!empty($_REQUEST["graph_list"])) {
foreach (explode(",", $_REQUEST["graph_list"]) as $item) {
$graph_list[$item] = 1;
}
} else {
$graph_list = array();
}
if (!empty($_REQUEST["graph_add"])) {
foreach (explode(",", $_REQUEST["graph_add"]) as $item) {
$graph_list[$item] = 1;
}
}
/* remove items */
if (!empty($_REQUEST["graph_remove"])) {
foreach (explode(",", $_REQUEST["graph_remove"]) as $item) {
unset($graph_list[$item]);
}
}
$i = 0;
foreach ($graph_list as $item => $value) {
$graph_array[$i] = $item;
$i++;
}
if (isset($graph_array) && sizeof($graph_array) > 0) {
/* build sql string including each graph the user checked */
$sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");
/* clear the filter vars so they don't affect our results */
$_REQUEST["filter"] = "";
$set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
}
}
}
$sql_base = "FROM (graph_templates_graph,graph_local)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\t" . (empty($sql_where) ? "WHERE" : "AND") . " graph_templates_graph.local_graph_id > 0\n\t\tAND graph_templates_graph.local_graph_id=graph_local.id\n\t\t" . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" : "") . "\n\t\t" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "\n\t\t" . (empty($_REQUEST["host"]) ? "" : " and graph_local.host_id=" . $_REQUEST["host"]) . "\n\t\t{$sql_or}";
$total_rows = count(db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id\n\t\t{$sql_base}"));
/* reset the page if you have changed some settings */
if (ROWS_PER_PAGE * ($_REQUEST["page"] - 1) >= $total_rows) {
$_REQUEST["page"] = "1";
}
$graphs = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.title_cache\n\t\t{$sql_base}\n\t\tGROUP BY graph_templates_graph.local_graph_id\n\t\tORDER BY graph_templates_graph.title_cache\n\t\tLIMIT " . ROWS_PER_PAGE * ($_REQUEST["page"] - 1) . "," . ROWS_PER_PAGE);
?>
<script type="text/javascript">
<!--
function applyGraphWReset(objForm) {
strURL = '?action=graphs&reset=1&graph_template_id=' + objForm.graph_template_id.value;
strURL = strURL + '&host=' + objForm.host.value;
strURL = strURL + '&cols=' + objForm.cols.value;
strURL = strURL + '&thumb=' + objForm.thumb.checked;
strURL = strURL + '&filter=' + objForm.filter.value;
document.location = strURL;
}
function applyGraphWOReset(objForm) {
strURL = '?action=graphs&graph_template_id=' + objForm.graph_template_id.value;
strURL = strURL + '&host=' + objForm.host.value;
strURL = strURL + '&cols=' + objForm.cols.value;
strURL = strURL + '&thumb=' + objForm.thumb.checked;
strURL = strURL + '&filter=' + objForm.filter.value;
document.location = strURL;
}
-->
</script>
<?php
html_start_box("<strong>Host MIB Graphs" . ($_REQUEST["style"] == "selective" ? " (Custom Selective Filter)" : "") . "</strong>", "100%", $colors["header"], "1", "center", "");
mikrotik_graph_view_filter();
/* include time span selector */
if (read_graph_config_option("timespan_sel") == "on") {
mikrotik_timespan_selector();
}
html_end_box();
/* do some fancy navigation url construction so we don't have to try and rebuild the url string */
if (ereg("page=[0-9]+", basename($_SERVER["QUERY_STRING"]))) {
$nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]);
} else {
$nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>";
}
$nav_url = ereg_replace("((\\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url);
html_start_box("", "100%", $colors["header"], "3", "center", "");
mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
mikrotik_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "", $_REQUEST["cols"], $_REQUEST["thumb"]);
if ($total_rows) {
mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
}
html_end_box();
}
示例2: form_actions
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 */
$data_template_datas = db_fetch_assoc("select id from data_template_data where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
if (sizeof($data_template_datas) > 0) {
foreach ($data_template_datas as $data_template_data) {
db_execute("delete from data_template_data_rra where data_template_data_id=" . $data_template_data["id"]);
}
}
db_execute("delete from data_template_data where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
db_execute("delete from data_template_rrd where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
db_execute("delete from snmp_query_graph_rrd where " . array_to_sql_or($selected_items, "data_template_id"));
db_execute("delete from snmp_query_graph_rrd_sv where " . array_to_sql_or($selected_items, "data_template_id"));
db_execute("delete from data_template where " . array_to_sql_or($selected_items, "id"));
/* "undo" any graph that is currently using this template */
db_execute("update data_template_data set local_data_template_data_id=0,data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
db_execute("update data_template_rrd set local_data_template_rrd_id=0,data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
db_execute("update data_local set data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
} elseif ($_POST["drp_action"] == "2") {
/* duplicate */
for ($i = 0; $i < count($selected_items); $i++) {
duplicate_data_source(0, $selected_items[$i], $_POST["title_format"]);
}
}
}
header("Location: data_templates.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(db_fetch_cell("select name from data_template where id=" . $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_templates.php' method='post'>\n";
if (isset($ds_array) && sizeof($ds_array)) {
if ($_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 Data Template(s) will be deleted. Any data sources attached\n\t\t\t\t\t\tto these templates will become individual Data Source(s) and all Templating benefits will be removed.</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='Delete Data Template(s)'>";
} elseif ($_POST["drp_action"] == "2") {
/* 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 Template(s) will be duplicated. You can\n\t\t\t\t\t\toptionally 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", "<template_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 Template(s)'>";
}
} else {
print "<tr><td class='even'><span class='textError'>You must select at least one data template.</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";
}
示例3: form_actions
//.........这里部分代码省略.........
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>
示例4: form_actions
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++) {
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++) {
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++) {
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++) {
db_execute("update host 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 ($_POST["drp_action"] == "1") { /* delete */
for ($i=0; $i<count($selected_items); $i++) {
if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; }
switch ($_POST["delete_type"]) {
case '2': /* delete graphs/data sources tied to this device */
$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) {
api_data_source_remove($data_source["local_data_id"]);
}
}
$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) {
api_graph_remove($graph["local_graph_id"]);
}
}
break;
}
api_device_remove($selected_items[$i]);
}
}
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)) {
$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");
html_start_box("<strong>" . $device_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
//.........这里部分代码省略.........
示例5: form_actions
function form_actions()
{
global $host_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 */
db_execute('DELETE FROM host_template WHERE ' . array_to_sql_or($selected_items, 'id'));
db_execute('DELETE FROM host_template_snmp_query WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
db_execute('DELETE FROM host_template_graph WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
/* "undo" any device that is currently using this template */
db_execute('UPDATE host SET host_template_id=0 WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
} elseif ($_POST['drp_action'] == '2') {
/* duplicate */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
duplicate_host_template($selected_items[$i], $_POST['title_format']);
}
}
header('Location: host_templates.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 name FROM host_template WHERE id = ?'), array($matches[1])) . '<br>';
$host_array[$i] = $matches[1];
$i++;
}
}
top_header();
html_start_box('<strong>' . $host_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
print "<form action='host_templates.php' autocomplete='off' method='post'>\n";
if (isset($host_array) && sizeof($host_array)) {
if ($_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>Are you sure you want to delete the following Device Template(s)? All Devices currently associated\n\t\t\t\t\t\twith these Device Template(s) will lose that assocation.</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</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 Device Template(s)'>";
} elseif ($_POST['drp_action'] == '2') {
/* 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 Device Template(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Device Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$host_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
form_text_box('title_format', '<template_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 Device Template(s)'>";
}
} else {
print "<tr><td class='even'><span class='textError'>You must select at least one host template.</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($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();
}
示例6: form_actions
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") {
//.........这里部分代码省略.........
示例7: form_actions
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);
//.........这里部分代码省略.........
示例8: export_colors
function export_colors() {
if (isset($_REQUEST["selectedColors"]) && strlen($_REQUEST["selectedColors"])) {
$selected_items = explode(",", $_REQUEST["selectedColors"]);
if (is_array($selected_items)) {
foreach($selected_items as $color_hex) {
/* clean up color_id string */
$color_hex = sanitize_search_string($color_hex);
$color_hexes[] = $color_hex;
}
}
}else{
$message = "<i>You need to select the colors that you want for export before you may export them</i>\n";
$_SESSION['sess_message_color_ref_int'] = array('message' => "<font size=-2>$message</font>", 'type' => 'info');
raise_message('color_ref_int');
header("Location: color.php");
exit;
}
$colors = db_fetch_assoc("SELECT * FROM colors WHERE " . array_to_sql_or($color_hexes, "hex"));
$xport_array = array();
array_push($xport_array, '"id","hex"');
if (sizeof($colors)) {
foreach($colors as $color) {
array_push($xport_array,'"' . $color['id'] . '","' . $color['hex'] . '"');
}
}
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=cacti_colors_xport.csv");
if (sizeof($xport_array)) {
foreach($xport_array as $xport_line) {
print $xport_line . "\n";
}
}
}
示例9: data_source_form_actions
function data_source_form_actions() {
global $colors;
require(CACTI_BASE_PATH . "/include/data_source/data_source_arrays.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") === DS_ACTION_DELETE) { /* delete */
if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; }
switch (get_request_var_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
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");
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 (get_request_var_post("drp_action") === DS_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("data_template_id"));
/* ==================================================== */
change_data_template($selected_items[$i], get_request_var_post("data_template_id"));
}
}elseif (get_request_var_post("drp_action") === DS_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 data_local set device_id=" . $_POST["device_id"] . " where id=" . $selected_items[$i]);
push_out_device(get_request_var_post("device_id"), $selected_items[$i]);
update_data_source_title_cache($selected_items[$i]);
}
}elseif (get_request_var_post("drp_action") === DS_ACTION_DUPLICATE) { /* 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, get_request_var_post("title_format"));
}
}elseif (get_request_var_post("drp_action") === DS_ACTION_CONVERT_TO_TEMPLATE) { /* 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], get_request_var_post("title_format"));
}
}elseif (get_request_var_post("drp_action") === DS_ACTION_ENABLE) { /* data source enable */
for ($i=0;($i<count($selected_items));$i++) {
api_data_source_enable($selected_items[$i]);
}
}elseif (get_request_var_post("drp_action") === DS_ACTION_DISABLE) { /* data source disable */
for ($i=0;($i<count($selected_items));$i++) {
api_data_source_disable($selected_items[$i]);
}
}elseif (get_request_var_post("drp_action") === DS_ACTION_REAPPLY_SUGGESTED_NAMES) { /* 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]);
//.........这里部分代码省略.........
示例10: cleanup_ds_and_graphs
function cleanup_ds_and_graphs()
{
global $config;
include_once $config['library_path'] . '/rrd.php';
include_once $config['library_path'] . '/utility.php';
include_once $config['library_path'] . '/api_graph.php';
include_once $config['library_path'] . '/api_data_source.php';
include_once $config['library_path'] . '/functions.php';
$remove_ldis = array();
$remove_lgis = array();
cacti_log('RRDClean now cleans up all data sources and graphs', true, 'MAINT');
//fetch all local_data_id's which have appropriate data-sources
$rrds = db_fetch_assoc("SELECT local_data_id, name_cache, data_source_path \n\t\tFROM data_template_data \n\t\tWHERE name_cache > ''");
//filter those whose rrd files doesn't exist
foreach ($rrds as $item) {
$ldi = $item['local_data_id'];
$name = $item['name_cache'];
$ds_pth = $item['data_source_path'];
$real_pth = str_replace('<path_rra>', $config['rra_path'], $ds_pth);
if (!file_exists($real_pth)) {
if (!in_array($ldi, $remove_ldis)) {
$remove_ldis[] = $ldi;
cacti_log("RRD file is missing for data source name: {$name} (local_data_id={$ldi})", true, 'MAINT');
}
}
}
if (empty($remove_ldis)) {
cacti_log('No missing rrd files found', true, 'MAINT');
return 0;
}
cacti_log('Processing Graphs', true, 'MAINT');
//fetch all local_graph_id's according to filtered rrds
$lgis = db_fetch_assoc('SELECT DISTINCT gl.id
FROM graph_local AS gl
INNER JOIN graph_templates_item AS gti
ON gl.id=gti.local_graph_id
INNER JOIN data_template_rrd AS dtr
ON dtr.id=gti.task_item_id
INNER JOIN data_local AS dl
ON dtr.local_data_id=dl.id
WHERE (' . array_to_sql_or($remove_ldis, 'local_data_id') . ')');
foreach ($lgis as $item) {
$remove_lgis[] = $item['id'];
cacti_log('RRD file missing for local_graph_id=' . $item['id'], true, 'MAINT');
}
if (!empty($remove_lgis)) {
cacti_log('removing graphs', true, 'MAINT');
api_graph_remove_multi($remove_lgis);
}
cacti_log('removing data sources', true, 'MAINT');
api_data_source_remove_multi($remove_ldis);
cacti_log('removed graphs:' . count($remove_lgis) . ' removed data-sources:' . count($remove_ldis), true, 'MAINT');
}
示例11: form_actions
function form_actions()
{
global $colors, $actions, $assoc_actions;
/* if we are to save this form, instead of display it */
if (isset($_POST["selected_items"])) {
if (isset($_POST["save_list"])) {
$selected_items = unserialize(stripslashes($_POST["selected_items"]));
if ($_POST["drp_action"] == "1") {
/* delete */
db_execute("DELETE FROM plugin_notification_lists WHERE " . array_to_sql_or($selected_items, "id"));
db_execute("UPDATE host SET thold_send_email=0 WHERE thold_send_email=2 AND " . array_to_sql_or($selected_items, "thold_host_email"));
db_execute("UPDATE host SET thold_send_email=1 WHERE thold_send_email=3 AND " . array_to_sql_or($selected_items, "thold_host_email"));
db_execute("UPDATE host SET thold_host_email=0 WHERE " . array_to_sql_or($selected_items, "thold_host_email"));
db_execute("UPDATE host SET thold_send_sms=0 WHERE thold_send_sms=2 AND " . array_to_sql_or($selected_items, "thold_host_phone"));
db_execute("UPDATE host SET thold_send_sms=1 WHERE thold_send_sms=3 AND " . array_to_sql_or($selected_items, "thold_host_phone"));
db_execute("UPDATE host SET thold_host_phone=0 WHERE " . array_to_sql_or($selected_items, "thold_host_phone"));
} elseif ($_POST["drp_action"] == "2") {
/* duplicate */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
}
}
header("Location: notify_lists.php");
exit;
} elseif (isset($_POST["save_associate"])) {
$selected_items = unserialize(stripslashes($_POST["selected_items"]));
input_validate_input_number(get_request_var_request('notification_action'));
if ($_POST["drp_action"] == "1") {
/* associate */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
/* set the notification list */
db_execute("UPDATE host SET thold_host_email=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
/* set the global/list election */
db_execute("UPDATE host SET thold_send_email=" . get_request_var_request("notification_action") . " WHERE id=" . $selected_items[$i]);
db_execute("UPDATE host SET thold_host_phone=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
/* set the global/list election */
db_execute("UPDATE host SET thold_send_sms=" . get_request_var_request("notification_action") . " WHERE id=" . $selected_items[$i]);
}
} elseif ($_POST["drp_action"] == "2") {
/* disassociate */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
/* set the notification list */
db_execute("UPDATE host SET thold_host_email=0 WHERE id=" . $selected_items[$i]);
/* set the global/list election */
db_execute("UPDATE host SET thold_send_email=" . get_request_var_request("notification_action") . " WHERE id=" . $selected_items[$i]);
/* set the notification list */
db_execute("UPDATE host SET thold_host_phone=0 WHERE id=" . $selected_items[$i]);
/* set the global/list election */
db_execute("UPDATE host SET thold_send_sms=" . get_request_var_request("notification_action") . " WHERE id=" . $selected_items[$i]);
}
}
header("Location: notify_lists.php?action=edit&tab=hosts&id=" . get_request_var_request("id"));
exit;
} elseif (isset($_POST["save_templates"])) {
$selected_items = unserialize(stripslashes($_POST["selected_items"]));
input_validate_input_number(get_request_var_request('notification_action'));
if ($_POST["drp_action"] == "1") {
/* associate */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
if ($_POST["notification_warning_action"] > 0) {
/* clear other settings */
if ($_POST["notification_warning_action"] == 1) {
/* set the notification list */
db_execute("UPDATE thold_template SET notify_warning=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
/* clear other items */
db_execute("UPDATE thold_template SET notify_warning_extra='' WHERE id=" . $selected_items[$i]);
db_execute("UPDATE thold_template SET warning_phones_extra='' WHERE id=" . $selected_items[$i]);
} else {
/* set the notification list */
db_execute("UPDATE thold_template SET notify_warning=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
}
}
if ($_POST["notification_alert_action"] > 0) {
/* clear other settings */
if ($_POST["notification_alert_action"] == 1) {
/* set the notification list */
db_execute("UPDATE thold_template SET notify_alert=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
/* clear other items */
db_execute("UPDATE thold_template SET notify_extra='' WHERE id=" . $selected_items[$i]);
db_execute("UPDATE thold_template SET alert_phones_extra='' WHERE id=" . $selected_items[$i]);
db_execute("DELETE FROM plugin_thold_template_contact WHERE template_id=" . $selected_items[$i]);
} else {
/* set the notification list */
db_execute("UPDATE thold_template SET notify_alert=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
}
}
}
} elseif ($_POST["drp_action"] == "2") {
/* disassociate */
//.........这里部分代码省略.........
示例12: form_actions
function form_actions()
{
global $actions, $assoc_actions;
/* ================= input validation ================= */
get_filter_request_var('drp_action');
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
if (isset_request_var('save_list')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_request_var('drp_action') == '1') {
/* delete */
db_execute('DELETE FROM plugin_notification_lists WHERE ' . array_to_sql_or($selected_items, 'id'));
db_execute('UPDATE host SET thold_send_email=0 WHERE thold_send_email=2 AND ' . array_to_sql_or($selected_items, 'thold_host_email'));
db_execute('UPDATE host SET thold_send_email=1 WHERE thold_send_email=3 AND ' . array_to_sql_or($selected_items, 'thold_host_email'));
db_execute('UPDATE host SET thold_host_email=0 WHERE ' . array_to_sql_or($selected_items, 'thold_host_email'));
} elseif (get_request_var('drp_action') == '2') {
/* duplicate */
// To Do
}
}
header('Location: notify_lists.php?header=false');
exit;
} elseif (isset_request_var('save_associate')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
get_filter_request_var('notification_action');
if (get_request_var('drp_action') == '1') {
/* associate */
for ($i = 0; $i < count($selected_items); $i++) {
/* set the notification list */
db_execute('UPDATE host SET thold_host_email=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
/* set the global/list election */
db_execute('UPDATE host SET thold_send_email=' . get_request_var('notification_action') . ' WHERE id=' . $selected_items[$i]);
}
} elseif (get_request_var('drp_action') == '2') {
/* disassociate */
for ($i = 0; $i < count($selected_items); $i++) {
/* set the notification list */
db_execute('UPDATE host SET thold_host_email=0 WHERE id=' . $selected_items[$i]);
/* set the global/list election */
db_execute('UPDATE host SET thold_send_email=' . get_request_var('notification_action') . ' WHERE id=' . $selected_items[$i]);
}
}
}
header('Location: notify_lists.php?header=false&action=edit&tab=hosts&id=' . get_request_var('id'));
exit;
} elseif (isset_request_var('save_templates')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
get_filter_request_var('notification_action');
if (get_request_var('drp_action') == '1') {
/* associate */
for ($i = 0; $i < count($selected_items); $i++) {
if (get_request_var('notification_warning_action') > 0) {
/* clear other settings */
if (get_request_var('notification_warning_action') == 1) {
/* set the notification list */
db_execute('UPDATE thold_template SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
/* clear other items */
db_execute("UPDATE thold_template SET notify_warning_extra='' WHERE id=" . $selected_items[$i]);
} else {
/* set the notification list */
db_execute('UPDATE thold_template SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
}
}
if (get_request_var('notification_alert_action') > 0) {
/* clear other settings */
if (get_request_var('notification_alert_action') == 1) {
/* set the notification list */
db_execute('UPDATE thold_template SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
/* clear other items */
db_execute("UPDATE thold_template SET notify_extra='' WHERE id=" . $selected_items[$i]);
db_execute('DELETE FROM plugin_thold_template_contact WHERE template_id=' . $selected_items[$i]);
} else {
/* set the notification list */
db_execute('UPDATE thold_template SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
}
}
}
} elseif (get_request_var('drp_action') == '2') {
/* disassociate */
for ($i = 0; $i < count($selected_items); $i++) {
if (get_request_var('notification_warning_action') > 0) {
/* set the notification list */
db_execute('UPDATE thold_template SET notify_warning=0 WHERE id=' . $selected_items[$i] . ' AND notify_warning=' . get_request_var('id'));
}
if (get_request_var('notification_alert_action') > 0) {
/* set the notification list */
db_execute('UPDATE thold_template SET notify_alert=0 WHERE id=' . $selected_items[$i] . ' AND notify_alert=' . get_request_var('id'));
}
}
}
}
header('Location: notify_lists.php?header=false&action=edit&tab=templates&id=' . get_request_var('id'));
exit;
} elseif (isset_request_var('save_tholds')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
//.........这里部分代码省略.........
示例13: form_actions
function form_actions()
{
global $colors, $host_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 */
db_execute("delete from host_template where " . array_to_sql_or($selected_items, "id"));
db_execute("delete from host_template_snmp_query where " . array_to_sql_or($selected_items, "host_template_id"));
db_execute("delete from host_template_graph where " . array_to_sql_or($selected_items, "host_template_id"));
/* "undo" any device that is currently using this template */
db_execute("update host set host_template_id=0 where " . array_to_sql_or($selected_items, "host_template_id"));
} elseif ($_POST["drp_action"] == "2") {
/* duplicate */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
duplicate_host_template($selected_items[$i], $_POST["title_format"]);
}
}
header("Location: host_templates.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>" . db_fetch_cell("select name from host_template where id=" . $matches[1]) . "<br>";
$host_array[$i] = $matches[1];
$i++;
}
}
include_once "./include/top_header.php";
html_start_box("<strong>" . $host_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
print "<form action='host_templates.php' autocomplete='off' method='post'>\n";
if (isset($host_array) && sizeof($host_array)) {
if ($_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>Are you sure you want to delete the following Host Template(s)? All Devices currently associated\r\n\t\t\t\t\t\twith these Host Template(s) will lose that assocation.</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</tr>\n\r\n\t\t\t\t";
$save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Delete Host Template(s)'>";
} elseif ($_POST["drp_action"] == "2") {
/* 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 Host Template(s) will be duplicated. You can\r\n\t\t\t\t\t\toptionally change the title format for the new Host Template(s).</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>Title Format:</strong><br>";
form_text_box("title_format", "<template_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()'> <input type='submit' value='Continue' title='Duplicate Host Template(s)'>";
}
} else {
print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one host template.</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($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";
}
示例14: mikrotik_view_graphs
function mikrotik_view_graphs()
{
global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes;
include './lib/timespan_settings.php';
include './lib/html_graph.php';
html_graph_validate_preview_request_vars();
/* include graph view filter selector */
html_start_box('<strong>Graph Preview Filters</strong>' . (isset($_REQUEST['style']) && strlen($_REQUEST['style']) ? ' [ Custom Graph List Applied - Filtering from List ]' : ''), '100%', '', '3', 'center', '');
html_graph_preview_filter('mikrotik.php', 'graphs', 'ht.hash IN ("' . implode('","', $host_template_hashes) . '")', 'gt.hash IN ("' . implode('","', $graph_template_hashes) . '")');
html_end_box();
/* the user select a bunch of graphs of the 'list' view and wants them displayed here */
$sql_or = '';
if (isset($_REQUEST['style'])) {
if (get_request_var_request('style') == 'selective') {
/* process selected graphs */
if (!empty($_REQUEST['graph_list'])) {
foreach (explode(',', $_REQUEST['graph_list']) as $item) {
$graph_list[$item] = 1;
}
} else {
$graph_list = array();
}
if (!empty($_REQUEST['graph_add'])) {
foreach (explode(',', $_REQUEST['graph_add']) as $item) {
$graph_list[$item] = 1;
}
}
/* remove items */
if (!empty($_REQUEST['graph_remove'])) {
foreach (explode(',', $_REQUEST['graph_remove']) as $item) {
unset($graph_list[$item]);
}
}
$i = 0;
foreach ($graph_list as $item => $value) {
$graph_array[$i] = $item;
$i++;
}
if (isset($graph_array) && sizeof($graph_array) > 0) {
/* build sql string including each graph the user checked */
$sql_or = array_to_sql_or($graph_array, 'gtg.local_graph_id');
$set_rra_id = empty($rra_id) ? read_graph_config_option('default_rra_id') : get_request_var_request('rra_id');
}
}
}
$total_graphs = 0;
// Filter sql_where
$sql_where = strlen($_REQUEST['filter']) ? "gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%'" : '';
$sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or;
// Host Id sql_where
if ($_REQUEST['host_id'] > 0) {
$sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . $_REQUEST['host_id'];
} else {
$host_ids = mikrotik_host_ids_from_hashes($host_template_hashes);
if (sizeof($host_ids)) {
$sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id IN (' . implode(',', $host_ids) . ')';
} else {
$sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
}
}
// Graph Template Id sql_where
if ($_REQUEST['graph_template_id'] > 0) {
$sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . $_REQUEST['graph_template_id'];
} else {
$graph_template_ids = mikrotik_graph_templates_from_hashes($graph_template_hashes);
if (sizeof($graph_template_ids)) {
$sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN (' . implode(',', $graph_template_ids) . ')';
} else {
$sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
}
}
$limit = $_REQUEST['graphs'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['graphs'];
$order = 'gtg.title_cache';
$graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs);
/* do some fancy navigation url construction so we don't have to try and rebuild the url string */
if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
$nav_url = str_replace('&page=' . get_request_var_request('page'), '', get_browser_query_string());
} else {
$nav_url = get_browser_query_string() . '&host_id=' . get_request_var_request('host_id');
}
$nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
html_start_box('', '100%', '', '3', 'center', '');
$nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('graphs'), $total_graphs, get_request_var_request('columns'), 'Graphs', 'page', 'main');
print $nav;
if (get_request_var_request('thumbnails') == 'true') {
html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
} else {
html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
}
if ($total_graphs > 0) {
print $nav;
}
html_end_box();
bottom_footer();
}
示例15: form_actions
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++) {
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 distinct\n\t\t\t\t\t\t\tdata_source.id\n\t\t\t\t\t\t\tfrom data_source_item,data_source,graph_item\n\t\t\t\t\t\t\twhere graph_item.data_source_item_id=data_source_item.id\n\t\t\t\t\t\t\tand data_source_item.data_source_id=data_source.id\n\t\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "graph_item.graph_id") . "\n\t\t\t\t\t\t\torder by data_source.name_cache");
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
api_data_source_remove($data_source["id"]);
}
}
break;
}
api_graph_remove($selected_items[$i]);
}
} elseif ($_POST["drp_action"] == "2") {
/* change graph template */
for ($i = 0; $i < count($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++) {
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++) {
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++) {
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++) {
db_execute("update graph set host_id = " . $_POST["host_id"] . " where id = " . $selected_items[$i]);
api_graph_title_cache_update($selected_items[$i]);
}
} elseif ($_POST["drp_action"] == "6") {
/* reapply suggested naming */
for ($i = 0; $i < count($selected_items); $i++) {
api_reapply_suggested_graph_title($selected_items[$i]);
api_graph_title_cache_update($selected_items[$i]);
}
} elseif ($_POST["drp_action"] == "7") {
/* resize graphs */
for ($i = 0; $i < count($selected_items); $i++) {
api_graph_resize($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)) {
$graph_list .= "<li>" . db_fetch_cell("select title_cache from graph where id = " . $matches[1]) . "<br>";
$graph_array[$i] = $matches[1];
}
$i++;
}
require_once CACTI_BASE_PATH . "/include/top_header.php";
html_start_box("<strong>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel_background"], "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 distinct\n\t\t\t\tdata_source.id,\n\t\t\t\tdata_source.name_cache\n\t\t\t\tfrom data_source_item,data_source,graph_item\n\t\t\t\twhere graph_item.data_source_item_id=data_source_item.id\n\t\t\t\tand data_source_item.data_source_id=data_source.id\n\t\t\t\tand " . array_to_sql_or($graph_array, "graph_item.graph_id") . "\n\t\t\t\torder by data_source.name_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 graphs?") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t";
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>";
}
//.........这里部分代码省略.........