From 300e01c186ef2cb665fe841410d741c096ae9170 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 22 Nov 2023 10:10:35 +0100 Subject: [PATCH] #12502 Fixed filter --- .../include/ajax/dashboard.ajax.php | 22 ++++- .../include/lib/Dashboard/Manager.php | 20 +---- pandora_console/views/dashboard/list.php | 80 +++---------------- 3 files changed, 30 insertions(+), 92 deletions(-) diff --git a/pandora_console/include/ajax/dashboard.ajax.php b/pandora_console/include/ajax/dashboard.ajax.php index f07d1aee57..50a0e0b7a1 100644 --- a/pandora_console/include/ajax/dashboard.ajax.php +++ b/pandora_console/include/ajax/dashboard.ajax.php @@ -99,10 +99,26 @@ if ($method === 'draw') { $table->data = []; + $where_name = ''; if (strlen($filter['free_search']) > 0) { - $where = 'WHERE name LIKE "%'.$filter['free_search'].'%"'; - } else { - $where = ''; + $where_name = 'name LIKE "%'.$filter['free_search'].'%"'; + } + + $where_group = ''; + if (empty($filter['group']) === false && $filter['group'] !== '0') { + $where_group = sprintf('id_group = %s', $filter['group']); + if (empty($where_name) === false) { + $where_group = 'AND '.$where_group; + } + } + + $where = ''; + if (empty($where_name) === false || empty($where_group) === false) { + $where = sprintf( + 'WHERE %s %s', + $where_name, + $where_group + ); } $sql = 'SELECT * FROM tdashboard '.$where.' ORDER BY id '.$pagination; diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 181777b405..40b6d2d1a0 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -731,8 +731,7 @@ class Manager implements PublicLogin int $limit=-1, bool $favourite=false, bool $slideshow=false, - string $id_user='', - array $rowFilter=[] + string $id_user='' ):array { global $config; @@ -750,14 +749,6 @@ class Manager implements PublicLogin $sql_where .= 'AND td.cells_slideshow = 1'; } - if (empty((int) $rowFilter['id_group']) === false) { - $sql_where .= ' AND td.id_group = '.$rowFilter['id_group']; - } - - if (empty($rowFilter['name_filter']) === false) { - $sql_where .= ' AND td.name like "%'.$rowFilter['name_filter'].'%"'; - } - if (empty($id_user) === true) { $id_user = $config['id_user']; } @@ -953,13 +944,6 @@ class Manager implements PublicLogin private function showList() { global $config; - $id_group_filter = \get_parameter_post('id_group', ''); - $name_filter = \get_parameter_post('name', ''); - - $rowFilter = [ - 'id_group' => $id_group_filter, - 'name_filter' => $name_filter, - ]; $limit_sql = $config['block_size']; @@ -973,7 +957,7 @@ class Manager implements PublicLogin $resultCopy = $this->copy(); } - $dashboards = $this->getDashboards($this->offset, $limit_sql, false, false, '', $rowFilter); + $dashboards = $this->getDashboards($this->offset, $limit_sql); $count = $this->getDashboardsCount(); View::render( diff --git a/pandora_console/views/dashboard/list.php b/pandora_console/views/dashboard/list.php index 657f0a8683..aae6778f6d 100644 --- a/pandora_console/views/dashboard/list.php +++ b/pandora_console/views/dashboard/list.php @@ -67,74 +67,6 @@ if (isset($resultCopy) === true) { ); } -// Filter table. -$filter_id_group = \get_parameter_post('id_group', ''); -$filter_name = \get_parameter_post('name', ''); - -$filterTable = new stdClass(); -$filterTable->class = 'filter-table-adv w100p'; -$filterTable->size[0] = '20%'; -$filterTable->size[1] = '20%'; -$filterTable->data = []; - -$filterTable->data[0][0] = html_print_label_input_block( - __('Group'), - html_print_select_groups( - false, - 'AR', - true, - 'id_group', - $filter_id_group, - '', - '', - '', - true, - false, - true, - 'w100p', - false, - '' - ) -); - -$filterTable->data[0][1] = html_print_label_input_block( - __('Name'), - html_print_input_text('name', $filter_name, '', 25, 80, true) -); - -$form_html = ''; - -ui_toggle( - $form_html, - ''.__('Filter').'', - 'dashboard_search', - false, - true, - false, - '', - 'white-box-content', - 'box-flat white_table_graph fixed_filter_bar' -); - - if (empty($dashboards) === true) { ui_print_info_message( [ @@ -189,15 +121,21 @@ if (empty($dashboards) === true) { 'form' => [ 'inputs' => [ [ - 'label' => __('Free search'), + 'label' => __('Name'), 'type' => 'text', - 'class' => 'w400px', + 'class' => 'w80p', 'id' => 'free_search', 'name' => 'free_search', ], + [ + 'label' => __('Group'), + 'type' => 'select_groups', + 'id' => 'group', + 'name' => 'group', + ], ], ], - 'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar ', + 'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar', 'csv' => false, ] );