<?php
/*
 * Server registration script
 * Made by starky
*/

/* Script security */
if(!defined("MONENGINE")) {
	header("Location: index.php");
	exit();
}
?>
<div id="blockid_3"></div>	
      <div class="hero-unit">
	  <div class="hero-head">
      <h4>Платные услуги для серверов</h4>
	  </div>
<?php
/*
 * Server search script
 * Made by starky
*/

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

/* Search form */
if(count($_POST) == 0) {
	$page = 'advanced_search';
} elseif(isset($_POST['advanced_search'])) {
	$page = 'adv_search_results';
} elseif(isset($_POST['quick_search'])) {
	$page = 'quick_search';
} else {
	$page = 'advanced_search';
}

if($page == 'advanced_search') {
	include(INCLUDES."countries.class.php");
	$countries = new countries;
	$servers = dbquery("SELECT `server_location` FROM `".DB_SERVERS."` WHERE `server_location` != ''");

	echo "
<table class='p_box'>
		<tr>
		<td>
		<div class='input-append'>
<form action='/paysearch/' method='POST'>
<input type='hidden' name='forvip' value='1'>
<input type='hidden' name='position' value=''>
<input name='ip' id='ip' style='width:400px;border: 1px solid #4f4f4f;' type='text' placeholder='Введите IP:PORT сервера' value=''>
<button name='advanced_search' type='submit' class='btn' type='button'>Поиск!</button>
</form>
</div>
		</td>
		<td>
		</td>
		</tr>
</table>
	";
} elseif($page == 'adv_search_results') {
	$searchfield = mysql_real_escape_string(trim($_POST['searchfield']));
	$map = mysql_real_escape_string(trim($_POST['map']));
	$ip = mysql_real_escape_string(trim($_POST['ip']));
	$freeslots = trim($_POST['freeslots']);
	$country = mysql_real_escape_string(trim($_POST['country']));
	$query_params = Array();
		/* IP adress */
	if(!empty($ip) and $ip != '*') {
		if(mb_strpos($ip, ',', 0, 'UTF-8') !== false) {
			$explode_maps = explode(',', $ip);
			$ip_params = '';
			foreach($explode_ip as $k => $ip) {
				$ip = trim($ip);
				if($k == 0) $ip_params .= '(';
				$ip_params .= "`server_ip` = '$ip'";
				if($k != (count($explode_ip) - 1)) {
					$ip_params .= ' OR ';
				} else {
					$ip_params .= ')';
				}
			}
			$query_params[] = $ip_params;
		} else {
			$ip = trim($ip);
			$query_params[]= "`server_ip` = '$ip'";
		
		
		
			
			
		}
	}
	
	
		/* Site */
	if(!empty($site) and $site != '*') {
		if(mb_strpos($site, ',', 0, 'UTF-8') !== false) {
			$explode_maps = explode(',', $site);
			$site_params = '';
			foreach($explode_site as $k => $site) {
				$site = trim($site);
				if($k == 0) $site_params .= '(';
				$site_params .= "`server_site` = '$site'";
				if($k != (count($explode_site) - 1)) {
					$site_params .= ' OR ';
				} else {
					$site_params .= ')';
				}
			}
			$query_params[] = $site_params;
		} else {
			$site = trim($site);
			$query_params[]= "`server_site` = '$site'";
	
	}
	}
	
	/* Free slots */
	$freeslots = preg_replace("/\D/", "", $freeslots);
	if(!empty($freeslots) and $freeslots != '*') $query_params[] = "`server_maxplayers` - `server_players` = '$freeslots'";
	/* Country */
	if(!empty($country) and $country != 'all') $query_params[] = "`server_location` = '$country'";
}
?>
<?php

echo "
<div class='paylistingus1'>

<div class='listingtop'><font size='4px'>Листинг премиум серверов</font>(текущее время на сервере ".date("d.m.Y H:i:s")."):</b></h2>
<ol>";
for($itop=1;$itop<5 * LINES_NUM+1;$itop++)
{
		$rtop = mysql_fetch_array(mysql_query("SELECT * FROM `mon_servers` WHERE server_top=$itop"));
		if($rtop['server_top']) 
		{
			echo "<li><font size='2px'>Место занято сервером <a href='/server/{$rtop['server_id']}/'>{$rtop['server_name']}</a>. Освободится через ".time2string($rtop['server_top_time'] - time(),true,false,false,false)." (".formatDate("d.m.Y H:i:s",$rtop['server_top_time']).")</li>";
		}
		else
		{
			echo "<li><font size='2px'>Место свободно!</li></font></font>";
		}
}

echo "</ol>
</div>
		<div style='padding:5px;border-top:1px solid #4F4F4F;'></div>
<div class='listingvip'><font size='4px'>Листинг VIP серверов:</font>
<ol>";
$qvip = mysql_query("SELECT * FROM `mon_servers` WHERE server_vip=1");
if(mysql_num_rows($qvip) == 1) echo "<font size='2px'><li>Все места свободны</li></font>";
while($rvip = mysql_fetch_array($qvip))
{
echo "<font size='2px'><li>Место занято сервером <a href='/server/{$rvip['server_id']}/'>{$rvip['server_name']}</a>. Освободится через ".time2string($rvip['server_vip_time'] - time(),true,false,false,false)." (".formatDate("d.m.Y H:i:s",$rvip['server_vip_time']).")</li>";	
}
echo "</ol></font>
</div>
		<div style='padding:5px;'></div>
<div class='listingcolor'><font size='4px'>Листинг серверов с цветом:</font>
<ol>";
$qcolor = mysql_query("SELECT * FROM `mon_servers` WHERE server_row_style RLIKE '_'");
if(mysql_num_rows($qcolor) == 1) echo "<li>Все места свободны</li>";
while($rcolor = mysql_fetch_array($qcolor))
{
echo "<li>Место занято сервером <a href='/server/{$rcolor['server_id']}/'>{$rcolor['server_name']}</a>. Освободится через ".time2string($rcolor['server_color_time'] - time(),true,false,false,false)." (".formatDate("d.m.Y H:i:s",$rcolor['server_color_time']).")</li>";	
}
echo "</ol>
</div></div>";
?>