<?php

function icon_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 " <img src='/user/icon/png/$imag[id_icon].png' style='padding-right: 3px;margin-top: -4px;'/> ";
        } else {
            echo " $icon ";
        }
    } elseif ($ank['id'] == 0) {
        echo '<i class="fa fa-at fa-fw"></i> ';
    }
}
