<?php  session_start(); error_reporting(0); 
//if session
if(isset($_SESSION['j_admin'])){ }else{ 
    die(
    "
    <div class='alert alert-danger'> Error 100. Try again.</div>
    "
    );
}
require_once("../j_conn/url.php");
require_once("../j_conn/dbc.php");
require_once("../j_incs/functions.php");
if(isset($_POST['old_password'])){ }else{ 
die(
"
<div class='alert alert-danger'> Error 101. Try again.</div>
"
);
}
?>
<script>
$('.rMe').each(function() {
	 if ($(this).val() == "") {
 	   $(this).css({"border-color": "brown", 
		 "border-width":"1px", 
		 "border-style":"solid"});
	 }else{
		$(this).css({"border-color": "#efefef", 
		 "border-width":"1px", 
		 "border-style":"solid"});	 
	 }
});
</script>
<?php 
//
$old_password = RMC($_POST['old_password']); 
check_length ($old_password,"4","40","Password","old_password");
//

$old_password = base64_encode("$hash$old_password"); 
//check password
$sql4="SELECT count(*) as sum from j_users WHERE j_id='".$id."' AND j_password='".$old_password."' AND  j_blocked < 1 AND j_deleted < 1"; //check 
$result4 = runSQL($sql4);
$data4 = mysqli_fetch_array($result4);
$sum4 = $data4['sum'];
if($sum4 > 0){
}else{
    die("<div class='alert alert-danger'> Invalid Current Password. Try again.</div>
    <script> $('[name=old_password]').css({'border-color': 'brown', 'border-width':'1px', 'border-style':'solid'});</script>
    ");
}

$re_username = $_SESSION['re_username'];
$amount_btc = $_SESSION['amount_btc'];
$amount_eth = $_SESSION['amount_eth'];


if(empty($re_username)){ 
    die("<div class='alert alert-danger'> Please provide Recipient's Username. Try again.</div>
    <script> $('[name=re_username]').css({'border-color': 'brown', 'border-width':'1px', 'border-style':'solid'});</script>
    ");
}

//
$sql25="SELECT * from j_users WHERE 
j_username='".$re_username."' AND j_blocked < 1 AND j_deleted < 1  AND j_status < 1
|| j_email='".$re_username."' AND j_blocked < 1 AND j_deleted < 1  AND j_status < 1
|| j_phone='".$re_username."' AND j_blocked < 1 AND j_deleted < 1  AND j_status < 1
"; //  
$result25 = runSQL($sql25);
$data25 = mysqli_fetch_array($result25);
$re_id = $data25['j_id'];
$re_currency = $data25['j_currency'];
$re_wallet = $data25['j_wallet'];
$re_wallet_usd = $data25['j_wallet_usd'];
$re_wallet_btc = $data25['j_wallet_btc'];
$re_wallet_eth = $data25['j_wallet_eth'];
$re_wallet_ltc = $data25['j_wallet_ltc'];
$re_username = $data25['j_username'];
$re_passport = $data25['j_passport'];
$re_email = $data25['j_email'];
$re_phone = $data25['j_phone'];
$re_firstname = $data25['j_firstname'];
$re_lastname = $data25['j_lastname'];
$currency_in_use = $data25['j_currency']; $currency = $currency_in_use;
$re_name = "$re_firstname $re_lastname"; $re_name = trim($re_name);


if(empty($re_firstname)){ 
    die("<div class='alert alert-danger'> Invalid  Recipient's Username. Try another.</div>
    <script> $('[name=re_username]').css({'border-color': 'brown', 'border-width':'1px', 'border-style':'solid'});</script>
    ");
}
//
$sql = "UPDATE j_users SET
j_wallet_btc ='".$amount_btc."',
j_wallet_eth ='".$amount_eth."'
WHERE j_id='".$re_id."'";
$result = runSQL($sql);
if(!$result){
	die("Error. Code 103.");
}

//send a mail for user
$u_email = $company_email;
$u_subject ="WALLET UPDATE";
$u_subject_m ="WALLET UPDATE";
$u_message ="<p>Dear $company;</p> <p>$re_name's wallet balance has been updated. 
</p>";
$uu_message = $u_message;
require("../j_incs/mail.php");
//send notify
send_notify("",'1',$u_subject_m,$u_message);
?>
<script>
    $(".form_hide").hide();
    $("#form2").remove();
    $("#submit2").attr('disabled', '');
 </script>
<div class="card">
    <div class="card-body">
        <div class="container">
            <div class="row">
                 <div class="col-md-12" style="text-align:center;">
                    <div class="responseBox success">
                        <i class="anticon anticon-check"></i>
                    </div>
                     <p>
                        <?php echo $u_message; ?>
                         <?php /*Successful*/ ?>
                         <br/>
                    </p>
                    <a class="btn btn-primary m-b-20 m-r-20" href="<?php echo $dir; ?>users/"> Check user balance</a>
                 </div>
            </div>
        </div>
    </div>
</div>