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

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;}
$a=mysql_result(mysql_query("SELECT COUNT(*) FROM `frends_new` WHERE `user`='$ok' AND `to`='$user[id]'"),0);
if ($a==0)
{
$set['title']='Ошибка!';
include_once 'sys/inc/thead.php';
title();
err();
echo "<div class='err'>Упс! Лохе!</div>";
include_once 'sys/inc/tfoot.php';
exit();
}else{
mysql_query("INSERT INTO `frends` (`user`, `frend`, `time`, `i`) values('$ank[id]', '$ok', '$time', '1')");
mysql_query("INSERT INTO `frends` (`user`, `frend`, `time`, `i`) values('$ok', '$ank[id]', '$time', '1')");
mysql_query("DELETE FROM `frends_new` WHERE `user` = '$ok' AND `to` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `frends_new` WHERE `user` = '$user[id]' AND `to` = '$ok' LIMIT 1");
mysql_query("OPTIMIZE TABLE `frends`");
mysql_query("OPTIMIZE TABLE `frends_new`");
$msgok="Поздравляем! Обитатель [url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] принял предложение вашей дружбы!";
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ok', '$msgok', '$time')");
header("Location: frend.php?".SID);
exit;
}
}

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 `frends` WHERE `user` = '$user[id]' AND `frend` = '$no' LIMIT 1");
mysql_query("DELETE FROM `frends` WHERE `user` = '$no' AND `frend` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `frends_new` WHERE `user` = '$no' AND `to` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `frends_new` WHERE `user` = '$user[id]' AND `to` = '$no' LIMIT 1");
mysql_query("OPTIMIZE TABLE `frends`");
mysql_query("OPTIMIZE TABLE `frends_new`");
$msgno="Пользователь [url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] отклонил ваше предложение дружбы!";
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$no', '$msgno', '$time')");
header("Location: frend_new.php?".SID);
exit;
}
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 `frends` WHERE `user` = '$user[id]' AND `frend` = '$no' LIMIT 1");
mysql_query("DELETE FROM `frends` WHERE `user` = '$no' AND `frend` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `frends_new` WHERE `user` = '$no' AND `to` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `frends_new` WHERE `user` = '$user[id]' AND `to` = '$no' LIMIT 1");
mysql_query("OPTIMIZE TABLE `frends`");
mysql_query("OPTIMIZE TABLE `frends_new`");
$msgno="Обитатель [url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] больше не является вашим другом.";
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$no', '$msgno', '$time')");
header("Location: frend.php?".SID);
exit;
}
$set['title']="Список предложений дружбы";
include_once 'sys/inc/thead.php';
title();

$k_f=mysql_result(mysql_query("SELECT COUNT(id) FROM `frends_new` WHERE `to` = '$user[id]' LIMIT 1"),0);
if ($k_f==0)
{
?>
<div class='noy'>Нет предложений на дружбу</div>
<?
}
$q = mysql_query("SELECT * FROM `frends_new` WHERE `to` = '$user[id]' ORDER BY time DESC");
while ($f = mysql_fetch_array($q))
{
$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$f['user']."' LIMIT 1"));
if($num==1){
echo "<div class='enk_div'>\n";
$num=0;
}else{
echo "<div class='enk2_div'>\n";
$num=1;}
echo "".avatar2($a['id'])."<br />";
echo "".on($a['id'])."\n";
echo "".pol($a['id'])."";
echo "<a href='/info.php?id=$a[id]'><span style='color:$a[ncolor]'>$a[nick]</span></a> (".vremja($f['time']).")<br />\n";
echo "<a href='frend_new.php?ok=$a[id]'>Принять</a>/<a href='frend_new.php?no=$a[id]'>Отклонить</a>\n";
echo "</div>\n";
}
include_once 'sys/inc/tfoot.php';
?>