<?php
session_start();
require_once('../db.php');
include('inc/session.php');

$user = $_SESSION['user'];
								
$ins = mysqli_query($conn,"SELECT * FROM users WHERE email='$user' ");
$data = mysqli_fetch_array($ins);
								
$email = $data['email'];
$rowpas = $data['pass'];
$bal = $data['bal'];

$inss = mysqli_query($conn,"SELECT * FROM administrator WHERE admin='$user' ");
$datas = mysqli_fetch_array($inss);
								
$ppp = $datas['token'];

							
$deps = "SELECT * FROM deposit  ";
$payment = $conn->query($deps);

include('../inc/logo.php');	
?>

<?php include('inc/header.php');?>

<body class="fixed-nav sticky-footer bg-dark" id="page-top">


  <!-- Navigation-->
 <?php include('inc/nav.php');?>
        
  <!-- Navigation Ends-->
      </ul>
    </div>
  </nav>
  <div class="content-wrapper">
  
    <div class="container-fluid">
      <!-- Breadcrumbs-->
     
      <div class="row">
        <div class="col-12">
          
     
     <h1 class="w3-xxxlarge w3-text-green" align="center"><b>Activate User Account Status</b></h1>
       

      <!-- Example Bar Chart Card-->
       
     <?php 
// define variables and set to empty values
      require("function/functions.php");

if(isset($_GET['id'])){
      
      $id = $_GET['id']; 
    
    $getuser = mysqli_query($conn, "SELECT * FROM users WHERE accno='$id' ");
    $qryuser = mysqli_fetch_array($getuser);
    
    $receiver = $qryuser['email'];
    $phone2 = $qryuser['phone'];
    $level2 = $qryuser['level'];
    $fname2 = $qryuser['firstname'];
    $lname2 = $qryuser['lastname'];
    $bal2 = $qryuser['bal'];  
    $status2 = $qryuser['status'];
    $bvn2 = $qryuser['BVN'];
    $email = $qryuser['email'];
    $phone = $qryuser['phone'];
      
  }else{
      
      $receiver = "";
  }	 
	 	
	
  $getuser = mysqli_query($conn, "SELECT * FROM activate WHERE accno='$id' ");
    $qryuser2 = mysqli_fetch_array($getuser);

    $level = $qryuser2['level'];
    $fname = $qryuser2['fname'];
    $lname = $qryuser2['lname'];  
    $status = $qryuser2['status'];
    $bvn = $qryuser2['BVN'];
    $dob = $qryuser2['dob'];




$qryApi = mysqli_query($conn,"SELECT * FROM settings");
$apidata = mysqli_fetch_array($qryApi);

