function graph() { global $colors, $item_rows; require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); require_once(CACTI_BASE_PATH . "/include/auth/auth_constants.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("device_id")); input_validate_input_number(get_request_var_request("rows")); input_validate_input_number(get_request_var_request("template_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_graph_current_page"); kill_session_var("sess_graph_filter"); kill_session_var("sess_graph_sort_column"); kill_session_var("sess_graph_sort_direction"); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { kill_session_var("sess_graph_device_id"); } kill_session_var("sess_graph_rows"); kill_session_var("sess_graph_template_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { unset($_REQUEST["device_id"]); } unset($_REQUEST["rows"]); unset($_REQUEST["template_id"]); } /* 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"); 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_graph_current_page", "1"); load_current_session_value("filter", "sess_graph_filter", ""); load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache"); load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC"); load_current_session_value("device_id", "sess_graph_device_id", "-1"); load_current_session_value("rows", "sess_graph_rows", "-1"); load_current_session_value("template_id", "sess_graph_template_id", "-1"); ?> <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]); applyGraphsFilterChange(document.form_graph_id); }else{ $(this).parent().find("#device_id").val(0); } }); }); function clearGraphsFilterChange(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'; document.location = strURL; } function applyGraphsFilterChange(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; document.location = strURL; } --> </script> <?php html_start_box("<strong>" . __("Graph Management") . "</strong>", "100", $colors["header"], "3", "center", "graphs.php?action=graph_edit&device_id=" . $_REQUEST["device_id"], true); ?> <tr class='rowAlternate2'> <td> <form name="form_graph_id" action="graphs.php"> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Host:");?> </td> <td width="1"> <?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 width="70"> <?php print __("Template:");?> </td> <td width="1"> <select name="template_id" onChange="applyGraphsFilterChange(document.form_graph_id)"> <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 if (read_config_option("auth_method") != 0) { $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name FROM (graph_templates_graph,graph_local) LEFT JOIN device ON (device.id=graph_local.device_id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPHS . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_DEVICES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPH_TEMPLATES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")) WHERE graph_templates_graph.local_graph_id=graph_local.id AND graph_templates.id IS NOT NULL " . (empty($sql_where) ? "" : "AND $sql_where") . " ORDER BY name"); }else{ $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name FROM graph_templates ORDER BY 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_x" align="middle" onClick="clearGraphsFilterChange(document.form_graph_id)"> </td> </tr> </table> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Search:");?> </td> <td> <input type="text" name="filter" size="40" value="<?php print $_REQUEST["filter"];?>"> </td> <td class="nw50"> <?php print __("Rows:");?> </td> <td width="1"> <select name="rows" onChange="applyGraphsFilterChange(document.form_graph_id)"> <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> <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_where = "AND (graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request("filter") . "%%')"; }else{ $sql_where = ""; } if (get_request_var_request("device_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("device_id") == "0") { $sql_where .= " AND graph_local.device_id=0"; }elseif (!empty($_REQUEST["device_id"])) { $sql_where .= " AND graph_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_where .= " AND graph_templates_graph.graph_template_id=0"; }elseif (!empty($_REQUEST["template_id"])) { $sql_where .= " AND graph_templates_graph.graph_template_id=" . $_REQUEST["template_id"]; } html_start_box("", "100", $colors["header"], "0", "center", ""); if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_graph"); }else{ $rows = get_request_var_request("rows"); } $total_rows = db_fetch_cell("SELECT COUNT(graph_templates_graph.id) FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where"); $graph_list = db_fetch_assoc("SELECT graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.device_id FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where ORDER BY " . get_request_var_request('sort_column') . " " . get_request_var_request('sort_direction') . " LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows); /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 7, "graphs.php"); print $nav; html_end_box(false); $display_text = array( "title_cache" => array(__("Graph Title"), "ASC"), "local_graph_id" => array(__("ID"), "ASC"), "name" => array(__("Template Name"), "ASC"), "height" => array(__("Size"), "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { $template_name = ((empty($graph["name"])) ? "<em>" . __("None") . "</em>" : $graph["name"]); form_alternate_row_color('line' . $graph["local_graph_id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . $graph["local_graph_id"] . "' title='" . $graph["title_cache"]) . "'>" . (($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph"))) : title_trim($graph["title_cache"], read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]); form_selectable_cell($graph["local_graph_id"], $graph["local_graph_id"]); form_selectable_cell((($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $template_name) : $template_name), $graph["local_graph_id"]); form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]); form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Graphs Found") . "</em></td></tr>"; } print "</table>\n"; # end table of html_header_sort_checkbox /* add a list of tree names to the actions dropdown */ $graph_actions = array_merge(graph_actions_list(), api_tree_add_tree_names_to_actions_array()); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); print "</form>\n"; # end form of html_header_sort_checkbox }
function device() { global $colors, $item_rows; require(CACTI_BASE_PATH . "/include/device/device_arrays.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("status")); input_validate_input_number(get_request_var_request("rows")); input_validate_input_number(get_request_var_request("poller")); input_validate_input_number(get_request_var_request("site")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search 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_device_current_page"); kill_session_var("sess_device_filter"); if (!substr_count($_SERVER["REQUEST_URI"], "/device_templates.php")) { kill_session_var("sess_device_template_id"); } kill_session_var("sess_device_status"); kill_session_var("sess_device_rows"); kill_session_var("sess_device_poller"); kill_session_var("sess_device_site"); kill_session_var("sess_device_sort_column"); kill_session_var("sess_device_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); if (!substr_count($_SERVER["REQUEST_URI"], "/device_templates.php")) { unset($_REQUEST["template_id"]); } unset($_REQUEST["status"]); unset($_REQUEST["poller"]); unset($_REQUEST["site"]); unset($_REQUEST["rows"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } /* let's see if someone changed an important setting */ $changed = FALSE; $changed += check_changed("filter", "sess_device_filter"); $changed += check_changed("template_id", "sess_device_template_id"); $changed += check_changed("status", "sess_device_status"); $changed += check_changed("rows", "sess_device_rows"); $changed += check_changed("poller", "sess_device_poller"); $changed += check_changed("site", "sess_device_site"); $changed += check_changed("device_id", "sess_ds_device_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_device_current_page", "1"); load_current_session_value("filter", "sess_device_filter", ""); load_current_session_value("template_id", "sess_device_template_id", "-1"); load_current_session_value("status", "sess_device_status", "-1"); load_current_session_value("rows", "sess_device_rows", "-1"); load_current_session_value("poller", "sess_device_poller", "-1"); load_current_session_value("site", "sess_device_site", "-1"); load_current_session_value("sort_column", "sess_device_sort_column", "description"); load_current_session_value("sort_direction", "sess_device_sort_direction", "ASC"); ?> <script type="text/javascript"> <!-- function clearDeviceFilterChange(objForm) { <?php print (isset($_REQUEST["tab"]) ? "strURL = '?template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "&action=edit&action=edit&tab=" . $_REQUEST["tab"] . "';" : "strURL = '?template_id=-1';");?> strURL = strURL + '&filter='; strURL = strURL + '&rows=-1'; document.location = strURL; } function applyDeviceFilterChange(objForm) { if (objForm.template_id.value) { strURL = '?template_id=' + objForm.template_id.value; strURL = strURL + '&filter=' + objForm.filter.value; }else{ strURL = '?filter=' + objForm.filter.value; } strURL = strURL + '&status=' + objForm.status.value; strURL = strURL + '&rows=' + objForm.rows.value; strURL = strURL + '&poller=' + objForm.poller.value; strURL = strURL + '&site=' + objForm.site.value; <?php print (isset($_REQUEST["tab"]) ? "strURL = strURL + '&id=' + objForm.template_id.value + '&action=edit&action=edit&tab=" . $_REQUEST["tab"] . "';" : "");?> document.location = strURL; } --> </script> <?php html_start_box("<strong>" . __("Devices") . "</strong>", "100", $colors["header"], "3", "center", "devices.php?action=edit&template_id=" . $_REQUEST["template_id"] . "&status=" . $_REQUEST["status"], true); ?> <tr class='rowAlternate2'> <td> <form action="devices.php" name="form_devices" method="post"> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Type:");?> </td> <td class="w1"> <select name="template_id" onChange="applyDeviceFilterChange(document.form_devices)"> <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 $device_templates = db_fetch_assoc("select id,name from device_template order by name"); if (sizeof($device_templates) > 0) { foreach ($device_templates as $device_template) { print "<option value='" . $device_template["id"] . "'"; if (get_request_var_request("template_id") == $device_template["id"]) { print " selected"; } print ">" . $device_template["name"] . "</option>\n"; } } ?> </select> </td> <td class="nw50"> <?php print __("Status:");?> </td> <td class="w1"> <select name="status" onChange="applyDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("status") == "-1") {?> selected<?php }?>><?php print __("Any");?></option> <option value="-3"<?php if (get_request_var_request("status") == "-3") {?> selected<?php }?>><?php print __("Enabled");?></option> <option value="-2"<?php if (get_request_var_request("status") == "-2") {?> selected<?php }?>><?php print __("Disabled");?></option> <option value="-4"<?php if (get_request_var_request("status") == "-4") {?> selected<?php }?>><?php print __("Not Up");?></option> <option value="3"<?php if (get_request_var_request("status") == "3") {?> selected<?php }?>><?php print __("Up");?></option> <option value="1"<?php if (get_request_var_request("status") == "1") {?> selected<?php }?>><?php print __("Down");?></option> <option value="2"<?php if (get_request_var_request("status") == "2") {?> selected<?php }?>><?php print __("Recovering");?></option> <option value="0"<?php if (get_request_var_request("status") == "0") {?> selected<?php }?>><?php print __("Unknown");?></option> </select> </td> <td class="nw50"> <?php print __("Rows:");?> </td> <td class="w1"> <select name="rows" onChange="applyDeviceFilterChange(document.form_devices)"> <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="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Site:");?> </td> <td class="w1"> <select name="site" onChange="applyDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("site") == "-1") {?> selected<?php }?>><?php print __("All");?></option> <option value="0"<?php if (get_request_var_request("site") == "0") {?> selected<?php }?>><?php print __("Not Defined");?></option> <?php $sites = db_fetch_assoc("select id,name from sites order by name"); if (sizeof($sites)) { foreach ($sites as $site) { print "<option value='" . $site["id"] . "'"; if (get_request_var_request("site") == $site["id"]) { print " selected"; } print ">" . $site["name"] . "</option>\n"; } } ?> </select> </td> <td class="nw50"> <?php print __("Poller:");?> </td> <td class="w1"> <select name="poller" onChange="applyDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("poller") == "-1") {?> selected<?php }?>><?php print __("All");?></option> <option value="0"<?php if (get_request_var_request("poller") == "0") {?> selected<?php }?>><?php print __("System Default");?></option> <?php $pollers = db_fetch_assoc("select id,description AS name from poller order by description"); if (sizeof($pollers)) { foreach ($pollers as $poller) { print "<option value='" . $poller["id"] . "'"; if (get_request_var_request("poller") == $poller["id"]) { print " selected"; } print ">" . $poller["name"] . "</option>\n"; } } ?> </select> </td> <td class="nw50"> <?php print __("Search:");?> </td> <td class="w1"> <input type="text" name="filter" size="20" value="<?php print $_REQUEST["filter"];?>"> </td> <td class="nw120"> <input type="submit" Value="<?php print __("Go");?>" name="go" align="middle"> <input type="button" Value="<?php print __("Clear");?>" name="clear_x" align="middle" onClick="clearDeviceFilterChange(document.form_devices)"> </td> </tr> </table> <div><input type='hidden' name='page' value='1'></div> </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_where = "where (device.hostname like '%%" . $_REQUEST["filter"] . "%%' OR device.description like '%%" . $_REQUEST["filter"] . "%%')"; }else{ $sql_where = ""; } if (get_request_var_request("status") == "-1") { /* Show all items */ }elseif (get_request_var_request("status") == "-2") { $sql_where .= (strlen($sql_where) ? " and device.disabled='on'" : "where device.disabled='on'"); }elseif (get_request_var_request("status") == "-3") { $sql_where .= (strlen($sql_where) ? " and device.disabled=''" : "where device.disabled=''"); }elseif (get_request_var_request("status") == "-4") { $sql_where .= (strlen($sql_where) ? " and (device.status!='3' or device.disabled='on')" : "where (device.status!='3' or device.disabled='on')"); }else { $sql_where .= (strlen($sql_where) ? " and (device.status=" . $_REQUEST["status"] . " AND device.disabled = '')" : "where (device.status=" . $_REQUEST["status"] . " AND device.disabled = '')"); } if (get_request_var_request("template_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("template_id") == "0") { $sql_where .= (strlen($sql_where) ? " and device.device_template_id=0" : "where device.device_template_id=0"); }elseif (!empty($_REQUEST["template_id"])) { $sql_where .= (strlen($sql_where) ? " and device.device_template_id=" . $_REQUEST["template_id"] : "where device.device_template_id=" . $_REQUEST["template_id"]); } if (get_request_var_request("poller") == "-1") { /* Show all items */ }elseif (get_request_var_request("poller") == "0") { $sql_where .= (strlen($sql_where) ? " and device.poller_id=0" : "where device.poller_id=0"); }elseif (!empty($_REQUEST["poller"])) { $sql_where .= (strlen($sql_where) ? " and device.poller_id=" . $_REQUEST["poller"] : "where device.poller_id=" . $_REQUEST["poller"]); } if (get_request_var_request("site") == "-1") { /* Show all items */ }elseif (get_request_var_request("site") == "0") { $sql_where .= (strlen($sql_where) ? " and device.site_id=0" : "where device.site_id=0"); }elseif (!empty($_REQUEST["site"])) { $sql_where .= (strlen($sql_where) ? " and device.site_id=" . $_REQUEST["site"] : "where device.site_id=" . $_REQUEST["site"]); } html_start_box("", "100", $colors["header"], "0", "center", ""); $total_rows = db_fetch_cell("select COUNT(device.id) from device $sql_where"); if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_device"); }else{ $rows = get_request_var_request("rows"); } $sortby = $_REQUEST["sort_column"]; if ($sortby=="hostname") { $sortby = "INET_ATON(hostname)"; } $device_graphs = array_rekey(db_fetch_assoc("SELECT device_id, count(*) as graphs FROM graph_local GROUP BY device_id"), "device_id", "graphs"); $device_data_sources = array_rekey(db_fetch_assoc("SELECT device_id, count(*) as data_sources FROM data_local GROUP BY device_id"), "device_id", "data_sources"); $sql_query = "SELECT device.*, poller.description AS poller, sites.name AS site FROM device LEFT JOIN poller ON device.poller_id=poller.id LEFT JOIN sites ON device.site_id=sites.id $sql_where ORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . " LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows; //print $sql_query; $devices = db_fetch_assoc($sql_query); /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 13, "devices.php"); print $nav; html_end_box(false); $display_text = array( "description" => array(__("Description"), "ASC"), "device.hostname" => array(__("Hostname"), "ASC"), "id" => array(__("ID"), "ASC"), "nosort1" => array(__("Graphs"), "ASC"), "nosort2" => array(__("Data Sources"), "ASC"), "status" => array(__("Status"), "ASC"), "status_event_count" => array(__("Event Count"), "ASC"), "cur_time" => array(__("Current (ms)"), "DESC"), "avg_time" => array(__("Average (ms)"), "DESC"), "availability" => array(__("Availability"), "ASC"), "polling_time" => array(__("Poll Time"), "DESC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($devices) > 0) { foreach ($devices as $device) { $spanextra = ""; if($device["disabled"] != CHECKED && $device["status"] == DEVICE_DOWN) { $date = __date("D, " . date_time_format() . " T", strtotime($device['status_fail_date'])); $spanextra = 'title="' . __("Down since %s with error: '%s'", $date, $device['status_last_error']) . '"'; } form_alternate_row_color('line' . $device["id"], true); form_selectable_cell("<a style='white-space:nowrap;' class='linkEditMain' href='" . htmlspecialchars("devices.php?action=edit&id=" . $device["id"]) . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $device["description"]) : $device["description"]) . "</a>", $device["id"]); form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $device["hostname"]) : $device["hostname"]), $device["id"]); form_selectable_cell(round(($device["id"]), 2), $device["id"]); form_selectable_cell((isset($device_graphs[$device["id"]]) ? $device_graphs[$device["id"]] : 0), $device["id"]); form_selectable_cell((isset($device_data_sources[$device["id"]]) ? $device_data_sources[$device["id"]] : 0), $device["id"]); form_selectable_cell( "<span $spanextra>".get_colored_device_status(($device["disabled"] == CHECKED ? true : false), $device["status"]) . "</span>", $device["id"]); form_selectable_cell(round(($device["status_event_count"]), 2), $device["id"]); form_selectable_cell(round(($device["cur_time"]), 2), $device["id"]); form_selectable_cell(round(($device["avg_time"]), 2), $device["id"]); form_selectable_cell(round($device["availability"], 2), $device["id"]); form_selectable_cell(round($device["polling_time"], 2), $device["id"]); form_checkbox_cell($device["description"], $device["id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Hosts") . "</em></td></tr>"; } print "</table>\n"; /* add a list of tree names to the actions dropdown */ $device_actions = array_merge($device_actions, api_tree_add_tree_names_to_actions_array()); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); print "</form>\n"; }