<?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();

if ($b == false) {
header('location: /');
die();
}
//echo'<div class="row"><div class="col-sm-6">
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="/office"style="text-decoration:none; color:white;"> Кабинет</a> :: Черный список</div></div></div>';
echo'<div class="t-body"><div class="list-group lg-alt">';
echo '<div class="list-group-item media"><div class="media-body"><div class="list-group-item-heading"><a href="?add"><i class="zmdi zmdi-account-add zmdi-hc-fw"></i>  Добавить мастера</a></div></div></div>';
if (isset($_POST['add'])) {
$user = check($_POST['user']);
$u = !is_numeric($user) ? "`nick`='".$user."'" : "`id`='".abs((int)$user)."'";
$row = DB::$dbs->queryFetch("SELECT * FROM blogger WHERE $u LIMIT 1");
if ($row == 0) {
err('Такого юзера нет!');
} elseif ($row['id'] == $b['id']) {
err('Нельзя себя добавлять.');
} elseif (empty($user)) {
err('Введите ID/Ник мастера.');
} elseif (DB::$dbs->querySingle("SELECT COUNT(id) FROM ignor WHERE user_id = ? AND id_user = ?", [$b['id'],$row['id']]) > 0) {
err('Этот мастер уже в Вашем игнор-листе.');
} else {
DB::$dbs->query("INSERT INTO ignor SET user_id = ?, id_user = ?", [$b['id'],$row['id']]);
$mess = Nick($b['id']).' добавил Вас в игнор-лист.';
jurnal($row['id'],$mess,5);
echo '<div class="alert alert-success">Успешно добавлено.</div>';
}
}
if (isset($_GET['add'])) {
echo '<div class="list-group-item media"><div class="media-body"><div class="list-group-item-heading"><form action="?add" method="POST">ID/Ник мастера:<br/><input type="text" class="form-control" name="user"/><br/><input type="submit" name="add" class="btn btn-primary" value="Добавить"/></form></div></div></div>';
}
if (isset($_GET['del'])) {
DB::$dbs->query("DELETE FROM ignor WHERE id = ?", [abs((int)$_GET['del'])]);
header('location: ?');
die();
}

$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM ignor WHERE user_id = ?", [$b['id']]);
if ($look == 0) {
err('Ваш черный-список пуст!');
}
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM ignor WHERE user_id = ? ORDER BY id DESC LIMIT $start,$num",[$b['id']]);
while($a = $sql->fetch()) {
$D = '<a href="?del='.$a['id'].'">[Удал]</a>';
echo ' <div class="list-group-item media"><div class="media-body"><div class="list-group-item-heading">'.Nick($a['id_user']).'  ' .$D .'</div></div></div>';
}
echo'</div></div>';
if ($k_page > 1) {
str('?',$k_page,$page);
}

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