diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 5d2c4bf30b..cd2319da1d 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-01-14 Juan Manuel Ramon + + * include/functions_component_groups.php + godmode/modules/manage_network_components.php: Don't remove + parent component groups with childs assigned to components. + + Merged from branches. + 2013-01-14 Juan Manuel Ramon * godmode/modules/manage_nc_groups.php: Parent row removed. diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index 5ace2e74d8..00696c2cfb 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -28,6 +28,7 @@ if (! check_acl ($config['id_user'], 0, "PM")) { require_once ($config['homedir'] . '/include/functions_network_components.php'); include_once($config['homedir'] . "/include/functions_categories.php"); enterprise_include_once ('meta/include/functions_components_meta.php'); +require_once ($config['homedir'].'/include/functions_component_groups.php'); // Header if (defined('METACONSOLE')) { @@ -415,9 +416,25 @@ foreach ($component_groups as $component_group_key => $component_group_val) { $num_components = db_get_num_rows('SELECT id_nc FROM tnetwork_component WHERE id_group = ' . $component_group_key); + + $childs = component_groups_get_childrens($component_group_key); + + $num_components_childs = 0; + + if ($childs !== false) { + + foreach ($childs as $child) { + + $num_components_childs += db_get_num_rows('SELECT id + FROM tlocal_component + WHERE id_network_component_group = ' . $child['id_sg']); + + } + + } // Only show component groups with local components - if ($num_components == 0) + if ($num_components == 0 && $num_components_childs == 0) unset($component_groups[$component_group_key]); } diff --git a/pandora_console/include/functions_component_groups.php b/pandora_console/include/functions_component_groups.php index 61f4a802a3..c32a9a8dd6 100644 --- a/pandora_console/include/functions_component_groups.php +++ b/pandora_console/include/functions_component_groups.php @@ -49,4 +49,29 @@ function component_groups_get_groups_tree_recursive($groups, $parent = 0, $deep return $return; } +/** + * Return a array of id_group of childrens (to branches down) + * + * @param integer $parent The id_group parent to search the childrens. + * @param array $groups The groups, its for optimize the querys to DB. + */ +function component_groups_get_childrens($parent, $groups = null) { + if (empty($groups)) { + $groups = db_get_all_rows_in_table('tnetwork_component_group'); + } + + $return = array(); + + foreach ($groups as $key => $group) { + if ($group['id_sg'] == 0) { + continue; + } + if ($group['parent'] == $parent) { + $return = $return + array($group['id_sg'] => $group) + component_groups_get_childrens($group['id_sg'], $groups); + } + } + + return $return; +} + ?>