<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
    
if(!$user) {//Переадресация для не авторизованных
header('location: /');    
exit;}

$id = _string(_num($_GET['id']));

if(!$id && $clan) {
    $id = $clan['id'];
}

  $i = mysql_query('SELECT * FROM `clans` WHERE `id` = "'.$id.'"');
  $i = mysql_fetch_array($i);

  if(!$i) { //Если не состоите в клане  
header('location: /clans/'); 
exit;}



switch($_GET['action']) {
default:
$title = 'Клан "'.$i['name'].'"';    
include './system/h.php';
echo'<div class="title">'.$title.'</div>';


echo'<div class="empty_block">';
$_exp = round(100 / (clan_exp($i['level']) / $i['exp']));

if($_exp > 100) {
$_exp = 100;
}

echo'<table cellpadding="0" cellspacing="0"><tr>
<td width="15%">';

  if($clan && $clan['id'] == $i['id'] && $clan_memb['rank'] == 4) {
echo'<a href="/clan/gerb/">';
}
echo'<img src="/images/ico/gerb/'.$i['gerb'].'.png" alt="*"/>';

  if($clan && $clan['id'] == $i['id'] && $clan_memb['rank'] == 4) {
echo'</a>';
}
echo'
</td><td> <img src="/images/ico/png/clan.png" alt="*" width="18"/> <b> '.$i['name'].'</b><br/>

<img src="/images/ico/png/clan_level.png" alt="*" width="18"/> Уровень: <b>'.$i['level'].'</b><br/>
<img src="/images/ico/png/exp.png" alt="*" width="18"/> Опыт: '.n_f($i['exp']).' / '.n_f(clan_exp($i['level'])).' <font color="#999">('.$_exp.'%)</font></td>
</tr></table>
<img src="/images/ico/png/calendar.png" alt="*" width="18"/> О клане: '.($i['description'] == '' ? 'Нет описания!':''.$i['description'].'').'
</div>
<div class="line"></div>';



echo'<div class="block_link"><a href="/clan_forum/'.$i['id'].'/"><img src="/images/ico/png/forum.png" alt="*"/> Форум клана </a></li>
</div><div class="line"></div>';
  
if($clan['id'] == $i['id']) {
	/*
echo'<div class="block_link"><a href="/clan/builds/"><img src="/images/ico/png/clan.png" alt="*"/> Клановые строения </a></li>
</div><div class="line"></div>';	
*/
echo'<div class="block_link"><a href="/clan/task"><img src="/images/ico/png/clan_task.png" alt="*"/> Клановые задания </a></li>
</div><div class="line"></div>';
echo'
<div class="block_link"><a href="/clan/money/"><img src="/images/ico/png/clan_budget.png" alt="*"/>
Казна клана: <img src="/images/ico/png/gold.png" alt="*" width="18"/> 
'.n_f($clan['g']).' <img src="/images/ico/png/silver.png" alt="*" width="18"/> '.n_f($clan['s']).'
</a></div>
<div class="line"></div>';
echo'<div class="block_link"><a href="/clan/clan_portal"><img src="/images/ico/png/dragons.png" alt="*"/> Сокровища драконов </a></li>
</div><div class="line"></div>';
  $_chat = mysql_query('SELECT COUNT(*) FROM `chat` WHERE `clan` = "'.$clan['id'].'" AND `to` = "'.$user['id'].'" AND `read` = "0"');
  $_chat = mysql_result($_chat,0);
  
echo'<div class="block_link"><a href="/clan/chat/"><img src="/images/ico/png/clan_chat.png" alt="*"/> 
Чат '.($_chat > 0 ? '<font color="#3c3">(+)</font>':'').'</a>
</div><div class="line"></div>';

echo'<div class="block_link"><a href="/clan/clan_history/"><img src="/images/ico/png/clan_statistic.png" alt="*"/> История клана </a></li>
</div><div class="line"></div>';
}  



$max = 10;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_memb` WHERE `clan` = "'.$i['id'].'"'),0);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));

if($page > $pages) {$page = $pages;}
if($page < 1) {$page = 1;}
$start = $page * $max - $max;


echo'<div class="title"><small> Состав клана: ('.$count.') </small></div>';

$q = mysql_query('SELECT * FROM `clan_memb` WHERE `clan` = "'.$i['id'].'" ORDER BY `rank` DESC,`exp` DESC LIMIT '.$start.', '.$max.'');
  while($row = mysql_fetch_array($q)) {

  $memb = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['user'].'"');
  $memb = mysql_fetch_array($memb);

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

  
if($clan && $clan['id'] == $i['id'] && $row['user'] != $user['id'] && $clan_memb['rank'] == 4) {
echo'<span style="float: right;"><a href="/clan/memb/'.$row['id'].'/"><img src="/images/ico/png/clan_settings.png" alt="*"/></a></span>';
}


echo'<div class="block_link"><a href="/user/'.$row['user'].'/">

'.nick($memb['id']).' - '.$rank.' 
<span style="float: right;"><img src="/images/ico/png/exp.png" alt="*" width="18"/> '.n_f($row['exp']).'</span>
</a></div><div class="line"></div>';
}
echo' '.pages('/clan/'.$i['id'].'/?').'
<div class="line"></div>';





if($clan && $clan['id'] == $i['id']) {

if($clan['id'] == $i['id'] && $clan_memb['rank'] >= 0) {
 echo'<div class="block_link"><a href="/clan/settings/"><img src="/images/ico/png/clan_settings.png" alt="*"/> Настройки </a></div> 
 <div class="line"></div>';
  }

}

include './system/f.php';
break;


case 'exit'://Выход из клана
$title = 'Выйти из клана';    
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';
if(!$clan['id'] OR $clan['id'] != $i['id'] OR $clan_memb['rank'] == 4) {
header('location: /clan/');
exit;}

  if(isset($_REQUEST['ok'])){
$text=' <a href="/user/'.$user['id'].'">'.nick($user['id']).'</a> <font color="#FF2400">покинул клан</font> '; //Текст уведомления
mysql_query("INSERT INTO `clan_history` SET `clan`='".$i['id']."',`text`='".$text."',`time`='".time()."'"); //Отправляем уведомление                                              
mysql_query('DELETE FROM `clan_memb` WHERE `clan` = "'.$clan['id'].'" AND `user` = "'.$user['id'].'"');
$_SESSION['mes'] = mes('Вы успешно покинули клан!'); 
header('location: /clans/');
exit;}


     echo '<div class="empty_block item_center">
Вы действительно хотите покинуть клан? <br/>
<a href="/clan/exit/?ok"> <input class="button" type="submit" value="Да"> </a>
<div class="link_center_h"><a href="/clan/"> Нет </a></div> </div>';
echo '<div class="line"></div>';

include './system/f.php';
break;

case 'settings'://Настройки клана
$title = 'Настройки клана';    
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';
if(!$clan['id'] OR $clan['id'] != $i['id']) {
header('location: /clan/');
exit;}
if($clan['id'] == $i['id'] && $clan_memb['rank'] >= 3) {
 echo' 
 <div class="block_link"><a href="/clan/msg/"><img src="/images/ico/png/news.png" alt="*"/>  Новое обьявление </a></div>
 <div class="line"></div>
 <div class="block_link"><a href="/clan/settings/clan/"><img src="/images/ico/png/clan_settings.png" alt="*"/>  Настройки клана </a></div>
 <div class="line"></div>';
 if($clan_memb['rank'] == 4) {
 echo' <div class="block_link"><a href="/clan/settings/delete/"><img src="/images/ico/png/logout.png" alt="*"/>  Распустить клан </a></div>
 <div class="line"></div>';}
}
if($clan['id'] == $i['id'] && $clan_memb['rank'] != 4) {
echo'  <div class="block_link"><a href="/clan/exit/"><img src="/images/ico/png/logout.png" alt="*"/> Покинуть клан</a></div>';
}
include './system/f.php';
break;


case 'delete'://Распустить клан
$title = 'Распустить клан';    
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';
if(!$clan['id'] OR $clan['id'] != $i['id'] OR $clan_memb['rank'] != 4) {
header('location: /clan/');
exit;}

  if(isset($_REQUEST['ok'])){

  $del = mysql_query('SELECT * FROM `clan_memb` WHERE `clan` = "'.$clan['id'].'"');
  $del = mysql_fetch_array($del);

$text='Ваш клан был распущен';
mysql_query("INSERT INTO `mail` SET `from`='2',`to`='".$del['user']."',`text`='".$text."',`time`='".time()."'");


   mysql_query("DELETE FROM `clans` WHERE `id` = '".$clan['id']."'");
   mysql_query("DELETE FROM `clan_chat` WHERE `clan` = '".$clan['id']."'");
   mysql_query("DELETE FROM `clan_memb` WHERE `clan` = '".$clan['id']."'");
   mysql_query("DELETE FROM `clan_msg` WHERE `clan` = '".$clan['id']."'");
$_SESSION['mes'] = mes('Вы успешно распустили клан!'); 
header('location: /clans/');
exit;}


     echo '<div class="empty_block item_center">
Вы действительно хотите Распустить клан? <br/>
<a href="/clan/settings/delete/?ok"> <input class="button" type="submit" value="Да"> </a>
<div class="link_center_h"><a href="/clan/"> Нет </a></div> </div>';
echo '<div class="line"></div>';

include './system/f.php';
break;

case 'msg'://Обьявления клана
$title = 'Новое обьявление';    
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';
if(!$clan['id'] OR $clan['id'] != $i['id'] && $clan_memb['rank'] >= 3) {//Доступно для генирала и лидера клана
header('location: /clan/');
exit;}


  if(isset($_REQUEST['ok'])){
$text = _string($_POST['text']);	
  if(empty($text) or mb_strlen($text) < 3) {
header('Location: /clan/msg/');
$_SESSION['mes'] = mes('Слишком короткое cообщение!');
exit; }
  
mysql_query('INSERT INTO `clan_msg` (`clan`,
                                             `user`,
                                             `text`,
                                             `time`) VALUES ("'.$clan['id'].'",
                                                             "'.$user['id'].'",
                                                                   "'.$text.'",
                                                                   "'.time().'")');
header('location: /clan/');  
}
     echo' '.$_SESSION['mes'].'  ';
    $_SESSION['mes']=NULL; //Удаляем сесию

 echo' <div class="empty_block item_center">
<form action="/clan/msg/" method="post">
  Новое обьявление:<br/> 
  <textarea name="text" placeholder="Вводите сообщение..."></textarea> <br/>
  <input class="button" name="ok" type="submit" value="Отправить"/>
</form>

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

include './system/f.php';
break;


case 'clan'://Обьявления клана
$title = 'Новое обьявление';    
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';
if(!$clan['id'] OR $clan['id'] != $i['id'] && $clan_memb['rank'] >= 3) {//Доступно для генирала и лидера клана
header('location: /clan/');
exit;}


  if(isset($_REQUEST['change_name'])){
$name = _string($_POST['name']);  
    if($clan['g'] < 500) {    
header('location: /clan/settings/clan/');   
$_SESSION['mes1'] = mes('Недостаточно золота!');
exit;}
    
	$sql = mysql_query("SELECT COUNT(`id`) FROM `clans` WHERE `name` = '".$name."'"); 
if(mysql_result($sql, 0)){
      header("Location: /clan/settings/clan/");
     $_SESSION['mes1'] = mes('Такое название клана уже есть в базе!');
     exit;  
}

    

mysql_query('UPDATE `clans` SET `g` = `g` - 500,
                                 `name` = "'.$name.'" WHERE `id` = "'.$clan['id'].'"');
 
$_SESSION['mes1'] = mes('Название клана измененно!');
header('location: /clan/settings/clan/');
}

  if($_POST['change_rank_for_invite']) {
$rank = _string(_num($_POST['rank']));  
mysql_query('UPDATE `clans` SET `rank_for_invite` = "'.$rank.'" WHERE `id` = "'.$clan['id'].'"');
$_SESSION['mes2'] = mes('Настройки клана измененно!');
header('location: /clan/settings/clan/');
exit;  
}

  if($_POST['change_rank_for_delete']) {
$rank = _string(_num($_POST['rank']));
mysql_query('UPDATE `clans` SET `rank_for_delete` = "'.$rank.'" WHERE `id` = "'.$clan['id'].'"');
$_SESSION['mes3'] = mes('Настройки клана измененно!');
header('location: /clan/settings/clan/');
exit;  
}
  
  
     echo' '.$_SESSION['mes1'].'  ';
    $_SESSION['mes1']=NULL; //Удаляем сесию
echo'<div class="empty_block item_center">
  <form action="/clan/settings/clan/" method="post">
  Сменить название клана: <br/>
  <input  name="name" value="'.$clan['name'].'"/><br/> 
  <input class="button"type="submit" value="Сохранить" name="change_name"/>
  <br/> <small>Стоимость <img src="/images/ico/png/gold.png" alt="*" width="16"/> 500 </small>
  </form> 
</div>
 <div class="line"></div>';

      echo' '.$_SESSION['mes2'].'  ';
    $_SESSION['mes2']=NULL; //Удаляем сесию
 echo'  <div class="empty_block item_center">
 Приглашать в клан может:<br/>
   <form action="/clan/settings/clan/" method="post">
   <select name="rank">
   <option value="0">Новобранец</option>
   <option value="1">Боец</option>
   <option value="2">Офицер</option>
   <option value="3">Генерал</option>
   <option value="4">Лидер клана</option>
   </select><br/>
   
    <input class="button" type="submit" value="Сохранить" name="change_rank_for_invite"/>
   </form>
</div>
 <div class="line"></div>';
 
      echo' '.$_SESSION['mes3'].'  ';
    $_SESSION['mes3']=NULL; //Удаляем сесию
 echo'  <div class="empty_block item_center">
 Удалять из клана может:<br/>
   <form action="/clan/settings/clan/" method="post">
   <select name="rank">
   <option value="0">Новобранец</option>
   <option value="1">Боец</option>
   <option value="2">Офицер</option>
   <option value="3">Генерал</option>
   <option value="4">Лидер клана</option>
   </select><br/>
   
   <input class="button" type="submit" value="Сохранить" name="change_rank_for_delete"/>
   </form>
</div>
 <div class="line"></div>';
 
include './system/f.php';
break;


case 'money':
$title = 'Казна клана';    
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';
if(!$clan['id'] OR $clan['id'] != $i['id']) {
header('location: /clan/');
exit;}



  if(isset($_REQUEST['ok'])){
$g = _string(_num($_POST['g']));
$s = _string(_num($_POST['s']));

    if($g <= '0' AND $s <= '0') {   
header('location: /clan/money/');
exit;}

    if($g > $user['g'] OR $s > $user['s']) {   
$_SESSION['mes'] = mes('У вас недостаточно ресурсов!');
header('location: /clan/money/');
exit;
}
    if($g && $user['g'] >= $g AND $g < '2147000000') {   
mysql_query('UPDATE `clans` SET `g` = `g` + '.$g.' WHERE `id` = "'.$clan['id'].'"');
mysql_query('UPDATE `users` SET `g` = `g` - '.$g.' WHERE `id` = "'.$user['id'].'"');  
}
    
    if($s && $user['s'] >= $s AND $s < '2147000000') {    
mysql_query('UPDATE `clans` SET `s` = `s` + '.$s.' WHERE `id` = "'.$clan['id'].'"');
mysql_query('UPDATE `users` SET `s` = `s` - '.$s.' WHERE `id` = "'.$user['id'].'"');  
}
$_SESSION['mes'] = mes('Казна клана успешно пополнена!');
header('location: /clan/money/');
exit;
}



     echo' '.$_SESSION['mes'].'  ';
    $_SESSION['mes']=NULL; //Удаляем сесию
echo'<div class="empty_block">
   Казна клана: <img src="/images/ico/png/silver.png" alt="*" width="18"/> '.n_f($i['s']).' <img src="/images/ico/png/gold.png" alt="*" width="18"/> '.n_f($i['g']).'<br/>
У вас на счету: <img src="/images/ico/png/silver.png" alt="*" width="18"/> '.n_f($user['s']).' <img src="/images/ico/png/gold.png" alt="*" width="18"/> '.n_f($user['g']).'
</div><div class="line"></div>';

echo'<div class="empty_block item_center">
<form action="/clan/money/" method="post">
  <img src="/images/ico/png/gold.png" alt="*" width="18"/>   <input name="g" value="0"/><br/>
  <img src="/images/ico/png/silver.png" alt="*" width="18"/> <input name="s" value="0"/><br/>
  <input class="button" name="ok" type="submit" value="Пополнить"/>
</form>
</div><div class="line"></div>';


include './system/f.php';
break;


case 'memb':
if(!$clan['id'] OR $clan['id'] == $i['id'] && $clan_memb['rank'] < 4) {
header('location: /clan/');
exit;}

$memb = _string(_num($_GET['memb']));

  $memb = mysql_query('SELECT * FROM `clan_memb` WHERE `clan` = "'.$clan['id'].'" AND `id` = "'.$memb.'"');
  $memb = mysql_fetch_array($memb);

  if(!$memb) {
header('location: /clan/');
exit;}
  
  $memb_user = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$memb['user'].'"');
  $memb_user = mysql_fetch_array($memb_user);
  
$title = $memb_user['login'];    
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';

    if($memb['rank'] != 3 && $memb['rank'] < $clan_memb['rank']) {
  
  if($_GET['up'] == true) { 
mysql_query('UPDATE `clan_memb` SET `rank` = "'.($memb['rank'] + 1).'" WHERE `clan` = "'.$clan['id'].'" AND `id` = "'.$memb['id'].'"');
$_SESSION['mes'] = mes('Игрок повышен в звании!');
header('location: /clan/memb/'.$memb['id'].'/');
exit;
  }
 }

  if($memb['rank'] < $clan_memb['rank'] && $memb['rank'] > 0) {

  if($_GET['down'] == true) {
mysql_query('UPDATE `clan_memb` SET `rank` = "'.($memb['rank'] - 1).'" WHERE `clan` = "'.$clan['id'].'" AND `id` = "'.$memb['id'].'"');
$_SESSION['mes'] = mes('Игрок понижен в звании!');
header('location: /clan/memb/'.$memb['id'].'/');
exit;
  }
 }

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

       echo' '.$_SESSION['mes'].'  ';
    $_SESSION['mes']=NULL; //Удаляем сесию
echo'<div class="empty_block">
Звание: '.$rank.'<br/>
  <img src="/images/ico/png/exp.png" alt="*" width="18"/> Опыт: '.n_f($memb['exp']).'<br/>
  <img src="/images/ico/png/gold.png" alt="*" width="18"/> '.n_f($memb['g']).'<br/>
<img src="/images/ico/png/silver.png" alt="*" width="18"/> '.n_f($memb['s']).'<br/>
Дата вступления: '.date('d.m.y', $memb['time']).'

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


   if($memb['rank'] != 3 && $memb['rank'] < $clan_memb['rank']) {
echo'<div class="link_center"><a href="/clan/memb/'.$memb['id'].'/?up=true"><font color="#fff">Повысить</font></a></div>';
}

  if($memb['rank'] < $clan_memb['rank'] && $memb['rank'] > 0) {
echo'<div class="link_center"><a href="/clan/memb/'.$memb['id'].'/?down=true"><font color="#fff">Понизить</font></a></div>';
}


?>



<?

  if($clan_memb['rank'] == 4) {
  
    if($_GET['lider'] == true) {    
mysql_query('UPDATE `clan_memb` SET `rank` = "4" WHERE `id` = "'.$memb['id'].'"');
mysql_query('UPDATE `clan_memb` SET `rank` = "3" WHERE `user` = "'.$user['id'].'"'); 
$_SESSION['mes'] = mes('Вы успешно передали лидера!');
header('location: /clan/memb/'.$memb['id'].'/');
exit;
}

echo'<div class="link_center"><a href="/clan/memb/'.$memb['id'].'/?lider=true"><font color="#fff">Передать лидерство</font></a></div>';
}


  if($memb['rank'] < $clan_memb['rank'] && $clan_memb['rank'] >= $clan['rank_for_delete']) {
  
  if($_GET['delete'] == true) {
mysql_query('DELETE FROM `clan_memb` WHERE `id` = "'.$memb['id'].'"');
$_SESSION['mes'] = mes('Вы успешно изгнали '.$memb_user['login'].'!');
header('location: /clan/');
exit;
}
  
echo' <div class="link_center"><a href="/clan/memb/'.$memb['id'].'/?delete=true"><font color="#fff">Исключить</font></a></div>';
}

echo'</div><div class="line"></div>';
include './system/f.php';
break;

////////////////////////////////////////
////////////////////////////////
case 'builds':
$title = 'Клановые строения';    
include './system/h.php';  
$id = _string(_num($_GET['id']));
echo'<div class="title">'.$title.'</div>';
if(!$clan['id'] OR $clan['id'] != $i['id']) {
header('location: /clan/');
exit;}




	echo'  <div class="block_link"><a href="/clan/build_1">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/builds/build1_0.png">
</td><td> 
<font color="#fff"> <b>Академия</b> ('.$i['build_1'].' из 15) </font><br>
+0% к клановому опыту
</td></tr>
</tbody></table>
</a></div><div class="line"></div>';  
	echo'  <div class="block_link"><a href="/lair">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/builds/build2_no.png">
</td><td> 
<font color="#fff"> <b>Архивы знаний</b> ('.$i['build_2'].' из 15) </font><br>
+4% к личному опыту
</td></tr>
</tbody></table>
</a></div><div class="line"></div>';  
	echo'  <div class="block_link"><a href="/lair">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/builds/build3_no.png">
</td><td> 
<font color="#fff"> <b>Магическая лавка</b> ('.$i['build_3'].' из 15) </font><br>
+4% к серебру
</td></tr>
</tbody></table>
</a></div><div class="line"></div>';  
	echo'  <div class="block_link"><a href="/lair">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/builds/build4_no.png">
</td><td> 
<font color="#fff"> <b>Трофейный зал</b> ('.$i['build_4'].' из 15) </font><br>
+6% к параметрам от трофеев
</td></tr>
</tbody></table>
</a></div><div class="line"></div>';  
	echo'  <div class="block_link"><a href="/lair">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/builds/build5_no.png">
</td><td> 
<font color="#fff"> <b>Оружейная</b> ('.$i['build_5'].' из 15) </font><br>
+8% к опыту при разборе вещей
</td></tr>
</tbody></table>
</a></div><div class="line"></div>';  
	echo'  <div class="block_link"><a href="/lair">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/builds/build6_no.png">
</td><td> 
<font color="#fff"> <b>Обелиск доблести</b> ('.$i['build_6'].' из 15) </font><br>
+4% к очкам доблести
</td></tr>
</tbody></table>
</a></div><div class="line"></div>';  




echo'<div class="empty_block item_center">
Чем выше уровень построек, тем больше бонусы!
</div><div class="line"></div>';
include './system/f.php';
break;

//////////////////////////////////////////
/////////////////////////////////////////
case 'build_1':
$title = 'Академия';    
include './system/h.php';  
$id = _string(_num($_GET['id']));
echo'<div class="title">'.$title.'</div>';
if(!$clan['id'] OR $clan['id'] != $i['id']) {
header('location: /clan/');
exit;}



  function value($i) {
  
    switch($i) {
case 0:
$value = 'g';
break;
case 1:
$value = 's';
break;
case 2:
$value = 's';
break;
case 3:
$value = 's';
break;
case 4:
$value = 's';
break;
case 5:
$value = 'g';
break;
case 6:
$value = 's';
break;
case 7:
$value = 's';
break;
case 8:
$value = 's';
break;
case 9:
$value = 's';
break;
case 10:
$value = 'g';
break;
case 11:
$value = 's';
break;
case 12:
$value = 's';
break;
case 13:
$value = 's';
break;
case 14:
$value = 's';
break;
case 15:
$value = 's';
break;
}  
return $value;
}

  function cost($i) {
    switch($i) {
case 0:
$cost = 1000; 
break;
case 1:
$cost = 60000; 
break;
case 2:
$cost = 120000; 
break;
case 3:
$cost = 180000; 
break;
case 4:
$cost = 189600; 
break;
case 5:
$cost = 120000; 
break;
case 6:
$cost = 240000; 
break;
case 7:
$cost = 360000; 
break;
case 8:
$cost = 388600; 
break;
case 9:
$cost = 180000; 
break;
case 10:
$cost = 360000; 
break;
case 11:
$cost = 540000; 
break;
case 12:
$cost = 729600; 
break;
case 13:
$cost = 240000; 
break;
case 14:
$cost = 480000; 
break;
case 15:
$cost = 720000; 
break;
}
return $cost;
}

  if($i['id'] == $clan['id'] && $clan_memb['rank'] == 4 && $i['build_1'] < 14) {

  if($_GET['up'] == true) {
  
    if($i[(value($i['build_1']) == 'g' ? 'g':'s')] >= cost($i['build_1'])) {
    
mysql_query('UPDATE `clans` SET `build_1` = `build_1` + 1,
     `'.(value($i['build_1']) == 'g' ? 'g':'s').'` = `'.(value($i['build_1']) == 'g' ? 'g':'s').'` - '.cost($i['build_1']).' WHERE `id` = "'.$i['id'].'"');
header('location: /clan/build_1/');
$_SESSION['mes'] = mes('Успешно улучшено!');  
exit;  
}else{

header('location: /clan/build_1/');
$_SESSION['mes'] = mes('Недостаточно ресурсов!');  
exit;  	
}	
  
  }
  }
echo' '.$_SESSION['mes'].' ';
    $_SESSION['mes']=NULL; //Удаляем сесию
  
	echo'  <div class="empty_block">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/builds/build1_0.png">
</td><td> 
<font color="#fff"> <b>Академия</b> ('.$i['build_1'].' из 15) </font><br>
Обучение в академии увеличивает получаемый клановый опыт от всех участников клана
</td></tr>
</tbody></table>';
  if($i['id'] == $clan['id'] && $clan_memb['rank'] == 4 && $i['build_1'] < 14) {
echo'<div class="link_center"><a href="/clan/build_1/?up=true"> <img src="/images/ico/png/'.(value($i['build_1']) == 'g' ? 'gold':'silver').'.png" alt="*"/ width="18">'.cost($i['build_1']).'</a></div> ';
}
echo'</div><div class="line"></div>';  

echo'<div class="empty_block item_center">
Дополнительный бонус: <font color="lime">30%</font> </br>
<center><a href="/"><input class="button" type="submit" name="start"value="Активировать"/></a></center> 
<font color="#90b0c0"> 24 часа </font></br>
Дополнительный бонус: <font color="lime">100%</font>
<center><a href="/"><input class="button" type="submit" name="start"value="Активировать"/></a></center> 
<font color="#90b0c0"> 24 часа </font></br>
</div><div class="line"></div>';  
echo'<div class="block_link"><a href="/clan/builds/"><img src="/images/ico/png/back.png" alt="*"/> Назад к строениям </a></li>
</div><div class="line"></div>';
include './system/f.php';
break;






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


case 'gerb':
if($clan['id'] == 0 || $clan_memb['rank'] < 4){
header('location: /clan/');
exit;
}

$title = 'Клановый герб'; 
include './system/h.php'; 


if(isset($_POST['id'])) {
$id = _num($_POST['id']);
if($id > 1 || $id < 16) {
mysql_query("UPDATE `clans` SET `gerb` = '$id' WHERE `id` = '".$clan['id']."'");
header("Location: /clan/");
exit();
}

}


echo '<div class="title"> Выберите герб </div>';
echo ' <div class="empty_block"/>
<form method="post" action="">';
for($i = 1; $i < 16; $i++) {

echo '<input type="radio" name="id" value="'.$i.'" /> 
<img src="/images/ico/gerb/'.$i.'.png" /> </br>'; 
echo '';
}
echo '

<center><input class="button" type="submit" value="Установить"></center>
</form>
</div><div class="line"></div>';
include './system/f.php'; 
break;



case 'chat':


$title = 'Клановый чат';
include './system/h.php';  
echo '<div class="title">'.$title.'</div>';




$text = _string($_POST['text']);
$to = _string(_num($_GET['to']));

  if($to) {
$_to = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$to.'"');
$_to = mysql_fetch_array($_to); }
  
  
  
  
  if(isset($_REQUEST['text'])){
$antiflood = mysql_fetch_array(mysql_query('SELECT * FROM `clan_chat` WHERE `user` = \''.$user['id'].'\' ORDER BY `time` DESC LIMIT 1'));
  
  if(empty($text) or mb_strlen($text,'UTF-8') < 1){
header("Location: ?");
$_SESSION['mes'] = mes('Пустое сообщение!');
exit;}
  if(time() - $antiflood['time'] < 0){
header("Location: ?");
$_SESSION['mes'] = mes('Нельзя писать так часто!');
exit;}
    





mysql_query('INSERT INTO `clan_chat` (`clan`,`user`,`to`,`text`,`time`)
                            VALUES ("'.$clan['id'].'","'.$user['id'].'",  "'.$_to['id'].'", "'.$text.'", "'.time().'")');
header('location: /clan/chat/');
$_SESSION['mes'] = mes('Сообщение отправленно!');
exit;  
}


  
  
     echo' '.$_SESSION['mes'].'  ';
    $_SESSION['mes']=NULL; //Удаляем сесию
echo'   
<div class="empty_block" align="center">
<form action="/clan/chat/?to='.$to.'" method="post">
Сообщение:<br/>
<textarea name="text" style="width: 70%;"> '.($to ? $_to['login'].', ':'').' </textarea><br/>
<input class="button" name="send_message" value="Отправить" type="submit">';
echo'</form>
<small><a href="'.$HOME.'/clan/chat">Обновить</a> | <a href="'.$HOME.'/smile">Смайлы</a> | <a href="'.$HOME.'/bb">BB коды</a></small>
</div>
<div class="line"></div>';


?>

  

<?

$max = 10;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_chat` WHERE `clan` = "'.$clan['id'].'"'),0);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));

if($page > $pages) {$page = $pages;}
if($page < 1) {$page = 1;}
$start = $page * $max - $max;

if($count > 0) {
$q = mysql_query('SELECT * FROM `clan_chat` WHERE `clan` = "'.$clan['id'].'" ORDER BY `id` DESC LIMIT '.$start.', '.$max.'');
  while($row = mysql_fetch_array($q)) {
    echo'<div class="empty_block">';

  if($row['to'] == $user['id'] && $row['read'] == 0) {
mysql_query('UPDATE `clan_chat` SET `read` = "1" WHERE `id` = "'.$row['id'].'"');  
}

  $sender = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['user'].'"');
  $sender = mysql_fetch_array($sender);

echo'<a href="/user/'.$sender['id'].'/">'.nick($sender['id']).'</a>';//Логин отправителя

  if($sender['id'] != $user['id']) {//Ответить на сообщение
echo'<a href="/clan/chat/?to='.$sender['id'].'">(&#187;)</a>';
}
 if($clan_memb['rank'] >= 3) {//Доступно для лидера и генерала
$comment = _string(_num($_GET['comment']));

  if($comment) {
mysql_query('DELETE FROM `clan_chat` WHERE `clan` = "'.$clan['id'].'" AND `id` = "'.$comment.'"');
header('location: /clan/chat/?page='.$page);
$_SESSION['mes'] = mes('Сообщение удалено!');
exit;}
echo' <a href="/clan/chat/?page='.$page.'&comment='.$row['id'].'">[x]</a>';
}


echo'<span style="float: right;"><small>'.vremja($row['time']).'</small></span>';
echo':<br/>';


echo'<font color="'.color($sender[id]).'">';//Цвет сообщений
  

  if($row['to']) {//Если ответ вам
      $__to = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['to'].'"');
      $__to = mysql_fetch_array($__to);
if($__to['id'] == $user['id']) {
echo'<font color="#90c090">';
}else{
echo'<font color="'.color($sender[id]).'">';  
}
echo''.$__to['login'].',
</font>';
 
}




echo''.bbcode(smile($row['text'])).'';//Сообщение
echo'</font>';//Закрываем цвет сообщений



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

}else{ 
echo '<div class="line"></div>
<div class="empty_block item_center"> Сообщений нет </div>
<div class="line"></div>';
}


