<?php

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

if (!empty($_GET['id']) && is_numeric($_GET['id']))
{
	$id = abs(intval($_GET['id']));
	$result = mysql_query("SELECT * FROM `blog` WHERE `id` = '".$id."' LIMIT 1");
	if (mysql_num_rows($result) == true)
	{
		$arr = mysql_fetch_array(mysql_query("SELECT * FROM `blog` WHERE `id` = '".$id."' LIMIT 1"));
	}
	else
	{
		if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `notifications` WHERE `refid` = '".$id."' AND `mod` = 'blog' AND `type` = 'like' AND `from_id` = '".$user_id."' LIMIT 1"),0) == true)
		{
			mysql_query("DELETE FROM `notifications` WHERE `refid` = '".$id."' AND `mod` = 'blog' AND `type` = 'like' AND `from_id` = '".$user_id."' LIMIT 1");
		}

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

if (empty($user_id) or $user_id != $arr['user_id']) {go(URL.'/');}

if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `notifications` WHERE `refid` = '".$arr['id']."' AND `mod` = 'blog' AND `type` = 'like' AND `from_id` = '".$user_id."' LIMIT 1"),0) == true)
{
	mysql_query("DELETE FROM `notifications` WHERE `refid` = '".$arr['id']."' AND `mod` = 'blog' AND `type` = 'like' AND `from_id` = '".$user_id."' LIMIT 1");
}
				
$title = ''.lang('Просмотр вопроса','Перегляд питання').' :: '.lang('Мне нравится','Мені подобається').'';
require_once '../incfiles/head.php';

echo '<div class="title">'.lang('Просмотр вопроса','Перегляд питання').'</div>
	<div class="block2">';

			echo vtime($arr['time']).'<ul><p><div id="text">'.text($arr['text']).'</div></p></ul>';

	echo '<a href="'.URL.'/response/post.php?id='.$id.'"" onclick="Page.Go(this.href); return false;">Назад</a>';

	echo'</div><div class="title">'.lang('Кому понравилось','Кому сподобалось').' <div class="right">'.$arr['clike'].'</div></div>';

			$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blog_like` WHERE `fid` = '".$arr['id']."' LIMIT 1"),0);
			if ($all == true)
			{
				$cp = ceil($all/10);
				$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
				$start = $p*10-10;

				$res = mysql_query("SELECT * FROM `blog_like` WHERE `fid` = '".$arr['id']."' ORDER by `time` DESC LIMIT $start,10");
				while ($array = mysql_fetch_array($res))
				{
					echo '<div class="block2">';
					echo user_name($array['user_id']).'<br/>'.vtime($array['time']);
					echo '</div>';
				}
			}
	
			navi($p,$cp,''.URL.'/response/show_like.php?id='.$arr['id'].'&');

require_once '../incfiles/foot.php';

?>