Fix user modification-creation

This commit is contained in:
Jose Gonzalez 2023-02-13 14:23:31 +01:00
parent d45a631ea5
commit d33babd48a
5 changed files with 70 additions and 52 deletions

View File

@ -28,7 +28,7 @@
// Load global vars.
global $config;
// hd($_REQUEST); //TODO. For testing purposes.
// hd($_REQUEST, true); //TODO. For testing purposes.
check_login();
require_once $config['homedir'].'/vendor/autoload.php';
@ -234,35 +234,39 @@ if (is_metaconsole() === true) {
user_meta_print_header();
$sec = 'advanced';
} else {
$buttons = [
'user' => [
'active' => false,
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure='.$pure.'">'.html_print_image(
'images/user.svg',
true,
[
'title' => __('User management'),
'class' => 'invert_filter main_menu_icon',
]
).'</a>',
],
'profile' => [
'active' => false,
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/profile_list&tab=profile&pure='.$pure.'">'.html_print_image(
'images/suitcase@svg.svg',
true,
[
'title' => __('Profile management'),
'class' => 'invert_filter main_menu_icon',
]
).'</a>',
],
];
if ((bool) check_acl($config['id_user'], 0, 'UM') === false) {
$buttons = [];
} else {
$buttons = [
'user' => [
'active' => false,
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure='.$pure.'">'.html_print_image(
'images/user.svg',
true,
[
'title' => __('User management'),
'class' => 'invert_filter main_menu_icon',
]
).'</a>',
],
'profile' => [
'active' => false,
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/profile_list&tab=profile&pure='.$pure.'">'.html_print_image(
'images/suitcase@svg.svg',
true,
[
'title' => __('Profile management'),
'class' => 'invert_filter main_menu_icon',
]
).'</a>',
],
];
$buttons[$tab]['active'] = true;
$buttons[$tab]['active'] = true;
}
ui_print_standard_header(
(empty($id) === false) ? sprintf('%s [ %s ]', __('Update User'), $config['id_user']) : __('Create User'),
(empty($id) === false) ? sprintf('%s [ %s ]', __('Update User'), $id) : __('Create User'),
'images/gm_users.png',
false,
'',
@ -521,7 +525,6 @@ if ($create_user === true) {
$info
);
HD('patatas', true);
ui_print_result_message(
$result,
__('Successfully created'),
@ -541,7 +544,7 @@ if ($create_user === true) {
$user_info = get_user_info($id);
$new_user = false;
if (!empty($json_profile)) {
if (empty($json_profile) === false) {
$json_profile = json_decode(io_safe_output($json_profile), true);
foreach ($json_profile as $key => $profile) {
if (is_array($profile) === false) {
@ -769,6 +772,7 @@ if ($update_user) {
);
}
hd('res1-res2', true);
ui_print_result_message(
$res1 || $res2,
__('User info successfully updated'),
@ -842,7 +846,7 @@ if ($update_user) {
false,
$info
);
hd('apitoken', true);
ui_print_result_message(
$res1,
($apiTokenRenewed === true) ? __('You have generated a new API Token.') : __('User info successfully updated'),
@ -890,7 +894,7 @@ if ((int) $status !== -1) {
}
if ($add_profile && empty($json_profile)) {
$id2 = (string) get_parameter('id');
$id2 = (string) get_parameter('id', get_parameter('id_user'));
$group2 = (int) get_parameter('assign_group');
$profile2 = (int) get_parameter('assign_profile');
$tags = (array) get_parameter('assign_tags');
@ -911,6 +915,15 @@ if ($add_profile && empty($json_profile)) {
false,
'Profile: '.$profile2.' Group: '.$group2.' Tags: '.$tags
);
/*
hd('>>>>>', true);
hd($id2, true);
hd($profile2, true);
hd($group2, true);
hd($tags, true);
hd($no_hierarchy, true);
hd('<<<<<<', true);
*/
$return = profile_create_user_profile($id2, $profile2, $group2, false, $tags, $no_hierarchy);
if ($return === false) {
$is_err = true;
@ -964,9 +977,9 @@ if (isset($values) === true && empty($values) === false) {
$user_info = $values;
}
if (!users_is_admin() && $config['id_user'] != $id && !$new_user) {
if (!users_is_admin() && $config['id_user'] !== $id && $new_user === false) {
$group_um = users_get_groups_UM($config['id_user']);
if (isset($group_um[0])) {
if (isset($group_um[0]) === true) {
$group_um_string = implode(',', array_keys(users_get_groups($config['id_user'], 'um', true)));
} else {
$group_um_string = implode(',', array_keys($group_um));
@ -996,7 +1009,7 @@ if (is_metaconsole() === true) {
html_print_div(
[
'class' => 'user_form_title',
'content' => ((bool) $id === true) ? sprintf('%s [ %s ]', __('Update User'), $config['id_user']) : __('Create User'),
'content' => ((bool) $id === true) ? sprintf('%s [ %s ]', __('Update User'), $id) : __('Create User'),
]
);
}
@ -1819,11 +1832,13 @@ if ((bool) $config['admin_can_add_user'] === true) {
);
}
$actionButtons[] = html_print_go_back_button(
ui_get_full_url('index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure=0'),
['button_class' => ''],
true
);
if ((bool) check_acl($config['id_user'], 0, 'UM') === true) {
$actionButtons[] = html_print_go_back_button(
ui_get_full_url('index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure=0'),
['button_class' => ''],
true
);
}
html_print_action_buttons(implode('', $actionButtons), ['type' => 'form_action']);

View File

@ -133,7 +133,7 @@ $userManagementTable->colspan = [];
$userManagementTable->rowspan = [];
// Title for Profile information.
$sustitleTable = ($new_user === true) ? __('Profile information') : sprintf('%s [ %s ]', __('Profile information for'), $config['id_user']);
$sustitleTable = ($new_user === true) ? __('Profile information') : sprintf('%s [ %s ]', __('Profile information for'), $id);
$userManagementTable->data['title_profile_information'] = html_print_subtitle_table($sustitleTable);
// Id user.
@ -701,6 +701,7 @@ $userManagementTable->data['fields_addSettings'][1] .= html_print_div(
);
html_print_table($userManagementTable);
// User Profile definition table.
profile_print_profile_table($id, io_safe_output($json_profile), false, ($is_err === true && $new_user === true));
// User Profile definition table. (Only where user is not creating).
if ($new_user === false && ((bool) check_acl($config['id_user'], 0, 'UM') === true)) {
profile_print_profile_table($id, io_safe_output($json_profile), false, ($is_err === true));
}

View File

@ -117,7 +117,9 @@ function profile_create_user_profile(
'assigned_by' => $assign,
'no_hierarchy' => $no_hierarchy ? 1 : 0,
];
hd('inicio insert', true);
hd($insert, true);
hd('final insert', true);
return db_process_sql_insert('tusuario_perfil', $insert);
}
@ -225,7 +227,8 @@ function profile_print_profile_table($id, $json_profile=false, $return=false, $c
} else {
// Only profiles that can be viewed by the user.
$group_um = users_get_groups_UM($config['id_user']);
if (isset($group_um[0])) {
hd($group_um, true);
if (isset($group_um[0]) === true) {
$group_um_string = implode(',', array_keys(users_get_groups($config['id_user'], 'um', true)));
} else {
$group_um_string = implode(',', array_keys($group_um));
@ -238,7 +241,7 @@ function profile_print_profile_table($id, $json_profile=false, $return=false, $c
$id,
$group_um_string
);
hd($sql, true);
$result = db_get_all_rows_sql($sql);
}

View File

@ -501,11 +501,11 @@ function ui_print_empty_data($message, $attributes='', $return=false, $tag='h3')
*/
function ui_print_result_message($result, $good='', $bad='', $attributes='', $return=false, $tag='h3')
{
if (empty($good) === false || $good === false) {
if (empty($good) === true || $good === false) {
$good = __('Request successfully processed');
}
if (empty($bad) === false || $bad === false) {
if (empty($bad) === true || $bad === false) {
$bad = __('Error processing request');
}

View File

@ -1735,12 +1735,12 @@ div.title_line {
#menu_tab_frame_view,
#menu_tab_frame_view_bc {
position: sticky;
top: 59px;
top: 60px;
z-index: 1000;
display: flex;
align-items: flex-end;
justify-content: space-between;
border-bottom: 4px solid #14524f;
border-bottom: 4px solid #c1ccdc;
/* width: calc(100% + 3em); */
width: -webkit-fill-available;
width: -moz-fill-available;
@ -1749,7 +1749,6 @@ div.title_line {
height: 56px;
box-sizing: border-box;
background-color: #fff;
box-shadow: 1px 1px 4px rgb(0 0 0 / 10%);
/* margin-left: -3em;*/
}
@ -9920,7 +9919,7 @@ select:disabled,
color: #8a96a6;
}
input:focus,
input:not([type="image"]):focus,
textarea:focus,
select:focus {
border: 1px solid #8a96a6;