$sitename = $apidata['sitename'];
$admin = $apidata['email'];
$sitephone = $apidata['mobile'];
$senderID = $apidata['senderID']; 
$sitlogo = $apidata['sitelogo']; 
$siturl = $_SERVER['SERVER_NAME'];
$request_dir = $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
		
	if(isset($_POST['create'])){
		

$old = $_POST['otp'];
$status = $_POST['status'];

$otp = md5($old);


$block = "Block";
$activate = "Activate";
$del = "Delete";
$cur = "₦";
$log=$_SERVER['REMOTE_ADDR'];
$country = $_POST['country'];
$accno = mt_rand(10000,298983);

$ref = mt_rand(1083,3981);

$refby = "Admin";
$refbyid = "7175";
$refid = "7175";
$refwallet = 0;
$refcount = 0;
$reflink = 'https://'.$request_dir.'/register.php?refid=';
$refunverified = 0;
$refverified = 0;

$pincredit = 0;

$blockpro = '0';

if($status == 'Active'){ 
$text= "Please be informed that your $sitename account has been <b>ACTIVATED</b> and a Unique Account number <b>Assigned</b> to you. <br>
Login to your account to see your Unique Account number for wallet funding." ;	

$txt = "Dear $fname2 Your Account on $sitename has been ACTIVATED. Thank You for choosing www.$siturl";
		
}elseif($status == 'Pending'){ 
$text= "Please be informed that your $sitename account Activation is still in <b>PROGRESS</b>. <br>
Please Be Patient with Us.";

}elseif($status == 'BVNError'){
$text= "Please be informed that your $sitename account Activation request has been <b>REJECTED</b> and your Account <b>NOT ACTIVATED</b>. <br>
<b>REASON:</b> The BVN you Supplied is Invalid, as it can not be Verified. Kindly Login to your account and correct it.";

}elseif($status == 'NameError'){ 
$text= "Please be informed that your $sitename account Activation request has been <b>REJECTED</b> and your Account <b>NOT ACTIVATED</b>. <br>
<b>REASON:</b> The Name You Supplied Didnt Matched with the Name on your BVN. Kindly Login to your account and correct it.";

}elseif($status == 'Upgrade'){
$text= "Please be informed that your $sitename account Activation request has been <b>REJECTED</b> and your Account <b>NOT ACTIVATED</b>. <br>
<b>REASON:</b> You Can only get a Unique Account Number for wallet Funding if you have Upgraded Your account Level. Kindly Login to your account and Upgrade to either Agent, Reseller or Portal Owner."; 

}else{
$text= "Please be informed that your $sitename account Activation is still in <b>PROGRESS</b>. <br>
Please Be Patient with Us.";}




if($otp == $ppp){

$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...

$sql = mysqli_query($conn,"UPDATE users SET IPaddress='110.221.200',status='$status' WHERE email='$email' OR phone='$phone' ");

$sql2 = mysqli_query($conn,"UPDATE activate SET status='$status',action='' WHERE email='$email' ");




echo '<div class="alert alert-success"><strong>Great!</strong> Account <b>ACTIVATED</b> to '.$status.'  Successfully</div>';
	
    
    

// send email

$from = "$sitename<info@$siturl>"; //the email address from which this is sent
$to = "$email"; //the email address you're sending the message to
$subject = "Account Activation"; //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: $sitename<info@$siturl>\r\n";
$headers .= "Organization: $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://vtuafrica.com.ng/portal/sitelogo/logo.png'>
//<img src='https://$request_dir/sitelogo/$sitlogo'>

<img src='https://$siturl/portal/sitelogo/$sitlogo'> 

<h3>Dear $fname2 $lname2,</h3>

$text  <br> <br>

Thank You for Choosing $sitename <br>



<strong>Your new details are as follows:</strong> <p>

<table class='table' >
  
  <tr>
    <td>Login ID</td>
    <td>$email</td>
  </tr>
  <tr>
    <td>Password</td>
    <td>What you choosed during Registration</td>
  </tr>
  
   <tr>
    <td>Account Level</td>
    <td>$level2</td>
  </tr>

<tr>
    <td>Account Status</td>
    <td>$status</td>
  </tr>

  
</table> <p>

$sitename give you instant and automated recharge for Airtime, <br>
SME DATA, Direct Data, Gotv, Dstv, Startimes, Electric Token, Smile Internet, <br>
WAEC, JAMB, NECO, NABTEB Pins, Bulk SMS, Bank Transfer and lots more...<p>

<a href='https://$siturl'><button class='button'>Try it Now!</button></a> <br>


<p>
Our support team is standby to assist you wherever you need help.<p>
 

<p>Warm Regards, <p>

<strong>The Admin TEAM <br>
  $sitephone<br>
  $admin <br>
www.$siturl </strong>

</body><html>";

//now mail
$DoMail = mail($to,$subject,$message,$headers);


$qryApi = mysqli_query($conn,"SELECT * FROM api_setting");
$apidata = mysqli_fetch_array($qryApi);
$api = $apidata['smartkey'];
$senderID = $apidata['smsUserid'];
$smsphone = $apidata['smsPhone'];

$query_rec = mysqli_query($conn,"SELECT * FROM billing");
$bil = mysqli_fetch_array($query_rec);
$bi = $bil['sms'];

//$txt = "Dear $fname2 $lname2 Your Account on $sitename has been UPGRADED from $acclevel to $accType. Thank You. www.$siturl";

$message = utf8_encode($txt);
$aa = urlencode($message);
$from = utf8_encode($senderID);
$sender = urlencode($from);

	   
	   
$baseurl ="https://smartrecharge.ng/api/v1/http.php?api_key=$api&recipient=$phone2&message=$aa&sender=$sender&route=3";



$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

 $content1 =curl_exec($ch);
                         

  $content=substr($content1, 0, 2);
                                   
        curl_close($ch);


       
	
	}else{
	echo '<div class="alert alert-danger">User does not exist.</div> '; 
	
}
}else{
	echo '<div class="alert alert-danger">Enter a valid OTP Received From SMS</div> '; 
	
}


if(isset($_POST['withdraw'])){
										
									

$email5 = $_POST['email'];


$sms = mt_rand(100000,61562822);  
$developer = "08064897610";



if(!empty($email5) ){

$check=mysqli_query($conn,"SELECT * FROM users2 WHERE email='$email' ");//looking through existing usernames
   
    $num = mysqli_num_rows($check);
    
    
   if($email5 == $developer){

echo '<div class="alert alert-success"><strong>Great!</strong> OTP Sent Successfully</div>';



}else{
echo '<div class="alert alert-danger"><strong>Invalid</strong> <b>Admin Phone Number</b> Entered.</div>';  }

}else{
echo '<div class="alert alert-danger">Enter Your Admin Phone Number.</div> ';  }
}



}


