function ds() { global $colors, $ds_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_ds_current_page"); kill_session_var("sess_ds_filter"); kill_session_var("sess_ds_sort_column"); kill_session_var("sess_ds_sort_direction"); kill_session_var("sess_ds_host_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["host_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_ds_current_page", "1"); load_current_session_value("filter", "sess_ds_filter", ""); load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache"); load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC"); load_current_session_value("host_id", "sess_ds_host_id", "-1"); $host = db_fetch_row("select hostname from host where id=" . $_REQUEST["host_id"]); html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "100%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit&host_id=" . $_REQUEST["host_id"]); include "./include/html/inc_data_source_filter_table.php"; html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST["filter"])) { $sql_where = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_template.name like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_input.name like '%%" . $_REQUEST["filter"] . "%%')"; } else { $sql_where = ""; } if ($_REQUEST["host_id"] == "-1") { /* Show all items */ } elseif ($_REQUEST["host_id"] == "0") { $sql_where .= " AND data_local.host_id=0"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where .= " AND data_local.host_id=" . $_REQUEST["host_id"]; } $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where}")); $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\n\t\t{$sql_where}\n\t\tGROUP BY data_template_data.local_data_id"), "id", "poller_interval"); $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . " LIMIT " . read_config_option("num_rows_data_source") * ($_REQUEST["page"] - 1) . "," . read_config_option("num_rows_data_source")); html_start_box("", "100%", $colors["header"], "3", "center", ""); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='6'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] - 1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tShowing Rows " . (read_config_option("num_rows_data_source") * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_data_source") || $total_rows < read_config_option("num_rows_data_source") * $_REQUEST["page"] ? $total_rows : read_config_option("num_rows_data_source") * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>"; if ($_REQUEST["page"] * read_config_option("num_rows_data_source") < $total_rows) { $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] + 1) . "'>"; } $nav .= "Next"; if ($_REQUEST["page"] * read_config_option("num_rows_data_source") < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n"; print $nav; $display_text = array("name_cache" => array("Name", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller<br>Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"]; $data_input_name = empty($data_source["data_input_name"]) ? "<em>External</em>" : $data_source["data_input_name"]; $poller_interval = isset($poller_intervals[$data_source["local_data_id"]]) ? $poller_intervals[$data_source["local_data_id"]] : 0; form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $data_source["local_data_id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"] . "'>" . ($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]); form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_input_name) : $data_input_name) . "</a>", $data_source["local_data_id"]); form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]); form_selectable_cell($data_source['active'], $data_source["local_data_id"]); form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_source['data_template_name']) : $data_source['data_template_name']) . "</a>", $data_source["local_data_id"]); form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Data Sources</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; }
function ds() { global $ds_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("ds_rows")); input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("method_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_ds_current_page"); kill_session_var("sess_ds_filter"); kill_session_var("sess_ds_sort_column"); kill_session_var("sess_ds_sort_direction"); kill_session_var("sess_ds_rows"); kill_session_var("sess_ds_host_id"); kill_session_var("sess_ds_template_id"); kill_session_var("sess_ds_method_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["ds_rows"]); unset($_REQUEST["host_id"]); unset($_REQUEST["template_id"]); unset($_REQUEST["method_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_ds_current_page", "1"); load_current_session_value("filter", "sess_ds_filter", ""); load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache"); load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC"); load_current_session_value("ds_rows", "sess_ds_rows", read_config_option("num_rows_data_source")); load_current_session_value("host_id", "sess_ds_host_id", "-1"); load_current_session_value("template_id", "sess_ds_template_id", "-1"); load_current_session_value("method_id", "sess_ds_method_id", "-1"); $host = db_fetch_row("select hostname from host where id=" . get_request_var_request("host_id")); /* if the number of rows is -1, set it to the default */ if (get_request_var_request("ds_rows") == -1) { $_REQUEST["ds_rows"] = read_config_option("num_rows_data_source"); } ?> <script type="text/javascript"> <!-- function applyDSFilterChange(objForm) { strURL = '?host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&ds_rows=' + objForm.ds_rows.value; strURL = strURL + '&template_id=' + objForm.template_id.value; strURL = strURL + '&method_id=' + objForm.method_id.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : htmlspecialchars($host["hostname"])) . "]", "100%", "", "3", "center", "data_sources.php?action=ds_edit&host_id=" . get_request_var_request("host_id")); ?> <tr class='even noprint'> <td> <form name="form_data_sources" action="data_sources.php"> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Host: </td> <td> <select name="host_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("host_id") == "-1") { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("host_id") == "0") { ?> selected<?php } ?> >None</option> <?php $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); if (sizeof($hosts) > 0) { foreach ($hosts as $host) { print "<option value='" . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($host["name"]), 40) . "</option>\n"; } } ?> </select> </td> <td width="50"> Template: </td> <td width="1"> <select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("template_id") == "0") { ?> selected<?php } ?> >None</option> <?php $templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\t\t\t\t\t\t\tFROM data_template\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\n\t\t\t\t\t\t\t\tON data_template.id=data_template_data.data_template_id\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\n\t\t\t\t\t\t\t\tORDER BY data_template.name"); if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($template["name"]), 40) . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;'> <input type="submit" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> <tr> <td width="50"> Method: </td> <td width="1"> <select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("method_id") == "-1") { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("method_id") == "0") { ?> selected<?php } ?> >None</option> <?php $methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name\n\t\t\t\t\t\t\t\tFROM data_input\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\n\t\t\t\t\t\t\t\tON data_input.id=data_template_data.data_input_id\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\n\t\t\t\t\t\t\t\tORDER BY data_input.name"); if (sizeof($methods) > 0) { foreach ($methods as $method) { print "<option value='" . $method["id"] . "'"; if (get_request_var_request("method_id") == $method["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($method["name"]), 40) . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="50"> Rows per Page: </td> <td width="1"> <select name="ds_rows" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("ds_rows") == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("ds_rows") == $key) { print " selected"; } print ">" . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> </tr> </table> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Search: </td> <td width="1"> <input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> </tr> </table> <input type='hidden' name='page' value='1'> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where1 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" . " OR data_input.name like '%%" . get_request_var_request("filter") . "%%')"; $sql_where2 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%')"; } else { $sql_where1 = ""; $sql_where2 = ""; } if (get_request_var_request("host_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("host_id") == "0") { $sql_where1 .= " AND data_local.host_id=0"; $sql_where2 .= " AND data_local.host_id=0"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where1 .= " AND data_local.host_id=" . get_request_var_request("host_id"); $sql_where2 .= " AND data_local.host_id=" . get_request_var_request("host_id"); } if (get_request_var_request("template_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("template_id") == "0") { $sql_where1 .= " AND data_template_data.data_template_id=0"; $sql_where2 .= " AND data_template_data.data_template_id=0"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where1 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id"); $sql_where2 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id"); } if (get_request_var_request("method_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("method_id") == "0") { $sql_where1 .= " AND data_template_data.data_input_id=0"; $sql_where2 .= " AND data_template_data.data_input_id=0"; } elseif (!empty($_REQUEST["method_id"])) { $sql_where1 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id"); $sql_where2 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id"); } $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}")); $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\n\t\t{$sql_where2}\n\t\tGROUP BY data_template_data.local_data_id"), "id", "poller_interval"); $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . get_request_var_request("ds_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("ds_rows")); print "<form name='chk' method='post' action='data_sources.php'>\n"; html_start_box("", "100%", "", "3", "center", ""); $nav = html_nav_bar("data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"), MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("ds_rows"), $total_rows, 7); print $nav; $display_text = array("name_cache" => array("Name", "ASC"), "local_data_id" => array("ID", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false); $i = 0; if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_source["data_template_name"] = htmlspecialchars($data_source["data_template_name"]); $data_name_cache = title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source")); if (trim(get_request_var_request("filter") != "")) { $data_name_cache = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_name_cache); } /* keep copy of data source for comparison */ $data_source_orig = $data_source; $data_source = api_plugin_hook_function('data_sources_table', $data_source); /* we're escaping strings here, so no need to escape them on form_selectable_cell */ if (empty($data_source["data_template_name"])) { $data_template_name = "<em>None</em>"; } elseif ($data_source_orig["data_template_name"] != $data_source["data_template_name"]) { /* was changed by plugin, plugin has to take care for html-escaping */ $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"]; } elseif (trim(get_request_var_request("filter") != "")) { /* we take care of html-escaping */ $data_template_name = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_template_name'])); } else { $data_template_name = htmlspecialchars($data_source["data_template_name"]); } if (empty($data_source["data_input_name"])) { $data_input_name = "<em>None</em>"; } elseif ($data_source_orig["data_input_name"] != $data_source["data_input_name"]) { /* was changed by plugin, plugin has to take care for html-escaping */ $data_input_name = empty($data_source["data_input_name"]) ? "<em>None</em>" : $data_source["data_input_name"]; } elseif (trim(get_request_var_request("filter") != "")) { /* we take care of html-escaping */ $data_input_name = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_input_name'])); } else { $data_input_name = htmlspecialchars($data_source["data_input_name"]); } $poller_interval = isset($poller_intervals[$data_source["local_data_id"]]) ? $poller_intervals[$data_source["local_data_id"]] : 0; form_alternate_row('line' . $data_source["local_data_id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"]) . "' title='" . htmlspecialchars($data_source["name_cache"], ENT_QUOTES) . "'>" . (get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]); form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']); form_selectable_cell($data_input_name, $data_source["local_data_id"]); form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]); form_selectable_cell($data_source['active'] == "on" ? "Yes" : "No", $data_source["local_data_id"]); form_selectable_cell($data_template_name, $data_source["local_data_id"]); form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Data Sources</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; }
function ds() { global $colors, $ds_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("ds_rows")); input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("method_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_ds_current_page"); kill_session_var("sess_ds_filter"); kill_session_var("sess_ds_sort_column"); kill_session_var("sess_ds_sort_direction"); kill_session_var("sess_ds_rows"); kill_session_var("sess_ds_host_id"); kill_session_var("sess_ds_template_id"); kill_session_var("sess_ds_method_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["ds_rows"]); unset($_REQUEST["host_id"]); unset($_REQUEST["template_id"]); unset($_REQUEST["method_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_ds_current_page", "1"); load_current_session_value("filter", "sess_ds_filter", ""); load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache"); load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC"); load_current_session_value("ds_rows", "sess_ds_rows", read_config_option("num_rows_data_source")); load_current_session_value("host_id", "sess_ds_host_id", "-1"); load_current_session_value("template_id", "sess_ds_template_id", "-1"); load_current_session_value("method_id", "sess_ds_method_id", "-1"); $host = db_fetch_row("select hostname from host where id=" . get_request_var_request("host_id")); /* if the number of rows is -1, set it to the default */ if (get_request_var_request("ds_rows") == -1) { $_REQUEST["ds_rows"] = read_config_option("num_rows_data_source"); } ?> <script type="text/javascript"> <!-- function applyDSFilterChange(objForm) { strURL = '?host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&ds_rows=' + objForm.ds_rows.value; strURL = strURL + '&template_id=' + objForm.template_id.value; strURL = strURL + '&method_id=' + objForm.method_id.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "100%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit&host_id=" . get_request_var_request("host_id")); ?> <tr bgcolor="<?php print $colors["panel"];?>"> <form name="form_data_sources"> <td> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Host: </td> <td> <select name="host_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("host_id") == "-1") {?> selected<?php }?>>Any</option> <option value="0"<?php if (get_request_var_request("host_id") == "0") {?> selected<?php }?>>None</option> <?php $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); if (sizeof($hosts) > 0) { foreach ($hosts as $host) { print "<option value='" . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . title_trim($host["name"], 40) . "</option>\n"; } } ?> </select> </td> <td width="50"> Template: </td> <td width="1"> <select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>>Any</option> <option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>>None</option> <?php $templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name FROM data_template INNER JOIN data_template_data ON data_template.id=data_template_data.data_template_id WHERE data_template_data.local_data_id>0 ORDER BY data_template.name"); if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim($template["name"], 40) . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;'> <input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle"> <input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle"> </td> </tr> <tr> <td width="50"> Method: </td> <td width="1"> <select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("method_id") == "-1") {?> selected<?php }?>>Any</option> <option value="0"<?php if (get_request_var_request("method_id") == "0") {?> selected<?php }?>>None</option> <?php $methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name FROM data_input INNER JOIN data_template_data ON data_input.id=data_template_data.data_input_id WHERE data_template_data.local_data_id>0 ORDER BY data_input.name"); if (sizeof($methods) > 0) { foreach ($methods as $method) { print "<option value='" . $method["id"] . "'"; if (get_request_var_request("method_id") == $method["id"]) { print " selected"; } print ">" . title_trim($method["name"], 40) . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="50"> Rows per Page: </td> <td width="1"> <select name="ds_rows" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("ds_rows") == "-1") {?> selected<?php }?>>Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("ds_rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> </tr> </table> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Search: </td> <td width="1"> <input type="text" name="filter" size="40" value="<?php print get_request_var_request("filter");?>"> </td> </tr> </table> </td> <input type='hidden' name='page' value='1'> </form> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where1 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" . " OR data_input.name like '%%" . get_request_var_request("filter") . "%%')"; $sql_where2 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%')"; }else{ $sql_where1 = ""; $sql_where2 = ""; } if (get_request_var_request("host_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("host_id") == "0") { $sql_where1 .= " AND data_local.host_id=0"; $sql_where2 .= " AND data_local.host_id=0"; }elseif (!empty($_REQUEST["host_id"])) { $sql_where1 .= " AND data_local.host_id=" . get_request_var_request("host_id"); $sql_where2 .= " AND data_local.host_id=" . get_request_var_request("host_id"); } if (get_request_var_request("template_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("template_id") == "0") { $sql_where1 .= " AND data_template_data.data_template_id=0"; $sql_where2 .= " AND data_template_data.data_template_id=0"; }elseif (!empty($_REQUEST["host_id"])) { $sql_where1 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id"); $sql_where2 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id"); } if (get_request_var_request("method_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("method_id") == "0") { $sql_where1 .= " AND data_template_data.data_input_id=0"; $sql_where2 .= " AND data_template_data.data_input_id=0"; }elseif (!empty($_REQUEST["method_id"])) { $sql_where1 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id"); $sql_where2 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id"); } $total_rows = sizeof(db_fetch_assoc("SELECT data_local.id FROM (data_local,data_template_data) LEFT JOIN data_input ON (data_input.id=data_template_data.data_input_id) LEFT JOIN data_template ON (data_local.data_template_id=data_template.id) WHERE data_local.id=data_template_data.local_data_id $sql_where1")); $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id, Min(data_template_data.rrd_step*rra.steps) AS poller_interval FROM data_template INNER JOIN (data_local INNER JOIN ((data_template_data_rra INNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id) INNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id $sql_where2 GROUP BY data_template_data.local_data_id"), "id", "poller_interval"); $data_sources = db_fetch_assoc("SELECT data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_input.name as data_input_name, data_template.name as data_template_name, data_local.host_id FROM (data_local,data_template_data) LEFT JOIN data_input ON (data_input.id=data_template_data.data_input_id) LEFT JOIN data_template ON (data_local.data_template_id=data_template.id) WHERE data_local.id=data_template_data.local_data_id $sql_where1 ORDER BY ". get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . (get_request_var_request("ds_rows")*(get_request_var_request("page")-1)) . "," . get_request_var_request("ds_rows")); html_start_box("", "100%", $colors["header"], "3", "center", ""); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("ds_rows"), $total_rows, "data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id")); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='7'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")-1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((get_request_var_request("ds_rows")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < get_request_var_request("ds_rows")) || ($total_rows < (get_request_var_request("ds_rows")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("ds_rows")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if ((get_request_var_request("page") * get_request_var_request("ds_rows")) < $total_rows) { $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")+1) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * get_request_var_request("ds_rows")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; $display_text = array( "name_cache" => array("Name", "ASC"), "local_data_id" => array("ID","ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); $i = 0; if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_source = api_plugin_hook_function('data_sources_table', $data_source); $data_template_name = ((empty($data_source["data_template_name"])) ? "<em>None</em>" : $data_source["data_template_name"]); $data_input_name = ((empty($data_source["data_input_name"])) ? "<em>External</em>" : $data_source["data_input_name"]); $poller_interval = ((isset($poller_intervals[$data_source["local_data_id"]])) ? $poller_intervals[$data_source["local_data_id"]] : 0); form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $data_source["local_data_id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"] . "' title='" . htmlspecialchars($data_source["name_cache"]) . "'>" . ((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]); form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']); form_selectable_cell(((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_input_name) : $data_input_name) . "</a>", $data_source["local_data_id"]); form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]); form_selectable_cell(($data_source['active'] == "on" ? "Yes" : "No"), $data_source["local_data_id"]); form_selectable_cell(((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_source['data_template_name']) : $data_source['data_template_name']) . "</a>", $data_source["local_data_id"]); form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Data Sources</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; }
function data_source() { global $colors, $item_rows; require(CACTI_BASE_PATH . "/include/data_source/data_source_arrays.php"); /* validate request variables */ data_source_validate(); /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_ds_current_page"); kill_session_var("sess_ds_filter"); kill_session_var("sess_ds_sort_column"); kill_session_var("sess_ds_sort_direction"); kill_session_var("sess_ds_rows"); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { kill_session_var("sess_ds_device_id"); } kill_session_var("sess_ds_template_id"); kill_session_var("sess_ds_method_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["rows"]); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { unset($_REQUEST["device_id"]); } unset($_REQUEST["template_id"]); unset($_REQUEST["method_id"]); $_REQUEST["page"] = 1; }else{ /* let's see if someone changed an important setting */ $changed = FALSE; $changed += check_changed("filter", "sess_ds_filter"); $changed += check_changed("rows", "sess_ds_rows"); $changed += check_changed("device_id", "sess_ds_device_id"); $changed += check_changed("template_id", "sess_ds_template_id"); $changed += check_changed("method_id", "sess_ds_method_id"); if ($changed) { $_REQUEST["page"] = "1"; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_ds_current_page", "1"); load_current_session_value("filter", "sess_ds_filter", ""); load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache"); load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC"); load_current_session_value("rows", "sess_ds_rows", "-1"); load_current_session_value("device_id", "sess_ds_device_id", "-1"); load_current_session_value("template_id", "sess_ds_template_id", "-1"); load_current_session_value("method_id", "sess_ds_method_id", "-1"); $device = db_fetch_row("select hostname from device where id=" . $_REQUEST["device_id"]); ?> <script type="text/javascript"> <!-- $().ready(function() { $("#device").autocomplete("./lib/ajax/get_devices_brief.php", { max: 8, highlight: false, scroll: true, scrollHeight: 300 }); $("#device").result(function(event, data, formatted) { if (data) { $(this).parent().find("#device_id").val(data[1]); applyDSFilterChange(document.form_data_sources); }else{ $(this).parent().find("#device_id").val(0); } }); }); function clearDSFilterChange(objForm) { strURL = '?filter='; <?php # called from outside if (isset($_REQUEST["tab"])) { # print the tab print "strURL = strURL + &tab=" . $_REQUEST["tab"] . "';"; # now look for more parameters if (isset($_REQUEST["device_id"])) { print "strURL = strURL + '&device_id=" . $_REQUEST["device_id"] . "&id=" . $_REQUEST["device_id"] . "';"; } if (isset($_REQUEST["template_id"])) { print "strURL = strURL + '&template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "';"; } }else { # clear all parms print "strURL = strURL + '&device_id=-1';"; print "strURL = strURL + '&template_id=-1';"; } ?> strURL = strURL + '&rows=-1'; strURL = strURL + '&method_id=-1'; document.location = strURL; } function applyDSFilterChange(objForm) { strURL = '?filter=' + objForm.filter.value; // take care of parms provided via autocomplete // those are passed as objForm.<parm>.value // instead of $_REQUEST["<parm>"] when called from outside if (objForm.device_id.value) { strURL = '?device_id=' + objForm.device_id.value; }else{ <?php print (isset($_REQUEST["device_id"]) ? "strURL = strURL + '&device_id=" . $_REQUEST["device_id"] . "&id=" . $_REQUEST["device_id"] . "';" : "strURL = strURL + '&device_id=-1';");?> } if (objForm.template_id.value) { strURL = '?template_id=' + objForm.template_id.value; }else{ <?php print (isset($_REQUEST["template_id"]) ? "strURL = strURL + '&template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "';" : "strURL = strURL + '&template_id=-1';");?> } strURL = strURL + '&rows=' + objForm.rows.value; strURL = strURL + '&method_id=' + objForm.method_id.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>" . __("Data Sources") . "</strong> " . __("[device:") . " " . (empty($device["hostname"]) ? __("No Host") : $device["hostname"]) . "]", "100", $colors["header"], "3", "center", "data_sources.php?action=data_source_edit&device_id=" . $_REQUEST["device_id"], true); ?> <tr class='rowAlternate2'> <td> <form action="data_sources.php" name="form_data_sources"> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Host:");?> </td> <td class="w1"> <?php if (isset($_REQUEST["device_id"])) { $hostname = db_fetch_cell("SELECT description as name FROM device WHERE id=".$_REQUEST["device_id"]." ORDER BY description,hostname"); } else { $hostname = ""; } ?> <input class="ac_field" type="text" id="device" size="30" value="<?php print $hostname; ?>"> <input type="hidden" id="device_id"> </td> <td class="nw50"> <?php print __("Template:");?> </td> <td class="w1"> <select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>><?php print __("Any");?></option> <option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>><?php print __("None");?></option> <?php $templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name FROM data_template INNER JOIN data_template_data ON data_template.id=data_template_data.data_template_id WHERE data_template_data.local_data_id>0 ORDER BY data_template.name"); if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim($template["name"], 40) . "</option>\n"; } } ?> </select> </td> <td class="nw120"> <input type="submit" value="<?php print __("Go");?>" name="go" align="middle"> <input type="button" value="<?php print __("Clear");?>" name="clear" align="middle" onClick="clearDSFilterChange(document.form_data_sources)"> </td> </tr> <tr> <td class="nw50"> <?php print __("Method:");?> </td> <td class="w1"> <select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("method_id") == "-1") {?> selected<?php }?>><?php print __("Any");?></option> <option value="0"<?php if (get_request_var_request("method_id") == "0") {?> selected<?php }?>><?php print __("None");?></option> <?php $methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name FROM data_input INNER JOIN data_template_data ON data_input.id=data_template_data.data_input_id WHERE data_template_data.local_data_id>0 ORDER BY data_input.name"); if (sizeof($methods) > 0) { foreach ($methods as $method) { print "<option value='" . $method["id"] . "'"; if (get_request_var_request("method_id") == $method["id"]) { print " selected"; } print ">" . title_trim($method["name"], 40) . "</option>\n"; } } ?> </select> </td> <td class="nw50"> <?php print __("Rows:");?> </td> <td class="w1"> <select name="rows" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") {?> selected<?php }?>><?php print __("Default");?></option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> </tr> </table> <table cellpadding="1" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Search:");?> </td> <td class="w1"> <input type="text" name="filter" size="40" value="<?php print $_REQUEST["filter"];?>"> </td> </tr> </table> <input type='hidden' name='page' value='1'> </form> </td> </tr> <?php html_end_box(false); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where1 = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" . " OR data_input.name like '%%" . get_request_var_request("filter") . "%%')"; $sql_where2 = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%')"; }else{ $sql_where1 = ""; $sql_where2 = ""; } if (get_request_var_request("device_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("device_id") == "0") { $sql_where1 .= " AND data_local.device_id=0"; $sql_where2 .= " AND data_local.device_id=0"; }else { $sql_where1 .= " AND data_local.device_id=" . $_REQUEST["device_id"]; $sql_where2 .= " AND data_local.device_id=" . $_REQUEST["device_id"]; } if (get_request_var_request("template_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("template_id") == "0") { $sql_where1 .= " AND data_template_data.data_template_id=0"; $sql_where2 .= " AND data_template_data.data_template_id=0"; }else { $sql_where1 .= " AND data_template_data.data_template_id=" . $_REQUEST["template_id"]; $sql_where2 .= " AND data_template_data.data_template_id=" . $_REQUEST["template_id"]; } if (get_request_var_request("method_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("method_id") == "0") { $sql_where1 .= " AND data_template_data.data_input_id=0"; $sql_where2 .= " AND data_template_data.data_input_id=0"; }else { $sql_where1 .= " AND data_template_data.data_input_id=" . $_REQUEST["method_id"]; $sql_where2 .= " AND data_template_data.data_input_id=" . $_REQUEST["method_id"]; } if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_data_source"); }else{ $rows = get_request_var_request("rows"); } $total_rows = sizeof(db_fetch_assoc("SELECT data_local.id FROM (data_local,data_template_data) LEFT JOIN data_input ON (data_input.id=data_template_data.data_input_id) LEFT JOIN data_template ON (data_local.data_template_id=data_template.id) WHERE data_local.id=data_template_data.local_data_id $sql_where1")); $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id, Min(data_template_data.rrd_step*rra.steps) AS poller_interval FROM data_template INNER JOIN (data_local INNER JOIN ((data_template_data_rra INNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id) INNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id $sql_where2 GROUP BY data_template_data.local_data_id"), "id", "poller_interval"); $dssql = "SELECT data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_input.name as data_input_name, data_template.name as data_template_name, data_local.device_id FROM (data_local,data_template_data) LEFT JOIN data_input ON (data_input.id=data_template_data.data_input_id) LEFT JOIN data_template ON (data_local.data_template_id=data_template.id) WHERE data_local.id=data_template_data.local_data_id $sql_where1 ORDER BY ". get_request_var_request('sort_column') . " " . get_request_var_request('sort_direction') . " LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows; $data_sources = db_fetch_assoc($dssql); html_start_box("", "100", $colors["header"], "0", "center", ""); /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 7, "data_sources.php"); print $nav; html_end_box(false); $display_text = array( "name_cache" => array(__("Name"), "ASC"), "local_data_id" => array(__("ID"),"ASC"), "data_input_name" => array(__("Data Input Method"), "ASC"), "nosort" => array(__("Poller Interval"), "ASC"), "active" => array(__("Active"), "ASC"), "data_template_name" => array(__("Template Name"), "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_source = api_plugin_hook_function('data_sources_table', $data_source); $data_template_name = ((empty($data_source["data_template_name"])) ? "<em>" . __("None") . "</em>" : $data_source["data_template_name"]); $data_input_name = ((empty($data_source["data_input_name"])) ? "<em>" . __("External") . "</em>" : $data_source["data_input_name"]); $poller_interval = ((isset($poller_intervals[$data_source["local_data_id"]])) ? $poller_intervals[$data_source["local_data_id"]] : 0); form_alternate_row_color('line' . $data_source["local_data_id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_sources.php?action=data_source_edit&id=" . $data_source["local_data_id"]) . "' title='" . htmlspecialchars($data_source["name_cache"]) . "'>" . (($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", title_trim(htmlentities($data_source["name_cache"], ENT_NOQUOTES, "UTF-8"), read_config_option("max_title_data_source"))) : title_trim(htmlentities($data_source["name_cache"], ENT_NOQUOTES, "UTF-8"), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]); form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']); form_selectable_cell((($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $data_input_name) : $data_input_name), $data_source["local_data_id"]); form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]); form_selectable_cell(($data_source['active'] == CHECKED ? "Yes" : "No"), $data_source["local_data_id"]); form_selectable_cell((($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $data_source['data_template_name']) : $data_source['data_template_name']), $data_source["local_data_id"]); form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Data Sources") . "</em></td></tr>"; } print "</table>\n"; # end table of html_header_sort_checkbox /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; # end form of html_header_sort_checkbox }
function ds() { global $ds_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('rows')); input_validate_input_number(get_request_var_request('host_id')); input_validate_input_number(get_request_var_request('template_id')); input_validate_input_number(get_request_var_request('method_id')); input_validate_input_number(get_request_var_request('page')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort_column string */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up sort_direction string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_ds_current_page'); kill_session_var('sess_ds_filter'); kill_session_var('sess_ds_sort_column'); kill_session_var('sess_ds_sort_direction'); kill_session_var('sess_default_rows'); kill_session_var('sess_ds_host_id'); kill_session_var('sess_ds_template_id'); kill_session_var('sess_ds_method_id'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); unset($_REQUEST['rows']); unset($_REQUEST['host_id']); unset($_REQUEST['template_id']); unset($_REQUEST['method_id']); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_ds_current_page', '1'); load_current_session_value('filter', 'sess_ds_filter', ''); load_current_session_value('sort_column', 'sess_ds_sort_column', 'name_cache'); load_current_session_value('sort_direction', 'sess_ds_sort_direction', 'ASC'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); load_current_session_value('host_id', 'sess_ds_host_id', '-1'); load_current_session_value('template_id', 'sess_ds_template_id', '-1'); load_current_session_value('method_id', 'sess_ds_method_id', '-1'); $host = db_fetch_row_prepared('SELECT hostname FROM host WHERE id = ?', array(get_request_var_request('host_id'))); /* if the number of rows is -1, set it to the default */ if (get_request_var_request('rows') == -1) { $_REQUEST['rows'] = read_config_option('num_rows_table'); } ?> <script type='text/javascript'> <!-- function applyFilter() { strURL = 'data_sources.php?host_id=' + $('#host_id').val(); strURL = strURL + '&filter=' + $('#filter').val(); strURL = strURL + '&rows=' + $('#rows').val(); strURL = strURL + '&template_id=' + $('#template_id').val(); strURL = strURL + '&method_id=' + $('#method_id').val(); strURL = strURL + '&page=' + $('#page').val(); strURL = strURL + '&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'data_sources.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh').click(function() { applyFilter() }); $('#clear').click(function() { clearFilter() }); $('#form_data_sources').submit(function(event) { event.preventDefault(); applyFilter(); }); }); --> </script> <?php if (read_config_option('grds_creation_method') == 1) { $add_url = htmlspecialchars('data_sources.php?action=ds_edit&host_id=' . get_request_var_request('host_id')); } else { $add_url = ''; } html_start_box('<strong>Data Sources</strong> [host: ' . (empty($host['hostname']) ? 'No Device' : htmlspecialchars($host['hostname'])) . ']', '100%', '', '3', 'center', $add_url); ?> <tr class='even noprint'> <td> <form id='form_data_sources' name='form_data_sources' action='data_sources.php'> <table cellpadding='2' cellspacing='0' border='0'> <tr> <?php print html_host_filter($_REQUEST['host_id']); ?> <td width='50'> Template </td> <td> <select id='template_id' name='template_id' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var_request('template_id') == '-1') { ?> selected<?php } ?> >Any</option> <option value='0'<?php if (get_request_var_request('template_id') == '0') { ?> selected<?php } ?> >None</option> <?php $templates = db_fetch_assoc('SELECT DISTINCT data_template.id, data_template.name FROM data_template INNER JOIN data_template_data ON data_template.id = data_template_data.data_template_id WHERE data_template_data.local_data_id > 0 ORDER BY data_template.name'); if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template['id'] . "'"; if (get_request_var_request('template_id') == $template['id']) { print ' selected'; } print '>' . title_trim(htmlspecialchars($template['name']), 40) . "</option>\n"; } } ?> </select> </td> <td> <input type='button' id='refresh' value='Go' title='Set/Refresh Filters'> </td> <td> <input type='button' id='clear' name='clear_x' value='Clear' title='Clear Filters'> </td> </tr> <tr> <td width='50'> Method </td> <td> <select id='method_id' name='method_id' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var_request('method_id') == '-1') { ?> selected<?php } ?> >Any</option> <option value='0'<?php if (get_request_var_request('method_id') == '0') { ?> selected<?php } ?> >None</option> <?php $methods = db_fetch_assoc('SELECT DISTINCT data_input.id, data_input.name FROM data_input INNER JOIN data_template_data ON data_input.id = data_template_data.data_input_id WHERE data_template_data.local_data_id > 0 ORDER BY data_input.name'); if (sizeof($methods) > 0) { foreach ($methods as $method) { print "<option value='" . $method['id'] . "'"; if (get_request_var_request('method_id') == $method['id']) { print ' selected'; } print '>' . title_trim(htmlspecialchars($method['name']), 40) . "</option>\n"; } } ?> </select> </td> <td style='white-space:nowrap;'> Data Sources </td> <td> <select id='rows' name='rows' onChange='applyFilter()'> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> </tr> </table> <table cellpadding='2' cellspacing='0' border='0'> <tr> <td width='50'> Search </td> <td> <input id='filter' type='text' size='25' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> ' onChange='applyFilter()'> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request('filter'))) { $sql_where1 = "AND (data_template_data.name_cache like '%" . get_request_var_request('filter') . "%'" . " OR data_template_data.local_data_id like '%" . get_request_var_request('filter') . "%'" . " OR data_template.name like '%" . get_request_var_request('filter') . "%'" . " OR data_input.name like '%" . get_request_var_request('filter') . "%')"; $sql_where2 = "AND (data_template_data.name_cache like '%" . get_request_var_request('filter') . "%'" . " OR data_template.name like '%" . get_request_var_request('filter') . "%')"; } else { $sql_where1 = ''; $sql_where2 = ''; } if (get_request_var_request('host_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('host_id') == '0') { $sql_where1 .= ' AND data_local.host_id=0'; $sql_where2 .= ' AND data_local.host_id=0'; } elseif (!empty($_REQUEST['host_id'])) { $sql_where1 .= ' AND data_local.host_id=' . get_request_var_request('host_id'); $sql_where2 .= ' AND data_local.host_id=' . get_request_var_request('host_id'); } if (get_request_var_request('template_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('template_id') == '0') { $sql_where1 .= ' AND data_template_data.data_template_id=0'; $sql_where2 .= ' AND data_template_data.data_template_id=0'; } elseif (!empty($_REQUEST['host_id'])) { $sql_where1 .= ' AND data_template_data.data_template_id=' . get_request_var_request('template_id'); $sql_where2 .= ' AND data_template_data.data_template_id=' . get_request_var_request('template_id'); } if (get_request_var_request('method_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('method_id') == '0') { $sql_where1 .= ' AND data_template_data.data_input_id=0'; $sql_where2 .= ' AND data_template_data.data_input_id=0'; } elseif (!empty($_REQUEST['method_id'])) { $sql_where1 .= ' AND data_template_data.data_input_id=' . get_request_var_request('method_id'); $sql_where2 .= ' AND data_template_data.data_input_id=' . get_request_var_request('method_id'); } $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}")); $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\n\t\t{$sql_where2}\n\t\tGROUP BY data_template_data.local_data_id"), 'id', 'poller_interval'); $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows')); print "<form name='chk' method='post' action='data_sources.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); $nav = html_nav_bar('data_sources.php?filter=' . get_request_var_request('filter') . '&host_id=' . get_request_var_request('host_id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 7, 'Data Sources', 'page', 'main'); print $nav; $display_text = array('name_cache' => array('display' => 'Data Source Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Data Source. Generally programtically generated from the Data Template definition.'), 'local_data_id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Data Source. Useful when performing automation or debugging.'), 'data_input_name' => array('display' => 'Data Input Method', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The method by which data is gathered for this Data Source.'), 'nosort' => array('display' => 'Poller Interval', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The frequency that data is collected for this Data Source.'), 'active' => array('display' => 'Active', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'Whether or not data will be collected for this Data Source. Controlled at the Data Template level.'), 'data_template_name' => array('display' => 'Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Data Template that this Data Source was based upon.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_source['data_template_name'] = htmlspecialchars($data_source['data_template_name']); $data_name_cache = title_trim(htmlspecialchars($data_source['name_cache']), read_config_option('max_title_length')); if (trim(get_request_var_request('filter') != '')) { $data_name_cache = preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $data_name_cache); } /* keep copy of data source for comparison */ $data_source_orig = $data_source; $data_source = api_plugin_hook_function('data_sources_table', $data_source); /* we're escaping strings here, so no need to escape them on form_selectable_cell */ if (empty($data_source['data_template_name'])) { $data_template_name = '<em>None</em>'; } elseif ($data_source_orig['data_template_name'] != $data_source['data_template_name']) { /* was changed by plugin, plugin has to take care for html-escaping */ $data_template_name = empty($data_source['data_template_name']) ? '<em>None</em>' : $data_source['data_template_name']; } elseif (trim(get_request_var_request('filter') != '')) { /* we take care of html-escaping */ $data_template_name = preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($data_source['data_template_name'])); } else { $data_template_name = htmlspecialchars($data_source['data_template_name']); } if (empty($data_source['data_input_name'])) { $data_input_name = '<em>None</em>'; } elseif ($data_source_orig['data_input_name'] != $data_source['data_input_name']) { /* was changed by plugin, plugin has to take care for html-escaping */ $data_input_name = empty($data_source['data_input_name']) ? '<em>None</em>' : $data_source['data_input_name']; } elseif (trim(get_request_var_request('filter') != '')) { /* we take care of html-escaping */ $data_input_name = preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($data_source['data_input_name'])); } else { $data_input_name = htmlspecialchars($data_source['data_input_name']); } $poller_interval = isset($poller_intervals[$data_source['local_data_id']]) ? $poller_intervals[$data_source['local_data_id']] : 0; form_alternate_row('line' . $data_source['local_data_id'], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('data_sources.php?action=ds_edit&id=' . $data_source['local_data_id']) . "' title='" . htmlspecialchars($data_source['name_cache'], ENT_QUOTES) . "'>" . (get_request_var_request('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", title_trim(htmlspecialchars($data_source['name_cache']), read_config_option('max_title_length'))) : title_trim(htmlspecialchars($data_source['name_cache']), read_config_option('max_title_length'))) . '</a>', $data_source['local_data_id']); form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id'], '', 'text-align:right'); form_selectable_cell($data_input_name, $data_source['local_data_id']); form_selectable_cell(get_poller_interval($poller_interval), $data_source['local_data_id']); form_selectable_cell($data_source['active'] == 'on' ? 'Yes' : 'No', $data_source['local_data_id']); form_selectable_cell($data_template_name, $data_source['local_data_id']); form_checkbox_cell($data_source['name_cache'], $data_source['local_data_id']); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='7'><em>No Data Sources</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; }