<?php

include 'system/sys.php';
include 'system/funcs.php';

if (!isset ($us)) {
        header ('location: /');
        exit;
}

if (!isset ($_GET['id'])) {
        header ('location: /');
        exit;
}

$query = DB :: $dbs -> query ("SELECT * FROM `us` WHERE (`id`=?)", array ((int) $_GET['id']));
if ($query -> rowCount () == 0) {
        header ('location: /');
        exit;
}

$u = $query -> fetch ();

H ('Страница ' . $u['nick'], uNick ($u['id']));


$query = DB :: $dbs -> query ("SELECT * FROM `reg` WHERE (`us`='" . $u['id'] . "') AND (`dop` != '')");
if ($query -> rowCount () != 0) {
        $reg = $query -> fetch ();
        $kem = DB :: $dbs -> queryFetch ("SELECT * FROM `us` WHERE `id`='" . $reg['kem'] . "'");
        echo '<div class="list1">Регистрацию ' . ( ( $reg['dop'] == 'da') ? 'подтвердил' : 'отклонил' ) . ($kem['sex']=='Муж'?'':'а') . ' ' . uNick ($reg['kem']) . '</div>';
}
$query = DB :: $dbs -> query ("SELECT * FROM `ban` WHERE (`us`='" . $u['id'] . "') AND (`end`>'" . time () . "')");
if ($query -> rowCount () != 0) {

        $ban = $query -> fetch ();
        
        echo '<div class="list1">';
        echo '<b style="color:red;">Пользователь в бане!</b><br/>';
        echo 'Причина: <b>' . $ban['text'] . '</b><br/>';
        echo 'Дата бана: <b>' . date ('d.m.Y в H:i:s', $ban['time']) . '</b><br/>';
        echo 'Дата освобождения: <b>' . date ('d.m.Y в H:i:s', $ban['end']) . '</b>';

        $who = DB :: $dbs -> queryFetch ("SELECT * FROM `us` WHERE (`id`='" . $ban['who'] . "')");
        if ($who['id'] == $us['id'] || $us['level'] > $who['level']) {

                if (isset($_GET['unban'])) {
                        DB :: $dbs -> query ("UPDATE `ban` SET `end`='" . time () . "' WHERE (`id`='" . $ban['id'] . "')");
                        header ('location:/us' . $u['id']);
                }
            
if ($u['id']!=$us['id'] && $u['level']<$us['level']) {
                echo ' [<a href="/us'.$u['id'].'?unban">x</a>]';
}
        
        }
        
        echo '</div>';

}


if ($u['offical']==1) {
        $offical .= '<img src="/images/menu/offical.png" alt="*" align="right" style="width: 24px;height: 24px;"/>  ';
}

echo '<div class="list1">';
echo '<span style="color:#818181;">&#187; Зарегистрирован' . ($u['sex']=='Муж'?'':'а') . ':</span> ' . datef ($u['reg']) . ' ' . $offical . '<br/>';
echo '<span style="color:#818181;">&#187; Последняя активность:</span> '. datef ($u['last']).'<br/>';

//
if ($u['online']!=0) {
        echo '<span style="color:#818181;">&#187; Пров' . ($u['sex']=='Муж'?'ёл':'ела') . ' на сайте:</span> ' . timef ($u['online']).'<br/>';
}



     if ($u['level']  > 3) $level = '<b style="color:red;">Создатель</b>';
else if ($u['level'] == 3) $level = '<b style="color:red;">Ст. Админ</b>';
else if ($u['level'] == 2) $level = '<b style="color:red;">Админ</b>';
else if ($u['level'] == 1) $level = '<b style="color:red;">Модер</b>';
else                       $row = '<b style="color:green;">Пользователь</b>';
if ($u['row']  > 5) $row = '<font color=red><b>Знаток</b></font>';
if ($u['row']  > 4) $row = '<font color=Khaki><b>MASTER</b></font>';
else if ($u['row'] == 3) $row = '<font color=#FF8C00><b>PRO</b></font>';
else if ($u['row'] == 2) $row = '<font color=Gold><b>Старожил</b></font>';
else if ($u['row'] == 1) $row = '<font color=green><b>Постоялец</b></font>';
else                       $row = '<font color=red><b>Новичок</b></font>';