echo''.pages('/clan/chat/?').'';
echo'<div class="line"></div>';
include './system/f.php';
break;


case 'const'://Верность клану
$title = 'Верность клану';    
include './system/h.php';   
echo '<div class="title">'.$title.'</div>';

  $i_clan_memb = mysql_query('SELECT * FROM `clan_memb` WHERE `user` = "'.$user['id'].'"');
  $i_clan_memb = mysql_fetch_array($i_clan_memb);
if($i_clan_memb['v'] >= '100') {
header('location: /user');
exit;}

echo'<div class="empty_block"><font color="#90b0c0">
Влияет на получаемый клановый опыт </br>
Начальная верность 10% </br>
Каждый день в клане повышает верность на 3% </br>
Максимальная верность 150% </br>
</font></div>
<div class="line"></div>';


  if($i_clan_memb['v'] < '50') { $cost=10; }else{ $cost=100; }
  if($_GET['up'] == true){  
    if($user['g'] < $cost){
$_SESSION['mes'] = mes('Недостаточно золота!');  
header('location: /clan/const');
exit;}

if($i_clan_memb['v'] < '50') {  //Поднять до 50%
mysql_query('UPDATE  `users` SET `g` = `g` - "10" WHERE `id`="'.$user['id'].'" LIMIT 1');
mysql_query('UPDATE  `clan_memb` SET `v` = "50" WHERE `user`="'.$user['id'].'" LIMIT 1');
}else{//Поднять до 100%
mysql_query('UPDATE  `users` SET `g` = `g` - "100" WHERE `id`="'.$user['id'].'" LIMIT 1');
mysql_query('UPDATE  `clan_memb` SET `v` = "100" WHERE `user`="'.$user['id'].'" LIMIT 1');	
}
header('location: /clan/const');
exit; 
}
	echo' '.$_SESSION['mes'].'  ';
	$_SESSION['mes']=NULL; //Удаляем сесию
