<?
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';

only_reg();

$ank['id']=$user['id'];

$set['title'] = 'Предложения Ленты';
include_once 'sys/inc/thead.php';
title();


if (isset($_GET['ok']))
{
	$ok = intval($_GET['ok']);
	if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$ok' LIMIT 1"),0)==0){header("Location: index.php?");exit;}
    mysql_query("INSERT INTO `fanat` (`user`, `frend`, `time`, `i`) values('$ank[id]', '$ok', '$time', '1')");
    mysql_query("INSERT INTO `fanat` (`user`, `frend`, `time`, `i`) values('$ok', '$ank[id]', '$time', '1')");
    mysql_query("DELETE FROM `fanat_obm` WHERE `user` = '$ok' AND `to` = '$user[id]' LIMIT 1");
	mysql_query("DELETE FROM `fanat_obm` WHERE `user` = '$user[id]' AND `to` = '$ok' LIMIT 1");
    mysql_query("OPTIMIZE TABLE `fanat`");
    mysql_query("OPTIMIZE TABLE `fanat_obm`");

$msgok="Поздравляем! обитатель [b]$user[nick][/b] добавлен в список Ваших читателей!";
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ok', '$msgok', '$time')");

msg ('Предложение обмена лентой успешно принято');

}
if (isset($_GET['no']))
{
  $no = intval($_GET['no']);
  if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$no' LIMIT 1"),0)==0){header("Location: index.php?");exit;}
  mysql_query("DELETE FROM `fanat` WHERE `user` = '$user[id]' AND `frend` = '$no' LIMIT 1");
  mysql_query("DELETE FROM `fanat` WHERE `user` = '$no' AND `frend` = '$user[id]' LIMIT 1");
  mysql_query("DELETE FROM `fanat_obm` WHERE `user` = '$no' AND `to` = '$user[id]' LIMIT 1");
  mysql_query("DELETE FROM `fanat_obm` WHERE `user` = '$user[id]' AND `to` = '$no' LIMIT 1");
  mysql_query("OPTIMIZE TABLE `fanat`");
  mysql_query("OPTIMIZE TABLE `fanat_obm`");

$msgno="К сожалению,обитатель [b]$user[nick][/b] отклонил ваше предложение обмена лентой активности!";
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$no', '$msgno', '$time')");

msg ('Предложение отклонено');
}


if (isset($_GET['del']))
{
  $no = intval($_GET['del']);
  if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$no' LIMIT 1"),0)==0){header("Location: index.php?");exit;}
  mysql_query("DELETE FROM `fanat` WHERE `user` = '$user[id]' AND `frend` = '$no' LIMIT 1");
  mysql_query("DELETE FROM `fanat` WHERE `user` = '$no' AND `frend` = '$user[id]' LIMIT 1");
  mysql_query("DELETE FROM `fanat_obm` WHERE `user` = '$no' AND `to` = '$user[id]' LIMIT 1");
  mysql_query("DELETE FROM `fanat_obm` WHERE `user` = '$user[id]' AND `to` = '$no' LIMIT 1");
  mysql_query("OPTIMIZE TABLE `fanat`");
  mysql_query("OPTIMIZE TABLE `fanat_obm`");

$msgno="К сожалению,[b]$user[nick][/b] удалил вас из списка своих читателей!";
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$no', '$msgno', '$time')");

msg ('Обмен лентой успешно завершен!');
}

$m = date('m', $time);
if (substr($m, 0, 1) == 0)$m = str_replace('0', '', $m);
$d = date('d', $time);
$k_f = mysql_result(mysql_query("SELECT COUNT(id) FROM `fanat_obm` WHERE `to` = '$user[id]' LIMIT 1"), 0);

if ($k_f==0)echo 'На данный момент это последнее предложение!';

$q = mysql_query("SELECT * FROM `fanat_obm` WHERE `to` = '$user[id]' ORDER BY time DESC");
while ($f = mysql_fetch_array($q))
{echo "<table class='post'>\n";
	$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$f['user']."' LIMIT 1"));

echo '<tr><td class="icon14">';
	avatar4($a['id']);
	echo '</td><td class="anput">';
		echo ''.online($a['id']).' <a href="/info.php?id='.$a['id'].'">'.$a['nick'].'</a> ('.vremja($f['time']).')<br/>';

	echo 'Предлогает обмен лентой<br/>';
	echo '<div class="menu_razd"><a href="fanat_obm.php?ok='.$a['id'].'">Обменяться</a> | <a href="fanat_obm.php?no='.$a['id'].'">Отклонить</a></div>';
echo '</td></tr>';
	echo "</table>";

}

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