<?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_blog = mysql_fetch_array(mysql_query("SELECT * FROM `blog` WHERE `id` = '".$id."' LIMIT 1"));
		$arr_user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$arr_blog['user_id']."' LIMIT 1"));
	}
	else
	{
		go(URL.'/');
	}
}
else
{
	go(URL.'/');
}

$title = $arr_user['name'].' '.$arr_user['surname'].' :: '.lang('Просмотр вопроса','Перегляд питання');
require_once '../incfiles/head.php';

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

	if ($user_id == $arr_user['id'])
	{
		if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `notifications` WHERE `refid` = '".$arr_blog['id']."' AND `mod` = 'blog' AND `type` = 'comm' AND `for_id` = '".$user_id."' LIMIT 1"),0) == true)
		{
			mysql_query("UPDATE FROM `notifications` WHERE `refid` = '".$arr_blog['id']."' AND `mod` = 'blog' AND `type` = 'comm' AND `for_id` = '".$user_id."' LIMIT 1");
		}
	}
echo user_name($arr_blog['user_id']).'<br/>'.vtime($arr_blog['time']).'<p><div id="text">'.text(smiles(hastag(links($arr_blog['text'])))).'</div></p>';



	echo '</div><div class="block">';
			if (!empty($user_id))
			{
				if ($user_id != $arr_user['id'])
				{
					if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blog_like` WHERE `fid` = '".$arr_blog['id']."' AND `user_id` = '".$user_id."'"),0) == false)
					{
						echo '<div id="count_like"><img src="'.URL.'/design/img/like.png"/> <a class="like" href="'.URL.'/response/like.php?id='.$arr_blog['id'].'">'.lang('Мне нравится','Мені подобається').'</a> <b>'.$arr_blog['clike'].'</b></div>';
					}
					else
					{
						echo '<div id="count_like"><img src="'.URL.'/design/img/like_ok.png"/> <b>'.$arr_blog['clike'].'</b></div>';
					}
				}
				else
				{

					echo '<img src="'.URL.'/design/img/like.png"/> <a href="'.URL.'/response/show_like.php?id='.$arr_blog['id'].'"" onclick="Page.Go(this.href); return false;">'.lang('Мне нравится','Мені подобається').'</a> <b>'.$arr_blog['clike'].'</b>';
				}
			}
			else
			{
				echo '<div id="count_like"><img src="'.URL.'/design/img/like.png"/> <b>'.$arr_blog['clike'].'</b></div>';
			}
		
			
			
		
			echo '</div>';
?>
<script>
$('a.like').click(function (){ 
var href = $(this).attr('href'); 
$('#count_like').load(href); 
return false; 
});
</script>
<?
			if (!empty($user_id) && $user_id == $arr_user['id'])
			{ 
				echo '<div class="block2">
				<a href="'.URL.'/response/edit.php?id='.$arr_blog['id'].'"" onclick="Page.Go(this.href); return false;">'.lang('Редактировать вопрос','Редагувати запитання').'</a>
				</div>';
			}
			echo '<div class="title">'.lang('Коментарии','Коментарі').' <div class="right">'.$arr_blog['comm'].'</div></div>';
?>
<script type="text/javascript">
$(function(){
	$('#form').on('submit', function(e){
	$('#form_content').html('');
	Page.Loading('start');
    e.preventDefault();
    var $that = $(this),
        formData = new FormData($that.get(0));
    $.ajax({
      url: $that.attr('action'),
      type: $that.attr('method'),
      contentType: false,
      processData: false,
      data: formData,
      success: function(response){
        if(response){
 			Page.Go($that.attr('action'));
       }
     }
    });
  });
});
</script>
<?

			if (!empty($user_id))
			{
				echo '<div class="block">

				<form id="form" action="'.URL.'/response/new_comm.php?id='.$arr_blog['id'].'" method="post">
				<textarea id="textarea" class="input" name="comm"></textarea>
				
				<input class="button2" type="submit" value="'.lang('Отправить','Надіслати').'"/>
				</form>
				
			</div>';
				
				
				
			}

		
			$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blog_comm` WHERE `fid` = '".$arr_blog['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;

				$arr_comm = mysql_query("SELECT * FROM `blog_comm` WHERE `fid` = '".$arr_blog['id']."' ORDER by `time` DESC LIMIT $start,10");
				while ($arr = mysql_fetch_array($arr_comm))
				{
					echo '<div class="block2">';
					if (!empty($user_id) && $user_id == $arr_user['id'] or !empty($user_id) && $user_id == $arr['user_id']) echo '<div class="right"><a href="'.URL.'/response/del_comm.php?id='.$arr['id'].'"" onclick="Page.Go(this.href); return false;"><img src="'.URL.'/design/img/closed.png"/></a></div>';
					echo user_name($arr['user_id']).'<br/>'.vtime($arr['time']).'<ul>';
					if (!empty($arr['quote_id'])) echo '<div class="quote">'.user_name($arr['quote_id']).' '.lang('пишет','пише').':<ul>'.$arr['quote'].'</ul></div>';
					echo text($arr['text']).'</ul>';
   if (!empty($user_id) && $user_id != $arr['user_id']) echo '<a href="'.URL.'/response/re_comm.php?id='.$arr['id'].'"" onclick="Page.Go(this.href); return false;"><img src="'.URL.'/design/img/comm.png"/></a>';
					echo '</div>';
				}
			}
			echo'</center></div>';
	
			navi($p,$cp,''.URL.'/response/post.php?id='.$id.'&');

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

?>