<?php

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

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

$set['title'] = lang('Гости');

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

aut();

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

$new = $db->super_query("SELECT COUNT(*) as count FROM `myguests` WHERE `id_ank` = '$user[id]' AND `read`='1'");
if ($new['count'] != 0) {
    $db->query("UPDATE `myguests` SET `read` = '0' WHERE `id_ank` = '$user[id]' AND `read` = '1' LIMIT $new[count]");
}

$k_post = $db->super_query("SELECT COUNT(*) as count FROM `myguests` WHERE `id_ank` = '$user[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'];

if ($k_post == 0) {
    $doc->NoResult();
}

$q = $db->query("SELECT * FROM `myguests` WHERE `id_ank` = '$user[id]' ORDER BY `time` DESC  LIMIT $start, $set[p_str]");
while ($post = $db->get_array($q)) {
    $ank = get_user($post['id_user']);
    if ($post['count'] == 1 || $post['count'] >= 5 && $post['count'] <= 21 || $post['count'] >= 25 && $post['count'] <= 1111111111) {
        $kol = "раз";
    } elseif ($post['count'] >= 2 && $post['count'] <= 4 || $post['count'] >= 22 && $post['count'] <= 24) {
        $kol = "раза";
    }
    echo "<table class='list-group-item-null list-group-item-grey dop'><tr><td class='icon14'>";
    avatar($ank['id'], '40', 'border-radius: 2px;');
    echo "</td><td class='null'>";
    echo "<span style='float: right;color: grey;'>" . date::timek($post['time']) . "</span>";
    user($ank['id']);
    echo "<br />";
    echo "<i class='fa fa-eye fa-fw'></i> " . lang('Посещал') . "" . ($ank['sex'] == 0 ? 'а' : '') . " $post[count] $kol";
    echo "</td></tr></table>";
}

if ($k_page > 1) {
    str("?", $k_page, $page);
}

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