<?
//Автор: DjBoBaH 
//Сайт: http://my-perm.net 
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';
include $_SERVER['DOCUMENT_ROOT']."/anti_ hacker.php"; 
if(isset($_GET['s']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `id` = '".intval($_GET['s'])."' LIMIT 1"),0)==1)
{
$s=intval($_GET['s']);
$soo=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo` WHERE `id` = '$s' LIMIT 1"));
include_once 'inc/ban.php';

$set['title']="".filter_var($soo['name'], FILTER_SANITIZE_SPECIAL_CHARS)." - Друзья соо"; // заголовок страницы
include_once '../sys/inc/thead.php';
echo '<div class="main_menu">';
title();echo "</div>\n";
echo '<div class="rekl_main">';
aut();
if(isset($user) && $user['id']==$soo['admid'])
{
if(isset($_GET['del']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_friends` WHERE `id` = '".intval($_GET['del'])."' AND `id_soo`='$soo[id]' LIMIT 1"),0)==1)
{
mysql_query("DELETE FROM `soo_friends` WHERE `id`='".intval($_GET['del'])."' LIMIT 1");
msg('Друг соо успешно удален');
}
elseif(isset($_POST['friend_add']) && $_POST['friend_add']!=$soo['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `id` = '".intval($_POST['friend_add'])."' LIMIT 1"),0)==1 && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_friends` WHERE `id_soo`='$soo[id]' AND `id_friend`='".intval($_POST['friend_add'])."' LIMIT 1"),0)==0)
{
$add_friend=intval($_POST['friend_add']);
mysql_query("INSERT INTO `soo_friends` (`id_soo`, `id_friend`, `time`) values ('$soo[id]', '$add_friend', '$time')");
msg('Друг соо успешно добавлен');
}
}
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_friends` WHERE `id_soo`='$soo[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
echo '<table class="post">';
if ($k_post==0)
{
echo '<tr>';
echo '<td class="p_t">';
echo 'Друзей нет';
echo '</td>';
echo '</tr>';
}
$q=mysql_query("SELECT * FROM `soo_friends` WHERE `id_soo`='$soo[id]' ORDER BY `time` ASC LIMIT $start, $set[p_str]");
while ($friends = mysql_fetch_assoc($q))
{
$friend=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo` WHERE `id` = '$friends[id_friend]' LIMIT 1"));
echo '<tr>';
echo '<td class="icon14">';
echo '<img src="img/cat.png" alt="" />';
echo '</td>';
echo '<td class="p_t">';
echo '<a href="/soo/'.$friend['id'].'">'.filter_var($fiend['name'], FILTER_SANITIZE_SPECIAL_CHARS).'</a> ('.vremja($friends['time']).')';
if(isset($user) && $user['id']==$soo['admid'])echo' [<a href="?s='.$soo['id'].'&del='.$friends['id'].'">x</a>]';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="p_m" colspan="2">';
echo ''.output_text($friend['desc']).'';
echo '</td>';
echo '</tr>';
}
echo '</table>';
if ($k_page>1)str("?s=$soo[id]&",$k_page,$page); // Вывод страниц
if(isset($user) && $user['id']==$soo['admid'])
{
if(isset($_GET['add']))
{
echo'<form method="post" action="?s='.$soo['id'].'">';
echo'Введите ID сообщества<br/>';
echo'<input type="text" name="friend_add" size="3">';
echo'<input type="submit" value="Добавить">';
echo'</form><br/>';
}
else
{
echo'<a href="?s='.$soo['id'].'&add">Добавить друга</a><br/>';
}
}
echo'<a href="index.php?s='.$soo['id'].'">В сообщество</a><br/>';
}
else
{
header("Location:index.php");
}
include_once '../sys/inc/tfoot.php';
?>