<?php
/*
 * Server list
*/

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

include(INCLUDES."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 '<style>
.title{
	z-index:1;
	zoom:1;
}
.title em{display:none;}
.title:hover em{
	display:block;
	position:absolute;
 	background-color:#000;
 	-webkit-border-radius:0px; /* красивости в виде скругленных углов */
 	-moz-border-radius:0px;
 	border-radius:0px;
	line-height:normal;
	color:#FFF;
	text-decoration:none;
	-webkit-box-shadow:0 0 0px #000; /* красивости в виде тени */
	-moz-box-shadow:0 0 0px #000;
	box-shadow:0 0 0px #000;
}
.title{
	z-index:1;
	zoom:1;
}
.title em{display:none;}
.title:hover em{
	display:block;
	position:absolute;
 	background-color:#000;
 	-webkit-border-radius:0px; /* красивости в виде скругленных углов */
 	-moz-border-radius:0px;
 	border-radius:0px;
	line-height:normal;
	color:#FFF;
	text-decoration:none;
	-webkit-box-shadow:0 0 0px #000; /* красивости в виде тени */
	-moz-box-shadow:0 0 0px #000;
	box-shadow:0 0 0px #000;
}
</style><div id="blockid_3"></div>	
      <div class="hero-unit">
	  <div class="hero-head">
      <h4>Список серверов</h4>
	  </div>
	  <div style="padding: 0px;margin-top: -30px;">
<table class="table table-striped table-hover" style="text-align: left;color: inherit;  font-size: 12px;  font-weight: 200;  line-height: 15px;" width="100%">
<tbody>';

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

/* TABLE HEAD */
echo "
	<tr style='height: 30px;'>
<tr style='height: 30px;'>
<th style='width: 35px;'><b>   Игра</b></th>
<th style='width: 400px;'><b>Название сервера</b></th>
<th style='width: 200px;'><b>Адрес</b></th>
<th style='width: 50;'><b>Карта</b></th>
<th style='width: 150px;'><b>Игроки</b></th>
<th style='width: 80px;text-align: center;'><b>Голоса</b></th>
</tr>
		</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'];
		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 = "<font color='#00FF00'>".$r['server_players']."/".$r['server_maxplayers']."</font>";}

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

else
{ $server_full="0"; }
if($server_full=='0') $la = "<img src='/images/la_icons/la0.gif'>";
if($server_full<='20' and $server_full>'0') $la = "<img src='/images/la_icons/la1.gif'>";
if($server_full<='40' and $server_full>'20') $la = "<img src='/images/la_icons/la2.gif'>";
if($server_full<='60' and $server_full>'40') $la = "<img src='/images/la_icons/la3.gif'>";
if($server_full<='80' and $server_full>'60') $la = "<img src='/images/la_icons/la4.gif'>";
if($server_full<='100' and $server_full>'80') $la = "<img src='/images/la_icons/la5.gif'>";


			$row = "<tr>";
		}
			$row.="
				<td><center><img src='/images/icons/$r[server_game].gif' style='width:16px;height:16px;vertical-align:middle;margin-bottom:2px;opacity:0.7;' title='$r[server_game] сервер'  alt='$r[server_game] сервер'  /></center></td>
				<td><a title='Перейти на страницу сервера {$r['server_name']}' href='".$settings['site_url']."server/{$r['server_id']}' rel='nofollow'></a></a>&nbsp;&nbsp; <a class='name' title='Перейти на страницу сервера {$r['server_name']}' href='".$settings['site_url']."server/{$r['server_id']}' rel='nofollow'>{$r['server_name']}</a> ".(($r['server_steam'] == '1') ? '<img src=\'images/icon_steam.png\'>' : '')."</td>
				<td><img src='images/flags/$server_location.png' style='width:16;height:11;opacity:0.7;' title='$r[server_location]' alt='$r[server_location]'> &nbsp;&nbsp;{$r['server_ip']}&nbsp;<a href='steam://connect/{$r['server_ip']}'></a> </td>
				<td><a class='st'><img src='/images/maps/cs16/{$r['server_map']}.jpg' style='width:30px;height:24px;'></a>&nbsp;&nbsp;<span class='title'>{$r['server_map']}<em><a href='/search' class='thumbnail'><img alt='' src='/images/maps/cs16/{$r['server_map']}.jpg' style='vertical-align:middle' width='160px' height='120px' /> </a></em></span></a></td>
				<td>$players</td>
				<td>
			";
			
			if($r['server_vip'] == 1) {
			$row .= '<center><span class="label label-info">VIP</span></center>';
		} else {
			$row .= "	<center><span class='votes_count' id='votes_count_{$r['server_id']}' > ".$r['votes']."</span>
						<span class='vote_buttons' id='vote_buttons_{$r['server_id']}'>
						<a href='javascript://' onClick=\"rating({$r['server_id']}, 'up', '".md5("m0n3ng1ne.s4lt:P{]we{$r['server_id']}@._)%;")."');\" class='voteup' id='{$r['server_id']}'></a>
						<a href='javascript://' onClick=\"rating({$r['server_id']}, 'down', '".md5("m0n3ng1ne.s4lt:P{]we{$r['server_id']}@._)%;")."');\" class='votedown' id='{$r['server_id']}'></a>
						</span>";
		}
		$row .= "</center></td></tr>";
		
		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 "<div class='pagination' align='center' style='margin-bottom:10px; margin-top:10px;'><ul>";
	if($pg_info['current'] == 1) {
		echo "<li><span>1</span></li>";
	} else {
		echo "<li><a href='/all/{$pg_info['previous']}' rel='nofollow'>&laquo;</a>&nbsp;";
		echo "<li><a href='/all/1'>1</a></li>";
	}
	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 "<li><span>$v</span></li>";
		} else {
			echo "<li><a href='/all/$v' rel='nofollow'>$v</a></li>";
		}
		echo "&nbsp;";
	}

	if($pg_info['current'] == $pg_info['last']) {
		echo "<li><span>{$pg_info['last']}</span></li>";
	} else {
		echo "<li><a href='/all/{$pg_info['last']}' rel='nofollow'>{$pg_info['last']}</a></li>";
		echo "<li><a href='/all/{$pg_info['next']}' rel='nofollow'>»</a></li>";
	}

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