<?php

 $request_dir = $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);	

if(isset($_GET['refid'])){
	
$afs = mysqli_real_escape_string($conn, $_GET['refid']);
	
	}else{
	
	$afs = "system";	
		}

$aff = filter_var($afs, FILTER_SANITIZE_STRING);
	
$qrysite = mysqli_query($conn,"SELECT * FROM settings");
$sql_logo = mysqli_fetch_array($qrysite);
$ademail = $sql_logo['email'];					

$qryaff = mysqli_query($conn,"SELECT * FROM users2 WHERE accno='$aff' ");
$getref = mysqli_fetch_array($qryaff);

if($aff === $getref['accno']){

$fname = $getref['firstname']; 
$lname = $getref['lastname'];
$email = $getref['email'];
$phone = $getref['phone'];
$accno = $getref['accno'];
$emailcode = $getref['accno'];
$smscode = $getref['credit'];  
$refid = $getref['refid']; 
$refby = $getref['refby'];
$refbyid = $getref['refbyid'];


$invitecount = $getref['refcount'] + 1;
$note = "Enter Valid Information Below To Activate Your Account.";

	
	}else{
		
$note = "Please Visit this page using The Link Sent To your E-mail";	
	$refbyid = "System";
	$refcount = 1;
		}
							
if(isset($_POST['sub'])){
										
									

$ecode = $_POST['email'];
$otp = $_POST['phone'];
$amount = $_POST['amount'];
$bank = $_POST['bank'];

$ecode = filter_var($ecode, FILTER_SANITIZE_STRING);
$otp = filter_var($otp, FILTER_SANITIZE_STRING);
$amount = filter_var($amount, FILTER_SANITIZE_STRING);
$bank = filter_var($bank, FILTER_SANITIZE_STRING);


$ecode = mysqli_real_escape_string($conn, $ecode);
$otp = mysqli_real_escape_string($conn, $otp);
$amount = mysqli_real_escape_string($conn, $amount);
$bank = mysqli_real_escape_string($conn, $amount);
										
$level = "free";
$block = "Block";
$activate = "Activate";
$del = "Delete";
$status = "Pending";
$bal = 0;
$cur = "₦";
$log=$_SERVER['REMOTE_ADDR'];
$acctype = "normal";
$country = $_POST['country'];
$pass = mt_rand(10000,1000000);
$hash = password_hash($pass, PASSWORD_DEFAULT);
$uid = mt_rand(108367652312,398166660123);

$ref = mt_rand(100000,10000000);
$mt = mt_rand(108367652312,41062832237);

$refwallet = 0;
$date = date('Y-m-d H:m:s');

$pincredit = 0;

$blockpro = '0';

$refcount = 0;

	
if(!empty($ecode) && !empty($otp) && !empty($bank) && !empty($amount) ){
	

		
$reflink = 'https://'.$request_dir.'/register.php?refid=';
$link = 'https://vtuafrica.com.ng/portal/registration.php?refid=64707';
$refunverified = 0;
$refverified = 0;	
	
	
			
			
		// Validate reCAPTCHA box 
        if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ 
            // Google reCAPTCHA API secret key 
            $secretKey = $capsec; 
             
            // Verify the reCAPTCHA response 
            $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['g-recaptcha-response']); 
             
            // Decode json data 
            $responseData = json_decode($verifyResponse); 
            
           
			
		// If reCAPTCHA response is valid 
            if($responseData !== success or $responseData == success){ 
                
											
		$validphone = preg_replace("/[^0-9]/", '', $phone);
		
	
		if($smscode == $otp) {									
										//  REG
								
	$check=mysqli_query($conn,"SELECT * FROM users WHERE email='$email' OR phone='$phone' ");//looking through existing usernames
   
    $num = mysqli_num_rows($check);

$check1=mysqli_query($conn,"SELECT * FROM xpress WHERE email='$email' OR phone='$phone' ");//looking through existing usernames
   
    $nu = mysqli_num_rows($check1);
    
    
    if ($num ==0){ //If there is already such username...



if ($nu ==0){

$sql = mysqli_query($conn,"INSERT into xpress(network,phone,amount,orderno,serviceid,meter,meter_type,status,email,Customer,fname,lname,accno,action,del,date) VALUES('DSTV','$validphone','$amount','$ref','$bank','$smscode','$emailcode','Pending','$email','$fname $lname','$fname','$lname','$accno','Action','Delete','$date')") or die(mysqli_error());



echo'<div class="alert alert-success">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Account Activation Request Submitted.
Check Your Email for your Login Details.</strong>  </div>';	

 }else {
	
	
	
	echo '<div class="alert alert-danger">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>You Have Already Submitted This Form! Please Wait for your account to be ACTIVATED.</strong> 
									</div>';
	
}									
								
									
				
// send email

$from = "".$sql_logo['sitename']."<noreply@".$_SERVER['SERVER_NAME'].">"; //the email address from which this is sent
$to = "$ademail"; //the email address you're sending the message to
$subject = "Registration Request"; //the subject of the message

// To send HTML mail, the Content-type header must be set
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "Return-Path: ".$sql_logo['sitename']."<".$sql_logo['sitename'].">\r\n";
$headers .= "Organization: ".$sql_logo['sitename']."\r\n";
 
// Create email headers
$headers .= 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();

$message = "

<html>
<head>
<style>
.table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 50%;
}

td {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}


.button {
  background-color: #008CBA; /* Blue */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  border-radius: 8px;
  cursor: pointer;
  
  -webkit-transition-duration: 0.4s; /* Safari */
  transition-duration: 0.4s;
}

.button:hover {
  background-color: #4CAF50; /* Green */
  color: white;
}

</style>
</head>

<body>

<img src='https://".$request_dir."/sitelogo/".$sql_logo['sitelogo']."'>

<h3>Dear $sitename Admin,</h3>

A New User has requested for Registration Approval. <br> 
The User Details are Found Below:

<table class='table' >
  
  <tr>
    <td>User Name:</td>
    <td>$fname $lname</td>
  </tr>

 <tr>
    <td>Email:</td>
    <td>$email</td>
  </tr>

 <tr>
    <td>Phone Number:</td>
    <td>$validphone</td>
  </tr>

 <tr>
    <td>Amount Paid:</td>
    <td>$amount</td>
  </tr>

 <tr>
    <td>Bank Paid To:</td>
    <td>$bank</td>
  </tr>

 <tr>
    <td>Email Code:</td>
    <td>$emailcode</td>
  </tr>

 <tr>
    <td>SMS Code:</td>
    <td>$smscode</td>
  </tr>


  
</table> <p>

Kindly Login to your Admin area to Approve this New User.

<p>


Thank You!. <p>

Warm Regards, <p>


".$sql_logo['sitename']."

</body><html>";

//now mail
$DoMail = mail($to,$subject,$message,$headers);
             	
    
		
		
 }else {
	
	
	
	echo '<div class="alert alert-danger">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Your Account is Already Activated! Please login to continue.</strong> 
									</div>';
	
}
			// check if phone is valid
			
		}
		else{echo '<div class="alert alert-danger">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Enter a valid Code Received From SMS</strong> 
									</div>'; }
									
									
									
            }else{echo '<div class="alert alert-danger">
	<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Robot verification failed, please try again.</strong> 
									</div>';}							
									
        }else{ echo '<div class="alert alert-danger">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Please check on the reCAPTCHA box.</strong> 
									</div>';
		
            
        }
									
									
												
											}
												
											else{
												echo'<div class="alert alert-danger">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Enter required field</strong>  
									</div>'; }
									
									mysqli_close($conn);
										}

?>