<?
/*
Сделано © alex-borisi
Все права защищены
http://nasimbe.ru
*/
include_once '../../sys/inc/start.php';
include_once '../../sys/inc/compress.php';
include_once '../../sys/inc/sess.php';
include_once '../../sys/inc/home.php';
include_once '../../sys/inc/settings.php';
include_once '../../sys/inc/db_connect.php';
include_once '../../sys/inc/ipua.php';
include_once '../../sys/inc/fnc.php';
include_once '../../sys/inc/user.php';

if (isset($user))$ank['id'] = $user['id'];
if (isset($_GET['id']))$ank['id'] = intval($_GET['id']);
$ank = get_user($ank['id']);

if ($ank['id'] == 0)
{
	header("Location: /index.php?" . SID);exit;
	exit;
}

if (isset($user) && isset($_GET['delete']) && $user['id'] == $ank['id'])
{
mysql_query("DELETE FROM `forum_zakl` WHERE `id_them` = '" . intval($_GET['delete']) . "' AND `id_user` = '$user[id]' LIMIT 1");
	
	$_SESSION['message'] = 'Закладка удалена';
	header("Location: ?page=" . intval($_GET['page']) . "" . SID);exit;
	exit;
}

if( !$ank ){ header("Location: /index.php?".SID); exit; }
$set['title'] = 'Закладки - Форум';
include_once '../../sys/inc/thead.php';
title();
aut(); // форма авторизации

echo '<div class="foot">';
echo '<img src="/style/icons/str2.gif" alt="*" /> <a href="/user/bookmark/index.php?id=' . $ank['id'] . '">Закладки</a> | <b>Форум</b>';
echo '</div>';

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_zakl` WHERE `id_user` = '$ank[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
echo '<table class="post">';

if ($k_post == 0)
{
	echo '<div class="mess">';
	echo 'Нет тем в закладках';
	echo '</div>';
}

$q=mysql_query("SELECT `id_them`,`time` FROM `forum_zakl` WHERE `id_user` = '$ank[id]' ORDER BY `time_obn` DESC LIMIT $start, $set[p_str]");

while ($zakl = mysql_fetch_assoc($q))
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_t` WHERE `id` = '$zakl[id_them]' LIMIT 1"),0)==1)
{

$them = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_t` WHERE `id` = '$zakl[id_them]' LIMIT 1"));

$forum = mysql_fetch_assoc(mysql_query("SELECT id FROM `forum_f` WHERE `id` = '$them[id_forum]' LIMIT 1"));

$razdel = mysql_fetch_assoc(mysql_query("SELECT id FROM `forum_r` WHERE `id` = '$them[id_razdel]' LIMIT 1"));

/*-----------зебра-----------*/ 
if ($num==0){
	echo '<div class="nav1">';
	$num=1;
}
elseif ($num==1){
	echo '<div class="nav2">';
	$num=0;
}
/*---------------------------*/

echo '<img src="/style/themes/' . $set['set_them'] . '/forum/14/them_' . $them['up'] . $them['close'] . '.png" alt="*" />';

$k_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id_them` = '$them[id]'"),0);

$k_n_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id_them` = '$them[id]' AND `time` > '$zakl[time]'"),0);

$page_z = k_page($k_p - $k_n_p + 1, $set['p_str']);

if ($k_n_p == 0)$k_n_p = NULL; else $k_n_p = '<font color=red>+' . $k_n_p . '</font>';

echo '<a href="/forum/' . $forum['id'] . '/' . $razdel['id'] . '/' . $them['id'] . '/?page=' . $pageEnd . '">' . htmlspecialchars($them['name']) . '</a> (' . $k_p . ')' . $k_n_p . '<br />';

	$ank1 = mysql_fetch_assoc(mysql_query("SELECT nick,id FROM `user` WHERE `id` = $them[id_user] LIMIT 1"));

	echo '<a href="/info.php?id=' . $ank1['id'] . '" title="Анкета">' . $ank1['nick'] . '</a> (' . vremja($them['time_create']) . ') ';

	$post = mysql_fetch_assoc(mysql_query("SELECT id_user,time,id FROM `forum_p` WHERE `id_them` = '$them[id]' AND `id_razdel` = '$razdel[id]' AND `id_forum` = '$forum[id]' ORDER BY `id` DESC LIMIT 1"));

	$ank2 = mysql_fetch_assoc(mysql_query("SELECT nick,id FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));

	if ( $ank2 && $ank2['id'] != $ank1['id'])
	echo ' :: <a href="/info.php?id=' . $ank2['id'] . '" title="Анкета">' . $ank2['nick'] . '</a> (' . vremja($post['time']) . ')<br />';
	
if ($ank['id'] == $user['id'])
echo '<div style="text-align:right;"><a href="?delete=' . $them['id'] . '&amp;page=' . $page . '"><img src="/style/icons/delete.gif" alt="*" /></a></div>';

echo '</div>';
}
}
echo '</table>';


echo '<div class="foot">';
echo '<img src="/style/icons/str2.gif" alt="*" /> <a href="/user/bookmark/index.php?id=' . $ank['id'] . '">Закладки</a> | <b>Форум</b>';
echo '</div>';


include_once '../../sys/inc/tfoot.php';
?>
