Merge branch 'ent-10860-problema-con-borrado-de-modulos-hijos-nietos-etc' into 'develop'

Ent 10860 problema con borrado de modulos hijos nietos etc

See merge request artica/pandorafms!5815
This commit is contained in:
Gorka Sanchez 2023-06-30 11:42:51 +00:00
commit 5e31ca7c65
2 changed files with 40 additions and 0 deletions

View File

@ -32,6 +32,7 @@ require_once $config['homedir'].'/include/functions_categories.php';
require_once $config['homedir'].'/include/graphs/functions_d3.php';
use PandoraFMS\Agent;
use Psr\Log\NullLogger;
include_javascript_d3();
@ -950,6 +951,15 @@ $table_advanced->data['tags_module_parent'][0] .= html_print_div(
if ((bool) $in_policies_page === false) {
// Cannot select the current module to be itself parent.
if ($id_agent_module !== 0) {
$module_parent_filter['tagente_modulo.id_agente_modulo'] = '<>'.$id_agent_module;
$array_parent_module_id = [];
get_agent_module_childs($array_parent_module_id, $id_agent_module, $id_agente);
} else {
$module_parent_filter = [];
$array_parent_module_id = [];
}
$module_parent_filter = ($id_agent_module) ? ['tagente_modulo.id_agente_modulo' => '<>'.$id_agent_module] : [];
$table_advanced->data['caption_tags_module_parent'][1] = __('Module parent');
// TODO. Review cause dont know not works.
@ -965,6 +975,13 @@ if ((bool) $in_policies_page === false) {
false,
$module_parent_filter
);
if (empty($array_parent_module_id) === false) {
foreach ($array_parent_module_id as $key => $value) {
unset($modules_can_be_parent[$value]);
}
}
// If the user cannot have access to parent module, only print the name.
if ((int) $parent_module_id !== 0
&& in_array($parent_module_id, array_keys($modules_can_be_parent)) === true

View File

@ -4655,3 +4655,26 @@ function policies_type_modules_availables(string $sec2): array
return $modules;
}
function get_agent_module_childs(
&$array_parent_module_id=[],
$id_agent_module=false,
$id_agente=false
) {
if ($array_parent_module_id !== false && $id_agent_module !== false && $id_agente !== false) {
$parent['parent_module_id'] = $id_agent_module;
$module_childs_id = agents_get_modules(
$id_agente,
'parent_module_id',
$parent
);
foreach ($module_childs_id as $key => $value) {
if ($value !== 0) {
$array_parent_module_id[] = $key;
get_agent_module_childs($array_parent_module_id, $key, $id_agente);
}
}
}
}