<?php
/*
 * Server list
 * Made by starky
*/

/* Script security */
if(!defined("MONENGINE")) {
	header("Location: index.php");
	exit();
}
/* Other code */

include(ENGINE."pagination.class.php");
$pagination = new pagination;

$page_num = 1;
if(isset($_GET['page_num'])) $page_num = $_GET['page_num'];
$needed_servers = dbquery("SELECT count(*) FROM ".DB_SERVERS . " WHERE server_new != 1 AND server_status != 0 AND server_off != 1");
$needed_servers = dbarray_fetch($needed_servers);
$needed_servers = $needed_servers[0];
$pg_info = $pagination->calculate_pages($needed_servers, $settings['servers_per_page'], $page_num);
$query_limit = $pg_info['limit'];

// Uncomment the next line for pagination debug
//print_r($pg_info);

$select_query = "SELECT * FROM ".DB_SERVERS . " 
WHERE 
server_new != 1 AND 
server_status != 0 AND 
server_off != 1 
ORDER BY 
server_vip DESC, votes DESC ".$query_limit
;


$servers = dbquery($select_query);

echo "<td valign='top' height='100%'><table class='list'><thead><tr>";

/*
	$locale['010']	Имя сервера
	$locale['011']	Адрес
	$locale['013']	Игроки
*/

/* TABLE HEAD */
echo "
<td class='c0'></td><td class='c1'><b>Название сервера <a href='http://mon-servers.ru/all/1/byname/down/' rel='nofollow'><img src='http://mon-servers.ru/images/block_on.gif'></a><a href='http://mon-servers.ru/all/1/byname/up/' rel='nofollow'><img src='http://mon-servers.ru/images/block_off.gif'></a></b></td>

		<td class='c2'><b>Адрес сервера <a href='http://mon-servers.ru/all/1/byadres/down/' rel='nofollow'><img src='http://mon-servers.ru/images/block_on.gif'></a><a href='http://mon-servers.ru/all/1/byadres/up/' rel='nofollow'><img src='http://mon-servers.ru/images/block_off.gif'></a></b></td>

		<td class='c6'><b>Мод</b></td>

		<td class='c3'><b>Карта <a href='http://mon-servers.ru/all/1/bymap/down/' rel='nofollow'><img src='http://mon-servers.ru/images/block_on.gif'></a><a href='http://mon-servers.ru/all/1/bymap/up/' rel='nofollow'><img src='http://mon-servers.ru/images/block_off.gif'></a></b></td>

		<td class='c4'><b>Игроки <a href='http://mon-servers.ru/all/1/byplayers/down/' rel='nofollow'><img src='http://mon-servers.ru/images/block_on.gif'></a><a href='http://mon-servers.ru/all/1/byplayers/up/' rel='nofollow'><img src='http://mon-servers.ru/images/block_off.gif'></a></b></td>

		<td class='c5'><b>Голоса <a href='http://mon-servers.ru/all/1/byrating/down/' rel='nofollow'><img src='http://mon-servers.ru/images/block_on.gif'></a><a href='http://mon-servers.ru/all/1/byrating/up/' rel='nofollow'><img src='http://mon-servers.ru/images/block_off.gif'></a></b></td></tr></thead>
		";

/* TABLE BODY */
echo "<tbody>";
if($servers_total !=0 ) {
	while($r=dbarray_fetch($servers)) {
		$players = $r['server_players']." / ".$r['server_maxplayers'];
		$server_location = $r['server_location'];
		$string = $r[server_mode];
		$string[0] = mb_strtoupper($string[0]);
		$vipcon="&nbsp;";
		if($r['server_vip'] == 1) $vipcon = "&nbsp;<a href='steam://connect/{$r['server_ip']} ' rel='nofollow'><img src='/images/sconnect.png' title='Присоединиться через steam' rel='nofollow'></a>";
		$steam="";
		if($r['server_steam'] == 1) $steam = "<span> &nbsp;<img src='/images/icon_steam.gif' title='Steam сервер' style='opacity:0.6'></span>";
		if(empty($server_location)) $server_location = 'undefined';

		if(array_key_exists($r['server_row_style'], $styles)) {
			$row = "<tr style='{$styles[$r['server_row_style']]['style']}'>";
				

		} else {
		
		



if($r['server_players'] == $r['server_maxplayers'])
{ $players = "".$r['server_players']." / ".$r['server_maxplayers']."";}

		if($r['server_status'] ==1)
{ $server_full=floor(($r['server_players']  /  $r['server_maxplayers']) * 100); }

else
{ $server_full="0"; }
if($server_full=='0') $la = "la0";
if($server_full<='20' and $server_full>'0') $la = "la1";
if($server_full<='40' and $server_full>'20') $la = "la2";
if($server_full<='60' and $server_full>'40') $la = "la3";
if($server_full<='80' and $server_full>'60') $la = "la4";
if($server_full<='100' and $server_full>'80') $la = "la5";
$row = "
<tr class='hserver'>
";
		}
			$row.="	
			{$cs16s}
			";
						if($r['server_vip'] == 1) {
			$row .= '';
		} else {
			$row .= "	
			";
		}
		$row .= "
		
		";
		
		echo $row;
	}
	
} else {
	echo "<th><center> ".$locale['017']."</center></th>";
}
/* TBODY END */
echo "</tbody></table>";
/* TABLE END */

/* PAGINATION */

if(count($pg_info['pages']) > 1) {
	echo "";
	if($pg_info['current'] == 1) {
		echo "<div class='paginate'><span class='disabled'>Назад</span>";
		echo "<span class='current'>1</span>";
	} else {
		echo "<a href='/all/{$pg_info['previous']}' rel='nofollow'>Назад</a>&nbsp;";
		echo "<span class='current'><a href='/all/1'>1</a></span>";
	}
	echo "&nbsp;";

	foreach($pg_info['pages'] as $k => $v) {
		if($v == 1 or $v == $pg_info['last']) continue; 
		if($v == $pg_info['current'] or $v == '...') {
			echo "$v</span>";
		} else {
			echo "<a href='/all/$v' rel='nofollow'>$v</a>";
		}
		echo "&nbsp;";
	}

	if($pg_info['current'] == $pg_info['last']) {
		echo "<span>{$pg_info['last']}</span>&nbsp;";
		echo "Далее</span>";
	} else {
		echo "<a href='/all/{$pg_info['last']}' rel='nofollow'>{$pg_info['last']}</a></span>";
		echo "<a href='/all/{$pg_info['next']}' rel='nofollow'>Вперёд</a></span>";
	}


	echo "</div>";
}
/* PAGINATION END */
?>