Fixed modules_get_relations
This commit is contained in:
parent
bf15240d7c
commit
4e47aede4c
|
@ -1191,49 +1191,54 @@ $table_relations->data[-1][3] .= html_print_image('images/lock.png', true).'</a>
|
|||
$table_relations->data[-1][4] = '<a id="delete_relation_button" href="">';
|
||||
$table_relations->data[-1][4] .= html_print_image('images/cross.png', true).'</a>';
|
||||
|
||||
$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] = "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente=".$agent_id.'&tab=module&edit_module=1&id_agent_module='.$module_id."'>".ui_print_truncate_text($module_name, 'module_medium', true, true, true, '[…]').'</a>';
|
||||
// Type.
|
||||
$table_relations->data[$relations_count][2] = ($module_relation['type'] === 'direct') ? __('Direct') : __('Failover');
|
||||
// Lock relationship updates.
|
||||
$table_relations->data[$relations_count][3] = '<a id="disable_updates_button" class="'.$disabled_update_class.'"href="javascript: change_lock_relation('.$relations_count.', '.$module_relation['id'].');">'.html_print_image('images/lock.png', true).'</a>';
|
||||
// Delete relationship.
|
||||
$table_relations->data[$relations_count][4] = '<a id="delete_relation_button" href="javascript: delete_relation('.$relations_count.', '.$module_relation['id'].');">'.html_print_image('images/cross.png', true).'</a>';
|
||||
$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] = "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente=".$agent_id.'&tab=module&edit_module=1&id_agent_module='.$module_id."'>".ui_print_truncate_text($module_name, 'module_medium', true, true, true, '[…]').'</a>';
|
||||
// Type.
|
||||
$table_relations->data[$relations_count][2] = ($module_relation['type'] === 'direct') ? __('Direct') : __('Failover');
|
||||
// Lock relationship updates.
|
||||
$table_relations->data[$relations_count][3] = '<a id="disable_updates_button" class="'.$disabled_update_class.'"href="javascript: change_lock_relation('.$relations_count.', '.$module_relation['id'].');">'.html_print_image('images/lock.png', true).'</a>';
|
||||
// Delete relationship.
|
||||
$table_relations->data[$relations_count][4] = '<a id="delete_relation_button" href="javascript: delete_relation('.$relations_count.', '.$module_relation['id'].');">'.html_print_image('images/cross.png', true).'</a>';
|
||||
$relations_count++;
|
||||
}
|
||||
|
||||
html_print_input_hidden('module_relations_count', $relations_count);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue