<?php  session_start(); error_reporting(0); 
//if session
if(isset($_SESSION['j_admin']) || 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": "#fafafa", 
		 "border-width":"0px", 
		 "border-style":"solid"});	 
	 }
});
</script>
<?php
$name_old = $name;
$phone_old = $phone;
$email_old = $email;
$username_old = $username;
$old_password = RMC($_POST["old_password"]); 
 if(!empty($old_password) 
 //&& !empty($file1_new)
 ){ //check if required field is not empty
}else{ die("<div class='alert alert-danger'> A required field is empty. Try again.</div>");}  

//hash 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>
    ");
}

//check if user has not transacted
$sql4="SELECT * from j_pays WHERE j_user_id='".$id."' AND j_deleted < 1 AND j_paid > 0 order by j_id desc limit 1"; //check 
$result4 = runSQL($sql4);
$total = mysqli_num_rows($result4);
if($total > 0 && !isset($_SESSION['j_admin_user'])){
	die(
	"
	<div class='alert alert-danger'> Sorry. You cannot edit your profile this time. Contact $company via email: <b>$company_email</b> or call: <b>$company_phone</b></div>
	"
	);
}

require_once("file1.php");
$u_passport = $filenames;
//
$sql = "UPDATE j_users SET
j_passport ='".$u_passport."'
WHERE j_id='".$id."' AND j_blocked < 1 AND j_deleted < 1
";
$result = runSQL($sql);
if($result){
   //send a mail
    if(!empty($email)){
        $u_email = $email;
        $u_subject ="PROFILE UPDATE";
        $u_message ="<p>Hi <b>$name</b>;</p> <p>Your Profile Picture has been updated successfully.</p>";
        require("../j_incs/mail.php");
    }
    //send-notify
    send_notify("",$id,$u_subject,$u_message);
    //
}else{
    die("Error. Code 103.");
}
//alert
?>
<script>
    $("#form").remove();
     $("#submit").attr('disabled', '');
         //window.location.href="<?php //echo $dir; ?>profile/";           
</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 class="text-center"><?php echo $u_message; ?> </p>
                     <p class="text-center">
                         <a class="btn btn-default btn-md" href="<?php echo $dir; ?>profile/"> View My Profile</a>
                     </p>
                 </div>
            </div>
        </div>
    </div>
</div>