Merge branch 'ent-4681-8764-Fallo-en-Vodat-a-la-hora-de-editar-módulos-de-politica' into 'develop'

Fixed modules_get_relations

See merge request artica/pandorafms!2751
This commit is contained in:
Daniel Rodriguez 2019-10-07 14:01:24 +02:00
commit 375fac7f3d
2 changed files with 75 additions and 65 deletions

View File

@ -1191,7 +1191,11 @@ $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>';
$relations_count = 0;
if ($id_agent_module) {
$module_relations = modules_get_relations(['id_module' => $id_agent_module]);
if (!$module_relations) {
$module_relations = [];
}
@ -1235,6 +1239,7 @@ foreach ($module_relations as $key => $module_relation) {
$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);

View File

@ -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 = 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
);
}
$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";
return db_get_all_rows_sql($sql);
}