<?php

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

function avatar($id, $width = '48', $style = null, $class = 'avatar') {
    global $set;

    $db = new db;

    $p = $db->get_row($db->query("SELECT * FROM `user` WHERE `id`='$id'  LIMIT 1"));
    $a = $db->get_row($db->query("SELECT * FROM `gallery_foto` WHERE `id_user`='$id' AND `avatar`='1' LIMIT 1"));

    if (is_file(H . "sys/gallery/avatar/$a[id].$a[ras]")) {
        echo "<div style='display:inline;'><img src='/modules/foto/foto150/$a[id].$a[ras]' alt='$a[name]' style='width: {$width}px; $style' class='$class' /></div>";
        $rat = $db->super_query("SELECT COUNT(*) as count FROM `gallery_rating` WHERE `id_foto` = $a[id] AND `like` = '6'");
        if ($rat['count'] > 0) {
            if ($width > 100) {
                echo "<div style='display:inline;margin-left:-35px;vertical-align:top;'><img style='padding-top:10px;' src='/style/icons/6.png'/></div>";
            } else {
                echo "";
            }
        }
    } else {
        echo "<div style='display:inline;'><img src='/style/icons/user_r.png' style='width: {$width}px; $style' class='$class'/></div>";
    }
}

function avatars($id, $px = '40') {
    global $set;

    $ank = get_user($id);

    if ($ank['sex'] == 0) {
        $sex = 'zh.jpg';
    } else {
        $sex = 'm.jpg';
    }
    if (is_file(H . "user/avatar/$id.gif")) {
        echo "<img src='/user/avatar/$id.gif' style = 'width: {$px}px;height: {$px}px' class = 'img-circle media-object'/>\n";
    } elseif (is_file(H . "user/avatar/$id.jpg")) {
        echo "<img src='/user/avatar/$id.jpg' style = 'width: {$px}px;height: {$px}px' class = 'img-circle media-object'/>\n";
    } elseif (is_file(H . "user/avatar/$id.png")) {
        echo "<img src='/user/avatar/$id.png' style = 'width: {$px}px;height: {$px}px' class = 'img-circle media-object'/>\n";
    } else {
        echo "<img src='/user/avatar/$sex' style = 'width: {$px}px;height: {$px}px' class = 'img-circle media-object'/>\n";
    }
}

function avatar_p($id, $px) {
    global $set;

    $ank = get_user($id);

    if ($ank['sex'] == 0) {
        $sex = 'zh.jpg';
    } else {
        $sex = 'm.jpg';
    }
    if (is_file(H . "user/avatar/$id.gif")) {
        echo "<img src='/user/avatar/$id.gif' style = 'width: {$px}px;height: auto' class = 'avatar'/>\n";
    } elseif (is_file(H . "user/avatar/$id.jpg")) {
        echo "<img src='/user/avatar/$id.jpg' style = 'width: {$px}px;height: auto' class = 'avatar'/>\n";
    } elseif (is_file(H . "user/avatar/$id.png")) {
        echo "<img src='/user/avatar/$id.png' style = 'width: {$px}px;height: auto' class = 'avatar'/>\n";
    } else {
        echo "<img src='/user/avatar/$sex' style = 'width: {$px}px;height: auto' class = 'avatar'/>\n";
    }
}

function avatar_path($id_user) {
    $ava = glob(H . 'user/avatar/' . $id_user . '.*');
    if ($ava) {
        return str_replace(H, '/', $ava[0]);
    } else {
        return false;
    }
}
