Merge branch 'ent-9506-cambios-en-vista-de-usuarios-perfiles' into 'develop'

Ent 9506 cambios en vista de usuarios perfiles

See merge request artica/pandorafms!5124
This commit is contained in:
Daniel Rodriguez 2022-10-14 10:31:41 +00:00
commit a36666f1fd
2 changed files with 116 additions and 50 deletions

View File

@ -31,8 +31,6 @@ global $config;
check_login();
enterprise_hook('open_meta_frame');
require_once $config['homedir'].'/include/functions_profile.php';
require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_groups.php';
@ -52,8 +50,47 @@ if (is_ajax()) {
$method = get_parameter('method');
$group_id = get_parameter('group_id');
$group_recursion = (bool) get_parameter('group_recursion', 0);
$get_user_profile_group = (bool) get_parameter('get_user_profile_group', false);
$return_all = false;
if ($get_user_profile_group === true) {
$id_user = get_parameter('id_user');
$user_is_admin = users_is_admin();
$user_profiles = [];
if ($user_is_admin === false) {
$group_um = users_get_groups_UM($config['id_user']);
}
// User profiles.
if ($user_is_admin || $id_user == $config['id_user'] || isset($group_um[0])) {
$user_profiles = db_get_all_rows_field_filter(
'tusuario_perfil',
'id_usuario',
$id_user
);
} else {
$user_profiles_aux = users_get_user_profile($id_user);
foreach ($group_um as $key => $value) {
if (isset($user_profiles_aux[$key]) === true) {
$user_profiles[$key] = $user_profiles_aux[$key];
unset($user_profiles_aux[$key]);
}
}
}
foreach ($user_profiles as $key => $value) {
$user_profiles[$key]['id_perfil'] = profile_get_name($value['id_perfil']);
$user_profiles[$key]['id_grupo'] = groups_get_name($value['id_grupo'], true);
}
echo json_encode($user_profiles);
return;
}
if ($group_id == -1) {
$sql = 'SELECT tusuario.id_user FROM tusuario
LEFT OUTER JOIN tusuario_perfil
@ -95,6 +132,8 @@ if (is_ajax()) {
}
}
enterprise_hook('open_meta_frame');
$sortField = get_parameter('sort_field');
$sort = get_parameter('sort', 'none');
$tab = get_parameter('tab', 'user');
@ -596,13 +635,11 @@ foreach ($info as $user_id => $user_info) {
// User profiles.
if ($user_is_admin || $user_id == $config['id_user'] || isset($group_um[0])) {
$user_profiles = db_get_all_rows_field_filter(
'tusuario_perfil',
'id_usuario',
$user_id
$user_profiles = db_get_all_rows_sql(
'SELECT * FROM tusuario_perfil where id_usuario LIKE "'.$user_id.'" LIMIT 5'
);
} else {
$user_profiles_aux = users_get_user_profile($user_id);
$user_profiles_aux = users_get_user_profile($user_id, 'LIMIT 5');
$user_profiles = [];
foreach ($group_um as $key => $value) {
if (isset($user_profiles_aux[$key]) === true) {
@ -682,39 +719,35 @@ foreach ($info as $user_id => $user_info) {
if ($user_profiles !== false) {
$total_profile = 0;
$data[4] .= '<div class="text_end">';
$data[4] .= '<div class="text_end">';
foreach ($user_profiles as $row) {
if ($total_profile <= 5) {
$data[4] .= "<div class='float-left'>";
$data[4] .= profile_get_name($row['id_perfil']);
$data[4] .= ' / </div>';
$data[4] .= "<div class='float-left pdd_l_5px'>";
$data[4] .= groups_get_name($row['id_grupo'], true);
$data[4] .= '</div>';
$data[4] .= "<div class='float-left'>";
$data[4] .= profile_get_name($row['id_perfil']);
$data[4] .= ' / </div>';
$data[4] .= "<div class='float-left pdd_l_5px'>";
$data[4] .= groups_get_name($row['id_grupo'], true);
$data[4] .= '</div>';
if ($total_profile == 0 && count($user_profiles) >= 5) {
$data[4] .= '<span onclick="showGroups()" class="pdd_l_15px">
'.html_print_image(
'images/zoom.png',
true,
[
'title' => __('Show'),
'class' => 'invert_filter',
]
).'</span>';
}
if ($total_profile == 0 && count($user_profiles) >= 5) {
$data[4] .= '<span onclick="showGroups(`'.$row['id_usuario'].'`)">'.html_print_image(
'images/zoom.png',
true,
[
'title' => __('Show profiles'),
'class' => 'invert_filter',
]
).'</span>';
$data[4] .= '<br />';
$data[4] .= '<br />';
$data[4] .= '</div>';
} else {
$data[4] .= "<div id='groups_list' class='invisible'>";
$data[4] .= '<div >';
$data[4] .= profile_get_name($row['id_perfil']);
$data[4] .= ' / '.groups_get_name($row['id_grupo'], true).'</div>';
$data[4] .= '<br/>';
$data[4] .= html_print_input_hidden(
'show_groups_'.$row['id_usuario'],
-1,
true
);
}
$data[4] .= '<br/>';
$data[4] .= '<br/>';
$total_profile++;
}
@ -727,6 +760,8 @@ foreach ($info as $user_id => $user_info) {
}
$data[4] .= '</div>';
$data[4] .= '<div class="invisible" id="profiles_'.$user_profiles[0]['id_usuario'].'">';
$data[4] .= '</div>';
} else {
$data[4] .= __('The user doesn\'t have any assigned profile/group');
}
@ -890,16 +925,46 @@ echo '</div>';
enterprise_hook('close_meta_frame');
echo '<script type="text/javascript">
function showGroups(){
var groups_list = document.getElementById("groups_list");
?>
<script type="text/javascript">
function showGroups(id_user) {
if ($(`#hidden-show_groups_${id_user}`).val() === '-1') {
var request = $.ajax({
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
type: 'GET',
dataType: 'json',
data: {
page: 'godmode/users/user_list',
get_user_profile_group: 1,
id_user: id_user
},
success: function (data, textStatus, xhr) {
let count = 1;
data.forEach( function(valor, indice, array) {
if (count >= 6) {
let main_div = $(`#profiles_${id_user}`);
main_div.append(
`<div id="left_${id_user}_${count}" class='float-left'>${valor.id_perfil} / </div>`,
`<div id="right_${id_user}_${count}" class='float-left pdd_l_5px'>${valor.id_grupo}</div>`,
`<br/><br/>`
);
}
count ++;
});
},
error: function (e, textStatus) {
console.error(textStatus);
}
});
$(`#hidden-show_groups_${id_user}`).val('1');
$(`#profiles_${id_user}`).show();
} else if ($(`#hidden-show_groups_${id_user}`).val() === '1') {
$(`#hidden-show_groups_${id_user}`).val('0');
$(`#profiles_${id_user}`).hide();
} else {
$(`#hidden-show_groups_${id_user}`).val('1');
$(`#profiles_${id_user}`).show();
}
}
if(groups_list.style.display == "none"){
document.querySelectorAll("[id=groups_list]").forEach(element=>
element.style.display = "block");
}else{
document.querySelectorAll("[id=groups_list]").forEach(element=>
element.style.display = "none");
};
}
</script>';
</script>

View File

@ -838,13 +838,14 @@ function users_has_profile_without_UM($id_user, $id_groups)
}
function users_get_user_profile($id_user)
function users_get_user_profile($id_user, $limit='')
{
$sql = sprintf(
"SELECT * FROM tusuario_perfil
INNER JOIN tperfil ON tperfil.id_perfil = tusuario_perfil.id_perfil
WHERE tusuario_perfil.id_usuario like '%s'",
$id_user
WHERE tusuario_perfil.id_usuario like '%s' %s",
$id_user,
$limit
);
$aux = db_get_all_rows_sql($sql);