37 | if (!defined('AJAX_CHAT_ROOM')) | 38 | if (!defined('AJAX_CHAT_ROOM')) |
38 | { | 39 | { |
39 | $chat_room = request_var('chat_room', ''); | 40 | $chat_room = request_var('chat_room', ''); |
40 | $chat_room = preg_replace('/[^0-9|]+/', '', trim($chat_room)); | 41 | $chat_room = preg_replace('/[^0-9|]+/', '', trim($chat_room)); |
41 | $chat_room_users = array(); | 42 | $chat_room_users = array(); |
42 | $chat_room_users = explode('|', $chat_room); | 43 | $chat_room_users = explode('|', $chat_room); |
43 | $chat_room_sql = " s.shout_room = '" . $chat_room . "' "; | 45 | $chat_room_sql = " s.shout_room = '" . $chat_room . "' "; |
44 | if(($userdata['user_level'] != ADMIN) && !empty($chat_room) && !in_array($userdata['user_id'], $chat_room_users)) | 46 | if(($userdata['user_level'] != ADMIN) && !empty($chat_room) && !in_array($userdata['user_id'], $chat_room_users)) |
45 | { | 47 | { |
46 | message_die(GENERAL_ERROR, $lang['Not_Auth_View']); | 48 | message_die(GENERAL_ERROR, $lang['Not_Auth_View']); |
47 | } | 49 | } |
48 | define('AJAX_CHAT_ROOM', true); | 50 | define('AJAX_CHAT_ROOM', true); |
| | 246 | // Alert other users that somebody is willing to chat with them |
| | 247 | if ($private_chat) |
| | 248 | { |
| | 249 | // It omits users that have been active for the last 5 minutes (300 seconds) |
| | 250 | $sql = "SELECT session_user_id |
| | 251 | FROM " . AJAX_SHOUTBOX_SESSIONS_TABLE . " |
| | 252 | WHERE " . $db->sql_in_set('session_user_id', $chat_room_users) . " |
| | 253 | AND session_time < " . (time() - 300) . " |
| | 254 | ORDER BY session_user_id ASC"; |
| | 255 | $result = $db->sql_query($sql); |
| | 256 | $row = $db->sql_fetchrowset($result); |
| | 257 | $db->sql_freeresult($result); |
| | 258 | |
| | 259 | $alert_users_array = array(); |
| | 260 | foreach ($chat_room_users as $chat_room_user) |
| | 261 | { |
| | 262 | if (($chat_room_user != $userdata['user_id']) && !in_array($chat_room_user, $row)) |
| | 263 | { |
| | 264 | $alert_users_array[] = $chat_room_user; |
| | 265 | } |
| | 266 | } |
| | 267 | |
| | 268 | $sql = "UPDATE " . USERS_TABLE . " SET user_private_chat_alert = '" . $chat_room . "' WHERE " . $db->sql_in_set('user_id',
$alert_users_array); |
| | 269 | $db->sql_query($sql); |
| | 270 | } |
| | 271 | |