<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB :: $dbs -> query ("SELECT * FROM down_r WHERE `id` = ?",[$id]);
if ($array -> rowCount() == 0) {
header('location: /');
die();
}
$r = $array -> fetch ();
$title->SetTitle('Загруз-центр - '.$r['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="/downs"style="text-decoration:none; color:white;">Загруз-центр</a> :: '.$r['name'].'</div></div></div>';
$do = isset($_GET['do']) ? check($_GET['do']) : false;
switch($do) {
default:
if ($b['level'] > 2) {
echo '<div class="list-group-item media"><span class="label label-danger">Новый</span> <a href="?do=add&id='.$id.'"> Добавить подраздел</a> </div>';
}
echo'<div class="t-body"><div class="list-group lg-alt">';
if (DB :: $dbs -> querySingle ("SELECT COUNT(id) FROM `down_pr` WHERE `id_r`= ?", [$r['id']])!=0) {
$query = DB::$dbs -> query("SELECT * FROM `down_pr` WHERE `id_r`= ?ORDER BY `id`", [$r['id']]);
while ($pr = $query -> fetch ()) {
echo '<div class="list-group-item media"><a href="show_kat.html?id=' . $pr['id'] . '"><i class="zmdi zmdi-folder-star"></i> ' . $pr['name'] . ' ('.DB :: $dbs -> querySingle ("SELECT COUNT(id) FROM `downs` WHERE `prid`= ? AND `mod` = ?", [$pr['id'],0]).')</div></a>';
}
} else {
err('Подразделы ещё не созданы!');
}
break;
case 'add':
if ($b['level'] < 2) { 
header('location: /');
die();
}
$array = DB::$dbs->query("SELECT * FROM down_r WHERE id = ? LIMIT 1", [$id]);
if ($array -> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
if (isset($_POST['add'])) {
if (empty($_POST['name'])) {
err('Введите название!');
} else {
DB::$dbs->query("INSERT INTO down_pr SET name = ?, id_r = ?", [check($_POST['name']),$id]);
header('location: /downs/show_dir.html?id='.$id);
}
}
echo '<div class="list-group-item media"><form action="?do=add&id='.$id.'" method="POST">Название:<br/> <input class="form-control" type="text" name="name"/><br/><input type="submit" class="btn btn-primary" name="add" value="Добавить"/></form></div>';
break;
}
echo '</div></div>';
$title->GetMenu();
$title->GetFooter();
?>