<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
    
if(!$user) {
header('location: /');
exit;}

$id = _string(_num($_GET['id']));
  if($id) {
    $i = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$id.'"');
    $i = mysql_fetch_array($i);
    
    if(!$i) {
      header('location: /user/');
      exit;}

    }else{ 
      $i = $user;
    }
    
$title = $i['login'];
include './system/h.php';

echo' '.$_SESSION['mes'].'  ';
$_SESSION['mes']=NULL; //Удаляем сесию
?>

<?

$w_1 = mysql_query('SELECT * FROM `inv` WHERE `user` = "'.$i['id'].'" AND `id` = "'.$i['w_1'].'"');
$w_1 = mysql_fetch_array($w_1);
if(!$w_1) {
  $w_1['item'] = 0;
}
$w_1_item = mysql_query('SELECT * FROM `items` WHERE `id` = "'.$w_1['item'].'"');
$w_1_item = mysql_fetch_array($w_1_item);

$w_2 = mysql_query('SELECT * FROM `inv` WHERE `user` = "'.$i['id'].'" AND `id` = "'.$i['w_2'].'"');
$w_2 = mysql_fetch_array($w_2);
if(!$w_2) {
  $w_2['item'] = 0;
}

$w_2_item = mysql_query('SELECT * FROM `items` WHERE `id` = "'.$w_2['item'].'"');
$w_2_item = mysql_fetch_array($w_2_item);

$w_3 = mysql_query('SELECT * FROM `inv` WHERE `user` = "'.$i['id'].'" AND `id` = "'.$i['w_3'].'"');
$w_3 = mysql_fetch_array($w_3);
if(!$w_3) {
  $w_3['item'] = 0;
}

$w_3_item = mysql_query('SELECT * FROM `items` WHERE `id` = "'.$w_3['item'].'"');
$w_3_item = mysql_fetch_array($w_3_item);


$w_4 = mysql_query('SELECT * FROM `inv` WHERE `user` = "'.$i['id'].'" AND `id` = "'.$i['w_4'].'"');
$w_4 = mysql_fetch_array($w_4);

if(!$w_4) {
  $w_4['item'] = 0;
}

$w_4_item = mysql_query('SELECT * FROM `items` WHERE `id` = "'.$w_4['item'].'"');
$w_4_item = mysql_fetch_array($w_4_item);

$w_5 = mysql_query('SELECT * FROM `inv` WHERE `user` = "'.$i['id'].'" AND `id` = "'.$i['w_5'].'"');
$w_5 = mysql_fetch_array($w_5);
if(!$w_5) {
  $w_5['item'] = 0;
}
$w_5_item = mysql_query('SELECT * FROM `items` WHERE `id` = "'.$w_5['item'].'"');
$w_5_item = mysql_fetch_array($w_5_item);

$w_6 = mysql_query('SELECT * FROM `inv` WHERE `user` = "'.$i['id'].'" AND `id` = "'.$i['w_6'].'"');
$w_6 = mysql_fetch_array($w_6);
if(!$w_6) {
  $w_6['item'] = 0;
}
$w_6_item = mysql_query('SELECT * FROM `items` WHERE `id` = "'.$w_6['item'].'"');
$w_6_item = mysql_fetch_array($w_6_item);

$w_7 = mysql_query('SELECT * FROM `inv` WHERE `user` = "'.$i['id'].'" AND `id` = "'.$i['w_7'].'"');
$w_7 = mysql_fetch_array($w_7);
if(!$w_7) {
  $w_7['item'] = 0;
}
$w_7_item = mysql_query('SELECT * FROM `items` WHERE `id` = "'.$w_7['item'].'"');
$w_7_item = mysql_fetch_array($w_7_item);