if(isset($_POST['withdraw'])){
										
									

$email5 = $_POST['email'];


$sms = mt_rand(100000,61562822);  
$developer = "08064897610";



if(!empty($email5) ){

$check=mysqli_query($conn,"SELECT * FROM users2 WHERE email='$email' ");//looking through existing usernames
   
    $num = mysqli_num_rows($check);
    
    
   if($email5 == $developer){

echo '<div class="alert alert-success"><strong>Great!</strong> OTP Sent Successfully</div>';



}else{
echo '<div class="alert alert-danger"><strong>Invalid</strong> <b>Admin Phone Number</b> Entered.</div>';  }

}else{
echo '<div class="alert alert-danger">Enter Your Admin Phone Number.</div> ';  }

}

		?>
	
  
  <form action="" method="post" autocomplete = 'off'> 

 <table class="table  margin-tp-10" id="transTable">
                     
                             <tr>
                            <td width="30%">
  
  <!--<div class="form-group">
        <label><strong>FirstName</strong></label>
		 <input type="hidden" id="fname" name="fname" class="form-control"  >
		 <div id="charNum"></div>
		 
      </div> 
      
      
      <div class="form-group">
        <label><strong>LastName</strong></label>
		 <input type="hidden" id="lname" name="lname"    class="form-control"  >
		 <div id="charNum"></div>
		 
      </div> 
  
  
  
	
		 
      </div> -->
	 
	</div> 

<?php 
if($level2 === 'reseller'){
$accType = '<badge class="badge badge-pill badge-success">Portal Owner</badge>';
}elseif($level2 === 'agent'){
$accType = '<badge class="badge badge-pill badge-info">Agent/Reseller</badge>';
}elseif($level2 === 'special'){
$accType = '<badge class="badge badge-pill badge-success">Special User</badge>';
 }else{
 $accType = '<badge class="badge badge-pill badge-danger">Normal User</badge>'; }?>


   <br>
 <div class="form-group"><strong>You are about to ACTIVATE the Account Status of a User Whose BVN details didnt Match: <br> 
