diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 6129fcebb4..ba6922e03c 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -539,6 +539,33 @@ echo sprintf('
', $menuTypeClass); element.style.display = "none" } + function notifications_clean_all() { + let wrapper_inner = document.getElementById('notification-wrapper-inner'); + while (wrapper_inner.firstChild) { + wrapper_inner.removeChild(wrapper_inner.firstChild); + } + } + + function mark_all_notification_as_read() { + jQuery.post ("ajax.php", + { + "page" : "godmode/setup/setup_notifications", + "mark_all_notification_as_read" : 1 + }, + function (data, status) { + notifications_clean_all(); + location.reload(); + }, + "json" + ) + .fail(function(xhr, textStatus, errorThrown){ + console.error( + "Failed to mark al notification as read. Error: ", + xhr.responseText + ); + }); + } + function click_on_notification_toast(event) { var match = /notification-(.*)-id-([0-9]+)/.exec(event.target.id); if (!match) { diff --git a/pandora_console/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index 6aaaabf032..f2289a7cc3 100644 --- a/pandora_console/godmode/setup/setup_notifications.php +++ b/pandora_console/godmode/setup/setup_notifications.php @@ -187,6 +187,27 @@ if (get_parameter('mark_notification_as_read', 0)) { return; } +if (get_parameter('mark_all_notification_as_read', 0)) { + $unread_messages = db_get_all_rows_sql('SELECT id_mensaje FROM tnotification_user WHERE utimestamp_read is NULL'); + + if ($unread_messages !== false) { + foreach ($unread_messages as $messages) { + messages_process_read($messages['id_mensaje']); + } + + $result = true; + } else { + $result = false; + } + + // If there is new messages, get the info. + echo json_encode( + ['result' => $result] + ); + + return; +} + if (get_parameter('get_notifications_dropdown', 0)) { echo notifications_print_dropdown(); return; diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 7ef169aec1..99299a21ac 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -169,6 +169,7 @@ class ConsoleSupervisor * NOTIF.PHP.DISABLE_FUNCTIONS * NOTIF.PHP.CHROMIUM * NOTIF.PHP.VERSION + * NOTIF.PHP.VERSION.SUPPORT */ $this->checkPHPSettings(); @@ -377,6 +378,7 @@ class ConsoleSupervisor * NOTIF.PHP.DISABLE_FUNCTIONS * NOTIF.PHP.CHROMIUM * NOTIF.PHP.VERSION + * NOTIF.PHP.VERSION.SUPPORT */ $this->checkPHPSettings(); @@ -853,6 +855,7 @@ class ConsoleSupervisor case 'NOTIF.PHP.DISABLE_FUNCTIONS': case 'NOTIF.PHP.CHROMIUM': case 'NOTIF.PHP.VERSION': + case 'NOTIF.PHP.VERSION.SUPPORT': case 'NOTIF.HISTORYDB': case 'NOTIF.PANDORADB': case 'NOTIF.PANDORADB.HISTORICAL': @@ -1807,14 +1810,14 @@ class ConsoleSupervisor $url = 'https://www.php.net/supported-versions.php'; $this->notify( [ - 'type' => 'NOTIF.PHP.VERSION', + 'type' => 'NOTIF.PHP.VERSION.SUPPORT', 'title' => __('PHP UPDATE REQUIRED'), 'message' => __('You should update your PHP version because it will be out of official support').'
'.__('Current PHP version: ').PHP_VERSION, 'url' => $url, ] ); } else { - $this->cleanNotifications('NOTIF.PHP.VERSION'); + $this->cleanNotifications('NOTIF.PHP.VERSION.SUPPORT'); } } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 076a81e7f3..652e878e82 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2849,6 +2849,8 @@ function html_print_anchor( $output .= '>'; + $output .= (isset($options['text']) === true) ? $options['text'] : ''; + $output .= (isset($options['content']) === true) ? io_safe_input_html($options['content']) : ''; $output .= ''; @@ -6882,6 +6884,7 @@ function html_print_menu_button(array $options, bool $return=false) 'class' => ($options['class'] ?? ''), 'style' => ($options['style'] ?? ''), 'onClick' => ($options['onClick'] ?? ''), + 'text' => ($options['text'] ?? ''), 'content' => $content, ], $return diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index ee23d122a4..dce8fa3502 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -136,6 +136,7 @@ function notifications_get_subtypes(?string $source=null) 'NOTIF.PHP.DISABLE_FUNCTIONS', 'NOTIF.PHP.CHROMIUM', 'NOTIF.PHP.VERSION', + 'NOTIF.PHP.VERSION.SUPPORT', 'NOTIF.HISTORYDB', 'NOTIF.PANDORADB', 'NOTIF.PANDORADB.HISTORICAL', @@ -1025,9 +1026,20 @@ function notifications_print_dropdown() $mess = []; } + $notification_menu = html_print_menu_button( + [ + 'href' => 'javascript:', + 'class' => 'notification_menu_actions', + 'text' => __('Mark all as read'), + 'onClick' => 'mark_all_notification_as_read()', + ], + true + ); + return sprintf( "
+ %s
@@ -1037,6 +1049,7 @@ function notifications_print_dropdown() >
", + $notification_menu, array_reduce( $mess, function ($carry, $message) { @@ -1114,7 +1127,7 @@ function notifications_print_dropdown_element($message_info)

", - $action.';click_on_notification_toast(event)', + $action.'; click_on_notification_toast(event)', $message_info['id_mensaje'], messages_get_url($message_info['id_mensaje']), $target, diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 06a3640c7c..11580027bf 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -12289,3 +12289,8 @@ tr[id^="network_component-plugin-wmi-fields-dynamicMacroRow-"] input, tr[id^="network_component-plugin-snmp-fields-dynamicMacroRow-"] input { width: 100% !important; } + +.notification_menu { + padding-top: 10px; + padding-left: 15px; +}