<?php
//set_time_limit(5);
error_reporting(0);
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
date_default_timezone_set('Asia/Ho_Chi_Minh');
$limit_page = 50;
include_once('SQL_jni.php');
$config['coder']['id']['event'] = null;
// Setting Website !
$config['DB']['CoBan']['TenTienTe'] = ' VNĐ';
$config['DB']['CoBan']['TenTienTe1'] = ' Coin';
$config['site']['Seo'] = 'Kiếm Tiên Mobile - Phiên bản 40 Phái';
$config['site']['KeyNap'] = 'KT';
$config['site']['Domain'] = 'KIEMTIENMOBILE.NET';
$config['site']['url']       = 'http://id.kiemtienmobile.net/';
$config['site']['fanepage']  = 'https://www.facebook.com/volamtrungnguyenmobile';
$config['site']['group']     = 'https://www.facebook.com/groups/volamtrungnguyenmobi/';
$config['site']['LinkShare'] = 'https://www.facebook.com/groups/volamtrungnguyenmobi/';
$servername = "localhost";
$username = "hmsogcqqhosting_duyanh";
$password = "3sqStRTwYFvL";
$dbname = "hmsogcqqhosting_web";
/* Link tải */
$config['site']['android'] = array(
    1 => array(
	"Title" => "Android <=10",
	"URL" => "https://install.appcenter.ms/users/jxonline/apps/volamthienvuong.com/distribution_groups/0908"),
    2 => array(
	"Title" => "Android >=11",
	"URL" => "https://install.appcenter.ms/users/jxonline/apps/volamthienvuong.com/distribution_groups/0908"),
);
$config['site']['ios'] = array(
    1 => array(
	"Title" => "IOS Thường",
	"URL" => "https://iosvip.vn/Apps/volamtuvi"),
    2 => array(
	"Title" => "IOS Tải Nhanh",
	"URL" => "https://iosvip.vn/Apps/volamtuvi"),
);
$config['site']['pay']['sale'] = 1;

/* CONFIG 1 SỐ THỨ */
$confog['Money']['VCB']['HOVATEN'] = '';
$confog['Money']['VCB']['STK'] = '';
$confog['Money']['VCB']['TENNGANHANG'] = 'Ngân Hàng Quốc Tế VIB';
$confog['Money']['VCB']['IMGNGANHANG'] = 'bank.png';
/* MM */
$confog['Money']['MM']['HOVATEN'] = '';
$confog['Money']['MM']['PHONE'] = '';
$confog['Money']['MM']['TENNGANHANG'] = 'Ví Điện Tử MoMo';
$confog['Money']['MM']['IMGNGANHANG'] = 'momo.jpg';
/* tạo chuyển trang */
if (isset($_REQUEST['url']))
{
    $_SESSION['url'] = $_REQUEST['url'];
}

// Create connection ===> jx_gw_branch
$conn = @mysqli_connect($servername, $username, $password, $dbname);
if ($conn->connect_error)
{
    die("Connection failed: " . $conn->connect_error);
}
function sw_get_current_weekday()
{
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    $weekday = date("l");
    $weekday = strtolower($weekday);
    switch ($weekday)
    {
        case 'monday':
            $weekday = 'Thứ hai';
            $weekdaynumber = 7;
        break;
        case 'tuesday':
            $weekday = 'Thứ ba';
            $weekdaynumber = 1;
        break;
        case 'wednesday':
            $weekday = 'Thứ tư';
            $weekdaynumber = 2;
        break;
        case 'thursday':
            $weekday = 'Thứ năm';
            $weekdaynumber = 3;
        break;
        case 'friday':
            $weekday = 'Thứ sáu';
            $weekdaynumber = 4;
        break;
        case 'saturday':
            $weekday = 'Thứ bảy';
            $weekdaynumber = 5;
        break;
        default:
            $weekday = 'Chủ nhật';
            $weekdaynumber = 6;
        break;
    }
    return $weekdaynumber;
}

