From a3a8d7aa7e77767870b57c8661095b1bf2fad456 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Tue, 17 Dec 2024 15:22:54 -0500 Subject: [PATCH] QA: Moving more pages to the Filter Class * There are just a few more easy ones. Looking at a few more class improvements too. --- aggregate_templates.php | 103 ++--------------------------- automation_snmp.php | 115 ++------------------------------ automation_templates.php | 111 ++----------------------------- color_templates.php | 102 ++--------------------------- data_input.php | 113 ++------------------------------ data_queries.php | 109 ++----------------------------- data_source_profiles.php | 137 ++------------------------------------- gprint_presets.php | 129 ++---------------------------------- lib/html_filter.php | 7 +- links.php | 99 ++-------------------------- managers.php | 110 ++----------------------------- sites.php | 109 ++----------------------------- 12 files changed, 62 insertions(+), 1182 deletions(-) diff --git a/aggregate_templates.php b/aggregate_templates.php index af15547003..e91a340236 100644 --- a/aggregate_templates.php +++ b/aggregate_templates.php @@ -540,42 +540,12 @@ function changeTotalsType() { function aggregate_template() { global $actions, $item_rows, $config; - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'pgt.name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ), - 'has_graphs' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array('options' => array('regexp' => '(true|false)')), - 'pageset' => true, - 'default' => read_config_option('default_has') == 'on' ? 'true' : 'false' - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('Aggregate Templates'), 'aggregate_templates.php', 'forms', 'sess_agg_tmp', 'aggregate_templates.php?action=edit'); - validate_store_request_vars($filters, 'sess_agg_tmp'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Templates'); + $pageFilter->set_sort_array('pgt.name', 'ASC'); + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -583,67 +553,6 @@ function aggregate_template() { $rows = get_request_var('rows'); } - html_filter_start_box(__('Aggregate Templates'), 'aggregate_templates.php?action=edit'); - - $filter_html = ' - -
- - - - - - - - - -
- ' . __('Search') . ' - - - - ' . __('Templates') . ' - - - - - - - - - - - - -
-
- - '; - - print $filter_html; - - html_end_box(); - /* form the 'where' clause for our main sql query */ $sql_where = ''; @@ -691,7 +600,7 @@ function aggregate_template() { 'align' => 'right', 'tip' => __('Aggregate Templates that are in use can not be Deleted. In use is defined as being referenced by an Aggregate.') ), - 'graphs.graphs' => array( + 'nosort1' => array( 'display' => __('Graphs Using'), 'align' => 'right', 'sort' => 'DESC' diff --git a/automation_snmp.php b/automation_snmp.php index 407c28c094..2dd2d055a1 100644 --- a/automation_snmp.php +++ b/automation_snmp.php @@ -878,35 +878,12 @@ function automation_snmp_edit() { function automation_snmp() { global $config, $item_rows, $actions; - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('SNMP Options'), 'automation_snmp.php', 'snmp_form', 'sess_autom_snmp', 'automation_snmp.php?action=edit'); - validate_store_request_vars($filters, 'sess_autom_snmp'); + $pageFilter->rows_label = __('Rules'); + $pageFilter->has_import = true; + $pageFilter->render(); if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); @@ -914,88 +891,6 @@ function automation_snmp() { $rows = get_request_var('rows'); } - html_filter_start_box(__('SNMP Options'), 'automation_snmp.php?action=edit'); - - ?> - - -
- - - - - - - - -
- - - '> - - - - - - - ' title=''> - ' title=''> - ' title=''> - -
-
- - - - array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('Device Rules'), 'automation_templates.php', 'snmp_at', 'sess_autot', 'automation_templates.php?action=edit'); - validate_store_request_vars($filters, 'sess_autot'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Templates'); + $pageFilter->has_import = true; + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -1574,93 +1560,6 @@ function template() { $rows = get_request_var('rows'); } - html_filter_start_box(__('Device Rules'), 'automation_templates.php?action=edit'); - - ?> - - -
- - - - - - - - -
- - - '> - - - - - - - ' title=''> - ' title=''> - ' title=''> - -
-
- - - - array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ), - 'has_graphs' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array('options' => array('regexp' => '(true|false)')), - 'pageset' => true, - 'default' => read_config_option('default_has') == 'on' ? 'true':'false' - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('Color Templates'), 'color_templates.php', 'form_template', 'sess_ct', 'color_templates.php?action=edit'); - validate_store_request_vars($filters, 'sess_ct'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Templates'); + $pageFilter->has_graphs = true; + $pageFilter->render(); if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); @@ -815,67 +786,6 @@ function color_template() { $rows = get_request_var('rows'); } - html_filter_start_box(__('Color Templates'), 'color_templates.php?action=template_edit'); - - $filter_html = ' - -
- - - - - - - - - -
- ' . __('Search') . ' - - - - ' . __('Color Templates') . ' - - - - - - - - - - - - -
-
- - '; - - print $filter_html; - - html_end_box(); - /* form the 'where' clause for our main sql query */ $sql_where = ''; diff --git a/data_input.php b/data_input.php index 960de51889..3bcf764280 100644 --- a/data_input.php +++ b/data_input.php @@ -709,36 +709,11 @@ function data_edit() { function data() { global $input_types, $actions, $item_rows, $hash_system_data_inputs; - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('Data Input Methods'), 'data_input.php', 'form_data_input', 'sess_data_input', 'data_input.php?action=edit'); - validate_store_request_vars($filters, 'sess_data_input'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Input Methods'); + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -746,86 +721,6 @@ function data() { $rows = get_request_var('rows'); } - html_filter_start_box(__('Data Input Methods'), 'data_input.php?action=edit'); - - ?> - - -
- - - - - - - - -
- - - '> - - - - - - - ' title=''> - ' title=''> - -
-
- - - - array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('Data Queries'), 'data_queries.php', 'form_data_queries', 'sess_dq', 'data_queries.php?action=edit'); - validate_store_request_vars($filters, 'sess_dq'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Data Queries'); + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -1287,82 +1262,6 @@ function data_query() { $rows = get_request_var('rows'); } - html_filter_start_box(__('Data Queries'), 'data_queries.php?action=edit'); - - ?> - - -
- - - - - - - - -
- - - '> - - - - - - - ' title=''> - ' title=''> - -
-
- - - - array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'step', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ), - 'has_data' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array('options' => array('regexp' => '(true|false)')), - 'pageset' => true, - 'default' => read_config_option('default_has') == 'on' ? 'true':'false' - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('Data Source Profiles'), 'data_source_profiles.php', 'snmp_dsp', 'sess_dsp', 'data_source_profiles.php?action=edit'); - validate_store_request_vars($filters, 'sess_dsp'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Profiles'); + $pageFilter->set_sort_array('step', 'ASC'); + $pageFilter->has_data = true; + $pageFilter->has_import = true; + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -1373,101 +1345,6 @@ function profile() { $rows = get_request_var('rows'); } - html_filter_start_box(__('Data Source Profiles'), 'data_source_profiles.php?action=edit'); - - ?> - - -
- - - - - - - - - -
- - - '> - - - - - - - > - - - - - ' title=''> - ' title=''> - ' title=''> - -
-
- - - - array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ), - 'has_graphs' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array('options' => array('regexp' => '(true|false)')), - 'pageset' => true, - 'default' => read_config_option('default_has') == 'on' ? 'true':'false' - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('GRPRINT Presets'), 'gprint_presets.php', 'form_gprint', 'sess_gp', 'gprint_presets.php?action=edit'); - validate_store_request_vars($filters, 'sess_gp'); - /* ================= input validation and session storage ================= */ + $pageFilter->rows_label = __('GPRINTs'); + $pageFilter->has_graphs = true; + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -227,95 +197,6 @@ function gprint_presets() { $rows = get_request_var('rows'); } - html_filter_start_box(__('GPRINT Presets'), 'gprint_presets.php?action=edit'); - - ?> - - -
- - - - - - - - - -
- - - '> - - - - - - - > - - - - - ' title=''> - ' title=''> - -
-
- - - - filter_array['sort'] = array( + $this->sort_array = array( 'sort_column' => $sort_column, 'sort_direction' => $sort_direction ); @@ -186,6 +187,10 @@ private function create_filter() { $this->filter_array = $this->create_default(); } + if ($this->sort_array !== false) { + $this->filter_array['sort'] = $this->sort_array; + } + // Make common adjustements if ($this->has_graphs) { if (isset_request_var('has_graphs')) { diff --git a/links.php b/links.php index b79d78efd0..169ae7d860 100644 --- a/links.php +++ b/links.php @@ -223,36 +223,12 @@ function form_actions() { function pages() { global $item_rows, $config, $actions; - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'sortorder', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('External Links'), 'links.php', 'links', 'sess_links', 'links.php?action=edit'); - validate_store_request_vars($filters, 'sess_links'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Receivers'); + $pageFilter->set_sort_array('sortorder', 'ASC'); + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -260,71 +236,6 @@ function pages() { $rows = get_request_var('rows'); } - html_filter_start_box(__('External Links'), 'links.php?action=edit'); - - ?> - - - - - - - __('Console'), 'TAB' => __('Top Tab'), diff --git a/managers.php b/managers.php index 5643cd83d9..1d05284586 100644 --- a/managers.php +++ b/managers.php @@ -73,36 +73,12 @@ function manager() { global $config, $actions, $item_rows; - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'hostname', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('SNMP Notification Receivers'), 'managers.php', 'form_snmpagent_managers', 'sess_snmp_mgr', 'managers.php?action=edit'); - validate_store_request_vars($filters, 'sess_snmp_mgr'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Receivers'); + $pageFilter->set_sort_array('hostname', 'ASC'); + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -110,82 +86,6 @@ function manager() { $rows = get_request_var('rows'); } - html_filter_start_box(__('SNMP Notification Receivers'), 'managers.php?action=edit'); - - ?> - - -
- - - - - - - - -
- - - ' onChange='applyFilter()'> - - - - - - - ' title=''> - ' title=''> - -
-
- - - - array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('Sites'), 'sites.php', 'form_site', 'sess_site', 'sites.php?action=edit'); - validate_store_request_vars($filters, 'sess_site'); - /* ================= input validation ================= */ + $pageFilter->rows_label = __('Sites'); + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -528,82 +503,6 @@ function sites() { $rows = get_request_var('rows'); } - html_filter_start_box(__('Sites'), 'sites.php?action=edit'); - - ?> - - -
- - - - - - - - -
- - - '> - - - - - - - ' title=''> - ' title=''> - -
-
- - - -