Merge branch 'ent-7676-12038-error-en-users-connected' into 'develop'

fixed sql error without profile

See merge request artica/pandorafms!4200
This commit is contained in:
Daniel Rodriguez 2021-08-03 06:48:56 +00:00
commit cdc8b0a80c
1 changed files with 81 additions and 34 deletions

View File

@ -33,10 +33,19 @@ function users_extension_main_god($god=true)
$image = 'images/user.png';
}
// Header
// Header.
ui_print_page_header(__('Users connected'), $image, false, '', $god);
// Get groups user has permission
$check_profile = db_get_row('tusuario_perfil', 'id_usuario', $config['id_user'], 'id_up');
if ($check_profile === false && !users_is_admin()) {
return ui_print_error_message(
__('This user does not have any associated profile'),
'',
false
);
}
// Get groups user has permission.
$group_um = users_get_groups_UM($config['id_user']);
// Is admin or has group permissions all.
$groups = implode(',', array_keys($group_um, 1));
@ -44,6 +53,15 @@ function users_extension_main_god($god=true)
// Get user conected last 5 minutes.Show only those on which the user has permission.
switch ($config['dbtype']) {
case 'mysql':
if (users_is_admin()) {
$sql = sprintf(
'SELECT tusuario.id_user, tusuario.last_connect
FROM tusuario
WHERE last_connect > (UNIX_TIMESTAMP(NOW()) - '.SECONDS_5MINUTES.')
GROUP BY tusuario.id_user
ORDER BY last_connect DESC'
);
} else {
$sql = sprintf(
'SELECT tusuario.id_user, tusuario.last_connect
FROM tusuario
@ -54,9 +72,19 @@ function users_extension_main_god($god=true)
ORDER BY last_connect DESC',
$groups
);
}
break;
case 'postgresql':
if (users_is_admin()) {
$sql = sprintf(
"SELECT tusuario.id_user, tusuario.last_connect
FROM tusuario
WHERE last_connect > (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - ".SECONDS_5MINUTES.')
GROUP BY tusuario.id_user
ORDER BY last_connect DESC'
);
} else {
$sql = sprintf(
"SELECT tusuario.id_user, tusuario.last_connect
FROM tusuario
@ -67,9 +95,19 @@ function users_extension_main_god($god=true)
ORDER BY last_connect DESC',
$groups
);
}
break;
case 'oracle':
if (users_is_admin()) {
$sql = sprintf(
"SELECT tusuario.id_user, tusuario.last_connect
FROM tusuario
WHERE last_connect > (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (".SECONDS_1DAY.')) - '.SECONDS_5MINUTES.')
GROUP BY tusuario.id_user
ORDER BY last_connect DESC'
);
} else {
$sql = sprintf(
"SELECT tusuario.id_user, tusuario.last_connect
FROM tusuario
@ -80,15 +118,20 @@ function users_extension_main_god($god=true)
ORDER BY last_connect DESC',
$groups
);
}
break;
default:
// Nothing to do.
break;
}
$rows = db_get_all_rows_sql($sql);
if (empty($rows)) {
$rows = [];
echo "<div class='nf'>".__('No other users connected').'</div>';
} else {
$table = new StdClass();
$table->cellpadding = 0;
$table->cellspacing = 0;
$table->width = '100%';
@ -105,7 +148,7 @@ function users_extension_main_god($god=true)
$rowPair = true;
$iterator = 0;
// Get data
// Get data.
foreach ($rows as $row) {
// Get data of user's last login.
switch ($config['dbtype']) {
@ -135,6 +178,10 @@ function users_extension_main_god($god=true)
)
);
break;
default:
// Nothing to do.
break;
}
if ($rowPair) {