Merge branch 'ent-11051-marcar-como-leidos-todos-los-mensajes-del-sistema' into 'develop'

Ent 11051 marcar como leidos todos los mensajes del sistema

See merge request artica/pandorafms!6202
This commit is contained in:
Rafael Ameijeiras 2023-08-22 06:46:29 +00:00
commit 8eab813101
7 changed files with 255 additions and 3 deletions

View File

@ -532,6 +532,54 @@ echo sprintf('<div id="header_table" class="header_table_%s">', $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 filter_notification() {
let notification_type = '';
$('.notification-item').hide();
$(".checkbox_filter_notifications:checkbox:checked").each(function() {
notification_type = $(this).val();
console.log(notification_type);
$('.notification-item[value='+notification_type+']').show();
if (notification_type == 'All'){
$('.notification-item').show();
}
});
if (notification_type == 'All'){
$('.notification-item').show();
}
if (notification_type == ''){
$('.notification-item').hide();
}
}
function click_on_notification_toast(event) {
var match = /notification-(.*)-id-([0-9]+)/.exec(event.target.id);
if (!match) {

View File

@ -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;

View File

@ -169,6 +169,7 @@ class ConsoleSupervisor
* NOTIF.PHP.DISABLE_FUNCTIONS
* NOTIF.PHP.CHROMIUM
* NOTIF.PHP.VERSION
* NOTIF.PHP.VERSION.SUPPORT
*/
$this->checkPHPSettings();
@ -383,6 +384,7 @@ class ConsoleSupervisor
* NOTIF.PHP.DISABLE_FUNCTIONS
* NOTIF.PHP.CHROMIUM
* NOTIF.PHP.VERSION
* NOTIF.PHP.VERSION.SUPPORT
*/
$this->checkPHPSettings();
@ -874,6 +876,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':
@ -1830,14 +1833,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').'<br>'.__('Current PHP version: ').PHP_VERSION,
'url' => $url,
]
);
} else {
$this->cleanNotifications('NOTIF.PHP.VERSION');
$this->cleanNotifications('NOTIF.PHP.VERSION.SUPPORT');
}
}

View File

@ -2904,6 +2904,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 .= '</a>';
@ -7118,6 +7120,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

View File

