Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

message_add()

Parameters

ColumnTypeDefaultDescription
$users
$text
$url ""
$owner null
$notification_type MESSAGE_ENUM_NOTIFICATION_TYPE_SCREEN
$ttl_seconds MESSAGE_DEFAULT_TTL_SECONDS
$related_activity 0
$related_ref 0

Location

include/message_functions.php lines 24 to 84

Definition

 
function message_add($users,$text,$url="",$owner=null,$notification_type=MESSAGE_ENUM_NOTIFICATION_TYPE_SCREEN,$ttl_seconds=MESSAGE_DEFAULT_TTL_SECONDS$related_activity=0$related_ref=0)
    {
    global 
$userref,$applicationname,$lang$baseurl$baseurl_short;
    
    if(!
is_int($notification_type))
        {
        
$notification_type=intval($notification_type); // make sure this in an integer
        
}
    
    
$orig_text=$text;
    
$text escape_check($text);
    
$url escape_check($url);

    if (!
is_array($users))
        {
        
$users=array($users);
        }

    if(
is_null($owner))
        {
        
$owner=$userref;
        }

    if (
is_null($owner))
        {
        
$owner_escaped 'NULL';
        }
    else
        {
        
$owner_escaped "'" escape_check($owner) . "'";
        }

    
sql_query("INSERT INTO `message` (`owner`, `created`, `expires`, `message`, `url`, `related_activity`, `related_ref`) VALUES ({$owner_escaped}, NOW(), DATE_ADD(NOW(), INTERVAL {$ttl_seconds} SECOND), '{$text}', '{$url}', '{$related_activity}', '{$related_ref}' )");
    
$message_ref sql_insert_id();

    foreach(
$users as $user)
        {
        
sql_query("INSERT INTO `user_message` (`user`, `message`) VALUES ($user,$message_ref)");
        
        
// send an email if the user has notifications and emails setting and the message hasn't already been sent via email
        
if(~$notification_type MESSAGE_ENUM_NOTIFICATION_TYPE_EMAIL)
            {
            
get_config_option($user,'email_and_user_notifications'$notifications_always_email);
            if(
$notifications_always_email)
                {
                
$email_to=sql_value("select email value from user where ref={$user}","");
                if(
$email_to!=='')
                    {
                    if(
strpos($url,$baseurl) === false)
                        {
                        
// If a relative link is provided make sure we add the full URL when emailing
                        
$url $baseurl $url;
                        }
                    
$message_text=nl2br($orig_text);
                    
send_mail($email_to,$applicationname ": " $lang['notification_email_subject'],$message_text "<br/><br/><a href='" $url "' >" $url "</a>");
                    }
                }
            }
        }

    }

This article was last updated 7th July 2020 09:35 Europe/London time based on the source file dated 2nd July 2020 09:49 Europe/London time.