<?php

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

$i = 0;
$inc_foto = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_user` = '$ank[id]' ORDER BY `id` DESC"), 0);
$foto_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery` WHERE `id_user` = '$ank[id]'"), 0);
$foto_count_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery` WHERE `id_user` = '$ank[id]' AND `time` > '" . (time() - 86400) . "'", $db), 0);
$foto_photo = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_user` = '$ank[id]'"), 0);
$users = mysql_result(mysql_query("SELECT COUNT(id_user) FROM `bookmark_user` WHERE `id_user` = '" . $ank['id'] . "'"), 0);
$gifts = mysql_result(mysql_query("SELECT COUNT(id_user) FROM `gifts` WHERE `id_user` = '" . $ank['id'] . "'"), 0);
$blog = mysql_result(mysql_query("SELECT COUNT(id_user) FROM `diary` WHERE `id_user` = '" . $ank['id'] . "'"), 0);
$files = mysql_result(mysql_query("SELECT COUNT(*) FROM `loads_list` WHERE `id_user` = '$ank[id]'"), 0);
$ocenky = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_rating` WHERE `avtor` = '$ank[id]'"), 0);
$log = mysql_result(mysql_query("SELECT COUNT(*) FROM `history_nick` WHERE `user_id` = '$ank[id]'"), 0);
$refs = mysql_num_rows(mysql_query("select * from `user_referals` WHERE `id_ref` = '" . $ank['id'] . "'"));
$fotos = mysql_result(mysql_query("SELECT COUNT(id_user) FROM `bookmark_foto` WHERE `id_user` = '" . $ank['id'] . "'"), 0);
$bookmark_count = $users + $fotos;
$black_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `user_blacklist` WHERE `id_user` = '$ank[id]'"), 0);
$guests = mysql_result(mysql_query("SELECT COUNT(*) FROM `myguests` WHERE `id_ank` = '$ank[id]'"), 0);
$guests_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `myguests` WHERE `id_ank` = '$ank[id]' AND `time` > '" . (time() - 86400) . "'", $db), 0);
if ($guests_new == 0) {
    $guests_new = NULL;
} else {
    $guests_new = " +$guests_new";
}
$k_fr = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `user` = '$ank[id]' AND `i` = '1'"), 0);
###########################################################7.2.1
$not = mysql_result(mysql_query("SELECT COUNT(`read`) FROM `notification` WHERE `id_kont` = '$user[id]'"), 0);
$not_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `notification` WHERE `id_kont` = '$user[id]' AND `time` > '" . (time() - 86400) . "'", $db), 0);

$nots = mysql_result(mysql_query("SELECT COUNT(`read`) FROM `notifications` WHERE `id_kont` = '$user[id]'"), 0);
$nots_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `notifications` WHERE `id_kont` = '$user[id]' AND `time` > '" . (time() - 86400) . "'", $db), 0);

$event = mysql_result(mysql_query("SELECT COUNT(`read`) FROM `events` WHERE `id_kont` = '$user[id]'"), 0);
$event_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `events` WHERE `id_kont` = '$user[id]' AND `time` > '" . (time() - 86400) . "'", $db), 0);

$not = $not + $nots + $event;
$not_new = $event_new + $not_new + $nots_new;

if ($not_new > 0) {
    $not = "$not +$not_new";
} else {
    $not = $not;
}
############################################################
$count_gifts = mysql_num_rows(mysql_query("SELECT * FROM `gifts` WHERE `id_user` = '$ank[id]'"));

if ($count_gifts > 0) {
    echo "<div class='list-group-item-null'>";
}

$query = mysql_query("SELECT * FROM `gifts` WHERE `id_user` = '$ank[id]' ORDER BY `time` DESC LIMIT 6");

while ($post = mysql_fetch_array($query)) {
    $gift = mysql_fetch_array(mysql_query("SELECT * FROM `gift` WHERE `id` = '$post[id_gift]'"));
    echo "<a href = '/modules/gifts/?id=$ank[id]&amp;gift=$post[id]' style = 'margin-right:4px;'><img src = '/modules/gifts/images/$gift[image]' width = '40' height = '40' /></a>\n";
}
if ($count_gifts > 6) {
    echo " <a href = '/modules/gifts/?id=$ank[id]' style = 'margin-left: 4px;text-decoration: none;'><span style = 'font-size: large;text-decoration: none;vertical-align: bottom;'>&raquo;</span></a>";
}
if ($count_gifts > 0) {
    echo "</div>";
}

##############################################################Обновлено с 7.2.1
if ($user['set_profile'] == 1) {
    echo "<div class='list-group-item-null'>";
    echo "<div class='tile-menu'>";
    if (isset($user)) {
        echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/anketa/?name=$ank[nick]'><div class='menu_picat'><i class='fa fa-user fa-3x'></i></div> <div class='menu_title_s'>" . lang('Анкета') . "</div></a></div>";
    }
    echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/bookmark/?id=$ank[id]'><span class='hint--bottom' data-hint='$bookmark_count'><div class='menu_picat'><i class='fa fa-bookmark fa-3x'></i></div> <div class='menu_title_s'> " . lang('Закладки') . "</div></span></a></div>";
    echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/modules/foto/$ank[id]/'><span class='hint--bottom' data-hint='$foto_photo'><div class='menu_picat'><i class='fa fa-photo fa-3x'></i></div> <div class='menu_title_s'> " . lang('Фотографии') . " </div></span></a></div>";
    if (isset($user) && $user['id'] == $ank['id']) {
        echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/modules/foto/ocenky.php?id=$ank[id]'><span class='hint--bottom' data-hint='$ocenky'><div class='menu_picat'><i class='fa fa-html5 fa-3x'></i></div> <div class='menu_title_s'> " . lang('Оценки к фото') . " </div></span></a></div>";
    }
    echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/modules/gifts/index.php?id=$ank[id]'><span class='hint--bottom' data-hint='$gifts'><div class='menu_picat'><i class='fa fa-gift fa-3x'></i></div> <div class='menu_title_s'> " . lang('Подарки') . "</div></span></a></div>";
    echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/modules/diary/user.php?id=$ank[id]'><span class='hint--bottom' data-hint='$blog'><div class='menu_picat'><i class='fa fa-book fa-3x'></i></div> <div class='menu_title_s'> " . lang('Блоги') . "</div></span></a></div>";
    echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/files.php?id=$ank[id]'><span class='hint--bottom' data-hint='$files'><div class='menu_picat'><i class='fa fa-file fa-3x'></i></div> <div class='menu_title_s'> " . lang('Файлы') . "</div></span></a></div>";
    echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/friends/?id=$ank[id]'><span class='hint--bottom' data-hint='$k_fr'><div class='menu_picat'><i class='fa fa-users fa-3x'></i></div> <div class='menu_title_s'> " . lang('Друзья') . " </div></span></a></div>";

    if (isset($user) && $user['id'] == $ank['id']) {
        echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/guests.php'><span class='hint--bottom' data-hint='$guests$guests_new'><div class='menu_picat'><i class='fa fa-eye fa-3x'></i></div> <div class='menu_title_s'> " . lang('Гости') . "</div></span></a></div>";
        echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/mail/'><div class='menu_picat'><i class='fa fa-envelope fa-3x'></i></div> <div class='menu_title_s'> " . lang('Сообщения') . "</div></a></div>";
        echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/blacklist/'><span class='hint--bottom' data-hint='$black_count'><div class='menu_picat'><i class='fa fa-ban fa-3x'></i></div> <div class='menu_title_s'> " . lang('Черный список') . "</div></span></a></div>";
        echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/notification/'><span class='hint--bottom' data-hint='$not'><div class='menu_picat'><i class='fa fa-bell fa-3x'></i></div> <div class='menu_title_s'> " . lang('Уведомления') . "</div></span></a></div>";
    }
    echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/referals/?id=$ank[id]'><span class='hint--bottom' data-hint='$refs'><div class='menu_picat'><i class='fa fa-map-marker fa-3x'></i></div> <div class='menu_title_s'> " . lang('Рефералы') . "</div></span></a></div>";
    echo "<div class='menu_wrapeer'><a class='menu_link_s' href='/user/history_login.php?id=$ank[id]'><span class='hint--bottom' data-hint='$log'><div class='menu_picat'><i class='fa fa-i-cursor fa-3x'></i></div> <div class='menu_title_s'> " . lang('История логинов') . " </div></span></a></div>";

    echo "</div>";
    echo "</div>";
} else {
    echo "<div class='list-group'>";
    if (isset($user)) {
        echo "<a href='/user/anketa/?name=$ank[nick]' class='list-group-item'><i class='fa fa-user fa-fw'></i> " . lang('Анкета') . "</a>";
    }
    echo "<a href='/user/bookmark/?id=$ank[id]' class='list-group-item'><i class='fa fa-bookmark fa-fw'></i> " . lang('Закладки') . " <span class='badge' style='float:right;'>$bookmark_count</span></a>";
    echo "<a href='/modules/foto/$ank[id]/' class='list-group-item'><i class='fa fa-photo fa-fw'></i> " . lang('Фотографии') . " <span class='badge' style='float:right;'>$foto_photo</span></a>";
    if (isset($user) && $user['id'] == $ank['id']) {
        echo "<a href='/modules/foto/ocenky.php?id=$ank[id]' class='list-group-item'><i class='fa fa-html5 fa-fw'></i> " . lang('Оценки к фото') . " <span class='badge' style='float:right;'>$ocenky</span></a>\n";
    }
    echo "<a href='/modules/gifts/index.php?id=$ank[id]' class='list-group-item'><i class='fa fa-gift fa-fw'></i> " . lang('Подарки') . " <span class='badge' style='float:right;'>$gifts</span></a>";
    echo "<a href='/modules/diary/user.php?id=$ank[id]' class='list-group-item'><i class='fa fa-book fa-fw'></i> " . lang('Блоги') . " <span class='badge' style='float:right;'>$blog</span></a>";
    echo "<a href='/user/files.php?id=$ank[id]' class='list-group-item'><i class='fa fa-file fa-fw'></i> " . lang('Файлы') . " <span class='badge' style='float:right;'>$files</span></a>";
    echo "<a href='/user/friends/?id=$ank[id]' class='list-group-item'><i class='fa fa-users fa-fw'></i> " . lang('Друзья') . " <span class='badge' style='float:right;'>$k_fr</span></a>";

    if (isset($user) && $user['id'] == $ank['id']) {
        echo "<a href='/user/guests.php' class='list-group-item'><i class='fa fa-eye fa-fw'></i> " . lang('Гости') . " <span class='badge' style='float:right;'>$guests$guests_new</span></a>";
        echo "<a href='/user/mail/' class='list-group-item'><i class='fa fa-envelope fa-fw'></i> " . lang('Сообщения') . "</a>";
        echo "<a href='/user/blacklist/' class='list-group-item'><i class='fa fa-ban fa-fw'></i> " . lang('Черный список') . " <span class='badge' style='float:right;'>$black_count</span></a>";
        echo "<a href='/user/notification/' class='list-group-item'><i class='fa fa-bell fa-fw'></i> " . lang('Уведомления') . " <span class='badge' style='float:right;'>$not</span></a>";
    }
    echo "<a href='/user/referals/?id=$ank[id]' class='list-group-item'><i class='fa fa-map-marker fa-fw'></i> " . lang('Рефералы') . " <span class='badge' style='float:right;'>$refs</span></a>";
    echo "<a class='list-group-item' href='/user/history_login.php?id=$ank[id]'><i class='fa fa-i-cursor fa-fw'></i> " . lang('История логинов') . " <span class='badge' style='float:right;'>$log</span></a>";

    echo "</div>";
}

include H . 'user/friends/include.php';
#################################################################Конец обновления
#
#Видно другому пользователю, вам не видно
if (isset($user) && $user['id'] != $ank['id']) {
    if (isset($user) && $user['level'] > $ank['level'] && $user['id'] != $ank['id']) {

        if (access('user_prof_edit')) {
            $doc->Link('list-group-item-null list-group-item-info', "/panel/user.php?id=$ank[id]", 'edit', 'Редактировать профиль');
        }
        if (access('user_ban_set') || access('user_ban_set_h') || access('user_ban_unset')) {
            $doc->Link('list-group-item-null list-group-item-info', "/panel/ban.php?id=$ank[id]", 'gavel', 'Дать бан');
        }
        if (access('user_delete')) {
            $doc->Link('list-group-item-null list-group-item-info', "/panel/delete_user.php?id=$ank[id]", 'user-times', 'Удалить');
            $mass[0] = $ank['id'];
            if (access('collisions') && count(collision($mass, 1)) > 1) {
                $doc->Link('list-group-item-null list-group-item-info', "/panel/delete_user.php?id=$ank[id]&amp;all", 'user-times', 'Удалить все уч. записи');
            }
        }
        if (access('adm_log_read') && $ank['level'] && ($ank['id'] == $user['id'] || $ank['level'] < $user['level'])) {
            $doc->Link('list-group-item-null list-group-item-info', "/panel/adm_log.php?id=$ank[id]", 'list-alt', 'Отчет действий');
        }
    }
}
    