Added child module delete warning

This commit is contained in:
Calvo 2023-01-19 10:34:13 +01:00
parent 1522990afd
commit 8c071532e9
2 changed files with 38 additions and 7 deletions

View File

@ -1283,9 +1283,14 @@ foreach ($modules as $module) {
}
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
// Check module relatonships to show warning message.
$module_children = json_encode(get_children_module($module['id_agente_modulo'], 'nombre'));
$url = htmlentities('index.php?sec=gagente&tab=module&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&delete_module='.$module['id_agente_modulo']);
// Delete module.
$data[9] = '<a href="index.php?sec=gagente&tab=module&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&delete_module='.$module['id_agente_modulo'].'"
onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
$data[9] = '<a href="#"
onClick="delete_module_warning(\''.htmlentities($module_children).'\',\''.$url.'\')">';
$data[9] .= html_print_image(
'images/cross.png',
true,
@ -1394,4 +1399,30 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
window.location = window.location + "&checked=true";
}
}
function delete_module_warning(children_json, url) {
var message = '<?php echo __('Are you sure?'); ?>';
var children = JSON.parse(children_json);
var ret = false;
if(children != false) {
message += '<br><strong>' + '<?php echo __('This module has children modules. Following modules will be also deleted: '); ?>' + '</strong><ul>';
$.each(children, function (key, value) {
message += '<li>' + value['nombre'] + '</li>';
});
message += '</ul>';
}
ret = confirmDialog({
title: "<?php echo __('Delete module'); ?>",
message: message,
onAccept: function() {
window.location.href = url;
}
});
return false;
}
</script>

View File

@ -3988,12 +3988,12 @@ function recursive_get_dt_from_modules_tree(&$f_modules, $modules, $deep)
* @param integer $id_module Id module
* @return array Children module data
*/
function get_children_module($id_module)
function get_children_module($id_module, $fields=false)
{
$children_module_data = db_get_all_rows_sql(
'SELECT *
FROM tagente_modulo
WHERE parent_module_id = '.$id_module
$children_module_data = db_get_all_rows_filter(
'tagente_modulo',
['parent_module_id' => $id_module],
$fields
);
return $children_module_data;