<? 
include './system/common.php';
include './system/functions.php';
include './system/user.php';
$title = 'Разрушители';
include './system/h.php';  




  if($user) {
echo'<div class="title">'.$title.'</div>';
  

 //Узнай новости!
 if($user['notified'] == '0'){
echo'<div class="line"></div>	
<div class="block_link"><a href="/forum/sub/1?notified=true"> <img src="/images/ico/png/news.png">  <font color="#7afe4e">Узнай новости!</font></a></div>
<div class="line"></div>';
 }
  ///////////////////ЕСЛИ ЕСТЬ НЕПРОЧИТАННЫЕ СООБЩЕНИЯ
echo'  '.($mail > 0?' <div class="line"></div><div class="block_link"><a href="/mail/"> <img src="/images/ico/png/post.png"> Новое сообщение <b>+'.$mail.'</b> </a></div><div class="line"></div>' : '').'';
    

 

	
	$bonus_date=date('d.m.Y');
	$bonus_gold=5;//Количество золота
	$bonus_maze_kluch=5;//Количество ключиков
if($bonus_date != $user['bonus_date']){
mysql_query('UPDATE  `users` SET `g` = `g` + "'.$bonus_gold.'",
								`maze_kluch` = `maze_kluch` + "'.$bonus_maze_kluch.'",
							    `bonus_date` = "'.$bonus_date.'",
								`lair_gold` = "0"  WHERE `id`="'.$user['id'].'" LIMIT 1');
echo' <div class="empty_block item_center"> <font color="#7afe4e">
Ежедневный подарок: <img src="/images/ico/png/gold.png" alt="*" width="18"/> '.$bonus_gold.'
					<img src="/images/ico/png/keys.png" alt="*" width="18"/> '.$bonus_maze_kluch.'</br>
Приходи завтра и получишь еще золота </font>
</div><div class="line"></div>';
}
	
/////////////////////////////////////////////////
/////////////////////////////////////////////////	
$invasion = mysql_fetch_assoc(mysql_query("SELECT * FROM `invasion` ORDER BY `id` DESC LIMIT 1"));
$invasionMember = mysql_fetch_assoc(mysql_query("SELECT * FROM  `invasion_member` WHERE `invasion`='".$invasion['id']."' and `user`='".$user['id']."'"));
$invasionTime=$invasion['time_start']-time();		
	if(!$invasionMember AND $invasionTime <= '600' AND $user['str'] >= '400'){//Показываем за 10мин до начала
	echo' <div class="empty_block item_center">
  <img src="/images/invasion/logo.png" alt="*"/></br>
Битва начнется через: '._time($invasion['time_start']-time()).'
<a href="invasion?enter"><div class="button">Подать заявку</div></a>
</div><div class="line"></div>';
	}	
////////////////////////////////////////////////////////
///////////////////////////////////////////////////////	
	
	
	

	
	
	
	
	
	
	
	if($clan) {//Клановое объявление
$clan_msg = mysql_fetch_array(mysql_query('SELECT * FROM `clan_msg` WHERE `clan` = "'.$clan['id'].'" AND `time` >= "'.$clan_memb['time'].'" ORDER BY `time` DESC LIMIT 1'));
if($clan_msg && mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_msg_read` WHERE `msg` = "'.$clan_msg['id'].'" AND `user` = "'.$user['id'].'"'),0) == 0 ) {
$clan_msg_user = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$clan_msg['user'].'"'));

  if($_GET['clan_msg_read'] == true) {   
mysql_query('INSERT INTO `clan_msg_read` (`msg`,
                                             `user`) VALUES ("'.$clan_msg['id'].'",
                                                                 "'.$user['id'].'")');
header('location: '.$_SERVER['PHP_SELF'].'?');  
}

echo'
<div class="empty_block item_center">
  <font color="#7afe4e"> '.bbcode(smile($clan_msg['text'])).' </font>
  <br/>';
if($clan_msg['user'] != 0){ echo''.nick($clan_msg_user['id']).' <small>'._times(time() - $clan_msg['time']).'</small><br/>';}
echo'<a href="?clan_msg_read=true">Скрыть</a>
</div><div class="line"></div>';

}

}else{//Приглашение в клан

  if(mysql_result(mysql_query('SELECT COUNT(*) FROM `clan_invite` WHERE `ho` = "'.$user['id'].'"'),0) > 0) {
$_invite = mysql_fetch_array(mysql_query('SELECT * FROM `clan_invite` WHERE `ho` = "'.$user['id'].'"'));
$clan_invite = mysql_fetch_array(mysql_query('SELECT * FROM `clans` WHERE `id` = "'.$_invite['clan'].'"'));
        
      if($_GET['invite'] == $clan_invite['id']) {
mysql_query('INSERT INTO `clan_memb` (`clan`,
                                      `user`,
									  `v`,
                                      `time`,
                                      `last_update`) VALUES ("'.$clan_invite['id'].'",  
                                                             "'.$user['id'].'",
															 "10",
                                                             "'.time().'",
                                                             "'.(time() + ((60 * 60) * 24)).'")');
$text=' <a href="/user/'.$_invite['user'].'">'.nick($_invite['user']).'</a> <font color="#7afe4e">принял</font>  <a href="/user/'.$user['id'].'">'.nick($user['id']).'</a>'; //Текст уведомления
mysql_query("INSERT INTO `clan_history` SET `clan`='".$clan_invite['id']."',`text`='".$text."',`time`='".time()."'"); //Отправляем уведомление                                              
mysql_query('DELETE FROM `clan_invite` WHERE `ho` = "'.$user['id'].'"');
header('location: /clan/');
exit;
}
    
    if($_GET['cancel_invite'] == true){    
mysql_query('DELETE FROM `clan_invite` WHERE `clan` = "'.$clan_invite['id'].'" AND `ho` = "'.$user['id'].'"'); 
header('location: /');
exit; 
}



echo'<div class="empty_block">
<table cellpadding="0" cellspacing="0">
<tr>
<td width="15%"><img src="/images/ico/gerb/'.$clan_invite['gerb'].'.png" alt="*"/></td>
<td><img src="/images/ico/png/clan.png" alt="*"/> <a href="/clan/'.$clan_invite['id'].'/"> '.$clan_invite['name'].' </a><br/>
Бонус: <font color="#90c090">+'.clan_buff($clan_invite['built_1']).'</font> к сумме параметров
</td>
</tr></table>


<div class="link_center"><a href="?invite='.$clan_invite['id'].'">Вступить в клан</a></div>
<div class="link_center_h"><a href="?cancel_invite=true">Отказаться</a></div>

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


    
    }

}
	
	
	
	
	
	
	
	
	
	
	
	
	   


	
	
	


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

$lair_mobs = mysql_fetch_assoc(mysql_query("SELECT * FROM `lair_mobs` WHERE `id`='".$user['lair']."' ")); 
$lair = mysql_fetch_assoc(mysql_query("SELECT * FROM `lair` WHERE `id`='".$lair_mobs['glava']."' ")); 
$lair_users = mysql_fetch_assoc(mysql_query("SELECT * FROM `lair_users` WHERE `user_id`='".$user['id']."' ")); 
if($user['lair_boi'] >= '1' AND $lair_users['time'] < time() ){
	echo'<div class="empty_block item_center"> Убей '.$lair_mobs['name2'].' </div>
	<div class="line"></div>';
	echo'  <div class="block_link"><a href="/lair">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/lair/lair'.$lair_mobs['img'].'.png">
</td><td> 
<font color="#fff"> <b>'.$lair_mobs['name'].'</b> </font><br>
'.$lair['name2'].' <br>
Осталось боев: '.$user['lair_boi'].'
</td></tr>
</tbody></table>
</a></div>';  
}else{	
	echo'<div class="block_link"><a>
	<img src="/images/ico/lair/grey_lair'.$lair_mobs['img'].'.png"> <font color="grey"> '.$lair['name'].' откроется через
	'._time($lair_users['time']-time()).' </font> 
	</a></div>'; 
	}



echo'<div class="line"></div>';
$be=mysql_fetch_array(mysql_query("SELECT * FROM `arena` WHERE `user`= '$user[id]' LIMIT 1"));
	if($be['attack'] >= '1'){
	echo'  <div class="block_link"><a href="/arena.php">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/png/arena.png">
</td><td> 
<font color="#fff"> <b>На Арену</b> </font><br>
Осталось боев: '.$be[attack].'
</td></tr>
</tbody></table>
</a></div>';  
	}else{	
		echo'<div class="block_link"><a>
		<img src="/images/ico/png/arena_grey.png"> <font color="grey"> Арена откроется через
	    '._time($be['time']-time()).' </font> 
		</a></div>'; 
	}
	echo'<div class="line"></div>';
	

/////////////////////////////
//Дракон 1
$lair_mobs = mysql_fetch_assoc(mysql_query("SELECT * FROM `clan_lair_boss` WHERE `clan` = '".$clan['id']."' AND `dead` = '0' ")); 
$lair = mysql_fetch_assoc(mysql_query("SELECT * FROM `clan_lair` WHERE `id`='".$lair_mobs['lair']."' ")); 
$lair_users = mysql_fetch_assoc(mysql_query("SELECT * FROM `clan_lair_memb` WHERE `user`='".$user['id']."' ")); 

$memb = mysql_fetch_assoc(mysql_query("SELECT * FROM `clan_memb` WHERE `user`='".$user['id']."' ")); 
$time=$memb['time']+86400*7;//Если больше 7 дней в клане
if($lair_mobs AND $lair_mobs['clan'] == $clan['id'] AND $lair_users['time'] < time() ){
	echo'  <div class="block_link"><a href="/clan_lair">
<table> <tbody><tr>
<td width="14%">
<img src="/images/ico/clan_lair/dragon'.$lair['id'].'_win.jpg" width="48">
</td><td> 
<font color="#fff"> <b>'.$lair['name'].'</b> </font><br>
'.$lair['gde'].' <br>
'.($time < time() ? ''._time($lair_mobs['time']-time()).'':'<font color="#FF2400">Вход закрыт</font>').'
</td></tr>
</tbody></table>
</a></div>';  
}elseif($lair_mobs){	
	echo'<div class="block_link"><a>
	<img src="/images/ico/clan_lair/grey_dragon'.$lair['id'].'.png"> <font color="grey"> '.$lair['name'].' откроется через
	'._time($lair_users['time']-time()).' </font> 
	</a></div>'; 
	}
	echo'<div class="line"></div>';
///////////////////////////	
	
	
	
	
	
	
	
	
	
	
	$lair_users=mysql_fetch_array(mysql_query("SELECT * FROM `lair_users` WHERE `user_id`= '".$user['id']."' LIMIT 1"));
	$arena=mysql_fetch_array(mysql_query("SELECT * FROM `arena` WHERE `user`= '".$user['id']."' LIMIT 1"));
$cena=''._num(($lair_users['time']-time()+$arena['time']-time())/100*0.18).'';
if($cena == 0){$cena=1;}
	if($lair_users['time'] > time() AND $lair_users['boss_dead'] == '1' AND $arena['time'] > time() AND $arena['end'] == '1'){
			    if($_GET['wakeup'] == true){    
mysql_query('UPDATE  `arena` SET `attack` = "15", `end` = "'.$end.'"  WHERE `user`="'.$user['id'].'" LIMIT 1');
mysql_query('UPDATE  `users` SET `lair_boi` = "2", `g` = `g` - "'.$cena.'" WHERE `id`="'.$user['id'].'" LIMIT 1');
mysql_query('UPDATE  `lair_users` SET `boss_dead` = "0", `time` = "0" WHERE `user_id`="'.$user['id'].'" LIMIT 1');
mysql_query('UPDATE  `travel` SET `step` = "1", `time` = "'.time().'" WHERE `user` = "'.$user['id'].'"');
header('location: /');
exit; 
}	echo'
	<div class="block_link"><a href="/?wakeup=true" class="link"><font color="#fff"><u> Открыть сейчас за <img src="/images/ico/png/gold.png" width="18"> '.$cena.' </u></font></a></div>
	<div class="line"></div>';
	}
	
$travel=mysql_result(mysql_query('SELECT COUNT(*) FROM `travel` WHERE `step` != "4"  AND `step` != "0"  AND `user` = "'.$user['id'].'" AND `time` <= "'.time().'"  '),0);
echo '
	 <div class="block_link"><a href="/travel.php" class="link"><img src="/images/ico/png/quest.png" width="18"> Набег '.($travel ? '<font color="#7afe4e">(+)</font>':'').' </a></div>
	 <div class="line"></div>
	 <div class="block_link"><a href="/coliseum" class="link"><img src="/images/ico/png/coliseum.png" width="18"> Колизей </a></div>
	 <div class="line"></div>
	 <div class="block_link"><a href="/maze" class="link"><img src="/images/ico/png/maze.png" width="18"> Лабиринт '.($user['maze_kluch'] >= 1 ? '<font color="#7afe4e">(+)</font>':'').'</a></div>
	 <div class="line"></div>';
	 

 $t = mysql_query ('select * from `task_user` WHERE (`user`="' . $user['id'] . '") AND (`complete`="0")');
if (mysql_num_rows ($t) != 0) {
    while ($task_user = mysql_fetch_array ($t)) {   // 
      $task_storyline = mysql_fetch_array(mysql_query ('SELECT * FROM `task` WHERE (`type` = "storyline") AND (`id`="' . $task_user['task'] . '")'));
      $task_daily = mysql_fetch_array(mysql_query ('SELECT * FROM `task` WHERE (`type` = "daily") AND (`id`="' . $task_user['task'] . '")'));     
        if ($task_user['how']==$task_storyline['how']){
		$storyline = true;}
        if ($task_user['how']==$task_daily['how']){
		$daily = true;}
    }
}
 
 if($storyline){
echo' <div class="block_link"><a href="/task" class="link"><img src="/images/ico/png/task.png" width="18"> Задания <font color="#7afe4e">(+)</font> </a></div>';
}elseif($daily){
echo' <div class="block_link"><a href="/task/daily" class="link"><img src="/images/ico/png/task.png" width="18"> Задания <font color="#7afe4e">(+)</font> </a></div>';
}else{
echo' <div class="block_link"><a href="/task" class="link"><img src="/images/ico/png/task.png" width="18"> Задания </a></div>';	
}
 
	 echo'
	 <div class="line"></div>
	 <div class="block_link"><a href="/train" class="link"><img src="/images/ico/png/train.png" width="18"> Тренировка </a></div>
	 <div class="line"></div>';
  
    
     echo'<div class="block_link"><a href="/invasion" class="link"><img src="/images/ico/png/invasion.png" width="18"> Вторжение ';
	 if($invasion['time_start']-time() > 0){
	 echo'<font color="#7afe4e">('._time($invasion['time_start']-time()).')</font>';
	 }
	 echo'</a></div>
	 <div class="line"></div>';
     
     
  echo'<div class="line2"></div>
  <div class="block_link"><a href="/shop/"><img src="/images/ico/png/shop.png" alt="*"/> Магазин </a></div>
  <div class="line"></div>
  <div class="block_link"><a href="/clans/"><img src="/images/ico/png/clan.png" alt="*"/> Кланы </a></div>
  <div class="line"></div>
  <div class="block_link"><a href="/rating/"><img src="/images/ico/png/best.png" alt="*"/> Рейтинг игроков </a></div>
  <div class="line"></div>
  <div class="block_link"><a href="/paywk/"><img src="/images/ico/png/buy_gold.png" alt="*"/> Купить золото </a></div>
  <div class="line"></div>';




    if(isSet($_GET['exit'])) {
setCookie('id', '');
setCookie('password', '');
header('location: /');
}
    


}else{
$login = _string($_POST['login']);
$login = strToLower($login);
$password = _string(md5(md5(md5($_POST['password']))));

  if(isset($_REQUEST['ok'])){
    
$user = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `login` = "'.$login.'" AND `password` = "'.$password.'" LIMIT 1'));
if($user==0) {
header('Location: /');
$_SESSION['mes'] = 'Неправильный Логин или Пароль!';
exit; }

    
setCookie('id', $user['id'], time() + 86400, '/');
setCookie('password', $password, time() + 86400, '/');
header('location: /');
  
}

echo'
<div class="empty_block item_center bottom">
<img src="/images/welcome.jpg" alt="" /> </br>
Непрекращающиеся сражения с настоящими противниками до последней капли крови! Опасные походы и захватывающие приключения! Начни путь великого героя!
<a href="/start"><div class="button">Зарегистрироваться</div></a>
</div>
<div class="line"></div>
<div class="empty_block item_center bottom">';
  echo' <b>'.$_SESSION['mes'].'</b> ';
    $_SESSION['mes']=NULL; //Удаляем сесию

  echo'<form action="/" method="post">
     Ваш логин:  <br/>  <input name="login" type="text"><br/>
     Ваш пароль: <br/>  <input name="password" type="password"><br/>  
<input type="submit" class="button" name="ok" value="Войти"/>
</form></div>
<div class="line"></div>';
}    
include './system/f.php';
?>