<?php
require_once('system/func.php');
auth(); // Закроем от не авторизованных


# Настройки #
$id = abs(intval($_GET['id']));
if ($id) {
    $profile = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $id . "'"));
} else {
    $profile = $user;
}
# Ошибки #
if (!$profile) {
    $_SESSION['msg'] = 'Такой игрок не существует';
    header('Location: /online?search');
    exit();
}

//if($profile['id'] =='2'){
//$_SESSION['msg'] = "Такой игрок не существует.";
//header('Location: /main');
//exit();
//}





if(isset($_GET[clan_memb]) and $myID != $profile[id] and $user[clan_rang] > 2 and $profile[id_clan] == 0 and $profile[side] == $user[side]){
if($count >= 20 /*Укажите любое число*/){ // Если участников в клане больше n , то выводим сообщение и выходим
$_SESSION[msg] = "Ваш клан переполнен";
header('Location: ?');
exit();
} // Если условие окажется не верным , то код просто будет читаться дальше
mysql_query("INSERT INTO `clan_memb` SET `id_user` = '$profile[id]', `id_clan` = '$user[id_clan]'");
$_SESSION[msg] = "Заявка отправлена!";
header('Location: ?');
exit();
} 


if (isset($_GET['friend']) && $profile['id'] != $user['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE (`user_1` = '" . $profile['id'] . "' AND `user_2` = '" . $user['id'] . "') OR (`user_2` = '" . $id . "' AND `user_1` = '" . $user['id'] . "')"), 0) == 0) {

    mysql_query("INSERT INTO `friends` SET `user_1` = '" . $user['id'] . "', `user_2` = '" . $profile['id'] . "', `status` = '0'");
    $_SESSION['msg'] = "Заявка отправлена!";
    header('Location: ?');
    exit();
}

$title = $profile['login'];
require_once('system/header.php');


if ($ban['time'] > time()) {

    echo "<div class='block_win'>Игрок заблокирован  </div>";


    echo "<div class='block_win'>Причина </font><font color='grey'> " . text($lock['text']) . " </font></div>";


}
# Информация для админа #
if ($user['access'] == 1 and $myID != $profile['id']) {
    echo "<div class='header'>";
    //echo "</div>";
    //if($user['access'] > $profile[access] and $myID != $profile['id'])echo "<td class='center'><li><div class=''><a href='/lock/$profile[id]/'><font color='red'>Изгнание</font></a></li></td></div>";
   // if ($user['access'] > $profile[access] and $myID != $profile['id']) {
       echo "<td class='center'><li><div class='bbtn mb5'><a href='/ban/$profile[id]/'><font color='orange'>Бан</font></a></li></td>";
    //}

   // if($user['access'] > $profile[access] and $myID != $profile['id'])echo "<td class='center'><div class=''><li><a href='/ip_proverka/$profile[id]'><font color='white'>Проверка мультов</font></a></li></td></div>";
    echo "</div>";

}

if ($user[access] >= 2) {
    //echo "<div class='header'>";

    //echo "<table style='width:100%;'>";
    if ($user['access'] > $profile[access] and $myID != $profile['id']) {
      // echo div('main_link');

     //echo "<center><td class='center'><div class=''><li><a href='/ip_proverka/$profile[id]'><font color='white'>Проверка мультов</font></a></center></li></td></div></div>";
    }

    if ($user['access'] > $profile[access] and $myID != $profile['id']) {
        echo div('wrapper');

        echo "<center><td class='center'><li><div class=''><a href='/ban/$profile[id]/'><font color='orange'>Бан</font></a></center></li></td></div>";
    }
    //if($user['access'] > $profile[access] and $myID != $profile['id'])echo "<td class='center'><li><div class=''><a href='/lock/$profile[id]/'><font color='red'>Бан</font></a></li></td></div>";

    echo "</table></div>";
}
$item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $myID . "' AND `odeta` = 'da' AND `tip` = 'golova' ORDER BY `id` LIMIT 1");


$clan = mysql_fetch_array(mysql_query("SELECT * FROM `clans` WHERE `id` = '" . $profile[id_clan] . "' LIMIT 1"));

$user_ban = mysql_fetch_array(mysql_query("SELECT * FROM `block` WHERE `id_user` = '" . $profile['id'] . "'"));

