Файл: user/friends/new.php
Строк: 158
<?php
require_once '../../sys/inc/start.php';
require_once '../../sys/inc/compress.php';
require_once '../../sys/inc/sess.php';
require_once '../../sys/inc/settings.php';
require_once '../../sys/inc/db_connect.php';
require_once '../../sys/inc/ipua.php';
require_once '../../sys/inc/fnc.php';
require_once '../../sys/inc/user.php';
only_reg();
$ank['id'] = $user['id'];
$set['title'] = 'Предложения дружбы';
require_once '../../sys/inc/thead.php';
aut();
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 `friends` (`user`, `friends`, `time`, `i`) values('$ank[id]', '$ok', '$time', '1')");
mysql_query("INSERT INTO `friends` (`user`, `friends`, `time`, `i`) values('$ok', '$ank[id]', '$time', '1')");
mysql_query("DELETE FROM `friends_new` WHERE `user` = '$ok' AND `to` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `friends_new` WHERE `user` = '$user[id]' AND `to` = '$ok' LIMIT 1");
mysql_query("OPTIMIZE TABLE `friends`");
mysql_query("OPTIMIZE TABLE `friends_new`");
$msg = "" . ($user['sex'] ? 'принял' : 'приняла') . " предложение вашей дружбы!";
mysql_query("INSERT INTO `tape` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$ok', '$msg', '$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 `friends` WHERE `user` = '$user[id]' AND `friends` = '$no' LIMIT 1");
mysql_query("DELETE FROM `friends` WHERE `user` = '$no' AND `friends` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `friends_new` WHERE `user` = '$no' AND `to` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `friends_new` WHERE `user` = '$user[id]' AND `to` = '$no' LIMIT 1");
mysql_query("OPTIMIZE TABLE `friends`");
mysql_query("OPTIMIZE TABLE `friends_new`");
$msg = "" . ($user['sex'] ? 'отклонил' : 'отклонила') . " ваше предложение дружбы!";
mysql_query("INSERT INTO `tape` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$no', '$msg', '$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 `friends` WHERE `user` = '$user[id]' AND `friends` = '$no' LIMIT 1");
mysql_query("DELETE FROM `friends` WHERE `user` = '$no' AND `friends` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `friends_new` WHERE `user` = '$no' AND `to` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `friends_new` WHERE `user` = '$user[id]' AND `to` = '$no' LIMIT 1");
mysql_query("OPTIMIZE TABLE `friends`");
mysql_query("OPTIMIZE TABLE `friends_new`");
$msg = "К сожалению, " . ($user['sex'] ? 'удалил' : 'удалила') . " Вас из друзей!";
mysql_query("INSERT INTO `tape` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$no', '$msg', '$time')");
msg('Успешно удален');
}
$k_online = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` INNER JOIN `user` ON `friends`.`friends`=`user`.`id` WHERE `friends`.`user` = '$ank[id]' AND `friends`.`i` = '1' AND `user`.`date_last`>'".(time() - 300)."'"), 0);
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `user` = '$ank[id]' AND `i` = '1'"), 0);
$k_z = mysql_result(mysql_query("SELECT COUNT(id) FROM `friends_new` WHERE `to` = '$ank[id]'"), 0);
echo "<div class = 'tabs'>";
echo "<a href = '/user/friends/'>Друзья [$k_post]</a>";
echo "<a href = '/user/friends/new.php' class = 'active'>Заявки [$k_z]</a>";
echo "<a href = '/user/friends/online.php'>Онлайн [$k_online]</a>";
echo "</div><div class = 'tabcontent'>";
$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 `friends_new` WHERE `to` = '$user[id]' LIMIT 1"), 0);
echo "<div class = 'menu_razd'>Заявки</div>";
if ($k_f == 0) {
echo "<table class = 'foot'><tr><td class = 'null'>";
echo "<img src = '/style/icons/bullet_error.png' /> Нет заявок";
echo "</td></tr></table>";
}
$q = mysql_query("SELECT * FROM `friends_new` WHERE `to` = '$user[id]' ORDER BY time DESC");
while ($f = mysql_fetch_array($q)){
$ank = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$f['user']."' LIMIT 1"));
echo "<table class = 'foot'><tr><td class = 'icon48'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
user($ank['id']);
echo "<br/>";
echo "<img src = '/style/icons/time.png' /> ".vremja($f['time'])."<br/>";
echo "<img src = '/style/icons/thumb_up.png' /> <a href = 'new.php?ok=$ank[id]'> Принять</a>";
echo " | ";
echo "<img src = '/style/icons/thumb_down.png' /> <a href = 'new.php?no=$ank[id]'> Отклонить</a>";
echo "</td></tr></table>";
}
$k_t = mysql_result(mysql_query("SELECT COUNT(id) FROM `friends_new` WHERE `user` = '$user[id]' LIMIT 1"), 0);
echo "<div class = 'menu_razd'>Мои предложения</div>";
if ($k_t == 0) {
echo "<table class = 'foot'><tr><td class = 'null'>";
echo "<img src = '/style/icons/bullet_error.png' /> Нет предложений";
echo "</td></tr></table>";
}
$q = mysql_query("SELECT * FROM `friends_new` WHERE `user` = '$user[id]' ORDER BY time DESC");
while ($f = mysql_fetch_array($q)){
$ank = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$f['to']."' LIMIT 1"));
echo "<table class = 'foot'><tr><td class = 'icon48'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
user($ank['id']);
echo "<br/>";
echo "<img src = '/style/icons/time.png' /> ".vremja($f['time'])."<br/>";
echo "<img src = '/style/icons/cross.png' /> <a href = 'new.php?no=$ank[id]'> Отменить предложение</a>";
echo "</td></tr></table>";
}
echo "</div>";
require_once '../../sys/inc/tfoot.php';