<?php

function user($user = NULL) {

    global $set, $time;
    $db = new db;

    $ank = $db->get_row($db->query("SELECT id, nick, browser, us_browser, country, activity, online, sex, rating, money, ncolor, ncolor2, group_access, date_reg, date_last FROM user WHERE id = '$user' LIMIT 1"));
    $ash = $db->get_row($db->query("SELECT * FROM user_icon WHERE id_user = '$ank[id]' LIMIT  1"));
    $ban_user = $db->super_query("SELECT COUNT(*) as count FROM `ban` WHERE `id_user` = '$user' AND `time` > '" . time() . "'");
    $ban_user = $ban_user['count'];
    $online = $ank['date_last'] > (time() - $set['user_online']);
    # Какашка
    if ($ban_user) {
        $icon = ' <i class="fa fa-legal fa-fw" style="color: blue;"></i> ';
    } else {
        # Администраторы	
        if ($ank['group_access'] > 7 and ! $online) {
            $icon = ' <i class="fa fa-user fa-fw" style="color: grey;"></i> ';
        } else
        if ($ank['group_access'] > 7) {
            $icon = ' <i class="fa fa-user fa-fw" style="color: black;"></i> ';
        }
        # Модераторы
        else
        if ($ank['group_access'] > 1 and $ank['group_access'] < 7 and ! $online) {
            $icon = ' <i class="fa fa-user fa-fw" style="color: grey;"></i> ';
        } else
        if ($ank['group_access'] > 1 and $ank['group_access'] < 7) {
            $icon = ' <i class="fa fa-user fa-fw" style="color: #8B00CC;"></i> ';
        }
        # Пользователи
        else {
            $icon = !$online ? '<i class="fa fa-user fa-fw" style="color: grey;"></i>' : ' ' . ($ank['sex'] == 1 ? "<i class='fa fa-user fa-fw' style='color: #7F92FF;'></i>" : "<i class='fa fa-user fa-fw' style='color: #FF7F7F;'></i>") . ' ';
        }
    }

    if ($ank['id'] > 0) {
        if ($ash['time'] >= $time) {
            $imag = $db->get_row($db->query("SELECT id_icon FROM user_icon WHERE id_user = '" . $ank['id'] . "' LIMIT 1"));
            echo "<a href='/id$ank[id]'><img src='/user/icon/png/$imag[id_icon].png' style='padding-right: 3px;margin-top: -4px;'/> <b>";
            echo gradient("$ank[nick]", "$ank[ncolor]", "$ank[ncolor2]");
            echo "</b></a> ";
        } else {
            echo "<a href = '/id$ank[id]'>$icon <b>";
            echo gradient("$ank[nick]", "$ank[ncolor]", "$ank[ncolor2]");
            echo "</b></a> ";
        }
    } elseif ($ank['id'] == 0) {
        echo "Система ";
    }


    if ($ank['group_access'] > 1) {

        if ($ank['group_access'] == 1) {
            $gr = lang('Пользователь');
        } elseif ($ank['group_access'] == 2) {
            $gr = lang('Модератор форума');
        } elseif ($ank['group_access'] == 3) {
            $gr = lang('Модератор загруз-центра');
        } elseif ($ank['group_access'] == 4) {
            $gr = lang('Модератор блогов');
        } elseif ($ank['group_access'] == 5) {
            $gr = lang('Модератор фотогалереи');
        } elseif ($ank['group_access'] == 6) {
            $gr = lang('Супермодератор');
        } elseif ($ank['group_access'] == 7) {
            $gr = lang('Администратор');
        } elseif ($ank['group_access'] == 8) {
            $gr = lang('Главный администратор');
        } elseif ($ank['group_access'] == 15) {
            $gr = lang('Создатель');
        }
    }

    if ($ank['date_last'] > (TIME - 600)) {
        if ($ank['browser'] == 'web') {
            echo " <font color='green' title='Пользователь с компьютера'><i class='fa fa-laptop fa-fw'></i></font>";
        } else {
            echo " <font color='green' title='Пользователь с телефона'><i class='fa fa-mobile fa-fw'></i></font>";
        }
    } else {
        if ($ank['browser'] == 'web') {
            echo " <font color='grey' title='Пользователь с компьютера'><i class='fa fa-laptop fa-fw'></i></font>";
        } else {
            echo " <font color='grey' title='Пользователь с телефона'><i class='fa fa-mobile fa-fw'></i></font>";
        }
    }

    getbrowser_($ank['us_browser']);

    $dr = $db->get_row($db->query("SELECT * FROM user WHERE id = '$ank[id]' AND ank_d_r = '" . date('d') . "' AND ank_m_r = '" . date('m') . "' ORDER by rand() LIMIT 1"));
    if ($dr['id']) {
        echo " <i class='fa fa-birthday-cake fa-fw' style='color: orange;'></i> ";
    }
    unset($dr);
}
