<?php
require_once('conf/dbc.php');
require_once('conf/session_start.php');


if ((!isset($_SESSION['id'])) or (!isset($_SESSION['nick'])))  {
  ?>
  <script type="text/javascript">
  document.location.href = "login.php";
  </script>
  <?php
  exit();
}

$page_title = 'Возрождение Тьмы-онлайн-игра на мобильный';
require_once('conf/head.php');
if ((isset($_SESSION['id'])) and (isset($_SESSION['nick'])))  {
  require_once('conf/banned.php');
$user_id = abs(intval($_SESSION['id']));
  /////////////////////////////////
  ////////////////////////////////////Записали локацию
  $query = "Select admin, hp, max_hp, location, m_fight, sost_cl, sost_p, sost_w from users where id = '$user_id'  limit 1";
  $result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД6');
  $row = mysqli_fetch_array($result);
  $location = $row['location'];
  $m_fight=$row['m_fight'];
  if ($location == 'monster1' or $location == 'monster2' or $location == 'monster3' or $location == 'monster4' or $location == 'monster5' or $location == 'monster6' or $location == 'monster7' or $location == 'monster8' or $location == 'monster9') {
    $query_t = "Select id from users where m_fight='$m_fight' and location = '$location' and hp>0 and last_active > NOW() - (300*5)";
    $result_t = mysqli_query($dbc, $query_t) or die ('Ошибка передачи запроса к БД2');
    $count = mysqli_num_rows($result_t);
        if ($count <= 1) {
          $query_t = "Select id from users where m_fight='$m_fight'";
      $result_t = mysqli_query($dbc, $query_t) or die ('Ошибка передачи запроса к БД2');
          while ($row_t=mysqli_fetch_array($result_t)) {
$id_t=$row_t['id'];
$query = "update users set m_fight=0 where id = '$id_t' limit 1";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД5');
}
$query_tt = "Select id_monster from m_fight where id_fight='$m_fight' limit 1";
$result_tt = mysqli_query($dbc, $query_tt) or die ('Ошибка передачи запроса к БД2');
$row_tt = mysqli_fetch_array($result_tt);
$m=$row_tt['id_monster'];

$query_tt = "Select clan, max_hp from monsters where id_monster='$m' limit 1";
$result_tt = mysqli_query($dbc, $query_tt) or die ('Ошибка передачи запроса к БД2');
$row_tt = mysqli_fetch_array($result_tt);
if ($row_tt['clan'] <> 0) {
$hp_monst=$row_tt['max_hp'];
$query_tt = "update m_fight set start=0, hp='$hp_monst' where id_fight='$m_fight' limit 1";
$result_tt = mysqli_query($dbc, $query_tt) or die ('Ошибка передачи запроса к БД2');
}
}
$query_tt = "Select start from m_fight where id_fight='$m_fight' limit 1";
$result_tt = mysqli_query($dbc, $query_tt) or die ('Ошибка передачи запроса к БД2');
$row_tt = mysqli_fetch_array($result_tt);
if ($row_tt['start'] == 0) {
$query_tt = "update users set m_fight=0 where id='$user_id' limit 1";
$result_tt = mysqli_query($dbc, $query_tt) or die ('Ошибка передачи запроса к БД2');
$query_tt = "DELETE FROM m_inf WHERE `user_id` ='$user_id' and id_fight='$m_fight' limit 1";
$result_tt = mysqli_query($dbc, $query_tt) or die ('Ошибка передачи запроса к БД2');
}
}
$hp = $row['hp'];
$max_hp = $row['max_hp'];
if ($hp <= 0) {
$sost_p = $row['sost_p'];
if ($sost_p>0) {
$sost_p = ($sost_p - 1);
}
$sost_w = $row['sost_w'];
if ($sost_w>0) {
$sost_w = ($sost_w - 1);
}
$sost_cl = $row['sost_cl'];
if ($sost_cl>0) {
$sost_cl = ($sost_cl - 1);
}
$query = "update users set hp = '$max_hp', location = 'index', sost_cl = '$sost_cl', sost_p = '$sost_p', sost_w = '$sost_w' where id = '$user_id' limit 1";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
$query = "update things set sost = '$sost_cl' where user_id = '$user_id' and type = 1 and place=2 limit 1";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
$query = "update things set sost = '$sost_p' where user_id = '$user_id' and type = 2 and place=2  limit 1";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
$query = "update things set sost = '$sost_w' where user_id = '$user_id' and type = 3 and place=2  limit 1";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
}
else {
$query_loc = "update users set location = 'index' where id = '$user_id' limit 1";
$result_loc = mysqli_query($dbc, $query_loc) or die ('Ошибка передачи запроса к БД');
$query_loc = "DELETE FROM `m_inf` WHERE user_id = '$user_id' and id_fight='$m_fight' limit 1";
$result_loc = mysqli_query($dbc, $query_loc) or die ('Ошибка передачи запроса к БД');
}
require_once('conf/top.php');
}
//Для путеводителя новичкам:)
$usid=abs(intval($_SESSION['id']));
$row=$dbc->query("SELECT * FROM `users` WHERE`id`='$usid' LIMIT 1")->fetch_assoc();
?>
<br/>

