Файл: user/friends/new.php
Строк: 192
<?php
/* DCMS Special
* Дата последнего редактирования 11.12.2015
* Модифицировал densnet
*/
foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
require_once "../../sys/inc/{$inc}.php";
}
only_reg();
$ank['id'] = $user['id'];
$set['title'] = 'Предложения дружбы';
require_once H . 'sys/inc/thead.php';
aut();
#Навигация
echo "<ol class='breadcrumb'>";
echo "<li><a href='/'><span class='fa fa-home fa-fw'></span></a></li>";
echo "<li><a href='/info.php?id=$user[id]'>$user[nick]</a></li>";
echo "<li class='active'>Заявки</li>";
echo "</ol>";
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;
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE (`user` = '$user[id]' AND `friends` = '$no') OR (`user` = '$no' AND `friends` = '$user[id]') LIMIT 1"), 0) > 0) {
mysql_query("INSERT INTO `notification` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$no', '" . ($user['sex'] ? 'удалил' : 'удалила') . " Вас из списка своих друзей.', '$time')");
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 `freinds_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('Пользователь удален из списка ваших друзей');
header("location: " . htmlspecialchars($_SERVER['HTTP_REFERER']) . "");
}
exit;
}
$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'>$k_post</span></a></li>";
echo "<li class='nav-item'><a class='nav-link active'>Заявки <span class='label label-default'>$k_z</span></a></li>";
echo "<li class='nav-item'><a class='nav-link' href='online.php'>Онлайн <span class='label label-default'>$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>";
if ($k_f == 0) {
echo "<div class='card-block'>";
echo "<i class='fa fa-info-circle fa-fw'></i> Нет результатов";
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 href='new.php?ok=$ank[id]'> <font color='green'>Принять</font></a> ";
echo "<a 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>";
if ($k_t == 0) {
echo "<div class='card-block'>";
echo "<i class='fa fa-info-circle fa-fw'></i> Нет результатов";
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 = 'Удалить'><i class='fa fa-trash-o fa-fw'></i></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';