// 
if ($u['jur']==1) {
        $level .= ' | <b style="color: green;">Журналист газеты</b>';
}

echo'&#187;   Уровень: ' . $level . '<br/>&#187;   Статус: <a href="/status.php">' . $row . '</a> | ID: <b>' . $u['id'] . '</b></br>';
echo '</div>';
echo '<div class="list1"><img src="' . (file_exists ('./files/avs/' . $u['id'] . '.jpg') ? 'files/avs/'.$u['id'].'.jpg' : 'images/noava.png') .'" width="300" style="border-radius: 10px" /></a></div>';
if ($us['id']!=$u['id']) {
        echo '<div class="raz"><img src="/images/004.png" alt=""/> <a href="/msg' . $u['id'] . '">Написать сообщение</a></div>';

        $query = DB :: $dbs -> query ("SELECT * FROM `ignor` WHERE (`us`='" . $us['id'] . "') AND (`kem`='" . $u['id'] . "')");
        echo '<div class="raz"><img src="/images/' . ($query -> rowCount () != 0 ? 'yes':'stop_2') . '.png" alt=""/> <a href="/msg' . $u['id'] . '?ignor">' . ($query -> rowCount () != 0 ? 'Убрать из игнора' : 'В игнор') . '</a></div>';

        $query = DB :: $dbs -> query ("SELECT * FROM `favorit` WHERE (`kem`='" . $us['id'] . "') AND (`us`='" . $u['id'] . "')");
        echo '<div class="raz"><img src="/images/' . ($query -> rowCount () != 0 ? 'blue_favorites' : 'favorites_folder') . '.png" alt=""/> <a href="/favorit.php?u=' . $u['id'] . '">' . ($query -> rowCount () != 0 ? 'Убрать из избранных' : 'В избранное') . '</a></div>';
        
        
        
        $query = DB :: $dbs -> query ("SELECT * FROM `podp` WHERE (`us`='" . $us['id'] . "') AND (`na`='" . $u['id'] . "')");
        if (isset ($_GET['pods'])) {
            
                if ($query -> rowCount () == 0) {
                    DB :: $dbs -> query ("INSERT INTO `podp` (`us`, `na`) VALUES ('" . $us['id'] . "', '" . $u['id'] . "')");
                }
                else {
                    DB :: $dbs -> query ("DELETE FROM `podp` WHERE (`us`='" . $us['id'] . "') AND (`na`='" . $u['id'] . "')");
                }
                
                header ('location: /us' . $u['id']);
            
        }
        echo '<div class="raz"><img src="/images/' . ($query -> rowCount () == 0 ? 'kontact-news' : 'news_unsubscribe') . '.png" alt=""/> <a href="/us.php?id=' . $u['id'] . '&pods">' . ($query -> rowCount () == 0 ? 'Подписаться на новости' : 'Отписаться от новостей') . '</a></div>';
        
}



echo '<div class="menu2">Личные данные</div>';
echo '<div class="ram">';
echo '<div class="raz">';

$query = DB :: $dbs -> query ("SELECT * FROM `nicks` WHERE (`us`='" . $u['id'] . "')");
echo '<img src="/images/menu/refresh.gif" alt="*" style="width:16px;height:16px;"/> <a href="/us' . $u['id'] . '?nicks">История ников</a> (' . $query -> rowCount () .')';

    if (isset ($_GET['nicks'])) {
            echo '<div class="list1">';
        
    if($query -> rowCount () == 0) {
            echo uNick ($u['id']) . ' не менял ник!';
    }
    else {
        
            $query = DB :: $dbs -> query ("SELECT * FROM `nicks` WHERE (`us`='" . $u['id'] . "') ORDER BY `id` DESC");
            while ($nick = $query -> fetch ()) {
                    echo '<b>' . $nick['old'] . '</b> -> <b>' . $nick['new'] . '</b><br>Сменил: ' . uNick ($nick['kem']) . ' (' . datef ($nick['time']) . ')<hr/>';
            }
   
    }

    echo '</div>';

}