function ItemList(){
	$return = array(
	"Amulet" => array("Phù","SettingList/Item/Equip/"),
	"Armor" => array("Áo","SettingList/Item/Equip/"),
	"Belt" => array("Đai","SettingList/Item/Equip/"),
	"Boots" => array("Giày","SettingList/Item/Equip/"),
	"Cuff" => array("Hộ Quyển","SettingList/Item/Equip/"),
	"Footmark" => array("Đế Chân","SettingList/Item/Equip/"),
	"Helm" => array("Đầu","SettingList/Item/Equip/"),
	"Horse" => array("Thú Cưỡi","SettingList/Item/Equip/"),
	"HorseEquip" => array("Trang Bị Thú Cưỡi","SettingList/Item/Equip/"),
	"Mantle" => array("Phi Phong","SettingList/Item/Equip/"),
	"Necklace" => array("Dây Chuyền","SettingList/Item/Equip/"),
	"NeiDan" => array("Nội Đan","SettingList/Item/Equip/"),
	"Pendant" => array("Ngọc Bội","SettingList/Item/Equip/"),
	"Ring" => array("Nhẫn","SettingList/Item/Equip/"),
	"WaiYi" => array("Ngoại Trang Áo","SettingList/Item/Equip/"),
	"Weapon" => array("Vũ Khí","SettingList/Item/Equip/"),
	"FaceEffect" => array("Hiệu Ứng Khuôn Mặt","SettingList/Item/Equip/"),
	"BackShow" => array("Ngoại Trang Lưng","SettingList/Item/Equip/"),
	"Faceshow" => array("Gương Mặt","SettingList/Item/Equip/"),
	"HelmShow" => array("Ngoại Trang Đầu","SettingList/Item/Equip/"),	
	"HorseShow" => array("Ngoại Trang Thú Cưỡi","SettingList/Item/Equip/"),	
	"MantleShow" => array("Ngoại Trang Phi Phong","SettingList/Item/Equip/"),	
	"WeaponShow" => array("Ngoại Trang Vũ Khí","SettingList/Item/Equip/"),
	"EnchantItem" => array("Phụ ma thạch","SettingList/Item/Other/"),
	"EnhanceItem" => array("Bí Bảo-Thủy Tinh","SettingList/Item/Other/"),
	"PartnerWeapon" => array("Vũ khí Đồng hành","SettingList/Item/Other/"),
	"PartnerSkillBook" => array("Skill Đồng hành","SettingList/Item/Other/"),
	"PartnerItem" => array("Đồng hành","SettingList/Item/Other/"),
	"Partner_equip" => array("Trang bị đồng hành","SettingList/Item/Other/"),
	"Partner_piece" => array("Mảnh đồng hành","SettingList/Item/Other/"),
	"Inscription" => array("Minh văn","SettingList/Item/Other/"),
	"FurnitureItem" => array("Gia cụ Gia Viên","SettingList/Item/Other/"),
	"Stone" => array("Đá Hồn","SettingList/Item/Other/"),
	"JueXueMiJi" => array("Mảnh Tuyệt Học","SettingList/Item/JueXue/"),
	"UnidentifyItem" => array("Tuyệt Học","SettingList/Item/Other/"),
	"SeriesStone" => array("Ngũ Hành","SettingList/Item/Other/"),
	"GuestItem" => array("Đồ Môn Khách","SettingList/Item/Other/"),
	"ScriptItem" => array("Khác","SettingList/Item/Other/"),
	"WonderSkillBook" => array("Skill Thứ 5","SettingList/Item/Other/"),
	);
	return $return;
}
// cover utf 8
mysqli_query($conn, "SET NAMES 'utf8'");
if (isset($_SESSION['UserName']))
{
    $INFOGoc = mysqli_fetch_array(mysqli_query($conn, "Select * From account_web WHERE Account = '" . $_SESSION['UserName'] . "'") , MYSQLI_ASSOC);
    $INFO = mysqli_fetch_array(mysqli_query($conn, "Select * From account_web_money WHERE Account = '" . $_SESSION['UserName'] . "' and ServerID = '".$_SESSION['ServerID']."'") , MYSQLI_ASSOC);
	$month = date('m');						
    $INFOSV = mysqli_fetch_array(mysqli_query($conn, "Select * From config_server WHERE ServerID = '".$_SESSION['ServerID']."'") , MYSQLI_ASSOC);
    // Logs
    $QueryDefault = "Select Sum(MoneyDefault)MoneyDefault From logscard WHERE UserName = '" . $_SESSION['UserName'] . "' and Server = '".$_SESSION['ServerID']."' and Active = '1' and";
    $ThoigianNew = date('d-m-Y').' 00:00:00';
    $ThoigianNewA = date('d-m-Y').' 00:00:00';
    switch (sw_get_current_weekday())
    {
        case 1:
            $ThoiGian_LogsCard = "-1 days";
            $ThoiGian_LogsCardA = "+6 days";
            
        break;
        case 2:
            $ThoiGian_LogsCard = "-2 days";
            $ThoiGian_LogsCardA = "+5 days";
            
        break;
        case 3:
            $ThoiGian_LogsCard = "-3 days";
            $ThoiGian_LogsCardA = "+4 days";
            
        break;
        case 4:
            $ThoiGian_LogsCard = "-4 days";
            $ThoiGian_LogsCardA = "+3 days";
        break;
        case 5:
            $ThoiGian_LogsCard = "-5 days";
            $ThoiGian_LogsCardA = "+2 days";
        break;
        case 6:
            $ThoiGian_LogsCard = "-6 days";
            $ThoiGian_LogsCardA = "+1 days";
        break;
        case 7:
            $ThoiGian_LogsCard = "+0 days";
            $ThoiGian_LogsCardA = "+6 days";
        break;
    }
   // $QueryLogsCard = $QueryDefault . " Timer >= '" . strtotime("-" . sw_get_current_weekday()-2 . " days", strtotime(date('d-m-Y'))) . "' and Timer < '" . strtotime("+" . $ThoiGian_LogsCard . " days", strtotime(date('d-m-Y'))) . "'";
   $QueryLogsCardA = "Timer >= '" . strtotime($ThoiGian_LogsCard,strtotime(date('d-m-Y'))) . "' and Timer <= '" . strtotime($ThoiGian_LogsCardA,strtotime(date('d-m-Y'))) . "'";
   $QueryLogsCard = $QueryDefault." ".$QueryLogsCardA;

}
function LayNgayTuan()
{
    if (date('d') >= 1 and date('d') <= 7)
    {
        return 1;
    }
    else if (date('d') > 7 and date('d') <= 13)
    {
        return 2;
    }
    else if (date('d') >= 14 and date('d') <= 21)
    {
        return 3;
    }
    else if (date('d') > 21 and date('d') <= 31)
    {
        return 4;
    }
}
function text_serialize($data, $text)
{
    $phantich = explode($text . '=', $data);
    $ketqua = explode('&', $phantich[1]);
    return $ketqua[0];
}
class php_cache{
    //相对或者绝对目录，末尾不要加 '/'
	
