*
 *    "PCPIN Chat 6" is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    "PCPIN Chat 6" is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
_pcpin_loadClass('message');
$msg = new PCPIN_Message($session);
if (!isset($target_user_id) || !is_scalar($target_user_id)) {
    $target_user_id = 0;
}
if (!empty($current_user->id) && $current_user->is_admin === 'y' && $session->_s_user_id == $current_user->id) {
    $xmlwriter->setHeaderStatus(1);
    if (!empty($target_user_id) && $current_user->_db_getList('banned_permanently,banned_until', 'id = ' . $target_user_id, 1)) {
        // User exists
        $xmlwriter->setHeaderStatus(0);
        $xmlwriter->setHeaderMessage('OK');
        if ($current_user->_db_list[0]['banned_permanently'] == 'y' || $current_user->_db_list[0]['banned_until'] > date('Y-m-d H:i:s')) {
            // Add new message
            $msg->addMessage(10107, 'n', $current_user->id, $current_nickname, 0, 0, $target_user_id . '/' . $current_user->id, date('Y-m-d H:i:s'), 0, '');
            // Unban user
            $current_user->banUnban($target_user_id, 0);
        }
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Get current chat state
 * @param   int       $room_id              ID of the room where the request was sent from
 * @param   boolean   $first_request        If TRUE, then full room information and full userlist will be returned,
 *                                          returned messages count will be limited by 'init_display_messages_count'
 * @param   boolean   $full_request         If TRUE, then full room information and full userlist will be returned
 * @param   int       $get_last_msgs        If > 0, then last X messages will be returned (including already delivered messages)
 * @param   boolean   $pref_timestamp       Optional. Current state of client's "Display message timestamp" preference
 * @param   boolean   $pref_allow_sounds    Optional. Current state of client's "Allow sounds" preference
 * @param   boolean   $pref_message_color   Optional. Current message color
 */
_pcpin_loadClass('message');
$msg = new PCPIN_Message($session);
_pcpin_loadClass('category');
$category = new PCPIN_Category($session);
_pcpin_loadClass('nickname');
$nickname = new PCPIN_Nickname($session);
_pcpin_loadClass('room');
$room = new PCPIN_Room($session);
_pcpin_loadClass('invitation');
$invitation = new PCPIN_Invitation($session);
_pcpin_loadClass('avatar');
$avatar = new PCPIN_Avatar($session);
_pcpin_loadClass('badword');
$badword = new PCPIN_Badword($session);
_pcpin_loadClass('banner');
$banner = new PCPIN_Banner($session);
$default_nicknames = array();
            }
        }
    }
}
if (empty($preselect_language)) {
    $preselect_language = $session->_conf_all['default_language'];
}
$l->setLanguage($preselect_language);
$message = $l->g('access_denied');
if (!isset($activation_code) || !is_scalar($activation_code)) {
    $activation_code = '';
}
_pcpin_loadClass('user');
$user = new PCPIN_User($session);
_pcpin_loadClass('message');
$msg = new PCPIN_Message($session);
_pcpin_loadClass('pcpintpl');
$tpl = new PcpinTpl();
$tpl->setBasedir('./tpl');
$tpl->readTemplatesFromFile('./dummy.tpl');
if ($activation_code != '') {
    if (isset($activate_email)) {
        // New email address activation
        if ($user->_db_getList('email_new != ', 'email_new_activation_code = ' . md5($activation_code), 1)) {
            // Requested email address found and activation code is OK
            $user->_db_setObject($user->_db_list[0]);
            $user->email = $user->email_new;
            $user->email_new = '';
            $user->email_new_date = '';
            $user->email_new_activation_code = '';
            $user->_db_updateObj($user->id);
 *
 *    "PCPIN Chat 6" is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    "PCPIN Chat 6" is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
_pcpin_loadClass('message');
$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);
 *
 *    "PCPIN Chat 6" is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    "PCPIN Chat 6" is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
_pcpin_loadClass('message');
$msg = new PCPIN_Message($session);
if (!isset($target_user_id) || !is_scalar($target_user_id)) {
    $target_user_id = 0;
}
if (!isset($reason) || !is_scalar($reason)) {
    $reason = '';
} else {
    $reason = trim($reason);
}
if (!empty($current_user->id)) {
    $xmlwriter->setHeaderStatus(1);
    if (!empty($target_user_id) && $current_user->_db_getList('is_admin,moderated_rooms', 'id = ' . $target_user_id, 1)) {
        // User exists
        if ($session->_db_getList('_s_ip,_s_id,_s_room_id', '_s_user_id = ' . $target_user_id, 1)) {
            // User is online
            $tgt_session_id = $session->_db_list[0]['_s_id'];
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
$room_id = 0;
_pcpin_loadClass('category');
$category = new PCPIN_Category($session);
_pcpin_loadClass('tmpdata');
$tmpdata = new PCPIN_TmpData($session);
_pcpin_loadClass('room');
$room = new PCPIN_Room($session);
_pcpin_loadClass('message');
$msg = new PCPIN_Message($session);
_pcpin_loadClass('binaryfile');
$binaryfile = new PCPIN_BinaryFile($session);
$errortext = array();
if (!isset($name)) {
    $name = '';
}
if (!isset($description)) {
    $description = '';
}
if (!isset($password) || !is_scalar($password)) {
    $password = '';
}
if (!empty($current_user->id) && !empty($category_id) && is_scalar($category_id)) {
    if (!$category->_db_getList('name, creatable_rooms', 'id = ' . $category_id, 1)) {
        // Category does not exists
 /**
  * Set new online status
  * @param   int     $status       New online status
  * @param   string  $status_msg   New online status message
  * @return  boolean TRUE on success or FALSE on error
  */
 function _s_setOnlineStatus($status = 0, $status_msg = '')
 {
     if (!empty($this->_s_id) && !empty($status) && is_scalar($status)) {
         $status_msg = trim($status_msg);
         // Update session
         $this->_s_updateSession($this->_s_id, true, true, null, null, null, null, null, null, null, null, null, $status, $status_msg);
         // Insert new system message (only if user in a room)
         if (!empty($this->_s_room_id)) {
             _pcpin_loadClass('message');
             $message = new PCPIN_Message($this);
             $message->addMessage(102, 'n', 0, '', $this->_s_room_id, 0, $this->_s_user_id . '/' . $status . '/' . $status_msg);
         }
     }
 }
 *
 *    "PCPIN Chat 6" is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * @param   string    $abuse_nickname
 * @param   string    $abuse_category
 * @param   string    $abuse_description
 */
_pcpin_loadClass('message');
$msg = new PCPIN_Message($session);
_pcpin_loadClass('room');
$room = new PCPIN_Room($session);
if (!isset($abuse_nickname)) {
    $abuse_nickname = '-';
}
if (!isset($abuse_category)) {
    $abuse_category = 0;
}
if (!isset($abuse_description)) {
    $abuse_description = '';
}
if (!empty($current_user->id)) {
    // Get moderators
    if (empty($session->_s_room_id)) {
        // User is not in room
if (!isset($target_user_id) || !is_scalar($target_user_id)) {
    $target_user_id = 0;
}
if (!isset($action)) {
    $action = 0;
}
if (empty($post_control_message)) {
    $post_control_message = false;
}
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) {
    $action_user = new PCPIN_User($session);
    $action_user->_db_loadObj($profile_user_id);
} else {
    $action_user =& $current_user;
}
if (!empty($action_user->id)) {
    $xmlwriter->setHeaderMessage('OK');
    $xmlwriter->setHeaderStatus(0);
    if (!empty($target_user_id) && ($action == 1 || $action == 0)) {
        $action_user->muteUnmuteLocally($target_user_id, $action);
        if (!empty($post_control_message)) {
            _pcpin_loadClass('message');
            $message = new PCPIN_Message($session);
            $message->addMessage(10200, 'n', $current_user->id, $current_nickname, 0, $action_user->id, $action_user->id, '', 1, '');
        }
    }
}
$xmlwriter->setData(array('muted_users' => $action_user->muted_users));
 /**
  * Delete user
  * @param   int   $user_id    User ID
  * @return  boolean   TRUE on success or FALSE on error
  */
 function deleteUser($user_id)
 {
     $result = false;
     if (!empty($user_id) && $this->_db_getList('id', 'id = ' . $user_id, 1)) {
         // Delete user
         if ($result = $this->_db_deleteRow($user_id)) {
             // Delete all avatars owned by user
             _pcpin_loadClass('avatar');
             $avatar = new PCPIN_Avatar($this);
             $avatar->deleteAvatar($user_id);
             // Delete all nicknames owned by user
             _pcpin_loadClass('nickname');
             $nickname = new PCPIN_Nickname($this);
             $nickname->deleteAllNickname($user_id);
             // Delete all messages sent TO this user
             _pcpin_loadClass('message');
             $message = new PCPIN_Message($this);
             if ($message->_db_getList('id', 'target_user_id = ' . $user_id)) {
                 $message_ids = array();
                 foreach ($message->_db_list as $data) {
                     $message_ids[] = $data['id'];
                 }
                 $message->_db_freeList();
                 $message->deleteMessages($message_ids);
             }
             // Delete userdata
             _pcpin_loadClass('userdata');
             $userdata = new PCPIN_UserData($this);
             $userdata->deleteUserData($user_id);
             // Update all users who ignored deleted user
             if ($res = $this->_db_query($this->_db_makeQuery(2050, $user_id))) {
                 $this->_db_freeResult($res);
             }
         }
     }
     return $result;
 }
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
if (!isset($recursion)) {
    $recursion = 1;
}
$invitations_arrived = 0;
$messages_arrived = 0;
$categories_tree = array();
if (!empty($current_user->id)) {
    $xmlwriter->setHeaderMessage('OK');
    $xmlwriter->setHeaderStatus(0);
    // Get room structure
    _pcpin_loadClass('category');
    $category = new PCPIN_Category($session);
    $categories_tree = $category->getTree($current_user->id, 0, !empty($recursion));
    // Are there any invitations or abuse reports?
    if (!empty($current_user->id)) {
        _pcpin_loadClass('invitation');
        $invitation = new PCPIN_Invitation($session);
        $invitations = $invitation->getNewInvitations($current_user->id, true);
        $invitations_arrived = !empty($invitations) ? 1 : 0;
        unset($invitations);
        _pcpin_loadClass('message');
        $msg = new PCPIN_Message($session);
        $messages = $msg->getNewMessages($session->_s_user_id);
        if (!empty($messages)) {
            $messages_arrived = 1;
        }
    }
}
$xmlwriter->setData(array('category' => !empty($categories_tree) ? $categories_tree[0] : array(), 'additional_data' => array('new_invitations' => $invitations_arrived, 'new_messages' => $messages_arrived)));
 *    (at your option) any later version.
 *
 *    "PCPIN Chat 6" is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * This file returns new messages for the user.
 * This file can be called from offside of chat room.
 */
_pcpin_loadClass('message');
$msg = new PCPIN_Message($session);
_pcpin_loadClass('room');
$room = new PCPIN_Room($session);
$abuses_xml = array();
if (!empty($current_user->id)) {
    $xmlwriter->setHeaderMessage('OK');
    $xmlwriter->setHeaderStatus(0);
    $messages = $msg->getNewMessages($current_user->id);
    $last_message_id = $session->_s_last_message_id;
    foreach ($messages as $message_data) {
        $last_message_id = $last_message_id < $message_data['id'] ? $message_data['id'] : $last_message_id;
        if ($message_data['type'] == 4001) {
            $msg_parts = explode('/', $message_data['body'], 5);
            if ($room->_db_getList('name', 'id = ' . $msg_parts[1], 1)) {
                $room_name = $room->_db_list[0]['name'];
                $room->_db_freeList();
 *
 *    "PCPIN Chat 6" is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    "PCPIN Chat 6" is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
_pcpin_loadClass('message');
$msg = new PCPIN_Message($session);
_pcpin_loadClass('ipfilter');
$ipfilter = new PCPIN_IPFilter($session);
_pcpin_loadClass('failed_login');
$failed_login_class = new PCPIN_Failed_Login($session);
if (!isset($login) || !is_scalar($login)) {
    $login = '';
}
if (!isset($password) || !is_scalar($password)) {
    $password = '';
}
if (!isset($time_zone_offset) || !is_scalar($time_zone_offset)) {
    $time_zone_offset = date('Z');
}
if (!isset($language_id) || !is_scalar($language_id)) {
    $language_id = 0;
 /**
  * Put user into/out of a room
  * @param   int       $user_id          User ID
  * @param   int       $target_room_id   ID of room where to put user into
  * @param   boolean   $skip_msg         If TRUE, then system message 115 will be NOT inserted
  * @param   string    $stealth_mode     "Stealth" mode flag ("y"/"n")
  * @return  boolean TRUE on success or FALSE on error
  */
 function putUser($user_id = 0, $target_room_id = 0, $skip_msg = false, $stealth_mode = 'n')
 {
     $ok = false;
     _pcpin_loadClass('message');
     $message = new PCPIN_Message($this);
     _pcpin_loadClass('session');
     $session = new PCPIN_Session($this, '', true);
     // Get user's session
     if (!empty($user_id) && $session->_db_getList('_s_user_id = ' . $user_id, 1)) {
         // Session exists
         if ($target_room_id != $session->_db_list[0]['_s_room_id']) {
             if (!empty($session->_db_list[0]['_s_room_id'])) {
                 // Put user out of a room
                 $ok = true;
                 if ($this->_db_getList('users_count', 'id = ' . $session->_db_list[0]['_s_room_id'], 1)) {
                     $this->updateRoom($session->_db_list[0]['_s_room_id'], false, true, null, null, null, null, $this->_db_list[0]['users_count'] - 1, null, null, null, date('Y-m-d H:i:s'));
                 }
                 if (true !== $skip_msg) {
                     $message->addMessage(115, 'n', 0, '', $session->_db_list[0]['_s_room_id'], 0, $user_id . '/' . $session->_db_list[0]['_s_room_id']);
                 }
             }
             if (!empty($target_room_id)) {
                 // Put user into a room
                 if ($this->_db_getList('users_count', 'id = ' . $target_room_id, 1)) {
                     $ok = true;
                     $this->updateRoom($target_room_id, false, true, null, null, null, null, $this->_db_list[0]['users_count'] + 1, null, null, null, date('Y-m-d H:i:s'));
                 } else {
                     // Room does not exists
                     $target_room_id = 0;
                 }
                 if (true !== $skip_msg) {
                     $message->addMessage(111, 'n', 0, '', $target_room_id, 0, $user_id . '/' . $target_room_id);
                 }
             }
             // Update session
             $session->_s_updateSession($session->_db_list[0]['_s_id'], false, true, null, null, $target_room_id, null, null, null, null, !empty($target_room_id) ? date('Y-m-d H:i:s') : '', null, null, null, $stealth_mode, null, null, '0000-00-00 00:00:00', '');
             if ($session->_db_list[0]['_s_online_status'] != 1) {
                 $session->_db_setObject($session->_db_list[0]);
                 $session->_s_setOnlineStatus(1);
             }
         } else {
             $ok = true;
         }
         // Delete temporary message attachments
         _pcpin_loadClass('tmpdata');
         $tmpdata = new PCPIN_TmpData($this);
         $tmpdata->deleteUserRecords($user_id, 3);
     }
     return $ok;
 }