<?php

include("../config.php");
session_start();

if(isset($_SESSION["user_login"])){
	$userid = $_SESSION["user_login"];
}else{
		header("location: ../register-login.php");
	}
	

		//get user info
		
		$stmt="SELECT * FROM users WHERE userid = :userid";
		$stmt=$pdo->prepare($stmt);
		$stmt->bindParam("userid", $userid, PDO::PARAM_STR);
		$stmt->execute();
		$row=$stmt->fetch();
		$userimage = (!empty($row["profilepix"]) ? "../img/users/".$row["profilepix"]: "../img/avatar.png");
		
	
	
?>

<style>
form label{
	font-weight:500!important;
	color:#444;
	cursor:pointer;
	font-size:16px!important;
}
</style>


<!DOCTYPE html>

<html lang="en">

<head>

        <meta charset="utf-8" />

        <title> Profile | Six Digital Assets</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta name="keywords" content="trade, trading, forex, investing, invest, investment, investor, money, chart, bitcoin, ethereum, USDT, coins, cryptocurrencies, crypto, profit, market, online money, money online,">
    <meta name="description" content="Six Digital Assets provides a full investment service focused on the Bitcoin and cryptocurrency trading market. A certified legal investment company incorporated and headquartered in Australia.">
    <meta name="author" content="Six Digital Assets">

        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

      

            <link rel="stylesheet" type="text/css" href="w3.css">

        <!-- Bootstrap Css -->

        <link href="assets/css/bootstrap.min.css" id="bootstrap-stylesheet" rel="stylesheet" type="text/css" />

        <!-- Icons Css -->

        <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />

        <!-- App Css-->

        <link href="assets/css/app.min.css" id="app-stylesheet" rel="stylesheet" type="text/css" />

		<link href="../css/style7eda3860.css" rel="stylesheet">

    </head>



    <body>


	<div class='coversoverlay'>
	<center><img src="../img/loader.gif" style="width:60px; margin-top:20%;"></center>
	</div>

  <!-- Begin page -->
  <div id="wrapper" style="overflow:auto!important">

   
   
   <!-- Topbar Start -->
	<?php
	include("header.php");
	?>
    <!-- end Topbar -->
   

    <!-- ========== Left Sidebar Start ========== -->
    <div class="left-side-menu">

      <div class="slimscroll-menu">

        <!-- User box -->
        <div class="user-box text-center ">

          <div class="dropdown">
            <a href="#" class="user-name dropdown-toggle h5 mt-2 mb-1 d-block" data-toggle="dropdown" aria-expanded="false"></a>
            <div class="dropdown-menu user-pro-dropdown">




            </div>
          </div>


        </div>

        <!--- Sidemenu -->
        <?php include("sidebar.php");?>
		
        <!-- End Sidebar -->
        <div class="clearfix"></div>



                </div>

                <!-- Sidebar -left -->



            </div>

            <!-- Left Sidebar End -->






            <div class="content-page" >

                <div class="content" style="width: 100%;color: white;">



                    <!-- Start Content-->

                    <div class="container-fluid" >

                        <div id="google_translate_element"></div>

                         <div class="row">

                            <div class="col-md-12" style="padding-left:0px; padding-right:0px">
                            
						
						
				<form class="col-md-7" style="margin-top:20px!important;margin: auto;">
				
                <div class="card-box" style="background-image:radial-gradient(ellipse closest-side, rgba(225, 225, 225, 0),#fff), url(../img/profile.jpg); background-size:; background-repeat:no-repeat; background-position:center">
				<h2 align="center" style='color:#767e80' id="wlcm">Update Profile</h2>
				<div class="dropdown-divider"></div><br>
				
		<center>
		<div id="ProfilePixResult">
		<img src="<?php echo $userimage;?>" alt="User Avatar" class="img-size-50 mr-3 img-circle" 
		style="height:120px;width:120px;; border-radius:50%;border:2px solid #d3d6d7">
        </div>
		
		<label for="profilepix" id="select-btn" style="margin-left:-20px; margin-top:10px;" class="btnss btn">Select photo &nbsp;
		<i class="fas fa-camera-retro"></i></label>
		<input type='file' name='profilepix' class='display-none' id='profilepix' accept="image/*" />
		</center>
		
		<div align="center" style="color:#ff3737; margin-left:-20px!important; margin-bottom:30px;font-size:17px;font-weight:500" id="result"></div>
		
		<section id="suc" class="display-none">
		<div class="success-display">Updated Successfully <i class="fas fa-check"></i></div>
		<div id="editAgain" style="color:#2e657e;font-size:15px; font-weight:bold; cursor:pointer; text-align:center;margin:20px;">
		<i class="fas fa-edit"></i> Click here to edit again</div>
		
		<div class="dropdown-divider"></div>
		<div style="text-align:center">
		<a href="account.php" style="color:#2e657e; font-size:16px;"><i class="fas fa-tachometer-alt"></i> Dashboard</a> 
		&nbsp; &nbsp; <a href="../" style="color:#2e657e; font-size:16px;"> <i class="fas fa-home"></i> Back Home</a>
		</div>
		</section>
				
				<div id="updateForm">
				  <div class="form-group">
                    <label for="fullName" style="margin-left:10px"><i class="fas fa-edit"></i> Full name</label>
                    <div class="col-sm-12">
                      <input type="text" name="fullName" class="form-control" id="fullName" value="<?php echo htmlspecialchars($row["fullName"])?>" placeholder="Enter full name">
                    </div>
                  </div>
				  
				  <div class="form-group">
                    <label for="username" style="margin-left:10px"><i class="fas fa-user"></i> Username</label>
                    <div class="col-sm-12">
                      <input type="text" name="username" class="form-control" id="username" value="<?php echo htmlspecialchars($row["username"])?>" placeholder="Enter a username">
                    </div>
                  </div>
				  
				  <div class="form-group">
                    <label for="email" style="margin-left:10px"><i class="fas fa-envelope"></i> Email</label>
                    <div class="col-sm-12">
                      <input type="email" required name="email" class="form-control" readonly id="email" 
					  value="<?php echo htmlspecialchars($row["email"])?>">
                    </div>
                  </div>
				  
				  <div class="form-group">
                    <label for="phone" style="margin-left:10px"><i class="fas fa-phone"></i> Phone number</label>
                    <div class="col-sm-12">
                      <input type="text" name="phone" class="form-control" id="phone" 
					  value="<?php if(!empty($row["phone"])){echo htmlspecialchars($row["phone"]);}?>" placeholder="Enter phone Number">
                    </div>
                  </div>
				  
				  <div class="form-group">
                    <label for="address" style="margin-left:10px"><i class="fas fa-building"></i> Address</label>
                    <div class="col-sm-12">
                      <input type="text" name="address" class="form-control" id="address" 
					  value="<?php if(!empty($row["address"])){echo htmlspecialchars($row["address"]);}?>" placeholder="Residential Address">
                    </div>
                  </div>
				  <div class="form-group">
                    <label for="country" style="margin-left:10px"><i class="fas fa-globe"></i> Country</label>
                    <div class="col-sm-12">
                      <input type="text" name="country" class="form-control" id="country" 
					  value="<?php if(!empty($row["country"])){echo htmlspecialchars($row["country"]);}?>" placeholder="Enter Country">
                    </div>
                  </div>
				  <br>
				  <div class="dropdown-divider"></div>  <br>
				  <div class="form-group">
                    <label for="btc" style="margin-left:10px; color:#396f89"><i class="fas fa-wallet"></i> Enter BTC Wallet Address</label>
                    <div class="col-sm-12">
                      <input type="text" name="btc" class="form-control" id="btc" 
					  value="<?php if(!empty($row["btc"])){echo htmlspecialchars($row["btc"]);}?>" placeholder="Enter BTC withdrawal Address">
                   
					</div>
                  </div>
				  <br>
				  
				  
				  <div class="form-group">
                    <label for="ethereum" style="margin-left:10px; color:#396f89"><i class="fas fa-link"></i> Ethereum Bep20 Address</label>
                    <div class="col-sm-12">
                    <input type="text" name="ethereum" class="form-control" id="ethereum" 
					  value="<?php if(!empty($row["ethereum"])){echo htmlspecialchars($row["ethereum"]);}?>" placeholder="Enter eth withdrawal Address">
					</div>
                  </div>
				  <br>
				  
				  
				  <div class="form-group">
                    <label for="usdt" style="margin-left:10px; color:#396f89"><i class="fas fa-link"></i> Tether USDT(TRC20)</label>
                    <div class="col-sm-12">
                    <input type="text" name="usdt" class="form-control" id="usdt" 
					  value="<?php if(!empty($row["usdt"])){echo htmlspecialchars($row["usdt"]);}?>" placeholder="Enter eth withdrawal Address">
                    <div style="color:#888; margin:10px 0px;font-size:14px">Please enter the correct addresses. Hence will be used for subsequent withdrawal</div>
					</div>
                  </div>
                 
	
                  <button type="submit" id="update" class="btn btnss btn-block">Update</button>
                
               </div>
			   
			   
              
				
                 
				 
				 </div>
              </form>  
						   </div>
							</div> <!-- container-fluid -->



                </div> <!-- content -->
                </div> 
              
					</div> 
	
					</div>
               


       

        <!-- Vendor js -->

        <script src="assets/js/vendor.min.js"></script>



        <!-- knob plugin -->

        <script src="assets/libs/jquery-knob/jquery.knob.min.js"></script>



        <!--Morris Chart-->

        <script src="assets/libs/morris-js/morris.min.js"></script>

        <script src="assets/libs/raphael/raphael.min.js"></script>



        <!-- Dashboard init js-->

        <script src="assets/js/pages/dashboard.init.js"></script>



        <!-- App js -->

        <script src="assets/js/app.min.js"></script>

   
   
   
   
   
   
   
   
   
   <script>
   
   $(document).ready(function(){
	
	$('.coversoverlay').hide();
		 
		 
		 
	
	
	
	//Update profile picture

 $('#profilepix').change(function(){
  var form_data = new FormData();
  var files = $('#profilepix')[0].files;


   for(var i=0; i<files.length; i++)
   {
    var name = document.getElementById("profilepix").files[i].name;
    var ext = name.split('.').pop().toLowerCase();
    if(jQuery.inArray(ext, ['gif','png','jpg','jpeg']) == -1) 
    {

//Toast error
   alert('Please select a valid image file');
	
	return false;
    }
    var oFReader = new FileReader();
    oFReader.readAsDataURL(document.getElementById("profilepix").files[i]);
    var f = document.getElementById("profilepix").files[i];
    var fsize = f.size||f.fileSize;
    if(fsize > 9194304) //9mb
    {
      
	//Toast error
   alert('Image is too large. Allowed max size is 9MB');
   
return false;
    }
    else
    {
     form_data.append("profilepix[]", document.getElementById('profilepix').files[i]);
    }
   }
  

	if(files.length > 0){
   $.ajax({
    url:"function.php",
    method:"POST",
    data: form_data,
    contentType: false,
    cache: false,
    processData: false,
    beforeSend:function(){$(".coversoverlay").show();},   
    success:function(data){
				
		//hide Loader
		$(".coversoverlay").hide();
		
		//Embed image
		$("#ProfilePixResult").html(data);
		
		
		
    }
   });
	}


 });
 
 
 
 
 
 
 //UPDATE User
 
 $("#update").click(function(e){
	 e.preventDefault();
	 
		let update = "update";
			
		let fullName = $("#fullName").val();
		let username = $("#username").val();
		let email = $("#email").val();
		let phone = $("#phone").val();
		let address = $("#address").val();
		let country = $("#country").val();
		let btc = $("#btc").val();
		let ethereum = $("#ethereum").val();
		let usdt = $("#usdt").val();
		

		$.ajax({
			url:'function.php',
			method:'POST',
			data:{fullName:fullName,username:username,email:email,phone:phone,address:address,country:country,btc:btc,ethereum:ethereum,usdt:usdt,update:update},
			beforeSend:function(){$(".coversoverlay").show()},
			success:function(data){
				$("#result").html(data);
				
				//console.log(data);
				$(".coversoverlay").hide();
				
			}
		});
		
		});
	
	
	//Edit Profile Again
	$("#editAgain").click(function(){
		
				$("#select-btn").fadeIn();
				$("#updateForm").slideDown(function(){
					
					$("#suc").addClass("display-none");
					$("#wlcm").html("Re-Update Profile");
					
				});	
			
	})
 
 
 
 
	 
   });
   
   
   
   
   </script>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    </body>

</html>