<?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 ".($rights > 7 ? "":"`id_kont`='" . $user_id . "' AND ")."`id`='" . $delid . "' AND `spam`='2';"));
				if ($rights>=7 || (!empty($res['delete']) && $res['delete']!=$user_id)) {
					mysql_query("DELETE FROM `mail_msg` WHERE ".($rights > 7 ? "":"`id_kont`='" . $user_id . "' AND ")."`id`='" . $delid . "' AND `spam`='2' LIMIT 1;");
					mysql_query("OPTIMIZE TABLE `mail_msg`;");
					if($res['file'])
						@unlink('../files/pochta/' . $row['file']);
				} else if(empty($res['delete'])) {
					mysql_query("UPDATE `mail_msg` SET `delete`='" . $user_id . "' WHERE `id`='".$delid."' AND `id_kont`='" . $user_id . "' AND `spam`='2';");
				}
				/*
				$res = mysql_fetch_assoc(mysql_query("SELECT * FROM `mail_msg` WHERE ".($rights>=7?'`spam`=2 AND':'`id_user`='.$user_id.' AND `id`='.$delid.' AND `spam`=2 or `id_kont`='.$user_id.' AND `spam`=2 AND')." `id`='$delid';"));
				if ($rights>=7 || (!empty($res['delete']) && $res['delete']!=$user_id)) {
					mysql_query("DELETE FROM `mail_msg` WHERE ".($rights>=7?'`spam`=2 AND':'`id`='.$res['id'].' AND `id_user`='.$user_id.' AND `spam`=2 OR `id_kont`='.$user_id.' AND `spam`=2 AND')." `id`='{$res['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 `spam`='2' AND `id_user`='$user_id' OR `id`='{$res['id']}' AND `delete`='' AND `spam`='2' AND `id_kont`='$user_id';");
					*/
			}
			unset($_SESSION['dc']);
			Header('Location: index.php?act=spam');
			exit;
		}
		else {
			if (empty ($_POST['delmes'])) {
				echo '<div class="rmenu">Вы ничего не выбрали для удаления<br/>
				<a href="'.$home.'/pochta/index.php?act=spam">Назад</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=masspam&amp;yes">Да</a> | <a href="'.$home.'/pochta/index.php?act=spam">Нет</a></div>';
			}
		}
?>