echo'<div class="empty_block item_center">
<font color="#90b0c0">Ваша верность клану '.$i_clan_memb['v'].'%</font>';
if($i_clan_memb['v'] < '50') {//Поднять до 50%
  echo'<div class="link_center"><a href="/clan/const?up=true">Поднять за <img src="/images/ico/png/gold.png" alt="*"/>10</a></div>
  <font color="#90b0c0">Поднять вашу верность до </font><font color="lime">50%</font>';
}else{//Поднять до 100%
  echo'<div class="link_center"><a href="/clan/const?up=true">Поднять за <img src="/images/ico/png/gold.png" alt="*"/>100</a></div>
  <font color="#90b0c0">Поднять вашу верность до </font><font color="lime">100%</font>';
}
echo'</div>
<div class="line"></div>';
echo'<div class="block_link"><a href="/user"><img src="/images/ico/png/back.png" alt="*"/> Назад к профиль </a></div>
<div class="line"></div>';
include './system/f.php';
break;



case 'clan_history'://История клана
$title = 'История клана';    
include './system/h.php';   
echo '<div class="title">'.$title.'</div>';


$max = 10;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_history` WHERE `clan` = "'.$clan['id'].'"'),0);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));

if($page > $pages) {$page = $pages;}
if($page < 1) {$page = 1;}
$start = $page * $max - $max;

if($count > 0) {
$q = mysql_query('SELECT * FROM `clan_history` WHERE `clan` = "'.$clan['id'].'" ORDER BY `id` DESC LIMIT '.$start.', '.$max.'');
  while($row = mysql_fetch_array($q)) {
    echo'<div class="empty_block">';



  $sender = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['user'].'"');
  $sender = mysql_fetch_array($sender);


echo'<span style="float: right;"><small>'.vremja($row['time']).'</small></span>
'.bbcode(smile($row['text'])).'
</div>
<div class="line"></div>';
}

}

echo''.pages('/clan/chat/?').'';
echo'</div class="line"></div>';
echo'<div class="block_link"><a href="/clan"><img src="/images/ico/png/back.png" alt="*"/> Назад в клан </a></div>
<div class="line"></div>';
include './system/f.php';
break;




case 'task'://Клановые задания
$title = 'Клановые задания';    
include './system/h.php';   
echo '<div class="title">'.$title.'</div>';
  $memb = mysql_query('SELECT * FROM `clan_memb` WHERE `user` = "'.$user['id'].'"');
  $memb = mysql_fetch_array($memb);

echo'<div class="empty_block">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="padding-top: 5px;">
<tbody><tr><td width="25%">
<center><img src="/images/ico/task/clan_task.png" alt="*" width="72"/></center>
</td>
<td width="75%">
<font color="#fff">Выполняй задания и добывай алмазы для клана </font></br>
Собрано алмазов: 68
</td>
</tr></tbody>
</table>
</div><div class="line"></div>';

////////////////////////////// Обновление новых квестов////////////////////////////
//Добавляем только ежеднемные задания 
$req_task = mysql_query ('select * from `clan_task_user` WHERE (`clan`="'.$memb['clan'].'") AND (`complete`="0")');
if (mysql_num_rows ($req_task) < 10) {
    // Обновление квестов
$req_task = mysql_query ('select * from `clan_task` ');
$i_task = 0;
while ($task__ = mysql_fetch_array ($req_task)) {
$q_task = mysql_query ('SELECT * FROM `clan_task_user` WHERE (`clan`="'.$memb['clan'].'") AND (`task`="'.$task__['id'].'") ');
if (mysql_num_rows ($q_task)==0) {
$i_task++;
if ($i_task <10) {
mysql_query ('INSERT INTO `clan_task_user` (`clan`, `task`) VALUES ("'.$memb['clan'].'", "'.$task__['id'].'") ');
}}}
}
////////////////////////////////////////////////////////////////////////

// Обновление неактивных квестов
$req = mysql_query ('select * from `clan_task_user` WHERE (`clan`="'.$memb['clan'].'") AND (`complete`="1") ');
if (mysql_num_rows ($req) < 10) {
    $i = 0;
    while ($clan_task_user = mysql_fetch_array ($req)) {
        
  if ($clan_task_user['time']<time ()) {
$i++;
if ($i < 10) {
mysql_query ('UPDATE `clan_task_user` SET `complete`="0",`how`="0" WHERE (`clan`="'.$memb['clan'].'") AND (`task`="'.$clan_task_user['task'].'") ');
   }
  }    
 }
}




  $id = _string(_num($_GET['task'])); //Оприделяем какое задание
$clan_task = mysql_fetch_array(mysql_query ('SELECT * FROM `clan_task` WHERE (`id`="'.$id.'")'));
$clan_task_user = mysql_fetch_array(mysql_query ('SELECT * FROM `clan_task_user` WHERE (`clan`="'.$memb['clan'].'") AND (`task`="'.$clan_task['id'].'")'));
  
  if($id){
	  if($clan_task_user['user'] == 0){
mysql_query ('UPDATE `clan_task_user` SET `user`="'.$user['id'].'", `time_task`="'.(time()+60*60*40).'" WHERE (`clan`="'.$memb['clan'].'") AND (`task`="'.$id.'")');
	  }elseif($clan_task_user['user_2'] == 0){
mysql_query ('UPDATE `clan_task_user` SET `user_2`="'.$user['id'].'" WHERE (`clan`="'.$memb['clan'].'") AND (`task`="'.$id.'") ');
	  }


header('location: /clan/task');
exit;
}



// Список невыполненных заданий
$req = mysql_query ('select * from `clan_task_user` WHERE (`clan`="'.$memb['clan'].'") AND (`complete`="0") ORDER BY `id` ASC');
if (mysql_num_rows ($req) == 0) {
    echo 'mkj';//Пишем, что нет заданий
}else{
    while ($clan_task_user = mysql_fetch_array ($req)) {        
        $clan_task = mysql_fetch_array(mysql_query ('SELECT * FROM `clan_task` WHERE (`id`="'.$clan_task_user['task'].'")'));
       
echo '<div class="empty_block">
<font color="#fff"> <img src="/images/ico/png/task.png" width="18"> '.$clan_task['name'].'</font><br/>
<font color="#90b0c0">';
  if ($clan_task_user['how']>=$clan_task['how']) {
    echo '  <img src="/images/ico/png/gold.png" alt="*" width="16"/> '.$clan_task['_gold'].'
            <img src="/images/ico/png/silver.png" alt="*" width="16"/> '.$clan_task['_silver'].'
            <img src="/images/ico/png/exp.png" alt="*" width="16"/> '.$clan_task['_exp'].' </br>'; 
}
echo'Прогресс: '.$clan_task_user['how'].' из '.$clan_task['how'].' </font><br/>';   
if($clan_task_user['user'] != 0){ echo' '.nick($clan_task_user['user']).' ';}
if($clan_task_user['user_2'] != 0){ echo' '.nick($clan_task_user['user_2']).' ';}
if($clan_task_user['time_task'] != 0){ echo' </br> Осталось: '._time($clan_task_user['time_task']-time()).' ';}


  if ($clan_task_user['how']>=$clan_task['how']) {
echo '<center><a href="/task?complete='.$clan_task['id'].'"> <input class="button" type="submit" value="Забрать награду"/></a></center>';     
}elseif($clan_task_user['user'] == 0){
	if(mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_task_user` WHERE `clan` = "'.$memb['clan'].'" AND `user` = "'.$user['id'].'" OR `user_2` = "'.$user['id'].'"'),0) == 0){
