From b4079bd557ede66005b03883145568a189c5ffcd Mon Sep 17 00:00:00 2001
From: "alejandro.campos@artica.es" <alejandro.campos@artica.es>
Date: Wed, 30 Nov 2022 16:52:40 +0100
Subject: [PATCH] fixed query errors

---
 pandora_console/include/lib/Dashboard/Widgets/top_n.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n.php b/pandora_console/include/lib/Dashboard/Widgets/top_n.php
index 8e5aba52c0..4ec148973f 100644
--- a/pandora_console/include/lib/Dashboard/Widgets/top_n.php
+++ b/pandora_console/include/lib/Dashboard/Widgets/top_n.php
@@ -375,11 +375,19 @@ class TopNWidget extends Widget
             );
         }
 
+        // Prevent double safe input in agents_get_group_agents function.
+        $agentRegex = io_safe_output($agentRegex);
+
         // This function check ACL.
         $agents = @agents_get_group_agents(0, ['aliasRegex' => $agentRegex]);
         $agentsId = \array_keys($agents);
         $agentsIdString = \implode(',', $agentsId);
 
+        // Prevent from error when performing IN clause with an empty string.
+        if ($agentsIdString === '') {
+            $agentsIdString = 'NULL';
+        }
+
         // Initialize variables.
         $date = \get_system_time();
         $datelimit = ($date - $period);