Send broadcast message for all users

Questions related to using nuBuilder Forte.

Send broadcast message for all users

Unread postby miasoft » Tue Jul 27, 2021 3:59 pm

I would like to send message (online from globeadmin account) for all active users. For example, "Please exit the program ..."
Is it possible?
Wbr, miasoft.
miasoft
 
Posts: 87
Joined: Wed Dec 23, 2020 8:58 pm

Re: Send broadcast message for all users

Unread postby kev1n » Tue Jul 27, 2021 5:45 pm

I prepared a "Notification" demo at https://test.nubuilder.cloud/

To test: Enter a message in the "Notification" form, check "active", save. All users will see a notification until you uncheck "active".

How to set it up:

1. In Setup-> Header, add this JS before the function nuOnLoad() :

Code: Select all
// Polling the server  for notifications
function fetchNotification() {
    nuRunPHPHidden('fetchnotification', 0);
}

setInterval(function() {
    fetchNotification();
}, 5000); // polling interval


2. Add a PHP Procedure fetchnotification

Code: Select all
function getNotificationMessage() {
    $sql = "SELECT `not_message` FROM `notification` WHERE `not_active` = 1";
    $t = nuRunQuery($sql);
    return (db_num_rows($t) != 0) ? db_fetch_row($t) [0] : '';
}

$message = getNotificationMessage();
if ($message != '') {

    $not = nuGetJSONData('NOTIFICATION');
    if ($not == '') {
        $dt = new DateTime();
        nuSetJSONData('NOTIFICATION', $dt->getTimestamp());
        nuDisplayError($message);
    }

}



3. Create a table:

