From 8a1bc583fcf81faaf41cd355eb9f874aeb88a469 Mon Sep 17 00:00:00 2001 From: Reinhard Scheck Date: Tue, 17 Jul 2007 20:08:44 +0000 Subject: [PATCH] Host Template List now with Filtering and Pagination git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cacti@4021 860744bd-22fc-0310-8c96-e9fe5004b5ca --- host_templates.php | 99 ++++++++++++++++--- .../html/inc_host_template_filter_table.php | 21 ++++ 2 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 include/html/inc_host_template_filter_table.php 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 = " + + + + \n + \n + \n + +
+ << "; if ($_REQUEST["page"] > 1) { $nav .= ""; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= ""; } $nav .= " + + 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] + + "; 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"; + + print $nav; + $display_text = array( "name" => array("Template Title", "ASC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); - $host_templates = db_fetch_assoc("SELECT * - FROM host_template - ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction']); - $i = 0; - if (sizeof($host_templates) > 0) { - foreach ($host_templates as $host_template) { - form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; - ?> + if (sizeof($template_list) > 0) { + foreach ($template_list as $template) { + form_alternate_row_color($colors["alternate"],$colors["light"],$i); + ?> - "> + ">\\1", $template["name"]);?> - "> + "> - - + No Host Templates\n"; } diff --git a/include/html/inc_host_template_filter_table.php b/include/html/inc_host_template_filter_table.php new file mode 100644 index 000000000..7bac99b8d --- /dev/null +++ b/include/html/inc_host_template_filter_table.php @@ -0,0 +1,21 @@ + "> +
+ + + + + + + +
+ Search:  + + "> + +   + +
+ + +
+