From 283dadc72db8617d76226f99d51d14c9f1eb3d10 Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 18 Nov 2021 11:33:34 +0100 Subject: [PATCH] Select group search filter working on groups' child --- pandora_console/include/functions_users.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index 6eb975eaff..a0cac33b30 100755 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -301,6 +301,7 @@ function users_get_groups( $search='' ) { static $group_cache = []; + $filter = ''; // Added users_group_cache to avoid unnecessary proccess on massive calls... @@ -342,13 +343,6 @@ function users_get_groups( $query = 'SELECT * FROM tgrupo ORDER BY nombre'; $raw_groups = db_get_all_rows_sql($query); - if (empty($search) === false) { - $filter = sprintf( - ' AND lower(tgrupo.nombre) like lower("%%%s%%")', - $search - ); - } - $query = sprintf( "SELECT tgrupo.*, tperfil.*, tusuario_perfil.tags, tusuario_perfil.no_hierarchy FROM tgrupo, tusuario_perfil, tperfil WHERE (tgrupo.id_grupo = tusuario_perfil.id_grupo OR tusuario_perfil.id_grupo = 0) @@ -451,6 +445,16 @@ function users_get_groups( } } + // Search filter. + if (empty($search) === false) { + $user_groups = array_filter( + $user_groups, + function ($group) use ($search) { + return (bool) preg_match('/'.$search.'/i', $group['nombre']); + } + ); + } + $users_group_cache[$users_group_cache_key] = $user_groups; return $user_groups;