<?php

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

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

if (isset($user)) {
    $ank['id'] = $user['id'];
}

if (isset($_GET['id'])) {
    $ank['id'] = intval($_GET['id']);
}

if ($ank['id'] == 0) {
    header("Location: /index.php?" . SID);
    exit;
}

$ank = get_user($ank['id']);

if (isset($user) && isset($_GET['delete']) && $user['id'] == $ank['id']) {
    $db->query("DELETE FROM `bookmark_user` WHERE `id` = '" . intval($_GET['delete']) . "' AND `id_user` = '$user[id]' LIMIT 1");

    $_SESSION['message'] = lang('Закладка удалена');
    header("Location: ?page=" . intval($_GET['page']) . "" . SID);
    exit;
}

if (!$ank) {
    header("Location: /index.php?" . SID);
    exit;
}

$set['title'] = lang('Закладки') . ' ' . $ank['nick'];

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

aut();
only_reg();

$k = $db->super_query("SELECT COUNT(id_user) as count FROM `bookmark_user` WHERE `id_user` = '" . $ank['id'] . "'");
$users = $k['count'];
$k = $db->super_query("SELECT COUNT(id_user) as count FROM `bookmark_foto` WHERE `id_user` = '" . $ank['id'] . "'");
$foto = $k['count'];
$k = $db->super_query("SELECT COUNT(id_user) as count FROM `bookmark_files` WHERE `id_user` = '" . $ank['id'] . "'");
$files = $k['count'];

#Навигация
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='/id$ank[id]'>$ank[nick]</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Закладки');
echo "</small></div><br />";

$k_post = $db->super_query("SELECT COUNT(*) as count FROM `bookmark_user` WHERE `id_user` = '$ank[id]'");
$k_post = $k_post['count'];
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];

echo "<div class='list-group-item-null list-group-item-grey'>";
if ($k_post == 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 active'>" . lang('Люди') . " <span class='label label-default'>$users</span></a></li>";
echo "<li class='nav-item'><a class='nav-link' href='foto.php?id=$ank[id]'>" . lang('Фото') . " <span class='label label-default'>$foto</span></a></li>";
//echo "<li class='nav-item'><a class='nav-link' href='files.php?id=$ank[id]'>" . lang('Файлы') . " <span class='label label-default'>$files</span></a></li>";
echo "</ul>";
echo "</div>";

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

$q = $db->query("SELECT * FROM `bookmark_user` WHERE `id_user` = '$ank[id]' ORDER BY id DESC LIMIT $start, $set[p_str]");

while ($post = $db->get_row($q)) {
    $ank_p = $db->get_row($db->query("SELECT * FROM `user` WHERE `id` = '$post[id_people]' LIMIT 1"));

    if ($ank_p['id'] == 0) {
        $ank_p['id'] = 0;
    }

    echo "<table class='list-group-item-null'><tr><td class='icon14'>";
    avatar($ank_p['id'], '48', 'border-radius: 2px;');
    echo "</td><td class='null'>";
    echo "<div style='float:right;color:grey;'><small title='" . date::time($post['time']) . "'>" . date::timek($post['time']) . "</small></div>";
    echo user($ank_p['id']);
    echo "<br />";

    if (isset($user) && $user['id'] == $ank['id']) {
        echo "<div style='float:right;'>";
        echo "<a href='?delete=$post[id]&amp;page=$page' class='hint--left' data-hint='" . lang('Удалить') . "'><i class='fa fa-trash-o fa-fw'></i></a>";
        echo "</div>";
    }

    if ($ank_p['id'] == 0) {
        echo "<font color='grey'><i class='fa fa-envelope fa-fw'></i> " . lang('Сообщение') . "</font>";
    } elseif ($user['id'] == $ank_p['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_p[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('?', $k_page, $page);
}


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