From c128f750e1d3b4a5f706aef88830bc2b583621df Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 30 Nov 2018 13:46:29 +0100 Subject: [PATCH 1/5] new fields form custom field view --- .../include/functions_custom_fields.php | 102 +++++++++++++++--- 1 file changed, 87 insertions(+), 15 deletions(-) diff --git a/pandora_console/include/functions_custom_fields.php b/pandora_console/include/functions_custom_fields.php index 90b6ebaa4e..a037ee700d 100644 --- a/pandora_console/include/functions_custom_fields.php +++ b/pandora_console/include/functions_custom_fields.php @@ -191,7 +191,7 @@ function get_custom_fields_data ($custom_field_name) { } function agent_counters_custom_fields($filters){ - //filter by status + //filter by status agent $and_status = ""; if(is_array($filters['id_status'])){ if(!in_array(-1, $filters['id_status'])){ @@ -241,17 +241,100 @@ function agent_counters_custom_fields($filters){ } } + //filter by status module + $and_module_status = ""; + if(is_array($filters['module_status'])){ + if(!in_array(-1, $filters['module_status'])){ + if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['module_status'])){ + if(count($filters['module_status']) > 0){ + $and_module_status = " AND ( "; + foreach ($filters['module_status'] as $key => $value) { + $and_module_status .= ($key != 0) + ? " OR (" + : " ("; + switch ($value) { + default: + case AGENT_STATUS_NORMAL: + $and_module_status .= " tae.estado = 0 OR tae.estado = 300 ) "; + break; + case AGENT_STATUS_CRITICAL: + $and_module_status .= " tae.estado = 1 OR tae.estado = 100 ) "; + break; + case AGENT_STATUS_WARNING: + $and_module_status .= " tae.estado = 2 OR tae.estado = 200 ) "; + break; + case AGENT_STATUS_UNKNOWN: + $and_module_status .= " tae.estado = 3 ) "; + break; + case AGENT_STATUS_NOT_INIT: + $and_module_status .= " tae.estado = 4 OR tae.estado = 5 ) "; + break; + } + } + $and_module_status .= " ) "; + } + } + else{ + //not normal + $and_module_status = "AND tae.estado <> 0 AND tae.estado <> 300 "; + } + } + } + + //filters module + if($filters['module_search']){ + $and_module_search = 'AND nombre LIKE "%' . $filters['module_search'] . '%"'; + } + + $module_filter = ""; + if($and_module_search != '' || $and_module_status != ''){ + $module_filter = ' AND ( + SELECT count(*) AS n + FROM tagente_modulo tam + INNER JOIN tagente_estado tae + ON tae.id_agente_modulo = tam.id_agente + WHERE tam.id_agente=ta.id_agente + '. $and_module_search . ' ' . $and_module_status .' + ) > 0 '; + } + //filter group and check ACL groups $groups_and = ""; if (!users_can_manage_group_all("AR")) { - if(!$filters['group']){ - $id_groups = explode(", ", array_keys(users_get_groups())); + if($filters['group']){ + $user_groups = array_keys(users_get_groups()); + $id_groups = implode(", ", $user_groups); $groups_and = " AND (ta.id_grupo IN ($id_groups) OR tasg.id_group IN($id_groups))"; } } if($filters['group']){ - $groups_and = " AND (ta.id_grupo =". $filters['group']." OR tasg.id_group =". $filters['group'].")"; + //recursion check acl + if($filters['recursion']){ + $recursion_groups = groups_get_id_recursive($filters['group'], true); + if (!users_can_manage_group_all("AR")) { + if(isset($user_groups) && is_array($user_groups)){ + $groups_intersect = array_intersect($user_groups, $recursion_groups); + if(isset($groups_intersect) && is_array($groups_intersect)){ + $groups_intersect = implode(", ", $groups_intersect); + $groups_and = " AND (ta.id_grupo IN ($groups_intersect) OR tasg.id_group IN($groups_intersect))"; + } + else{ + return false; + } + } + else{ + return false; + } + } + else{ + $recursion_groups = implode(", ", $recursion_groups); + $groups_and = " AND (ta.id_grupo IN ($recursion_groups) OR tasg.id_group IN($recursion_groups))"; + } + } + else{ + $groups_and = " AND (ta.id_grupo =". $filters['group']." OR tasg.id_group =". $filters['group'].")"; + } } //filter custom data @@ -264,17 +347,6 @@ function agent_counters_custom_fields($filters){ //filter custom name $custom_field_name = $filters['id_custom_fields']; - //filters module - $module_filter = ""; - if($filters['module_search']){ - $module_filter = ' AND ( - SELECT count(*) AS n - FROM tagente_modulo - WHERE nombre LIKE "%' . $filters['module_search'] . '%" - AND id_agente=ta.id_agente - ) > 0 '; - } - if(is_metaconsole()){ $metaconsole_connections = metaconsole_get_connection_names(); // For all nodes From 01a9621eb528ebc67a921f95a0afd1491743cc0e Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 3 Dec 2018 11:36:34 +0100 Subject: [PATCH 2/5] Custom fields view add new filters --- pandora_console/extras/mr/23.sql | 9 +++ .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 8 ++- .../include/ajax/custom_fields.php | 6 +- .../include/functions_custom_fields.php | 62 ++++++++++--------- pandora_console/pandoradb.sql | 2 + pandora_console/pandoradb_data.sql | 4 +- 6 files changed, 56 insertions(+), 35 deletions(-) create mode 100644 pandora_console/extras/mr/23.sql diff --git a/pandora_console/extras/mr/23.sql b/pandora_console/extras/mr/23.sql new file mode 100644 index 0000000000..e14f68a304 --- /dev/null +++ b/pandora_console/extras/mr/23.sql @@ -0,0 +1,9 @@ +START TRANSACTION; + +--ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `module_status` varchar(600) default ''; + +ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `module_status` varchar(600) default ''; + +ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `recursion` int(1) unsigned default '0'; + +COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index e27569a0cf..5b81170b8c 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1180,13 +1180,13 @@ ALTER TABLE titem MODIFY `source_data` int(10) unsigned; INSERT INTO `tconfig` (`token`, `value`) VALUES ('big_operation_step_datos_purge', '100'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('small_operation_step_datos_purge', '1000'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('days_autodisable_deletion', '30'); -INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 22); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 23); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_docs_logo', 'default_docs.png'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_support_logo', 'default_support.png'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png'); UPDATE tconfig SET value = 'https://licensing.artica.es/pandoraupdate7/server.php' WHERE token='url_update_manager'; DELETE FROM `tconfig` WHERE `token` = 'current_package_enterprise'; -INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '729'); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '730'); -- --------------------------------------------------------------------- -- Table `tconfig_os` @@ -1826,3 +1826,7 @@ CREATE TABLE IF NOT EXISTS `tagent_custom_fields_filter` ( `module_search` varchar(600) default '', PRIMARY KEY(`id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `module_status` varchar(600) default ''; + +ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `recursion` int(1) unsigned default '0'; diff --git a/pandora_console/include/ajax/custom_fields.php b/pandora_console/include/ajax/custom_fields.php index 91a3ddb115..566ac0e8d1 100644 --- a/pandora_console/include/ajax/custom_fields.php +++ b/pandora_console/include/ajax/custom_fields.php @@ -40,7 +40,6 @@ if ($get_custom_fields_data){ return; } - if($build_table_custom_fields){ $order = get_parameter("order", ''); $length = get_parameter("length", 20); @@ -237,6 +236,7 @@ if($build_table_child_custom_fields){ $id_agent = get_parameter("id_agent", 0); $id_server = get_parameter("id_server", 0); $module_search = str_replace('amp;', '',get_parameter("module_search", '')); + $module_status = str_replace('amp;', '',get_parameter("module_status", '')); if(!$id_server || !$id_agent){ return false; @@ -534,6 +534,8 @@ if($create_filter_cf){ $values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']); $values['id_status'] = json_encode($filters['id_status']); $values['module_search'] = $filters['module_search']; + $values['module_status'] = json_encode($filters['module_status']); + $values['recursion'] = $filters['recursion']; $insert = db_process_sql_insert('tagent_custom_fields_filter', $values); @@ -599,6 +601,8 @@ if($update_filter_cf){ $values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']); $values['id_status'] = json_encode($filters['id_status']); $values['module_search'] = $filters['module_search']; + $values['module_status'] = json_encode($filters['module_status']); + $values['recursion'] = $filters['recursion']; //update $update = db_process_sql_update('tagent_custom_fields_filter', $values, $condition); diff --git a/pandora_console/include/functions_custom_fields.php b/pandora_console/include/functions_custom_fields.php index a037ee700d..7b18fb0b0d 100644 --- a/pandora_console/include/functions_custom_fields.php +++ b/pandora_console/include/functions_custom_fields.php @@ -292,7 +292,7 @@ function agent_counters_custom_fields($filters){ SELECT count(*) AS n FROM tagente_modulo tam INNER JOIN tagente_estado tae - ON tae.id_agente_modulo = tam.id_agente + ON tae.id_agente_modulo = tam.id_agente_modulo WHERE tam.id_agente=ta.id_agente '. $and_module_search . ' ' . $and_module_status .' ) > 0 '; @@ -457,36 +457,38 @@ function agent_counters_custom_fields($filters){ ); foreach ($result_meta as $k => $nodo) { - foreach ($nodo as $key => $value) { - //Sum counters total - $final_result['counters_total']['t_m_normal'] += $value['m_normal']; - $final_result['counters_total']['t_m_critical'] += $value['m_critical']; - $final_result['counters_total']['t_m_warning'] += $value['m_warning']; - $final_result['counters_total']['t_m_unknown'] += $value['m_unknown']; - $final_result['counters_total']['t_m_not_init'] += $value['m_not_init']; - $final_result['counters_total']['t_m_alerts'] += $value['m_alerts']; - $final_result['counters_total']['t_m_total'] += $value['m_total']; - $final_result['counters_total']['t_a_critical'] += $value['a_critical']; - $final_result['counters_total']['t_a_warning'] += $value['a_warning']; - $final_result['counters_total']['t_a_unknown'] += $value['a_unknown']; - $final_result['counters_total']['t_a_normal'] += $value['a_normal']; - $final_result['counters_total']['t_a_not_init'] += $value['a_not_init']; - $final_result['counters_total']['t_a_agents'] += $value['a_agents']; + if(isset($nodo) && is_array($nodo)){ + foreach ($nodo as $key => $value) { + //Sum counters total + $final_result['counters_total']['t_m_normal'] += $value['m_normal']; + $final_result['counters_total']['t_m_critical'] += $value['m_critical']; + $final_result['counters_total']['t_m_warning'] += $value['m_warning']; + $final_result['counters_total']['t_m_unknown'] += $value['m_unknown']; + $final_result['counters_total']['t_m_not_init'] += $value['m_not_init']; + $final_result['counters_total']['t_m_alerts'] += $value['m_alerts']; + $final_result['counters_total']['t_m_total'] += $value['m_total']; + $final_result['counters_total']['t_a_critical'] += $value['a_critical']; + $final_result['counters_total']['t_a_warning'] += $value['a_warning']; + $final_result['counters_total']['t_a_unknown'] += $value['a_unknown']; + $final_result['counters_total']['t_a_normal'] += $value['a_normal']; + $final_result['counters_total']['t_a_not_init'] += $value['a_not_init']; + $final_result['counters_total']['t_a_agents'] += $value['a_agents']; - //Sum counters for data - $array_data[$value['name_data']]['m_normal'] += $value['m_normal']; - $array_data[$value['name_data']]['m_critical'] += $value['m_critical']; - $array_data[$value['name_data']]['m_warning'] += $value['m_warning']; - $array_data[$value['name_data']]['m_unknown'] += $value['m_unknown']; - $array_data[$value['name_data']]['m_not_init'] += $value['m_not_init']; - $array_data[$value['name_data']]['m_alerts'] += $value['m_alerts']; - $array_data[$value['name_data']]['m_total'] += $value['m_total']; - $array_data[$value['name_data']]['a_critical'] += $value['a_critical']; - $array_data[$value['name_data']]['a_warning'] += $value['a_warning']; - $array_data[$value['name_data']]['a_unknown'] += $value['a_unknown']; - $array_data[$value['name_data']]['a_normal'] += $value['a_normal']; - $array_data[$value['name_data']]['a_not_init'] += $value['a_not_init']; - $array_data[$value['name_data']]['a_agents'] += $value['a_agents']; + //Sum counters for data + $array_data[$value['name_data']]['m_normal'] += $value['m_normal']; + $array_data[$value['name_data']]['m_critical'] += $value['m_critical']; + $array_data[$value['name_data']]['m_warning'] += $value['m_warning']; + $array_data[$value['name_data']]['m_unknown'] += $value['m_unknown']; + $array_data[$value['name_data']]['m_not_init'] += $value['m_not_init']; + $array_data[$value['name_data']]['m_alerts'] += $value['m_alerts']; + $array_data[$value['name_data']]['m_total'] += $value['m_total']; + $array_data[$value['name_data']]['a_critical'] += $value['a_critical']; + $array_data[$value['name_data']]['a_warning'] += $value['a_warning']; + $array_data[$value['name_data']]['a_unknown'] += $value['a_unknown']; + $array_data[$value['name_data']]['a_normal'] += $value['a_normal']; + $array_data[$value['name_data']]['a_not_init'] += $value['a_not_init']; + $array_data[$value['name_data']]['a_agents'] += $value['a_agents']; + } } } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 9e5545219d..aa2d2aedb4 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3371,5 +3371,7 @@ CREATE TABLE IF NOT EXISTS `tagent_custom_fields_filter` ( `id_custom_fields_data` varchar(600) default '', `id_status` varchar(600) default '', `module_search` varchar(600) default '', + `module_status` varchar(600) default '', + `recursion` int(1) unsigned default '0', PRIMARY KEY(`id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 9bca5cc191..53b7b79257 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -109,10 +109,10 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_report_front_logo', 'images/pandora_logo_white.jpg'), ('custom_report_front_header', ''), ('custom_report_front_footer', ''), -('MR', 22), +('MR', 23), ('identification_reminder', 1), ('identification_reminder_timestamp', 0), -('current_package_enterprise', '729'), +('current_package_enterprise', '730'), ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.0009765625":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'), ('custom_docs_logo', 'default_docs.png'), ('custom_support_logo', 'default_support.png'), From 0c27534ca363745a696458b13165b4411cae0a8b Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 3 Dec 2018 12:53:41 +0100 Subject: [PATCH 3/5] fixed refresh status agents --- .../include/ajax/custom_fields.php | 70 +++++++++++++------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/pandora_console/include/ajax/custom_fields.php b/pandora_console/include/ajax/custom_fields.php index 566ac0e8d1..e06fb07980 100644 --- a/pandora_console/include/ajax/custom_fields.php +++ b/pandora_console/include/ajax/custom_fields.php @@ -236,7 +236,7 @@ if($build_table_child_custom_fields){ $id_agent = get_parameter("id_agent", 0); $id_server = get_parameter("id_server", 0); $module_search = str_replace('amp;', '',get_parameter("module_search", '')); - $module_status = str_replace('amp;', '',get_parameter("module_status", '')); + $module_status = get_parameter("module_status", 0); if(!$id_server || !$id_agent){ return false; @@ -246,6 +246,46 @@ if($build_table_child_custom_fields){ $name_where = " AND tam.nombre LIKE '%" . $module_search . "%'"; } + //filter by status module + $and_module_status = ""; + if(is_array($module_status)){ + if(!in_array(-1, $module_status)){ + if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $module_status)){ + if(count($module_status) > 0){ + $and_module_status = " AND ( "; + foreach ($module_status as $key => $value) { + $and_module_status .= ($key != 0) + ? " OR (" + : " ("; + switch ($value) { + default: + case AGENT_STATUS_NORMAL: + $and_module_status .= " tae.estado = 0 OR tae.estado = 300 ) "; + break; + case AGENT_STATUS_CRITICAL: + $and_module_status .= " tae.estado = 1 OR tae.estado = 100 ) "; + break; + case AGENT_STATUS_WARNING: + $and_module_status .= " tae.estado = 2 OR tae.estado = 200 ) "; + break; + case AGENT_STATUS_UNKNOWN: + $and_module_status .= " tae.estado = 3 ) "; + break; + case AGENT_STATUS_NOT_INIT: + $and_module_status .= " tae.estado = 4 OR tae.estado = 5 ) "; + break; + } + } + $and_module_status .= " ) "; + } + } + else{ + //not normal + $and_module_status = "AND tae.estado <> 0 AND tae.estado <> 300 "; + } + } + } + if (is_metaconsole()) { $server = metaconsole_get_connection_by_id ($id_server); metaconsole_connect($server); @@ -262,9 +302,10 @@ if($build_table_child_custom_fields){ INNER JOIN tagente_estado tae ON tam.id_agente_modulo = tae.id_agente_modulo WHERE tam.id_agente = %d - %s", + %s %s", $id_agent, - $name_where + $name_where, + $and_module_status ); $modules = db_get_all_rows_sql ($query); @@ -282,7 +323,7 @@ if($build_table_child_custom_fields){ $table_modules->head[5] = __('Status'); $table_modules->data = array(); - $status_agent = -1; + if(isset($modules) && is_array($modules)){ foreach ($modules as $key => $value) { $table_modules->data[$key][0] = $value['nombre']; @@ -311,9 +352,6 @@ if($build_table_child_custom_fields){ switch ($value['estado']) { case 0: case 300: - if($status_agent != 1 && $status_agent != 2 && $status_agent != 3){ - $status_agent = 0; - } $table_modules->data[$key][5] = html_print_image( 'images/status_sets/default/severity_normal.png', true, @@ -324,7 +362,6 @@ if($build_table_child_custom_fields){ break; case 1: case 100: - $status_agent = 1; $table_modules->data[$key][5] = html_print_image( 'images/status_sets/default/severity_critical.png', true, @@ -335,10 +372,6 @@ if($build_table_child_custom_fields){ break; case 2: case 200: - if($status_agent != 1){ - $status_agent = 2; - } - $table_modules->data[$key][5] = html_print_image( 'images/status_sets/default/severity_warning.png', true, @@ -348,10 +381,6 @@ if($build_table_child_custom_fields){ ); break; case 3: - if($status_agent != 1 && $status_agent != 2){ - $status_agent = 3; - } - $table_modules->data[$key][5] = html_print_image( 'images/status_sets/default/severity_maintenance.png', true, @@ -362,9 +391,6 @@ if($build_table_child_custom_fields){ break; case 4: case 5: - if($status_agent == -1 || $status_agent == 4){ - $status_agent = 5; - } $table_modules->data[$key][5] = html_print_image( 'images/status_sets/default/severity_informational.png', true, @@ -374,10 +400,6 @@ if($build_table_child_custom_fields){ ); break; default: - if($status_agent != 1 && $status_agent != 2 && $status_agent != 3){ - $status_agent = 0; - } - $table_modules->data[$key][5] = html_print_image( 'images/status_sets/default/severity_normal.png', true, @@ -390,6 +412,8 @@ if($build_table_child_custom_fields){ } } + $status_agent = agents_get_status($id_agent, true); + if (is_metaconsole()) { metaconsole_restore_db(); } From a03adb1762335f3840a288f1ccfcb1c4a20cf3cb Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 3 Dec 2018 18:00:41 +0100 Subject: [PATCH 4/5] add field group filter --- pandora_console/extras/mr/23.sql | 2 +- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 2 + .../include/ajax/custom_fields.php | 53 +++++++++++++++---- .../include/functions_custom_fields.php | 9 ++++ pandora_console/pandoradb.sql | 1 + 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/pandora_console/extras/mr/23.sql b/pandora_console/extras/mr/23.sql index e14f68a304..a602023e3b 100644 --- a/pandora_console/extras/mr/23.sql +++ b/pandora_console/extras/mr/23.sql @@ -1,6 +1,6 @@ START TRANSACTION; ---ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `module_status` varchar(600) default ''; +ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `group_search` int(10) unsigned default '0'; ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `module_status` varchar(600) default ''; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 5b81170b8c..5b98fdbec0 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1830,3 +1830,5 @@ CREATE TABLE IF NOT EXISTS `tagent_custom_fields_filter` ( ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `module_status` varchar(600) default ''; ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `recursion` int(1) unsigned default '0'; + +ALTER TABLE `tagent_custom_fields_filter` ADD COLUMN `group_search` int(10) unsigned default '0'; diff --git a/pandora_console/include/ajax/custom_fields.php b/pandora_console/include/ajax/custom_fields.php index e06fb07980..d24dd88b40 100644 --- a/pandora_console/include/ajax/custom_fields.php +++ b/pandora_console/include/ajax/custom_fields.php @@ -32,6 +32,7 @@ $append_tab_filter = (bool)get_parameter('append_tab_filter', 0); $create_filter_cf = (bool)get_parameter('create_filter_cf', 0); $update_filter_cf = (bool)get_parameter('update_filter_cf', 0); $delete_filter_cf = (bool)get_parameter('delete_filter_cf', 0); +$change_name_filter = (bool)get_parameter('change_name_filter', 0); if ($get_custom_fields_data){ $name_custom_fields = get_parameter("name_custom_fields", 0); @@ -457,7 +458,7 @@ if($build_table_save_filter){ $table->id = 'save_filter_form'; $table->width = '100%'; $table->class = 'databox'; - + $array_filters = get_filters_custom_fields_view(0, true); $table->data[0][0] = __('Filter name'); $table->data[0][1] = html_print_select( @@ -465,9 +466,10 @@ if($build_table_save_filter){ '', '', '', '', true, false, true, '', false ); + $table->data[0][3] = html_print_submit_button (__('Load filter'), 'load_filter', false, 'class="sub upd"', true); - - echo "
"; + + echo ""; html_print_table($table); echo "
"; } @@ -486,7 +488,16 @@ if($append_tab_filter){ echo "
"; $table->data[0][0] = __('Filter name'); $table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true); - $table->data[0][2] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true); + + $table->data[0][2] = __('Group'); + $table->data[0][3] = html_print_select_groups( + $config['id_user'], 'AR', true, 'group_search', + 0, '', '', '0', true, false, + false, '', false, '', false, false, + 'id_grupo', false + ); + + $table->data[0][4] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true); } else{ echo "
"; @@ -494,12 +505,22 @@ if($append_tab_filter){ $array_filters = get_filters_custom_fields_view(0, true); $table->data[0][0] = __('Filter name'); $table->data[0][1] = html_print_select( - $array_filters, 'id_name', - '', '', __('None'), -1, - true, false, true, '', false + $array_filters, 'id_name', '', + 'filter_name_change_group(this.value)', + __('None'), -1, true, false, true, + '', false ); + + $table->data[1][0] = __('Group'); + $table->data[1][1] = html_print_select_groups( + $config['id_user'], 'AR', true, 'group_search_up', + $group, '', '', '0', true, false, + false, '', false, '', false, false, + 'id_grupo', false + ); + $table->data[0][2] = html_print_submit_button (__('Delete filter'), 'delete_filter', false, 'class="sub upd"', true); - $table->data[0][3] = html_print_submit_button (__('Update filter'), 'update_filter', false, 'class="sub upd"', true); + $table->data[1][2] = html_print_submit_button (__('Update filter'), 'update_filter', false, 'class="sub upd"', true); } html_print_table($table); @@ -515,6 +536,7 @@ if($create_filter_cf){ //initialize vars $filters = json_decode(io_safe_output(get_parameter("filters", '')), true); $name_filter = get_parameter("name_filter", ''); + $group_search = get_parameter("group_search", 0); //check that the name is not empty if($name_filter == ''){ @@ -553,6 +575,7 @@ if($create_filter_cf){ //insert $values = array(); $values['name'] = $name_filter; + $values['group_search'] = $group_search; $values['id_group'] = $filters['group']; $values['id_custom_field'] = $filters['id_custom_fields']; $values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']); @@ -591,6 +614,7 @@ if($update_filter_cf){ //initialize vars $filters = json_decode(io_safe_output(get_parameter("filters", '')), true); $id_filter = get_parameter("id_filter", ''); + $group_search = get_parameter("group_search", 0); //check selected filter if($id_filter == -1){ @@ -621,6 +645,7 @@ if($update_filter_cf){ //array values update $values = array(); $values['id_group'] = $filters['group']; + $values['group_search'] = $group_search; $values['id_custom_field'] = $filters['id_custom_fields']; $values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']); $values['id_status'] = json_encode($filters['id_status']); @@ -697,7 +722,17 @@ if($delete_filter_cf){ return; } +if($change_name_filter){ + $id_filter = get_parameter("id_filter", 0); + if(isset($id_filter)){ + $res = get_group_filter_custom_field_view($id_filter); + echo json_encode($res); + return; + } + + return json_encode(false); +} -} \ No newline at end of file +} diff --git a/pandora_console/include/functions_custom_fields.php b/pandora_console/include/functions_custom_fields.php index 7b18fb0b0d..e22956adf1 100644 --- a/pandora_console/include/functions_custom_fields.php +++ b/pandora_console/include/functions_custom_fields.php @@ -533,4 +533,13 @@ function get_filters_custom_fields_view($id = 0, $for_select = false, $name = "" } return $result; } + +function get_group_filter_custom_field_view ($id){ + if(isset($id)){ + $res = db_get_row_filter('tagent_custom_fields_filter',array('id' => $id)); + return $res; + } + return false; +} + ?> \ No newline at end of file diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index aa2d2aedb4..054204d85a 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3373,5 +3373,6 @@ CREATE TABLE IF NOT EXISTS `tagent_custom_fields_filter` ( `module_search` varchar(600) default '', `module_status` varchar(600) default '', `recursion` int(1) unsigned default '0', + `group_search` int(10) unsigned default '0', PRIMARY KEY(`id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file From 222da4ee403e7054d73b08ed5bf637e465b2e59a Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 4 Dec 2018 09:36:48 +0100 Subject: [PATCH 5/5] group filter custom field view --- pandora_console/include/ajax/custom_fields.php | 3 ++- pandora_console/include/functions_custom_fields.php | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/ajax/custom_fields.php b/pandora_console/include/ajax/custom_fields.php index d24dd88b40..8500166413 100644 --- a/pandora_console/include/ajax/custom_fields.php +++ b/pandora_console/include/ajax/custom_fields.php @@ -460,6 +460,7 @@ if($build_table_save_filter){ $table->class = 'databox'; $array_filters = get_filters_custom_fields_view(0, true); + $table->data[0][0] = __('Filter name'); $table->data[0][1] = html_print_select( $array_filters, 'id_name', @@ -491,7 +492,7 @@ if($append_tab_filter){ $table->data[0][2] = __('Group'); $table->data[0][3] = html_print_select_groups( - $config['id_user'], 'AR', true, 'group_search', + $config['id_user'], 'AR', true, 'group_search_cr', 0, '', '', '0', true, false, false, '', false, '', false, false, 'id_grupo', false diff --git a/pandora_console/include/functions_custom_fields.php b/pandora_console/include/functions_custom_fields.php index e22956adf1..dcc038b620 100644 --- a/pandora_console/include/functions_custom_fields.php +++ b/pandora_console/include/functions_custom_fields.php @@ -506,8 +506,16 @@ function agent_counters_custom_fields($filters){ } function get_filters_custom_fields_view($id = 0, $for_select = false, $name = ""){ + //filter group and check ACL groups + $groups_and = ""; + if (!users_can_manage_group_all()) { + $user_groups = array_keys(users_get_groups(false, "AR", false)); + $id_groups = implode(", ", $user_groups); + $groups_and = " AND (group_search IN ($id_groups)) "; + } + if($for_select){ - $query = "SELECT id, `name` FROM tagent_custom_fields_filter"; + $query = "SELECT id, `name` FROM tagent_custom_fields_filter WHERE 1=1" . $groups_and; $rs = db_get_all_rows_sql($query); if(isset($rs) && is_array($rs)){ foreach ($rs as $key => $value) { @@ -519,7 +527,7 @@ function get_filters_custom_fields_view($id = 0, $for_select = false, $name = "" } } else{ - $query = "SELECT * FROM tagent_custom_fields_filter WHERE 1=1"; + $query = "SELECT * FROM tagent_custom_fields_filter WHERE 1=1" . $groups_and; if($id){ $query .= " AND id = " . $id;