diff --git a/host_templates.php b/host_templates.php index 5f41b5076..4e4bea42a 100644 --- a/host_templates.php +++ b/host_templates.php @@ -25,6 +25,8 @@ include("./include/auth.php"); include_once("./lib/utility.php"); +define("MAX_DISPLAY_PAGES", 21); + $host_actions = array( 1 => "Delete", 2 => "Duplicate" @@ -361,47 +363,114 @@ function template_edit() { function template() { global $colors, $host_actions; + /* ================= input validation ================= */ + 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 */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } - /* clean up search string */ + /* 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_host_template_current_page"); + kill_session_var("sess_host_template_filter"); + kill_session_var("sess_host_template_sort_column"); + kill_session_var("sess_host_template_sort_direction"); + + unset($_REQUEST["page"]); + unset($_REQUEST["filter"]); + unset($_REQUEST["sort_column"]); + unset($_REQUEST["sort_direction"]); + } + /* remember these search fields in session vars so we don't have to keep passing them around */ - load_current_session_value("sort_column", "sess_host_template_column", "name"); + load_current_session_value("page", "sess_host_template_current_page", "1"); + load_current_session_value("filter", "sess_host_template_filter", ""); + load_current_session_value("sort_column", "sess_host_template_sort_column", "name"); load_current_session_value("sort_direction", "sess_host_template_sort_direction", "ASC"); display_output_messages(); html_start_box("Host Templates", "98%", $colors["header"], "3", "center", "host_templates.php?action=edit"); + include("./include/html/inc_graph_template_filter_table.php"); + + html_end_box(); + + /* form the 'where' clause for our main sql query */ + $sql_where = "WHERE (host_template.name LIKE '%%" . $_REQUEST["filter"] . "%%')"; + + html_start_box("", "98%", $colors["header"], "3", "center", ""); + + $total_rows = db_fetch_cell("SELECT + COUNT(host_template.id) + FROM host_template + $sql_where"); + + $template_list = db_fetch_assoc("SELECT + host_template.id,host_template.name + FROM host_template + $sql_where + ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . + " LIMIT " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device")); + + /* generate page list */ + $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host_templates.php?filter=" . $_REQUEST["filter"]); + + $nav = "
| + << "; if ($_REQUEST["page"] > 1) { $nav .= ""; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= ""; } $nav .= " + | \n ++ Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select] + | \n ++ "; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= ""; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= ""; } $nav .= " >> + | \n +