<?
$kat_id = (int)abs($_GET['dell_kat']);
$kat = DB :: $pdo -> queryFetch("SELECT * FROM `gifts_kat` WHERE `id` = ? LIMIT 1;", array($kat_id));
if (!isset($kat) || $kat['id'] <= 0)
{
?>
<div class="list _gray _font-s _center">Категория не найдена!</div>
<?
} else {
if (isset($_POST['cfms']))
{
$total = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `gifts` WHERE `id_kat` = '".$kat_id."'");
if ($total > 0)
{
$query_gifts = DB :: $pdo -> query("SELECT * FROM `gifts` WHERE `id_kat` = '".$kat_id."' ORDER BY `id` DESC");
while($r = $query_gifts -> fetch())
{
if (is_file("".$_SERVER['DOCUMENT_ROOT']."/template/gifts/".$r['id'].".jpg"))
{
unlink("".$_SERVER['DOCUMENT_ROOT']."/template/gifts/".$r['id'].".jpg");
}
DB :: $pdo -> query("DELETE FROM `gifts` WHERE `id` = '".$r['id']."' LIMIT 1");
}
}
DB :: $pdo -> query("DELETE FROM `user_gifts` WHERE `id_kat` = '".$kat['id']."'");
DB :: $pdo -> query("DELETE FROM `gifts_kat` WHERE `id` = '".$kat['id']."' LIMIT 1");
system :: redirect("Категория успешно удалена.", "/gifts?admin");
}
?>
<div class="list _bg-blue">
<form method="post" class="post-add" data-type="arbour" action="/gifts?admin&dell_kat=<?echo $kat['id'];?>">
<b><center>Вы уверены, что хотите удалить эту папку?</center></b><br />
<div class="_center" style="margin-top: 3px;">
<input type="submit" class="main-btn _w-100" name="cfms" value="Да, продолжить" />
</div>
</form>
<div class="p-error"></div>
</div>
<?
}
echo system :: touch("/gifts?admin&adm_kat=".$kat['id']."", system :: icon("arr-l")."Назад");
require (CORE."foot.php");
?>