Originally written by Mark Evans at www.gllabs.org
Some of you may have noticed that I have a little box that appears on the main index page when you have a new Private Message. Here is how I implemented it.
I created a static page with the following function call (you need to turn on PHP for static pages for this to work).
echo phpblock_checkpm();
I then checked the Centerblock checkbox for the static page.
Then in lib-custom.php I put the following function:
function phpblock_checkpm() {
global $_TABLES, $CONF_MSG, $_USER, $_CONF,$_IMAGE_TYPE;
$retval = '';
if ( !empty($_USER['username'] )) {
if (!$CONF_MSG['RestrictedAccess'] OR SEC_hasRights('messenger.user') ) {
// Check and see if user wants to view Broadcast messages - if not exclude them
if (DB_getItem($_TABLES['messenger_userinfo'],"broadcasts", "uid={$_USER['uid']}") == '1') {
$sql = DB_query("SELECT count(*) as count FROM {$_TABLES['messenger_dist']} dist LEFT JOIN {$_TABLES['messenger_msg']} msg ON
dist.msg_id=msg.id WHERE (target_uid = {$_USER['uid']} AND read_date is NULL) ");
} else {
$sql = DB_query("SELECT count(*) as count FROM {$_TABLES['messenger_dist']} dist LEFT JOIN {$_TABLES['messenger_msg']} msg ON
dist.msg_id=msg.id WHERE (target_uid = {$_USER['uid']} AND read_date is NULL) OR (target_uid = '0' AND archive='0')");
}
list($count) = DB_fetchArray($sql);
if ($count > 0) {
$timestamp = strftime( $_CONF['daytime'] );
$retval .= COM_startBlock( 'New Private Message' . ' - ' . $timestamp, '',
COM_getBlockTemplate( '_msg_block', 'header' ))
. '<p style="padding:5px"><img src="' . $_CONF['layout_url']
. '/images/sysmessage.' . $_IMAGE_TYPE . '" border="0" align="left"'
. ' alt="" style="padding-right:5px; padding-bottom:3px">'
. 'You have ' . $count . ' unread <a href="/messenger/index.php">Private Messages</a>' . '</p>'
. COM_endBlock( COM_getBlockTemplate( '_msg_block', 'footer' ));
} else {
$retval = '';
}
}
}
return $retval;
}
Pretty simple. Hope you find this useful.