Файл: user/friends/new.php
Строк: 200
<?php
/* DCMS S (Special)
* Версия файла 0.0.1
* Дата последнего редактирования 22.11.2015
* Модифицировал densnet
*/
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();
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('Предложение отклонено');
header("Location: new.php?r=outgoing");
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 `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='card'>";
echo "<div class='card-header'>Друзья</div><div class='card-block'>";
echo "<ul class='nav nav-tabs'>";
echo "<li class='nav-item'><a class='nav-link' href='index.php'>Друзья <span class='label label-default label-pill'>$k_post</span></a></li>";
echo "<li class='nav-item'><a class='nav-link active'>Заявки <span class='label label-default label-pill'>$k_z</span></a></li>";
echo "<li class='nav-item'><a class='nav-link' href='online.php'>Онлайн <span class='label label-default label-pill'>$k_online</span></a></li>";
echo "</ul>";
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='card-block'>";
echo "<ul class='nav nav-pills'>";
echo "<li class='nav-item'><a class='nav-link active'>Входящие</a></li>";
echo "<li class='nav-item'><a class='nav-link' href='/user/friends/new.php?r=outgoing'>Исходящие</a></li>";
echo "</ul><br /><br />";
if ($k_f == 0) {
echo "<div class='card-block'>";
echo "<span class='fa fa-info-circle fa-fw'></span> Нет результатов";
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><tr><td class = 'icon14'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
user($ank['id']);
echo " <small>" . date::time($f['time']) . "</small>";
echo "<br />";
echo "<a class = 'add' href = 'new.php?ok=$ank[id]'> <font color = 'green'>Принять</font></a> ";
echo "<a class = 'add' href = 'new.php?no=$ank[id]'><font color = 'red'> Отклонить</font></a>";
echo "</td></tr></table>";
}
echo '</div>';
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='card-block'>";
echo "<ul class='nav nav-pills'>";
echo "<li class='nav-item'><a class='nav-link' href='/user/friends/new.php?'>Входящие</a></li>";
echo "<li class='nav-item'><a class='nav-link active'>Исходящие</a></li>";
echo "</ul><br /><br />";
if ($k_t == 0) {
echo "<div class='card-block'>";
echo "<span class='fa fa-info-circle fa-fw'></span> Нет результатов";
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><tr><td class = 'icon14'>";
avatar($ank['id'], '48');
echo "</td><td class = 'null'>";
echo "<span style='float:right' id='hides'>";
echo "<a href = 'new.php?no=$ank[id]' title = 'Удалить'><span class='fa fa-trash-o'></span></a>";
echo "</span>";
user($ank['id']);
echo " <small>" . date::time($f['time']) . "</small>";
echo "<br />";
echo "Ожидается...";
echo "</td></tr></table>";
}
echo '</div>';
break;
}
echo "</div>";
require_once H . 'sys/inc/tfoot.php';