From 756cf4cbf72cdfebe2c293ce1069172110f0e3e4 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 9 Mar 2015 19:29:45 +0100 Subject: [PATCH] Added the posibility to filter by 1 group or tag. Useful when accessing the tree view from the group view --- pandora_console/include/ajax/tree.ajax.php | 2 + pandora_console/include/class/Tree.class.php | 66 ++++++++++++++++++- .../include/javascript/tree/TreeController.js | 2 +- pandora_console/operation/tree.php | 8 +++ 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index 46d1d1ef04..bb495698d6 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -42,6 +42,8 @@ if (is_ajax ()) { 'statusAgent' => AGENT_STATUS_ALL, 'searchModule' => '', 'statusModule' => -1, + 'groupID' => 0, + 'tagID' => 0, ); $filter = get_parameter('filter', $default_filters); diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 66f430e59d..c2de776450 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -479,10 +479,16 @@ class Tree { if (empty($rootID) || $rootID == -1) { if ($this->strictACL) return false; - + + // tagID filter. To access the view from tactical views f.e. + $tag_filter = ''; + if (!empty($this->filter['tagID'])) { + $tag_filter = "WHERE tt.id_tag = " . $this->filter['tagID']; + } + $columns = 'tt.id_tag AS id, tt.name AS name'; $order_fields = 'tt.name ASC, tt.id_tag ASC'; - + // Tags SQL if ($item_for_count === false) { $sql = "SELECT $columns @@ -500,6 +506,7 @@ class Tree { $group_acl $agent_search_filter $agent_status_filter + $tag_filter GROUP BY tt.id_tag ORDER BY $order_fields"; } @@ -1450,6 +1457,28 @@ class Tree { } } + private static function extractItemWithID ($items, $item_id, $item_type = "group") { + foreach ($items as $item) { + if ($item["type"] != $item_type) + continue; + + // Item found + if ($item["id"] == $item_id) + return $item; + + if ($item["type"] == "group" && !empty($item["children"])) { + $result = self::extractItemWithID($item["children"], $item_id, $item_type); + + // Item found on children + if ($result !== false) + return $result; + } + } + + // Item not found + return false; + } + public function getData() { if (! $this->strictACL) { @@ -1565,6 +1594,16 @@ class Tree { // array_filter clean the empty elements $processed_items = array_filter($processed_items_tmp); } + + // groupID filter. To access the view from tactical views f.e. + if (!empty($processed_items) && !empty($this->filter['groupID'])) { + $result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group"); + + if ($result === false) + $processed_items = array(); + else + $processed_items = array($result); + } } else { $unmerged_items = array(); @@ -1597,6 +1636,20 @@ class Tree { $processed_items = $this->getMergedItems($unmerged_items); } + + if (!empty($processed_items)) { + if (!empty($this->filter["groupID"])) { + $result = self::extractItemWithID($processed_items, $this->filter["groupID"], "group"); + } + else if (!empty($this->filter["tagID"])) { + $result = self::extractItemWithID($processed_items, $this->filter["tagID"], "tag"); + } + + if ($result === false) + $processed_items = array(); + else + $processed_items = array($result); + } } // Agents else { @@ -1686,6 +1739,15 @@ class Tree { $processed_items = $this->getMergedItems($item_list); } + // groupID filter. To access the view from tactical views f.e. + if (!empty($processed_items) && !empty($this->filter['groupID'])) { + $result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group"); + + if ($result === false) + $processed_items = array(); + else + $processed_items = array($result); + } } // Agents else { diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 552a017b3f..07f869b553 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -306,7 +306,7 @@ TreeController = { +'images/groups_small/'+element.icon+'" /> '); } else if (typeof element.iconHTML != 'undefined' && element.iconHTML.length > 0) { - $content.append(element.iconHTML); + $content.append(element.iconHTML + " "); } $content.append(element.name); break; diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 2b4dd5b062..30b8b3d984 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -22,6 +22,8 @@ $search_agent = get_parameter('searchAgent', ''); $status_agent = get_parameter('statusAgent', AGENT_STATUS_ALL); $search_module = get_parameter('searchModule', ''); $status_module = get_parameter('statusModule', -1); +$group_id = (int) get_parameter('group_id'); +$tag_id = (int) get_parameter('tag_id'); $strict_acl = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); @@ -204,6 +206,10 @@ if (!$strict_acl) { ui_toggle($form_html, __('Tree search')); } } + +html_print_input_hidden("group-id", $group_id); +html_print_input_hidden("tag-id", $tag_id); + // --------------------- form filter ----------------------------------- ui_include_time_picker(); @@ -263,6 +269,8 @@ enterprise_hook('close_meta_frame'); parameters['filter']['statusAgent'] = $("select#status_agent").val(); parameters['filter']['searchModule'] = $("input#text-search_module").val(); parameters['filter']['statusModule'] = $("select#status_module").val(); + parameters['filter']['groupID'] = $("input#hidden-group-id").val(); + parameters['filter']['tagID'] = $("input#hidden-tag-id").val(); $.ajax({ type: "POST",