echo '</div>';

if ($u['id'] != $us['id'] && $u['ank'] == 0) {
        echo '<div class="lst">';
        echo 'Вы не можете просматривать анкетные данные пользователя ' . uNick ($u['id']) . ', так как он предпочёл их скрыть!';
        echo '</div>';
}
else {

        if (!empty ($u['name'])) {
                echo '<div class="list1"><img src="/images/ank/name.png" alt="*" /> Имя: ' . $u['name'] . ' </div>';
        }
        
        echo '<div class="list1"><img src="/images/ank/users.png" alt="*" style="width:16px;height:16px;"/> Пол: ' . $u['sex'] . '</div>';
        
        echo '<div class="list1"><img src="/images/ank/calendar.png" alt="*" style="width:16px;height:16px;"/> Дата рождения: ' . $u['birthday'] . '</div>';
        
        if (!empty ($u['country'])) {
                echo '<div class="list1"><img src="/images/ank/globe.png" alt="*" style="width:16px;height:16px;"/> Страна: ' . $u['country'] . '</div>';
        }
        
        if (!empty ($u['city'])) {
                echo '<div class="list1"><img src="/images/ank/stran.png" alt="*" /> Город: ' . $u['city'] . '</div>';
        }
        if (!empty ($u['icq'])) {
echo '<div class="list1">&#187; ICQ: ' . $u['icq'] . '</div>';
}
if (!empty ($u['skype'])) {
echo '<div class="list1">&#187; SKYPE: ' . $u['skype'] . '</div>';
}
if (!empty ($u['site'])) {
echo '<div class="list1">&#187; Сайт: <a href="' . $u['site'] . '">' . $u['site'] . '</a></div>';
}
        if (!empty ($u['about'])) {
                echo '<div class="list1"><img src="/images/ank/o_seb.png" alt="*" /> О себе: ' . bb ($u['about']) . '</div>';
        }
        
        /* Для безопасности
         * if (!empty ($u['email'])) {
            
            echo '
            <div class="list1">
                E-mail: ' . $u['email'] . '
            </div>
            ';
        }
        */


}

echo '</div>';


echo '</div><div class="menu2">Реквизиты: WEBMONEY</div>' ;
if($u['wmid'] == NULL){
echo '<div class="list1">WMID не заполнен! Не рекомендуем проводить денежные операции! </div>';
} else {
echo '<div class="list1">
<img src="/images/wm/wmid.png"alt="*">WMID: <a href="http://passport.webmoney.ru/asp/certview.asp?wmid='.$u['wmid'].'">'.$u['wmid'].'</a> [<b>'.($u['wmid_pod']==0?'<font color="red">Не подтвержден</font>':'<font color="green">Подтвержден</font>').'</b>]<br/>
<img src="/images/menu/ups.png" height="16 "alt="*"> BL <img src="https://bl.wmtransfer.com/img/bl/'.$u['wmid'].'?w=45&h=18&bg=0XDBE2E9"> <br/>
<img src="/images/menu/ups.png" height="16 "alt="*"> Претензии/Отзывы: <img src="http://arbitrage.webmoney.ru/xml/AL.aspx?wmid='.$u['wmid'].'" /><br/>
<img src="/images/wm/kosh.png" height="16 "alt="*">  WMR: R'.$u['wmr'].'</div>';
}
echo '</div><div class="menu2">Реквизиты: QIWI</div>' ;
if($u['qiwi'] == NULL){
echo '<div class="list1">QIWI не заполнен! Не рекомендуем проводить денежные операции! </div>';
} else {
echo '<div class="list1"><img src="/images/wm/qiwi.png"> QIWI: '.$u['qiwi'].' [<b>'.($u['qiwi_pod']==0?'<font color="red">Не подтвержден</font>':'<font color="green">Подтвержден</font>').'</b>]</div>';
}
echo '<div class="menu2">Информация и Активность</div>';
echo '<div class="ram">';

