<?php

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

DB::GET_SET("DELETE FROM `FORUM_THEM_LIKES` WHERE `THEM_ID` = '".$fthem['ID']."'");

DB::GET_SET("DELETE FROM `FORUM_THEM_EYE` WHERE `THEM_ID` = '".$fthem['ID']."'");

$data = DB::GET_STRING_ALL("SELECT `ID` FROM `FORUM_THEM_COMMENTS` WHERE `THEM_ID` = '".$fthem['ID']."'");

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

/*
-------------------
Удаление самой темы
-------------------
*/

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

IF (ACCESS('forum_edit', NULL, 1) || MANAGEMENT == 1){
  
  LOGS('Форум - удаление темы '.$account['LOGIN'].'', $user['ID']);

}

SUCCESS('Тема успешно удалена', 'session');
REDIRECT('/modules/?path=forum&section=subsection_themes&id='.$subsection['ID'].'');

?>