From e05bf38245cc614fad6d56c148eda8f1106987c2 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 18 Feb 2011 15:13:34 +0000 Subject: [PATCH] 2011-02-18 Miguel de Dios * include/functions_db.php, operation/search_modules.php, operation/search_agents.php: sorry, I didn't think about the subgroups may have other subgroups (and this may be recursive), rewrite the SQL for search with groups, now the groups come from the PHP function to get all groups, children groups, grandchildren groups... git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3927 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 +++++ pandora_console/include/functions_db.php | 38 +++----------------- pandora_console/operation/search_agents.php | 38 +++----------------- pandora_console/operation/search_modules.php | 38 +++----------------- 4 files changed, 20 insertions(+), 102 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index d477ae0e7f..5f2fb27877 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2011-02-18 Miguel de Dios + + * include/functions_db.php, operation/search_modules.php, + operation/search_agents.php: sorry, I didn't think about the subgroups may + have other subgroups (and this may be recursive), rewrite the SQL for + search with groups, now the groups come from the PHP function to get + all groups, children groups, grandchildren groups... + 2011-02-18 Miguel de Dios * include/functions_db.php, operation/search_modules.php, diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 82715ccdb9..2937a5a54a 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -702,6 +702,9 @@ function get_agent_modules ($id_agent = null, $details = false, $filter = false, } $id_agent = safe_int ($id_agent, 1); + + $userGroups = get_user_groups($config['id_user'], 'AR', false); + $id_userGroups = array_keys($userGroups); $where = " WHERE ( 1 = ( @@ -714,40 +717,7 @@ function get_agent_modules ($id_agent = null, $details = false, $filter = false, SELECT id_agente FROM tagente WHERE id_grupo IN ( - SELECT id_grupo - FROM tgrupo - WHERE id_grupo IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = '" . $config['id_user'] . "' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - OR ( - parent IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = '" . $config['id_user'] . "' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) AND 1 = ( - SELECT propagate - FROM tgrupo - WHERE id_grupo IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = '" . $config['id_user'] . "' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) - ) + " . implode(',', $id_userGroups) . " ) ) OR 0 IN ( diff --git a/pandora_console/operation/search_agents.php b/pandora_console/operation/search_agents.php index acd387aa19..f326ea5523 100755 --- a/pandora_console/operation/search_agents.php +++ b/pandora_console/operation/search_agents.php @@ -105,6 +105,9 @@ switch ($sortField) { $agents = false; if ($searchAgents) { + $userGroups = get_user_groups($config['id_user'], 'AR', false); + $id_userGroups = array_keys($userGroups); + $sql = " FROM tagente AS t1 INNER JOIN tgrupo AS t2 @@ -116,40 +119,7 @@ if ($searchAgents) { WHERE id_user = '" . $config['id_user'] . "' ) OR t1.id_grupo IN ( - SELECT id_grupo - FROM tagente - WHERE id_grupo IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = '" . $config['id_user'] . "' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - OR ( - parent IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = '" . $config['id_user'] . "' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) AND 1 = ( - SELECT propagate - FROM tgrupo - WHERE id_grupo IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = '" . $config['id_user'] . "' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) - ) + " . implode(',', $id_userGroups) . " ) OR 0 IN ( SELECT id_grupo diff --git a/pandora_console/operation/search_modules.php b/pandora_console/operation/search_modules.php index 3ea10a3e81..aad803ce6b 100644 --- a/pandora_console/operation/search_modules.php +++ b/pandora_console/operation/search_modules.php @@ -55,6 +55,9 @@ switch ($sortField) { $modules = false; if ($searchModules) { + $userGroups = get_user_groups($config['id_user'], 'AR', false); + $id_userGroups = array_keys($userGroups); + $chunk_sql = ' FROM tagente_modulo AS t1 INNER JOIN tagente AS t2 @@ -64,40 +67,7 @@ if ($searchModules) { INNER JOIN tagente_estado AS t4 ON t4.id_agente_modulo = t1.id_agente_modulo WHERE (t2.id_grupo IN ( - SELECT id_grupo - FROM tgrupo - WHERE id_grupo IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = "' . $config['id_user'] . '" - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - OR ( - parent IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = "' . $config['id_user'] . '" - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) AND 1 = ( - SELECT propagate - FROM tgrupo - WHERE id_grupo IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario = "' . $config['id_user'] . '" - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) - ) + ' . implode(',', $id_userGroups) . ' ) OR 0 IN ( SELECT id_grupo