<?php
require_once '../incfiles/core.php';
require_once '../incfiles/func.php';
require_once '../incfiles/auth.php';
require_once '../incfiles/user.php';

if (empty($user_id)) {go(URL.'/');}

if (!empty($_POST['text']))
{
	// Проверка на флуд
	$flood = time() - 5;
	if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blog` WHERE `time` > '".$flood."' AND `user_id` = '".$user_id."' LIMIT 1"),0) == true)
	{
		require_once('../incfiles/head.php');
		echo '<div class="title">Антифлуд</div><div class="block">'.lang('Вы не можете так часто писать','Ви не можете так часто задавати питання').'.<br />'.lang('Подождите 5','Почекайте 5 ').' сек.
		<meta http-equiv="refresh" content="5;URL='.URL.'/response/new.php"/></div>';
		require_once('../incfiles/foot.php');
		exit;
	}

	$text = check($_POST['text']);
	$text = substr($text, 0, 10000);
	if (empty($text)) $err = true;
	
	if($err == false && mysql_query("INSERT INTO `blog` SET
	`user_id` = '".$user_id."',
	`text` = '".$text."',
	`time` = '".time()."'
	") == true)
	{
		mysql_query("UPDATE `users` SET count_blog=count_blog+1 WHERE `id` = '".$user_id."'");
		mysql_query("UPDATE `users` SET `statts` = `statts` + '0.1' WHERE `id` = '".$user_id."'");

		$arr_blog = mysql_fetch_array(mysql_query("SELECT * FROM `blog` WHERE `user_id` = '".$user_id."' ORDER by `time` DESC LIMIT 1"));

			mysql_query("INSERT INTO `feed` SET
			`user_id` = '".$user_id."',
			`mod` = 'blog',
			`type` = 'new_post',
			`refid` = '".$arr_blog['id']."',
			`time` = '".time()."',
			`uptime` = '".time()."'
			");
	}
}

go(URL.'/response/?id='.$user_id.'');


?>