<?php

/*
---------------------------------------
Удаление комментариев и лайков к записи
---------------------------------------
*/

DB::GET_SET("DELETE FROM `BLOGS_LIKES` WHERE `BLOG_ID` = '".$blog['ID']."'");

DB::GET_SET("DELETE FROM `BLOGS_EYE` WHERE `BLOG_ID` = '".$blog['ID']."'");

$data = DB::GET_STRING_ALL("SELECT `ID` FROM `BLOGS_COMMENTS` WHERE `BLOG_ID` = '".$blog['ID']."'");

WHILE ($list = $data->FETCH()){
  
  DB::GET_SET("DELETE FROM `BLOGS_COMMENTS_LIKES` WHERE `COMMENT_ID` = '".$list['ID']."'");
  
  DB::GET_SET("DELETE FROM `ATTACHMENTS` WHERE `ID_POST` = '".$list['ID']."' AND `TYPE_POST` = 'blogs_comments'");
  
  DB::GET_SET("DELETE FROM `BLOGS_COMMENTS` WHERE `ID` = '".$list['ID']."' LIMIT 1");
  
}

/*
---------------------
Удаление самой записи
---------------------
*/

DB::GET_SET("DELETE FROM `ATTACHMENTS` WHERE `ID_POST` = '".$list['ID']."' AND `BLOGS` = '1'");
  
DB::GET_SET("DELETE FROM `BLOGS` WHERE `ID` = '".$blog['ID']."' AND `USER_ID` = '".$account['ID']."'");

SUCCESS('Запись успешно удалена', 'session');
REDIRECT('/modules/?path=blogs&section=users&id='.$account['ID'].'');

?>