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;