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

if ((!isset($_SESSION['id'])) or (!isset($_SESSION['nick'])))  {
  ?>
<!--1390114136-->
  <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'])))  {
$user_id = abs(intval($_SESSION['id']));
  /////////////////////////////////
  ////////////////////////////////////Записали локацию
  $query = "Select  location from users where id = '$user_id'  limit 1";
  $result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД6');
  $row = mysqli_fetch_array($result);
  $location = $row['location'];
  if ($location == 'online') {
    }
else {
$query_loc = "update users set location = 'online' where id = '$user_id' limit 1";
$result_loc = mysqli_query($dbc, $query_loc) or die ('Ошибка передачи запроса к БД');
}
require_once('conf/top.php');
}

?>
    <div id="main">
   <?php
$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); 
	?>
	<br/>
 <p class="name2">Кто онлайн <b class="bonus"><?php echo "[$total]"; ?></b></p>
<div class="inoj"><center> <a class="inoj" href="online_noclan.php"><img src="img/plus2.png" width="12"/>Без отряда</center></a></div>	
	<?php
   /////////////////////////////////
   ////////////////////////////////
if (!empty($_GET['page'])) {
$cur_page = abs(intval($_GET['page']));
}
else {
  $cur_page = 1;
}
    $result_per_page = 10;
	$skip = (($cur_page - 1) * $result_per_page);
		$num_page = ceil($total / $result_per_page);
	if ($num_page > 0) {
$query_us = "Select * from users where last_active > NOW()-(300*5) and gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by opit DESC, yron_p DESC ,tochn_p DESC, bronya DESC limit $skip, $result_per_page";
      $result_us = mysqli_query($dbc, $query_us) or die ('Ошибка передачи запроса к БД');
	  while ($row_us = mysqli_fetch_array($result_us)) {
           $location = $row_us['location'];
           $lvl = $row_us['lvl'];
	    $nick = $row_us['nick'];
	    $id_us = $row_us['id'];
            $admin = $row_us['admin'];
          $vip = $row_us['vip'];
          $clan = $row_us['clan'];
		$gruppa = $row_us['gruppa'];
	    ?>
	    <p class="zx">

<?php if ($vip == '1') { echo '<span class="golub"><small>(vip)</small></span> ';}?>
		<?php
        if ($gruppa == 'svoboda') {?><img src="img/ico/svobodaon.png" width="12" height="12" alt="s"/><?php }
        if ($gruppa == 'dolg') {?><img src="img/ico/dolgon.png" width="12" height="12" alt="d"/><?php }
	if ($gruppa == 'naemniki') {?><img src="img/ico/naemniki.png" width="12" height="12" alt="od."/><?php }
	if ($gruppa == 'renegat') {?><img src="img/ico/renegat.png" width="12" height="12" alt="d"/><?php }
        if ($gruppa == 'chistoenebo') {?><img src="img/ico/chistoenebo.png" width="12" height="12" alt="od."/><?php }
	  ?><a style="text-decoration:none;" href="profile.php?id=<?php echo "$id_us"; ?>"><?php echo "$nick";?></a>  <img src="img/ico/lvl.gif" width="15" height="15" alt="ур."/><?php echo "$lvl";?>
<?php if ($clan =='0') { echo '[ <img src="img/plus2.png" alt="+"/> ] ';}
if($row_us[mesto]=='S.T.A.L.K.E.R.-онлайн-игра на мобильный'){echo'<span class="darkkhaki"> (Главная)</span>';}else{
echo'<span class="darkkhaki"> ('.$row_us['mesto'].')</span>';}

	  }
	  ?>
	  <div class="zx">
	  <?php
$phpself= filter($_SERVER['PHP_SELF']);
	  ///////////////////////////////////////
	  ////////////////////////////////////////
	  if ($cur_page > 1) {
	    echo '<a href="' . "$phpself" . '?page=1"><<</a> ';
      }
	  else {
	    echo '<< ';
	  }
	  if ($cur_page > 1) {
	    echo '<a href="' . "$phpself" . '?page=' . ($cur_page-1) . '"><</a> ';
      }
	  else {
	    echo '<';
	  }
	/////
	  if (($cur_page-3)>0) {
	 $k = ($cur_page-3);
	    ?><a href="<?php echo "$phpself" . '?page=' . ($cur_page-3)?>"><?php echo "$k";?></a><?php
      }
	 if (($cur_page-2)>0) {
	 $k = ($cur_page-2);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page-2)?>"><?php echo "$k";?></a> <?php
      }
     if (($cur_page-1)>0) {
	 $k = ($cur_page-1);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page-1)?>"><?php echo "$k";?></a> <?php
      }
	?> <span class="white"><?php echo " $cur_page ";?></span><?php
	 if (($cur_page+1)<=$num_page) {
	 $k = ($cur_page+1);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page+1)?>"><?php echo "$k";?></a> <?php
      }
	  	 if (($cur_page+2)<=$num_page) {
	 $k = ($cur_page+2);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page+2)?>"><?php echo "$k";?></a> <?php
      }
	 if (($cur_page+3)<=$num_page) {
	 $k = ($cur_page+3);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page+3)?>"><?php echo "$k";?></a> <?php
      }
	/////
	if ($cur_page < $num_page) {
	  echo '<a href="' . "$phpself" . '?page=' . ($cur_page+1) . '">></a> ';
    }
	else {
	  echo '>';
	}
	if ($cur_page < $num_page) {
	  echo ' <a href="' . "$phpself" .  '?page=' . $num_page . '">>></a> ';
    }
	else {
	  echo ' >>';
	}

	////////////////////////////////
	///////////////////////////////
	}
	?>
	</div>
	<?php
   /////////////////////////////////
   //////////////////////////////////
require_once('conf/navig.php');
require_once('conf/foot.php');
mysqli_close($dbc);

?>
</body>
</html>