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

	if(!strripos($users_groups[$_SESSION['rights']]['rights'], "t") !== false)
		exit;

	$id = check($_POST['id'], 'int');

	if(!$id)
		exit;

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

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

	$query = $pdo->query('SELECT `id`, `name`, `description`, `img` FROM `forums` WHERE `section_id`="'.$id.'" ORDER BY `trim`');
			$query->setFetchMode(PDO::FETCH_OBJ);

	while($forum = $query->fetch())
	{
		$tpl->load_template('settings_forum_forums.tpl');
			$tpl->set('{section}', $id);
			$tpl->set('{token}', $token);
			$tpl->set('{id}', $forum->id);
			$tpl->set('{name}', $forum->name);
			$tpl->set('{img}', $forum->img);
			$tpl->set('{description}', $forum->description);
		$tpl->compile('content');
	}

	if($tpl->result['content'] == '')
	{
		$tpl->load_template('content_none.tpl');
			$tpl->set('{text}', 'Форумов нет');
		$tpl->compile('content');
	}

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