<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$title->SetTitle(homeurl.' - Загруз-центр');
$title->GetHeader();


$newkom = DB::$dbs->querySingle("SELECT count(id) FROM `down_komm` WHERE `time` > ?", [time()-86400]);
$date = time() - 3600 * 72;
$newfiles = DB::$dbs->querySingle("SELECT COUNT(id) FROM `downs` WHERE `time` > ? AND `mod` = ?", [$date,0]);
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></div>';
echo'<div class="tile-body"><div class="count-box bg-blue"><div class="row text-center">

<a href="/downs/newkomm.html"style="text-decoration:none; color:white;"><div class="col-sm-3 col-xs-6"><div class="cb-item"><h3 style="text-decoration:none; color:white;">'.$newkom.'</h3><small>Обсуждение</small></div></div></a>
<a href="/downs/newfiles.html"style="text-decoration:none; color:white;"><div class="col-sm-3 col-xs-6"><div class="cb-item"><h3 style="text-decoration:none; color:white;">'.$newfiles.'</h3><small>Новое</small></div></div></a>
<a href="/downs/search.html"style="text-decoration:none; color:white;"><div class="col-sm-3 col-xs-6"><div class="cb-item"><h3 style="text-decoration:none; color:white;">0</h3><small>Поиск</small></div></div></a>
<a href="/downs/rules.html"style="text-decoration:none; color:white;"><div class="col-sm-3 col-xs-6"><div class="cb-item"><h3 style="text-decoration:none; color:white;">2</h3><small>Правила</small></div></div></a>
</div></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 down_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>';
}

if (DB::$dbs->querySingle("SELECT count(id) FROM `down_r`")== 0){
echo '<div class="alert alert-danger"role="alert"> Категорий нет</div>';
} else {
echo'<div class="t-body"><div class="list-group lg-alt">';
$query = DB::$dbs -> query("SELECT * FROM `down_r` ORDER BY `id` ASC");
while ($row = $query -> fetch()) {
echo '<a href="show_dir.html?id='.$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 `downs` WHERE `rid`= ? AND `mod` = ?", [$row['id'],0]).')</div><small class="list-group-item-text">'.$row['opis'].'</small></div></a>';
}
}
echo '</div>';
$title->GetMenu();
$title->GetFooter();
?>