if ($user_ban['time'] > time()) {

    echo div('block_c') . "" . color('red') . "Пользователь заблокирован!<br></font>";
    // echo span('white')." Причина:</span> $user_ban[text]<br> ";
    if ($post[time] > time()) {
        echo " " . tl($post[time] - time());
    }
    echo span('white') . " <center>Осталось времени:</span> " . tl($user_ban['time'] - time()) . "</center></div> ";

}

$ban = mysql_fetch_array(mysql_query("SELECT * FROM `ban` WHERE `id_user` = '" . $profile['id'] . "'"));

if ($ban['last'] > time()) {

    echo div('block_c') . "" . color('red') . "Пользователь забанен!<br></font>";
    //echo span('white')." Причина:</span> $ban[text] <br>";
    echo span('white') . " Осталось еще:</span> " . tl($ban['last'] - time()) . "</div> ";

}


///////////////////////////////////////


echo "  <font size='3px'>";
if ($profile['access'] == 2) {
    $access = "<span class='almaz'>Администратор</span>";
} elseif ($profile['access'] == 1) {
    $access = "<span class='violet'>Модератор</span>";

} elseif ($profile['access'] == 0) {
    $access = "<span class='gold'>Игрок</span>";
}

//$img_avatar  = "<img src='/images/avatar/$profile[sex]/$profile[avatar].jpg'></a>";


//$avatar = $profile['avatar'];
//$sex = $profile['sex'];


if ($myID == $profile['id']) {
    $exp_progress = '<br>' . ico('icons', 'exp.png') . ' ' . color('white') . ' Опыт:</font> ' . n_f($profile['exp']) . '/' . n_f($exp) . '(' . round($profile['exp'] / $exp * 100, 1) . '%)';
}

$date_reg = ' ' . ico('icons', 'arrow_refresh.png') . ' В игре:</font> ' . tl(time() - $profile['registr']) . '';


if ($profile['online'] > time() - 18000) {
    $online = color('lime') . "онлайн</font>";
} else {
    $online = color('red') . "оффлайн </font> (" . tl(time() - $profile['online']) . ')';
}


switch ($profile['class']) {
    //case 1:
    //$StatusClass= color('green'). " Варвар </font>";
    // $BonusStr = 10;
    // $BonusDef= 15;
    // $BonusHp  = 15;
    // $ClassImg = "<img src='/images/class/barbarian.jpg' width='85px'>";
    // break;

    // case 2:
    // $StatusClass= color('orange'). " Разбойник </font>";
    // $BonusStr = 25;
    // $BonusDef= 5;
    // $BonusHp  = 10;
    //  $ClassImg = "<img src='/images/class/robber.jpg' width='85px'>";
    //  break;

    // case 3:
    // $StatusClass= color('gold'). " Рыцарь </font>";
    // break;
    // default:
    // $StatusClass= color('tomato'). " Не выбран </font>";

}


$ClassHp = ceil($user['max_health'] * $BonusHp / 100);
$ClassStr = ceil($user['str'] * $BonusStr / 100);
$ClassDef = ceil($user['def'] * $BonusDef / 100);

//echo "<div class='header_b'>";

echo "<div class='wrapper'>";
echo icons_user($profile[id]) . " <span class='white'>        $profile[login]</span></br>";



switch($profile[clan_rang]){
case 1:
$clan_rang = 'Новичок';
break;
case 2:
$clan_rang = 'Сержант';
break;
case 3:
$clan_rang = 'Лейтенант';
break;
case 4:
$clan_rang = 'Генерал';
break;
case 5:
$clan_rang = "<font color='green'>Лидер клана</font>";
break;
}
if($clan){
echo "".ico('icons','clan.png')." <a href='/clan/$clan[id]/'>$clan[name]</a> - $clan_rang</br>";
}



echo "</div>";

echo div('header');


if ($profile['access'] == 3) {


    echo "<center><span class='item-2'>Старший модератор</span></center>";


} elseif ($profile['access'] == 1) {
    // echo "<div class='block'>";

    echo "<center><span class='item-1'><font color='#90ee90'>Модератор</font></span></center>";
    //echo "<div class='block'>";

} elseif ($profile['access'] == 2) {
    // echo "<div class='block'>";

    echo "<center><span class='item-4'><font color='#00d0ff'>Администратор</font></span></center>";
    //echo "<div class='block'>";

} else {
    echo "<span class='white'></span>";
}












echo "";


?>


