From 1dbc9c72b8037e7838491f45342d8cc7ba602fbd Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 17 Feb 2022 14:12:48 +0100 Subject: [PATCH 1/3] Fix users count on index and user list --- pandora_console/godmode/users/user_list.php | 12 +++++---- .../include/functions_reporting.php | 26 ++++++++++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index 7ac3f55261..2457932339 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -545,6 +545,13 @@ if ($search) { } } +foreach ($info1 as $user_id => $user_info) { + // If user is not admin then don't display admin users. + if ($user_is_admin === false && (bool) $user_info['is_admin'] === true) { + unset($info1[$user_id]); + } +} + $info = $info1; // Prepare pagination. @@ -557,11 +564,6 @@ $rowPair = true; $iterator = 0; $cont = 0; foreach ($info as $user_id => $user_info) { - if (!$user_is_admin && $user_info['is_admin']) { - // If user is not admin then don't display admin users. - continue; - } - // User profiles. if ($user_is_admin || $user_id == $config['id_user'] || isset($group_um[0])) { $user_profiles = db_get_all_rows_field_filter( diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 9ccd8e1ff0..7c40b92653 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -11053,11 +11053,29 @@ function reporting_get_stats_users($data) $tdata = []; $tdata[0] = html_print_image('images/user.png', true, ['title' => __('Defined users'), 'class' => 'invert_filter']); - $user_groups = users_get_strict_mode_groups($config['id_user'], false); - if (array_key_exists(0, $user_groups)) { - $users = users_get_user_users($config['id_user'], 'AR', true); + $user_is_admin = users_is_admin(); + + $users = []; + + if ($user_is_admin) { + $users = get_users('', ['disabled' => 0], ['id_user', 'is_admin']); } else { - $users = users_get_user_users($config['id_user'], 'AR', false); + $group_um = users_get_groups_UM($config['id_user']); + // 0 is the group 'all'. + if (isset($group_um[0])) { + $users = get_users('', ['disabled' => 0], ['id_user', 'is_admin']); + } else { + foreach ($group_um as $group => $value) { + $users = array_merge($users, users_get_users_by_group($group, $value)); + } + } + } + + foreach ($users as $user_id => $user_info) { + // If user is not admin then don't display admin users. + if ($user_is_admin === false && (bool) $user_info['is_admin'] === true) { + unset($users[$user_id]); + } } $tdata[1] = count($users); From 78ab628c8b3216dc7bac299f722678b5ecbd13f3 Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 10 Mar 2022 08:22:45 +0100 Subject: [PATCH 2/3] Fix tactical view user count when user is in group --- pandora_console/include/functions_reporting.php | 2 +- pandora_console/include/functions_users.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 66aeec8bc8..39aa94d336 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -11199,7 +11199,7 @@ function reporting_get_stats_users($data) $users = get_users('', ['disabled' => 0], ['id_user', 'is_admin']); } else { foreach ($group_um as $group => $value) { - $users = array_merge($users, users_get_users_by_group($group, $value)); + $users = array_merge($users, users_get_users_by_group($group, $value, false)); } } } diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index a0cac33b30..ef1e54576e 100755 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -778,9 +778,10 @@ function users_get_groups_UM($id_user) * Obtiene una matriz con los grupos como clave y si tiene o no permiso UM sobre ese grupo(valor) * * @param string User id + * @param boolean $disabled Return also disabled users * @return array Return . */ -function users_get_users_by_group($id_group, $um=false) +function users_get_users_by_group($id_group, $um=false, $disabled=true) { $sql = sprintf( "SELECT tusuario.* FROM tusuario @@ -789,6 +790,10 @@ function users_get_users_by_group($id_group, $um=false) $id_group ); + if ($disabled === false) { + $sql .= 'WHERE tusuario.disabled = 0'; + } + $users = db_get_all_rows_sql($sql); $return = []; foreach ($users as $key => $user) { From 176a94ce9910fab7241180b0f00daa2fdb013ee3 Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 10 Mar 2022 08:26:22 +0100 Subject: [PATCH 3/3] Fix tactical view user count when user is in group --- pandora_console/include/functions_users.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index ef1e54576e..f4e6e25be8 100755 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -777,8 +777,10 @@ function users_get_groups_UM($id_user) /** * Obtiene una matriz con los grupos como clave y si tiene o no permiso UM sobre ese grupo(valor) * - * @param string User id - * @param boolean $disabled Return also disabled users + * @param string $id_group User id. + * @param boolean $um Um. + * @param boolean $disabled Reurn also disabled users. + * * @return array Return . */ function users_get_users_by_group($id_group, $um=false, $disabled=true)