// Attachments?
 _pcpin_loadClass('tmpdata');
 $tmpdata = new PCPIN_TmpData($session);
 $tmpdata->_db_getList('user_id = ' . $current_user->id, 'type = 3');
 $tmpdata_list = $tmpdata->_db_list;
 $tmpdata->_db_freeList();
 if (!empty($tmpdata_list)) {
     $tmpdata->deleteUserRecords($current_user->id, 3, 0, true);
 }
 $data['body'] = trim($data['body']);
 if ($data['body'] != '' || !empty($tmpdata_list)) {
     $type = isset($data['type']) ? $data['type'] : 0;
     $offline = isset($data['offline']) ? $data['offline'] : 'n';
     $target_room_id = isset($data['target_room_id']) ? $data['target_room_id'] : $session->_s_room_id;
     $target_user_id = isset($data['target_user_id']) ? $data['target_user_id'] : 0;
     $body = _pcpin_substr($data['body'], 0, $session->_conf_all['message_length_max']);
     $privacy = isset($data['privacy']) ? $data['privacy'] : 0;
     $css_properties = isset($data['css_properties']) ? $data['css_properties'] : '';
     // Initial state: User must be not global muted
     $message_ok = $current_user->global_muted_until < date('Y-m-d H:i:s') && $current_user->global_muted_permanently == 'n';
     if (empty($type)) {
         $message_ok = false;
         continue;
     }
     // Check target room
     if (!empty($target_room_id)) {
         if ($session->_s_room_id != $target_room_id) {
             // A message to another room
             if ($privacy == 2 && $target_user_id > 0 && $current_user->is_admin !== 'y' && false === strpos(',' . $current_user->moderated_rooms . ',', ',' . $target_room_id . ',')) {
                 // TODO (ignoring...)
                 $message_ok = false;
 /**
  * Generate random string from pattern
  * @param   int       $length     Desired string length
  * @param   string    $pattern    Pattern to use
  * @param   boolean   $binary     Optional. If TRUE, then the pattern is a binary string and will be handled byte-by-byte.
  * @return  string    Generated random string
  */
 function randomString($length = 0, $pattern = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', $binary = false)
 {
     $out = '';
     if ($length > 0 && $pattern != '') {
         if (!$binary) {
             // Pattern is a text string
             $pattern_length_minus_one = strlen($pattern) - 1;
             for ($i = 0; $i < $length; $i++) {
                 $out .= substr($pattern, mt_rand(0, $pattern_length_minus_one), 1);
             }
         } else {
             // Pattern is a binary string
             $pattern_length_minus_one = _pcpin_strlen($pattern) - 1;
             for ($i = 0; $i < $length; $i++) {
                 $out .= _pcpin_substr($pattern, mt_rand(0, $pattern_length_minus_one), 1);
             }
         }
     }
     return $out;
 }
$msg = new PCPIN_Message($session);
if (empty($profile_user_id) || $profile_user_id != $current_user->id && $current_user->is_admin !== 'y') {
    $profile_user_id = $current_user->id;
}
if ($profile_user_id != $current_user->id) {
    $profile_user = new PCPIN_User($session);
    $profile_user->_db_loadObj($profile_user_id);
} else {
    $profile_user =& $current_user;
}
$activation_required = '';
if (!empty($profile_user_id)) {
    if (!isset($email) || !is_scalar($email)) {
        $email = '';
    } else {
        $email = _pcpin_substr(trim($email), 0, 255);
    }
    if (!PCPIN_Common::checkEmail($email, $session->_conf_all['email_validation_level'])) {
        // Email invalid
        $xmlwriter->setHeaderStatus(1);
        $xmlwriter->setHeaderMessage($l->g('email_invalid'));
    } else {
        if (!$current_user->checkEmailUnique($profile_user_id, $email)) {
            // Email address already taken
            $xmlwriter->setHeaderStatus(1);
            $xmlwriter->setHeaderMessage($l->g('email_already_taken'));
        } else {
            // Email address is free
            if ($current_user->is_admin !== 'y' && !empty($session->_conf_all['activate_new_emails'])) {
                // Email address needs to be activated
                $activation_required = 1;
 /**
  * Add new IP address into the database
  * @param   string    $type         IP address type (IPv4 or IPv6)
  * @param   string    $ip           IP address
  * @param   string    $expires      Expiration date (MySQL DATETIME). Empty value means no expiration.
  * @param   string    $description  Description
  * @param   string    $action       Record type (allow/deny)
  * @return  boolean   TRUE on success or FALSE on error
  */
 function addAddress($type = '', $ip = '', $expires = '', $description = '', $action = 'd')
 {
     $this->id = 0;
     $this->type = $type;
     $this->address = $ip;
     $this->added_on = date('Y-m-d H:i:s');
     $this->expires = $expires == '' ? '0000-00-00 00:00:00' : $expires;
     $this->description = _pcpin_substr(trim($description), 0, 255);
     $this->action = $action;
     if ($result = $this->_db_insertObj()) {
         $this->id = $this->_db_lastInsertID();
     }
     return $result;
 }