<?
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';
$set['title']="Подписка/Отписка";
include_once '../../sys/inc/thead.php';
title();
aut();
only_reg();
if(isset($_GET['frend'])){
$usId2 = intval($_GET['frend']);
$issetUs2 = mysql_result(mysql_query("select COUNT(id) from `user` WHERE `id` = '$usId2' "),0);
if (isset($_GET['frend']) and $issetUs2 == 1 and $usId2 != $user['id']){
$a = mysql_result(mysql_query("SELECT COUNT(*) FROM `frends_new` WHERE `user`='$usId2' AND `to`='$user[id]'"),0);
if ($a==0)
{
$err = 'Ошибка!';
}
else{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fans` WHERE `user` = '$user[id]' and `fanat` = '$usId2' "),0)==0)
{
mysql_query("INSERT INTO `fans` (`user`, `fanat`, `time`) VALUES ('".$user['id']."', '".$usId2."', '".$time."')");
mysql_query("DELETE FROM `frends_new` WHERE `user` = '$usId2' AND `to` = '$user[id]' LIMIT 1");
mysql_query("INSERT INTO `notification` (`avtor`, `id_user`, `id_object`, `type`, `time`) VALUES ('$user[id]', '$usId2', '$user[id]', 'frend_podp', '$time')");
$_SESSION['message']="Пользователь добавлен в подписчики!";
header("Location: /user/frends/new.php");
}
else
{
$err = 'Пользователь уже является вашим подписчиком!';
}
}
}
}
if(isset($_GET['user'])){
$usId = intval($_GET['user']);
$issetUs = mysql_result(mysql_query("select COUNT(id) from `user` WHERE `id` = '$usId' "),0);
if (isset($_GET['user']) and $issetUs == 1 and $usId != $user['id']){
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fans` WHERE `user` = '$usId' and `fanat` = '$user[id]' "),0)==0){
mysql_query("INSERT INTO `fans` (`user`, `fanat`, `time`) VALUES ('".$usId."', '".$user['id']."', '".$time."')");
mysql_query("INSERT INTO `notification` (`avtor`, `id_user`, `id_object`, `type`, `time`) VALUES ('$user[id]', '$usId', '$user[id]', 'podpiska', '$time')");
$_SESSION['message']="Вы успешно подписались!";
header("Location: /info.php?id=$usId");
}
else
{
$flud=mysql_fetch_assoc(mysql_query("SELECT * FROM `fans` WHERE `user` = '$usId' and `fanat` = '$user[id]' LIMIT 1"));
if(($flud['time']+10) < $time){
mysql_query("DELETE FROM `fans` WHERE `user` = '$usId' and `fanat` = '$user[id]' LIMIT 1");
mysql_query("INSERT INTO `notification` (`avtor`, `id_user`, `id_object`, `type`, `time`) VALUES ('$user[id]', '$usId', '$user[id]', 'otpiska', '$time')");
$_SESSION['message']="Вы успешно отписались!";
header("Location: /info.php?id=$usId");
}
else
{
$err = 'Не так часто!';
}
}
}
else
{
$err = 'Ошибка!';
}
}
err();
include_once '../../sys/inc/tfoot.php';
?>