Fixed comments issues

This commit is contained in:
Jose Gonzalez 2021-12-01 13:15:34 +01:00
parent 64e08d7124
commit 3238811f96
2 changed files with 29 additions and 11 deletions

View File

@ -130,8 +130,12 @@ if ($get_comments === true) {
if (isset($event['event_rep']) === true && $event['event_rep'] > 0) {
// Evaluate if we are in metaconsole or not.
$eventTable = (is_metaconsole() === true) ? 'tmetaconsole_event' : 'tevento';
// Default grouped message filtering.
$whereGrouped = sprintf('`evento` = "%s"', io_safe_output($event['evento']));
// Default grouped message filtering (evento and estado).
$whereGrouped = sprintf(
'`evento` = "%s" AND `estado` = "%s"',
io_safe_output($event['evento']),
$event['estado']
);
// If id_agente is reported, filter the messages by them as well.
if ((int) $event['id_agente'] > 0) {
$whereGrouped .= sprintf(' AND `id_agente` = "%s"', $event['id_agente']);

View File

@ -25,6 +25,8 @@
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
global $config;
require_once $config['homedir'].'/include/functions_ui.php';
@ -35,7 +37,7 @@ enterprise_include_once('include/functions_metaconsole.php');
enterprise_include_once('meta/include/functions_events_meta.php');
enterprise_include_once('meta/include/functions_agents_meta.php');
enterprise_include_once('meta/include/functions_modules_meta.php');
if (is_metaconsole()) {
if (is_metaconsole() === true) {
$id_source_event = get_parameter('id_source_event');
}
@ -5124,12 +5126,29 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
$comments_array[] = io_safe_output(json_decode($comm, true));
}
// Plain comments. Can be improved.
$sortedCommentsArray = [];
foreach ($comments_array as $comm) {
foreach ($comm as $subComm) {
$sortedCommentsArray[] = $subComm;
}
}
// Sorting the comments by utimestamp (newer is first).
usort(
$comments_array,
$sortedCommentsArray,
function ($a, $b) {
return ($a[(count($a) - 1)]['utimestamp'] < $b[(count($b) - 1)]['utimestamp']);
if ($a['utimestamp'] == $b['utimestamp']) {
return 0;
}
return ($a['utimestamp'] > $b['utimestamp']) ? -1 : 1;
}
);
// Clean the unsorted comments and return it to the original array.
$comments_array = [];
$comments_array[] = $sortedCommentsArray;
} else {
$comments = str_replace(["\n", '&#x0a;'], '<br>', $comments);
// If comments are not stored in json, the format is old.
@ -5137,12 +5156,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
}
foreach ($comments_array as $comm) {
// Show the comments more recent first.
if (is_array($comm) === true) {
$comm = array_reverse($comm);
}
$comments_format = (empty($comm) === true ? 'old' : 'new');
$comments_format = (empty($comm) === true) ? 'old' : 'new';
switch ($comments_format) {
case 'new':