From d3bd24fc181743fa0e801ba2abbecb0d1f9d9b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Mon, 24 May 2021 11:01:50 +0200 Subject: [PATCH] Fixed some errors and fixed issue finding policies --- .../operation/search_agents.getdata.php | 6 +- .../operation/search_policies.getdata.php | 73 +++++++++++++------ 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/pandora_console/operation/search_agents.getdata.php b/pandora_console/operation/search_agents.getdata.php index dede18d3f1..5b86af6f2a 100644 --- a/pandora_console/operation/search_agents.getdata.php +++ b/pandora_console/operation/search_agents.getdata.php @@ -195,8 +195,10 @@ if ($searchAgents) { t1.comentarios COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR t1.id_agente = $aux"; - if (count($id) >= 2) { - for ($i = 1; $i < count($id); $i++) { + $idCount = count($id); + + if ($idCount >= 2) { + for ($i = 1; $i < $idCount; $i++) { $aux = $id[$i]['id_agent']; $search_sql .= " OR t1.id_agente = $aux"; } diff --git a/pandora_console/operation/search_policies.getdata.php b/pandora_console/operation/search_policies.getdata.php index 078ebb7be5..c338e4b19d 100644 --- a/pandora_console/operation/search_policies.getdata.php +++ b/pandora_console/operation/search_policies.getdata.php @@ -1,24 +1,39 @@ 'id', @@ -58,6 +74,7 @@ switch ($sortField) { case 'name': switch ($sort) { case 'up': + default: $selectNameUp = $selected; $order = [ 'field' => 'name', @@ -78,6 +95,7 @@ switch ($sortField) { case 'description': switch ($sort) { case 'up': + default: $selectId_groupUp = $selected; $order = [ 'field' => 'description', @@ -98,6 +116,7 @@ switch ($sortField) { case 'last_contact': switch ($sort) { case 'up': + default: $selectId_groupUp = $selected; $order = [ 'field' => 'last_connect', @@ -118,6 +137,7 @@ switch ($sortField) { case 'id_group': switch ($sort) { case 'up': + default: $selectId_groupUp = $selected; $order = [ 'field' => 'last_connect', @@ -138,6 +158,7 @@ switch ($sortField) { case 'status': switch ($sort) { case 'up': + default: $selectStatusUp = $selected; $order = [ 'field' => 'is_admin', @@ -174,31 +195,39 @@ switch ($sortField) { break; } -if ($searchpolicies) { +if ($searchpolicies === true) { /* We take the user groups to get policies that meet the requirements of the search and which the user have permission on this groups */ + $user_groups = users_get_groups($config['id_user'], 'AR', false); $id_user_groups = array_keys($user_groups); $id_user_groups_str = implode(',', $id_user_groups); - $sql = "SELECT id, name, description, id_group, status - FROM tpolicies - WHERE name LIKE '$stringSearchSQL' - AND id_group IN ($id_user_groups_str)"; + $sql = "SELECT id, name, description, id_group, status + FROM tpolicies + WHERE name LIKE '$stringSearchSQL' + AND + (id_group IN ($id_user_groups_str) + OR 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = 'admin' + ) + ) + "; } - $sql .= ' LIMIT '.$config['block_size'].' OFFSET '.get_parameter('offset', 0); + $sql .= ' LIMIT '.$config['block_size'].' OFFSET '.get_parameter('offset', 0); $policies = db_process_sql($sql); - if ($policies !== false) { $totalPolicies = count($policies); - if ($only_count) { + if ($only_count === true) { unset($policies); } } else {