    var $cache_dir = '../config/cache';
    var $cache_extension = '.name_file_cache.ini';
	function get_client_ip()
{
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if (isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if (isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if (isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR'];
    else $ipaddress = 'UNKNOWN';
    return $ipaddress;
}
    function set_cache($name, $cache){
        $cache_file = $this->cache_dir. '/' .$name . $this->cache_extension;
 
        if($fp = @fopen($cache_file, 'w+')) {
            fwrite($fp, $cache);
            fclose($fp);
            return true;
        } else {
            //echo $cache_file;
            //exit('Can not write to cache files, please check cache directory ');
            return false;
        }
    }
    function read_cache(){
        return file_get_contents($this->cache_dir.'/'.md5($this->get_client_ip()).$this->cache_extension);
    }
    function check_file(){
    $filename = $this->cache_dir.'/'.md5($this->get_client_ip()).$this->cache_extension;
if (file_exists($filename)){
    return 1;
}else{
   return 0;
}		
	}
}
function get_client_ip()
{
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if (isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if (isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if (isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR'];
    else $ipaddress = 'UNKNOWN';
    return $ipaddress;
}
//check vòng quay may mắn
function check_wheel($percent)
{
    if ($percent < 2) return false;
    if ($percent >= 100) return true;
    $array_number = array();
    //tạo mảng
    for ($i = 0;$i < 100;$i++)
    {
        array_push($array_number, $i);
    }
    //lấy ra $percent số ngẫu nhiên
    $random_array = array_rand($array_number, $percent);
    //check
    if (in_array(rand(0, 99) , $random_array)) return true;
    else return false;
    return false;
}
// auto check code
function CheckCode_IS($serverid, $IDChar, $account, $idevent, $itemCheck)
{
    global $conn;
    //	$pc = new php_cache;
    //$timerSet = $pc->read_cache();
    $get_Server_CheckCode = mysqli_query($conn, "Select * From config_server WHERE ServerID = '$serverid'");
    if (mysqli_num_rows($get_Server_CheckCode))
    {

        $get_ServerCheckCode = mysqli_fetch_array($get_Server_CheckCode, MYSQLI_ASSOC);
        $get_Code_ITEM = mysqli_query($conn, "Select * From giftcode_item WHERE IDEvent = '$idevent'");
        $listitem;
        if (mysqli_num_rows($get_Code_ITEM))
        {
            while ($row = mysqli_fetch_array($get_Code_ITEM, MYSQLI_ASSOC))
            {
                if ($row['Item_Text'])
                {
                    $listitem .= $row['Item_Text'] . ',' . $row['Count_B'] . '%3B';
                }
                else
                {
                    $listitem .= 'item,' . $row['ItemID'] . ',' . $row['Count_A'] . '%3B';
                }
            }
            $listitem .= '-CanXoa-';
            $item = str_replace('%3B-CanXoa-', '', $listitem);
        }
        // khác lạ
        if (md5($item) != $itemCheck)
        {
            mysqli_query($conn, "UPDATE account_web Set Block = 1 WHERE Account = '$account'"); // khóa nick
            // kích nhân vật
            $chuoititle = json_encode(array(
                'type' => "4"
            ));
            $url = "http://" . $get_ServerCheckCode["IpJson"] . ":" . $get_ServerCheckCode['PortJson'] . "/efunsendreward?userId=1&roleId=$IDChar&serverCode=$serverid&title=$chuoititle&content=" . urlencode("Làm Người Ai Làm Thế, Haizzz");
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_URL, $url);
            $output = curl_exec($ch);
            curl_close($ch);
            //save logs
            $myfile = fopen("../../config/cache/" . $serverid . '_' . '_' . $IDChar . '_' . $account . '_' . strtotime(date('d/m/Y H:i:s')) . ".txt", "w+") or die("Unable to open file!");
            fwrite($myfile, "[Tạm Khóa]\n
				Lý Do : Nhận phần thưởng GIFTCODE không giống với hệ Thống.\n
				Ngày Ban : " . date('d/m/Y H:i:s') . "\n
				============[Thông Tin Nhân vật]=============\n
				Máy Chủ : $serverid [" . $get_ServerCheckCode['ServerName'] . "]\n
				Tài Khoản : $account\n
				ID Đặc Quyền : $IDChar\n
				CODE ID EVENT : $idevent\n
				MD5 SEND: $itemCheck
				MD5 CHECK: " . md5($item) . " \n");
        }
    }
}
function setting_wheel($tpye)
{
    switch ($type)
    {
        case 1:
            return 2;
        break;
        case 2:
            return 5;
        break;
        case 3:
            return 80;
        break;
        case 4:
            return 50;
        break;
        case 5:
            return 10;
        break;
        case 6:
            return 10;
        break;
        case 7:
            return 10;
        break;
        case 8:
            return 80;
        break;
        default:
            return 70;
        break;

    }
}
function info_wheel($type)
{
    $wheel = array();
    //26, 88, 137, 185, 235, 287, 337
    switch ($type)
    {
        case 1:
            $wheel['msg'] = 'Đá Hồn lv4 Ngẫu Nhiên';
            $wheel['angles'] = 360;
            $wheel['item'] = 'item,2169,1';
        break;
        case 2:
            $wheel['msg'] = '1000 Ngân Sức';
            $wheel['angles'] = 320;
            $wheel['item'] = 'SilverBoard,1000';
        break;
        case 3:
            $wheel['msg'] = '100 Ngân Sức';
            $wheel['angles'] = 270;
            $wheel['item'] = 'SilverBoard,100';
        break;
        case 4:
            $wheel['msg'] = 'Ngẫu nhiên';
            $wheel['angles'] = 600;
            $wheel['item'] = 'SilverBoard,1';
        break;
        case 5:
            $wheel['msg'] = 'x10 Tùy Hầu Châu';
            $wheel['angles'] = 400;
            $wheel['item'] = 'SilverBoard,250';
        break;
        case 6:
            $wheel['msg'] = '500 Ngân Sức';
            $wheel['angles'] = 130;
            $wheel['item'] = 'SilverBoard,500';
        break;
        case 7:
            $wheel['msg'] = 'x10 Hòa Thị Bích';
            $wheel['angles'] = 790;
            $wheel['item'] = 'item,2804,10';
        break;
        case 8:
            $wheel['msg'] = 'x10 Tùy hầu châu';
            $wheel['angles'] = 525;
            $wheel['item'] = 'item,10014,10';
        break;
        default:
            $wheel['msg'] = '1 Ngân Sức :))';
            $wheel['angles'] = 600;
            $wheel['item'] = 'SilverBoard,1';
        break;

    }
    return $wheel;
}
function is_mobile()
{
    if (empty($_SERVER['HTTP_USER_AGENT']))
    {
        $is_mobile = false;
    }
    elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
     || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false)
    {
        $is_mobile = true;
    }
    else
    {
        $is_mobile = false;
    }
    return $is_mobile;
}
function randomtime()
{
    $rand = rand(1111111111, 9999999999);
    $ttime = time() - $rand;
    return $ttime;
}
function RequestServer($server, $data)
{
	global $conn;
        $get_Server = mysqli_query($conn, "Select * From config_server WHERE ServerID = '$server'");
        if (!mysqli_num_rows($get_Server)) {
            return 'Lấy thông tin Máy chủ thất bại.';
        }
        $get_Server = mysqli_fetch_array($get_Server, MYSQLI_ASSOC);

    $dataPost = http_build_query($data);
    $url = "http://" . $get_Server['IpJson'] . ":" . $get_Server['PortJson'] . "/efunsendreward";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $dataPost);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    $reset = json_decode($result);
    return $reset;
}
function CallAPIGame($server, $ip, $port, $nvid, $hash)
{
    $pud = randomtime();
    $chuoititle = json_encode(array(
        'type' => $hash
    )); // là do sai type send mail
    // set item{
    $data = array(
        "userId" => 1,
        "roleId" => $nvid,
        "serverCode" => $server,
        "title" => $chuoititle
    );
    $dataPost = http_build_query($data);
    $url = "http://" . $ip . ":" . $port . "/efunsendreward";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $dataPost);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    $reset = json_decode($result);
    if ($reset->code == 0)
    {
        return $reset->nKinId;
    }
    else
    {
        return '-0';
    }
}
function sendMailGame($item, $title, $nvid, $server, $ip, $port)
{
    $pud = randomtime();

    // set item{
    $data = array(
        "userId" => 1,
        "roleId" => $nvid,
        "serverCode" => $server,
        "serialNo" => $pud,
        "packageId" => $item,
        "title" => "BBCCAACCMMAKK",
        "content" => $title
    );
    $dataPost = http_build_query($data);
    $url = "http://" . $ip . ":" . $port . "/efunsendreward";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $dataPost);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    $reset = json_decode($result);
    if ($reset->code == 1000)
    {
        return 0;
    }
    else
    {
        if ($reset->message == 'serialNo Repeated!')
        {
            return "Vui lòng thử lại sau";
        }
        else
        {
            return "Không xác định được lỗi";
        }
    }
}

function nameCardType($id)
{
    switch ($id)
    {
        case 1:
        case "VTT":
            return 'Viettel';
        break;

        case 3:
        case "VNP":
            return 'Vinaphone';
        break;

        case 2:
        case "VMS":
            return 'Mobifone';
        break;

        case 4:
            return 'Gate';
        break;
        case 'VCB':
            return 'VietComBank';
        break;
        case 'MoMo':
            return 'Ví Điện Tử MoMo';
        break;

        default:
            return 'Không xác định';
        break;
    }
}

// gettttttttttt
function getnameItem($itemid)
{
    global $servername;
    global $username;
    global $password;
    global $dbname;

    // Create connection ===> jx_ws01_branch
    $conn = @mysqli_connect($servername, $username, $password, $dbname);
    if ($conn->mysqli_connect_errno)
    {
        return "Connection failed char: " . $conn->mysqli_connect_errno;
    }

    mysqli_query($conn, "SET NAMES 'utf8'");
    $getchar = mysqli_query($conn, "Select Name From item_goods WHERE ItemID = '$itemid'");
    if (mysqli_num_rows($getchar))
    {
        $ok_getchar = mysqli_fetch_array($getchar, MYSQLI_ASSOC);
        return $ok_getchar['Name'];
    }
    else
    {
        return '.....';
    }
}
function getListServer()
{
    global $servername;
    global $username;
    global $password;
    global $dbname;

    // Create connection ===> jx_ws01_branch
    $conn = @mysqli_connect($servername, $username, $password, $dbname);
    if ($conn->mysqli_connect_errno)
    {
        return "Connection failed char: " . $conn->mysqli_connect_errno;
    }

    mysqli_query($conn, "SET NAMES 'utf8'");
    $getchar = mysqli_query($conn, "Select ServerID,ServerName From config_server");
    if (mysqli_num_rows($getchar))
    {
		while($row = mysqli_fetch_assoc($getchar)){
			$listsv .= '<option value="'.$row['ServerID'].'">'.$row['ServerName'].'</option>';
		}
        return $listsv;
    }
    else
    {
        return '';
    }
}
function getServerName($sv)
{
    if ($sv == 0)
    {
        return 'Tất Cả';
    }
    global $servername;
    global $username;
    global $password;
    global $dbname;

    // Create connection ===> jx_ws01_branch
    $conn = @mysqli_connect($servername, $username, $password, $dbname);
    if ($conn->mysqli_connect_errno)
    {
        return "Connection failed char: " . $conn->mysqli_connect_errno;
    }

    mysqli_query($conn, "SET NAMES 'utf8'");
    $ok_getsv = mysqli_query($conn, "Select * From config_server WHERE ServerID = '$sv'");
    if (mysqli_num_rows($ok_getsv))
    {
        $ok_getsv = mysqli_fetch_array($ok_getsv, MYSQLI_ASSOC);
        return $ok_getsv['ServerName'];
    }
    else
    {
        return '.....';
    }
}

function getNameChar($sv, $char)
{
    global $servername;
    global $username;
    global $password;
    global $dbname;

    // Create connection ===> jx_ws01_branch
    $conn = @mysqli_connect($servername, $username, $password, $dbname);
    if ($conn->mysqli_connect_errno)
    {
        return "Connection failed char: " . $conn->mysqli_connect_errno;
    }

    mysqli_query($conn, "SET NAMES 'utf8'");
    $ok_getsv = mysqli_query($conn, "Select * From config_server WHERE ServerID = '$sv'");
    if (mysqli_num_rows($ok_getsv))
    {
        $ok_getsv = mysqli_fetch_array($ok_getsv, MYSQLI_ASSOC);
        $conn_char = @mysqli_connect('14.225.253.250', 'root', 'Tinhdang9x!@#', $ok_getsv['Databases']);
        if ($conn_char->mysqli_connect_errno)
        {
            die("Connection failed: " . $conn_char->mysqli_connect_errno);
        }

        mysqli_query($conn_char, "SET NAMES 'utf8'");
        $get_char = mysqli_query($conn_char, "Select PlayerName From Player WHERE ID = '$char'");
        if (!mysqli_num_rows($get_char))
        {
            return '<font color="red">Chưa chọn</font>';
        }

        $get_char = mysqli_fetch_array($get_char);
        return $get_char['PlayerName'];
    }
    else
    {
        return '.....';
    }
}
function getnameText($string)
{
    switch ($string)
    {
        case 'Gold':
            return 'Vàng';
        break;

        case 'Coin':
            return 'Bạc';
        break;

        case 'VipExp':
            return 'EXP VIP';
        break;

        case 'Exp':
            return 'Kinh Nghiệm';
        break;

        case 'Honor':
            return 'Vinh Dự';
        break;
		
		case 'MoonStone':
            return 'Nguyệt Ảnh Thạch';
        break;

        case 'Contrib':
            return 'Cống Hiến';
        break;

        case 'Renown':
            return 'Danh Vọng';
        break;

        case 'Energy':
            return 'Nguyên Khí';
        break;

        case 'SilverBoard':
            return 'Ngân Sức';
        break;
		
		case 'DarkSteel':
            return 'Trảm Liệt Thần Thạch';
        break;
		case 'LinhThach':
            return 'Coin';
        break;
		case 'TienThat':
            return 'Xu Sv';
        break;

        default:
            return $string;
        break;
    }
}
function getIP()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
    
    {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    // to check ip is pass from proxy
    
    {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
        $ip = $_SERVER['REMOTE_ADDR'];
    }

    return $ip;
}
function checkTelco($phonenumber)
{
    if (strlen($phonenumber) == 10)
    {
        $phoneSplit = substr($phonenumber, 0, 3);
    }
    elseif (strlen($phonenumber) == 11)
    {
        $phoneSplit = substr($phonenumber, 0, 4);
    }
    else
    {
        return false;
    }

    // echo $phoneSplit;
    // check telco
    switch ($phoneSplit)
    {
        case "090":
        case "093":
        case "0120":
        case "0121":
        case "0122":
        case "0126":
        case "0128":
            return "Mobifone";
        break;

        case '096':
        case '097':
        case '098':
        case '0163':
        case '0164':
        case '0165':
        case '0166':
        case '0167':
        case '0168':
        case '0169':
            return "Viettel";
        break;

        case '091':
        case '094':
        case '0123':
        case '0124':
        case '0125':
        case '0127':
        case '0129':
            return "Vinaphone";
        break;

        case "092":
        case "0188":
            return "Vietnamobile";
        break;

        case "095":
            return "Sfone";
        break;

        case "0993":
        case "0994":
        case "0995":
        case "0996":
        case "0199":
            return "Gmobile";
        break;

        default:
            return false;
        break;
    }
}

function mysubstr($str, $limit = 100)
{
    if (strlen($str) <= $limit) return $str;
    return mb_substr($str, 0, $limit - 3, 'UTF-8') . '***';
}

function rand_string($length)
{
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $size = strlen($chars);
    for ($i = 0;$i < $length;$i++)
    {
        $str .= $chars[rand(0, $size - 1) ];
    }

    return $str;
}

