<?php
include 'common.php';


function GetNews($lang)
{
	$dbhandle = DB_Connect();
	//Select DB
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
	or die("Could not select db");



	mysqli_query($dbhandle,"set session character_set_connection=utf8;");
	mysqli_query($dbhandle,"set session character_set_results=utf8;");
	mysqli_query($dbhandle,"set session character_set_client=utf8;");

	
	$stmt = $dbhandle->prepare("select count(*) as cnt, title, content, title_en, content_en from news where open=1");	
	//$stmt->bind_param("ss", $account_id, $login_time);
	$stmt->execute();
	$result = $stmt->get_result();
	$row = $result->fetch_assoc();
	
	mysqli_stmt_free_result($stmt);
	
	$news = false;    //공지사항 있음
	if($row["cnt"] > 0)
	{
		$news = true;
	}
			
	

	if ($news == true)
	{
		$response = "NEWS";
		$title = $row["title_en"];
		$notice = $row["content_en"];
			
		
		if ($lang == "kr")
		{			
			$title = $row["title"];
			$notice = $row["content"];
	
			//$title = "이벤트 공지사항";
			//$notice = "한국시간(UTC+9) 2020-11-09 00시 부터  2020-11-15 까지 매일 로그인시 크리스탈 150개씩 지급합니다.\n\n- 추가로 2020-11-10 00시부터 2020-11-15 까지 매일 HP포션 200개씩 지급합니다. \n\n- 2011-11-10 00시부터 1시간 접속 장애로 불편을 드려 죄송합니다. 보상으로 HP포션 300개추가 지급합니다.";
		}	

		$isXmlHttpRequest = (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) ?
		(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false: false;
		($isXmlHttpRequest) ? header('Content-type: application/json') : header('Content-type: text/plain');

		echo json_encode(array('result'=>$response,'title'=>$title,'notice'=>$notice));
	}
}

$lang = $_GET['lang'];
$version = $_GET['version'];
$char_uid = $_GET['char_uid'];
$user_id = $_GET['user_id'];

GetNews($lang);


?>