<?php
session_start();
include_once('../../config/#Config.php');
if (!$_SESSION['UserName']) {
die('<script>window.location.href=\''.$config['site']['url'].'index.php\';</script>');
}
$get_AD = mysqli_query($conn, "Select * From config_admin WHERE Account = '".$_SESSION['UserName']."'");
if(!mysqli_num_rows($get_AD)){
	die('Không đủ quyền.');
}
// check nhận vật
            // connect sv
            /* ------------------------------------------- CONNECT CHAR SV ------------------------------- */
            $get_Server = mysqli_query($conn, "Select * From config_server WHERE ServerID = '" . $_POST['sv'] . "'");
            if (!mysqli_num_rows($get_Server)) {
                $data['Text'] = 'Lấy thông tin Máy chủ thất bại.';
                echo json_encode($data);
                exit();
            }
            $get_Server = mysqli_fetch_array($get_Server, MYSQLI_ASSOC);
   $conn_char  = @mysqli_connect($get_Server['IPdata'], $get_Server['Userdata'], $get_Server['PassData'], $get_Server['Databases']);
            if ($conn_char->mysqli_connect_errno) {
                $data['Text'] = "Connection failed: " . $conn_char->mysqli_connect_errno;
                echo json_encode($data);
                exit();
            }
            mysqli_query($conn_char, "SET NAMES 'utf8'"); 			
            /* ------------------------------------------- CONNECT CHAR SV ------------------------------- */
            if(!$_POST['notice']){
				die('Vui lòng nhập nội dung.');
			}
			$chuoititle = json_encode(array('type' => "1"));
$url    = "http://" . $get_Server['IpJson'] . ":" . $get_Server['PortJson'] . "/efunsendreward?serverCode=".$get_Server['ServerID']."&title=$chuoititle&content=" . urlencode($_POST['notice']);
$ch     = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_TIMEOUT,1000);
$output = curl_exec($ch);
$reset  = json_decode($output);
if($reset['code'] == 1000){
   die('0');
} else {
   die('Gửi nội dung thất bại');
}