Fixed the order and hierarchy of groups in group view

This commit is contained in:
mdtrooper 2015-04-20 16:24:59 +02:00
parent 36c5349cf4
commit 8549dccd52
3 changed files with 29 additions and 4 deletions
pandora_console

@ -1631,6 +1631,8 @@ function modules_get_previous_data ($id_agent_module, $utimestamp = 0, $string =
ORDER BY utimestamp DESC',
$id_agent_module, $utimestamp, $utimestamp - SECONDS_2DAY);
$search_in_history_db = db_search_in_history_db($utimestamp);
return db_get_row_sql ($sql, $search_in_history_db);

@ -137,7 +137,10 @@ function users_get_groups_for_select($id_user, $privilege = "AR", $returnAllGro
*
* @return array A list of the groups the user has certain privileges.
*/
function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup = true, $returnAllColumns = false, $id_groups = null, $keys_field = 'id_grupo') {
function users_get_groups ($id_user = false, $privilege = "AR",
$returnAllGroup = true, $returnAllColumns = false, $id_groups = null,
$keys_field = 'id_grupo') {
if (empty ($id_user)) {
global $config;
@ -159,7 +162,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
$groups = db_get_all_rows_filter('tgrupo', array('id_grupo' => $list_id_groups, 'order' => 'parent, nombre'));
}
else {
$groups = db_get_all_rows_in_table ('tgrupo', 'parent, nombre');
$groups = db_get_all_rows_in_table ('tgrupo', array('parent', 'nombre'));
}
$user_groups = array ();

@ -53,7 +53,16 @@ if (isset ($_GET["update_netgroup"])) {
}
// Get group list that user has access
$groups_full = users_get_groups ($config['id_user'], "AR", true, true);
$groups_full = users_get_groups ($config['id_user'], "AR", true, true,
null, 'id_grupo', true);
foreach ($groups_full as $i => $g) {
if ($g['id_grupo'] == 0) {
$groups_full[$i]['parent'] = -1;
}
}
$groups_full = sort_by_hierarchy($groups_full);
$groups = array();
foreach ($groups_full as $group) {
@ -140,5 +149,16 @@ else {
"</div>";
}
function sort_by_hierarchy($groups, $parent = -1) {
$return = array();
foreach ($groups as $g) {
if ($g['parent'] == $parent) {
$return[] = $g;
$return = array_merge($return, sort_by_hierarchy($groups, $g['id_grupo']));
}
}
return $return;
}
?>