<?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.');
}
$getinfo = mysqli_query($conn, "Select * From account_web WHERE Account = '".$_POST['user']."'");
?>        
<script>
    function LoadNhanVat(){
$.post('ajax/load_nhanvat.php', {user:'<?=$_POST['user']?>',sv:'<?=$_POST['sv']?>'},function(data){
$('#nhanvat').html(data);
});

    }
	LoadNhanVat();
    function LoadInfoNhanVat(){
        $.post('ajax/load_infogame.php', {user:'<?=$_POST['user']?>',nvid:$('#nhanvat').val(),sv:'<?=$_POST['sv']?>'}, function(data){
               $('#gold').val(data['Gold']);
               $('#money').val(data['Money']);
               $('#Contrib').val(data['Contrib']);
               $('#FightPower').val(data['FightPower']);
               $('#Lv').val(data['Lv']);
        },'json');
    }
</script>
        <!-- Modal body -->
		<?php if(mysqli_num_rows($getinfo)) { $info_get = mysqli_fetch_array($getinfo, MYSQLI_ASSOC); ?>

        <div class="modal-body">
		       <label>Chọn nhân vật</label>
            <div class="form-group pass_show"> 
            <select class="form-control" id="nhanvat" onChange="LoadInfoNhanVat();">
        </select>
            </div> 
            <div class="main-card mb-3 card">
                                            <div class="card-body"><h5 class="card-title">Thông Tin Game</h5>
											
                                                <div class="input-group">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-warning">Cấp Độ</button>
                                                        </div>
                                                        <input type="text" class="form-control" id="Lv" value="0" disabled>
                                                    </div>   
                                                    <br/>                                                   
                                                    <div class="input-group">
                                                        <div class="input-group-prepend">
                                                            <button class="btn btn-secondary">Bạc</button>
                                                        </div>
                                                        <input type="text" class="form-control" id="gold" value="0" disabled>
                                                    </div>
                                                    <br>
                                                    <div class="input-group">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-success">Kim Nguyên Bảo</button>
                                                        </div>
                                                        <input type="text" class="form-control" id="money" value="0" disabled>
                                                    </div>
                                                    <br>
                                                    <div class="input-group">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-info">Cống Hiến</button>
                                                        </div>
                                                        <input type="text" class="form-control" id="Contrib" value="0" disabled>
                                                    </div>
                                                    <br>       
                                                    <div class="input-group">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-secondary">Lực Chiến</button>
                                                        </div>
                                                        <input type="text" class="form-control" id="FightPower" value="0" disabled>
                                                    </div>                                                
                                                    <br>                                                                                               
                                                </div>
                                            </div>
                                        </div>
										            <div class="form-group pass_show"> 
				<input type="submit" class="btn btn-warning btn-block" value="Tab[Khóa Nhân Vật]" onClick="newTab('KhoaTaiKhoan')" style="witdh:150px;float:right"/>
				<input type="submit" class="btn btn-warning btn-block" value="Tab[Mở Khóa Nhân Vật]" onClick="newTab('MoTaiKhoan')" style="witdh:150px;float:right"/>
            </div>
            </div> 			
		<?php } else { echo 'Không tìm thấy thông tin tài khoản này.';} ?>			
        </div>
        
        <Script>
		function saveInfo(){
			$.post('ajax/ajax_infouser.php', {user:'<?=$_POST['user']?>',sv:'<?=$_POST['sv']?>',TienThat:$('#info_tieenthat').val(),calc:$('#calc').val(),pass:$('#info_pass').val(),email:$('#info_email').val(),phone:$('#info_phone').val(),money:$('#info_money').val()}, function(data){
		if(data['type'] == 0){
            toastr.success(data['text'], 'Thông Báo', {timeOut: 5000});			
		} else {
            toastr.info(data['text'], 'Lỗi', {timeOut: 5000});
			
        }
        return false;
	},'json');
		}
		function newTab(tab){
			if($('#nhanvat').val() == "" || $('#server').val() == "0"){
				            toastr.info('Bạn chưa chọn Máy Chủ hoặc Nhân vật.', 'Lỗi', {timeOut: 5000});
							return false;
			}
			if(tab == "KhoaTaiKhoan"){
				$.post('from/loadkichuser.php', {user:'<?=$_POST['user']?>',id:$('#nhanvat').val(),sv:'<?=$_POST['sv']?>'}, function(data){
$('#infoUserLogs').html(data);
});
			} else {
			$.post('from/loadkichuser1.php', {user:'<?=$_POST['user']?>',id:$('#nhanvat').val(),sv:'<?=$_POST['sv']?>'}, function(data){
				$('#infoUserLogs').html(data);
			});
			}
		}
		</script>