diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 800f738394..945bea5edd 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -489,6 +489,10 @@ if ($create_user) { if (!empty($json_profile)) { $json_profile = json_decode(io_safe_output($json_profile), true); foreach ($json_profile as $key => $profile) { + if (is_array($profile) === false) { + $profile = json_decode($profile, true); + } + if (!empty($profile)) { $group2 = $profile['group']; $profile2 = $profile['profile']; @@ -806,6 +810,10 @@ if ($add_profile && empty($json_profile)) { 'Profile: '.$profile2.' Group: '.$group2.' Tags: '.$tags ); $return = profile_create_user_profile($id2, $profile2, $group2, false, $tags, $no_hierarchy); + if ($return === false) { + $is_err = true; + } + ui_print_result_message( $return, __('Profile added successfully'), @@ -1439,7 +1447,7 @@ if ($config['admin_can_add_user']) { echo ''; -html_print_input_hidden('json_profile', ''); +html_print_input_hidden('json_profile', $json_profile); echo ''; @@ -1566,7 +1574,12 @@ $(document).ready (function () { var user_is_global_admin = ''; var is_err = ''; var data = []; + var aux = 0; + if(json_profile.val() != '') { + var data = JSON.parse(json_profile.val()); + } + $('input:image[name="add"]').click(function (e) { e.preventDefault(); var profile = $('#assign_profile').val(); @@ -1588,10 +1601,14 @@ $(document).ready (function () { return; } - if (id_user === '' || is_err === 1) { + if (id_user == '' || is_err == 1) { let new_json = `{"profile":${profile},"group":${group},"tags":[${tags}],"hierarchy":${hierarchy}}`; data.push(new_json); - json_profile.val('['+data+']'); + json_profile.val(JSON.stringify(data)); + profile_text = `${profile_text}`; + group_img = `${group_text}`; + group_text = `${group_img}${group_text}`; + $('#table_profiles tr:last').before( ` ${profile_text} @@ -1601,6 +1618,10 @@ $(document).ready (function () { ${img_delete} ` ); + + getGroupIcon(group, $(`#img_group_${aux}`)); + aux++; + } else { this.form.submit(); } diff --git a/pandora_console/include/functions_profile.php b/pandora_console/include/functions_profile.php index c6a62c4c9d..ad052dadbd 100644 --- a/pandora_console/include/functions_profile.php +++ b/pandora_console/include/functions_profile.php @@ -181,7 +181,7 @@ function profile_delete_profile_and_clean_users($id_profile) * @param int User id * @param bool Show the tags select or not */ -function profile_print_profile_table($id, $json_profile=false) +function profile_print_profile_table($id, $json_profile=false, $return=false) { global $config; @@ -246,6 +246,10 @@ function profile_print_profile_table($id, $json_profile=false) if ($json_profile !== false && empty($json_profile) !== true) { $profile_decoded = json_decode($json_profile); foreach ($profile_decoded as $profile) { + if (is_object($profile) === false) { + $profile = json_decode($profile); + } + $result[] = [ 'id_grupo' => $profile->group, 'id_perfil' => $profile->profile, @@ -293,10 +297,10 @@ function profile_print_profile_table($id, $json_profile=false) $data['hierarchy'] = $profile['no_hierarchy'] ? __('Yes') : __('No'); $data['actions'] = '
'; + $data['actions'] .= html_print_input_image('del', 'images/cross.png', 1, ['class' => 'invert_filter'], true); $data['actions'] .= html_print_input_hidden('delete_profile', 1, true); $data['actions'] .= html_print_input_hidden('id_user_profile', $profile['id_up'], true); $data['actions'] .= html_print_input_hidden('id_user', $id, true); - $data['actions'] .= html_print_input_image('del', 'images/cross.png', 1, ['class' => 'invert_filter'], true); $data['actions'] .= '
'; array_push($table->data, $data); @@ -362,8 +366,7 @@ function profile_print_profile_table($id, $json_profile=false) $data['actions'] .= ''; array_push($table->data, $data); - - html_print_table($table); + html_print_table($table, $return); if (!is_metaconsole()) { echo ''; } diff --git a/pandora_console/include/javascript/pandora_ui.js b/pandora_console/include/javascript/pandora_ui.js index eeeb5fcfd5..ecb23827d9 100644 --- a/pandora_console/include/javascript/pandora_ui.js +++ b/pandora_console/include/javascript/pandora_ui.js @@ -740,3 +740,26 @@ function reveal_password(name) { revealElement.attr("src", imagesPath + "eye_show.png"); } } + +/** + * Returns html img group icon. + * @param {int} $id_group + */ +function getGroupIcon(id_group, img_container) { + $.ajax({ + type: "POST", + url: "ajax.php", + dataType: "json", + data: { + page: "godmode/groups/group_list", + get_group_json: 1, + id_group: id_group + }, + success: function(data) { + img_container.attr("src", "images/groups_small/" + data["icon"] + ".png"); + }, + error: function() { + img_container.attr("src", ""); + } + }); +}