$w_8 = mysql_query('SELECT * FROM `inv` WHERE `user` = "'.$i['id'].'" AND `id` = "'.$i['w_8'].'"');
$w_8 = mysql_fetch_array($w_8);
if(!$w_8) {
  $w_8['item'] = 0;
}
$w_8_item = mysql_query('SELECT * FROM `items` WHERE `id` = "'.$w_8['item'].'"');
$w_8_item = mysql_fetch_array($w_8_item);


  $i_clan_memb = mysql_query('SELECT * FROM `clan_memb` WHERE `user` = "'.$i['id'].'"');
  $i_clan_memb = mysql_fetch_array($i_clan_memb);
  
    if(!$i_clan_memb) {
    if($clan && $clan_memb['rank'] >= $clan['rank_for_invite'] && $clan['r'] == $i['r'] && $_GET['clan_invite'] == true) {
    if(mysql_result(mysql_query('SELECT COUNT(`id`) FROM `clan_invite` WHERE `ho` = "'.$i['id'].'" AND `clan` = "'.$clan['id'].'"'),0) == 0) {
      mysql_query('INSERT INTO `clan_invite` (`clan`,
                                              `user`,
											  `ho`) VALUES ("'.$clan['id'].'",
															"'.$user['id'].'",
                                                            "'.$i['id'].'")');
echo' '.mes('Приглашение отправлено!').'';
}else{}
   }
}
  


echo'<div class="empty_block">
<b>'.nick($i['id']).'</b> <img src="/images/ico/png/up.png" alt="*"/> <small> '.$i['level'].' ур, '.($i['sex'] == 0 ? 'Мужской':'Женский').' </small><br/>';


  if($i_clan_memb) {
    $i_clan = mysql_query('SELECT * FROM `clans` WHERE `id` = "'.$i_clan_memb['clan'].'"');
    $i_clan = mysql_fetch_array($i_clan);

  switch($i_clan_memb['rank']) {
  
    case 0:
    $rank = 'Новобранец';
     break;
    case 1:
    $rank = 'Боец';
     break;
    case 2:
    $rank = 'Офицер';
     break;
    case 3:
    $rank = 'Генерал';
     break;
    case 4:
    $rank = '<font color=\'#30c030\'>Лидер клана</font>';
     break;
    
  }


echo'<img src="/images/ico/png/clan.png" alt="*"/> <a href="/clan/'.$i_clan['id'].'/">'.$i_clan['name'].'</a>, '.$rank.' <br/>';

  }

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


$ban = mysql_fetch_assoc(mysql_query("SELECT * FROM `ban` WHERE `user` = '".$i['id']."'"));
$block = mysql_fetch_assoc(mysql_query("SELECT * FROM `block` WHERE `user` = '".$i['id']."'"));
if(isset($ban['user']) AND isset($block['user']) != $i['id'])
{
echo'
<div class="empty_block item_center">
<font color=khaki><b>Пользователь забанен!</font></b><br/>
Причина: '.$ban['text'].'</br>
Осталось: '._time($ban['time'] - time()).'</br>
Кто: '.nick($ban['who']).'</br>
</div><div class="line"></div>';
}elseif(isset($block['user'])){
echo'<div class="line"></div>
<div class="empty_block item_center">
<font color=khaki><b>Пользователь заблокирован!</font></b><br/>
Причина: '.$block['text'].'</br>
Осталось: '._time($block['time'] - time()).'</br>
Кто: '.nick($block['who']).'</br>
</div><div class="line"></div>';    
}


echo'
<div class="empty_block item_center">
<table border="0" cellspacing="0" cellpadding="0"><tbody>
<tr><td><img src="/images/items/'.$w_1['item'].'.png" alt="*" height="50" width="50/"></td><td class="image" colspan="0" rowspan="5"><center>';


echo'  <img src="/manekenImage/0/'.$w_1['item'].'/'.$w_2['item'].'/'.$w_3['item'].'/'.$w_4['item'].'/'.$w_5['item'].'/'.$w_6['item'].'/'.$w_7['item'].'/'.$w_8['item'].'/" width="75%" alt="*"/> ';


