<?php

if (!empty($_POST['msg']))
{	
	$msg = check($_POST['msg']);
	$msg = substr($msg, 0, 1000);
	if (empty($msg)) go(URL.'/chat/');

	if (!empty($_POST['reuser']) && is_numeric($_POST['reuser']))
	{
		$for_id = abs(intval($_POST['reuser']));
		$msg = user_name3(abs(intval($_POST['reuser']))).', '.$msg;
	} else $for_id = '';
	
	if (mysql_query("INSERT INTO `chat` SET
	`user_id` = '".$user_id."',
	`for_id` = '".$for_id."',
	`msg` = '".$msg."',
	`time` = '".time()."'
	") == true) {}
	mysql_query("UPDATE `users` SET `notifications` = 1, notifications_journal=notifications_journal+1 WHERE `id` = '".$arr_msg['for_id']."'");
			if ($user_id != $arr_post['user_id'])
			{
				mysql_query("INSERT INTO `notifications` SET
				`from_id` = '".$user_id."',
				`sex` = '".$user['sex']."',
				`for_id` = '".$arr_post['user_id']."',
				`mod` = 'chat',
				`type` = 'comm',
				`refid` = '".$arr_post['id']."',
				`time` = '".time()."',
				`count` = 1,
				`new` = 1
				");
			
				mysql_query("UPDATE `users` SET `notifications` = 1, notifications_journal=notifications_journal+1 WHERE `id` = '".$arr_msg['for_id']."'");
				mysql_query("UPDATE `users` SET `statts` = `statts` + '0.1' WHERE `id` = '".$user_id."'");
			}

}


?>