<?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");
		
		 
		//redirect incase it was admin
		if($row["type"]=="admin"){
			header("location: ../admin/dashboard.php");
		}
		
		
?>

<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> Referral Programme | </title>

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

        <meta content="A fully featured platform" name="description" />

        <meta content="Coderthemes" name="author" />

        <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-8" style="padding-left:0px; padding-right:0px;margin:auto">
                            
						
			
                <div class="card-box" style="background-image:radial-gradient(ellipse closest-side, rgb(255 255 255 / 91%),#f5f6f9);margin-top:30px;">
				<h2 align="center" style='color:#767e80' id="wlcm">Refer Users</h2>
				<div class="dropdown-divider" style="border-color: #cad7eb;"></div><br>
				
		
		
		
		<div style="color:#396f89; 0px;font-size:17px; line-height:25px;">
		Our Referral Commision is structured that registered members receive a bonus when their referrals make a successful Investment. Our referral bonus is an unlimited for all successful investment made from your referrals. 
		<p><br>Note that you can't refer the same people twice. <a href="tandc.php">Terms and Conditions</a> applies.
		
		
		<div class="card-box" style="background-image:radial-gradient(ellipse closest-side, rgb(255 255 255 / 91%),#eaf1ff); margin-top:30px;">
		<div style="color:#396f89; font-size:17px;margin-left:10px;"><b>Unique link below</b></div>
		
		<br>
		<div class="form-group">
        <label for="link" style="margin-left:10px; color:#396f89; font-size:17px; font-weight:500"><i class="fas fa-link"></i> Invite Link</label>
        <input type="text" readonly class="form-control" id="link" 
		value="<?php echo "https://secureswiss-wealth-pro.org/register-login.php?ref=".htmlspecialchars($row["invite_ref"]);?>">
		</div>
	
        <div onclick="copyAddress()" id="copyAddress" class="btn btnss btn-block copyAddress"> Click to Copy 
		&nbsp;<i class="fas fa-copy"></i></div>
			   
		</div>
		
		
		
		<p><br>
			   
              
				
               
		<center>
		<div class="dropdown-divider" style="border-color: #c8d2e5;"></div>
		<div style="color:#396f89; font-size:18px;"><b>Referral History</b></div>
		<div class="dropdown-divider" style="border-color: #c8d2e5;"></div>
		<br></center>



				
				
				
				
				
				
				
				
				<?php
				
				//Get referred users
				$stmt=$pdo->prepare("SELECT * FROM referral WHERE userid = :userid ORDER BY id DESC");
				$stmt->bindParam(":userid", $userid, PDO::PARAM_STR);
				$stmt->execute();
				if($stmt->rowCount()>0){
				$referees = $stmt->fetchAll();
				
				foreach($referees as $referee){
				
				//get Referee info
				$stmt=$pdo->prepare("SELECT * FROM users WHERE userid = :userid");
				$stmt->bindParam(":userid", $referee["referee"], PDO::PARAM_STR);
				$stmt->execute();
				$refInfo = $stmt->fetch();
				
				$refereeImg = (!empty($refInfo["profilepix"]) ? "../img/users/".$refInfo["profilepix"]: "../img/avatar.png");
				
				?>
				
				<div class="card-box" style="background-image: radial-gradient(ellipse closest-side, rgba(255, 255, 255, 0),#f1f6fb), url(../img/active.jpg); background-repeat:no-repeat; background-position:center; padding:12px;">
				
				<div style="color:#396f89; font-size:13px; margin-bottom:10px; font-weight:500">
				<i class="fas fa-calendar"></i> &nbsp; <b>Registered </b> &nbsp; 
				<?php echo date("jS F, Y", strtotime($referee["refDate"]));?></div>
				
				<section style="display:flex">
				<div><img src="<?php echo $refereeImg;?>" class="avatars"></div>
				<div style="margin:10px 6px; font-size:18px; color:#405972; font-weight:500;">
				<?php if(!empty($refInfo["fullName"])){echo htmlspecialchars($refInfo["fullName"]);}else{echo "Site User";}?><br>
				<div style="color:#405972; font-size:14px; margin-top:4px;">Approved User</div>
				</div>
				</section>
				
				<div class="dropdown-divider" style="border-color: #c8d2e5;"></div>
				
				<div style="color:#396f89; font-size:15px; margin-bottom:10px;margin-left:10px; font-weight:500;text-transform:capitalize;">
				<b>Status </b> &nbsp; 
				<?php echo htmlspecialchars($referee["status"]); if($referee["status"]=="paid"){echo " <i class='fa fa-check'></i>";}?></div>
				
				
				<?php if($referee["status"] == "paid"){?>
				<div style="color:#396f89; font-size:13px; margin:-10px 10px 10px 10px; font-weight:500">
				A 3% ref bonus will be paid to your account</div>
				<?php }?>
				
				
				</div>
				
				<?php }}else{?>
				
				<div style="color:#818ba1; font-size:20px; margin-bottom:10px; font-weight:500">
				<center>Record is empty </center></div>
				
				
				<?php }?>
				
				
		
				




			   
				 
				 </div>
               
						   </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>
   
   
    //Copy invite Link
   function copyAddress() {
  var copyText = document.getElementById("link");
  copyText.select();
  copyText.setSelectionRange(0, 99999)
  document.execCommand("copy");
  alert("Unique Link Compied")
}  




   $(document).ready(function(){
	
	$('.coversoverlay').hide();
		
 
 
 
 
 
 
 
 $("#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();
				
			}
		});
		
		});
	

 
 
	 
   });
   
   
   
   
   </script>
   
   
   
  
   
    </body>

</html>