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

// check
	if (!$_POST['mf_no']){
		msg('올바른 URL로 접근하여 주십시오');
	}

// data
	// set data
	$q = "SELECT count(*) as cnt  FROM " . $TB['MAIL_STAR'] . " WHERE ms_m_no ='". $AUTH['auth_m_no'] . "' AND ms_mf_no = '" . $_POST['mf_no'] . "'";
	$mail_star_cnt = db_get_one($q);

	$message = null;
	$error = true;
	if ($mail_star_cnt > 0){
		$sql = "DELETE FROM " . $TB['MAIL_STAR'] . " WHERE ms_m_no ='". $AUTH['auth_m_no'] . "' AND ms_mf_no = '" . $_POST['mf_no'] . "'";
		$error = db_query($sql);
		$message = "중요 메일을 해제하였습니다.";
	} else {
		$created_at = date("Y-m-d H:i:s");
		$sql = "INSERT INTO ".$TB['MAIL_STAR']." (id, ms_m_no, ms_mf_no, created_at) VALUES (" . db_sqc_next($TB['MAIL_STAR']) . ", '". $AUTH['auth_m_no'] . "', '".$_POST['mf_no']."', '" . $created_at . "')";
		$error = db_query($sql);
		$message = "중요 메일로 지정하였습니다.";
	}

	if ($error === false) {
		$message = '서버 장애로 요청하신 작업이 실패하였습니다';
	}

	echo response_json(array(
		'success' => $error,
		'message' => $message,
	));

	exit;


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