//
echo '<div class="raz"><img src="/images/theme.png" alt=""/> Тем в  <a href="/thems' . $u['id'] . '">форуме</a>: ' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `forum_t` WHERE (`us` = '" . $u['id'] . "')") . '</div>';

//
echo '<div class="raz"><img src="/images/txt4.png" alt=""/> Постов в  <a href="/posts' . $u['id'] . '">форуме</a>: ' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `forum_p` WHERE (`us`='" . $u['id'] . "')") . ' (Сегодня: ' .  DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `forum_p` WHERE (`us`='" . $u['id'] . "') " . ($us['level'] > 0 ? '' : 'AND (`del`=\'0\')') . " AND (`time`>'" . (time () - 86400) . "')") . ')</div>';

//
echo '<div class="raz"><img src="/images/comments.png" alt=""/> Комментариев: <a href="/uskomments.php?id=' . $u['id'] . '">' . ( DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `news_komm` WHERE (`us`='" . $u['id'] . "')") + DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `zc_komm` WHERE (`us`='" . $u['id'] . "')") ) . '</a></div>';

//
echo '<div class="raz"><img src="/images/files2.png" alt=""/> <a href="/files.php?id=' . $u['id'] . '">Файлы</a> (' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `zc_f` WHERE (`us`='" . $u['id'] . "') AND (`dop`='da')") . ')</div>';

if ($u['id']!=$us['id'] && $u['new']==0) {
    //
}

echo '</div>';

echo '<div class="menu2">Репутация на сайте</div>';
echo '<div class="ram">';

//

//
echo '<div class="raz"><img src="/images/clean.png" alt=""/> <a href="/senk' . $u['id'] . '">Поблагодарили</a> [' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `senk` WHERE (`komu`='" . $u['id'] . "')") . ']</div>';

echo '<div class="raz"><img src="/images/arb.png" alt=""/><a href="/arbitraz.php?id=' . $u['id'] . '"> Арбитраж:</a> (' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `arbitraz` WHERE (`komy`='" . $_GET['id'] . "') AND (`check`='1')") . ')</div>';
//
echo '<div class="raz"><img src="/images/rating.png" alt=""/> Рейтинг: <font color="green">' . $u['reit'] . '</font></div>';
echo '<div class="raz"><img src="/images/zar.png" alt=""/> Уровень доверия: <font color="green"><b>' . $u['dover'] . ' %</b></font></div>';

//
echo '<div class="raz"><img src="/images/infr.png" alt=""/> <a href="/nar' . $u['id'] . '">Пенализации</a> [' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `nar` WHERE (`us`='" . $u['id'] . "')") . ']</div>';

echo '</div>';
echo '<div class="menu2">Меню пользователя</div>';

if ($u['mosh'] != 0) {
        
        echo '<div class="list1">';
        echo '<img src="/images/block.png" alt="" align="middle"/> <b style="color: red;">Данный пользователь - мошенник!</b>';

        $usk = DB :: $dbs -> queryFetch ("SELECT * FROM `us` WHERE (`id`='" . $u['mosh'] . "')");
        if ($usk['id'] == $us['id'] || $us['level']>$usk['level']) {
                if (isset ($_GET['mosh'])) {
                        DB :: $dbs -> query ("UPDATE `us` SET `mosh`='0' WHERE (`id`='" . $u['id'] . "')");
                        header ('location: /us' . $u['id']);
                }
                echo ' [<a href="/us' . $u['id'] . '?mosh">Убрать с доски </a>]';
        }
        echo '</div>';
        
}
else {
    if ($u['id']!=$us['id'] && $u['level']<$us['level']) {
        if (isset ($_GET['mosh'])) {
                DB :: $dbs -> query ("UPDATE `us` SET `mosh`='" . $us['id'] . "' WHERE (`id`='" . $u['id'] . "')");
                header ('location: /us' . $u['id']);
        }
        echo '<div class="list1"><a href="/us' . $u['id'] . '?mosh">Повесить клеймо мошенника</a></div>';
    }
}

