Fix user profile add bugs

This commit is contained in:
Calvo 2022-10-17 12:26:38 +02:00
parent 1c157ba2e4
commit 2251062d30
3 changed files with 54 additions and 7 deletions

View File

@ -489,6 +489,10 @@ if ($create_user) {
if (!empty($json_profile)) { if (!empty($json_profile)) {
$json_profile = json_decode(io_safe_output($json_profile), true); $json_profile = json_decode(io_safe_output($json_profile), true);
foreach ($json_profile as $key => $profile) { foreach ($json_profile as $key => $profile) {
if (is_array($profile) === false) {
$profile = json_decode($profile, true);
}
if (!empty($profile)) { if (!empty($profile)) {
$group2 = $profile['group']; $group2 = $profile['group'];
$profile2 = $profile['profile']; $profile2 = $profile['profile'];
@ -806,6 +810,10 @@ if ($add_profile && empty($json_profile)) {
'Profile: '.$profile2.' Group: '.$group2.' Tags: '.$tags 'Profile: '.$profile2.' Group: '.$group2.' Tags: '.$tags
); );
$return = profile_create_user_profile($id2, $profile2, $group2, false, $tags, $no_hierarchy); $return = profile_create_user_profile($id2, $profile2, $group2, false, $tags, $no_hierarchy);
if ($return === false) {
$is_err = true;
}
ui_print_result_message( ui_print_result_message(
$return, $return,
__('Profile added successfully'), __('Profile added successfully'),
@ -1439,7 +1447,7 @@ if ($config['admin_can_add_user']) {
echo '</div>'; echo '</div>';
html_print_input_hidden('json_profile', ''); html_print_input_hidden('json_profile', $json_profile);
echo '</form>'; echo '</form>';
@ -1566,6 +1574,11 @@ $(document).ready (function () {
var user_is_global_admin = '<?php echo users_is_admin($id); ?>'; var user_is_global_admin = '<?php echo users_is_admin($id); ?>';
var is_err = '<?php echo $is_err; ?>'; var is_err = '<?php echo $is_err; ?>';
var data = []; var data = [];
var aux = 0;
if(json_profile.val() != '') {
var data = JSON.parse(json_profile.val());
}
$('input:image[name="add"]').click(function (e) { $('input:image[name="add"]').click(function (e) {
e.preventDefault(); e.preventDefault();
@ -1588,10 +1601,14 @@ $(document).ready (function () {
return; return;
} }
if (id_user === '' || is_err === 1) { if (id_user == '' || is_err == 1) {
let new_json = `{"profile":${profile},"group":${group},"tags":[${tags}],"hierarchy":${hierarchy}}`; let new_json = `{"profile":${profile},"group":${group},"tags":[${tags}],"hierarchy":${hierarchy}}`;
data.push(new_json); data.push(new_json);
json_profile.val('['+data+']'); json_profile.val(JSON.stringify(data));
profile_text = `<a href="index.php?sec2=godmode/users/configure_profile&id=${profile}">${profile_text}</a>`;
group_img = `<img id="img_group_${aux}" src="" data-title="${group_text}" data-use_title_for_force_title="1" class="bot forced_title" alt="${group_text}"/>`;
group_text = `<a href="index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id=${group}">${group_img}${group_text}</a>`;
$('#table_profiles tr:last').before( $('#table_profiles tr:last').before(
`<tr> `<tr>
<td>${profile_text}</td> <td>${profile_text}</td>
@ -1601,6 +1618,10 @@ $(document).ready (function () {
<td>${img_delete}</td> <td>${img_delete}</td>
</tr>` </tr>`
); );
getGroupIcon(group, $(`#img_group_${aux}`));
aux++;
} else { } else {
this.form.submit(); this.form.submit();
} }

View File

@ -181,7 +181,7 @@ function profile_delete_profile_and_clean_users($id_profile)
* @param int User id * @param int User id
* @param bool Show the tags select or not * @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; global $config;
@ -246,6 +246,10 @@ function profile_print_profile_table($id, $json_profile=false)
if ($json_profile !== false && empty($json_profile) !== true) { if ($json_profile !== false && empty($json_profile) !== true) {
$profile_decoded = json_decode($json_profile); $profile_decoded = json_decode($json_profile);
foreach ($profile_decoded as $profile) { foreach ($profile_decoded as $profile) {
if (is_object($profile) === false) {
$profile = json_decode($profile);
}
$result[] = [ $result[] = [
'id_grupo' => $profile->group, 'id_grupo' => $profile->group,
'id_perfil' => $profile->profile, '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['hierarchy'] = $profile['no_hierarchy'] ? __('Yes') : __('No');
$data['actions'] = '<form method="post" onsubmit="if (!confirm (\''.__('Are you sure?').'\')) return false">'; $data['actions'] = '<form method="post" onsubmit="if (!confirm (\''.__('Are you sure?').'\')) return false">';
$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('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_profile', $profile['id_up'], true);
$data['actions'] .= html_print_input_hidden('id_user', $id, 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'] .= '</form>'; $data['actions'] .= '</form>';
array_push($table->data, $data); array_push($table->data, $data);
@ -362,8 +366,7 @@ function profile_print_profile_table($id, $json_profile=false)
$data['actions'] .= '</form>'; $data['actions'] .= '</form>';
array_push($table->data, $data); array_push($table->data, $data);
html_print_table($table, $return);
html_print_table($table);
if (!is_metaconsole()) { if (!is_metaconsole()) {
echo '</div>'; echo '</div>';
} }

View File

@ -740,3 +740,26 @@ function reveal_password(name) {
revealElement.attr("src", imagesPath + "eye_show.png"); 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", "");
}
});
}