<?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' => 'Неверный токен')));

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

	$users = $pdo->query('SELECT `id`, `login`, `avatar`, `reit`, `thanks`, `answers` FROM `users` ORDER BY `reit` DESC LIMIT 5'); 
			 $users->setFetchMode(PDO::FETCH_OBJ);

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

	while($user = $users->fetch())
	{
		$tpl->load_template('topusers.tpl');
			$tpl->set('{id}', $user->id);
			$tpl->set('{login}', $user->login);
			$tpl->set('{avatar}', $user->avatar);
			$tpl->set('{reit}', $user->reit);
			$tpl->set('{thanks}', $user->thanks);
			$tpl->set('{answers}', $user->answers);
		$tpl->compile('content');
	}

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

