2013-01-11 15:32:28 +01:00
|
|
|
<?php
|
|
|
|
// Pandora FMS - http://pandorafms.com
|
|
|
|
// ==================================================
|
|
|
|
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
|
|
|
|
// Please see http://pandorafms.org for full contribution list
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package Include
|
|
|
|
* @subpackage Component groups
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format components groups in tree way.
|
|
|
|
*
|
|
|
|
* @param array $groups The list of groups to create the treefield list.
|
|
|
|
* @param integer $parent The id_group of parent actual scan branch.
|
|
|
|
* @param integer $deep The level of profundity in the branch.
|
|
|
|
*
|
|
|
|
* @return array The treefield list of components groups.
|
|
|
|
*/
|
|
|
|
function component_groups_get_groups_tree_recursive($groups, $parent = 0, $deep = 0) {
|
|
|
|
$return = array();
|
2013-05-07 14:32:30 +02:00
|
|
|
|
2013-01-11 15:32:28 +01:00
|
|
|
foreach ($groups as $key => $group) {
|
|
|
|
if ($group['parent'] == $parent) {
|
|
|
|
$group['deep'] = $deep;
|
|
|
|
|
|
|
|
$branch = component_groups_get_groups_tree_recursive($groups, $key, $deep + 1);
|
|
|
|
if (empty($branch)) {
|
|
|
|
$group['hash_branch'] = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$group['hash_branch'] = true;
|
|
|
|
}
|
|
|
|
$return = $return + array($key => $group) + $branch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2013-01-14 15:16:06 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2013-01-11 15:32:28 +01:00
|
|
|
?>
|