diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php
index ac110b0d6f..5a4653fc29 100644
--- a/pandora_console/godmode/agentes/module_manager_editor_common.php
+++ b/pandora_console/godmode/agentes/module_manager_editor_common.php
@@ -1191,49 +1191,54 @@ $table_relations->data[-1][3] .= html_print_image('images/lock.png', true).'
$table_relations->data[-1][4] = '';
$table_relations->data[-1][4] .= html_print_image('images/cross.png', true).'';
-$module_relations = modules_get_relations(['id_module' => $id_agent_module]);
-if (!$module_relations) {
- $module_relations = [];
-}
$relations_count = 0;
-foreach ($module_relations as $key => $module_relation) {
- if ($module_relation['module_a'] == $id_agent_module) {
- $module_id = $module_relation['module_b'];
- $agent_id = modules_give_agent_id_from_module_id(
- $module_relation['module_b']
- );
- } else {
- $module_id = $module_relation['module_a'];
- $agent_id = modules_give_agent_id_from_module_id(
- $module_relation['module_a']
- );
+if ($id_agent_module) {
+ $module_relations = modules_get_relations(['id_module' => $id_agent_module]);
+
+ if (!$module_relations) {
+ $module_relations = [];
}
- $agent_name = ui_print_agent_name($agent_id, true);
+ $relations_count = 0;
+ foreach ($module_relations as $key => $module_relation) {
+ if ($module_relation['module_a'] == $id_agent_module) {
+ $module_id = $module_relation['module_b'];
+ $agent_id = modules_give_agent_id_from_module_id(
+ $module_relation['module_b']
+ );
+ } else {
+ $module_id = $module_relation['module_a'];
+ $agent_id = modules_give_agent_id_from_module_id(
+ $module_relation['module_a']
+ );
+ }
- $module_name = modules_get_agentmodule_name($module_id);
- if (empty($module_name) || $module_name == 'false') {
- $module_name = $module_id;
+ $agent_name = ui_print_agent_name($agent_id, true);
+
+ $module_name = modules_get_agentmodule_name($module_id);
+ if (empty($module_name) || $module_name == 'false') {
+ $module_name = $module_id;
+ }
+
+ if ($module_relation['disable_update']) {
+ $disabled_update_class = '';
+ } else {
+ $disabled_update_class = 'alpha50';
+ }
+
+ // Agent name.
+ $table_relations->data[$relations_count][0] = $agent_name;
+ // Module name.
+ $table_relations->data[$relations_count][1] = "".ui_print_truncate_text($module_name, 'module_medium', true, true, true, '[…]').'';
+ // Type.
+ $table_relations->data[$relations_count][2] = ($module_relation['type'] === 'direct') ? __('Direct') : __('Failover');
+ // Lock relationship updates.
+ $table_relations->data[$relations_count][3] = ''.html_print_image('images/lock.png', true).'';
+ // Delete relationship.
+ $table_relations->data[$relations_count][4] = ''.html_print_image('images/cross.png', true).'';
+ $relations_count++;
}
-
- if ($module_relation['disable_update']) {
- $disabled_update_class = '';
- } else {
- $disabled_update_class = 'alpha50';
- }
-
- // Agent name.
- $table_relations->data[$relations_count][0] = $agent_name;
- // Module name.
- $table_relations->data[$relations_count][1] = "".ui_print_truncate_text($module_name, 'module_medium', true, true, true, '[…]').'';
- // Type.
- $table_relations->data[$relations_count][2] = ($module_relation['type'] === 'direct') ? __('Direct') : __('Failover');
- // Lock relationship updates.
- $table_relations->data[$relations_count][3] = ''.html_print_image('images/lock.png', true).'';
- // Delete relationship.
- $table_relations->data[$relations_count][4] = ''.html_print_image('images/cross.png', true).'';
- $relations_count++;
}
html_print_input_hidden('module_relations_count', $relations_count);
diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php
index fbee2a5331..39cc5b4a49 100755
--- a/pandora_console/include/functions_modules.php
+++ b/pandora_console/include/functions_modules.php
@@ -2654,21 +2654,18 @@ function modules_get_relations($params=[])
}
$modules_type = '';
+ $modules_type_filter = '';
if (isset($params['modules_type'])) {
- $modules_type = $params['modules_type'];
+ $module_type = 'INNER JOIN ttipo_modulo ttm ON tam.id_tipo_modulo = ttm.id_tipo';
+ $modules_type_filter = sprintf(
+ "AND ttm.nombre = '%s'",
+ $params['modules_type']
+ );
}
- $sql = 'SELECT DISTINCT tmr.id, tmr.module_a, tmr.module_b,
- tmr.disable_update, tmr.type
- FROM tmodule_relationship tmr,
- tagente_modulo tam,
- tagente ta,
- ttipo_modulo ttm
- WHERE ';
-
- $agent_filter = '';
- if ($id_agent > 0) {
- $agent_filter = sprintf('AND ta.id_agente = %d', $id_agent);
+ $distinct = '';
+ if (empty($params)) {
+ $distinct = 'DISTINCT';
}
$module_a_filter = '';
@@ -2678,6 +2675,11 @@ function modules_get_relations($params=[])
$module_b_filter = sprintf('AND tmr.module_b = %d', $id_module);
}
+ $agent_filter = '';
+ if ($id_agent > 0) {
+ $agent_filter = sprintf('AND ta.id_agente = %d', $id_agent);
+ }
+
$disabled_update_filter = '';
if ($disabled_update >= 0) {
$disabled_update_filter = sprintf(
@@ -2686,22 +2688,25 @@ function modules_get_relations($params=[])
);
}
- $modules_type_filter = '';
- if ($modules_type != '') {
- $modules_type_filter = sprintf(
- "AND (tam.id_tipo_modulo = ttm.id_tipo AND ttm.nombre = '%s')",
- $modules_type
- );
- }
-
- $sql .= "( (tmr.module_a = tam.id_agente_modulo
- $module_a_filter)
- OR (tmr.module_b = tam.id_agente_modulo
- $module_b_filter) )
- AND tam.id_agente = ta.id_agente
- $agent_filter
- $disabled_update_filter
- $modules_type_filter";
+ $sql = sprintf(
+ 'SELECT %s tmr.id, tmr.module_a, tmr.module_b,
+ tmr.disable_update, tmr.type
+ FROM tmodule_relationship tmr
+ INNER JOIN tagente_modulo tam
+ ON (tmr.module_a = tam.id_agente_modulo %s)
+ OR (tmr.module_b = tam.id_agente_modulo %s)
+ INNER JOIN tagente ta
+ ON tam.id_agente = ta.id_agente
+ %s
+ WHERE 1=1 %s %s %s',
+ $distinct,
+ $module_a_filter,
+ $module_b_filter,
+ $module_type,
+ $agent_filter,
+ $disabled_update_filter,
+ $modules_type_filter
+ );
return db_get_all_rows_sql($sql);
}