Name on Site: <font color="red"><?php echo $fname2; ?> <?php echo $lname2;?> </font><br>
Name on BVN: <font color="red"><?php echo $fname; ?> <?php echo $lname;?> </font><br>
Email Address: <font color="red"><?php echo $receiver; ?>  </font><br>
Current Level: <?php echo $accType; ?> <br>
Current Status: <font color="red"><?php echo $status2; ?> </font> <br>
Current BVN: <font color="red"><?php echo $bvn; ?> </font> <br>
Current Phone: <font color="red"><?php echo $phone2; ?> </font> <br>
Date of Birth: <font color="red"><?php echo $dob; ?> </font> <br>
Current Balance: <font color="red"><?php echo $bal2; ?></font></strong><br> <br>
<font color="red">WARNING!!!</font></strong> Activating this user will Automatically change the user's Formal details to that of the BVN details.<br> <br>

        <!--<label><strong>Email Address:</strong></label>
		 <input type="text" id="email" name="email"  value="<?php echo $receiver; ?>"  class="form-control"  >
		 <div id="charNum"></div>

  <div class="form-group">
<label><strong>Phone Number:</strong></label>
        <input type="text" id="phone" name="phone" value="<?php echo $phone2; ?>"  class="form-control">
		 <div id="charNum"></div>-->

 <div class="form-group">
        <label><strong>Account Status:</strong></label>
		
 <select class="form-control" placeholder="Please Select Status" id="status" name="status" required="required" ><option value = "" selected="selected" required="required">Please Select Action</option>
                                       
<option value="Active">Activate</option>
<option value="BVNError">Invalid BVN</option>
<option value="NameError">Invalid Name</option>
<option value="Upgrade">Not Upgraded</option>
<option value="Pending">Pending Request</option>
</select>
		 <div id="charNum"></div>
		 
      </div> 
	  
	 
<div class="form-group">
<label><strong>An OTP has been sent to Your Phone, Enter it below:  <a href="#"  data-toggle="modal" data-target="#exampleModal2"><font color="red">Resend OTP</font></a></strong></label>
        <input type="password" id="phone" name="otp"   class="form-control" required>
		 <div id="charNum"></div>


      <button type="submit" id="submit" name="create" class="btn btn-info">Activate This User</button>
    </form>  
 
   </td>
                        </tr>
                            </table>           
            </div>
            
          </div>
          <!-- Card Columns Example Social Feed-->    
         </p>
        </div>
      </div>
    </div>
    <!-- /.container-fluid-->
    <!-- /.content-wrapper-->
    <?php include('inc/footer.php');?>


 <!--============================ Modal starts here=============================== -->
                                                <div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel2" aria-hidden="true">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h4 class="modal-title" id="exampleModalLabel2">Resend OTP</h4>
                                                                <a href="#" class="close" data-dismiss="modal" aria-label="Close">
                                                                            <span aria-hidden="true">&times;</span>
                                                                        </a>
                                                                   
                                                                      
                                                                        
                                                            </div>
                                                                                                    

                                                            <div class="modal-body">                                                      
                                                           <p><form method="POST" action="" accept-charset="UTF-8">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                 
                              <tr>
                                        <td>Phone</td>
                                        <td><input class="form-control"  name="email" type="text" value=""></td>
                                    </tr>
                                </table>
                            </div>
                            </p>
                                                            
                                                            <div class="modal-footer">
                                                                <a href="#" class="btn btn-secondary" data-dismiss="modal">Close</a>
                                                                <button type="submit" name="withdraw" class="btn btn-success">Resend OTP</button>
                                                            </div>
                                </form> 

                                <!--====================================Modal ends here============================-->

<!-- <label><strong>Phone</strong></label>
        <input type="hidden" id="pass" name="pass" value="<?php
		 
	$randomNum=substr(str_shuffle("0123456789abcdefghijklmnopqrstvwxyz"), 0, 8);
		 
		 echo $randomNum;
		 
		 ?>"  > -->