<?php
	session_start();
	include('config.php');
	if(isset($_POST['fname'])){
		$name = validate($conn, $_POST['fname']);
		$lname = validate($conn, $_POST['lname']);
		$username = validate($conn, $_POST['username']);
		$email = validate($conn, $_POST['email']);
		$password = validate($conn, $_POST['password']);
		$phone = validate($conn, $_POST['phone']);
		$sq = validate($conn, $_POST['sq']);
		$sa = validate($conn, $_POST['sa']);
		$ref = validate($conn, $_POST['ref']);
		//$payeer = validate($conn, $_POST['payeer']);
		$btc = validate($conn, $_POST['btc']);
		$country = validate($conn, $_POST['country']);
		
		$rname = validate($conn, $_POST['rname']);
		$remail = validate($conn, $_POST['remail']);
		$cds = time();
		$c = md5($email);

		$salt = $password.'bn54bnxys367jd23007';
	    $pass_by = md5($salt);
		$qv = $conn->query("SELECT * FROM `main_reg` WHERE `email`='$email'");
		if(mysqli_num_rows($qv) >= 1){
    			//echo 'email';
        			echo 'one';
        		}else{
        			
        			$q = $conn->query("INSERT INTO `main_reg`(`first_name`, `last_name`, `email`, `password`, `country`,`hash_p`,`ref`, `plain`,`username`, `sa`, `sq`, `payeer`, `btc`, `litcoin`, `eth`, `btccash`,`perfect`, `cd`) VALUES ('$name','$lname','$email','$pass_by','$country','$c', '$ref','$password','$username','','','','$btc','','','','$phone', '$cds')");
        			
        			$conn->query("INSERT INTO `balance`(`id`, `code`, `amount`, `status`) VALUES (NULL,'$c','$amount','0')");
        			//$conn->query("INSERT INTO `user_wallet`(`id`, `address`, `code`, `type`) VALUES (NULL,'$wallet_address','$code','Bitcoin')");
        			//$full = ucfirst($name.' '.$lname);
        			
        			mail_to($name, $lname, $c, $email, $ref, $password, $username, $cds);
        			//mail_to_un($name, $rname, $remail);
        			if($q == true){
        			    
        				echo 'three';
        			}else{
        				echo 'four';
        			}
        		}
            
         
    		


	}


function mail_to($name, $lname, $c, $email, $ref, $pass, $username, $cd){
		$from = "support@eaglewinks.com";
$to = $email;
    $subject = "Account Registration";
    $headers = "MIME-Version: 1.10.2" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "From: Eagle Winks <support@eaglewinks.com>";
 //$headers .= 'From: Stack Investments Group, U.S <info@stackinvestments.us>';
 
 $message = '
            <div style="width: 500px; margin: 0 auto; border: 1px solid #ccc; border-radius: 6px; padding: 10px;
            background: #f2f2f2;">
            <div style="background: #08cc7f; padding: 10px; width: 480px; text-align:center;">
                <img src="https://eaglewinks.com/assets/images/logo.png" width="250px">
            </div>
            <br>
            <h2 style="text-align:center; color:;">Your Eagle Winks Account was Successfully Created</h2>
	          
	          <p style="text-align: left !important;">
	          Hi '.$name.'<br><br>
	          Congratulations, You are now part of Eagle Winks family.<br><br>
	          Please find credentials for your account below:<br><br>
	          <ul>
	            <li><b>Email: </b>'.$email.'</li>
	            <li><b>Password: </b>'.$pass.'</li>
	            <li><b>Ref Code: </b>'.$cd.'</li>
	          </ul>
	            
	          </p>
	          <br><br><br><span style="text-align: center;">Best Regards,<br>Eagle Winks</span>
	          </div>';
$temp = $message; 
										
                        
            //mail($to,$subject,$message, $headers);
        mail($to,$subject,$temp,$headers);
	}
	
	
	
	
	
function mail_to_un($name, $receiver, $memail){
    
    $id = rand(000,888);
    
    
    
	$from = "support@Eagle Winksltd.com";
    $to = $memail;
    $subject = 'You have a direct Signup on Eagle Winks';
    $headers = "MIME-Version: 1.10.2" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "From: Eagle Winks <support@Eaglewinks.com>";
 //$headers .= 'From: Stack Investments Group, U.S <info@stackinvestments.us>';
 $message = '
	          <p style="color:;">
	            Dear '.$receiver.',<br><br>
	            You have a direct signup on Eagle Winks <br><br>
                
	            Thank you.<br>
	            Eagle Winks <br>
	            
	            
	            
	          </p>
	          
	          ';
$temp = $message;
            //mail($to,$subject,$message, $headers);
        mail($to,$subject,$temp,$headers);
}    

	function chk_email($name, $email, $country, $conn, $lname, $password, $username){// Check Email
		
			$c = md5($email);

			$salt = $password.'bn54bnxys367jd23007';
	    	$pass_by = md5($salt);

			$stmt = $conn->prepare("SELECT username FROM main_reg WHERE username = ?");
    		$stmt->bind_param('s', $username);
    		$stmt->execute();
    		
    		if($stmt->num_rows >= 1){
    			//echo 'email';
    			echo 'one';
    		}else{
    			

    		}
		

	}


	function reg($name, $email, $country, $conn, $lname, $password){// Registration
		
		$c = md5($email);

		$salt = $password.'bn54bnxys367jd23007';
    	$pass_by = md5($salt);

		$s = 0;
		
		$ec = $conn->query("INSERT INTO `main_reg`(`id`, `first_name`, `last_name`, `email`, `password`, `country`, `active`, `status`) VALUES (NULL,'1','2','john','4','5')");
		if($ec == true){
		    //mail_to($name, $email ,$phone, $country, $conn, $ref, $mname, $lname, $username, $password, $c);
		    echo 'three';
			//echo 'z';
		}else{
		    echo 'four';
		}
		
	}

	function validate($con, $vi){
		$var = mysqli_real_escape_string($con, $vi);
		$var_p = filter_var($var, FILTER_SANITIZE_STRING);
		return $var_p;
	}
?>