@ -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',
@ -1010,6 +1011,106 @@ function notifications_print_user_switch($source, $user, $label)
}
/**
* Generates an HTML of notification filter types.
*
* @return string HTML filter notification.
*/
function notification_filter()
{
$types_list[] = 'All';
$notification_types = db_get_all_rows_sql('SELECT DISTINCT tm.subtype FROM tmensajes as tm INNER JOIN tnotification_user as tnu ON tm.id_mensaje = tnu.id_mensaje WHERE tnu.utimestamp_read IS NULL');
if ($notification_types !== false) {
foreach ($notification_types as $notification_type) {
$type = explode('.', $notification_type['subtype'])[1];
$types_list[] = $type;
}
}
$types_list = array_unique($types_list);
$notification_filter = "<ul id='menu-filter_notification'>";
$notification_filter .= "<li>
<input type='checkbox' name='filter_menu' id='filter_menu'>
<label for='filter_menu' id='filter_menu_label'>".__('Filter').'</label>';
$notification_filter .= "<ul class='sublevel-filter_notification'>";
foreach ($types_list as $type) {
if ($type === 'All') {
$checked = 'checked';
} else {
$checked = '';
}
switch ($type) {
case 'HISTORYDB':
$type_name = 'HISTORY DB';
break;
case 'PANDORADB':
$type_name = 'PANDORA DB';
break;
case 'UPDATEMANAGER':
$type_name = 'UPDATE MANAGER';
break;
case 'ALLOWOVERRIDE':
$type_name = 'ALLOW OVERRIDE';
break;
case 'DISCOVERYTASK':
$type_name = 'DISCOVERY TASK';
break;
default:
$type_name = $type;
break;
}
$notification_filter .= "<li><div class='item-filter'>
<input type='checkbox'
class='checkbox_filter_notifications'
value=".$type."
name='filter_".$type."'
".$checked."
id='filter_".$type."'>
<label for='filter_".$type."'>".$type_name.'</label>
</div>
</li>';
}
$notification_filter .= "<li><div class='item-filter'>";
$notification_filter .= html_print_div(
[
'class' => 'action-buttons w100p',
'content' => html_print_submit_button(
__('Filter'),
'btn_submit',
false,
[
'class' => 'mini sub filter',
'icon' => 'search mini',
'onClick' => 'filter_notification()',
],
true
),
],
true
);
$notification_filter .= '</div>
</li>';
$notification_filter .= '</ul>';
$notification_filter .= '</li>';
$notification_filter .= '</ul>';
return $notification_filter;
}
/**
* Generates the dropdown notifications menu.
*
@ -1022,9 +1123,24 @@ 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
);
$notification_filter = notification_filter();
return sprintf(
"<div id='notification-wrapper'>
<div id='notification-wrapper-inner'>
<div class='notificaion_menu_container'>
<div class='menu_tab filter_notification'>%s</div>
<div class='menu_tab notification_menu'>%s</div>
</div>
%s
</div>
</div>
@ -1034,6 +1150,8 @@ function notifications_print_dropdown()
>
</div>
",
$notification_filter,
$notification_menu,
array_reduce(
$mess,
function ($carry, $message) {
@ -1093,6 +1211,8 @@ function notifications_print_dropdown_element($message_info)
$message_info['subject'] = io_safe_input($img);
}
$type = explode('.', $message_info['subtype'])[1];
if (strlen($body_preview) >= 170) {
$body_preview = substr($body_preview, 0, 150);
$body_preview .= __('. Read More...');
@ -1103,6 +1223,7 @@ function notifications_print_dropdown_element($message_info)
class='notification-item'
onclick='%s'
id='notification-item-id-%s'
value='%s'
href='%s'
target='%s'
>
@ -1116,8 +1237,9 @@ function notifications_print_dropdown_element($message_info)
</p>
</div>
</a>",
$action.';click_on_notification_toast(event)',
$action.'; click_on_notification_toast(event)',
$message_info['id_mensaje'],
$type,
messages_get_url($message_info['id_mensaje']),
$target,
html_print_image('images/info.svg', true, ['style' => 'height: 40px;margin-left: -20px;margin-top: -40px;']),

View File

@ -12358,6 +12358,59 @@ tr[id^="network_component-plugin-snmp-fields-dynamicMacroRow-"] input {
width: 100% !important;
}
.notificaion_menu_container {
display: flex;
padding-top: 10px;
padding-left: 15px;
}
.notification_menu {
width: 100px;
}
.filter_notification {
width: auto;
min-width: 50px;
}
#menu-filter_notification * {
list-style: none;
}
#menu-filter_notification li {
line-height: 180%;
}
#menu-filter_notification input[name="filter_menu"] {
position: absolute;
left: -1000em;
}
#menu-filter_notification label[id="filter_menu_label"]:before {
content: "\025b8";
margin-right: 4px;
}
#menu-filter_notification
input[name="filter_menu"]:checked
~ label[id="filter_menu_label"]:before {
content: "\025be";
}
#menu-filter_notification .sublevel-filter_notification {
display: none;
}
#menu-filter_notification input[name="filter_menu"]:checked ~ ul {
display: block;
}
.item-filter > label {
display: inline-block;
width: auto;
vertical-align: middle;
}
.item-filter > input[type="checkbox"] {
display: inline-block;
width: 40px;
height: 100%;
vertical-align: middle;
}
/*Horizontal tree*/
.horizontal_tree-icon {

View File

@ -2058,6 +2058,8 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) {
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist#'
);
$notification->{'subtype'} .= safe_input('NOTIF.DISCOVERYTASK.REVIEW');
$notification->{'mensaje'} = safe_input(
'Discovery task (host&devices) \''.safe_output($self->{'task_data'}{'name'})
.'\' has been completed. Please review the results.'