<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$title->SetTitle('Полезные куски кодов - Категории');
$title->GetHeader();
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB::$dbs->query("SELECT * FROM codes_cat WHERE id = ? LIMIT 1", [$id]);
if ($array -> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: <a href="/codes"style="text-decoration:none; color:white;">Полезные коды</a> ::  '.$arr['name'].'  </div></div></div>';
if ($b == true){
echo '<div class="tile"><ul class="nav nav-pills nav-stacked"><li><a href="addcode.php?id='.$id.'"> <span class="label label-danger">Новое</span> Добавить код</a></ul></div>';
}
$k_post = DB::$dbs->querySingle("SELECT COUNT(id) FROM codes_code WHERE cid = ?", [$id]);
if ($k_post == 0) {
err('В данной категории нет кодов!');
}
echo'<div class="t-body"><div class="list-group lg-alt">';
$num = 10;
$k_page = k_page($k_post, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM codes_code WHERE cid = ? ORDER BY time DESC LIMIT $start,$num",[$id]);
while($a = $sql->fetch()) {
echo '<a class="list-group-item media" href="code.php?id='.$a['id'].'"><div class="pull-left"><img class="img-circle pull-left" src="/'.(user_inf($a['user_id'], 'ava') != NULL ? user_inf($a['user_id'], 'ava') : 'assets/img/4.jpg').'" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">   '.$a['name'].'  </div><small class="list-group-item-text">('.vr($a['time']).')</small></div></a>';
}
echo'</div></div>';
if ($k_page > 1) {
str('?id='.$id.'&',$k_page,$page);
}


$title->GetMenu();
$title->GetFooter();
?>