<?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'];
$mobile = $sql_logo['mobile'];
$sitename = $sql_logo['sitename'];
$siturl = $_SERVER['SERVER_NAME'];

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

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

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


$invitecount = $getref['refcount'] + 1;
$note = "Enter new password below.";

$emails = "E-mail: $email";
$phones = "Phone: $phone";
$myname = "Welcome Back! $fname $lname";

	
	}else{

$note = "Sorry! This Link has Expired. <br>Generate a new Link";

//$note = "Please Visit this page using The Link Sent To your E-mail";	

		}
							
if(isset($_POST['sub'])){
										
									

$ecode1 = $_POST['otp'];
$pass1 = $_POST['pass'];
$pass11 = $_POST['pass1'];

$ecode = mysqli_real_escape_string($conn, $_POST['otp']);
$pass = mysqli_real_escape_string($conn, $_POST['pass']);
$pass1 = mysqli_real_escape_string($conn, $_POST['pass1']);

$ecode = filter_var($ecode, FILTER_SANITIZE_STRING);
$pass = filter_var($pass, FILTER_SANITIZE_STRING);
$pass1 = filter_var($pass1, FILTER_SANITIZE_STRING);

										
$level = "free";
$block = "Block";
$activate = "Activate";
$del = "Delete";
$status = "Pending";
$bal = 0;
$cur = "₦";
$log=$_SERVER['REMOTE_ADDR'];
$acctype = "normal";
$country = $_POST['country'];
$mypass = md5($pass);
$hash = password_hash($pass, PASSWORD_DEFAULT);
$uid = mt_rand(1083676523,398166660123);

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

$refwallet = 0;


$pincredit = 0;

$blockpro = '0';

$refcount = 0;
//$date = date("d/m/Y");
$date = date('d/m/Y');
$time = date('H:m:s');

	
if(!empty($ecode) && !empty($pass) && !empty($pass1) ){
	

		
$reflink = 'https://'.$request_dir.'/register.php?refid=';
$link = 'https://vtuafrica.com.ng/portal/registration.php?refid=43';
$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($ecode == $emailcode) {							
							

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

$updat = mysqli_query($conn,"UPDATE users SET pass='$mypass',acc='$hash',otp='$ref' WHERE email ='$email' ") or die(mysqli_error()); 


echo '<div class="alert alert-success">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Password Changed Successfully.</strong> 
									</div>';
    
   	

 }else {
	
	
	
	echo '<div class="alert alert-danger">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Your Account is not Found on our Site. Plaese Contact Admin.</strong> 
									</div>';
	
}

	
									
								
									
				
// send email

$from = "".$sql_logo['sitename']."<noreply@".$_SERVER['SERVER_NAME'].">"; //the email address from which this is sent
$to = "$email"; //the email address you're sending the message to
$subject = "Password Reset Completed"; //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 $fname $lname,</h3>

Your $sitename account password has been changed successfully on $date. <br> <br>
If you did not reset your password at the time mentioned above, please call our customer care line on $mobile  immediately. <br><br>
Thank you for choosing $sitename. <br> <br>

We offer you instant and automated recharge for Airtime, Data, Gotv, Dstv, Bet9ja, Startimes, <br<
Electric Token, , Spectranet, Bank Transfer, Bulk SMS, <br>
WAEC PIN, NECO PIN, Recharge Card PIN and lots more....<br><br>



Kindly Login to start using our services. <br>
<a href='https://".$_SERVER['SERVER_NAME']."'><button class='button'>Login Now!</button></a> <br>

<p>


Thank You!. <p>

Warm Regards, <p>


".$sql_logo['sitename']." <br>
$mobile <br>
$ademail <br>

</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>The Two Passwords Do not Match.</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 Email</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);
										}

?>