From 2d057f9ae9c9b15e7444a3ef3379d72e40abd980 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 2 Oct 2018 13:35:48 +0200 Subject: [PATCH] Fixed tags problems with secondary groups in tree view --- pandora_console/include/class/Tree.class.php | 33 ++++++++----------- .../include/class/TreeTag.class.php | 4 +++ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 11f7fa56c5..86da888d04 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -205,26 +205,19 @@ class Tree { return "AND ta.$field_filter > 0" . $show_init_condition; } - // FIXME: Separate and condition from inner join protected function getTagJoin () { - // $parent is the agent id - $group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $this->id); - $tag_join = ''; - if (empty($group_id)) { - // ACL error, this will restrict the module search - $tag_join = 'INNER JOIN ttag_module tta - ON 1=0'; - } - else if (!empty($this->acltags) && isset($this->acltags[$group_id])) { - $tags_str = $this->acltags[$group_id]; + return 'INNER JOIN ttag_module ttm + ON tam.id_agente_modulo = ttm.id_agente_modulo'; + } - if (!empty($tags_str)) { - $tag_join = sprintf('INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag IN (%s)', $tags_str); - } - } - return $tag_join; + protected function getTagCondition () { + $tags = tags_get_user_applied_agent_tags($this->id, "AR"); + // All tags permision, returns no condition + if ($tags === true) return ""; + // No permision, do not show anything + if ($tags === false) return " AND 1=0"; + $tags_sql = implode(',', $tags); + return "AND ttm.id_tag IN ($tags_sql)";; } protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) { @@ -900,7 +893,8 @@ class Tree { $module_search_filter = $this->getModuleSearchFilter(); $module_status_filter = $this->getModuleStatusFilterFromTestado(); $agent_filter = "AND ta.id_agente = " . $this->id; - $tag_join = $this->getTagJoin(); + $tag_condition = $this->getTagCondition(); + $tag_join = empty($tag_condition) ? '' : $this->getTagJoin(); $condition = $this->L2condition; $inner = $this->L2inner; @@ -929,6 +923,7 @@ class Tree { $agent_status_filter $module_status_filter $module_search_filter + $tag_condition ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC"; return $sql; } diff --git a/pandora_console/include/class/TreeTag.class.php b/pandora_console/include/class/TreeTag.class.php index 516dceb3db..c02fb7ba4a 100644 --- a/pandora_console/include/class/TreeTag.class.php +++ b/pandora_console/include/class/TreeTag.class.php @@ -52,6 +52,10 @@ class TreeTag extends Tree { protected function getTagJoin () { return ''; } + + protected function getTagCondition () { + return ''; + } } ?>