ajax comments
This commit is contained in:
parent
9fa9a346ca
commit
526ebdebd9
|
@ -82,12 +82,65 @@ $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);
|
||||
|
||||
if ($get_comments) {
|
||||
$event = get_parameter('event', false);
|
||||
$filter = get_parameter('filter', false);
|
||||
|
||||
if ($event === false) {
|
||||
return __('Failed to retrieve comments');
|
||||
}
|
||||
|
||||
if ($filter['group_rep'] == 1) {
|
||||
$events = events_get_all(
|
||||
['te.*'],
|
||||
// Filter.
|
||||
$filter,
|
||||
// Offset.
|
||||
null,
|
||||
// Limit.
|
||||
null,
|
||||
// Order.
|
||||
null,
|
||||
// Sort_field.
|
||||
null,
|
||||
// History.
|
||||
$filter['history'],
|
||||
// Return_sql.
|
||||
false,
|
||||
// Having.
|
||||
sprintf(
|
||||
' HAVING max_id_evento = %d',
|
||||
$event['id_evento']
|
||||
)
|
||||
);
|
||||
if ($events !== false) {
|
||||
$event = $events[0];
|
||||
}
|
||||
} else {
|
||||
$events = events_get_event(
|
||||
$event['id_evento'],
|
||||
false,
|
||||
$meta,
|
||||
$history
|
||||
);
|
||||
|
||||
if ($events !== false) {
|
||||
$event = $events[0];
|
||||
}
|
||||
}
|
||||
|
||||
echo events_page_comments($event, true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_event_filters) {
|
||||
$event_filter = events_get_event_filter_select();
|
||||
|
||||
echo io_json_mb_encode($event_filter);
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete event (filtered or not).
|
||||
|
@ -1058,6 +1111,7 @@ if ($get_extended_event) {
|
|||
global $config;
|
||||
|
||||
$event = get_parameter('event', false);
|
||||
$filter = get_parameter('filter', false);
|
||||
|
||||
if ($event === false) {
|
||||
return;
|
||||
|
@ -1253,7 +1307,7 @@ if ($get_extended_event) {
|
|||
|
||||
$general = events_page_general($event);
|
||||
|
||||
$comments = events_page_comments($event);
|
||||
$comments = '<div id="extended_event_comments_page" class="extended_event_pages"></div>';
|
||||
|
||||
$notifications = '<div id="notification_comment_error" style="display:none">'.ui_print_error_message(__('Error adding comment'), '', true).'</div>';
|
||||
$notifications .= '<div id="notification_comment_success" style="display:none">'.ui_print_success_message(__('Comment added successfully'), '', true).'</div>';
|
||||
|
@ -1264,6 +1318,18 @@ if ($get_extended_event) {
|
|||
|
||||
$loading = '<div id="response_loading" style="display:none">'.html_print_image('images/spinner.gif', true).'</div>';
|
||||
|
||||
$i = 0;
|
||||
$tab['general'] = $i++;
|
||||
$tab['details'] = $i++;
|
||||
if (!empty($related)) {
|
||||
$tab['related'] = $i++;
|
||||
}
|
||||
|
||||
$tab['custom_fields'] = $i++;
|
||||
$tab['comments'] = $i++;
|
||||
$tab['responses'] = $i++;
|
||||
$tab['custom_data'] = $i++;
|
||||
|
||||
$out = '<div id="tabs">'.$tabs.$notifications.$loading.$general.$details.$related.$custom_fields.$comments.$responses.$custom_data.html_print_input_hidden('id_event', $event['id_evento']).'</div>';
|
||||
|
||||
$js = '<script>
|
||||
|
@ -1275,31 +1341,31 @@ if ($get_extended_event) {
|
|||
// Load the required tab.
|
||||
switch ($dialog_page) {
|
||||
case 'general':
|
||||
$js .= '$tabs.tabs( "option", "active", 0);';
|
||||
$js .= '$tabs.tabs( "option", "active", '.$tab['general'].');';
|
||||
break;
|
||||
|
||||
case 'details':
|
||||
$js .= '$tabs.tabs( "option", "active", 1);';
|
||||
$js .= '$tabs.tabs( "option", "active", '.$tab['details'].');';
|
||||
break;
|
||||
|
||||
case 'related':
|
||||
$js .= '$tabs.tabs( "option", "active", 2);';
|
||||
$js .= '$tabs.tabs( "option", "active", '.$tab['related'].');';
|
||||
break;
|
||||
|
||||
case 'custom_fields':
|
||||
$js .= '$tabs.tabs( "option", "active", 3);';
|
||||
$js .= '$tabs.tabs( "option", "active", '.$tab['custom_fields'].');';
|
||||
break;
|
||||
|
||||
case 'comments':
|
||||
$js .= '$tabs.tabs( "option", "active", 4);';
|
||||
$js .= '$tabs.tabs( "option", "active", '.$tab['comments'].');';
|
||||
break;
|
||||
|
||||
case 'responses':
|
||||
$js .= '$tabs.tabs( "option", "active", 5);';
|
||||
$js .= '$tabs.tabs( "option", "active", '.$tab['responses'].');';
|
||||
break;
|
||||
|
||||
case 'custom_data':
|
||||
$js .= '$tabs.tabs( "option", "active", 6);';
|
||||
$js .= '$tabs.tabs( "option", "active", '.$tab['custom_data'].');';
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1309,6 +1375,24 @@ if ($get_extended_event) {
|
|||
|
||||
$js .= '});';
|
||||
|
||||
$js .= '
|
||||
$("#link_comments").click(function (){
|
||||
$.post ({
|
||||
url : "ajax.php",
|
||||
data : {
|
||||
page: "include/ajax/events",
|
||||
get_comments: 1,
|
||||
event: '.json_encode($event).',
|
||||
filter: '.json_encode($filter).'
|
||||
},
|
||||
dataType : "html",
|
||||
success: function (data) {
|
||||
$("#extended_event_comments_page").empty();
|
||||
$("#extended_event_comments_page").html(data);
|
||||
}
|
||||
});
|
||||
});';
|
||||
|
||||
if (events_has_extended_info($event['id_evento']) === true) {
|
||||
$js .= '
|
||||
$("#link_related").click(function (){
|
||||
|
|
|
@ -4531,7 +4531,7 @@ function events_page_general($event)
|
|||
*
|
||||
* @return string HTML.
|
||||
*/
|
||||
function events_page_comments($event)
|
||||
function events_page_comments($event, $ajax=false)
|
||||
{
|
||||
// Comments.
|
||||
global $config;
|
||||
|
@ -4540,7 +4540,7 @@ function events_page_comments($event)
|
|||
|
||||
$comments = $event['user_comment'];
|
||||
if (isset($event['comments'])) {
|
||||
$comments = $event['comments'];
|
||||
$comments = explode('<br>', $event['comments']);
|
||||
}
|
||||
|
||||
$table_comments = new stdClass;
|
||||
|
@ -4551,100 +4551,102 @@ function events_page_comments($event)
|
|||
|
||||
$comments = str_replace(["\n", '
'], '<br>', $comments);
|
||||
|
||||
// If comments are not stored in json, the format is old.
|
||||
$comments_array = json_decode(io_safe_output($comments), true);
|
||||
if (!empty($comments) && json_last_error() != JSON_ERROR_NONE) {
|
||||
$comments_array = [
|
||||
[
|
||||
'comment' => 'Error retrieving comments',
|
||||
'action' => 'Internal message',
|
||||
'id_user' => 'SYSTEM',
|
||||
'utimestamp' => time(),
|
||||
],
|
||||
];
|
||||
}
|
||||
if (is_array($comments)) {
|
||||
foreach ($comments as $comm) {
|
||||
if (empty($comm)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Show the comments more recent first.
|
||||
if (is_array($comments_array)) {
|
||||
$comments_array = array_reverse($comments_array);
|
||||
}
|
||||
|
||||
if (empty($comments_array)) {
|
||||
$comments_format = 'old';
|
||||
$comments_array[] = json_decode(io_safe_output($comm), true);
|
||||
}
|
||||
} else {
|
||||
$comments_format = 'new';
|
||||
// If comments are not stored in json, the format is old.
|
||||
$comments_array = json_decode(io_safe_output($comments), true);
|
||||
}
|
||||
|
||||
switch ($comments_format) {
|
||||
case 'new':
|
||||
if (empty($comments_array)) {
|
||||
$table_comments->style[0] = 'text-align:center;';
|
||||
$table_comments->colspan[0][0] = 2;
|
||||
$data = [];
|
||||
$data[0] = __('There are no comments');
|
||||
$table_comments->data[] = $data;
|
||||
}
|
||||
foreach ($comments_array as $comm) {
|
||||
// Show the comments more recent first.
|
||||
if (is_array($comm)) {
|
||||
$comm = array_reverse($comm);
|
||||
}
|
||||
|
||||
if (isset($comments_array) === true
|
||||
&& is_array($comments_array) === true
|
||||
) {
|
||||
foreach ($comments_array as $c) {
|
||||
$data[0] = '<b>'.$c['action'].' by '.$c['id_user'].'</b>';
|
||||
$data[0] .= '<br><br><i>'.date($config['date_format'], $c['utimestamp']).'</i>';
|
||||
$data[1] = $c['comment'];
|
||||
$table_comments->data[] = $data;
|
||||
}
|
||||
}
|
||||
break;
|
||||
if (empty($comm)) {
|
||||
$comments_format = 'old';
|
||||
} else {
|
||||
$comments_format = 'new';
|
||||
}
|
||||
|
||||
case 'old':
|
||||
$comments_array = explode('<br>', $comments);
|
||||
|
||||
// Split comments and put in table.
|
||||
$col = 0;
|
||||
$data = [];
|
||||
|
||||
foreach ($comments_array as $c) {
|
||||
switch ($col) {
|
||||
case 0:
|
||||
$row_text = preg_replace('/\s*--\s*/', '', $c);
|
||||
$row_text = preg_replace('/\<\/b\>/', '</i>', $row_text);
|
||||
$row_text = preg_replace('/\[/', '</b><br><br><i>[', $row_text);
|
||||
$row_text = preg_replace('/[\[|\]]/', '', $row_text);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$row_text = preg_replace("/[\r\n|\r|\n]/", '<br>', io_safe_output(strip_tags($c)));
|
||||
break;
|
||||
|
||||
default:
|
||||
// Ignore.
|
||||
break;
|
||||
}
|
||||
|
||||
$data[$col] = $row_text;
|
||||
|
||||
$col++;
|
||||
|
||||
if ($col == 2) {
|
||||
$col = 0;
|
||||
$table_comments->data[] = $data;
|
||||
switch ($comments_format) {
|
||||
case 'new':
|
||||
if (empty($comm)) {
|
||||
$table_comments->style[0] = 'text-align:center;';
|
||||
$table_comments->colspan[0][0] = 2;
|
||||
$data = [];
|
||||
$data[0] = __('There are no comments');
|
||||
$table_comments->data[] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($comments_array) == 1 && $comments_array[0] == '') {
|
||||
$table_comments->style[0] = 'text-align:center;';
|
||||
$table_comments->colspan[0][0] = 2;
|
||||
if (isset($comm) === true
|
||||
&& is_array($comm) === true
|
||||
) {
|
||||
foreach ($comm as $c) {
|
||||
$data[0] = '<b>'.$c['action'].' by '.$c['id_user'].'</b>';
|
||||
$data[0] .= '<br><br><i>'.date($config['date_format'], $c['utimestamp']).'</i>';
|
||||
$data[1] = $c['comment'];
|
||||
$table_comments->data[] = $data;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'old':
|
||||
$comm = explode('<br>', $comments);
|
||||
|
||||
// Split comments and put in table.
|
||||
$col = 0;
|
||||
$data = [];
|
||||
$data[0] = __('There are no comments');
|
||||
$table_comments->data[] = $data;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Ignore.
|
||||
break;
|
||||
foreach ($comm as $c) {
|
||||
switch ($col) {
|
||||
case 0:
|
||||
$row_text = preg_replace('/\s*--\s*/', '', $c);
|
||||
$row_text = preg_replace('/\<\/b\>/', '</i>', $row_text);
|
||||
$row_text = preg_replace('/\[/', '</b><br><br><i>[', $row_text);
|
||||
$row_text = preg_replace('/[\[|\]]/', '', $row_text);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$row_text = preg_replace("/[\r\n|\r|\n]/", '<br>', io_safe_output(strip_tags($c)));
|
||||
break;
|
||||
|
||||
default:
|
||||
// Ignore.
|
||||
break;
|
||||
}
|
||||
|
||||
$data[$col] = $row_text;
|
||||
|
||||
$col++;
|
||||
|
||||
if ($col == 2) {
|
||||
$col = 0;
|
||||
$table_comments->data[] = $data;
|
||||
$data = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($comm) == 1 && $comm[0] == '') {
|
||||
$table_comments->style[0] = 'text-align:center;';
|
||||
$table_comments->colspan[0][0] = 2;
|
||||
$data = [];
|
||||
$data[0] = __('There are no comments');
|
||||
$table_comments->data[] = $data;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Ignore.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (((tags_checks_event_acl(
|
||||
|
@ -4687,9 +4689,11 @@ function events_page_comments($event)
|
|||
);
|
||||
}
|
||||
|
||||
$comments = '<div id="extended_event_comments_page" class="extended_event_pages">'.$comments_form.html_print_table($table_comments, true).'</div>';
|
||||
if ($ajax) {
|
||||
return $comments_form.html_print_table($table_comments, true);
|
||||
}
|
||||
|
||||
return $comments;
|
||||
return '<div id="extended_event_comments_page" class="extended_event_pages">'.$comments_form.html_print_table($table_comments, true).'</div>';
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -557,9 +557,8 @@ function event_comment() {
|
|||
dataType: "html",
|
||||
success: function(data) {
|
||||
$("#button-comment_button").removeAttr("disabled");
|
||||
$("#response_loading").show();
|
||||
dt_events.draw(false);
|
||||
show_event_dialog(current_event, "comments", data);
|
||||
$("#response_loading").hide();
|
||||
$("#link_comments").click();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -237,7 +237,8 @@ if (is_ajax()) {
|
|||
'tg.nombre as group_name',
|
||||
];
|
||||
if (!is_metaconsole()) {
|
||||
$fields[] = 'am.nombre as id_agentmodule';
|
||||
$fields[] = 'am.nombre as module_name';
|
||||
$fields[] = 'am.id_agente_modulo as id_agentmodule';
|
||||
$fields[] = 'ta.server_name as server_name';
|
||||
} else {
|
||||
$fields[] = 'ts.server_name as server_name';
|
||||
|
@ -274,6 +275,11 @@ if (is_ajax()) {
|
|||
function ($carry, $item) {
|
||||
$tmp = (object) $item;
|
||||
$tmp->evento = io_safe_output($tmp->evento);
|
||||
if ($tmp->module_name) {
|
||||
$tmp->module_name = io_safe_output($tmp->module_name);
|
||||
}
|
||||
|
||||
$tmp->agent_name = io_safe_output($tmp->agent_name);
|
||||
$tmp->ack_utimestamp = ui_print_timestamp(
|
||||
$tmp->ack_utimestamp,
|
||||
true
|
||||
|
@ -1809,6 +1815,8 @@ function process_datatables_item(item) {
|
|||
item.id_grupo = item.group_name;
|
||||
}
|
||||
|
||||
/* Module name */
|
||||
item.id_agentmodule = item.module_name;
|
||||
}
|
||||
|
||||
/* Datatables auxiliary functions ends */
|
||||
|
|
Loading…
Reference in New Issue