<img src="/img/bg_main_2_large.png" width="100%">
<?php
if ($row['lvl'] == '3' or $row['lvl'] == '4') { echo '<div style="background:#000001 url(/img/dlfon.gif) repeat;">
<center><p style="border-style: double;"><span class="white">Скелет мертв. Земля ему пухом... Кстати, давай заглянем в Захваты туда!</span></p></center></div>';}
?>
<?php
if ($row['lvl'] == '1' or $row['lvl'] == '2') { echo '<div style="background:#000001 url(/img/dlfon.gif) repeat;">
<center>
<p style="border-style: double;"><span class="white">Добро пожаловать в  онлайн игру Возрождение Тьмы!"<br />Начнем твое обучение: сражения на О.Сарум - способ заработать немного серебра и опыта. Так давай же сходим туда.</span></p></div>
</div></center>';}


if (isset($_GET['news_read'])){
$dbc->query("update `users` set `news_read` = '0' where `id` = '$row[id]' limit 1");
echo'<center><span class="bonus">Новость успешно скрыта</span></center>';
header("Location: /index.php");
exit;
}
$news=$dbc->query("SELECT * FROM`news` ORDER BY `id` DESC LIMIT 1")->fetch_assoc();
$name=$news['name'];
if ($row[news_read] == 1){
echo '<div class="r6"><center><span class="darkkhaki">'.$name.'</span><form action="news.php" method="post"><input type="submit" style="width:100px; height:25px;" class="input" value="Читать"/></form><a style="text-decoration:none;" href="?news_read">Скрыть</a></div>';

}

//****************************************//
$query_forum = "Select id from users where last_active > NOW()-(300*5) and location = 'forum' and gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits'" ;
	$result_forum = mysqli_query($dbc, $query_forum) or die ('Ошибка передачи запроса к БД');
	$forum = mysqli_num_rows($result_forum); 

$query_n = "Select id from users where last_active > NOW()-(300*5) and location = 'chat' and gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits'" ;
	$result_n = mysqli_query($dbc, $query_n) or die ('Ошибка передачи запроса к БД');
	$chat = mysqli_num_rows($result_n); 

$new = "Select id from news where id" ;
	$renew = mysqli_query($dbc, $new) or die ('Ошибка передачи запроса к БД');
	$news = mysqli_num_rows($renew); 


$query_num = "Select id from users where last_active > NOW()-(300*5) and gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits'" ;
	$result_num = mysqli_query($dbc, $query_num) or die ('Ошибка передачи запроса к БД');
	$total = mysqli_num_rows($result_num); 
?>
<div class="stats"><div class="line"></div>
<?php
if ($row['admin'] == '2' or $row['admin'] == '3') { echo '
<div class="forlink"><a class="link" href="moderka.php"><img src="img/ico/chat.png" width="12" height="12"/></img>Модер-панель</a></div>';}
?><div class="line"></div>
<?php
if ($row['admin'] == '1') { echo '<div class="but-list-light center"><a class="link" href="adminka.php"><img src="inc/arrow.png" width="12" height="12"/></img>Админка</a></div>
';}
?>
<div class="line"></div>




<table class="foot" width="100%" border="0" cellpadding="0" cellspacing="0" style="padding-top: 5px;">
<tbody>
<tr>
<td width="33%">
<a class="big-but" href="baza_chn.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/shop.png"></div>
<span>Город Тогор</span></a>
</td>	
<td width="33%">
<a class="big-but" href="a_clothes.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/old-man-grey.png"></div><span>Странник</span></a>
</td>
<td width="33%">
<a class="big-but" href="lock.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/old-man-grey.png"></div><span>Старик</span></a>
</td>
</tr><tr><td width="33%">
<a class="big-but" href="tainiki.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/shaman-grey.png"></div><span>Шаман</span></a>
</td><td width="33%">
<a class="big-but" href="ohota.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/hunting-grey.png"></div><span>Охота <?php
if($row['ohota_time'] < time() and $row['ohota'] == 1 or $row['ohota'] == 0)
{echo'<span style=color:#3CFF00;font-size:15px;> + </span>';}
?></span></a>
</td><td width="33%">
<a class="big-but" href="zona.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/capture.png"></div><span>Захват</span></a>
</td>
</tr><tr><td width="33%">
<a class="big-but" href="monsters.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/coliseum-grey.png"></div><span>Сарум</span></a>
</td><td width="33%">
<a class="big-but" href="arena.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/duel-grey.png"></div><span>Дуэли</span></a>
</td><td width="33%">
<a class="big-but" href="secret.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/survival-grey.png"></div><span>Выживания</span></a>
</td>
</tr>
</tbody></table>

<table class="foot" width="100%" border="0" cellpadding="0" cellspacing="0" style="padding-top: 5px;"><tbody><tr><td width="33%">
<a class="big-but" href="online.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/task.png"></div><span>Онлайн <span class="bonus"><?php echo "($total)"; ?></span></span></a>
</td><td width="33%">
<a class="big-but" href="chat.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/icon/faq.png"></div><span>Чат <span class="bonus"><?php echo "($chat)"; ?></a></span></span></a>
</td><td width="33%">
<a class="big-but" href="forum.php?type=main">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/task.png"></div><span>Форум <span class="bonus"><?php echo "($forum)"; ?></a></span>
</td>
</tr><tr><td width="33%">
<a class="big-but" href="news.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/icon/faq.png"></div><span>Новости<?php
if($row['new_news']>0)
{echo'<span style=color:#3CFF00;font-size:15px;> [+'.$row[new_news].'] </span>';}?></span></a>
</td><td width="33%">
<a class="big-but" href="rating.php">
<div class="imgwrap"><img src="http://sdark.mobi/images/icon/faq.png"></div><span>Рейтинги</span></a>
</td><td width="33%">
<a class="big-but" href="/shaman/">
<div class="imgwrap"><img src="http://sdark.mobi/images/main/hiking-grey.png"></div><span>Поход</span></a>
</td>
</tr></tbody>
</table>

<?php
if ((isset($_SESSION['id'])) and (isset($_SESSION['nick'])))  {
  require_once('conf/navig.php');
}
require_once('conf/foot.php');
?>
</body>
<p><a style="text-decoration:none;" href="https://vk.com/darkness_reborns"><img src="img/logo_vk.png"/></a></p>
</html>