<?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'])){
if(!empty($_POST['id'])){
$id = intval($_POST['id']);
$cus = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT id,usr,ti,log FROM ".DB_PREFIX."_es INNER JOIN ".DB_PREFIX."_users ON ".DB_PREFIX."_es.usr = ".DB_PREFIX."_users.uid WHERE id='$id' LIMIT 1"));


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


mysqli_query($connect_db, "UPDATE ".DB_PREFIX."_es SET st = '1', reas = '' WHERE id='$id' LIMIT 1");

$sub = mysqli_query($connect_db, "SELECT id,usr FROM ".DB_PREFIX."_es_s WHERE tou='$cus[usr]'");
while($rows = mysqli_fetch_array($sub)) {
$msgs = "<b>Eshop:</b> $cus[log] добавил новый товар <a href=\"http://eshop.".SITE."/show/$id\">$cus[ti]</a>";

//Отправка уведомления в личный кабинет и уведомления на E-mail
$msg = "$cus[log] добавил новый товар <a href=\"".PROTOCOL.SITE."/eshop_show/$id\">$cus[ti]</a>";
mysqli_query($connect_db, "INSERT INTO `".DB_PREFIX."_notif` (usr,msg,st,dt) VALUES ('$rows[usr]','$msg','1','$dt')");
wu_email_send_usr($rows['usr'], 'Новое уведомление', $msg);

}
exit('1');
} else { exit('0'); }
} else { exit('3'); }
?>