<?php
	header('X-Frame-Options: DENY');
	header('X-XSS-Protection: 1; mode=block');
	header('Content-Type: text/html; charset=utf-8');

	include('../../../inc/db.php');
	include('../../../inc/classes/class.template.php');

	$tpl = new Template;
	$tpl->dir = '../tpl/ajax/elements/';

	$id = isset($_POST['id']) ? intval($_POST['id']) : 1;

	$query = $pdo->query('SELECT `sid`, `name`, `map`, `players_max`, `players_now` FROM `monitoring` WHERE `sid`="'.$id.'" LIMIT 1');
			 $query->setFetchMode(PDO::FETCH_OBJ);

	$tpl->result['content'] = '';

	$server = $query->fetch();

	$query = $pdo->query('SELECT `address` FROM `servers` WHERE `id`="'.$server->sid.'" LIMIT 1');
			 $query->setFetchMode(PDO::FETCH_OBJ);
	$info = $query->fetch();

	$tpl->load_template('server.tpl');
		$tpl->set('{id}', $id);
		$tpl->set('{name}', $server->name);
		$tpl->set('{map_img}', ($server->map && file_exists('../../../files/maps_imgs/'.$server->map.'.jpg')) ? '/files/maps_imgs/'.$server->map.'.jpg' : '/files/maps_imgs/none.jpg');
		$tpl->set('{map_name}', $server->map);
		$tpl->set('{max}', $server->players_max);
		$tpl->set('{now}', $server->players_now);
		$tpl->set('{address}', $info->address);
		$tpl->set('{id}', $server->sid);
	$tpl->compile('content');

	$tpl->show($tpl->result['content']);
?>