diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php
index ef1b66a731..269d92f984 100644
--- a/pandora_console/godmode/groups/group_list.php
+++ b/pandora_console/godmode/groups/group_list.php
@@ -723,6 +723,11 @@ if ($is_management_allowed === true
['id_grupo' => $id_group]
);
+ $result_user_profile = db_process_sql_delete(
+ 'tusuario_perfil',
+ ['id_grupo' => $id_group]
+ );
+
if ($result && (!$usedGroup['return'])) {
db_process_sql_delete(
'tfavmenu_user',
@@ -1128,7 +1133,7 @@ if ($tab == 'tree') {
$confirm_message = __('The child groups will be updated to use the parent id of the deleted group').'. '.$confirm_message;
}
- $table->data[$key][6] .= ''.html_print_image(
+ $table->data[$key][6] .= ''.html_print_image(
'images/delete.svg',
true,
[
@@ -1214,7 +1219,6 @@ $tab = 'group_edition';
});
$('#button-filter').on('click', function(event) {
- console.log('here');
event.preventDefault();
load_tree(show_full_hirearchy, show_not_init_agents, show_not_init_modules);
@@ -1314,5 +1318,39 @@ $tab = 'group_edition';
});
}
+ function preprocessDeletion(group_id, delete_URL, confirm_text) {
+ var parameters = {};
+ parameters['page'] = 'include/ajax/group';
+ parameters['method'] = 'checkGroupIsLinkedToElement';
+ parameters['group_id'] = group_id;
+ parameters['table_name'] = 'tusuario_perfil';
+ parameters['field_name'] = 'id_grupo';
+
+ $.ajax({
+ type: "POST",
+ url: "",
+ data: parameters,
+ success: function(data) {
+ if (data.result == '1') {
+ confirmDialog({
+ title: '',
+ message: '',
+ onAccept: function() {
+ window.location.assign(delete_URL);
+ }
+ });
+ } else {
+ if (!confirm(confirm_text)) {
+ return false;
+ } else {
+ window.location.assign(delete_URL);
+ }
+ }
+ },
+ dataType: "json"
+ });
+
+ return true;
+ }
diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php
index 60d22cee1e..53e39b7243 100644
--- a/pandora_console/include/functions.php
+++ b/pandora_console/include/functions.php
@@ -6943,6 +6943,48 @@ function get_defined_translation($string)
}
+/**
+ * General utility to check if at least one element in an array meets a certain criteria defined by passed function.
+ *
+ * @param array $array Array to be checked.
+ * @param callable $fn Checking function (must accept one argument => array item to be evaluated and returns
+ * true/false depending on whether or not the condition was fulfilled).
+ *
+ * @return boolean
+ */
+function array_some(array $array, callable $fn)
+{
+ foreach ($array as $value) {
+ if ($fn($value) === true) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+/**
+ * General utility to check if every element in an array meets a certain criteria defined by passed function.
+ *
+ * @param array $array Array to be checked.
+ * @param callable $fn Checking function (must accept one argument => array item to be evaluated and returns
+ * true/false depending on whether or not the condition was fulfilled).
+ *
+ * @return boolean
+ */
+function array_every(array $array, callable $fn)
+{
+ foreach ($array as $value) {
+ if ($fn($value) === false) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
/**
* Merge any number of arrays by pairs of elements at the same index.
*
diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php
index a09baf5d9f..1cce0ec199 100644
--- a/pandora_console/include/functions_groups.php
+++ b/pandora_console/include/functions_groups.php
@@ -107,22 +107,6 @@ function groups_check_used($idGroup)
$return['tables'][] = __('Discovery task');
}
- switch ($config['dbtype']) {
- case 'mysql':
- case 'postgresql':
- $numRows = db_get_num_rows('SELECT * FROM tgraph WHERE id_group = '.$idGroup.';');
- break;
-
- case 'oracle':
- $numRows = db_get_num_rows('SELECT * FROM tgraph WHERE id_group = '.$idGroup);
- break;
- }
-
- if ($numRows > 0) {
- $return['return'] = true;
- $return['tables'][] = __('Graphs');
- }
-
switch ($config['dbtype']) {
case 'mysql':
case 'postgresql':
diff --git a/pandora_console/include/lib/Group.php b/pandora_console/include/lib/Group.php
index 66317471f6..66afa624ad 100644
--- a/pandora_console/include/lib/Group.php
+++ b/pandora_console/include/lib/Group.php
@@ -50,6 +50,7 @@ class Group extends Entity
'loadInfoAgent',
'getAgentsByGroup',
'getGroupsName',
+ 'checkGroupIsLinkedToElement',
];
@@ -777,5 +778,35 @@ class Group extends Entity
exit;
}
+ /**
+ * Check whether group is linked to a database element (needed for ajax check).
+ *
+ * @return void
+ */
+ public static function checkGroupIsLinkedToElement()
+ {
+ $group_id = get_parameter('group_id', null);
+ $table_name = get_parameter('table_name', null);
+ $field_name = get_parameter('field_name', null);
+
+ if (count(array_filter([$group_id, $table_name, $field_name])) < 3) {
+ $result['result'] = 0;
+ } else {
+ $sql = sprintf(
+ 'SELECT * FROM %s WHERE %s = %s',
+ $table_name,
+ $field_name,
+ $group_id
+ );
+
+ $count = db_get_num_rows($sql);
+
+ $result['result'] = (int) ($count > 0);
+ }
+
+ echo json_encode($result);
+ exit;
+ }
+
}