<table cellpadding="15" cellspacing="25" align="center">

    <tr>
        <td style="vertical-align:top;">

            <?
            $item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $profile['id'] . "' AND `odeta` = 'da' AND `tip` = 'golova' ORDER BY `id` LIMIT 1");
            $item = mysql_fetch_array($item);
            if ($item) {
                echo '<a  href="/item/' . $item[id] . '" title="' . $item[name] . '">
<img src="/images/items/' . $item[tip] . '/' . $item[item] . '.png" width="65px"  alt="*" /></a><br>';
            } else {
                echo '<img src="/images/icons/item_null.png" width="65px"  alt="*" /><br>';
            }
            $item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $profile['id'] . "' AND `odeta` = 'da' AND `tip` = 'plechi' ORDER BY `id` LIMIT 1");
            $item = mysql_fetch_array($item);
            if ($item) {
                echo '<a  href="/item/' . $item[id] . '" title="' . $item[name] . '">
<img src="/images/items/' . $item[tip] . '/' . $item[item] . '.png" width="65px"  alt="*" /></a><br>';
            } else {
                echo '<img src="/images/icons/item_null.png" width="65px"  alt="*" /><br>';
            }
            $item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $profile['id'] . "' AND `odeta` = 'da' AND `tip` = 'tors' ORDER BY `id` LIMIT 1");
            $item = mysql_fetch_array($item);
            if ($item) {
                echo '<a  href="/item/' . $item[id] . '" title="' . $item[name] . '">
<img src="/images/items/' . $item[tip] . '/' . $item[item] . '.png" width="65px"  alt="*" /></a><br>';
            } else {
                echo '<img src="/images/icons/item_null.png" width="65px"  alt="*" /><br>';
            }
            $item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $profile['id'] . "' AND `odeta` = 'da' AND `tip` = 'perchatki' ORDER BY `id` LIMIT 1");
            $item = mysql_fetch_array($item);
            if ($item) {
                echo '<a  href="/item/' . $item[id] . '" title="' . $item[name] . '">
<img src="/images/items/' . $item[tip] . '/' . $item[item] . '.png" width="65px"  alt="*" /></a><br>';
            } else {
                echo '<img src="/images/icons/item_null.png" width="65px"  alt="*" /><br/>';
            }
            ?>
        </td>
        <td>
            <?
            echo div('header');
            if (!empty($profile['avatars'])) {
                echo "<div class='ram'>";

                echo "<center><img src='/images/avatars/$profile[avatars]'  width='190' height='170''></center>";
                            echo "</div>";

            } else {
                echo "<div class='ram'>";

                echo "<center><img src='/images/avatars/noavatar.png'  width='190' height='170''></center>";
                            echo "</div>";

            }
            echo "</div>";
            ?>
        </td>

        <td style="vertical-align:top;">

            <?
            $item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $profile['id'] . "' AND `odeta` = 'da' AND `tip` = 'lev' ORDER BY `id` LIMIT 1");
            $item = mysql_fetch_array($item);
            if ($item) {
                echo '<a  href="/item/' . $item[id] . '" title="' . $item[name] . '">
<img src="/images/items/' . $item[tip] . '/' . $item[item] . '.png" width="65px"  alt="*" /></a><br>';
            } else {
                echo '<img src="/images/icons/item_null.png" width="65px"  alt="*" /><br>';
            }
            $item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $profile['id'] . "' AND `odeta` = 'da' AND `tip` = 'prav' ORDER BY `id` LIMIT 1");
            $item = mysql_fetch_array($item);
            if ($item) {
                echo '<a  href="/item/' . $item[id] . '" title="' . $item[name] . '">
<img src="/images/items/' . $item[tip] . '/' . $item[item] . '.png" width="65px"  alt="*" /></a><br>';
            } else {
                echo '<img src="/images/icons/item_null.png" width="65px"  alt="*" /><br>';
            }
            $item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $profile['id'] . "' AND `odeta` = 'da' AND `tip` = 'nogi' ORDER BY `id` LIMIT 1");
            $item = mysql_fetch_array($item);
            if ($item) {
                echo '<a  href="/item/' . $item[id] . '" title="' . $item[name] . '">
<img src="/images/items/' . $item[tip] . '/' . $item[item] . '.png" width="65px"  alt="*" /></a><br>';
            } else {
                echo '<img src="/images/icons/item_null.png" width="65px"  alt="*" /><br>';
            }
            $item = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '" . $profile['id'] . "' AND `odeta` = 'da' AND `tip` = 'obuv' ORDER BY `id` LIMIT 1");
            $item = mysql_fetch_array($item);
            if ($item) {
                echo '<a  href="/item/' . $item[id] . '" title="' . $item[name] . '">
<img src="/images/items/' . $item[tip] . '/' . $item[item] . '.png" width="65px"  alt="*" /></a>';
            } else {
                echo '<img src="/images/icons/item_null.png" width="65px"  alt="*" />';
            }
            ?>
        </td>
    </tr>
