Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > Notification API

Notification API: addNotification

Scroll Prev Next More

 

Adds notification for one or all users.

Syntax

addNotification( $message, $title = null, $icon = null, $url = null, $expire = null, $permissions = null, $newWindow = false )

Arguments

$message

notification text

$title

optional notification title

$icon

optional icon, can be in one of three formats:

- URL: "https://website.com/images/image.png" or "images/file.gif"

- Bootstrap icon: "glyphicon-film", "glyphicon-hand-right"

The full list of available Bootstrap icons.

- Font Awesome icon: "fa-envelope", "fa-user"

The full list of available Font Awesome icons.

$url

optional URL. When specified, a click on notification sends the user to the specified address. See makePageLink function

$expire

optional expiration date and time for the message. Can be either datetime in "YYYY-MM-DD hh:mm:ss" format, or a number of minutes the notification should be visible.

Examples:

"2022-01-10 00:00:00" or 1440 for 24-hour period

$permissions

Optional, null by default. Can be one of the following:
 
- not specified or null - all users will see this notification

- string i.e. "admin". The value is interpreted as a username. Only the specified user will see the notification.

- array with keys "user" and optional value "provider"

  $permissions["user"] - username. Only this user will see the notification.

  $permissions["provider"] - when the user is a database user, whose username and password are stored in a database table, this parameter must be empty. When the user is logged via from Active Directory, OpenID,    Google etc, then put the two-letter security provider code here. You can find it on the 'Security screen' under the provider settings dialog.

- array with key "group"

 $permissions["group"] - only members of this group will see the notification

- array with keys "table" and "page"

 $permissions["table"] - name of the table, custom view, report or chart name.

 $permissions["page"] - page name like "list", "list1" etc.

 When this type of permissions is specified, only those users who have access to the specified page will see the notification.

 

$newWindow

Optional, false by default. When true, the notification link will be open in a new browser tab. When false, the link will be open in the same browser tab.

Return value

No return value

Example 1

This example shows how to add a notification for all users when a new record added to the Categories table. This code needs to be added to AfterAdd event of the Categories table.

 

addNotification( "New category added: ".$values["CategoryName"] , "New category", "fa-envelope", makePageLink( "categories", "view", $keys) );  

Example 2

Add notification with with link opened in new window.

 

 

addNotification( "It's time to check your mail", "Mail check", "glyphicon-envelope", "https://mail.google.com", null, null, true );

Example 3

 

Add notification visible only to 'bob' user.

 

 

addNotification( "Wake up, Bob", "Morning", null, null, null, "bob", true );

Example 4

Add notification visible only to 'Administrator' user from Active Directory

 

$permissions = array(
"user" => "Administrator",
"provider" => "ad"
);
addNotification( "Good night, Admin", "Night", null, null, null, $permissions, true );

Example 5

Add notification visible only to users who have access to Orders - Edit page

 

 

$permissions = array(
"table" => "orders",
"page" => "edit"
);
addNotification( "Update your orders, guys", "Order", null, null, "orders_list.php", $permissions, true );

Example 6

Add notification visible only to users in specific group.
 

 

$permissions = array(
"group" => "<Admin>"
);
addNotification( "Let's have a coffee break", "Admins only", null, null, null, $permissions, true );

See also:

About Notification API

Function createNotification

Function makePageLink

Created with Help+Manual 7 and styled with Premium Pack Version 3 © by EC Software