<?

function PageConfig($PageConfig = false) {
	global $t, $sql, $set;
	
	$message = isset($_COOKIE['message']) ? output($_COOKIE['message']) : false;
	$message_err = isset($_COOKIE['message_err']) ? output($_COOKIE['message_err']) : false;

	$news_razd = [];
	$query = $sql->fetchAll("SELECT * FROM `news_razd` ORDER BY `sort` ASC");
	foreach ($query AS $p) {
		$news_razd[] = $p;
	}
	
	if (isset($PageConfig)){
		
		if (empty($PageConfig['title'])) {
			$PageConfig['title'] = $set['default_title'];
		}
		$PageConfig['title'] = output($PageConfig['title'], 'html');

		if (empty($PageConfig['keywords'])) {
			$PageConfig['keywords'] = $set['default_keywords'];
		}
		$PageConfig['keywords'] = output($PageConfig['keywords'], 'html');
		
		if (empty($PageConfig['description'])) {
			$PageConfig['description'] = $set['default_description'];
		}
		$PageConfig['description'] = output($PageConfig['description'], 'html');
		
		$t->assign('PageConfig', $PageConfig);
	}
	
	$t->assign('news_razd', $news_razd);
	$t->assign('message', $message);
	$t->assign('message_err', $message_err);
	
	if (empty($PageConfig['head'])) {
		echo $t->fetch('head');
	}
	cookie('message');
	cookie('message_err');
	return $PageConfig;
}