Code: Select all
CREATE TABLE `notification` (
  `notification_id` varchar(25) NOT NULL,
  `not_message` text DEFAULT NULL,
  `not_created_at` datetime DEFAULT current_timestamp(),
  `not_active` varchar(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

ALTER TABLE `notification`
  ADD PRIMARY KEY (`notification_id`);


4. Create the form:

Code: Select all
-- nuBuilder cloner SQL Dump
-- Version 1.21
-- Generation Time: July 27, 2021 10:09:59 AM

-- Form Description: notification
-- Form Code: notification_BE
-- Form Table: notification
-- Form Type: browseedit


--
-- zzzzsys_form: notification_BE
--

INSERT INTO zzzzsys_form (zzzzsys_form_id, sfo_type, sfo_code, sfo_description, sfo_breadcrumb_title, sfo_table, sfo_primary_key, sfo_browse_redirect_form_id, sfo_browse_row_height, sfo_browse_rows_per_page, sfo_browse_title_multiline, sfo_browse_sql, sfo_javascript)
VALUES ( '60ffbf57150269c', 'browseedit', 'notification_BE', 'notification', NULL, 'notification', 'notification_id', NULL, NULL, NULL, '0', 'SELECT * FROM notification', NULL );

--
-- zzzzsys_tab
--

INSERT INTO zzzzsys_tab (zzzzsys_tab_id, syt_zzzzsys_form_id, syt_title, syt_order, syt_help)
VALUES ( '60ffbf571539841', '60ffbf57150269c', 'Main', '10', NULL );

--
-- zzzzsys_browse
--

INSERT INTO zzzzsys_browse (zzzzsys_browse_id, sbr_zzzzsys_form_id, sbr_title, sbr_display, sbr_align, sbr_format, sbr_order, sbr_width)
VALUES ( '60ffbf5715767f7', '60ffbf57150269c', 'Message', 'not_message', 'l', '', '10', '250' );
INSERT INTO zzzzsys_browse (zzzzsys_browse_id, sbr_zzzzsys_form_id, sbr_title, sbr_display, sbr_align, sbr_format, sbr_order, sbr_width)
VALUES ( '60ffbf571577c98', '60ffbf57150269c', 'Created At', 'not_created_at', 'l', '', '20', '250' );

--
-- zzzzsys_object
--

INSERT INTO zzzzsys_object (zzzzsys_object_id, sob_all_zzzzsys_form_id, sob_all_table, sob_all_type, sob_all_id, sob_all_label, sob_all_zzzzsys_tab_id, sob_all_order, sob_all_top, sob_all_left, sob_all_width, sob_all_height, sob_all_cloneable, sob_all_align, sob_all_validate, sob_all_access, sob_all_event, sob_calc_formula, sob_calc_format, sob_run_zzzzsys_form_id, sob_run_filter, sob_run_method, sob_run_target, sob_run_type, sob_run_id, sob_display_sql, sob_select_multiple, sob_select_2, sob_select_sql, sob_lookup_code, sob_lookup_description, sob_lookup_description_width, sob_lookup_autocomplete, sob_lookup_zzzzsys_form_id, sob_lookup_javascript, sob_lookup_php, sob_lookup_table, sob_subform_zzzzsys_form_id, sob_subform_foreign_key, sob_subform_add, sob_subform_delete, sob_subform_type, sob_subform_table, sob_input_count, sob_input_format, sob_input_type, sob_input_javascript, sob_input_datalist, sob_html_code, sob_html_chart_type, sob_html_javascript, sob_html_title, sob_html_vertical_label, sob_html_horizontal_label, sob_image_zzzzsys_file_id)
VALUES ( '60ffbf5715a74ef', '60ffbf57150269c', 'notification', 'textarea', 'not_message', 'Message', '60ffbf571539841', '10', '55', '122', '251', '64', '1', 'left', '0', '0', NULL, '', '', '', '', '', NULL, NULL, '', 'SELECT COUNT(*) FROM zzzzsys_debug', '', '0', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '0', 'N|$ 1,000.00', 'nuScroll', '[\'North\',\'South\',\'East\',\'West\']', NULL, '', '', '', '', '', '', '' );
INSERT INTO zzzzsys_object (zzzzsys_object_id, sob_all_zzzzsys_form_id, sob_all_table, sob_all_type, sob_all_id, sob_all_label, sob_all_zzzzsys_tab_id, sob_all_order, sob_all_top, sob_all_left, sob_all_width, sob_all_height, sob_all_cloneable, sob_all_align, sob_all_validate, sob_all_access, sob_all_event, sob_calc_formula, sob_calc_format, sob_run_zzzzsys_form_id, sob_run_filter, sob_run_method, sob_run_target, sob_run_type, sob_run_id, sob_display_sql, sob_select_multiple, sob_select_2, sob_select_sql, sob_lookup_code, sob_lookup_description, sob_lookup_description_width, sob_lookup_autocomplete, sob_lookup_zzzzsys_form_id, sob_lookup_javascript, sob_lookup_php, sob_lookup_table, sob_subform_zzzzsys_form_id, sob_subform_foreign_key, sob_subform_add, sob_subform_delete, sob_subform_type, sob_subform_table, sob_input_count, sob_input_format, sob_input_type, sob_input_javascript, sob_input_datalist, sob_html_code, sob_html_chart_type, sob_html_javascript, sob_html_title, sob_html_vertical_label, sob_html_horizontal_label, sob_image_zzzzsys_file_id)
VALUES ( '60ffbf5715ab04e', '60ffbf57150269c', 'notification', 'input', 'not_active', 'Active?', '60ffbf571539841', '20', '136', '356', '17', '20', '1', 'left', '0', '0', '0', '', '', '', '', '', '', '', '', 'SELECT COUNT(*) FROM zzzzsys_debug', '0', '0', '', '', '', '', NULL, '', '', NULL, '', '', '', '', '', '', '', '0', '', 'checkbox', '', '', '', '', '', '', '', '', '' );
kev1n
nuBuilder Team
 
Posts: 1996
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Send broadcast message for all users

Unread postby miasoft » Tue Jul 27, 2021 6:59 pm

Thanks! All work fine! Very helpfull feature for me. :)
Wbr, miasoft.
miasoft
 
Posts: 87
Joined: Wed Dec 23, 2020 8:58 pm


Return to General

Who is online

Users browsing this forum: wes862 and 18 guests