echo'<form action="/clan/task?task='.$clan_task_user['task'].'" method="post">
<center><input class="button" type="submit" value="Выполнить"/></center>
</form>';	
	}
}elseif($clan_task_user['user_2'] == 0 AND $clan_task_user['user'] != $user['id']){
	if(mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_task_user` WHERE `clan` = "'.$memb['clan'].'" AND `user` = "'.$user['id'].'" OR `user_2` = "'.$user['id'].'"'),0) == 0){
echo'<form action="/clan/task?task='.$clan_task_user['task'].'" method="post">
<center><input class="button" type="submit" value="Помочь с заданием"/></center>
</form>';
	}	
}
echo '</div>
<div class="line"></div>';
    }
}


// Список выполненных задани
$req = mysql_query ('select * from `clan_task_user` WHERE (`clan`="'.$memb['clan'].'") AND (`complete`="1") ');
if (mysql_num_rows ($req) != 0) {

    while ($clan_task_user = mysql_fetch_array ($req)) {
        $clan_task = mysql_fetch_array(mysql_query ('SELECT * FROM `clan_task` WHERE (`id`="'.$clan_task_user['task'].'")'));
			
echo '
<div class="empty_block"> '.$clan_task['name'].' </span><br/>
Будет доступно через: '._time($clan_task_user['time']-time()).' </div>
<div class="line"></div>';
   }
}
echo' <div class="empty_block item_center"> 
<font color="#90b0c0">За каждое выполненное задание клан получает от 1 до 10 алмазов (случайно), а герой золото и серебро в награду
Подробнее </font><a href="/task/dailyInfo"><font color="#fff">здесь</font></a>
</div><div class="line"></div>';


echo'<div class="block_link"><a href="/clan"><img src="/images/ico/png/back.png" alt="*"/> Назад в клан </a></div>
<div class="line"></div>';
include './system/f.php';
break;

case 'clan_portal'://Сокровища драконов
$title = 'Сокровища драконов';    
include './system/h.php';   
echo '<div class="title">'.$title.'</div>';
     echo' '.$_SESSION['mes'].'  ';
    $_SESSION['mes']=NULL; //Удаляем сесию
	
  $memb = mysql_fetch_array(mysql_query('SELECT * FROM `clan_memb` WHERE `user` = "'.$user['id'].'"'));
  $clan = mysql_fetch_array(mysql_query('SELECT * FROM `clans` WHERE `id` = "'.$memb['clan'].'"'));

    $clan_lair = _string(_num($_GET['clan_lair'])); //Оприделяем какой дракон	
	$lair = mysql_fetch_array(mysql_query('SELECT * FROM `clan_lair` WHERE `id` = "'.$clan_lair.'" '));
$lair_boss = mysql_fetch_array(mysql_query('SELECT * FROM `clan_lair_boss` WHERE `clan` = "'.$memb['clan'].'" AND `dead` = "0" '));

	if($clan_lair){
if($memb['rank'] < 3){
$_SESSION['mes'] = mes('Открить портал может лидер клана или генерал!');
header('location: /clan/clan_portal');
exit; } 

if(mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_lair_boss` WHERE `clan` = "'.$memb['clan'].'" AND `dead` = "0" '),0) != 0){
$_SESSION['mes'] = mes('У вас имеется открытый портал!');
header('location: /clan/clan_portal');
exit; } 
	
//Если нет дракона, записываем
mysql_query('INSERT INTO `clan_lair_boss`  (`clan`,
											`lair`,
											`str`,
											`vit`,
											`def`,
											`time`) VALUES  ("'.$memb['clan'].'", 
															"'.$clan_lair.'", 
															"'.$lair['lair_attack'].'", 
															"'.$lair['lair_hp'].'", 
															"'.$lair['lair_def'].'",
															"'.(time()+3600*30).'" )');
$text='Ваш клан открыл портал к сокровищам. Убейте дракона и заберите сокровища!';															
	mysql_query('INSERT INTO `clan_msg` (`clan`,
                                          `user`,
                                          `text`,
                                          `time`) VALUES ("'.$memb['clan'].'",
                                                          "0",
                                                          "'.$text.'",
                                                          "'.time().'")');
$_SESSION['mes'] = mes('Вы открыли портал в '.$lair['gde2'].'!');


mysql_query("DELETE FROM `clan_lair_memb` WHERE `clan` = '".$clan['id']."'"); //удаляем игроков из старого босса
header('location: /clan/clan_portal');
exit;
}
echo'  <div class="empty_block">
<table> <tbody><tr>
<td width="23%">
<img src="/images/ico/clan_lair/location1.jpg">
</td><td> 
<font color="#fff"><b>Пещера дракона</b></font> <br>
Охраняет зеленый дракон
'.$lair_boss['id'].'
'.($lair_boss['lair'] == 1 ? '</br><font color="#7afe4e">Портал открыт</font></td></tr></tbody></table>':'
</td></tr></tbody></table>
<center> '.($clan['diamond'] >= 75 ? '<div class="link_center"><a href="/clan/clan_portal?clan_lair=1"> Открыть за <img src="/images/ico/png/diamond.png" width="18">75 </a></div>':'<div class="button2">Открыть за <img src="/images/ico/png/diamond.png" width="18">75</div>').'</center>
').'
</div><div class="line"></div>';

