Notification functions
Zurück | Kapitel 19. Handling common coding tasks | Weiter

## Notification functions

A user usually expects some feedback from a computer. So if the user created a new entry, deleted something or executed some other function, you might want to output a message indicating success or notifying the user about an error that occurred. This is where the notification comes into play, plus it offers a few more nifty features.

| Anmerkung
This is not intended to create a debugging log of what is happening internally to the module. Have a look at the logging functions for this!

### Using notification in more.groupware

In the settings module, in the general section, are a few notification settings. Some are accessible for all users, some are for admin users only. Those are explained elsewhere in the manual.

You can always trigger notification with one simple function call. The framework knows about several types of messages, namely NOTIFY_SCREEN, NOTIFY_MIM and NOTIFY_MAIL. Those are predefined constants you can use right away.

In appconfig the notification class is initiated and can be reached anywhere using $GLOBALS['notify']. Use the function $GLOBALS['notify']->message() to make use of it. (If you noticed the similarity to the logging function - yes, this is intentional.)

The types of message available are the following: NOTIFY_SCREEN spools a message for direct display on the screen, either below the sub menu or as a JavaScript alert() window (depending on user settings). Those messages will be shown upon next page load, for users not currently logged in those messages are stored and displayed at the next login. If used for the current user, this is perfect for displaying results of user actions.

NOTIFY_MIM sends an instant message to the target user's MIM. This can be used to notify users of new items that have been created or, as in todo and calendar, to inform about delegated items and new appointments.

NOTIFY_MAIL can be used to send a message through email. This does not use the webmail2 module, but uses PHP's mail() function. This may cause problems on some systems, and will eventually be changed.

Beispiel 19.4. Displaying a success message.

    $GLOBALS['notify']->message(NOTIFY_SCREEN, 'Item creation succeeded.');

The example above is the most simple way of using notification. The message will be displayed for the current user upon next page load (in most cases 'right after the call', when $smarty->display() is called).

to be continued...

Zurück | Nach oben | Weiter
Logging functions | Zum Anfang | Database handling