<?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='/info.php?id=$user[id]'>$user[nick]</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Гости');
echo "</small></div><br />";

$new = mysql_result(mysql_query("SELECT COUNT(*) FROM `myguests` WHERE `id_ank` = '$user[id]' AND `read`='1'"), 0);
if ($new != 0) {
    mysql_query("UPDATE `myguests` SET `read`='0' WHERE `id_ank`='$user[id]' AND `read`='1' LIMIT $new");
}

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `myguests` WHERE `id_ank` = '$user[id]'"), 0);
$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 = mysql_query("SELECT * FROM `myguests` WHERE `id_ank` = '$user[id]' ORDER BY `time` DESC  LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_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'><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>";
    echo "<div class='hr'></div>";
}

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

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