<?php
include_once('../inclfiles/core.php');
if($id != 0){
	if(mysql_num_rows(mysql_query("SELECT * FROM `forum_razdels` WHERE `id` = ".$id."")) != 0){
		$razdel = mysql_fetch_array(mysql_query("SELECT * FROM `forum_razdels` WHERE `id` = ".$id.""));
        $title = $razdel['name'];
		include_once('../inclfiles/head.php');
		$all = mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `razdel` = ".$id." ".$deleted.""));
		if($all != 0){
			$total=intval(($all-1)/$set['napage'])+1;
			if(empty($page) OR $page < 0) $page = 1;
			if($page > $total) $page = $total;
			$past=intval($all/$set['napage']);
			$start=$page*$set['napage']-$set['napage'];
			$themes = mysql_query("SELECT * FROM `forum_themes` WHERE`razdel` = ".$id." ".$deleted." ORDER BY `time_last` DESC LIMIT ".$start.",".$set['napage']."");
			while($theme = mysql_fetch_array($themes)){
				if($theme['zakril'] != 0) $zakr = 'zakrito';
				else $zakr = 'theme';
				if($user AND $user['level'] >= 2) $counter = 'posts_all';
				else $counter = 'posts';
				a('index.php?id='.$theme['id'].'&',time_right($theme['time_last']).$theme['name'].deleted($theme['deleted']),$zakr,$theme[$counter]);
			}
			navigation($all,$set['napage'],$page,'razdels.php?',$total);
		}
		else t('В данном разделе нет тем');
	}
	else{
		$title = 'Ошибка';
		include_once('../inclfiles/head.php');
		t('Раздел не найден');
	}
	a('razdels.php?','Все разделы','razdels');
}
else{
	$title = 'Разделы форума';
	include_once('../inclfiles/head.php');
	$all = mysql_num_rows(mysql_query("SELECT * FROM `forum_razdels`"));
	if($all != 0){
		$razdels = mysql_query("SELECT * FROM `forum_razdels`");
		while($razdel = mysql_fetch_array($razdels)){
			if($user AND $user['level'] == 4) $razdel['kol_all'] = $razdel['kol_all'] + $razdel['kol_deleted'];
	        a('razdels.php?id='.$razdel['id'],$razdel['name'].counters(mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `zakril` = 0 AND `razdel` = ".$razdel['id']." ".$deleted."")),mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `razdel` = ".$razdel['id']." ".$deleted.""))).'<br/><small>'.$razdel['opis'].'</small>','none');
		}
	}
	else t('Нет разделов');
}
a('index.php?','Форум','forum',mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` WHERE `zakril` = 0 ".$deleted."")),mysql_num_rows(mysql_query("SELECT * FROM `forum_themes` ".$wdeleted."")));
include_once('../inclfiles/foot.php');
?>