diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php
index 11811eda38..c3678ab90f 100644
--- a/pandora_console/include/ajax/events.php
+++ b/pandora_console/include/ajax/events.php
@@ -83,10 +83,10 @@ $in_process_event = get_parameter('in_process_event', 0);
$validate_event = get_parameter('validate_event', 0);
$delete_event = get_parameter('delete_event', 0);
$get_event_filters = get_parameter('get_event_filters', 0);
-$get_comments = get_parameter('get_comments', 0);
+$get_comments = (bool) get_parameter('get_comments', false);
$get_events_fired = (bool) get_parameter('get_events_fired');
$get_id_source_event = get_parameter('get_id_source_event');
-if ($get_comments) {
+if ($get_comments === true) {
$event = get_parameter('event', false);
$filter = get_parameter('filter', false);
@@ -94,6 +94,8 @@ if ($get_comments) {
return __('Failed to retrieve comments');
}
+ $eventsGrouped = [];
+
if ($filter['group_rep'] == 1) {
$events = events_get_all(
['te.*'],
@@ -119,23 +121,39 @@ if ($get_comments) {
// True for show comments of validated events.
true
);
+
if ($events !== false) {
$event = $events[0];
}
} else {
- $events = events_get_event(
- $event['id_evento'],
- false,
- $meta,
- $history
- );
+ // Consider if the event is grouped.
+ if (isset($event['event_rep']) === true && $event['event_rep'] > 0) {
+ $eventsGrouped = db_get_all_rows_sql(
+ sprintf(
+ 'SELECT `user_comment`
+ FROM `tevento`
+ WHERE `id_agente` = "%d" AND `data` = "%d" AND `estado` = "%d"',
+ $event['id_agente'],
+ $event['data'],
+ $event['estado']
+ )
+ );
+ } else {
+ $events = events_get_event(
+ $event['id_evento'],
+ false,
+ $meta,
+ $history
+ );
- if ($events !== false) {
- $event = $events;
+ if ($events !== false) {
+ $event = $events;
+ }
}
}
- echo events_page_comments($event, true);
+ // End of get_comments.
+ echo events_page_comments($event, true, $eventsGrouped);
return;
}
diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php
index 5e727cf08c..21ca42d1c9 100644
--- a/pandora_console/include/functions_events.php
+++ b/pandora_console/include/functions_events.php
@@ -1619,14 +1619,14 @@ function events_get_events($filter=false, $fields=false)
*/
function events_get_event($id, $fields=false, $meta=false, $history=false)
{
- if (empty($id)) {
+ if (empty($id) === true) {
return false;
}
global $config;
- if (is_array($fields)) {
- if (! in_array('id_grupo', $fields)) {
+ if (is_array($fields) === true) {
+ if (in_array('id_grupo', $fields) === false) {
$fields[] = 'id_grupo';
}
}
@@ -1634,7 +1634,7 @@ function events_get_event($id, $fields=false, $meta=false, $history=false)
$table = events_get_events_table($meta, $history);
$event = db_get_row($table, 'id_evento', $id, $fields);
- if (! check_acl($config['id_user'], $event['id_grupo'], 'ER')) {
+ if ((bool) check_acl($config['id_user'], $event['id_grupo'], 'ER') === false) {
return false;
}
@@ -2255,7 +2255,7 @@ function events_comment(
// If comments are not stored in json, the format is old.
$event_comments_array = json_decode($event_comments[0]['user_comment']);
- if (empty($event_comments_array)) {
+ if (empty($event_comments_array) === true) {
$comments_format = 'old';
} else {
$comments_format = 'new';
@@ -2268,6 +2268,7 @@ function events_comment(
$comment_for_json['action'] = $action;
$comment_for_json['id_user'] = $config['id_user'];
$comment_for_json['utimestamp'] = time();
+ $comment_for_json['event_id'] = $first_event;
$event_comments_array[] = $comment_for_json;
@@ -2282,11 +2283,11 @@ function events_comment(
break;
case 'old':
- // Give old ugly format to comment. TODO: Change this method for
- // aux table or json.
+ // Give old ugly format to comment.
+ // Change this method for aux table or json.
$comment = str_replace(["\r\n", "\r", "\n"], '
', $comment);
- if ($comment != '') {
+ if ($comment !== '') {
$commentbox = '
'.stripslashes(str_replace(['\n', '\r'], '
', $c['comment'])).'