Added check for the profile is used by admin users before to delete. TICKET: #1753

This commit is contained in:
mdtrooper 2015-02-06 18:00:57 +01:00
parent cf84411c59
commit 39780da045
1 changed files with 30 additions and 15 deletions

View File

@ -65,25 +65,40 @@ $id_profile = (int) get_parameter ('id');
// Profile deletion // Profile deletion
if ($delete_profile) { if ($delete_profile) {
// Delete profile
$profile = db_get_row('tperfil', 'id_perfil', $id_profile); $count_users_admin_in_profile = db_get_value_sql("
$sql = sprintf ('DELETE FROM tperfil WHERE id_perfil = %d', $id_profile); SELECT COUNT(*)
$ret = db_process_sql ($sql); FROM tusuario
if ($ret === false) { WHERE is_admin = 1 AND id_user IN (
ui_print_error_message(__('There was a problem deleting the profile')); SELECT id_usuario
FROM tusuario_perfil
WHERE id_perfil = " . $id_profile . ")");
if ($count_users_admin_in_profile >= 1) {
ui_print_error_message(
__('Unsucessful delete profile. Because the profile is used by some admin users.'));
} }
else { else {
db_pandora_audit("Profile management", // Delete profile
"Delete profile ". $profile['name']); $profile = db_get_row('tperfil', 'id_perfil', $id_profile);
$sql = sprintf ('DELETE FROM tperfil WHERE id_perfil = %d', $id_profile);
$ret = db_process_sql ($sql);
if ($ret === false) {
ui_print_error_message(__('There was a problem deleting the profile'));
}
else {
db_pandora_audit("Profile management",
"Delete profile ". $profile['name']);
ui_print_success_message(__('Successfully deleted'));
}
ui_print_success_message(__('Successfully deleted')); //Delete profile from user data
$sql = sprintf ('DELETE FROM tusuario_perfil WHERE id_perfil = %d', $id_profile);
db_process_sql ($sql);
$id_profile = 0;
} }
//Delete profile from user data
$sql = sprintf ('DELETE FROM tusuario_perfil WHERE id_perfil = %d', $id_profile);
db_process_sql ($sql);
$id_profile = 0;
} }
// Store the variables when create or update // Store the variables when create or update