// 
if ($u['id']==$us['id'] && $us['level']>3 || $u['level']<$us['level'] && $us['level']>3) {
        echo '<div class="list1"><a href="/adm/us.php?id=' . $u['id'] . '">Редактировать данные</a></div>';
} 
// 
if ($u['id']!=$us['id'] && $u['level']<$us['level']) {
        echo '<div class="list1"><a href="/adm/mail.php?id=' . $u['id'] . '">Просмотр почты</a></div>';
}


// 
if ($u['id']==$us['id'] && $us['level']>0 || $u['level']<$us['level'] && $us['level']>0) {
        echo '<div class="list1"><a href="/adm/nick.php?id=' . $u['id'] . '">Сменить ник</a></div>';
}
// 
if ($u['id']!=$us['id'] && $u['level']<$us['level']) {
        echo '<div class="list1"><a href="/adm/ban.php?id=' . $u['id'] . '">Бан</a></div>';
}



if ($u['id']==$us['id'] || $u['new'] == 1) {
        
        echo '<div class="menu2">Новости</div>';
        if ($u['id']==$us['id']) {


                echo '<div class="list1"><form action="/us' . $u['id'] . '?send" method="post">';
                echo 'Новость:<br/><textarea name="text"></textarea><br/>';
                echo '<input type="submit" value="Отправить"/>';
                echo '</form>';
echo '</div>';
                if (isset ($_GET['send'])) {
                        $_POST['text'] = htmlspecialchars (addslashes (trim ($_POST['text'])));
                        if (empty ($_POST['text'])) {
                                echo '<div class="list1">Вы не ввели текст новости..</div>';
                        }
                        else {
                                if (DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `new` WHERE (`us`='" . $us['id'] . "') AND (`t`>'" . (time () - 60) . "')") != 0) {
                                        echo '<div class="list">Вы пишите слишком часто!</div>';
                                }
                                else {
                                        DB :: $dbs -> query ("INSERT INTO `new` (`us`,`kem`,`text`,`t`) VALUES ('" . $u['id'] . "', '" . $us['id'] . "', ?, '" . time () . "')", array ($_POST['text']));
                                        header ('location: /us' . $u['id']);
                                }
                        }
                }

        }        
        //
        if (isset ($_GET['del'])) {
        
                if ($u['id']==$us['id'] || $u['level']<$us['level']) {
                        $query = DB :: $dbs -> query ("SELECT * FROM `new` WHERE (`id`=?)", array (intval ($_GET['del'])));
                        if ($query -> rowCount () != 0) {
                                $new = $query -> fetch ();
                                if ($new['us']==$u['id']) {
                                        DB :: $dbs -> query ("DELETE FROM `new` WHERE (`id`='" . $new['id'] . "')");
                                        DB :: $dbs -> query ("DELETE FROM `new_komm` WHERE (`id_new`='" . $new['id'] . "')");
                                }
                        }
                }
                header ('location: /us' . $u['id']);
        }
        
        
        // 
        $items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `new` WHERE (`us`='" . $u['id'] . "')");
        if ($items == 0) {
                echo '<div class="list1">Новостей нет..</div>';
        }
        else {
                
                $query = DB :: $dbs -> query ("SELECT * FROM `new` WHERE (`us`='" . $u['id'] . "') ORDER BY `id` DESC LIMIT 5");
                while ($new = $query -> fetch ()) {
                        
                        //
                        echo '<div class="list1">';
                        echo uNick ($new['kem']) . ' (' . datef ($new['t']) . ')<br/>';
                        
                        // 
                        if (!empty ($new['komm'])) {
                                echo 'Комментарий: <b>' . bb ($new['komm']) . '</b><br/>';
                        }
                        
                        if ($new['id_p']!=0) {                        
                                $p = DB :: $dbs -> queryFetch ("SELECT * FROM `forum_p` WHERE (`id`='" . $new['id_p'] . "')");
                                $t = DB :: $dbs -> queryFetch ("SELECT * FROM `forum_t` WHERE (`id`='" . $p['id_t'] . "')");
                                echo '<img src="/images/re.png" alt=""/> ' . uNick ($p['us']) . '<br/>';
                                echo 'Тема: <a href="/forum/thema' . $t['id'] . '"><b>' . $t['name'] . '</b></a><br/>';
                                echo 'Сообщение: ';
                                
                                if ($p['del']==0) {
                                
                                        if  (mb_strlen ($p['text']) > 150) {
                                                echo mb_substr (bb ($p['text']), 0, 150) . '.. <img src="" alt=""/><br/>';
                                                echo '<a href="/newkomm.php?id=' . $new['id'] . '">читать полностью</a>';
                                        }
                                        else {
                                                echo bb ($p['text']);
                                        }
                                
                                }
                                else {
                                        echo '<b>Сообщение удалено!</b>';
                                }
                                               
                        }
                
                        //
                        if ($new['id_f']!=0) {        
                                $f = DB :: $dbs -> queryFetch ("SELECT * FROM `zc_f` WHERE (`id`='" . $new['id_f'] . "')");
                                echo '<img src="/images/re.png" alt=""/> ' . uNick ($f['us']) . '<br/>';
                                echo 'Файл: <a href="/zc/file' . $f['id'] . '"><b>' . $f['name'] . '</b></a>';
                        }
                        
                                        
                        // 
                        if (!empty ($new['text'])) {
                                echo bb ($new['text']);
                        }
                        
                        
                        if ($u['id']==$us['id'] || $u['level']<$us['level']) {
                                // 
                                echo ' <a href="/us.php?id=' . $u['id'] . '&del=' . $new['id'] . '">удал.</a>';
                        }
                        

                        echo '</div>';
                        
                        
                        
                                                
                        // 
                        echo '<div class="lst">';
                        echo '<form action="/newkomm.php?id=' . $new['id'] . '&add" method="post">';
                        echo 'Комментарий: <input name="komm"/> <input type="submit" value="Добавить"/>';
                        echo '</form>';
                        echo '</div>';
                        
                        $itemss = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `new_komm` WHERE (`id_new`='" . $new['id'] . "')");
                        if ($itemss != 0) {
                                
                                echo '<div style="padding-left:15%;">';

                                
                                $q = DB :: $dbs -> query ("SELECT * FROM `new_komm` WHERE (`id_new`='" . $new['id'] . "') ORDER BY `id` DESC LIMIT 5");
                                while ($komm = $q -> fetch ()) {
                                
                                        $kommus = DB :: $dbs -> queryFetch ("SELECT * FROM `us` WHERE (`id`='" . $komm['id'] . "')");
                                
                                        echo '<div class="lst">';

                                        echo uNick ($komm['us']) . ' (' . datef ($komm['t']) . ')';

                                        if ($komm['us']!=$us['id']) {
                                                echo ' [<a href="/newkomm.php?id=' . $new['id'] . '&komu=' . $komm['us'] . '">отв</a>] ';
                                        }

                                        if ($kommus['id']==$us['id'] && $us['level']>1 || $kommus['level']<$us['level'] && $us['level']>1) {
                                                echo ' [<a href="/newkomm.php?id=' . $new['id'] . '&del=' . $komm['id'] . '">x</a>] ';
                                        }
                                        
                                        echo '<br/>';
                                        

                                        echo bb ($komm['text']);
                                        echo '</div>';
                                }
                                
                                //
                                if ($itemss>5) {
                                        echo '<div class="list1"><a href="/newkomm.php?id=' . $new['id'] . '">Показать все комментарии</a> (' . $itemss . ')</div>';
                                }
                                
                                echo '</div>';
                                
                        }
                        
                        echo '<hr/>';
                
                }
                
                // 
                if ($items>=5) {
                        echo '<div class="list1"><a href="/usnews.php?id=' . $u['id'] . '">Больше новостей</a> (' . $items . ')</div>';
                }
                
                
                
        }

}

F ();