<?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;

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

	function forum_get_groups(&$users_groups, $access = ';', $id = '')
	{
		global $tpl;

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

		$tpl->load_template('settings_forum_groups.tpl');
			$tpl->set('{id}', $id);
			$tpl->set('{input}', '0');
			$tpl->set('{name}', 'Все');
			$tpl->set('{checked}', $access == ';' ? 'checked' : '');
			$tpl->set('{onclick}', 'all');
		$tpl->compile('groups');

		$access = explode(';', $access);

		foreach($users_groups as &$value)
		{
			if(!$value['id'])
				continue;

			$tpl->load_template('settings_forum_groups.tpl');
				$tpl->set('{id}', $id);
				$tpl->set('{input}', $value['id']);
				$tpl->set('{name}', $value['name']);
				$tpl->set('{checked}', in_array($value['id'], $access) ? 'checked' : '');
				$tpl->set('{onclick}', $value['id']);
			$tpl->compile('groups');
		}

		return $tpl->result['groups'];
	}

	echo forum_get_groups($users_groups);
?>