<?php 
require('../flowap/system.php');
switch($act) {
    default: 
    	$ids = functions::htmlred($_GET['url']); 
    	$pdr = DB::$dbs->queryFetch('SELECT `id`,`name` FROM `podrazd` WHERE `urlt` = ? LIMIT 1', [$ids]);
	    if(empty($pdr['id'])):
	        $_SESSION['err'] = 'Такого подраздела не существует.';
	        header('location: /'); exit;
	    endif;
    	$title->SetTitle('Раздел - '.$pdr['name']);
    	$title->GetHeader();

	    $onl = DB::$dbs->querySingle('SELECT COUNT(id) FROM `blog` WHERE `moder` = 1 and `podrazdel` = ?',[$pdr['id']]);
	    $num = 6;
	    $total = intval(($onl - 1) / $num) + 1;
	    $page = isset($_GET['page'])?intval($_GET['page']):1;
	    if(empty($page) or $page < 0) $page = 1;
	    if($page > $total) $page = $total;
	    $start = $page * $num - $num;
	    if($onl == 0):
	    	$_SESSION['err'] = 'В подразделе пока не чего нет.';
	        header('location: /'); exit;
	    else:
	    	?>
	    	<div class="row2">
		    	<?php 
		    	$sql = DB::$dbs->query("SELECT `name`,`urlt`,`time`,`message`,`idus`,`id`,`status`,`likes` FROM `blog` WHERE `moder` = 1 and `podrazdel` = ? ORDER BY `time` DESC LIMIT $start, $num",[$pdr['id']])->fetchAll(PDO::FETCH_BOTH);
		        foreach ($sql as $blog): ?>
		        	<div class="flowap3 flowap3d" style="display: inherit;">
			        	<div class="postr1">
			        		<div style="padding-top: 8px;">
			        			<div class="postr4 <?php echo (DB::$dbs->querySingle('SELECT COUNT(*) FROM `likes` WHERE `idus` = ? and `iblog` = ? and `liker` = 1',[$user['id'],$blog['id']]) == 1?'lisss':NULL);?>" onclick="liker(<?php echo $blog['id'];?>);" id="lik_<?php echo $blog['id'];?>" title="поставить лайк"><i class="fas fa-angle-up"></i></div>
			        			<div class="postr3" style="color: green;" id="liker_<?php echo $blog['id'];?>" title="количество лайков"><?php echo $blog['likes'];?></div>
			        			<div class="postr4 <?php echo (DB::$dbs->querySingle('SELECT COUNT(*) FROM `likes` WHERE `idus` = ? and `iblog` = ? and `liker` = 0',[$user['id'],$blog['id']]) == 1?'lisss':NULL);?>" onclick="dezliker(<?php echo $blog['id'];?>);" id="diz_<?php echo $blog['id'];?>" title="поставить дизлайк"><i class="fas fa-angle-down"></i></div>
			        		</div>
			        	</div>
			        	<div class="postr2">
							<div class="fontniz">
								<div class="fontniz2" style="font-weight: 700;" title="кто написал">
									<?php echo functions::usvv($blog['idus']);?>
								</div>
								<time class="fontniz2" style="float: right;" title="время блога">
									<i class="far fa-clock"></i> <?php echo functions::vremja($blog['time']);?>
								</time>
							</div>
							<a title="прочитать полностью" href="/blog/<?php echo $blog['urlt'];?>" class="flowap5">
								<div class="bogess">
									<h1 class="clls"><?php echo $blog['name'];?></h1>
									<?php echo mb_substr(bbcode::notags($blog['message']), 0, 350, 'UTF-8');?>... 
									<div>
										<?php echo $nums1[$blog['status']];?>
									</div>
								</div>	
							</a>
						</div>
					</div>
		    	<?php endforeach; ?>
	    	</div>
	    	<?php echo functions::page('?',$start,$total);
	    	$title->GetFooter();		
	    endif;
	break;
}
?>