<?php
define('NTLCMS', 1);
$module = 'mail';
include ('../system/start.php');
include ('../system/function.php');
include ('../system/antidos.php');
include ('../system/head.php');
include ('../system/crypt.class.php');
if (!$active) {
header('Location: '.URL);
$_SESSION['fail'] = 'Вы не авторизированы!';
exit;
}
if (empty($_GET['user'])) {
header('Location: '.URL.'/messages');
$_SESSION['fail'] = 'Пользователь не указан!';
exit;
}
$user = checkout($_GET['user']);
$contact = DB::run()->query("SELECT * FROM `contacts` WHERE `kto` = ? AND `kogo` = ?", 
array($ulogin, $user))->fetch(PDO::FETCH_OBJ);
if (!$contact) {
header('Location: '.URL.'/messages');
$_SESSION['fail'] = 'Диалог не найден!';
exit;
}
DB::run()->query("DELETE FROM `message` WHERE (`kto` = ? AND `komy` = ?) OR (`kto` = ? AND `komy` = ?)", 
array($ulogin, $user, $user, $ulogin));
DB::run()->query("DELETE FROM `contacts` WHERE `kto` = ? AND `kogo` = ?", 
array($ulogin, $user));
header('Location: '.URL.'/messages');
$_SESSION['success'] = 'Диалог с пользователем '.$user.' успешно очищен!';
exit;
?>