echo'
</center></td>
<td height="50px"><img src="/images/items/'.$w_2['item'].'.png" alt="*" height="50" width="50/"></td></tr><tr><td><img src="/images/items/'.$w_3['item'].'.png" alt="*" height="50" width="50/"></td><td><img src="/images/items/'.$w_4['item'].'.png" alt="*" height="50" width="50/"></td>
</tr><tr><td><img src="/images/items/'.$w_5['item'].'.png" alt="*" height="50" width="50/"></td><td><img src="/images/items/'.$w_6['item'].'.png" alt="*" height="50" width="50/"></td></tr><tr><td><img src="/images/items/'.$w_7['item'].'.png" alt="*" height="50" width="50/"></td><td><img src="/images/items/'.$w_8['item'].'.png" alt="*" height="50" width="50/">
</td></tr></tbody></table>
</div><div class="line"></div>';






/////////////////////////////////////////
/////////////////////////////////////////
$c = mysql_query('SELECT * FROM `trophies_user` WHERE `user_id` = "'.$i['id'].'" ');
if (mysql_num_rows ($c) != 0) { echo'<a href="/trophies/'.($user['id'] == $i['id'] ? '':''.$i['id'].'').'"><div class="empty_block item_center">';  }
while($row = mysql_fetch_array($c)){
echo'<img src="/images/ico/medals/trophy'.$row['trophies_id'].'.png">';
}
$c = mysql_query('SELECT * FROM `trophies_user` WHERE `user_id` = "'.$i['id'].'" ');
if (mysql_num_rows ($c) != 0) { echo'</div></a><div class="line"></div>';}
/////////////////////////////////////////
/////////////////////////////////////////





  $equips = 0;
  if($i['w_1']) {
    $equips++;
  }
  if($i['w_2']) {
    $equips++;
  }
  if($i['w_3']) {
    $equips++;
  }
  if($i['w_4']) {
    $equips++;
  }
  if($i['w_5']) {
    $equips++;
  }
  if($i['w_6']) {
    $equips++;
  }
  if($i['w_7']) {
    $equips++;
  }
  if($i['w_8']) {
    $equips++;
  }



