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

$k_post = $db->super_query("SELECT COUNT(`user`.`id`) as count 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");
$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 `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 = $db->get_row($q)) {
    $ank = get_user($ank['id']);

    echo "<table class='list-group-item-null-mini list-group-item-grey dop'><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])";
    }
    $k = $db->super_query("SELECT COUNT(*) as count FROM `admin_log` WHERE `id_user` = '$ank[id]'");
    $adm_log_c_all = $k['count'];
    $mes = mktime(0, 0, 0, date('m') - 1); #время месяц назад
    $k = $db->super_query("SELECT COUNT(*) as count FROM `admin_log` WHERE `id_user` = '$ank[id]' AND `time` > '$mes'");
    $adm_log_c_mes = $k['count'];

    echo "<br />";
    echo "Вся активность: $adm_log_c_all<br />";
    echo "За месяц: $adm_log_c_mes<br />";
    echo "Посл. онлайн: " . date::times($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-edit fa-fw'></i> " . lang('Редактировать профиль') . "</a><br />";
    }

    echo "</td></tr></table>";
}

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

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