<?

if (!isset($urlType[2])) {
	Redirection('/');
}

$count = $sql->rowCount("SELECT * FROM `news_razd` WHERE `link` = ? LIMIT 1", [$urlType[2]]);
if ($count == 0) {
	Redirection('/');
}
$razd = $sql->fetch("SELECT * FROM `news_razd` where link = ? ", [$urlType[2]]);

$count_max = 9;
$count = $sql->rowCount("SELECT * FROM `news` WHERE `razd` = '{$razd['id']}' AND `act` = '1'");
$page_num = (!empty($_GET['page']) ? (int) $_GET['page'] : 1); 
$page = page('?page=',  $page_num , $count , $count_max);
$page['count'] = $count;
$page['page_num'] = $page_num;
$page['count_max'] = $count_max;

$PageConfig = [
	'title' => 'Новости - '. $razd['name'] .', страница №'. $page_num,
	'keywords' => $razd['keywords'] ,
	'description' => $razd['description'] ,	
];

PageConfig($PageConfig);

$news = [];
$query = $sql->fetchAll("SELECT * FROM `news` where `razd` = '{$razd['id']}' AND `act` = '1' ORDER BY `date_public` DESC LIMIT {$page['start']} , {$page['num']};");
foreach ($query AS $p) {
	if (FileSystem::TextStrlen($p['title']) > 79) {
		$p['title'] = FileSystem::TextCut($p['title'] , 80);
	}
	$news[] = $p;
}
$razd['text'] = output($razd['text']);

$t->assign('razd', $razd);
$t->assign('page', $page);
$t->assign('news', $news);
echo $t->fetch('news.razd');