Файл: user/friends/new.php
Строк: 185
<?php
/* Мод "Друзья"
* Версия v0.0.1
* Дата последнего редактирования 21.11.2014
* Двиг DCMS Special
* Модифицировал densnet
* Файл new.php
* Описание: выводит список заявок в друзья. Входящие и исходящие
*/
require_once '../../sys/inc/start.php';
require_once H . 'sys/inc/compress.php';
require_once H . 'sys/inc/sess.php';
require_once H . 'sys/inc/settings.php';
require_once H . 'sys/inc/db_connect.php';
require_once H . 'sys/inc/ipua.php';
require_once H . 'sys/inc/fnc.php';
require_once H . 'sys/inc/user.php';
user::only_reg();
$ank['id'] = $user['id'];
$set['title'] = 'Предложения дружбы';
require_once H . 'sys/inc/thead.php';
title();
aut();
#Навигация
echo "<div class = 'navigation'><a href = '/index.php'>Главная</a> > <a href = '/id$user[id]'>$user[nick]</a> > <a href = '/user/friends/?id=$ank[id]'>Друзья</a> > <a href = '?'><b>Заявки</b></a></div>";
echo "<div style = 'font-size: 18px;font-weight: bold;' class = 'razdel'>" . img('friends.png') . " Друзья</div>";
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 `notification` (`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 `notification` (`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 = "Мы больше не являемся друзьями!";
mysql_query("INSERT INTO `notification` (`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 t_bar clear_fix'>";
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>";
$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);
$r = (isset($_GET['r'])) ? htmlspecialchars($_GET['r']) : null;
switch ($r) {
default:
echo "<div class = 'tabs t_bar clear_fix'>";
echo "<a href = '/user/friends/new.php' class = 'active'>Входящие</a>";
echo "<a href = '/user/friends/new.php?r=outgoing'>Исходящие</a>";
echo "</div>";
if ($k_f == 0) {
echo "<div class = 'errs'>";
echo img('error.png') . " Нет результатов";
echo "</div>";
}
$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 = 'razd'><tr><td class = 'icon14'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
echo "<span style = 'float:right;'>" . date::time($f['time']) . "</span>";
user($ank['id']);
echo "<br /><br />";
echo "<a class = 'count' href = 'new.php?ok=$ank[id]'>" . img('ok.png') . " <font color = 'green'>Принять</font></a> ";
echo "<a class = 'count' href = 'new.php?no=$ank[id]'><font color = 'red'>" . img('cancel.png') . " Отклонить</font></a>";
echo "</td></tr></table>";
}
break;
case 'outgoing':
$k_t = mysql_result(mysql_query("SELECT COUNT(id) FROM `friends_new` WHERE `user` = '$user[id]' LIMIT 1"), 0);
echo "<div class = 'tabs t_bar clear_fix'>";
echo "<a href = '/user/friends/new.php?'>Входящие</a>";
echo "<a href = '/user/friends/new.php?r=outgoing' class = 'active'>Исходящие</a>";
echo "</div>";
if ($k_t == 0) {
echo "<div class = 'errs'>";
echo img('error.png') . " Нет результатов";
echo "</div>";
}
$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 = 'razd'><tr><td class = 'icon14'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
user($ank['id']);
echo " (" . date::time($f['time']) . ")<br /><br />";
echo "<a class = 'count' href = 'new.php?no=$ank[id]'><font color = 'red'>Отменить предложение</font></a>";
echo "</td></tr></table>";
}
break;
}
require_once H . 'sys/inc/tfoot.php';