diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 9b79f1f7c2..571955fd25 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -90,6 +90,8 @@ $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'); $node_id = (int) get_parameter('node_id', 0); +$settings_modal = get_parameter('settings', 0); +$parameters_modal = get_parameter('parameters', 0); if ($get_comments === true) { global $config; @@ -512,8 +514,13 @@ if ($load_filter_modal) { false ); + $action = 'index.php?sec=eventos&sec2=operation/events/events&pure='; + if ($settings_modal !== 0 && $parameters_modal !== 0) { + $action .= '&settings='.$settings_modal.'¶meters='.$parameters_modal; + } + echo '
'; - echo '
'; + echo ''; $table = new StdClass; $table->id = 'load_filter_form'; @@ -953,7 +960,7 @@ function save_new_filter() { } else { id_filter_save = data; - + $("#info_box").filter(function(i, item) { if ($(item).data('type_info_box') == "success_create_filter") { return true; @@ -2459,7 +2466,7 @@ if ($drawConsoleSound === true) { 'label' => __('Start'), 'type' => 'button', 'name' => 'start-search', - 'attributes' => [ 'class' => 'play' ], + 'attributes' => [ 'class' => 'play secondary' ], 'return' => true, ], 'div', @@ -2585,23 +2592,24 @@ if ($get_events_fired) { $return[] = array_merge( $event, [ - 'fired' => $event['id_evento'], - 'message' => ui_print_string_substr( + 'fired' => $event['id_evento'], + 'message' => ui_print_string_substr( strip_tags(io_safe_output($event['evento'])), 75, true, '9' ), - 'priority' => ui_print_event_priority($event['criticity'], true, true), - 'type' => events_print_type_img( + 'priority' => ui_print_event_priority($event['criticity'], true, true), + 'type' => events_print_type_img( $event['event_type'], true ), - 'timestamp' => ui_print_timestamp( + 'timestamp' => ui_print_timestamp( $event['timestamp'], true, ['style' => 'font-size: 9pt; letter-spacing: 0.3pt;'] ), + 'event_timestamp' => $event['timestamp'], ] ); } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 4862705545..1b232ca1ca 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3621,6 +3621,7 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $ $classes = ''; $fixedId = ''; $iconStyle = ''; + $minimize_arrow = false; // $spanStyle = 'margin-top: 4px;'; $spanStyle = ''; if (empty($name) === true) { @@ -3658,6 +3659,8 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $ $buttonType = ($attr_array['type'] ?? 'button'); $buttonAttributes = $value; break; + } else if ($attribute === 'minimize-arrow') { + $minimize_arrow = true; } else { $attributes .= $attribute.'="'.$value.'" '; } @@ -3682,15 +3685,30 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $ $iconDiv = ''; } + if ($minimize_arrow === true) { + $minimezeDiv = html_print_div( + [ + 'id' => 'minimize_arrow_event_sound', + 'style' => 'background-color:transparent; right: 1em; margin-left:0.5em; position:relative; display:none;', + 'class' => 'arrow_menu_down w30p', + ], + true + ); + } else { + $minimezeDiv = ''; + } + // Defined id. Is usable for span and button. // TODO. Check if will be proper use button or submit when where appropiate. $mainId = ((empty($fixedId) === false) ? $fixedId : 'button-'.$name); if ($imageButton === false) { - $content = ''.$label.''; + $content = $minimezeDiv; + $content .= ''.$label.''; $content .= $iconDiv; } else { - $content = $iconDiv; + $content = $minimezeDiv; + $content .= $iconDiv; } // In case of not selected button type, in this case, will be normal button. diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 286c6d5ac4..6c31136c34 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -55,7 +55,7 @@ function show_event_dialog(event, dialog_page) { title: event.evento, resizable: true, draggable: true, - modal: true, + modal: false, minWidth: 875, minHeight: 600, close: function() { @@ -943,6 +943,185 @@ function process_buffers(buffers) { } } +function openSoundEventsDialogModal(settings, dialog_parameters, reload) { + let mode = $("#hidden-mode_alert").val(); + if (reload != false) { + if (mode == 0) { + let filter_id = $("#filter_id option:selected").val(); + let interval = $("#interval option:selected").val(); + let time_sound = $("#time_sound option:selected").val(); + let sound_id = $("#sound_id option:selected").val(); + let parameters = { + filter_id: filter_id, + interval: interval, + time_sound: time_sound, + sound_id: sound_id, + mode: mode + }; + parameters = JSON.stringify(parameters); + parameters = btoa(parameters); + let url = + window.location + "&settings=" + settings + "¶meters=" + parameters; + $(location).attr("href", url); + } else { + let url = window.location + "&settings=" + settings; + $(location).attr("href", url); + } + } else { + openSoundEventsDialog(settings, dialog_parameters, reload); + } +} + +function openSoundEventsDialog(settings, dialog_parameters, reload) { + let encode_settings = settings; + if (reload == undefined) { + reload = true; + } + if (dialog_parameters != undefined) { + dialog_parameters = JSON.parse(atob(dialog_parameters)); + } + settings = JSON.parse(atob(settings)); + // Check modal exists and is open. + if ( + $("#modal-sound").hasClass("ui-dialog-content") && + $("#modal-sound").dialog("isOpen") + ) { + $(".ui-dialog-titlebar-minimize").trigger("click"); + return; + } + //Modify button + $("#minimize_arrow_event_sound").removeClass("arrow_menu_up"); + $("#minimize_arrow_event_sound").addClass("arrow_menu_down"); + $("#minimize_arrow_event_sound").show(); + + // Initialize modal. + $("#modal-sound") + .empty() + .dialog({ + title: settings.title, + resizable: false, + modal: false, + width: 600, + height: 600, + open: function() { + $.ajax({ + method: "post", + url: settings.url, + data: { + page: settings.page, + drawConsoleSound: 1 + }, + dataType: "html", + success: function(data) { + $("#modal-sound").append(data); + $("#tabs-sound-modal").tabs({ + disabled: [1] + }); + + // Test sound. + $("#button-melody_sound").click(function() { + var sound = false; + if ($("#id_sound_event").length == 0) { + sound = true; + } + + test_sound_button(sound, settings.urlSound); + }); + + // Play Stop. + $("#button-start-search").click(function() { + if (reload == true) { + openSoundEventsDialogModal(encode_settings, 0, reload); + } + var mode = $("#hidden-mode_alert").val(); + var action = false; + if (mode == 0) { + action = true; + } + if ($("#button-start-search").hasClass("play")) { + $("#modal-sound").css({ + height: "500px" + }); + $("#modal-sound") + .parent() + .css({ + height: "550px" + }); + } else { + $("#modal-sound").css({ + height: "450px" + }); + $("#modal-sound") + .parent() + .css({ + height: "500px" + }); + } + + action_events_sound(action, settings); + }); + + if (reload == false && dialog_parameters != undefined) { + if ($("#button-start-search").hasClass("play")) { + $("#filter_id").val(dialog_parameters["filter_id"]); + $("#interval").val(dialog_parameters["interval"]); + $("#time_sound").val(dialog_parameters["time_sound"]); + $("#sound_id").val(dialog_parameters["sound_id"]); + + $("#filter_id").trigger("change"); + $("#interval").trigger("change"); + $("#time_sound").trigger("change"); + $("#sound_id").trigger("change"); + + $("#button-start-search").trigger("click"); + } + } + + // Silence Alert. + $("#button-no-alerts").click(function() { + if ($("#button-no-alerts").hasClass("silence-alerts") === true) { + // Remove audio. + remove_audio(); + + // Clean events. + $("#tabs-sound-modal .elements-discovered-alerts ul").empty(); + $("#tabs-sound-modal .empty-discovered-alerts").removeClass( + "invisible_important" + ); + + // Clean progress. + $("#progressbar_time").empty(); + + // Change img button. + $("#button-no-alerts") + .removeClass("silence-alerts") + .addClass("alerts"); + // Change value button. + $("#button-no-alerts").val(settings.noAlert); + $("#button-no-alerts > span").text(settings.noAlert); + + // Background button. + $(".container-button-alert").removeClass("fired"); + + // New progress. + listen_event_sound(settings); + } + }); + }, + error: function(error) { + console.error(error); + } + }); + }, + close: function() { + $("#minimize_arrow_event_sound").hide(); + remove_audio(); + $(this).dialog("destroy"); + } + }) + .show(); +} + function openSoundEventModal(settings) { if ($("#hidden-metaconsole_activated").val() === "1") { var win = open( @@ -966,6 +1145,7 @@ function openSoundEventModal(settings) { } settings = JSON.parse(atob(settings)); + // Check modal exists and is open. if ( $("#modal-sound").hasClass("ui-dialog-content") && @@ -1045,10 +1225,12 @@ function add_audio(urlSound) { sound + "' autoplay='true' hidden='true' loop='false'>" ); + $("#button-sound_events_button").addClass("animation-blink"); } function remove_audio() { $(".actions-sound-modal audio").remove(); + $("#button-sound_events_button").removeClass("animation-blink"); } function listen_event_sound(settings) { @@ -1064,6 +1246,37 @@ function listen_event_sound(settings) { } function check_event_sound(settings) { + // Update elements time. + $(".elements-discovered-alerts ul li").each(function() { + let element_time = $(this) + .children(".li-hidden") + .val(); + let obj_time = new Date(element_time); + let current_dt = new Date(); + let timestamp = current_dt.getTime() - obj_time.getTime(); + timestamp = timestamp / 1000; + if (timestamp <= 60) { + timestamp = Math.round(timestamp) + " seconds"; + } else if (timestamp <= 3600) { + let minute = Math.floor((timestamp / 60) % 60); + minute = minute < 10 ? "0" + minute : minute; + let second = Math.floor(timestamp % 60); + second = second < 10 ? "0" + second : second; + timestamp = minute + " minutes " + second + " seconds"; + } else { + let hour = Math.floor(timestamp / 3600); + hour = hour < 10 ? "0" + hour : hour; + let minute = Math.floor((timestamp / 60) % 60); + minute = minute < 10 ? "0" + minute : minute; + let second = Math.round(timestamp % 60); + second = second < 10 ? "0" + second : second; + timestamp = hour + " hours " + minute + " minutes " + second + " seconds"; + } + $(this) + .children(".li-time") + .children("span") + .html(timestamp); + }); jQuery.post( settings.url, { @@ -1117,7 +1330,13 @@ function check_event_sound(settings) { "beforeend", '
' + element.timestamp + "
" ); - $("#tabs-sound-modal .elements-discovered-alerts ul").append(li); + li.insertAdjacentHTML( + "beforeend", + '' + ); + $("#tabs-sound-modal .elements-discovered-alerts ul").prepend(li); }); // -100 delay sound. @@ -1248,3 +1467,266 @@ function get_table_events_tabs(event, filter) { } }); } +// Define the minimize button functionality; +function hidden_dialog(dialog) { + setTimeout(function() { + $("#modal-sound").css("visibility", "hidden"); + dialog.css("z-index", "-1"); + }, 200); +} + +function show_dialog(dialog) { + setTimeout(function() { + $("#modal-sound").css("visibility", "visible"); + dialog.css("z-index", "1115"); + }, 50); +} + +/* +############################################################################# +## +## + Compacts the Modal Sound Dialog to a tiny toolbar +## + Dynamically adds a button which can reduce/reapply the dialog size +## + If alarm gets raised & minimized, the dialog window maximizes and the toolbar flashes red for 10 seconds. +## - Works fine until a link/action gets clicked. The Toolbar shifts to the bottom of the Modal-Sound Dialog. +## +############################################################################# +*/ + +$(document).ajaxSend(function(event, jqXHR, ajaxOptions) { + const requestBody = ajaxOptions.data; + try { + if (requestBody && requestBody.includes("drawConsoleSound=1")) { + console.log( + "AJAX request sent with drawConsoleSound=1:", + ajaxOptions.url + ); + + // Find the dialog element by the aria-describedby attribute + var dialog = $('[aria-describedby="modal-sound"]'); + + // Select the close button within the dialog + var closeButton = dialog.find(".ui-dialog-titlebar-close"); + + // Add the minimize button before the close button + var minimizeButton = $("