From 37675e0fce32d785688bc34801ecfcc3918879ad Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Thu, 16 Dec 2021 16:35:31 +0100 Subject: [PATCH] Added php8 function and solve issue with agent id sorting in events --- pandora_console/include/functions.php | 21 ++++++ pandora_console/operation/events/events.php | 72 ++++++++++++--------- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 9b617af6aa..dc7294393e 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -5966,3 +5966,24 @@ function send_test_email( return $result; } + + +if (function_exists('str_contains') === false) { + + + /** + * Checks if $needle is found in $haystack and returns a boolean value. + * For lower than PHP8 versions. + * + * @param string $haystack The string who can have the needle. + * @param string $needle The needle. + * + * @return boolean True if haystack contains the needle. + */ + function str_contains(string $haystack, string $needle) + { + return $needle !== '' && mb_strpos($haystack, $needle) !== false; + } + + +} diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 5c06f4806e..70c44428ed 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -261,11 +261,6 @@ if (is_ajax() === true) { if ($get_events) { try { ob_start(); - $order = get_datatable_order(true); - - if (is_array($order) === true && $order['field'] === 'mini_severity') { - $order['field'] = 'te.criticity'; - } $fields = [ 'te.id_evento', @@ -296,6 +291,20 @@ if (is_ajax() === true) { 'ta.direccion', ]; + $order = get_datatable_order(true); + + if (is_array($order) === true && $order['field'] === 'mini_severity') { + $order['field'] = 'te.criticity'; + } + + // Find the order field and set the table and field name. + foreach ($fields as $field) { + if (str_contains($field, $order['field']) === true) { + $order['field'] = $field; + break; + } + } + if (is_metaconsole() === false) { $fields[] = 'am.nombre as module_name'; $fields[] = 'am.id_agente_modulo as id_agentmodule'; @@ -345,7 +354,8 @@ if (is_ajax() === true) { $tmp = (object) $item; $tmp->meta = is_metaconsole(); - if (is_metaconsole()) { + // phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + if ($tmp->meta === true) { if ($tmp->server_name !== null) { $tmp->data_server = metaconsole_get_servers($tmp->server_id); $tmp->server_url_hash = metaconsole_get_servers_url_hash($tmp->data_server); @@ -371,7 +381,7 @@ if (is_ajax() === true) { sprintf( 'SELECT criticity, timestamp FROM %s WHERE id_evento = %s', - ($tmp->meta) ? 'tmetaconsole_event' : 'tevento', + ($tmp->meta === true) ? 'tmetaconsole_event' : 'tevento', $tmp->max_id_evento ) ); @@ -538,7 +548,7 @@ if (is_array($tag_without) === false) { } -foreach ($tags as $id_tag => $tag) { +foreach ((array) $tags as $id_tag => $tag) { if (is_array($tag_with) === true && ((array_search($id_tag, $tag_with) === false) || (array_search($id_tag, $tag_with) === null)) ) { @@ -2197,7 +2207,7 @@ function process_datatables_item(item) { // Url to agent view. var url_link = ''; var url_link_hash = ''; - if(item.meta === true){ + if(item.meta === true){ url_link = server_url+'/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='; url_link_hash = hashdata; } @@ -2327,7 +2337,7 @@ function click_button_add_tag(what_button) { id_button_remove = "#button-remove_without"; id_button_add = "#button-add_without"; } - + $(id_select_origin + " option:selected").each(function() { if (what_button == 'with') { select_destiny_empty = select_with_tag_empty; @@ -2335,17 +2345,17 @@ function click_button_add_tag(what_button) { else { //without select_destiny_empty = select_without_tag_empty; } - - + + without_val = $(this).val(); if(without_val == null) { next; } without_text = $(this).text(); - + if (select_destiny_empty) { $(id_select_destiny).empty(); - + if (what_button == 'with') { select_with_tag_empty = false; } @@ -2353,15 +2363,15 @@ function click_button_add_tag(what_button) { select_without_tag_empty = false; } } - + $(id_select_destiny).append($("")); $(id_select_origin + " option:selected").remove(); $(id_button_remove).removeAttr('disabled'); - + if ($(id_select_origin + " option").length == 0) { $(id_select_origin).append($("")); $(id_button_add).attr('disabled', 'true'); - + if (what_button == 'with') { origin_select_with_tag_empty = true; } @@ -2369,10 +2379,10 @@ function click_button_add_tag(what_button) { origin_select_without_tag_empty = true; } } - + replace_hidden_tags(what_button); }); - + } function replace_hidden_tags(what_button) { @@ -2384,15 +2394,15 @@ function replace_hidden_tags(what_button) { id_select_destiny = "#tag_without_temp"; id_hidden = "#hidden-tag_without"; } - + value_store = []; - + jQuery.each($(id_select_destiny + " option"), function(key, element) { val = $(element).val(); - + value_store.push(val); }); - + $(id_hidden).val(Base64.encode(JSON.stringify(value_store))); } @@ -2407,28 +2417,26 @@ function reorder_tags_inputs() { jQuery.each($("#tag_with_temp option"), function(key, element) { val = $(element).val(); text = $(element).text(); - + if (val == val_none) return; - + $("#select_with").append($("")); }); $("#tag_with_temp option").remove(); - - + $('#select_without option[value="' + val_none + '"]').remove(); jQuery.each($("#tag_without_temp option"), function(key, element) { val = $(element).val(); text = $(element).text(); - + if (val == val_none) return; - + $("#select_without").append($("")); }); $("#tag_without_temp option").remove(); - - + tags_base64 = $("#hidden-tag_with").val(); if (tags_base64.length > 0) { tags = jQuery.parseJSON(Base64.decode(tags_base64)); @@ -2461,7 +2469,7 @@ function reorder_tags_inputs() { select_with_tag_empty = false; $("#button-remove_with").removeAttr('disabled'); } - + tags_base64 = $("#hidden-tag_without").val(); if (tags_base64.length > 0) { tags = jQuery.parseJSON(Base64.decode(tags_base64));