<?php

/* DCMS Special
 * Дата последнего редактирования 02.10.2016
 * Модифицировал densnet
 */

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
    require_once "../../sys/inc/$inc.php";
}

only_reg();

$doc->Title('Список друзей онлайн');

require_once H . 'sys/inc/thead.php';

aut();

$ank['id'] = $user['id'];

if (isset($_GET['id'])) {
    $sid = intval($_GET['id']);
} else {
    $sid = $user['id'];
}

$ank = get_user($sid);

$q = mysql_query("SELECT * FROM `user` WHERE `id` = $ank[id] LIMIT 1");
if (mysql_num_rows($q) == 0) {
    header("Location: index.php?" . SID);
    exit;
}

#Навигация
echo "<div class='list-group-item-null list-group-item-grey'><small>";
echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
echo "<a href='/info.php?id=$ank[id]'>$ank[nick]</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Друзья');
echo "</small></div><br />";

$ank = mysql_fetch_array($q);
$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='list-group-item-null list-group-item-grey'>";
if ($k_online == 0) {
    echo "<ul class='nav nav-tabs' style='margin-bottom: -12px;'>";
} else {
    echo "<ul class='nav nav-tabs' style='margin-bottom: -11px;'>";
}
echo "<li class='nav-item'><a class='nav-link' href='index.php?id=$ank[id]'>" . lang('Друзья') . " <span class='label label-default'>$k_post</span></a></li>";
if (isset($user) && $user['id'] == $ank['id']) {
    echo "<li class='nav-item'><a class='nav-link' href='new.php'>" . lang('Заявки') . " <span class='label label-default'>$k_z</span></a></li>";
}
echo "<li class='nav-item'><a class='nav-link active'>" . lang('Онлайн') . " <span class='label label-default'>$k_online</span></a></li>";
echo "</ul>";
echo "</div>";

if ($k_online == 0) {
    echo "<br />";
    $doc->NoResult();
}

$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];

$q = mysql_query("SELECT * 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) . "' ORDER BY `user`.`date_last` DESC LIMIT $start, $set[p_str]");
while ($f = mysql_fetch_array($q)) {

    $ank = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$f[friends]' LIMIT 1"));

    echo "<table class='list-group-item-null'><tr><td class = 'icon14'>";
    avatar($ank['id'], '48');
    echo "</td><td class = 'null'>";
    user($ank['id']);
    echo "<br/>";
    if (isset($user) && $user['id'] == $ank['id']) {
        echo "<font color='grey'><i class='fa fa-envelope fa-fw'></i> " . lang('Сообщение') . "</font>";
    } else {
        echo "<a href = '/user/mail/messageList.php?contact=$ank[id]'><i class='fa fa-envelope fa-fw'></i> " . lang('Сообщение') . "</a>";
    }

    echo "</td></tr></table>";
    echo "<div class='hr'></div>";
}

if ($k_page > 1) {
    str("?id=$ank[id]&amp;", $k_page, $page);
}

require_once H . 'sys/inc/tfoot.php';
