<?php
session_start();
require('db.php');
include('inc/logo.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 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['otp'];
$smscode = $getref['otp'];  
$refid = $getref['refid']; 
$refby = $getref['refby'];
$refbyid = $getref['refbyid'];



	
	}else{
		
	$email = "";	

$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['resend'])){
										
									

$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);


	
if(!empty($email) ){
	


											
	$check=mysqli_query($conn,"SELECT * FROM users WHERE email='$email'  ");
   
    $num = mysqli_num_rows($check);
    
    
    if ($num > 0){ 



$updat = mysqli_query($conn,"UPDATE users SET otp='$ref',credit='$mt' WHERE email ='$email' ") or die(mysqli_error()); 

							
									
				
// 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 = "Email Verification"; //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>

To Continue using our Services, kindly verify your Email address using the link below:<br><br>

<a href='https://".$request_dir."/forgot-password/emailverification.php?refid=".$mt."'><button class='button'>Click Here To Verify Your Email!</button></a> <br><br>

If the Above link is not working, then copy the code below into your browsing:<br><br>

https://".$request_dir."/forgot-password/emailverification.php?refid=".$mt."
  <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);
             	

$errorMessage = '<div class="alert alert-success">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Email Verification Code Sent Successfully to your email.<br>
		Check your email address for more information. Remember to check your Spam folder if you dont see it.</strong> 
									</div>';

		
 }else {
	
	
	
	$errorMessage = '<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>';
	
}

		

									
									
												
											
}else{
												
$errorMessage = '<div class="alert alert-danger">
										
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Enter required field</strong>  
									
</div>'; }
									
									
mysqli_close($conn);
										
}
	

?>
<!doctype html>
<html lang="en">

<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!-- Required meta tags -->
    
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Resend Email Code</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css">
    <link href="assets/vendor/fonts/circular-std/style.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/libs/css/style.css">
    <link rel="stylesheet" href="assets/vendor/fonts/fontawesome/css/fontawesome-all.css">
    <link href="sitelogo/favicon.png" rel="icon" />
    <style>
    html,
    body {
        height: 100%;
    }

    body {
        display: -ms-flexbox;
        display: flex;
        -ms-flex-align: center;
        align-items: center;
        padding-top: 40px;
        padding-bottom: 40px;
    }
    </style>
</head>

<body>
    <!-- ============================================================== -->
    <!-- login page  -->
    <!-- ============================================================== -->
	
	    <div class="splash-container">
        <div class="card ">
            <div class="card-header text-center"><a href="index.php"><?php logo2($sitelogo); ?></a><span class="splash-description">Email Verification Needed.</span> <br><font color=red size='3pt'>
                Please Kindly verify your email Address</font>

        <?php if ($errorMessage != '') { ?>
				<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $errorMessage; ?></div>                            
			<?php } ?>    
            </div>
			
			
            <div class="card-body">
                <form method="post" action="">
                    <div class="form-group">
                        <input class="form-control form-control-lg" name="loginId" id="loginId" type="text" placeholder="Email" autocomplete="off" value="<?php echo $email; ?>" readonly>
                    </div>
					
                
                    <button type="submit"  name="resend" class="btn btn-primary btn-lg btn-block">Resend Email Verification Code</button>
                </form>
                
                
            </div>
            <div class="card-footer bg-white p-0  ">
                <div class="card-footer-item card-footer-item-bordered">
                    <a href="#" class="footer-link">Create An Account</a></div>
                <div class="card-footer-item card-footer-item-bordered">
                    <a href="#" class="footer-link">Forgot Password</a>
                </div>
            </div>
        </div>
    </div>
	
	
    

    <!-- ============================================================== -->
    <!-- end login page  -->
    <!-- ============================================================== -->
    <!-- Optional JavaScript -->
    <script src="assets/vendor/jquery/jquery-3.3.1.min.js"></script>
    <script src="assets/vendor/bootstrap/js/bootstrap.bundle.js"></script>
</body>
 
</html>