</table>

</div>

<?

//echo "<div class='header'>";
echo '<div class="header"><a href="/statys.php"> '.$profile['statys_text'].'</a></div>';

//echo "</div>";








$ability = mysql_query("SELECT * FROM `ability` WHERE `id_user` = '" . $profile['id'] . "'");
$ability = mysql_fetch_array($ability);


echo div('header');


?>

<div class="cntr white m5">
    <div class="tptrn ib">
        <div class="p_end">Умения</div>
    </div>
</div></div>
<?
echo '</div><div class="text_p1">';

echo "<table style='width:100%;'>";

if ($ability[spellHpLvl] > 0) {
    echo " <td class='center'> " . img('ability', 'spell_health.png ') . "<br>" . ico('icons', 'level.png') . "$ability[spellHpLvl]</td></a>";
} else {
    echo " <td class='center'>" . spell('ability', 'spell_health.png ') . "<br> </td></a>";
}


if ($ability[spellDefLvl] > 0) {
    echo " <td class='center'> " . img('ability', 'spell_defence.png ') . "<br>" . ico('icons', 'level.png') . "$ability[spellDefLvl]</td></a>";
} else {
    echo " <td class='center'>" . spell('ability', 'spell_defence.png ') . "<br> </td></a>";
}


if ($ability[spellStrLvl] > 0) {
    echo " <td class='center'> " . img('ability', 'double_attack.jpg ') . "<br>" . ico('icons', 'level.png') . "$ability[spellStrLvl]</td></a>";
} else {
    echo " <td class='center'>" . spell('ability', 'double_attack.jpg ') . "<br> </td></a>";
}


echo "</table></div>";


if ($myID == $profile['id']) {
echo div('header');

if ($user[r] == 0) {
echo div('main_link');
    echo '<a href="/p.php"><div class="ssilki_dop p_0"><img src="/images/icons/gift.png" width="28px"> Подарок</a></div></div>';
}
    echo div('main_link');
    //echo' <a  " href="/train"> class="llb"> <img src="/images/icons/train.png" width="25px"> Тренировка</a></div>';
    echo '<a href="/train"><div class="ssilki_dop p_0"><img src="/images/icons/train.png" width="28px"> Тренировка</a></div></div>';


    echo div('main_link');
    echo '<a href="/inv" class="llb"> <div class="ssilki_dop p_0"><img src="/images/icons/inv.png" width="28px"> Сумка</a></div></div>';
    $q = mysql_fetch_array(mysql_query("SELECT * FROM `sunduk_user` WHERE `status` = 'close'  AND `id_user` = '$myID' "));

    if ($q >= 1) {
        echo div('main_link');
        echo '<a href="/sunduk" class="llb"><div class="ssilki_dop p_0"> <img src="/images/icons/inv1.png" width="28px"> Сундуки ' . color('lime') . ' + </font> </a></div></div>';
    } else {
        echo div('main_link');
        echo '<a href="/sunduk" class="llb"> <div class="ssilki_dop p_0"><img src="/images/icons/inv1.png" width="28px"> Сундуки</a></div></div>';
    }

    echo div('main_link');
    echo '<a href="/mail/" class="llb"><div class="ssilki_dop p_0"> <img src="/images/icons/mail1.png" width="28px"> Почта</a></div></div>';

    echo div('main_link');
    echo '<a href="/friends/" class="llb"><div class="ssilki_dop p_0"> <img src="/images/icons/friends1.png" width="28px"> Друзья</a></div></div>';


    echo div('main_link');
    echo '<a href="/my_gift/" class="llb"><div class="ssilki_dop p_0"> <img src="/images/icons/gift.png" width="28px"> Мои подарки</a></div></div>';
echo div('main_link');
    echo '<a href="/list_refer.php" class="llb"> <div class="ssilki_dop p_0"><img src="/images/icons/ref.png" width="28px"> Рефералы</a></div></div>';




    echo div('main_link');
    echo '<a href="/settings.php" class="llb"><div class="ssilki_dop p_0"><img src="/images/icons/settings.png" width="28px"> Настройки</a></div></div>';


}
echo div('header');


