From d871b599ef2620d1e6f40283820bc1d1d79a398f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 14 May 2019 23:49:01 +0200 Subject: [PATCH] General fixes and UM comm updates Former-commit-id: b4c58f467f195627f96afe7f06b59004adeb83be --- pandora_console/general/logon_ok.php | 14 +- pandora_console/general/register.php | 4 +- pandora_console/godmode/menu.php | 13 - .../godmode/setup/setup_notifications.php | 13 + .../godmode/update_manager/update_manager.php | 14 - .../include/class/ConsoleSupervisor.php | 30 +- .../include/functions_messages.php | 26 +- .../include/functions_notifications.php | 27 +- .../include/functions_update_manager.php | 295 ------------------ pandora_console/include/styles/pandora.css | 6 +- pandora_console/index.php | 118 ++++--- 11 files changed, 150 insertions(+), 410 deletions(-) diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index 6ecefbf3ac..2004e3af9b 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -215,7 +215,19 @@ if (!empty($all_data)) { // END OF NEWS BOARD. } - $nots = messages_get_overview('utimestamp', 'DESC', false); + $nots = messages_get_overview( + 'utimestamp', + 'DESC', + false, + true, + 0, + [ + 'description' => [ + 'messages', + 'System status', + ], + ] + ); if (!empty($nots)) { // Notifications board. echo '
'; diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index 2a5f7a185b..ee94ef85f0 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -128,12 +128,12 @@ ui_require_css_file('register'); $initial = isset($config['initial_wizard']) !== true || $config['initial_wizard'] != '1'; -$newsletter = !db_get_value( +$newsletter = db_get_value( 'middlename', 'tusuario', 'id_user', $config['id_user'] -); +) === null; $registration = isset($config['pandora_uid']) !== true || $config['pandora_uid'] == ''; diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index ac3154b657..eaf33df640 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -457,19 +457,6 @@ if (check_acl($config['id_user'], 0, 'PM') && $config['enable_update_manager']) $sub['godmode/update_manager/update_manager&tab=setup']['text'] = __('Update Manager options'); $sub['godmode/update_manager/update_manager&tab=setup']['id'] = 'Options'; - if (license_free() && is_user_admin($config['id_user'])) { - include_once 'include/functions_update_manager.php'; - // If there are unread messages, display the notification icon - $number_total_messages; - $number_unread_messages = update_manager_get_unread_messages(); - if ($number_unread_messages > 0) { - $menu_godmode['messages']['notification'] = $number_unread_messages; - } - - $sub['godmode/update_manager/update_manager&tab=messages']['text'] = __('Messages'); - $sub['godmode/update_manager/update_manager&tab=messages']['id'] = 'Messages'; - } - $menu_godmode['messages']['sub'] = $sub; } diff --git a/pandora_console/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index 9ee95f78cc..473acba471 100644 --- a/pandora_console/godmode/setup/setup_notifications.php +++ b/pandora_console/godmode/setup/setup_notifications.php @@ -160,6 +160,19 @@ if (get_parameter('get_notifications_dropdown', 0)) { return; } +if (get_parameter('get_notification', 0)) { + $msg_id = get_parameter('id', 0); + + if ($msg_id > 0) { + $msg = messages_get_message($msg_id); + + $msg['mensaje'] = io_safe_output($msg['mensaje']); + echo json_encode($msg); + } + + return; +} + // Notification table. It is just a wrapper. $table_content = new StdClass(); $table_content->data = []; diff --git a/pandora_console/godmode/update_manager/update_manager.php b/pandora_console/godmode/update_manager/update_manager.php index db91738a17..7939667567 100644 --- a/pandora_console/godmode/update_manager/update_manager.php +++ b/pandora_console/godmode/update_manager/update_manager.php @@ -45,12 +45,6 @@ $buttons = [ ], ]; -if (license_free()) { - $buttons['messages'] = [ - 'active' => ($tab == 'messages') ? true : false, - 'text' => ''.html_print_image('images/email_mc.png', true, ['title' => __('Update manager messages')]).'', - ]; -} switch ($tab) { case 'setup': @@ -64,10 +58,6 @@ switch ($tab) { case 'online': $title = __('Update manager » Online'); break; - - case 'messages': - $title = __('Update manager » Messages'); - break; } ui_print_page_header( @@ -88,10 +78,6 @@ switch ($tab) { include $config['homedir'].'/godmode/update_manager/update_manager.offline.php'; break; - case 'messages': - include $config['homedir'].'/godmode/update_manager/update_manager.messages.php'; - break; - case 'online': default: include $config['homedir'].'/godmode/update_manager/update_manager.online.php'; diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index c429fa7d2c..44d8571b92 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -206,9 +206,7 @@ class ConsoleSupervisor * NOTIF.UPDATEMANAGER.MESSAGES */ - if (update_manager_verify_registration()) { - $this->getUMMessages(); - } + $this->getUMMessages(); } @@ -434,9 +432,8 @@ class ConsoleSupervisor * NOTIF.UPDATEMANAGER.MESSAGES */ - if (update_manager_verify_registration()) { - $this->getUMMessages(); - } + $this->getUMMessages(); + } @@ -2248,6 +2245,22 @@ class ConsoleSupervisor { global $config; + if (update_manager_verify_registration() === false) { + // Console not subscribed. + return; + } + + // Avoid contact for messages too much often. + if (isset($config['last_um_check']) + && time() < $config['last_um_check'] + ) { + return; + } + + // Only ask for messages once a day. + $future = (time() + 24 * SECONDS_1HOUR); + config_update_value('last_um_check', $future); + include_once $config['homedir'].'/include/functions_update_manager.php'; $params = [ @@ -2272,13 +2285,12 @@ class ConsoleSupervisor ); foreach ($messages as $message) { if (!isset($message['url'])) { - // Avoid log messges. - $message['url'] = null; + $message['url'] = '#'; } $this->notify( [ - 'type' => 'NOTIF.UPDATEMANAGER.MESSAGES', + 'type' => 'NOTIF.UPDATEMANAGER.MESSAGES.'.$message['id'], 'title' => $message['subject'], 'message' => base64_decode($message['message_html']), 'url' => $message['url'], diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index 35066129bc..1bc54c9c89 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -442,14 +442,15 @@ function messages_get_count_sent(string $user='') /** * Get message overview in array * - * @param string $order How to order them valid: - * (status (default), subject, timestamp, sender). - * @param string $order_dir Direction of order - * (ASC = Ascending, DESC = Descending). - * @param boolean $incl_read Include read messages in return. - * @param boolean $incl_source_info Include source info. - * @param integer $limit Maximum number of result in the query. - * @param array $other_filter Add a filter on main query. + * @param string $order How to order them valid: + * (status (default), subject, timestamp, sender). + * @param string $order_dir Direction of order + * (ASC = Ascending, DESC = Descending). + * @param boolean $incl_read Include read messages in return. + * @param boolean $incl_source_info Include source info. + * @param integer $limit Maximum number of result in the query. + * @param array $other_filter Add a filter on main query. + * @param string $join_other_filter How to join filter on main query. * * @return integer The number of messages this user has */ @@ -459,7 +460,8 @@ function messages_get_overview( bool $incl_read=true, bool $incl_source_info=false, int $limit=0, - array $other_filter=[] + array $other_filter=[], + string $join_other_filter='AND' ) { global $config; @@ -529,7 +531,11 @@ function messages_get_overview( $config['id_user'], $config['id_user'], $read, - db_format_array_where_clause_sql($other_filter, 'AND', ' AND '), + db_format_array_where_clause_sql( + $other_filter, + $join_other_filter, + ' AND ' + ), $order, ($limit !== 0) ? ' LIMIT '.$limit : '' ); diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index a498ef54d3..7552c2c7b4 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -972,13 +972,32 @@ function notifications_print_dropdown() */ function notifications_print_dropdown_element($message_info) { + $action = ''; + + switch ($message_info['description']) { + case 'Official communication': + $action = 'show_modal(this.id);'; + $target = ''; + $body_preview = io_safe_output($message_info['mensaje']); + break; + + default: + $action = ''; + $target = '_blank'; + $body_preview = strip_tags( + io_safe_output($message_info['mensaje']), + '
'
+            );
+        break;
+    }
+
     return sprintf(
         "
             %s
             
@@ -990,10 +1009,12 @@ function notifications_print_dropdown_element($message_info)

", + $action.';click_on_notification_toast(event)', $message_info['id_mensaje'], messages_get_url($message_info['id_mensaje']), + $target, html_print_image('images/'.$message_info['icon'], true), io_safe_output($message_info['subject']), - strip_tags(io_safe_output($message_info['mensaje']), '
')
+        $body_preview
     );
 }
