<?php

if (!empty($_POST['del']) && is_numeric($_POST['del'])) // Видалення діалогу
{



	$del = abs(intval($_POST['del']));	
	if ($user_id == $del) go(URL.'/mail/');
	$result = mysql_query("SELECT * FROM `mail_dialog` WHERE `for_id` = '".$user_id."' AND `from_id` = '".$del."' AND `del` != '".$user_id."' LIMIT 1");
	if (mysql_num_rows($result) == true) $arr_dialog = mysql_fetch_array($result);
	else go(URL.'/mail/');


	if ($arr_dialog['del'] == 0)
	{
		mysql_query("UPDATE `mail_msg` SET `del` = '".$user_id."' WHERE `for_id` = '".$user_id."' AND `from_id` = '".$del."'");
		mysql_query("UPDATE `mail_msg` SET `del` = '".$user_id."' WHERE `for_id` = '".$del."' AND `from_id` = '".$user_id."'");
		mysql_query("UPDATE `mail_dialog` SET `del` = '".$user_id."', `np` = 0 WHERE `for_id` = '".$user_id."' AND `from_id` = '".$del."' LIMIT 1");
		mysql_query("UPDATE `mail_dialog` SET `del` = '".$user_id."' WHERE `from_id` = '".$user_id."' AND `for_id` = '".$del."' LIMIT 1");
	}
	else
	{
		mysql_query("DELETE FROM `mail_msg` WHERE `for_id` = '".$user_id."' AND `from_id` = '".$del."'");
		mysql_query("DELETE FROM `mail_msg` WHERE `for_id` = '".$del."' AND `from_id` = '".$user_id."'");
		mysql_query("DELETE FROM `mail_dialog` WHERE `for_id` = '".$user_id."' AND `from_id` = '".$del."' LIMIT 1");
		mysql_query("DELETE FROM `mail_dialog` WHERE `for_id` = '".$del."' AND `from_id` = '".$user_id."' LIMIT 1");
		if (!empty($arr_dialog['dir']) && is_dir(HOME.'/files/mail/'.$arr_dialog['dir'])) delete_dir(HOME.'/files/mail/'.$arr_dialog['dir']);
	}
	
	
	
}


?>