?>

<div class="cntr white m5">
    <div class="tptrn ib">
        <div class="p_end">Параметры</div>
    </div>
</div>
<?

echo '</div><div class="header_b"><div class="text_p1">';
echo ico('icons', 'str.png') . ' <span class="white">Сила:</span>  <span class="llb">' . $profile['str'] . '<br></span>';
echo ico('icons', 'def.png') . '  <span class="white">Броня:</span> <span class="llb">' . $profile['def'] . '<br></span>';
echo ico('icons', 'health.png') . ' <span class="white"> Здоровье:</span> <span class="llb">' . $profile['max_health'] . '<br></span>';
echo '</div>';
echo div('header');

?>
<div class="cntr white m5">
    <div class="tptrn ib">
        <div class="p_end">Информация</div>
    </div>
</div></div>
<?

$campaign = mysql_query("SELECT * FROM `campaign` WHERE `id_user` = '" . $profile[id] . "'");
$campaign = mysql_fetch_array($campaign);
$campStatus = ico('icons', 'razdel.png') . " Кампания: глава $campaign[id_camp] ";

echo "<div class='text_p1'>
" . ico('icons', 'level.png') . "  " . color('white') . " Уровень: </font>$profile[level] $exp_progress <br> $campStatus<br>" . color('white') . "" . ico('icons', 'time.png') . " Статус: $online<br> $date_reg</div>";

echo div('header');


if ($profile['id'] != $myID) {


    echo div('main_link');
    echo "<a class='llb' href='/mail/" . $profile['id'] . "'><div class='ssilki_dop p_0'><img src='/images/icons/mail1.png' width='28px'> Написать сообщение</a></div>";
    echo "</div>";
    
    //echo div('main_link');
   // echo '<a href="/mail/" class="llb"><div class="ssilki_dop p_0"> <img src="/images/icons/mail.png" width="23px"> Почта</a></div></div>';
    //echo div('main_link');
   // echo "<a class='llb' href='/gift/" . $profile['id'] . "'><div class='ssilki_dop p_0'><img src='/images/icons/gift.png' width='23px'> Подарить подарок</div></a>";
  //  echo "</div>";
    


echo div('main_link');
    echo "<a class='llb' href='/pers_gift/" . $profile['id'] . "'><div class='ssilki_dop p_0'><img src='/images/icons/gift.png' width='28px'> Подарки $profile[login]</a></div>";
    echo "</div>";



    if (mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE (`user_1` = '" . $id . "' AND `user_2` = '" . $user['id'] . "') OR (`user_2` = '" . $id . "' AND `user_1` = '" . $user['id'] . "')"), 0) == 0) {
        echo div('main_link');
        echo "<a class='llb' href='?friend'><div class='ssilki_dop p_0'><img src='/images/icons/friends1.png' width='28px'> Добавить в друзья</a></div>";
        echo "</div>";
    }

    if ($myID != $id and $user[clan_rang] > 2 and $profile[id_clan] == 0 and $user['side'] == $profile['side'] and mysql_result(mysql_query("SELECT COUNT(*) FROM `clan_memb` WHERE `id_user` = '$id' AND `id_clan` = '$user[id_clan]'"), 0) == 0) {
        echo div('main_link');
        echo "<a class='llb' href='?clan_memb'><div class='ssilki_dop p_0'><img src='/images/icons/clan.png' width='28px'> Пригласить в клан</div></a>";
        echo "</div>";
    }
}

    //echo '</div>';

?>
<?
if ($user[access] == 3) {
    ?>
    <div class='main_link'><a class='llb' href='/access/<?= $profile[id] ?>'>
            <div class='ssilki_dop p_0'><img src='/images/icons/arena.png' width=28px> Редактор прав
        </a></div></div>
    <?
    //echo '</div>';
}
    if ($user[access] == 2) {
    ?>
    <div class='main_link'><a class='llb' href='/adm_access/<?= $profile[id] ?>'>
            <div class='ssilki_dop p_0'><img src='/images/icons/arena.png' width=28px> Редактор прав
        </a></div></div>
    <?
    echo '</div>';
    
}
$clan = null;
require_once('system/footer.php');
?>
