ent-9067 notifications fixed

This commit is contained in:
edu.corral 2022-06-16 13:02:49 +02:00
parent ba5693a961
commit 4ee4590690
3 changed files with 221 additions and 132 deletions

View File

@ -2145,8 +2145,8 @@ class ConsoleSupervisor
[
'type' => 'NOTIF.UPDATEMANAGER.REGISTRATION',
'title' => __('This instance is not registered in the Update manager section'),
'message' => __('Click <a class="bolder underline" href="javascript: force_run_register();"> here</a> to start the registration process'),
'url' => 'javascript: force_run_register();',
'message' => __('Click here to start the registration process'),
'url' => '__url__/index.php?sec=messages&sec2=godmode/update_manager/update_manager&tab=online',
]
);
} else {
@ -2166,7 +2166,7 @@ class ConsoleSupervisor
// Check default password for "admin".
$admin_with_default_pass = db_get_value_sql(
'SELECT count(*) FROM tusuario
WHERE
WHERE
id_user="admin"
AND password="1da7ee7d45b96d0e1f45ee4ee23da560"
AND is_admin=1
@ -2441,11 +2441,11 @@ class ConsoleSupervisor
config_update_value('last_um_check', $future, true);
$messages = update_manager_get_messages();
if (is_array($messages) === true) {
$source_id = get_notification_source_id(
'Official&#x20;communication'
);
foreach ($messages as $message) {
if (isset($message['url']) === false) {
$message['url'] = '#';
@ -2476,8 +2476,8 @@ class ConsoleSupervisor
// List all servers except satellite server.
$server_version_list = db_get_all_rows_sql(
sprintf(
'SELECT `name`, `version`
FROM tserver
'SELECT `name`, `version`
FROM tserver
WHERE server_type != %d
GROUP BY `version`',
SERVER_TYPE_ENTERPRISE_SATELLITE

View File

@ -84,10 +84,7 @@ function get_notification_targets(int $id_message)
if (is_array($ret)) {
foreach ($ret as $row) {
array_push(
$targets['users'],
get_user_fullname($row['id_user'])
);
array_push($targets['users'], get_user_fullname($row['id_user']));
}
}
@ -227,8 +224,10 @@ function check_notification_readable(int $id_message)
*
* @return array [users] and [groups] with the targets.
*/
function get_notification_source_targets(int $id_source, ?string $subtype=null)
{
function get_notification_source_targets(
int $id_source,
?string $subtype=null
) {
$ret = [];
$filter = '';
@ -484,7 +483,8 @@ function notifications_add_group_to_source($source_id, $groups)
continue;
}
$res = $res && db_process_sql_insert(
$res = $res &&
db_process_sql_insert(
'tnotification_source_group',
[
'id_group' => $group,
@ -525,7 +525,8 @@ function notifications_add_users_to_source($source_id, $users)
continue;
}
$res = $res && db_process_sql_insert(
$res = $res &&
db_process_sql_insert(
'tnotification_source_user',
[
'id_user' => $user,
@ -551,7 +552,13 @@ function notifications_add_users_to_source($source_id, $users)
function notifications_get_group_source_not_configured($source_id)
{
$groups_selected = notifications_get_group_sources_for_select($source_id);
$all_groups = users_get_groups_for_select(false, 'AR', false, true, $groups_selected);
$all_groups = users_get_groups_for_select(
false,
'AR',
false,
true,
$groups_selected
);
return array_diff($all_groups, $groups_selected);
}
@ -566,12 +573,10 @@ function notifications_get_group_source_not_configured($source_id)
*/
function notifications_get_user_source_not_configured($source_id)
{
$users_selected = array_keys(notifications_get_user_sources_for_select($source_id));
$users = get_users(
'id_user',
['!id_user' => $users_selected],
['id_user']
$users_selected = array_keys(
notifications_get_user_sources_for_select($source_id)
);
$users = get_users('id_user', ['!id_user' => $users_selected], ['id_user']);
return index_array($users, 'id_user', 'id_user');
}
@ -587,8 +592,8 @@ function notifications_get_user_source_not_configured($source_id)
function notifications_build_user_enable_return($status, $enabled)
{
return [
'status' => ((bool) $status === true) ? 1 : 0,
'enabled' => ((bool) $enabled === true) ? 1 : 0,
'status' => (bool) $status === true ? 1 : 0,
'enabled' => (bool) $enabled === true ? 1 : 0,
];
}
@ -625,16 +630,11 @@ function notifications_get_user_label_status($source, $user, $label)
$common_groups = array_intersect(
array_keys(users_get_groups($user)),
array_keys(
notifications_get_group_sources_for_select($source['id'])
)
array_keys(notifications_get_group_sources_for_select($source['id']))
);
// No group found, return no permissions.
$value = empty($common_groups) ? false : $source[$label];
return notifications_build_user_enable_return(
$value,
false
);
return notifications_build_user_enable_return($value, false);
}
@ -681,13 +681,7 @@ function notifications_get_counters()
{
$num_notifications = 0;
$last_id = 0;
$last_message = messages_get_overview(
'timestamp',
'DESC',
false,
false,
1
);
$last_message = messages_get_overview('timestamp', 'DESC', false, false, 1);
if (!empty($last_message)) {
$num_notifications = messages_get_count();
$last_id = $last_message[0]['id_mensaje'];
@ -718,7 +712,9 @@ function notifications_get_counters()
function notifications_print_ball($num_notifications, $last_id)
{
$no_notifications = (int) $num_notifications === 0;
$class_status = ($no_notifications) ? 'notification-ball-no-messages' : 'notification-ball-new-messages';
$class_status = $no_notifications
? 'notification-ball-no-messages'
: 'notification-ball-new-messages';
return sprintf(
'<div
%s
@ -728,7 +724,7 @@ function notifications_print_ball($num_notifications, $last_id)
>
%s
</div>',
($no_notifications) ? '' : 'onclick="addNotifications(event)"',
$no_notifications ? '' : 'onclick="addNotifications(event)"',
$class_status,
$last_id,
$num_notifications
@ -799,7 +795,7 @@ function notifications_print_global_source_configuration($source)
'type' => 'switch',
'id' => 'nt-'.$source['id'].'.'.$type.'-subtype',
'class' => 'elem-clickable',
'value' => (isset($blacklist[$type]) === false),
'value' => isset($blacklist[$type]) === false,
'return' => true,
]
);
@ -833,14 +829,11 @@ function notifications_print_global_source_configuration($source)
*
* @return string HTML with the generated selector
*/
function notifications_print_source_select_box(
$info_selec,
$id,
$source_id
) {
$title = ($id === 'users') ? __('Notified users') : __('Notified groups');
$add_title = ($id === 'users') ? __('Add users') : __('Add groups');
$delete_title = ($id === 'users') ? __('Delete users') : __('Delete groups');
function notifications_print_source_select_box($info_selec, $id, $source_id)
{
$title = $id === 'users' ? __('Notified users') : __('Notified groups');
$add_title = $id === 'users' ? __('Add users') : __('Add groups');
$delete_title = $id === 'users' ? __('Delete users') : __('Delete groups');
// Generate the HTML.
return sprintf(
@ -873,11 +866,7 @@ function notifications_print_source_select_box(
true,
[
'title' => $add_title,
'onclick' => sprintf(
"add_source_dialog('%s', '%s')",
$id,
$source_id
),
'onclick' => sprintf("add_source_dialog('%s', '%s')", $id, $source_id),
]
),
html_print_image(
@ -1062,12 +1051,28 @@ function notifications_print_dropdown()
function notifications_print_dropdown_element($message_info)
{
$action = '';
switch ($message_info['description']) {
case 'Official&#x20;communication':
$action = 'show_modal(this.id);';
$target = '';
$body_preview = __('Click here to get more information');
preg_match(
'/LTS\s+(\d*)/',
io_safe_output($message_info['subject']),
$array_version
);
if (empty($array_version) === false
&& isset($array_version[1]) === true
) {
$version = (int) $array_version[1];
$result = notifications_curl_new_version_description($version);
if (empty($result) === false) {
$title = explode('\n', $result);
hd($title, true);
$action = 'show_modal_lts("'.base64_encode(io_safe_output($message_info['subject'])).'","'.base64_encode($result).'")';
}
}
break;
default:
@ -1128,3 +1133,45 @@ function notifications_print_dropdown_element($message_info)
$body_preview
);
}
function notifications_curl_new_version_description(int $version)
{
global $config;
$pandora_license = db_get_value('value', 'tupdate_settings', '`key`', 'customer_key');
$params = [
'action' => 'newer_packages',
'puid' => $config['pandora_uid'],
'build' => ($version - 1),
'current_package' => ($version - 1),
'license' => $pandora_license,
'limit_count' => 1,
'language' => $config['language'],
'timezone' => $config['timezone'],
'version' => 'v7.0NG.'.$config['current_package'],
'email' => '',
'format' => 'lts',
];
$defaults = [
CURLOPT_URL => $config['url_update_manager'],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => 1,
];
$ch = curl_init();
curl_setopt_array($ch, $defaults);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
if (isset($result[0]['description']) === false) {
$result = '';
} else {
$result = $result[0]['description'];
}
return $result;
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Index.
*
@ -53,8 +54,8 @@ $develop_bypass = 0;
if ($develop_bypass != 1) {
// If no config file, automatically try to install.
if (! file_exists('include/config.php')) {
if (! file_exists('install.php')) {
if (!file_exists('include/config.php')) {
if (!file_exists('install.php')) {
$url = explode('/', $_SERVER['REQUEST_URI']);
$flag_url = 0;
foreach ($url as $key => $value) {
@ -128,8 +129,8 @@ if ($develop_bypass != 1) {
}
}
if ((! file_exists('include/config.php'))
|| (! is_readable('include/config.php'))
if ((!file_exists('include/config.php'))
|| (!is_readable('include/config.php'))
) {
$login_screen = 'error_noconfig';
include 'general/error_screen.php';
@ -224,9 +225,9 @@ ob_start('ui_process_page_head');
enterprise_include_once('index.php');
echo '<script type="text/javascript">';
echo 'var dispositivo = navigator.userAgent.toLowerCase();';
echo 'if( dispositivo.search(/iphone|ipod|ipad|android/) > -1 ){';
echo 'document.location = "'.ui_get_full_url('/mobile').'"; }';
echo 'var dispositivo = navigator.userAgent.toLowerCase();';
echo 'if( dispositivo.search(/iphone|ipod|ipad|android/) > -1 ){';
echo 'document.location = "'.ui_get_full_url('/mobile').'"; }';
echo '</script>';
// This tag is included in the buffer passed to ui_process_page_head so
@ -275,7 +276,7 @@ if (strlen($search) > 0) {
// Login process.
enterprise_include_once('include/auth/saml.php');
if (! isset($config['id_user'])) {
if (!isset($config['id_user'])) {
// Clear error messages.
unset($_COOKIE['errormsg']);
setcookie('errormsg', null, -1);
@ -731,9 +732,9 @@ if (! isset($config['id_user'])) {
}
// Boolean parameters.
$correct_pass_change = (boolean) get_parameter('correct_pass_change', false);
$reset = (boolean) get_parameter('reset', false);
$first = (boolean) get_parameter('first', false);
$correct_pass_change = (bool) get_parameter('correct_pass_change', false);
$reset = (bool) get_parameter('reset', false);
$first = (bool) get_parameter('first', false);
// Strings.
$reset_hash = get_parameter('reset_hash');
$pass1 = get_parameter_post('pass1');
@ -955,7 +956,7 @@ if (! isset($config['id_user'])) {
exit('</html>');
} else {
if (((bool) $user_in_db['is_admin'] === false)
&& ( (bool) $user_in_db['not_login'] === true
&& ((bool) $user_in_db['not_login'] === true
|| (is_metaconsole() === false
&& has_metaconsole() === true
&& is_management_allowed() === false
@ -1170,7 +1171,7 @@ if (has_metaconsole() === true
$err .= '</div>';
?>
<script type="text/javascript">
$(document).ready(function () {
$(document).ready(function() {
infoMessage({
title: '<?php echo __('Warning'); ?>',
text: '<?php echo $err; ?>',
@ -1208,7 +1209,7 @@ if ($searchPage) {
$main_sec = $sec;
}
} else if ($sec == 'gextensions') {
$main_sec = get_parameter('extension_in_menu');
$main_sec = get_parameter('extension_in_menu');
if (empty($main_sec) === true) {
$main_sec = $sec;
}
@ -1379,12 +1380,12 @@ if ($config['pure'] == 0) {
// Main pure.
}
html_print_div(
echo html_print_div(
['id' => 'wiz_container'],
true
);
html_print_div(
echo html_print_div(
['id' => 'um_msg_receiver'],
true
);
@ -1426,26 +1427,27 @@ require 'include/php_to_js_values.php';
?>
<script type="text/javascript" language="javascript">
// When there are less than 5 rows, all rows must be white
var theme = "<?php echo $config['style']; ?>";
if(theme === 'pandora'){
if($('table.info_table tr').length < 5){
if (theme === 'pandora') {
if ($('table.info_table tr').length < 5) {
$('table.info_table tbody > tr').css('background-color', '#fff');
}
}
// When the user scrolls down 400px from the top of the document, show the
// button.
window.onscroll = function() {scrollFunction()};
window.onscroll = function() {
scrollFunction()
};
function scrollFunction() {
if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
if(document.getElementById("top_btn")){
if (document.getElementById("top_btn")) {
document.getElementById("top_btn").style.display = "block";
}
} else {
if(document.getElementById("top_btn")){
if (document.getElementById("top_btn")) {
document.getElementById("top_btn").style.display = "none";
}
}
@ -1455,48 +1457,49 @@ require 'include/php_to_js_values.php';
function topFunction() {
/*
* Safari.
* document.body.scrollTop = 0;
* For Chrome, Firefox, IE and Opera.
* document.documentElement.scrollTop = 0;
*/
* Safari.
* document.body.scrollTop = 0;
* For Chrome, Firefox, IE and Opera.
* document.documentElement.scrollTop = 0;
*/
$("HTML, BODY").animate({ scrollTop: 0 }, 500);
$("HTML, BODY").animate({
scrollTop: 0
}, 500);
}
// Initial load of page.
$(document).ready(adjustFooter);
// Every resize of window.
$(window).resize(adjustFooter);
// Every show/hide call may need footer re-layout.
(function() {
var oShow = jQuery.fn.show;
var oHide = jQuery.fn.hide;
jQuery.fn.show = function () {
jQuery.fn.show = function() {
var rv = oShow.apply(this, arguments);
adjustFooter();
return rv;
};
jQuery.fn.hide = function () {
jQuery.fn.hide = function() {
var rv = oHide.apply(this, arguments);
adjustFooter();
return rv;
};
})();
function first_time_identification () {
jQuery.post ("ajax.php",
{
function first_time_identification() {
jQuery.post("ajax.php", {
"page": "general/register",
"load_wizards": 'initial'
},
function (data) {
$('#wiz_container').empty ()
.html (data);
run_configuration_wizard ();
function(data) {
$('#wiz_container').empty()
.html(data);
run_configuration_wizard();
},
"html"
);
@ -1512,42 +1515,41 @@ require 'include/php_to_js_values.php';
);
return;
}
jQuery.post ("ajax.php",
{
jQuery.post("ajax.php", {
"page": "godmode/setup/setup_notifications",
"get_notification": 1,
"id": match[2]
},
function (data) {
function(data) {
notifications_hide();
try {
var json = JSON.parse(data);
$('#um_msg_receiver')
.empty ()
.html (json.mensaje);
.empty()
.html(json.mensaje);
$('#um_msg_receiver').prop('title', json.subject);
// Launch modal.
$("#um_msg_receiver").dialog({
resizable: true,
draggable: true,
modal: true,
width: 800,
buttons: [
{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
buttons: [{
text: "OK",
click: function() {
$(this).dialog("close");
}
],
}],
overlay: {
opacity: 0.5,
background: "black"
},
opacity: 0.5,
background: "black"
},
closeOnEscape: false,
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
open: function(event, ui) {
$(".ui-dialog-titlebar-close").hide();
}
});
$(".ui-widget-overlay").css("background", "#000");
@ -1563,30 +1565,70 @@ require 'include/php_to_js_values.php';
);
}
//Dynamically assign footer position and width.
function adjustFooter() {
/*
if (document.readyState !== 'complete' || $('#container').position() == undefined) {
return;
function show_modal_lts(title, description) {
notifications_hide();
// Launch modal.
try {
$('#um_msg_receiver').prop('title', atob(title));
$('#um_msg_receiver')
.empty()
.html('<div style="width:700px;height:500px">'+
'<pre>'+atob(description)+'</pre>'
+'</div>');
$("#um_msg_receiver").dialog({
resizable: true,
draggable: true,
modal: true,
width: 800,
height: 600,
overflow: 'auto',
buttons: [{
text: "OK",
click: function() {
$(this).dialog("close");
}
}],
overlay: {
opacity: 0.5,
background: "black"
},
closeOnEscape: false,
open: function(event, ui) {
$(".ui-dialog-titlebar-close").hide();
}
});
}
catch (error) {
console.log(error);
}
}
// minimum top value (upper limit) for div#foot
var ulim = $('#container').position().top + $('#container').outerHeight(true);
// window height. $(window).height() returns wrong value on Opera and Google Chrome.
var wh = document.documentElement.clientHeight;
// save div#foot's height for latter use
var h = $('#foot').height();
// new top value for div#foot
var t = (ulim + $('#foot').outerHeight() > wh) ? ulim : wh - $('#foot').outerHeight();
/*
if ($('#foot').position().top != t) {
$('#foot').css({ position: "absolute", top: t, left: $('#foot').offset().left});
$('#foot').height(h);
//Dynamically assign footer position and width.
function adjustFooter() {
/*
if (document.readyState !== 'complete' || $('#container').position() == undefined) {
return;
}
// minimum top value (upper limit) for div#foot
var ulim = $('#container').position().top + $('#container').outerHeight(true);
// window height. $(window).height() returns wrong value on Opera and Google Chrome.
var wh = document.documentElement.clientHeight;
// save div#foot's height for latter use
var h = $('#foot').height();
// new top value for div#foot
var t = (ulim + $('#foot').outerHeight() > wh) ? ulim : wh - $('#foot').outerHeight();
/*
if ($('#foot').position().top != t) {
$('#foot').css({ position: "absolute", top: t, left: $('#foot').offset().left});
$('#foot').height(h);
}
if ($('#foot').width() != $(window).width()) {
$('#foot').width($(window).width());
}
*/
}
if ($('#foot').width() != $(window).width()) {
$('#foot').width($(window).width());
}
*/
}
</script>
<?php
if (__PAN_XHPROF__ === 1) {