<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$newkom = DB::$dbs->querySingle("SELECT count(id) FROM `magazin_komm` WHERE `time` > ?", [time()-86400]);
$list = ['kat','dir','file','buy','addfiles','addfiles','newkomm','rules','newtovc','usinf','uskab','search','screen','refile','seller','whobuy','corz','mybuy','myout','ustovc','zip','Chaindel'];
$do = isset($_GET['do']) ? htmlspecialchars($_GET['do']) : false;
$act = isset($_GET['act']) ? htmlspecialchars($_GET['act']) : false;
if (in_array($do, $list)) {
require_once('../market/incfiles/'.$do.'.php');
} else {
$title->SetTitle(homeurl.' - Онлайн маркет');
$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> :: Маркет</div></div>';
echo'<ul class="nav nav-pills nav-stacked"><li><a href="newkomm"><i class="zmdi zmdi-comments"></i>  Новые комментарии '.$nkom = ($newkom > 0 ? '('.$newkom.'</b>)':NULL).'</ul></a>';
echo'<ul class="nav nav-pills nav-stacked"><li><a href="search"><i class="zmdi zmdi-search"></i>  Поиск товаров</a></ul>';
echo'<ul class="nav nav-pills nav-stacked"><li><a href="rules"><i class="zmdi zmdi-fire"></i>  Пользовательское соглашение</a></ul></div>';
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i> Список категорий</div></div></div>';
if ($b['level'] > 3) {
echo '<div class="list-group-item media"> <span class="label label-danger">Новые</span><a href="?new"> Добавить категорию</a></div>';
}
if (isset($_POST['add'])) {
DB::$dbs->query("INSERT INTO magazin_r SET name = ?, opis = ?", [check($_POST['name']),check($_POST['opis'])]);
header('location: ?');
}
if (isset($_GET['new'])) {
echo '<div class="list-group-item media"><form action="?" method="POST">Название <br/> <input class="form-control" type="text" name="name"/>Описание:<br/><textarea class="form-control" rows="5" name="opis"></textarea><br/><input type="submit" class="btn btn-primary" name="add" value="Добавить"/></form></div>';
}
echo'<div class="t-body"><div class="list-group lg-alt">';
if (DB::$dbs->querySingle("SELECT count(id) FROM `magazin_r`")== 0){
echo '<div class="alert alert-danger">Категорий нет</div>';
} else {
$query = DB::$dbs -> query("SELECT * FROM `magazin_r` ORDER BY `id` ASC");
while ($row = $query -> fetch()) {
echo '<a href="kat/'.$row['id'].'" class="list-group-item media"><div class="pull-left"><img class="img-circle pull-left" src="/assets/img/2.jpg" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">'.$row['name'].'  ('.DB::$dbs->querySingle("SELECT count(id) FROM `magazin_file` WHERE `id_r`  = ?",[$row['id']]).')</div><small class="list-group-item-text">'.$row['opis'].'</small></div></a>';
}
}
echo '</div></div>';
if($b == true) {
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i> Меню продавца</div></div>';
$tovc = DB::$dbs->querySingle("SELECT count(id) FROM `magazin_file` WHERE `time` > ?", [time()-86400]);
echo'<ul class="nav nav-pills nav-stacked"><li><a href="/seller/'.$b['id'].'"><i class="zmdi zmdi-shuffle"></i> Моя страница</a></ul>';
echo'<ul class="nav nav-pills nav-stacked"><li><a href="uskab"><i class="zmdi zmdi-shuffle"></i>  Кабинет</a></ul>';
echo'<ul class="nav nav-pills nav-stacked"><li><a href="newtovc"><i class="zmdi zmdi-shuffle"></i> Новые товары '.($tovc>0 ? '('.$tovc.')':'').'</a></ul></div>';
}
}
$title->GetMenu();
$title->GetFooter();
?>