root/ip/trunk/includes/ajax_shoutbox_inc.php

150161
34
	$action = (!empty($_POST['act'])) ? htmlspecialchars($_POST['act']) : htmlspecialchars($_GET['act']);
34
	$action = (!empty($_POST['act'])) ? htmlspecialchars($_POST['act']) : htmlspecialchars($_GET['act']);
35
}
35
}
36
36
37
$private_chat = false;
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);
44
	$chat_room_users_count = sizeof($chat_room_users);
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);
51
	$private_chat = true;
49
}
52
}
50
53
51
if($action)
54
if($action)
...
...
64
	$error = AJAX_SHOUTBOX_NO_ERROR;
67
	$error = AJAX_SHOUTBOX_NO_ERROR;
65
	$error_msg = '';
68
	$error_msg = '';
66
69
70
	// Delete alert for poster if present
71
	if ($private_chat && !empty($userdata['user_private_chat_alert']))
72
	{
73
		$sql = "UPDATE " . USERS_TABLE . " SET user_private_chat_alert = '0' WHERE user_id = " . $userdata['user_id'];
74
		$db->sql_query($sql);
75
	}
76
67
	// Code for getting data
77
	// Code for getting data
68
	if($action == 'read')
78
	if($action == 'read')
69
	{
79
	{
...
...
233
			}
243
			}
234
		}
244
		}
235
245
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
236
		// Some weird conversion of the data inputed
272
		// Some weird conversion of the data inputed
237
		if($userdata['session_logged_in'])
273
		if($userdata['session_logged_in'])
238
		{
274
		{