* @param array $clan_ids the ids of clans that are allowed to read and write in this chatroom
* @param string $foreign_identifier something like "cf_12345" or "clan_1234"
* return identifier
*/
function createChatRoom(array $clan_ids, $foreign_identifier) {
db_query('INSERT INTO clan_chatrooms(foreign_id) values(\''.$foreign_identifier.'\')');
if(mysql_affected_rows() == 0) {
return 'Konnte den Clanchatroom nicht erstellen, da er schon exisitert!';
}
$chat_id = getClanChatId($foreign_identifier);
foreach ($clan_ids as $clan_id) {
db_query('INSERT INTO clan_chatroom_clans(clan_chat_id, clan_id) values(\''.$chat_id.'\', \''.$clan_id.'\')');
}
return $chat_id;
}
/**
* this method returns the clanChatId using the foreign identifier!!
* @param string $foreign_identifier
*/
function getClanChatId($foreign_identifier) {
$row = mysql_fetch_row(db_query('SELECT clan_chat_id FROM clan_chatrooms WHERE foreign_id = \''.$foreign_identifier.'\''));
return $row[0];
}
function checkAccessRights($user_id, $clan_chat_id) {
if($user_id == NULL) {
return false;
}
$qry = db_query('SELECT clan_chat_id FROM clan_chatroom_clans cc INNER JOIN user u ON cc.clan_id = u.clan WHERE cc.clan_chat_id = ' . $clan_chat_id . ' and u.id = ' .$user_id);
if(!$qry) {
return false;
}
return mysql_num_rows($qry);
}
function sendClanChatMessage($user_id, $clan_chat_id, $message) {
if(checkAccessRights($user_id, $clan_chat_id)) {
$user = getUser($user_id);
while(true) {
$qry = db_query('SELECT IFNULL(max(msg_id),0) + 1 FROM clan_chatroom_messages WHERE clan_chat_id = ' .$clan_chat_id);