Merge branch 'ent-9266-13916-formulario-de-registro-usuario-se-restablece-tras-error' into 'develop'
Fix user form reset if profile fails See merge request artica/pandorafms!5137
This commit is contained in:
commit
38af75ccc1
|
@ -509,6 +509,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'];
|
||||
|
@ -532,6 +536,14 @@ if ($create_user) {
|
|||
|
||||
$result_profile = profile_create_user_profile($id, $profile2, $group2, false, $tags, $no_hierarchy);
|
||||
|
||||
if ($result_profile === false) {
|
||||
$is_err = true;
|
||||
$user_info = $values;
|
||||
$password_new = '';
|
||||
$password_confirm = '';
|
||||
$new_user = true;
|
||||
}
|
||||
|
||||
ui_print_result_message(
|
||||
$result_profile,
|
||||
__('Profile added successfully'),
|
||||
|
@ -824,6 +836,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'),
|
||||
|
@ -1492,12 +1508,12 @@ if ($config['admin_can_add_user']) {
|
|||
|
||||
echo '</div>';
|
||||
|
||||
html_print_input_hidden('json_profile', '');
|
||||
html_print_input_hidden('json_profile', $json_profile);
|
||||
|
||||
echo '</form>';
|
||||
|
||||
|
||||
profile_print_profile_table($id);
|
||||
profile_print_profile_table($id, io_safe_output($json_profile));
|
||||
|
||||
echo '<br />';
|
||||
|
||||
|
@ -1613,13 +1629,18 @@ $(document).ready (function () {
|
|||
switch_ehorus_conf();
|
||||
});
|
||||
$('#checkbox-ehorus_user_level_enabled').trigger('change');
|
||||
|
||||
var img_delete = '<?php echo $delete_image; ?>';
|
||||
var id_user = '<?php echo io_safe_output($id); ?>';
|
||||
var is_metaconsole = '<?php echo $meta; ?>';
|
||||
var user_is_global_admin = '<?php echo users_is_admin($id); ?>';
|
||||
var is_err = '<?php echo $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();
|
||||
|
@ -1641,10 +1662,14 @@ $(document).ready (function () {
|
|||
return;
|
||||
}
|
||||
|
||||
if (id_user === '') {
|
||||
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 = `<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(
|
||||
`<tr>
|
||||
<td>${profile_text}</td>
|
||||
|
@ -1654,6 +1679,10 @@ $(document).ready (function () {
|
|||
<td>${img_delete}</td>
|
||||
</tr>`
|
||||
);
|
||||
|
||||
getGroupIcon(group, $(`#img_group_${aux}`));
|
||||
aux++;
|
||||
|
||||
} else {
|
||||
this.form.submit();
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
function profile_print_profile_table($id, $json_profile=false, $return=false)
|
||||
{
|
||||
global $config;
|
||||
|
||||
|
@ -243,7 +243,23 @@ function profile_print_profile_table($id)
|
|||
}
|
||||
|
||||
if ($result === false) {
|
||||
$result = [];
|
||||
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,
|
||||
'tags' => $profile->tags,
|
||||
'hierarchy' => $profile->hierarchy,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$result = [];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($result as $profile) {
|
||||
|
@ -268,7 +284,12 @@ function profile_print_profile_table($id)
|
|||
if (empty($profile['tags'])) {
|
||||
$data['tags'] = '';
|
||||
} else {
|
||||
$tags_ids = explode(',', $profile['tags']);
|
||||
if (is_array($profile['tags'] === false)) {
|
||||
$tags_ids = explode(',', $profile['tags']);
|
||||
} else {
|
||||
$tags_ids = $profile['tags'];
|
||||
}
|
||||
|
||||
$tags = tags_get_tags($tags_ids);
|
||||
$data['tags'] = tags_get_tags_formatted($tags);
|
||||
}
|
||||
|
@ -276,10 +297,10 @@ function profile_print_profile_table($id)
|
|||
$data['hierarchy'] = $profile['no_hierarchy'] ? __('Yes') : __('No');
|
||||
|
||||
$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('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'] .= '</form>';
|
||||
|
||||
array_push($table->data, $data);
|
||||
|
@ -345,8 +366,7 @@ function profile_print_profile_table($id)
|
|||
$data['actions'] .= '</form>';
|
||||
|
||||
array_push($table->data, $data);
|
||||
|
||||
html_print_table($table);
|
||||
html_print_table($table, $return);
|
||||
if (!is_metaconsole()) {
|
||||
echo '</div>';
|
||||
}
|
||||
|
|
|
@ -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", "");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue