<?php
	/*
	* Модуль почты для JohnCMS 3.2.2 v2.6
	* Copyright © 2010-2011 UPcoder.RU Group All Rights Reserved.
	* Coding by Krite 2010-2011
	*/
	defined('_IN_JOHNCMS') or die('Error: restricted access');
	$textl = 'Массовое удаление исходящих';
	$headmod = 'pochta';
	require_once('../incfiles/head.php');
	echo '<div class="phdr"><h3>Удаление исходящих</h3></div>';
	if (isset ($_GET['yes'])) {
			$dc = $_SESSION['dc'];
			$prd = $_SESSION['prd'];
			foreach ($dc as $delid) {
				$res = mysql_fetch_assoc(mysql_query("SELECT * FROM `mail_msg` WHERE `id_user`='" . $user_id . "' AND `id`='" . $delid . "' or `id_kont`='" . $user_id . "' AND `id`='" . $delid . "';"));
				if (!empty($res['delete']) && $res['delete']!=$user_id) {
					mysql_query("DELETE FROM `mail_msg` WHERE `id`='".$res['id']."' AND `id_user`='$user_id' OR `id`='{$res['id']}' AND `id_kont`='" . $user_id . "' LIMIT 1;");
					mysql_query("OPTIMIZE TABLE `mail_msg`;");
					if($res['file'])
						@unlink('../files/pochta/' . $row['file']);
				}
				elseif(empty($res['delete']))
					mysql_query("UPDATE `mail_msg` SET  `delete` = '" . $user_id . "' WHERE `id`='".$res['id']."' AND `delete`='' AND `id_user`='" . $user_id . "' OR `id`='".$res['id']."' AND `delete`='' AND `id_kont`='" . $user_id . "';");
			}
			unset($_SESSION['dc']);
			Header('Location: index.php?act=out');
			exit;
		}
		else {
			if (empty ($_POST['delmes'])) {
				echo '<div class="rmenu">Вы ничего не выбрали для удаления<br/>
				<a href="'.$home.'/pochta/index.php?act=out">Назад</a></div>';
			}
			else {
				foreach ($_POST['delmes'] as $v) {
					$dc[] = abs(intval($v));
				}
				$_SESSION['dc'] = $dc;
				$_SESSION['prd'] = htmlspecialchars(getenv("HTTP_REFERER"));
				echo '<div class="rmenu">Вы уверены в удалении постов?<br/><a href="'.$home.'/pochta/index.php?act=massout&amp;yes">Да</a> | <a href="'.$home.'/pochta/index.php?act=out">Нет</a></div>';
			}
		}
?>