diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 34627d1a38..af971ad6f3 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -68,6 +68,7 @@ class Tree { private function getRecursiveGroup($parent, $limit = null) { $filter = array(); + $filter['parent'] = $parent; if (!empty($this->filter['search'])) { @@ -81,12 +82,15 @@ class Tree { if (empty($groups)) $groups = array(); + // Filter by status $filter_status = AGENT_STATUS_ALL; if (!empty($this->filter['status'])) { $filter_status = $this->filter['status']; } + + foreach ($groups as $iterator => $group) { $groups[$iterator]['counters'] = array(); $groups[$iterator]['counters']['ok'] = @@ -129,6 +133,7 @@ class Tree { $remove_group = false; break; } + if ($remove_group) unset($groups[$iterator]); } @@ -145,7 +150,16 @@ class Tree { } } - return $groups; + if ($parent == 0) { + $agents = array(); + } + else { + $agents = $this->getDataAgents('group', $parent); + } + + $data = array_merge($groups, $agents); + + return $data; } public function getDataGroup() { @@ -157,19 +171,19 @@ class Tree { $parent = 0; } - $groups = $this->getRecursiveGroup($parent, 1); + $data = $this->getRecursiveGroup($parent, 1); switch ($this->childrenMethod) { case 'on_demand': - foreach ($groups as $iterator => $group) { - if (!empty($group['children'])) { - $groups[$iterator]['searchChildren'] = 1; + foreach ($data as $iterator => $item) { + if (!empty($item['children'])) { + $data[$iterator]['searchChildren'] = 1; // I hate myself - unset($groups[$iterator]['children']); + unset($data[$iterator]['children']); } else { - $groups[$iterator]['searchChildren'] = 0; + $data[$iterator]['searchChildren'] = 0; // I hate myself - unset($groups[$iterator]['children']); + unset($data[$iterator]['children']); } } break; @@ -195,18 +209,40 @@ class Tree { // Make the data $this->tree = array(); - foreach ($groups as $group) { - $data = array(); - $data['id'] = $group['id_grupo']; - $data['type'] = 'group'; - $data['name'] = $group['nombre']; - $data['searchChildren'] = $group['searchChildren']; - $data['searchCounters'] = $group['searchCounters']; + foreach ($data as $item) { + $temp = array(); + $temp['id'] = $item['id_grupo']; + $temp['type'] = 'group'; + $temp['name'] = $item['nombre']; + $temp['searchChildren'] = $item['searchChildren']; + $temp['searchCounters'] = $item['searchCounters']; - $this->tree[] = $data; + $this->tree[] = $temp; } } + public function getDataAgents($type, $id) { + switch ($type) { + case 'group': + $filter = array( + 'id_grupo' => $id, + 'status' => $this->filter['status'], + 'nombre' => "%" . $this->filter['search'] . "%" + ); + $agents = agents_get_agents($filter); + if (empty($agents)) { + $agents = array(); + } + break; + } + + foreach ($agents as $iterator => $agent) { + $agents[$iterator]['type'] = 'agent'; + } + + return $agents; + } + public function getDataModuleGroup() { } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index c7e5fcc551..51d7584534 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -367,7 +367,8 @@ function agents_get_agents ($filter = false, $fields = false, $access = 'AR', $o $where = db_format_array_where_clause_sql ($filter, 'AND', ''); - $where_nogroup = db_format_array_where_clause_sql ($filter_nogroup, 'AND', ''); + $where_nogroup = db_format_array_where_clause_sql( + $filter_nogroup, 'AND', ''); if ($where_nogroup == '') { $where_nogroup = '1 = 1'; diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index 095d30e61a..991436a5f5 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -159,7 +159,7 @@ echo ""; $.ajax({ type: "POST", - url: "/ajax.php", + url: "ajax.php", data: parameters, success: function(data) { if (data.success) { @@ -170,8 +170,8 @@ echo ""; detailRecipient: $("div#tree-controller-detail-recipient"), page: page, tree: data.tree, - baseURL: "/", - ajaxURL: "/ajax.php", + baseURL: "", + ajaxURL: "ajax.php", filter: { search: parameters['filter']['search'], status: parameters['filter']['status']