<?php
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
if (empty($id)) {
header ('location: /index.html');
exit;
}
$query = DB :: $dbs -> query ("SELECT * FROM `magazin_pr` WHERE `id`= ?", [$id]);
if ($query -> rowCount () == 0) {
header ('location: /');
exit;
}
$pr = $query -> fetch ();
$r = DB :: $dbs -> queryFetch ("SELECT * FROM magazin_r WHERE id = ?", [$pr['id_r']]);

$title->SetTitle('Маркет - ' . $pr['name'].'');
$title->GetHeader();
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="/market"style="text-decoration:none; color:white;"> Маркет</a> :: <a href="/market/kat/'.$r['id'].'"style="text-decoration:none; color:white;">' . $r['name'].'</a> :: ' . $pr['name'].'</div></div></div>';
if($b == true) {
if($b['wm'] == 0){
err('WMID не заполнен! Добавление товара не возможнo!');
} else {
echo'<div class="list-group-item media"> <span class="label label-danger">Новое</span><a href="/market/addfiles/'.$id.'"> Новый Товар</a></div>'; 
}
}
$k_post = DB::$dbs->querySingle("SELECT COUNT(id) FROM magazin_file WHERE id_pr = ?", [$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 magazin_file WHERE id_pr = ? ORDER BY time DESC LIMIT $start,$num",[$id]);
while($a = $sql->fetch()) {
$screen = DB::$dbs->queryFetch("SELECT * FROM `magazin_screen` WHERE `file` = ? ORDER BY `id` DESC LIMIT 1",[$a['id']]);
echo '<a href="/market/file/'.$a['id'].'" class="list-group-item media"><div class="pull-left"><img class="img-circle pull-left" src="/files/mag_screen/'.$screen['screen'].'" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">'.$a['name'].' ('.vr($a['time']).')</div><small class="list-group-item-text">Стоимость: <b><font color="green">'.$a['price'].'</font></b> р.</small></div></a>';
}
echo'</div></div>';
if ($k_page > 1) {
str('?id='.$id.'&',$k_page,$page);
}
?>