<?php

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

DB::GET_SET("DELETE FROM `PHOTOS_LIKES` WHERE `PHOTO_ID` = '".$photo['ID']."'");

$data = DB::GET_STRING_ALL("SELECT `ID` FROM `PHOTOS_COMMENTS` WHERE `PHOTO_ID` = '".$photo['ID']."'");

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

/*
--------------------
Удаление самого фото
--------------------
*/

@UNLINK(ROOT.'/files/upload/photos/source/'.$photo['ID'].'.'.$photo['EXT'].'');
@UNLINK(ROOT.'/files/upload/photos/260x600/'.$photo['ID'].'.jpg');
@UNLINK(ROOT.'/files/upload/photos/240x240/'.$photo['ID'].'.jpg');
@UNLINK(ROOT.'/files/upload/photos/150x150/'.$photo['ID'].'.jpg');
@UNLINK(ROOT.'/files/upload/photos/50x50/'.$photo['ID'].'.jpg');

DB::GET_SET("DELETE FROM `PHOTOS_SHOW` WHERE `PHOTO_ID` = '".$photo['ID']."' AND `USER_ID` = '".$account['ID']."'");
  
DB::GET_SET("DELETE FROM `PHOTOS` WHERE `ID` = '".$photo['ID']."' AND `USER_ID` = '".$account['ID']."'");

SUCCESS('Фотография успешно удалена', 'session');
REDIRECT('/modules/?path=photos&section=users&id='.$account['ID'].'&dir='.$id_dir.'');

?>