diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index c36536348f..39e74be0a3 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1494,6 +1494,15 @@ function events_get_all( MAX(id_evento) as max_id_evento', ($idx !== false) ? 'GROUP_CONCAT(DISTINCT user_comment SEPARATOR "
") AS comments,' : '' ); + + $group_selects_trans = sprintf( + ',tmax_event.event_rep, + %s + tmax_event.timestamp_last, + tmax_event.timestamp_first, + tmax_event.max_id_evento', + ($idx !== false) ? 'tmax_event.comments,' : '' + ); } } else { $idx = array_search('te.user_comment', $fields); @@ -1502,43 +1511,107 @@ function events_get_all( } } - $sql = sprintf( - 'SELECT %s + if ((int) $filter['group_rep'] === 1 && $count === false) { + $sql = sprintf( + 'SELECT %s + %s + FROM %s + INNER JOIN ( + SELECT te.id_evento %s + FROM %s + %s + %s + %s JOIN %s ta + ON ta.%s = te.id_agente + %s + %s + %s JOIN tgrupo tg + ON %s + WHERE 1=1 + %s + %s + %s + %s + %s + ) tmax_event + ON te.id_evento = tmax_event.max_id_evento %s - FROM %s - %s - %s - %s JOIN %s ta - ON ta.%s = te.id_agente - %s - %s - %s JOIN tgrupo tg - ON %s - WHERE 1=1 - %s - %s - %s - %s - %s - ', - join(',', $fields), - $group_selects, - $tevento, - $event_lj, - $agentmodule_join, - $tagente_join, - $tagente_table, - $tagente_field, - $conditionMetaconsole, - join(' ', $agent_join_filters), - $tgrupo_join, - join(' ', $tgrupo_join_filters), - join(' ', $sql_filters), - $group_by, - $order_by, - $pagination, - $having - ); + %s + %s JOIN %s ta + ON ta.%s = te.id_agente + %s + %s + %s JOIN tgrupo tg + ON %s', + join(',', $fields), + $group_selects_trans, + $tevento, + $group_selects, + $tevento, + $event_lj, + $agentmodule_join, + $tagente_join, + $tagente_table, + $tagente_field, + $conditionMetaconsole, + join(' ', $agent_join_filters), + $tgrupo_join, + join(' ', $tgrupo_join_filters), + join(' ', $sql_filters), + $group_by, + $order_by, + $pagination, + $having, + $event_lj, + $agentmodule_join, + $tagente_join, + $tagente_table, + $tagente_field, + $conditionMetaconsole, + join(' ', $agent_join_filters), + $tgrupo_join, + join(' ', $tgrupo_join_filters), + join(' ', $sql_filters) + ); + } else { + $sql = sprintf( + 'SELECT %s + %s + FROM %s + %s + %s + %s JOIN %s ta + ON ta.%s = te.id_agente + %s + %s + %s JOIN tgrupo tg + ON %s + WHERE 1=1 + %s + %s + %s + %s + %s + ', + join(',', $fields), + $group_selects, + $tevento, + $event_lj, + $agentmodule_join, + $tagente_join, + $tagente_table, + $tagente_field, + $conditionMetaconsole, + join(' ', $agent_join_filters), + $tgrupo_join, + join(' ', $tgrupo_join_filters), + join(' ', $sql_filters), + $group_by, + $order_by, + $pagination, + $having + ); + } if ($return_sql === true) { return $sql;