<?php
session_start();
include_once('../../config/#Config.php');
if(!$_SESSION['UserName']){
die('<script>window.location.href=\''.$config['site']['url'].'index.php\';</script>');
} else {
$get_AD = mysqli_query($conn, "Select * From config_admin WHERE Account = '".$_SESSION['UserName']."'");
if(!mysqli_num_rows($get_AD)){
	die('Không đủ quyền.');
}
$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 tồn tại hay không
	$get_check = mysqli_query($conn, "Select * From account_web WHERE Account = '".$_REQUEST['user']."'");
	if(mysqli_num_rows($get_check)){
	$get_check = mysqli_fetch_array($get_check, MYSQLI_ASSOC);
	$money = 0;
	if($_REQUEST['money']){
		$money = $_REQUEST['money'];
	}
	$TienThat = 0;
	if($_REQUEST['TienThat']){
		$TienThat = $_REQUEST['TienThat'];
	}
	$calc = $_REQUEST['calc'];
	if($calc == 1) $toantu = '+';
	elseif($calc == 2) $toantu = '-';
	if($money >0 or $TienThat > 0){
    mysqli_query($conn, "UPDATE account_web Set Money = Money + $money,TienThat = TienThat $toantu $TienThat WHERE Account = '".$_REQUEST['user']."'");		
	}
		if($_REQUEST['phone']){
			$sql = "Phone = N'".$_REQUEST['phone']."'";
			mysqli_query($conn, "UPDATE account_web Set $sql WHERE Account = '".$_REQUEST['user']."'");	
		}
		if($_REQUEST['email']){
			$sql = "Email = N'".$_REQUEST['email']."'";
			mysqli_query($conn, "UPDATE account_web Set $sql WHERE Account = '".$_REQUEST['user']."'");	
		}
	if($_REQUEST['pass']){
		$sql = "Password = '".md5($_REQUEST['pass'])."'";
			mysqli_query($conn, "UPDATE account_web Set $sql WHERE Account = '".$_REQUEST['user']."'");	
	}
   if($money > 0){
					mysqli_query($conn, "INSERT INTO logs_admin (UserName,Type,Messager,Timer) VALUES ('" . $_SESSION['UserName'] . "', '2', N'+ ".number_format($money)." Xu Web Cho S".$_REQUEST['sv']."-".$_REQUEST['user']."', '".strtotime(date('d-m-Y H:i:s'))."')");				            
   }
   if($TienThat > 0){
					mysqli_query($conn, "INSERT INTO logs_admin (UserName,Type,Messager,Timer) VALUES ('" . $_SESSION['UserName'] . "', '2', N'$toantu ".number_format($TienThat)." Xu Share Cho Tài Khoản ".$_REQUEST['sv']."-".$_REQUEST['user']."', '".strtotime(date('d-m-Y H:i:s'))."')");				            
   }
   if($_REQUEST['phone'] && $_REQUEST['phone'] != $get_check['Phone']){
					mysqli_query($conn, "INSERT INTO logs_admin (UserName,Type,Messager,Timer) VALUES ('" . $_SESSION['UserName'] . "', '2', N'Đổi Phone ".$_REQUEST['phone']." Cho ".$POST['user']."', '".strtotime(date('d-m-Y H:i:s'))."')");				            
   }
   if($_REQUEST['email'] && $_REQUEST['email']  != $get_check['Email']){
					mysqli_query($conn, "INSERT INTO logs_admin (UserName,Type,Messager,Timer) VALUES ('" . $_SESSION['UserName'] . "', '2', N'Đổi EMail ".$_REQUEST['email']." Cho ".$_REQUEST['user']."', '".strtotime(date('d-m-Y H:i:s'))."')");				            
   }
	$return['type'] = 0;
		$return['text'] = 'Thay Đổi Thành Công';
		echo json_encode($return);
		exit();
		} else {
		$return['type'] = 1;
		$return['text'] = 'Tài khoản này không tồn tại.';
		echo json_encode($return);
		exit();
	}
}

?>