<?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($_GET['id']) && is_numeric($_GET['id']))
{
	$id = abs(intval($_GET['id']));

	$query = mysql_query("SELECT * FROM `blog` WHERE `id` = '".$id."' LIMIT 1");
	if (mysql_num_rows($query) == true)
	{
		$arr = mysql_fetch_array($query);

		$arr_user_id = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$arr['user_id']."' LIMIT 1"));
		if ($arr_user_id['ban'] == 1) {go(URL.'/user/?id='.$arr['user_id']);}

		$comm = check($_POST['comm']);
		$comm = substr($comm, 0, 1000);
		if (empty($comm)) {go(URL.'/response/post.php?id='.$arr['id'].'');}

		// Проверка на флуд
		$flood = time() - 5;
		if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blog_comm` 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 сек.
			<meta http-equiv="refresh" content="5;URL='.URL.'/response/post.php?id='.$arr['id'].'"/></div>';
			require_once('../incfiles/foot.php');
			exit;
		}

		if (mysql_query("INSERT INTO `blog_comm` SET
		`fid` = '".$id."',
		`user_id` = '".$user_id."',
		`text` = '".$comm."',
		`time` = '".time()."'
		") == true)
		{
			mysql_query("UPDATE `blog` SET comm=comm+1 WHERE `id` = '".$id."'");
			mysql_query("UPDATE `users` SET `statts` = `statts` + '0.1' WHERE `id` = '".$user_id."'");

			
					mysql_query("INSERT INTO `notifications` SET
					`user_id` = '".$user_id."',
					`sex` = '".$user['sex']."',
					`for_id` = '".$arr['user_id']."',
					`mod` = 'blog',
					`type` = 'comm',
					`refid` = '".$id."',
					`time` = '".time()."',
					`count` = 1,
					`new` = 1
					");
				
				mysql_query("UPDATE `users` SET `notifications` = 1, notifications_journal=notifications_journal+1 WHERE `id` = '".$arr['user_id']."'");
				//mysql_query("UPDATE `users` SET `statts` = `statts` + '0.1' WHERE `id` = '".$user_id."'");
			}
			go(URL.'/response/post.php?id='.$arr['id'].'');
		}
	}

else
{
	require_once('../incfiles/head.php');
	echo '<div class="title">'.lang('Ошибка','Помилка').'</div><div class="block">'.lang('Запись не найдена','Запис не знайдено').'</div>';
	require_once('../incfiles/foot.php');
	exit;
}

?>