From 2df58cf15b168543d4f7e45623b472cadc466445 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 6 May 2011 09:17:40 +0000 Subject: [PATCH] 2011-05-05 Miguel de Dios * operation/search_agents.php: changed the SQL query for PostgreSQL. * godmode/agentes/configurar_agente.php: cleaned source code style. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4313 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- .../godmode/agentes/configurar_agente.php | 1 + pandora_console/operation/search_agents.php | 94 +++++++++++++------ pandora_server/ChangeLog | 6 ++ 3 files changed, 72 insertions(+), 29 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 0528a25d21..1d370806e5 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -129,6 +129,7 @@ if ($create_agent) { $cascade_protection = (int) get_parameter_post ("cascade_protection", 0); $icon_path = (string) get_parameter_post ("icon_path",''); $update_gis_data = (int) get_parameter_post("update_gis_data", 0); + $fields = db_get_all_fields_in_table('tagent_custom_fields'); if($fields === false) $fields = array(); diff --git a/pandora_console/operation/search_agents.php b/pandora_console/operation/search_agents.php index b66a636567..149b7e0d0c 100755 --- a/pandora_console/operation/search_agents.php +++ b/pandora_console/operation/search_agents.php @@ -112,41 +112,77 @@ 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 - ON t2.id_grupo = t1.id_grupo - WHERE ( - 1 = ( - SELECT is_admin - FROM tusuario - WHERE id_user = '" . $config['id_user'] . "' - ) - OR t1.id_grupo IN ( - " . implode(',', $id_userGroups) . " - ) - OR 0 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 + switch ($config["dbtype"]) { + case "mysql": + $sql = " + FROM tagente AS t1 + INNER JOIN tgrupo AS t2 + ON t2.id_grupo = t1.id_grupo + WHERE ( + 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = '" . $config['id_user'] . "' ) - ) - ) - AND ( - t1.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR - t2.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' - ) - "; - + OR t1.id_grupo IN ( + " . implode(',', $id_userGroups) . " + ) + OR 0 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 ( + t1.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR + t2.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' + ) + "; + break; + case "postgresql": + case "oracle": + $sql = " + FROM tagente AS t1 + INNER JOIN tgrupo AS t2 + ON t2.id_grupo = t1.id_grupo + WHERE ( + 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = '" . $config['id_user'] . "' + ) + OR t1.id_grupo IN ( + " . implode(',', $id_userGroups) . " + ) + OR 0 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 ( + t1.nombre LIKE '%%" . $stringSearchSQL . "%%' OR + t2.nombre LIKE '%%" . $stringSearchSQL . "%%' + ) + "; + break; + } $select = "SELECT t1.id_agente, t1.ultimo_contacto, t1.nombre, t1.id_os, t1.intervalo, t1.id_grupo, t1.disabled"; $limit = " ORDER BY " . $order['field'] . " " . $order['order'] . " LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); - $agents = db_process_sql($select . $sql . $limit); + $query = $select . $sql . $limit; + + $agents = db_process_sql($query); if($agents !== false) { $totalAgents = db_get_row_sql('SELECT COUNT(id_agente) AS agent_count ' . $sql); diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index dab9360019..e6d69e7c18 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2011-05-05 Miguel de Dios + + * operation/search_agents.php: changed the SQL query for PostgreSQL. + + * godmode/agentes/configurar_agente.php: cleaned source code style. + 2011-05-05 Miguel de Dios * include/functions_visual_map.php,