echo'  <div class="empty_block">
<table> <tbody><tr>
<td width="23%">
<img src="/images/ico/clan_lair/location2.jpg">
</td><td> 
<font color="#fff"><b>Казна гномов</b></font> <br>
Охраняет синий дракон

'.($lair_boss['lair'] == 2 ? '</br><font color="#7afe4e">Портал открыт</font></td></tr></tbody></table>':'
</td></tr></tbody></table>
<center> '.($clan['diamond'] >= 125 ? '<div class="link_center"><a href="/clan/clan_portal?clan_lair=2"> Открыть за <img src="/images/ico/png/diamond.png" width="18">125</a></div>':'<div class="button2">Открыть за <img src="/images/ico/png/diamond.png" width="18">125</div>').'</center>
').'
</div><div class="line"></div>';

echo'  <div class="empty_block">
<table> <tbody><tr>
<td width="23%">
<img src="/images/ico/clan_lair/location3.jpg">
</td><td> 
<font color="#fff"><b>Сокровищница королей</b></font> <br>
Охраняет красный дракон

'.($lair_boss['lair'] == 3 ? '</br><font color="#7afe4e">Портал открыт</font></td></tr></tbody></table>':'
</td></tr></tbody></table>
<center> '.($clan['diamond'] >= 175 ? '<div class="link_center"><a href="/clan/clan_portal?clan_lair=3"> Открыть за <img src="/images/ico/png/diamond.png" width="18">175</a></div>':'<div class="button2">Открыть за <img src="/images/ico/png/diamond.png" width="18">175</div>').'</center>
').'
</div><div class="line"></div>';

echo'  <div class="empty_block">
<table> <tbody><tr>
<td width="23%">
<img src="/images/ico/clan_lair/location4.jpg">
</td><td> 
<font color="#fff"><b>Сокровищница Богов</b></font> <br>
Охраняет черный дракон

'.($lair_boss['lair'] == 4 ? '</br><font color="#7afe4e">Портал открыт</font></td></tr></tbody></table>':'
</td></tr></tbody></table>
<center> '.($clan['diamond'] >= 250 ? '<div class="link_center"><a href="/clan/clan_portal?clan_lair=4"> Открыть за <img src="/images/ico/png/diamond.png" width="18">250</a></div>':'<div class="button2">Открыть за <img src="/images/ico/png/diamond.png" width="18">250</div>').'</center>
').'
</div><div class="line"></div>';

echo'<div class="block_link"><a href="/clan"><img src="/images/ico/png/back.png" alt="*"/> Назад в клан </a></div>
<div class="line"></div>';
include './system/f.php';
break;

}
?>