<?php

require_once('conf/dbc.php');
require_once('conf/session_start.php');
require_once('conf/ban.php');
$page_title = 'Вооружение';
require_once('conf/head.php');
if ((isset($_SESSION['id'])) and (isset($_SESSION['nick'])))  {
  require_once('conf/top.php');
}
?><br>
  <center><p class="name">Рейтинг вооружения</center>
	</p>
	<?php
$type=abs(intval($_GET['type']));
	if (empty($type)) {
	$type=1;
	}
	?>















   <?php
    
    $query_num = "Select id from users where 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); 
	?>
	<p class="foot">Всего игроков <?php echo "[ $total ]"; ?></p>
	<?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) {
	  if ($type==1) {
	  $query_us = "Select nick ,id,gruppa,lvl, avatar, max_hp, bronya, razriv_cl, yron_p, tochn_p, safety_p, yron_w, tochn_w, safety_w, last_active from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by max_hp DESC limit $skip, $result_per_page";
	  }
	  if ($type==2) {
	  $query_us = "Select nick ,id,gruppa, lvl, last_active, bronya from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by bronya DESC limit $skip, $result_per_page";
	  }
	  if ($type==3) {
	  $query_us = "Select nick ,id,gruppa, lvl, last_active, razriv_cl from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by razriv_cl DESC limit $skip, $result_per_page";
	  }
	  if ($type==4) {
	  $query_us = "Select nick ,id,gruppa, lvl, last_active, yron_p from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by yron_p DESC limit $skip, $result_per_page";
	  }
	  if ($type==5) {
	  $query_us = "Select nick ,id,gruppa,lvl, last_active, tochn_p from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by tochn_p DESC limit $skip, $result_per_page";
	  }
	  if ($type==6) {
	  $query_us = "Select nick ,id,gruppa,lvl, last_active, safety_p from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by safety_p DESC limit $skip, $result_per_page";
	  }
	  if ($type==7) {
	  $query_us = "Select nick ,id,gruppa,lvl, last_active, yron_w from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by yron_w DESC limit $skip, $result_per_page";
	  }
	  if ($type==8) {
	  $query_us = "Select nick ,id,gruppa, lvl, last_active, tochn_w from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by tochn_w DESC limit $skip, $result_per_page";
	  }
	  if ($type==9) {
	  $query_us = "Select nick ,id,gruppa,lvl, last_active, safety_w from users where gruppa <> 'mytants' and gruppa <>'bandits' and gruppa <> 'zombie' and gruppa <> 'monolits' order by safety_w DESC limit $skip, $result_per_page";
	  }
      $result_us = mysqli_query($dbc, $query_us) or die ('Ошибка передачи запроса к БД');
	  $now = (date("Y-m-d H:i:s"));
      $now = strtotime("$now");
	  while ($row_us = mysqli_fetch_array($result_us)) {
	    $lvl = $row_us['lvl'];
            $nick = $row_us['nick'];
	    $id_us = $row_us['id'];
		$gruppa = $row_us['gruppa'];
		$last_active = $row_us['last_active'];
        $last_active = strtotime("$last_active");
        $razn_last_act = ($now - $last_active);
	    ?>
	    <div style="background: url(/style/img/2.jpg);">

		<?php
     if ($gruppa == 'svoboda') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/svobodaon.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/svobodaon.png" width="12" height="12" alt="н"/><?php }}
	  if ($gruppa == 'dolg') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/dolgon.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/dolgon.png" width="12" height="12" alt="н"/><?php }}
	   if ($gruppa == 'naemniki') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/naemniki.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/naemniki.png" width="12" height="12" alt="н"/><?php }}
	  if ($gruppa == 'renegat') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/renegat.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/renegat.png" width="12" height="12" alt="н"/><?php }}
	  if ($gruppa == 'chistoenebo') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/chistoenebo.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/chistoenebo.png" width="12" height="12" alt="н"/><?php }}
  ?> [<?php echo "$lvl";?>ур]
         <a style="text-decoration:none;"  href="profile.php?id=<?php echo "$id_us"; ?>"><?php echo "$nick";?></a></div></p><b>
	  <?php
	  if ($type==1) { 
	
   
echo '  <table width="370" border="0" cellpadding="0" cellspacing="0">
    <tbody>
    <tr>
    <td width="170" valign="top"><img src="img/avatars/'.$row_us['avatar'].'" width="120" height="190" border="0"/></td>
    <td width="3000" valign="top">
<div class="foot">Макс ХП <img src="/img/ico2/life.png" width="17" height="17">: '.$row_us['max_hp'].' </div>
<div class="foot">Макс Брони <img src="/img/ico2/bandit.gif" width="17" height="17">: '.$row_us['bronya'].'</div>
<div class="foot">Разрыв <img src="/img/ico2/upgrd.gif" width="17" height="17">: '.$row_us['razriv_cl'].'</div>
<div class="foot">Урон <img src="http://sdark.mobi/images/icon/stat/sila.png" width="17" height="17">: '.$row_us['yron_p'].'</div>
<div class="foot">Точность <img src="http://sdark.mobi/images/icon/stat/sila.png" width="17" height="17">: '.$row_us['tochn_p'].'</div>
<div class="foot">Надёжность <img src="http://sdark.mobi/images/icon/stat/sila.png" width="17" height="17">: '.$row_us['safety_p'].' %</div>
<div class="foot">Урон <img src="http://sdark.mobi/images/icon/stat/sila.png" width="17" height="17">: '.$row_us['yron_w'].'</div>
<div class="foot">Точность <img src="http://sdark.mobi/images/icon/stat/sila.png" width="17" height="17">: '.$row_us['tochn_w'].'</div>
<div class="foot">Надёжность <img src="http://sdark.mobi/images/icon/stat/sila.png" width="17" height="17">: '.$row_us['safety_w'].' %</div>
</td>
    </tr>
    </tbody>
    </table>';
}


	  if ($type==2) { echo $row_us['bronya'];}
	  if ($type==3) { echo $row_us['razriv_cl'];}
	  if ($type==4) { echo $row_us['yron_p'];}
	  if ($type==5) { echo $row_us['tochn_p'];}
	  if ($type==6) { echo $row_us['safety_p'] . '%';}
	  if ($type==7) { echo $row_us['yron_w'];}
	  if ($type==8) { echo $row_us['tochn_w'];}
	  if ($type==9) { echo $row_us['safety_w'] . '%';}
?>	
</b>
	  
	    <?php
	  }
	  ?>

	  <center><div style="background: url(/style/img/2.jpg);">
	  <?php
$phpself= filter($_SERVER['PHP_SELF']);
	  ///////////////////////////////////////
	  ////////////////////////////////////////
	  if ($cur_page > 1) {
	    echo '<a href="' . "$phpself" . '?page=1' . '&type=' . $type . '"><<</a> ';
      }
	  else {
	    echo '<< ';
	  }
	  if ($cur_page > 1) {
	    echo '<a href="' . "$phpself" . '?page=' . ($cur_page-1) . '&type=' . $type . '"><</a> ';
      }
	  else {
	    echo '<';
	  }
	/////
	  if (($cur_page-3)>0) {
	 $k = ($cur_page-3);
	    ?><a href="<?php echo "$phpself" . '?page=' . ($cur_page-3) . "&type=$type"?>"><?php echo "$k";?></a><?php
      }
	 if (($cur_page-2)>0) {
	 $k = ($cur_page-2);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page-2) . "&type=$type"?>"><?php echo "$k";?></a> <?php
      }
     if (($cur_page-1)>0) {
	 $k = ($cur_page-1);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page-1) . "&type=$type"?>"><?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) . "&type=$type"?>"><?php echo "$k";?></a> <?php
      }
	  	 if (($cur_page+2)<=$num_page) {
	 $k = ($cur_page+2);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page+2) . "&type=$type"?>"><?php echo "$k";?></a> <?php
      }
	 if (($cur_page+3)<=$num_page) {
	 $k = ($cur_page+3);
	    ?> <a href="<?php echo "$phpself" . '?page=' . ($cur_page+3) . "&type=$type"?>"><?php echo "$k";?></a> <?php
      }
	/////
	if ($cur_page < $num_page) {
	  echo '<a href="' . "$phpself" . '?page=' . ($cur_page+1) . '&type=' . $type . '">></a> ';
    }
	else {
	  echo '>';
	}
	if ($cur_page < $num_page) {
	  echo ' <a href="' . "$phpself" .  '?page=' . $num_page . '&type=' . $type . '">>></a> ';
    }
	else {
	  echo ' >>';
	}

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

?>
</body>
</html>