<?php
	header('Content-Type: text/html; charset=utf-8');

	include('../../../inc/start.php');
	include('../../../inc/protect.php');

	if(!isset($_POST['token']) || $_SESSION['token'] != clean($_POST['token'], null))
		exit(json_encode(array('status' => 'error', 'text' => 'Неверный токен')));

	$id = intval($_POST['id']);

	if(!$id)
		exit;

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

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

	$admins = $pdo->query('SELECT `admins`.`id`, `admins`.`type`, `admins`.`name`, `admins`.`cause`, `admins`.`pirce`, `admins`.`link`, `admins`.`active`, `servers`.`name` AS `server_name` FROM `admins` LEFT JOIN `servers` ON `servers`.`id`=`admins`.`server` WHERE `admins`.`user_id`="'.$id.'" ORDER BY `admins`.`server`'); 
			  $admins->setFetchMode(PDO::FETCH_OBJ);

	while($admin = $admins->fetch())
	{
		switch($admin->type)
		{
			case 'a':
				$type = 'Ник и пароль';
			break;

			case 'ce':
				$type = 'SteamID';
			break;

			case 'ca':
				$type = 'SteamID и пароль';
			break;

			default:
				$type = 'Неизвестно';
		}

		$tpl->load_template('profile_privileges.tpl');
			$tpl->set('{id}', $admin->id);
			$tpl->set('{server}', $admin->server_name);
			$tpl->set('{active}', $admin->active);
			$tpl->set('{cause}', $admin->cause);
			$tpl->set('{price}', $admin->pirce);
			$tpl->set('{link}', $admin->link);
			$tpl->set('{name}', $admin->name);
			$tpl->set('{type}', $type);
		$tpl->compile('content');
	}

	if($tpl->result['content'] == '')
	{
		$tpl->load_template('content_none.tpl');
			$tpl->set('{text}', 'Привилегий нет');
		$tpl->compile('content');
	}

	echo $tpl->result['content'];
?>