<?php
require_once('../wu_init.php');
require('../wu-functions/wu_functions.php');
include('wu_checkadmin.php');
if (!wu_token()) { exit('wu-error'); }
if (!USER_LOGGED) { exit('wu-error'); }

if(isset($_POST['id']) && isset($_POST['reas'])){
if(!empty($_POST['id']) && !empty($_POST['reas'])){
$id = intval($_POST['id']);
$reas = mysqli_real_escape_string($connect_db, $_POST['reas']);
$cus = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT id,usr,inf,ty,sec,ti FROM ".DB_PREFIX."_es WHERE id='$id' LIMIT 1"));

//Отправка уведомления в личный кабинет и уведомления на E-mail
$msg = "Товар $cus[ti] удалён по следующей причине: $reas";
mysqli_query($connect_db, "INSERT INTO `".DB_PREFIX."_notif` (usr,msg,st,dt) VALUES ('$cus[usr]','$msg','0','$dt')");
wu_email_send_usr($cus['usr'], 'Новое уведомление', $msg);


$imgq = mysqli_query($connect_db, "SELECT id,img FROM ".DB_PREFIX."_es_i WHERE m='$id'");
while($img = mysqli_fetch_array($imgq)) {
unlink("../../eshop.".SITE."/images/$img[img]");
}
if ($cus['inf'] == 0 && $cus['ty'] == 0) {
unlink("../../eshop/items/$cus[sec]");
}
mysqli_query($connect_db, "DELETE FROM ".DB_PREFIX."_es_b WHERE m = '$id'");
mysqli_query($connect_db, "DELETE FROM ".DB_PREFIX."_es_u WHERE m = '$id'");
mysqli_query($connect_db, "DELETE FROM ".DB_PREFIX."_es_i WHERE m = '$id'");
mysqli_query($connect_db, "DELETE FROM ".DB_PREFIX."_es_c WHERE m = '$id'");
mysqli_query($connect_db, "DELETE FROM ".DB_PREFIX."_es_f WHERE f = '$id'");
mysqli_query($connect_db, "DELETE FROM ".DB_PREFIX."_es_r WHERE m = '$id'");
mysqli_query($connect_db, "DELETE FROM ".DB_PREFIX."_es_v WHERE m = '$id'");
mysqli_query($connect_db, "DELETE FROM ".DB_PREFIX."_es WHERE id = '$id'");
mysqli_query($connect_db, "UPDATE ".DB_PREFIX."_users SET rat=rat-0.2 WHERE uid='$cus[usr]' LIMIT 1");
exit('1');
} else { exit('0'); }
} else { exit('3'); }
?>