/** * Create new room * @param int $category_id Parent category ID * @param string $type Room type * @param string $name Room name * @param string $description Room description * @param string $default_message_color Default message color * @param string $password Password. If not empty, then room will be password-protected. * @param int $background_image Binaryfile-ID of room background image * @return boolean TRUE on success or FALSE on error */ function createRoom($category_id = 0, $type = '', $name = '', $description = '', $default_message_color = '', $password = '', $background_image = 0) { $result = false; if (!empty($category_id) && $name != '') { $this->id = 0; $this->type = $type; $this->date_created = date('Y-m-d H:i:s'); $this->name = $name; $this->category_id = $category_id; $this->description = $description; $this->users_count = 0; $this->default_message_color = $default_message_color; $this->password = $password != '' ? md5($password) : ''; $this->background_image = $background_image; $this->last_ping = date('Y-m-d H:i:s'); $this->listpos = 0; // Calculate listing position if ($this->_db_getList('listpos', 'category_id = ' . $category_id, 'listpos DESC', 1)) { $this->listpos = $this->_db_list[0]['listpos'] + 1; } if ($result = $this->_db_insertObj()) { $this->id = $this->_db_lastInsertID(); } // Update "moderated_rooms" field by category moderators _pcpin_loadClass('category'); $category = new PCPIN_Category($this); $moderators = $category->getModerators($category_id); if (!empty($moderators)) { _pcpin_loadClass('user'); $user = new PCPIN_User($this); foreach ($moderators as $data) { $rooms = array_unique(explode(',', trim($data['moderated_rooms'] . ',' . $this->id, ','))); sort($rooms); $user->_db_updateRow($data['id'], 'id', array('moderated_rooms' => implode(',', $rooms))); } } } return $result; }