<?php

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

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

access('adm_show_adm', null, 'index.php?' . SID);
adm_check();
$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='/panel/'>" . lang('Панель управления') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Администрация');
echo "</small></div><br />";

$k_post = mysql_result(mysql_query("SELECT COUNT(`user`.`id`) FROM `user` LEFT JOIN `user_group` ON `user`.`group_access` = `user_group`.`id` WHERE `user_group`.`level` != 0 AND `user_group`.`level` IS NOT NULL"), 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 `user`.`id` FROM `user` LEFT JOIN `user_group` ON `user`.`group_access` = `user_group`.`id` WHERE `user_group`.`level` != 0 AND `user_group`.`level` IS NOT NULL ORDER BY `user_group`.`level` DESC LIMIT $start, $set[p_str]");
while ($ank = mysql_fetch_assoc($q)) {
    $ank = get_user($ank['id']);

    echo "<table class='list-group-item-null'><tr><td class='icon14'>";
    avatar($ank['id'], '90', 'border-radius: 2px;');
    echo "</td><td class='null'>";

    if (access('adm_log_read') && $ank['level'] != 0 && ($ank['id'] == $user['id'] || $ank['level'] < $user['level'])) {
        echo "<a href = 'adm_log.php?id=$ank[id]'>$ank[nick]</a> ($ank[group_name])";
    } else {
        echo "<a href = '/id$ank[id]'>$ank[nick]</a> ($ank[group_name])";
    }

    $adm_log_c_all = mysql_result(mysql_query("SELECT COUNT(*) FROM `admin_log` WHERE `id_user` = '$ank[id]'"), 0);
    $mes = mktime(0, 0, 0, date('m') - 1); // время месяц назад
    $adm_log_c_mes = mysql_result(mysql_query("SELECT COUNT(*) FROM `admin_log` WHERE `id_user` = '$ank[id]' AND `time` > '$mes'"), 0);

    echo "<br />";
    echo "Вся активность: $adm_log_c_all<br />";
    echo "Активность за месяц: $adm_log_c_mes<br />";
    echo "Посл. посещение: " . date::time($ank['date_last']) . "<br />";

    if (isset($user) && ($user['level'] > $ank['level'] || $user['level'] == 4)) {
        echo "<br /><a href='user.php?id=$ank[id]'><i class='fa fa-pencil fa-fw'></i> " . lang('Редактировать профиль') . "</a><br />";
    }

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

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

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