<?php
  

 header('Content-Type: application/json');
  
    require_once('../../db.php');


	// API parameter
    
	if(isset($_REQUEST['apikey']) ){
	
	$apikey = $_REQUEST['apikey'];
	//$auth =  "ACTIVE";
	$auth = "paid";
   
     $apikey = filter_var($apikey, FILTER_SANITIZE_STRING);

   
    $apikey = str_replace( array( '+', 'www', '/', '(', ')', 'https',  'http',  '//', 'drop', 'update', 'delete', 'insert',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $apikey);

	
	
	$stat = "Completed";
	date_default_timezone_set('Africa/Lagos');

    $dateTime = date(' Y-m-d h:i A');
 

	
	// check if the account is valid
	
	if(!isset($apikey)){
	    
	    response(107,"BAD REQUEST");} else{
	
	$retr = "SELECT * FROM users WHERE apikey='$apikey' ";
	
	$exe = mysqli_query($conn,$retr);
	$rob = mysqli_fetch_array($exe);
	
	$user = $rob['apikey'];
	$aut = $rob['level'];
	
	$arr = array("$apikey","$auth");
	
	$pair = array("$user","$aut");		
	
	if($arr === $pair){
	    
		
		//vtuafrica here
		
$query_rec = mysqli_query($conn,"SELECT * FROM api_setting");
			
$apib = mysqli_fetch_array($query_rec); 

$apikey =  $apib['APIkey'];

$code = mysqli_real_escape_string($conn, $apib['accesscode']);
$apikey = mysqli_real_escape_string($conn, $apib['APIkey']);



$accesscode = filter_var($code, FILTER_SANITIZE_STRING);

$apikey = filter_var($apikey, FILTER_SANITIZE_STRING);            
        
$website = $_SERVER['SERVER_NAME'];           
        
	

$host = "https://vtuafrica.com.ng/portal/api/access?website=$website&accesscode=$accesscode";

//Initialize cURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$data = curl_exec($ch);
$result = json_decode($data);

//Close the cURL handle.
curl_close($ch);

//echo $data;
$latest = $result->latest;
$myversion = $result->version;
$version = "Version 2 (Diamond)";   
$pdate = $result->pdate;
$status = $result->Status;     //"Approveda";


  if($status == "Approved"){
	  
	  
	  
	    // check if the user have balance
	
	$query_rec = mysqli_query($conn,"SELECT * FROM gotv");
			
         $sme = mysqli_fetch_array($query_rec);	


         $query_rec1 = mysqli_query($conn,"SELECT * FROM dstv");
			
			$smeA2 = mysqli_fetch_array($query_rec1);


         $query_rec2 = mysqli_query($conn,"SELECT * FROM startimes");
			
			$smeR = mysqli_fetch_array($query_rec2);


 //GOTV
		
$smallieA = $sme['smallieA'];
$smallieB = $sme['smallieB'];
$smallieC = $sme['smallieC'];
$jinja = $sme['jinja'];
$jolli = $sme['jolli'];
$max = $sme['max'];




//DSTV			
		
$padi = $smeA2['padi'];
$yanga = $smeA2['yanga'];
$confam = $smeA2['confam'];
$compact = $smeA2['compact'];
$compactplus = $smeA2['compact_plus'];
$premium = $smeA2['premium'];
$asia = $smeA2['asia'];
$premiumfrench = $smeA2['premium_french'];




//startimes	
					
$novaA = $smeR['novaA'];
$novaB = $smeR['novaB'];
$nova = $smeR['nova'];

$basicA = $smeR['basicA'];
$basicB = $smeR['basicB'];
$basic = $smeR['basic'];




$smartA = $smeR['smartA'];
$smartB = $smeR['smartB'];
$smart = $smeR['smart'];

$classicA = $smeR['classicA'];
$classicB = $smeR['classicB'];
$classic = $smeR['classic'];



$uniqueA = $smeR['uniqueA'];
$uniqueB = $smeR['uniqueB'];
$unique = $smeR['unique'];

$superA = $smeR['superA'];
$superB = $smeR['superB'];
$super = $smeR['super'];


	
 response(100,array(
"status"=>$stat,
"gotv_smallie"=>$smallieA,
"gotv_smallie_3months"=>$smallieB,
"gotv_smallie_1year"=>$smallieC,
"gotv_jinja"=>$jinja,
"gotv_jolli"=>$jolli,
"gotv_max"=>$max,
"dstv_padi"=>$padi,
"dstv_yanga"=>$yanga,
"dstv_confam"=>$confam,
"dstv_compact"=>$compact,
"dstv_compact_plus"=>$compactplus,
"dstv_premium"=>$premium,
"dstv_asia"=>$asia,
"dstv_premium_french"=>$premiumfrench,

"startimes_nova_daily"=>$novaA,
"startimes_nova_weekly"=>$novaB,
"startimes_nova"=>$nova,
"startimes_basic_daily"=>$basicA,
"startimes_basic_weekly"=>$basicB,
"startimes_basic"=>$basic,
"startimes_smart_daily"=>$smartA,
"startimes_smart_weekly"=>$smartB,
"startimes_smart"=>$smart,
"startimes_classic_daily"=>$classicA,
"startimes_classic_weekly"=>$classicB,
"startimes_classic"=>$classic,
"startimes_super_daily"=>$superA,
"startimes_super_weekly"=>$superB,
"startimes_super"=>$super,
"startimes_unique_daily"=>$uniqueA,
"startimes_unique_weekly"=>$unique,
"startimes_unique"=>$unique,

"transaction_date"=>$dateTime

));
	
	

  } else{  
    
    $sta = "Pirated Copy";
	$message = "Please Note that This VTU Software is a Pirated Software Copy. Get Original one from VTU Africa. visit www.vtuafrica.com.ng";
	
	response(204,array("status"=>$stat,"message"=>$$message));


    }

	
	
// close account not found
  } else{  
    
    response(103,"INVALID APIKEY SUPPLIED"); 


    }


} // close wrong parameter



	}   else{ 
	   
	   response(400,"INVALID PARAMETER"); 
	       
	       
	   }
	    

function response($status,$status_message)
{
	
	
	$response['code']=$status;
	$response['data']=$status_message;
	
	
	$json_response = json_encode($response);
	
	
	$deko = json_decode($json_response);
	
	echo $json_response;
}
    
    ?>
    
	


  
   	

