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,6 +65,20 @@ $id_profile = (int) get_parameter ('id');
// Profile deletion // Profile deletion
if ($delete_profile) { if ($delete_profile) {
$count_users_admin_in_profile = db_get_value_sql("
SELECT COUNT(*)
FROM tusuario
WHERE is_admin = 1 AND id_user IN (
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 {
// Delete profile // Delete profile
$profile = db_get_row('tperfil', 'id_perfil', $id_profile); $profile = db_get_row('tperfil', 'id_perfil', $id_profile);
$sql = sprintf ('DELETE FROM tperfil WHERE id_perfil = %d', $id_profile); $sql = sprintf ('DELETE FROM tperfil WHERE id_perfil = %d', $id_profile);
@ -84,6 +98,7 @@ if ($delete_profile) {
db_process_sql ($sql); db_process_sql ($sql);
$id_profile = 0; $id_profile = 0;
}
} }
// Store the variables when create or update // Store the variables when create or update