diff --git a/pandora_console/images/alarm-off.png b/pandora_console/images/alarm-off.png new file mode 100644 index 0000000000..99f3895e0b Binary files /dev/null and b/pandora_console/images/alarm-off.png differ diff --git a/pandora_console/images/gear.png b/pandora_console/images/gear.png new file mode 100644 index 0000000000..e383f94e44 Binary files /dev/null and b/pandora_console/images/gear.png differ diff --git a/pandora_console/images/no-alerts-discovered.png b/pandora_console/images/no-alerts-discovered.png new file mode 100644 index 0000000000..ec9b9a88b1 Binary files /dev/null and b/pandora_console/images/no-alerts-discovered.png differ diff --git a/pandora_console/images/play-white.png b/pandora_console/images/play-white.png new file mode 100644 index 0000000000..2b9b1e93b2 Binary files /dev/null and b/pandora_console/images/play-white.png differ diff --git a/pandora_console/images/silence-alerts.png b/pandora_console/images/silence-alerts.png new file mode 100644 index 0000000000..22b1c95930 Binary files /dev/null and b/pandora_console/images/silence-alerts.png differ diff --git a/pandora_console/images/sound_wave.png b/pandora_console/images/sound_wave.png new file mode 100644 index 0000000000..d04c823de3 Binary files /dev/null and b/pandora_console/images/sound_wave.png differ diff --git a/pandora_console/images/stop.png b/pandora_console/images/stop.png new file mode 100644 index 0000000000..20903a0132 Binary files /dev/null and b/pandora_console/images/stop.png differ diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 77d9647a4b..5a92d33c16 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -55,6 +55,7 @@ if (! check_acl($config['id_user'], 0, 'ER') return; } +$drawConsoleSound = (bool) get_parameter('drawConsoleSound', false); $process_buffers = (bool) get_parameter('process_buffers', false); $get_extended_event = (bool) get_parameter('get_extended_event'); $change_status = (bool) get_parameter('change_status'); @@ -2225,6 +2226,228 @@ if ($process_buffers === true) { return; } +if ($drawConsoleSound === true) { + echo ui_require_css_file('wizard', 'include/styles/', true); + echo ui_require_css_file('discovery', 'include/styles/', true); + echo ui_require_css_file('sound_events', 'include/styles/', true); + $output = '
'; + // Header tabs. + $output .= ''; + + // Content tabs. + $output .= '
'; + $output .= '

'; + $output .= __('Console configuration'); + $output .= '

'; + $inputs = []; + + // Load filter. + $fields = \events_get_event_filter_select(); + $inputs[] = [ + 'label' => \__('Set condition'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'name' => 'filter_id', + 'selected' => 0, + 'return' => true, + 'nothing' => \__('All new events'), + 'nothing_value' => 0, + 'class' => 'fullwidth', + ], + ]; + + $times_interval = [ + 10 => '10 '.__('seconds'), + 15 => '15 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '60 '.__('seconds'), + ]; + + $times_sound = [ + 2 => '2 '.__('seconds'), + 5 => '5 '.__('seconds'), + 10 => '10 '.__('seconds'), + 15 => '15 '.__('seconds'), + 30 => '30 '.__('seconds'), + 60 => '60 '.__('seconds'), + ]; + + $inputs[] = [ + 'class' => 'interval-sounds', + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Interval'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $times_interval, + 'name' => 'interval', + 'selected' => 10, + 'return' => true, + ], + ], + [ + 'label' => __('Time Sound'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $times_sound, + 'name' => 'time_sound', + 'selected' => 10, + 'return' => true, + ], + ], + ], + ]; + + $sounds = [ + 'aircraftalarm.wav' => 'Air craft alarm', + 'air_shock_alarm.wav' => 'Air shock alarm', + 'alien_alarm.wav' => 'Alien alarm', + 'alien_beacon.wav' => 'Alien beacon', + 'bell_school_ringing.wav' => 'Bell school ringing', + 'Door_Alarm.wav' => 'Door alarm', + 'EAS_beep.wav' => 'EAS beep', + 'Firewarner.wav' => 'Fire warner', + 'HardPCMAlarm.wav' => 'Hard PCM Alarm', + 'negativebeep.wav' => 'Negative beep', + 'Star_Trek_emergency_simulation.wav' => 'StarTrek emergency simulation', + ]; + + $inputs[] = [ + 'class' => 'test-sounds', + 'direct' => 1, + 'block_content' => [ + [ + 'label' => \__('Sound melody'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $sounds, + 'name' => 'sound_id', + 'selected' => 'Star_Trek_emergency_simulation.wav', + 'return' => true, + 'class' => 'fullwidth', + ], + ], + [ + 'arguments' => [ + 'type' => 'button', + 'name' => 'melody_sound', + 'label' => __('Test sound'), + 'attributes' => 'class="sub upd"', + 'return' => true, + ], + ], + ], + ]; + + // Print form. + $output .= HTML::printForm( + [ + 'form' => [ + 'action' => '', + 'method' => 'POST', + ], + 'inputs' => $inputs, + ], + true, + false + ); + $output .= '
'; + + $output .= '
'; + $output .= '

'; + $output .= __('Discovered alerts'); + $output .= '

'; + $output .= '
'; + $output .= html_print_image( + 'images/no-alerts-discovered.png', + true, + [ + 'title' => __('No alerts discovered'), + 'class' => 'invert_filter', + ] + ); + $output .= ''; + $output .= __('Congrats! there’s nothing to show'); + $output .= ''; + $output .= '
'; + $output .= '
    '; + $output .= '
    '; + $output .= '
    '; + + $output .= '
    '; + $output .= '
    '; + $output .= '
    '; + $output .= '
    '; + $output .= html_print_input( + [ + 'label' => __('Start'), + 'type' => 'button', + 'name' => 'start-search', + 'attributes' => 'class="sub play"', + 'return' => true, + ], + 'div', + true + ); + $output .= '
    '; + $output .= '
    '; + $output .= html_print_input( + [ + 'type' => 'button', + 'name' => 'no-alerts', + 'label' => __('No alerts'), + 'attributes' => 'class="sub alerts"', + 'return' => true, + ], + 'div', + true + ); + $output .= '
    '; + + $output .= html_print_input( + [ + 'type' => 'hidden', + 'name' => 'mode_alert', + 'value' => 0, + 'return' => true, + ], + 'div', + true + ); + $output .= '
    '; + $output .= '
    '; + + echo $output; + return; +} + if ($get_events_fired) { global $config; $filter_id = (int) get_parameter('filter_id', 0); diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index ab276cda9e..b7f4170afa 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -1,4 +1,4 @@ -/*global jQuery, $, forced_title_callback, confirmDialog*/ +/*global jQuery, $, forced_title_callback, confirmDialog, progressTimeBar*/ // Show the modal window of an event function show_event_dialog(event, dialog_page) { @@ -1028,3 +1028,256 @@ function process_buffers(buffers) { }); } } + +function openSoundEventModal(settings) { + settings = JSON.parse(atob(settings)); + + // Check modal exists and is open. + if ( + $("#modal-sound").hasClass("ui-dialog-content") && + $("#modal-sound").dialog("isOpen") + ) { + return; + } + + // Initialize modal. + $("#modal-sound") + .empty() + .dialog({ + title: settings.title, + resizable: false, + modal: true, + position: { my: "right top", at: "right bottom", of: window }, + overlay: { + opacity: 0.5, + background: "black" + }, + 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); + }); + + // Play Stop. + $("#button-start-search").click(function() { + var mode = $("#hidden-mode_alert").val(); + var action = false; + if (mode == 0) { + action = true; + } + + action_events_sound(action, settings); + }); + + // 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); + + // Background button. + $(".container-button-alert").removeClass("fired"); + + // New progress. + listen_event_sound(settings); + } + }); + }, + error: function(error) { + console.error(error); + } + }); + }, + close: function() { + remove_audio(); + $(this).dialog("destroy"); + } + }) + .show(); +} + +function test_sound_button(test_sound) { + if (test_sound === true) { + add_audio(); + } else { + remove_audio(); + } +} + +function action_events_sound(mode, settings) { + if (mode === true) { + // Enable tabs. + $("#tabs-sound-modal").tabs("option", "disabled", [0]); + // Active tabs. + $("#tabs-sound-modal").tabs("option", "active", 1); + // Change mode. + $("#hidden-mode_alert").val(1); + // Change img button. + $("#button-start-search") + .removeClass("play") + .addClass("stop"); + // Change value button. + $("#button-start-search").val(settings.stop); + // Add Progress bar. + listen_event_sound(settings); + } else { + // Enable tabs. + $("#tabs-sound-modal").tabs("option", "disabled", [1]); + // Active tabs. + $("#tabs-sound-modal").tabs("option", "active", 0); + // Change mode. + $("#hidden-mode_alert").val(0); + // Change img button. + $("#button-start-search") + .removeClass("stop") + .addClass("play"); + // Change value button. + $("#button-start-search").val(settings.start); + // Remove progress bar. + $("#progressbar_time").empty(); + // Remove audio. + remove_audio(); + // Clean events. + $("#tabs-sound-modal .elements-discovered-alerts ul").empty(); + $("#tabs-sound-modal .empty-discovered-alerts").removeClass( + "invisible_important" + ); + // Change img button. + $("#button-no-alerts") + .removeClass("silence-alerts") + .addClass("alerts"); + // Change value button. + $("#button-no-alerts").val(settings.noAlert); + + // Background button. + $(".container-button-alert").removeClass("fired"); + } +} + +function add_audio() { + var sound = "./include/sounds/" + $("#tabs-sound-modal #sound_id").val(); + $(".actions-sound-modal").append( + "