<?php
$title = 'Удаление изображения';
include_once($_SERVER["DOCUMENT_ROOT"].'/php/style/head.php');
$_GET['id'] = abs(intval($_GET['id']));
$query = $db->query("SELECT * FROM `products_reviews_comm_images` WHERE `id`='".$_GET['id']."'");
if($query->num_rows == 0){
	header('location:/');
	// Картинки не существует
}
$image = $query->fetch_assoc();
$query = $db->query("SELECT * FROM `products_reviews_comm` WHERE `id`='".$image['id_comm']."'");
if($query->num_rows == 0){
	header('location:/');
	// Отзыва не существует
}
$comm = $query->fetch_assoc();
if($user['admin'] < 1 && $user['id'] != $comm['id_user']){
	header('location:/');
	// Нет прав на удаление картинки
}
$review = $db->query("SELECT * FROM `products_reviews` WHERE `id`=".$comm['id_review']."")->fetch_assoc();
$db->query("DELETE FROM `products_reviews_comm_images` WHERE `id`='".$image['id']."'");
unlink($_SERVER["DOCUMENT_ROOT"].'/files/images/reviews/comments/'.$image['image']);
header('location:/product/'.$review['id_product'].'/reviews/'.$review['id'].'/comments/'.$comm['id'].'/edit');
include_once($_SERVER["DOCUMENT_ROOT"].'/php/style/foot.php');
?>