<?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 `users` WHERE `id` = '".$id."' LIMIT 1");
	if (mysql_num_rows($result) == true)
	{
		$arr_user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$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>';

	if (!empty($user_id) && $user_id == $arr_user['id'])
	{
?>
<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>
<?
		echo '<div class="block">
		<form id="form" action="'.URL.'/response/new.php" method="post">
		<textarea id="textarea" name="text" class="input"></textarea>
		<input type="submit" name="cfms" value="'.lang('Задать вопрос','Створити запитання').'" class="button" />
		</form>
		</div>';
	}
	
$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blog` WHERE `user_id` = '".$arr_user['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` WHERE `user_id` = '".$arr_user['id']."' ORDER by `time` DESC LIMIT $start,10");
		while ($arr = mysql_fetch_array($res))
		{
			echo '<div class="block2">';
			echo user_name($arr_user['id']).'<br/>'.vtime($arr['time']).'<div class="text"><div class="hide_text"> </div><ul>'.text($arr['text']).'</ul></div><div class="right">';

			if (!empty($user_id) && $user_id != $arr_user['id'])
			{
				if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blog_like` WHERE `fid` = '".$arr['id']."' AND `user_id` = '".$user_id."'"),0) == false) echo '<span id="'.$arr['id'].'"><a class="'.$arr['id'].'" href="'.URL.'/response/like.php?id='.$arr['id'].'"><img src="'.URL.'/design/img/like.png"/> <b>'.$arr['clike'].'</b></a></span>';
				else echo '<img src="'.URL.'/design/img/like_ok.png"/> <b>'.$arr['clike'].'</b>';
			}
			else
			{
				echo '<img src="'.URL.'/design/img/like.png"/> <b>'.$arr['clike'].'</b>';
			}
			echo '</div><a href="'.URL.'/response/post.php?id='.$arr['id'].'"" onclick="Page.Go(this.href); return false;">'.lang('Читать','Прочитати').'&gt;&gt;</a> <img src="'.URL.'/design/img/comm.png"/> <b>'.$arr['comm'].'</b>
			</div>';
?>
<script>
$('#<?echo $arr['id'];?> a').click(function (){ 
var href = $(this).attr('href'); 
$('#<?echo $arr['id'];?>').load(href); 
return false; 
});
</script>
<?
		}
	}

	navi($p,$cp,'/response/?id='.$arr_user['id'].'&');
	
require_once '../incfiles/foot.php';

?>