<?
require_once('include/global.php');
require_once('include/mail_lib.php');
require_once('include/file.php');


// check
	if (!$_GET['mrc_no'] && !$_GET['m_no'])
		msg('올바른 URL로 접근하여 주십시오');

	if ($_GET['isadmin'])
	{
		auth_limit('admin');
		$_GET['d_no'] = $G['DINFO']['d_no'];
		$d_no = $_GET['d_no'];
	} else
	{
		auth_limit('serveradmin');
		$d_no = $_GET['d_no'];
	}	// if()

// data
	$q = "
		SELECT
			mrc.*, m.m_id, m.m_mail_file_group
		FROM
			" . $TB['MAIL_RECEIVE_CHECK'] . " mrc
			LEFT JOIN " . $TB['MEMBER'] . " m ON m.m_no = mrc.m_no
			LEFT JOIN " . $TB['DOMAIN'] . " d ON d.d_no = m.d_no
		WHERE
			mrc.m_no='". $_GET['m_no'] . "'
			AND mrc.mrc_no='". $_GET['mrc_no'] . "'
			AND d.d_no='". $d_no ."'
		";
	$row = db_get_row($q);
	if (!$row)
		msg('존재하지 않는 예약내역입니다.');

	if ($row['mrc_reserve_status'] != 'W')
		msg('이미 발송되었므로, 취소할 수 없습니다.');

	$mails_dir = $UPLOAD_ROOT. '/' . 'mailreserve/' . $G_SYS[MAIL_DOMAIN] . '/' . $row['m_mail_file_group'] . '/' . $row['m_id'];
	$file = 'Reserve.'.$row['mrc_no'].'.eml';

	if (file_exists($mails_dir.'/'.$file))
	{
		unlink($mails_dir.'/'.$file);

		$q = "DELETE FROM ".$TB['MAIL_RECEIVE_CHECK']." WHERE mrc_no='".$row['mrc_no']."' AND m_no='" . $AUTH['auth_m_no'] . "'";
		db_query($q);
	} else
	{
		msg('이미 발송되었므로, 취소할 수 없습니다.');
	}	// if()


// end
	msg("예약발송이 취소되었습니다.", 0);
	movepage('admin_mail_send_reserve.php?'.get_qs('mrc_no'));

require_once('include/global_end.php');
?>