echo'<div class="block_link">
<a href="/equip/'.$i['id'].'/"><img src="/images/ico/png/slots.png" alt="*"/> Снаряжение ('.$equips.'/8)</a></div>
<div class="line"></div>
<div class="block_link"><a href="/ability/'.$i['id'].'/"><img src="/images/ico/png/ability.png" alt="*"/> Умения </a></div>
<div class="line"></div>';

 if($i['id'] == $user['id']) {
echo'<div class="block_link"><a href="/inv/"> <img src="/images/ico/png/bag.png" alt="*"/> Сумка ('.mysql_result(mysql_query('SELECT COUNT(`id`) FROM `inv` WHERE `user` = "'.$user['id'].'" AND `equip` = "0"'),0).'/20) '.(mysql_result(mysql_query('SELECT COUNT(*) FROM `inv` WHERE `user` = "'.$user['id'].'" AND `equip` = "0"  AND `new` = "0"'),0) > 0 ? '<font color=\'#30c030\'>(+)</font>':'').' </a></div>
<div class="line"></div>';




echo'
<div class="block_link"><a href="/mail/"><img src="/images/ico/png/post.png" alt="*"/> Почта</a></div>
<div class="line"></div>

<div class="block_link"><a href="/train/"><img src="/images/ico/png/train.png" alt="*"/> Тренировка</a></div>
<div class="line"></div>';
  }else{



  if(!$i_clan_memb && $clan && $clan_memb['rank'] >= $clan['rank_for_invite'] && $clan['r'] == $i['r']) {
if(mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_invite` WHERE `ho` = "'.$i['id'].'" AND `clan` = "'.$clan['id'].'"'),0) == 0) {
echo'<div class="block_link"><a href="/user/'.$i['id'].'/?clan_invite=true"><img src="/images/ico/png/clan.png" alt="*"/> Пригласить в клан</a></div>
<div class="line"></div>';
  }
}

echo'<div class="block_link"><a href="/mail/'.$i['id'].'/"><img src="/images/ico/png/post.png" alt="*"/> Отправить почту</a></div>
<div class="line"></div>';
}
$gifts = mysql_result(mysql_query('SELECT COUNT(*) FROM `gifts_user` WHERE `komy`="'.$i['id'].'" ORDER BY `id`'),0);
echo'<div class="block_link"><a href="/gifts/'.$i['id'].'/"><img src="/images/ico/png/gift_s.png" alt="*"/> Подарки ('.$gifts.') </a></div>
<div class="line"></div>';



echo'<div class="empty_block">';


echo'    <img src="/images/ico/png/attack.png" alt="*"/>   Сила: '.$i['str'].'  <font color="#999">(урон '.round($i['str']/3.5).' -  '.round($i['str']/3).')</font>
<br/>    <img src="/images/ico/png/hp.png" alt="*"/>  Жизнь: '.$i['vit'].'
<br/>    <img src="/images/ico/png/def.png" alt="*"/> Защита: '.$i['def'].'     <font color="#999">(поглощение урона '.round($i['def']/12).' - '.round($i['def']/9).')</font>  ';
   

if($user['id'] == $i['id'] OR !$i['id']) {
echo'
<br/> <img src="/images/ico/png/exp.png" alt="*"> Опыт: '.n_f($i['exp']).'/'.n_f($exp).' <font color="#909090">('.$exp_progress.'%)</font>
<br/> <img src="/images/ico/png/gold.png" alt="*"> Золото: '.n_f($user['g']).' 
<br/> <img src="/images/ico/png/silver.png" alt="*"> Серебро: '.n_f($user['s']).' ';
}

$premium = mysql_fetch_array(mysql_query('SELECT * FROM `premium` WHERE `user` = "'.$i['id'].'"'));  
if($premium) {    echo'</br><img src="/images/ico/png/premium.png" alt="*"/> <a href="/shop/premium"><font color="#fff"><u>Премиум-аккаунт</u></font></a>';}
if($i_clan_memb){ echo'</br><img src="/images/ico/png/clan.png" alt="*"/> <font color="#7afe4e">Верность клану: '.$i_clan_memb['v'].'%</font>';
 if($i['id'] == $user['id'] AND $i_clan_memb['v'] < '100') { echo' <a href="/clan/const/"><font color="#fff"><u>поднять</u></font></a>';}}
echo'</div>
<div class="line"></div>';

	
echo'	
<div class="empty_block">
Последнее действие: ['._times(time() - $i['online']).']
</div><div class="line"></div>';

if($user['access'] >= '1' AND $user['id'] != $i['id']){
echo' <div class="empty_block">
'.$i['ip'].' </br>
'.$i['ua'].'
</div><div class="line"></div>';

$mult = mysql_result(mysql_query('SELECT COUNT(*) FROM `users` WHERE `ip` = "'.$i['ip'].'" AND `id` != "'.$i['id'].'"'),0);
echo'<div class="block_link"><a href="/adm/clon/'.$i['id'].'"><img src="/images/ico/png/friend.png" alt="*"/> Мультов '.$mult.' </a></div>
<div class="line"></div>';
}
if($user['access'] >= '2' AND $user['id'] != $i['id']){
echo'<div class="block_link"><a href="/adm/block/'.$i['id'].'/"><img src="/images/ico/png/black.png" alt="*"/> Заблокировать </a></div>
<div class="line"></div>
<div class="block_link"><a href="/adm/access/'.$i['id'].'/"><img src="/images/ico/png/premium.png" alt="*"/> Назначить на должность </a></div>
<div class="line"></div>';
}
if($user['access'] == '3' AND $user['id'] != $i['id']){
echo'<div class="block_link"><a href="/adm/acc/'.$i['id'].'/"><img src="/images/ico/png/chat_new.png" alt="*"/> Редактировать игрока </a></div>
<div class="line"></div>';
}

include './system/f.php';

?>