From ef3d27f8cfc2f6c8f30853fa5379f07d8c004728 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 23 Dec 2024 17:53:24 -0500 Subject: [PATCH] QA: Migrate Remaining Automation to Filter Class + Fixes * All Automation Sections are not using Filter Class * Fixed some bugs relative to display * Enhanced the form_get_table_id() function to handle tabs + action * Finished migrating Tree rules to show matching items as a sub-tab * Some tab relabeling --- automation_graph_rules.php | 11 +- automation_tree_rules.php | 95 ++-- lib/api_automation.php | 981 ++++++++++++++----------------------- lib/html_utility.php | 12 +- 4 files changed, 414 insertions(+), 685 deletions(-) diff --git a/automation_graph_rules.php b/automation_graph_rules.php index f87c0aefc..310a91202 100644 --- a/automation_graph_rules.php +++ b/automation_graph_rules.php @@ -34,6 +34,9 @@ AUTOMATION_ACTION_GRAPH_DELETE => __('Delete'), ); +/* sanitize the tab */ +get_filter_request_var('tab', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-z_A-Z]+)$/'))); + /* set default action */ set_default_action(); @@ -654,7 +657,7 @@ function automation_graph_rules_edit() { $tabs = array( 'rule' => __('Rule'), 'hosts' => __('Matching Devices'), - 'objects' => __('Matching Objects') + 'objects' => __('Matching Indexes') ); html_sub_tabs($tabs, 'action=edit&id=' . get_request_var('id')); @@ -883,12 +886,6 @@ function automation_graph_rules() { $rows = get_request_var('rows'); } - if ((!empty($_SESSION['sess_autom_gr_status'])) && (!isempty_request_var('status'))) { - if ($_SESSION['sess_autom_gr_status'] != get_nfilter_request_var('status')) { - set_request_var('page', 1); - } - } - $sql_where = ''; $sql_params = array(); diff --git a/automation_tree_rules.php b/automation_tree_rules.php index 98add9925..367609ad6 100644 --- a/automation_tree_rules.php +++ b/automation_tree_rules.php @@ -35,6 +35,9 @@ AUTOMATION_ACTION_TREE_DELETE => __('Delete'), ); +/* sanitize the tab */ +get_filter_request_var('tab', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-z_A-Z]+)$/'))); + /* set default action */ set_default_action(); @@ -548,58 +551,56 @@ function automation_tree_rules_item_edit() { get_filter_request_var('id'); get_filter_request_var('item_id'); get_filter_request_var('rule_type'); - get_filter_request_var('show_trees'); /* ==================================================== */ - /* handle show_trees mode */ - if (isset_request_var('show_trees')) { - if (get_request_var('show_trees') == '0') { - kill_session_var('automation_tree_rules_show_trees'); - } elseif (get_request_var('show_trees') == '1') { - $_SESSION['automation_tree_rules_show_trees'] = true; - } - } + if (!isempty_request_var('id')) { + $tabs = array( + 'rule' => __('Rule Item') + ); + + if (!isempty_request_var('rule_type') && !isempty_request_var('item_id')) { + if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_TREE_ACTION) { + $item = db_fetch_row_prepared('SELECT * + FROM automation_tree_rule_items + WHERE id = ?', + array(get_request_var('item_id'))); - if (!isempty_request_var('rule_type') && !isempty_request_var('item_id')) { - if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_TREE_ACTION) { - $item = db_fetch_row_prepared('SELECT * FROM automation_tree_rule_items WHERE id = ?', array(get_request_var('item_id'))); - - if ($item['field'] != AUTOMATION_TREE_ITEM_TYPE_STRING) { - ?> - - - - -
*'>
-
-
- __('Rule Item') + ); + + html_sub_tabs($tabs, 'action=item_edit&id=' . get_request_var('id') . '&item_id=' . get_request_var('item_id') . '&rule_type=' . get_request_var('rule_type')); } - global_item_edit(get_request_var('id'), get_request_var('item_id'), get_request_var('rule_type')); + if (!isset_request_var('tab') || get_request_var('tab') == 'rule') { + global_item_edit(get_request_var('id'), get_request_var('item_id'), get_request_var('rule_type')); - form_hidden_box('rule_type', get_request_var('rule_type'), get_request_var('rule_type')); - form_hidden_box('id', (isset_request_var('id') ? get_request_var('id') : '0'), ''); - form_hidden_box('item_id', (isset_request_var('item_id') ? get_request_var('item_id') : '0'), ''); + form_hidden_box('rule_type', get_request_var('rule_type'), get_request_var('rule_type')); + form_hidden_box('id', (isset_request_var('id') ? get_request_var('id') : '0'), ''); + form_hidden_box('item_id', (isset_request_var('item_id') ? get_request_var('item_id') : '0'), ''); - if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_TREE_MATCH) { - form_hidden_box('save_component_automation_match_item', '1', ''); - } else { - form_hidden_box('save_component_automation_tree_rule_item', '1', ''); - } - form_save_button('automation_tree_rules.php?action=edit&id=' . get_request_var('id') . '&rule_type=' . get_request_var('rule_type')); - print '
'; - - /* display list of matching trees */ - if (!isempty_request_var('rule_type') && !isempty_request_var('item_id')) { - if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_TREE_ACTION) { - if (isset($_SESSION['automation_tree_rules_show_trees']) && ($item['field'] != AUTOMATION_TREE_ITEM_TYPE_STRING)) { - if ($_SESSION['automation_tree_rules_show_trees']) { - display_matching_trees(get_request_var('id'), AUTOMATION_RULE_TYPE_TREE_ACTION, $item, 'automation_tree_rules.php?action=item_edit&id=' . get_request_var('id') . '&item_id=' . get_request_var('item_id') . '&rule_type=' . get_request_var('rule_type')); - } - } + if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_TREE_MATCH) { + form_hidden_box('save_component_automation_match_item', '1', ''); + } else { + form_hidden_box('save_component_automation_tree_rule_item', '1', ''); + } + + form_save_button('automation_tree_rules.php?action=edit&id=' . get_request_var('id') . '&rule_type=' . get_request_var('rule_type')); + } elseif (!isempty_request_var('rule_type') && !isempty_request_var('item_id')) { + /* display list of matching trees */ + if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_TREE_ACTION && + $item['field'] != AUTOMATION_TREE_ITEM_TYPE_STRING) { + display_matching_trees(get_request_var('id'), AUTOMATION_RULE_TYPE_TREE_ACTION, $item, 'automation_tree_rules.php?action=item_edit&id=' . get_request_var('id') . '&item_id=' . get_request_var('item_id') . '&rule_type=' . get_request_var('rule_type')); } } @@ -712,7 +713,7 @@ function automation_tree_rules_edit() { ); } - html_sub_tabs($tabs, 'action=edit&id=' . get_request_var('id')); + html_sub_tabs($tabs, 'action=edit&id=' . get_filter_request_var('id')); $header_label = __esc('Tree Rule Selection [edit: %s]', $rule['name']); } else { @@ -720,7 +721,7 @@ function automation_tree_rules_edit() { 'rule' => __('Rule') ); - html_sub_tabs($tabs, 'action=edit&id=' . get_request_var('id')); + html_sub_tabs($tabs, 'action=edit&id=' . get_filter_request_var('id')); $header_label = __('Tree Rules Selection [new]'); } @@ -791,9 +792,9 @@ function automation_tree_rules_edit() { form_save_button('automation_tree_rules.php', 'return'); } elseif ($rule['leaf_type'] == TREE_ITEM_TYPE_HOST) { - display_matching_hosts($rule, AUTOMATION_RULE_TYPE_TREE_MATCH, 'automation_tree_rules.php?action=edit&id=' . get_request_var('id')); + display_matching_hosts($rule, AUTOMATION_RULE_TYPE_TREE_MATCH, 'automation_tree_rules.php?action=edit&tab=hosts&id=' . get_request_var('id')); } elseif ($rule['leaf_type'] == TREE_ITEM_TYPE_GRAPH) { - display_matching_graphs($rule, AUTOMATION_RULE_TYPE_TREE_MATCH, 'automation_tree_rules.php?action=edit&id=' . get_request_var('id')); + display_matching_graphs($rule, AUTOMATION_RULE_TYPE_TREE_MATCH, 'automation_tree_rules.php?action=edit&tab=graphs&id=' . get_request_var('id')); } ?> diff --git a/lib/api_automation.php b/lib/api_automation.php index 334ac6677..26def8324 100644 --- a/lib/api_automation.php +++ b/lib/api_automation.php @@ -22,122 +22,121 @@ +-------------------------------------------------------------------------+ */ -function display_matching_hosts($rule, $rule_type, $url) { - global $device_actions, $item_rows; +function create_tree_devices_filter($rows_label = '') { + global $item_rows; - $details = automation_get_matching_device_sql($rule, $rule_type); + if ($rows_label == '') { + $rows_label = __('Devices'); + } - html_start_box(__('Matching Devices'), '100%', '', '3', 'center', ''); - - ?> - - -
- - - - - - - - - - - - -
- - - '> - - - - - - - - - - - - - - - '> - '> - -
-
- - - - ' . __('No Matching Devices') . ''; + print '' . __('No Matching Devices') . ''; } html_end_box(false); @@ -244,83 +243,22 @@ function clearDeviceFilter() { } function automation_get_matching_device_sql(&$rule, $rule_type) { - if (isset_request_var('cleard')) { - set_request_var('clear', 'true'); - } - - /* ================= input validation and session storage ================= */ - $filters = array( - 'rowsd' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'paged' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'host_status' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'host_template_id' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'filterd' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'description', - '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' => 'true' - ) - ); - - validate_store_request_vars($filters, 'sess_auto'); - /* ================= input validation ================= */ - - if (isset_request_var('cleard')) { - unset_request_var('clear'); - } - /* if the number of rows is -1, set it to the default */ - if (get_request_var('rowsd') == -1) { + if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { - $rows = get_request_var('rowsd'); - } - - if ((!empty($_SESSION['sess_automation_host_status'])) && (!isempty_request_var('host_status'))) { - if ($_SESSION['sess_automation_host_status'] != get_request_var('host_status')) { - set_request_var('paged', '1'); - } + $rows = get_request_var('rows'); } /* form the 'where' clause for our main sql query */ - if (get_request_var('filterd') != '') { + if (get_request_var('filter') != '') { $sql_where = 'WHERE h.deleted = "" - AND (h.hostname LIKE ' . db_qstr('%' . get_request_var('filterd') . '%') . ' - OR h.description LIKE ' . db_qstr('%' . get_request_var('filterd') . '%') . ' - OR h.location LIKE ' . db_qstr('%' . get_request_var('filterd') . '%') . ' - OR h.external_id LIKE ' . db_qstr('%' . get_request_var('filterd') . '%') . ' - OR s.site LIKE ' . db_qstr('%' . get_request_var('filterd') . '%') . ' - OR ht.name LIKE ' . db_qstr('%' . get_request_var('filterd') . '%') . ')'; + AND (h.hostname LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' + OR h.description LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' + OR h.location LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' + OR h.external_id LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' + OR s.site LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' + OR ht.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')'; } else { $sql_where = "WHERE h.deleted = ''"; } @@ -331,7 +269,7 @@ function automation_get_matching_device_sql(&$rule, $rule_type) { $host_where_disabled = "(IFNULL(TRIM(h.disabled),'') == 'on')"; } - $host_where_status = get_request_var('host_status'); + $host_where_status = get_request_var('status'); if ($host_where_status == '-1') { /* Show all items */ @@ -406,53 +344,6 @@ function automation_get_matching_device_sql(&$rule, $rule_type) { } function automation_get_matching_graphs_sql($rule, $rule_type) { - /* ================= 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' - ), - 'host_id' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'template_id' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'title_cache', - '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' => 'true' - ) - ); - - validate_store_request_vars($filters, 'sess_autog'); - /* ================= input validation ================= */ - /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); @@ -527,7 +418,7 @@ function automation_get_matching_graphs_sql($rule, $rule_type) { h.disabled AS disabled, $sdisabled h.status, ht.name AS host_template_name, gtg.id, gtg.local_graph_id, gtg.height, gtg.width, - gtg.title_cache, gt.name, s.name AS site_name, h.locaiton + gtg.title_cache, gt.name, s.name AS site_name, h.location FROM host AS h INNER JOIN graph_local AS gl ON h.id = gl.host_id @@ -551,140 +442,135 @@ function automation_get_matching_graphs_sql($rule, $rule_type) { ); } -function display_matching_graphs($rule, $rule_type, $url) { - global $graph_actions, $item_rows; +function create_tree_graphs_filter() { + global $item_rows; - html_start_box(__('Matching Objects'), '100%', '', '3', 'center', ''); - - ?> - - -
- - - - - - - - -
- - - - - - - - - - '> - '> - -
- - - - - - - -
- - - '> - - - - -
-
- - - - __('Any'), + '-3' => __('Enabled'), + '-2' => __('Disabled'), + '-4' => __('Not Up'), + '3' => __('Up'), + '1' => __('Down'), + '2' => __('Recovering'), + '0' => __('Unknown') + ); + + return array( + 'rows' => array( + array( + 'filter' => array( + 'method' => 'textbox', + 'friendly_name' => __('Search'), + 'filter' => FILTER_DEFAULT, + 'placeholder' => __('Enter a search term'), + 'size' => '30', + 'default' => '', + 'pageset' => true, + 'max_length' => '120', + 'value' => '' + ), + 'host_id' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Device'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '-1', + 'pageset' => true, + 'array' => $rhosts, + 'value' => '-1' + ), + 'template_id' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Template'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '-1', + 'pageset' => true, + 'array' => $rtemplates, + 'value' => '-1' + ), + 'rows' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Graphs'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '-1', + 'pageset' => true, + 'array' => $item_rows, + 'value' => '-1' + ) + ) + ), + 'buttons' => array( + 'go' => array( + 'method' => 'submit', + 'display' => __('Go'), + 'title' => __('Apply Filter to Table'), + ), + 'clear' => array( + 'method' => 'button', + 'display' => __('Clear'), + 'title' => __('Reset Filter to Default Values'), + ) + ), + 'sort' => array( + 'sort_column' => 'title_cache', + 'sort_direction' => 'ASC' + ) + ); +} + +function process_sanitize_draw_tree_graphs_filter($render = false, $url = '') { + $filters = create_tree_graphs_filter(); + + $header = __('Matching Graphs'); + + /* create the page filter */ + $pageFilter = new CactiTableFilter($header, $url, 'forms', 'sess_auto_tgm'); + + $pageFilter->set_filter_array($filters); + + if ($render) { + $pageFilter->render(); + } else { + $pageFilter->sanitize(); + } +} + +function display_matching_graphs($rule, $rule_type, $url) { + global $graph_actions, $item_rows; + + process_sanitize_draw_tree_graphs_filter(true, $url); $details = automation_get_matching_graphs_sql($rule, $rule_type); $rows = $details['rows']; @@ -697,7 +583,7 @@ function clearFilter() { $graph_list = array(); } - $nav = html_nav_bar($url, MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 8, __('Devices'), 'page', 'main'); + $nav = html_nav_bar($url, MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 9, __('Graphs'), 'page', 'main'); print $nav; @@ -761,13 +647,15 @@ function clearFilter() { form_selectable_cell(filter_value($template_name, get_request_var('filter')), $graph['local_graph_id']); form_selectable_cell(filter_value($graph['description'], get_request_var('filter'), 'host.php?action=edit&id=' . $graph['host_id']), $graph['local_graph_id']); form_selectable_cell(filter_value($graph['hostname'], get_request_var('filter')), $graph['local_graph_id']); + form_selectable_cell(filter_value($graph['site_name'], get_request_var('filter')), $graph['local_graph_id']); + form_selectable_cell(filter_value($graph['location'], get_request_var('filter')), $graph['local_graph_id']); form_selectable_cell(filter_value($graph['host_template_name'], get_request_var('filter')), $graph['local_graph_id']); form_selectable_cell(get_colored_device_status((($graph['disabled'] == 'on' || $graph['site_disabled'] == 'on') ? true : false), $graph['status']), $graph['local_graph_id']); form_end_row(); } } else { - print '' . __('No Graphs Found') . ''; + print '' . __('No Graphs Found') . ''; } html_end_box(true); @@ -966,81 +854,10 @@ function automation_get_new_graphs_sql($rule) { function display_new_graphs($rule, $url) { global $config, $item_rows; - html_start_box(__('Matching Objects'), '100%', '', '3', 'center', ''); - - ?> - - -
- - - - - - - - -
- - - '> - - - - - - - '> - '> - -
-
- - - - rows_label = __('Objects'); + $pageFilter->render(); $details = automation_get_new_graphs_sql($rule); @@ -1057,11 +874,11 @@ function clearObjectFilter() { $rows = $details['rows']; $name = $details['name']; - $nav = html_nav_bar('automation_graph_rules.php?action=edit&id=' . $rule['id'], MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 30, __('Matching Objects'), 'page', 'main'); + $nav = html_nav_bar('automation_graph_rules.php?action=edit&id=' . $rule['id'], MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 30, __('Matching Indexes'), 'page', 'main'); print $nav; - html_start_box(__('Matching Objects [ %s ] ', html_escape($name)) . display_tooltip(__('A blue font color indicates that the rule will be applied to the objects in question. Other objects will not be subject to the rule.')), '100%', '', '3', 'center', ''); + html_start_box(__('Matching Indexes [ %s ] ', html_escape($name)) . display_tooltip(__('A blue font color indicates that the rule will be applied to the objects in question. Other objects will not be subject to the rule.')), '100%', '', '3', 'center', ''); /** * print the Data Query table's header @@ -1146,12 +963,35 @@ function clearObjectFilter() { print $nav; } } else { - print "" . __('Error in data query') . ''; + $display_text = array(__('Error Message')); + + html_start_box(__('Index Errors [ %s ]', html_escape($details['xml_array']['name'])), '100%', '', '3', 'center', ''); + html_header($display_text); + print "" . __('Error in data query') . ''; + html_end_box(); } print ''; } +function process_sanitize_draw_tree_items_filter($render = false, $url = '') { + $filters = create_tree_devices_filter(__('Data Queries')); + + $header = __('Matching Items'); + + /* create the page filter */ + $pageFilter = new CactiTableFilter($header, $url, 'forms', 'sess_auto_tim'); + $pageFilter->rows_label = __('Data Queries'); + + $pageFilter->set_filter_array($filters); + + if ($render) { + $pageFilter->render(); + } else { + $pageFilter->sanitize(); + } +} + function display_matching_trees($rule_id, $rule_type, $item, $url) { global $automation_tree_header_types; global $device_actions, $item_rows; @@ -1159,46 +999,7 @@ function display_matching_trees($rule_id, $rule_type, $item, $url) { $function = automation_function_with_pid(__FUNCTION__); cacti_log($function . " called: $rule_id/$rule_type", false, 'AUTOM8 TRACE', POLLER_VERBOSITY_HIGH); - /* ================= 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' - ), - 'host_template_id' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'host_status' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'description', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); - - validate_store_request_vars($filters, 'sess_autot'); - /* ================= input validation ================= */ + process_sanitize_draw_tree_items_filter(true, $url); if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); @@ -1206,123 +1007,6 @@ function display_matching_trees($rule_id, $rule_type, $item, $url) { $rows = get_request_var('rows'); } - if ((!empty($_SESSION['sess_automation_host_status'])) && (!isempty_request_var('host_status'))) { - if ($_SESSION['sess_automation_host_status'] != get_request_var('host_status')) { - set_request_var('page', '1'); - } - } - - html_start_box(__('Matching Items'), '100%', '', '3', 'center', ''); - - ?> - - -
- - - - - - - - - - - - -
- - - '> - - - - - - - - - - - - - - - '> - '> - -
-
- - - - array(__('Description'), 'ASC'), - 'hostname' => array(__('Hostname'), 'ASC'), - 'host_template_name' => array(__('Device Template Name'), 'ASC'), - 'status' => array(__('Status'), 'ASC'), - 'source' => array($item['field'], 'ASC'), - 'result' => array(__('Resulting Branch'), 'ASC'), + 'description' => array( + 'display' => __('Description'), + 'sort' => 'ASC' + ), + 'hostname' => array( + 'display' => __('Hostname'), + 'sort' => 'ASC' + ), + 'host_template_name' => array( + 'display' => __('Device Template Name'), + 'sort' => 'ASC' + ), + 'status' => array( + 'display' => __('Status'), + 'sort' => 'ASC' + ), + 'source' => array( + 'display' => $item['field'], + 'sort' => 'ASC' + ), + 'result' => array( + 'display' => __('Resulting Branch'), + 'sort' => 'ASC' + ), ); html_header_sort( @@ -1464,7 +1167,7 @@ function clearFilter() { get_request_var('sort_column'), get_request_var('sort_direction'), '1', - $url . '?action=edit&id=' . get_request_var('id') . '&page=' . get_request_var('page') + $url ); if (cacti_sizeof($templates)) { @@ -1498,7 +1201,7 @@ function clearFilter() { form_end_row(); } } else { - print "" . __('No Items Found') . ''; + print '' . __('No Items Found') . ''; } html_end_box(true); @@ -1511,6 +1214,8 @@ function clearFilter() { function api_automation_column_exists($column, $tables) { $column = str_replace(array('h.', 'ht.', 'gt.', 'gl.', 'gtg.'), array('', '', '', '', ''), $column); +cacti_log("The column is now $column"); + if (cacti_sizeof($tables)) { foreach($tables as $table) { if (db_column_exists($table, $column)) { @@ -1537,13 +1242,34 @@ function display_match_rule_items($title, $rule, $rule_type, $module) { html_start_box($title . ' ', '100%', '', '3', 'center', $module . '?action=item_edit&id=' . $rule_id . '&rule_type=' . $rule_type); $display_text = array( - array('display' => __('Item'), 'align' => 'left'), - array('display' => __('Sequence'), 'align' => 'left'), - array('display' => __('Operation'), 'align' => 'left'), - array('display' => __('Field'), 'align' => 'left'), - array('display' => __('Operator'), 'align' => 'left'), - array('display' => __('Pattern'), 'align' => 'left'), - array('display' => __('Actions'), 'align' => 'right') + array( + 'display' => __('Item'), + 'align' => 'left' + ), + array( + 'display' => __('Sequence'), + 'align' => 'left' + ), + array( + 'display' => __('Operation'), + 'align' => 'left' + ), + array( + 'display' => __('Field'), + 'align' => 'left' + ), + array( + 'display' => __('Operator'), + 'align' => 'left' + ), + array( + 'display' => __('Pattern'), + 'align' => 'left' + ), + array( + 'display' => __('Actions'), + 'align' => 'right' + ) ); html_header($display_text, 2); @@ -1605,9 +1331,12 @@ function display_match_rule_items($title, $rule, $rule_type, $module) { $i++; } } else { - print '' . __('No Device Selection Criteria') . ''; + print '' . __('No Device Selection Criteria') . ''; } + /* sanitize the variables */ + process_sanitize_draw_tree_devices_filter(); + $details = automation_get_matching_device_sql($rule, $rule_type); $data = db_fetch_assoc($details['rows_query']); @@ -1627,7 +1356,7 @@ function display_graph_rule_items($title, &$rule, $rule_type, $module) { ORDER BY sequence', array($rule_id)); - html_start_box($title . ' ', '100%', '', '3', 'center', $module . '?action=item_edit&id=' . $rule_id . '&rule_type=' . $rule_type); + html_start_box($title . ' ', '100%', '', '3', 'center', $module . '?action=item_edit&id=' . $rule_id . '&rule_type=' . $rule_type); $display_text = array( array('display' => __('Item'), 'align' => 'left'), @@ -1690,7 +1419,7 @@ function display_graph_rule_items($title, &$rule, $rule_type, $module) { $i++; } } else { - print '' . __('No Graph Creation Criteria') . ''; + print '' . __('No Graph Creation Criteria') . ''; } html_end_box(true); @@ -1744,7 +1473,7 @@ function display_tree_rule_items($title, $rule, $item_type, $rule_type, $module) form_alternate_row(); - $url = $module . '?action=item_edit&id=' . $rule_id. '&item_id=' . $item['id'] . '&rule_type=' . $rule_type; + $url = $module . '?action=item_edit&tab=rule&id=' . $rule_id. '&item_id=' . $item['id'] . '&rule_type=' . $rule_type; form_selectable_cell(filter_value(__('Item # %d', $i+1), '', $url), $i); form_selectable_cell($item['sequence'], $i); @@ -1788,7 +1517,7 @@ function display_tree_rule_items($title, $rule, $item_type, $rule_type, $module) $i++; } } else { - print '' . __('No Tree Creation Criteria') . ''; + print '' . __('No Tree Creation Criteria') . ''; } html_end_box(true); @@ -5698,7 +5427,7 @@ function automation_network_import($json_data) { break; case 'host_template': $template = db_fetch_row_prepared('SELECT id, name - FROM host_templates + FROM host_template WHERE hash = ?', array($coldata)); diff --git a/lib/html_utility.php b/lib/html_utility.php index 0327751ea..f7f112f1f 100644 --- a/lib/html_utility.php +++ b/lib/html_utility.php @@ -323,10 +323,12 @@ function form_selectable_cell($contents, $id, $width = '', $style_or_class = '', } function form_get_table_id() { - if (isset_request_var('action') && get_request_var('action') != '') { - return basename(get_current_page(), '.php') . ':action-' . get_request_var('action') . ':'; - } elseif (isset_request_var('tab') && get_request_var('tab') != '') { - return basename(get_current_page(), '.php') . ':tab-' . get_request_var('tab') . ':'; + if (isset_request_var('action') && get_nfilter_request_var('action') != '' && isset_request_var('tab') && get_nfilter_request_var('tab') != '') { + return basename(get_current_page(), '.php') . ':action-tab-' . get_nfilter_request_var('action') . '-' . get_nfilter_request_var('tab') . ':'; + } elseif (isset_request_var('action') && get_nfilter_request_var('action') != '') { + return basename(get_current_page(), '.php') . ':action-' . get_nfilter_request_var('action') . ':'; + } elseif (isset_request_var('tab') && get_nfilter_request_var('tab') != '') { + return basename(get_current_page(), '.php') . ':tab-' . get_nfilter_request_var('tab') . ':'; } else { return basename(get_current_page(), '.php') . ':'; } @@ -1146,7 +1148,7 @@ function update_order_string($inplace = false) { $direction = get_request_var('sort_direction'); if ($column == 'ip' || $column == 'ip_address') { - $_SESSION['sort_string'][$page] ='ORDER BY INET_ATON(' . $column . ') ' . $direction; + $_SESSION['sort_string'][$page] = 'ORDER BY INET_ATON(' . $column . ') ' . $direction; } else { $_SESSION['sort_string'][$page] = 'ORDER BY ' . $del . implode($del . '.'. $del, explode('.', get_request_var('sort_column'))) . $del . ' ' . get_request_var('sort_direction'); }