<?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)) {
    die('Lấy thông tin Máy chủ thất bại.');
}
$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) {
    die("Connection failed: " . $conn_char->mysqli_connect_errno);
}
mysqli_query($conn_char, "SET NAMES 'utf8'");
/* ------------------------------------------- CONNECT CHAR SV ------------------------------- */
if ($_POST['action'] == "closeActivity" or $_POST['action'] == "reloadActivty") {
    if (!$_POST['nameActivity']) {
        die('Vui lòng nhập nội dung.');
    }
    $connte = 'content=' . urlencode($_POST['nameActivity']) . '&';
}

$chuoititle = json_encode(array(
    "type" =>  $_POST['action']
));
$url        = "http://" . $get_Server['IpJson'] . ":" . $get_Server['PortJson'] . "/efunsendreward?".$connte."serverCode=" . $get_Server['ServerID'] . "&title=" . $chuoititle;
$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'] == 0) {
    die('0');
} else {
    die('Có lỗi hãy thử lại');
}
