<?php
$IN_ENGINE = true;
$show_menu = true;
require_once("includes/dbconnect.php");
require_once("includes/preprocessing.php");
require_once("includes/functions.php");
require_once("template/header.php");
?>

<table cellpadding="0" cellspacing="0" border="0" class="cont_header_txt"><tr><td>Наши клиенты</td></tr></table>

<?php
$content = "";
$content .= "<form action='' method='POST'>\n";

$content .= "<table cellpadding='0' cellspacing='0' width='100%'>\n";

$content .= "<tr>\n";
$content .= "<td colspan='4' height='35' align='center'>Голосовые сервера в списке клиентов не отображаются</td>\n";
$content .= "</tr>\n";

$content .= "<tr>\n";
$content .= "<td class='order' width='50%'>Сервер:</td>\n";
$content .= "<td width='17'><img src='template/images/3_q1.gif' alt=''></td><td width='17'><img src='template/images/3_q2.gif' alt=''></td>\n";
$content .= "<td class='order1' width='50%'><select name='engine' class='field'>";
$query = mysql_query("SELECT eid, name, type FROM dgh_engines WHERE kind <> 'voice' AND type <> 'csgo' ORDER BY name");

$options = array();
$options[''] = "Любой";
while($result = mysql_fetch_array($query)) {
	$options[$result['eid']] = $result['name'];
}
$content .= showoptions($options, $_POST['engine']);

$content .= "</td>\n";
$content .= "</tr><tr><td colspan='4' height='1'><img src='template/images/space.gif' height='1'></td></tr>\n";

$content .= "<tr>\n";
$content .= "<td class='order' width='50%'>Локация:</td>\n";
$content .= "<td width='17'><img src='template/images/3_q1.gif' alt=''></td><td width='17'><img src='template/images/3_q2.gif' alt=''></td>\n";
$content .= "<td class='order1' width='50%'><select name='location' class='field'>";
$query = mysql_query("SELECT lid, locname FROM dgh_locations ORDER BY locname");

$options = array();
$options[''] = "Любая";
while($result = mysql_fetch_array($query)) {
	$options[$result['lid']] = $result['locname'];
}
$content .= showoptions($options, $_POST['location']);

$content .= "</td>\n";
$content .= "</tr><tr><td colspan='4' height='1'><img src='template/images/space.gif' height='1'></td></tr>\n";

$content .= "<tr>\n";
$content .= "<td class='order' width='50%'>Платформа:</td>\n";
$content .= "<td width='17'><img src='template/images/3_q1.gif' alt=''></td><td width='17'><img src='template/images/3_q2.gif' alt=''></td>\n";
$content .= "<td class='order1' width='50%'><select name='platform' class='field'>";
$options = array();
$options[''] = "Любая";
$options['win'] = "Windows";
$options['lin'] = "Linux";
$content .= showoptions($options, $_POST['platform']);

$content .= "</td>\n";
$content .= "</tr><tr><td colspan='4' height='1'><img src='template/images/space.gif' height='1'></td></tr>\n";

$content .= "<tr>\n";
$content .= "<td colspan='4' height='35' align='center'><input class='button' type='submit' name='sort' value='Показать выбранное'></form></td>\n";
$content .= "</tr>\n";

$content .= "</form>\n";
$content .= "</table>\n";

$style_padding = 0;
include("template/table_content.php");;

$variants = "";

if (isset($_POST['sort'])) {
	if (!empty($_POST['engine'])) $variants .= " AND srv.engine = '".$_POST['engine']."'";
	if (!empty($_POST['location'])) $variants .= " AND lc.lid = '".$_POST['location']."'";
	if (!empty($_POST['platform'])) $variants .= " AND srv.platform = '".$_POST['platform']."'";
}

$query = mysql_query("SELECT * FROM dgh_servers AS srv JOIN dgh_engines JOIN dgh_ips as ip JOIN dgh_masterservers as ms JOIN dgh_locations as lc WHERE kind <> 'voice' AND isenable = '1' AND eid = srv.engine AND ip.iid = srv.ip AND ip.master_server = ms.sid AND ms.location = lc.lid ".$variants." ORDER BY rand() LIMIT 10");

$i = 1;
while($result = mysql_fetch_array($query)) {
	if ($result['platform'] == "win") $result['platform'] = "Windows";
	if ($result['platform'] == "lin") $result['platform'] = "Linux";
	
	$cache = mysql_query("SELECT * FROM dgh_monitoring_cache WHERE number = '".$result['number']."'");
	$cache = mysql_fetch_array($cache);
	
	$players = "";
	$content = "";
	$content .= "<table width='100%'>";
	
	if (!empty($cache['number'])) {
		if ($cache['status'] == "1" && $cache['totalplayers'] != "" && $cache['maxplayers'] != "") $players = $cache['totalplayers']."/".$cache['maxplayers'];
		if ($cache['status'] == "0") $cache['status'] = "<font color='red'>offline</font>";
		if ($cache['status'] == "1") $cache['status'] = "<font color='green'>online</font>";
		
		$content .= "<tr>";
		$content .= "<td colspan='2'><b>".$cache['title']."</b></td>";
		$content .= "<td align='right'>".$cache['status']."</td>";
		$content .= "</tr>";
	}
	
	$content .= "<tr>";
	$content .= "<td width='60%'><b>IP-адрес:</b> ".$result['external_ip'].":".$result['port']."</td>";
	$content .= "<td width='10%'>".$players."</td>";
	$content .= "<td width='30%' align='right'>".$result['locname']." (".$result['platform'].")</td>";
	$content .= "</tr>";
	
	$content .= "</table>";
	
	$title = "#".$i." ".$result['name'];
	$style_padding = 10;
	include("template/table_content.php");
	
	$i++;
}

require_once("template/footer.php");
?>