diff --git a/pandora_console/include/functions_update_manager.php b/pandora_console/include/functions_update_manager.php
index 9b3ba0ce5c..2479ca543b 100755
--- a/pandora_console/include/functions_update_manager.php
+++ b/pandora_console/include/functions_update_manager.php
@@ -1627,112 +1627,6 @@ function update_manager_register_instance()
 }
 
 
-/**
- * Deprecated? study.
- *
- * @return void
- */
-function update_manager_download_messages()
-{
-    include_once 'include/functions_io.php';
-    global $config;
-
-    if (!isset($config['pandora_uid'])) {
-        return;
-    }
-
-    // Do not ask in next 2 hours.
-    $future = (time() + 2 * SECONDS_1HOUR);
-    config_update_value('last_um_check', $future);
-
-    /*
-     * Delete old messages
-     * db_get_sql('DELETE FROM tupdate WHERE UNIX_TIMESTAMP(filename) < UNIX_TIMESTAMP(NOW())');
-     * Build the curl request
-     */
-
-    $params = [
-        'pandora_uid' => $config['pandora_uid'],
-        'timezone'    => $config['timezone'],
-        'language'    => $config['language'],
-    ];
-
-    $result = update_manager_curl_request('get_messages', $params);
-
-    if (!$result['success']) {
-        return ($result['update_message']);
-    }
-
-    switch ($result['http_status']) {
-        case 200:
-            $message = json_decode($result['update_message'], true);
-
-            if ($message['success'] == 1) {
-                foreach ($message['messages'] as $single_message) {
-                    // Convert subject -> db_field_value;.
-                    // message_html -> data;
-                    // expiration -> filename;
-                    // message_id -> svn_version;.
-                    $single_message['db_field_value'] = io_safe_input(
-                        $single_message['subject']
-                    );
-                    unset($single_message['subject']);
-                    $single_message['data'] = io_safe_input_html(
-                        $single_message['message_html']
-                    );
-                    // It is mandatory to prepend a backslash to all
-                    // single quotes.
-                    $single_message['data'] = preg_replace(
-                        '/\'/',
-                        '\\\'',
-                        $single_message['data']
-                    );
-                    unset($single_message['message_html']);
-                    $single_message['filename'] = $single_message['expiration'];
-                    unset($single_message['expiration']);
-                    $single_message['svn_version'] = $single_message['message_id'];
-                    unset($single_message['message_id']);
-
-                    // Add common tconfig id_update_package.
-                    $single_message['id_update_package'] = $config['id_um_package_messages'];
-
-                    $result = db_process_sql_insert(
-                        'tupdate',
-                        $single_message
-                    );
-                }
-            }
-        break;
-
-        default:
-            // Ignore.
-        break;
-    }
-}
-
-
-/**
- * Deprecated? review.
- *
- * @param integer $id_message Message id.
- *
- * @return boolean Result.
- */
-function update_manager_remote_read_messages($id_message)
-{
-    global $config;
-
-    $params = [
-        'pandora_uid' => $config['pandora_uid'],
-        'message_id'  => $id_message,
-    ];
-
-    $result = update_manager_curl_request('mark_as_read', $params);
-
-    return $result['success'];
-}
-
-
 /**
  * Extracts OUM package.
  *
@@ -1999,195 +1893,6 @@ function update_manager_get_current_package()
 }
 
 
-/**
- * Deprecated? verify.
- * Set the read or not read status message of current user.
- *
- * @param integer $message_id Message id.
- * @param string  $status     Status.
- *
- * @return void
- */
-function update_manger_set_read_message($message_id, $status)
-{
-    global $config;
-
-    $rollback = db_get_value(
-        'data_rollback',
-        'tupdate',
-        'svn_version',
-        $message_id
-    );
-    $users_read = json_decode($rollback, true);
-    $users_read[$config['id_user']] = $status;
-
-    $rollback = json_encode($users_read);
-    db_process_sql_update(
-        'tupdate',
-        ['data_rollback' => $rollback],
-        ['svn_version' => $message_id]
-    );
-}
-
-
-/**
- * Deprecated? verify.
- * Get the read or not read status message
- *
- * @param integer $message_id Message id.
- * @param boolean $rollback   Rollback or not.
- *
- * @return boolean Success or not.
- */
-function update_manger_get_read_message($message_id, $rollback=false)
-{
-    global $config;
-
-    if ($rollback === false) {
-        $rollback = db_get_value(
-            'data_rollback',
-            'tupdate',
-            'svn_version',
-            $message_id
-        );
-    }
-
-    $users_read = json_decode($rollback, true);
-
-    if (isset($users_read[$config['id_user']])
-        && ($users_read[$config['id_user']] == 1)
-    ) {
-        return true;
-    }
-
-    return false;
-}
-
-
-/**
- * Deprecated? verify.
- * Get the last message.
- *
- * @return array Latest message.
- */
-function update_manger_get_last_message()
-{
-    global $config;
-
-    $sql = 'SELECT data, svn_version, db_field_value FROM tupdate ';
-    $sql .= 'WHERE data_rollback NOT LIKE \'%"'.$config['id_user'].'":1%\' ';
-    $sql .= 'OR data_rollback IS NULL ';
-    $sql .= 'ORDER BY svn_version DESC ';
-
-    $message = db_get_row_sql($sql);
-    return $message;
-}
-
-
-/**
- * Deprecated? verify.
- * Get the a single message message.
- *
- * @param integer $message_id Message id.
- *
- * @return array Target message.
- */
-function update_manger_get_single_message($message_id)
-{
-    global $config;
-
-    $sql = 'SELECT data, svn_version, db_field_value FROM tupdate ';
-    $sql .= 'WHERE svn_version='.$message_id;
-
-    $message = db_get_row_sql($sql);
-    return $message;
-}
-
-
-/**
- * Deprecated? verify.
- * Count messages (local).
- *
- * @return integer Count.
- */
-function update_manager_get_total_messages()
-{
-    global $config;
-
-    $sql = 'SELECT COUNT(*) FROM tupdate';
-    return (int) db_get_sql($sql);
-}
-
-
-/**
- * Deprecated? verify.
- * Retrieves unread messages count.
- *
- * @return integer Pending read messages.
- */
-function update_manager_get_unread_messages()
-{
-    global $config;
-
-    $total = update_manager_get_total_messages();
-    $sql = 'SELECT COUNT(*) FROM tupdate WHERE data_rollback LIKE \'%"'.$config['id_user'].'":1%\'';
-    $read = (int) db_get_sql($sql);
-
-    return ($total - $read);
-}
-
-
-/**
- * Deprecated? verify.
- * Retrieves some messages count.
- *
- * @return integer Pending read messages.
- */
-function update_manager_get_not_deleted_messages()
-{
-    global $config;
-
-    $total = update_manager_get_total_messages();
-    $sql = 'SELECT COUNT(*) FROM tupdate WHERE description LIKE \'%"'.$config['id_user'].'":1%\'';
-    $read = (int) db_get_sql($sql);
-
-    return ($total - $read);
-}
-
-
-/**
- * Deprecated? verify.
- * Deletes message.
- *
- * @param integer $message_id Message id.
- *
- * @return void
- */
-function update_manger_set_deleted_message($message_id)
-{
-    global $config;
-
-    $rollback = db_get_value(
-        'description',
-        'tupdate',
-        'svn_version',
-        $message_id
-    );
-    $users_read = json_decode($rollback, true);
-    $users_read[$config['id_user']] = 1;
-
-    $rollback = json_encode($users_read);
-    db_process_sql_update(
-        'tupdate',
-        ['description' => $rollback ],
-        ['svn_version' => $message_id]
-    );
-
-    // Mark as read too.
-    update_manger_set_read_message($message_id, 1);
-}
-
-
 /**
  * Function recursive delete directory.
  *
diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css
index 98afa42029..86a461485e 100644
--- a/pandora_console/include/styles/pandora.css
+++ b/pandora_console/include/styles/pandora.css
@@ -4586,14 +4586,14 @@ div#dialog_messages table th:last-child {
 }
 .notification-item:hover {
   border: #ccc solid 1px;
+  text-decoration: none;
 }
 .notification-item > * {
   padding-left: 15px;
   pointer-events: none;
 }
-
-.notification-item:hover {
-  text-decoration: none;
+.notification-item > img {
+  width: 75px;
 }
 
 .notification-info {
diff --git a/pandora_console/index.php b/pandora_console/index.php
index fb6e2c5c03..730e404a20 100755
--- a/pandora_console/index.php
+++ b/pandora_console/index.php
@@ -902,15 +902,6 @@ clear_pandora_error_for_header();
 $config['logged'] = false;
 extensions_load_extensions($process_login);
 
-// Check for update manager messages
-if (license_free() && is_user_admin($config['id_user'])
-    && (($config['last_um_check'] < time())
-    || (!isset($config['last_um_check'])))
-) {
-    include_once 'include/functions_update_manager.php';
-    update_manager_download_messages();
-}
-
 if ($process_login) {
      // Call all extensions login function
     extensions_call_login_function();
@@ -1204,6 +1195,8 @@ if ($config['pure'] == 0) {
 echo '
'; echo '
'; +echo '
'; +echo '
'; if ($config['pure'] == 0) { echo '
'; @@ -1258,8 +1251,6 @@ require 'include/php_to_js_values.php'; $("HTML, BODY").animate({ scrollTop: 0 }, 500); } - - //Initial load of page $(document).ready(adjustFooter); @@ -1329,57 +1320,64 @@ require 'include/php_to_js_values.php'; } - var times_fired_register_wizard = 0; - - function run_identification_wizard (register, newsletter , return_button) { - if (times_fired_register_wizard) { - $(".ui-dialog-titlebar-close").show(); - - //Reset some values - $("#label-email-newsletter").hide(); - $("#text-email-newsletter").hide(); - $("#required-email-newsletter").hide(); - $("#checkbox-register").removeAttr('checked'); - $("#checkbox-newsletter").removeAttr('checked'); - - // Hide or show parts - if (register == 1) { - $("#checkbox-register").show(); - $("#label-register").show (); - } - if (register == 0) { - $("#checkbox-register").attr ('style', 'display: none !important'); - $("#label-register").hide (); - } - if (newsletter == 1) { - $("#checkbox-newsletter").show(); - $("#label-newsletter").show (); - } - if (newsletter == 0) { - $("#checkbox-newsletter").attr ('style', 'display: none !important'); - $("#label-newsletter").hide (); - } - $("#login_accept_register").dialog('open'); - } - else { - $(".ui-dialog-titlebar-close").show(); - $("#container").append('
'); - jQuery.post ("ajax.php", - {"page": "general/login_identification_wizard", - "not_return": 1, - "force_register": register, - "force_newsletter": newsletter, - "return_button": return_button}, - function (data) { - $(".id_wizard").hide () - .empty () - .append (data); - }, - "html" + function show_modal(id) { + var match = /notification-(.*)-id-([0-9]+)/.exec(id); + if (!match) { + console.error( + "Cannot handle toast click event. Id not valid: ", + event.target.id ); + return; } - times_fired_register_wizard++; - return false; + jQuery.post ("ajax.php", + { + "page": "godmode/setup/setup_notifications", + "get_notification": 1, + "id": match[2] + }, + function (data) { + notifications_hide(); + try { + var json = JSON.parse(data); + $('#um_msg_receiver') + .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" ); + } + } + ], + overlay: { + opacity: 0.5, + background: "black" + }, + closeOnEscape: false, + open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); } + }); + + $(".ui-widget-overlay").css("background", "#000"); + $(".ui-widget-overlay").css("opacity", 0.6); + $(".ui-draggable").css("cursor", "inherit"); + + } catch (error) { + console.log(error); + } + + }, + "html" + ); } //Dynamically assign footer position and width.