<?php
    ob_start();
    include'../connection.php';
	include'../functions.php';
	
	$tableName = "recharge";
	
	/*    
	$quM   = "SELECT Date FROM $tableName ORDER BY Id ASC";
	$reM   = mysqli_query($con,$quM);
	$dataM = mysqli_fetch_array($reM);
	echo $dateData = $dataM[0]."<br>";
	echo $yearData = substr($dateData,0,4)."<br>";
	echo $monthData = substr($dateData,5,2)."<br>";
	*/
	    
	if(isset($_POST['export']))
	{
	    $rechdate1 = $_POST['rechdate1'];
	    $rechdate2 = $_POST['rechdate2'];
	    
	    echo $sql = "SELECT * FROM $tableName WHERE Date>='$rechdate1' AND Date<='$rechdate2'";
	    $result = mysqli_query($con,$sql);
	    $count = mysqli_num_rows($result);
	    if($count>=1)
	    {
    	    $finaldata = array();
	
	        while($data=mysqli_fetch_assoc($result))
	        {
	            $finaldata[]=$data;
	        }
	
    	    $fnDate = date_create($rechdate1);
	        $fnDate = date_format($fnDate, "Ym");
	    
	    
	        $filename = $tableName.$fnDate . ".xls";
    	    header("Content-Type: application/vnd.ms-excel");
	        header("Content-Disposition: attachment; filename=\"$filename\"");
	        $firstrow=false;
    	    foreach($finaldata as $data)
	        {
	            if(!$firstrow)
	            {
	                echo implode("\t",array_keys($data))."\n";
    	            $firstrow=true;
	            }
	            echo implode("\t",array_values($data))."\n";
	        }
	        exit();
	    }
	    else
	    {
	        echo "Data Not Found !";
	    }
	    
	}
	
	
	
	//print_r($finaldata);
?>



<html>
    <head>
    </head>
    <body>
        <form method="post">
            <input type="date" name="rechdate1">
            <input type="date" name="rechdate2">
            <input type="submit" name="export" value="Export to excel">
        </form>
    </body>
</html>
	












































































	
	
	/*
	
	// Get the protocol (http or https)
    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http';

    // Get the host name
    $host = $_SERVER['HTTP_HOST'];

    // Get the request URI, which includes the path and query string
    $request_uri = $_SERVER['REQUEST_URI'];

    // Construct the complete URL
    $complete_url = $protocol . '://' . $host . $request_uri;

    echo $protocol."<br>";
    echo $host."<br>";
    echo $request_uri."<br>";
    echo $complete_url."<br>";

	
	
	/*
	echo "<pre>";
	    var_dump($_GET);
	echo "</pre>";
	
	
	/*
	
	// Rech Bye Sale curl programme Tested ok//
	$mnum = "9897095971";
	$ApiOpCode = "5";
	$amount = 10;
	$newrechid = 123456123456;
	
	$apiUsrId=3334;
    $apiToken="e696918427bc39de4a0761dbddd35ad9";
    
    $apiUrl     = "https://api.rechargebuysale.com/ExchangeTransactionAPI?UserID=$apiUsrId&Token=$apiToken&Account=$mnum&Amount=$amount&SPKey=$ApiOpCode&APIRequestID=$newrechid&Format=1";
	
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $apiUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $result   = json_decode($response);
    curl_close($ch);
    echo "<pre>";
   // print_r($response);
    
    echo $status = $result->status;
    
    
	
	
	
	

	
	//RC Recharge curl Programme Tested Ok//
	
	$mnum = "9897095971";
	$ApiOpCode = "BSNLSTV";
	$amount = 10;
	$newrechid = 123456123456;
	
	$apiUsrId = "159";
	$apiToken = "GnQB5VE8GoNCHfUnR";
	
	//$apiUrl  = "https://rcrecharge.com/Rechargeapi.asmx/Balance?UserId=58931&APIKey=";
    echo $apiUrl    = "https://rcrecharge.com/Rechargeapi.asmx/Recharge?UserId=$apiUsrId&APIKey=$apiToken&MobileNo=$mnum&OperatorCode=$ApiOpCode&Amount=$amount&APIReferanceID=$newrechid";
    
    
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $apiUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $result   = json_decode($response);
    curl_close($ch);
    echo "<pre>";
    print_r($response);
    
    echo $status = $result->Status;
    
    
    
    
    /*
    
    
    
    
    
    

curl_setopt_array($curl, array(
	CURLOPT_URL => '',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);

print_r($response);

	print_r($response);
	$ApiHitRes="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','RESULT','$response')";
	mysqli_query($con,$ApiHitRes);
	
	$result = json_decode($response);
		                                            
	echo $status    = $result->status;                                            
	    
    
    
    
    
    
    
    
    
    
    
    
    
    
	
	/*
	$updateLapu="UPDATE recharge SET Api='$api', Lapu='$LapuApi' where Id='$newrechid'";
	mysqli_query($con,$updateLapu);
    
	    if($status=="2" || $status=="SUCCESS")
        {
            require'../LinkFile/rechSuccess.php';
        }
        else if($status=="3" || $status=="FAIL" )
        {
            if($countSetApi>$x)
	    	{
		        $apiLoop="CONTINUE";
		    }
		    else
		    {
		        if(chk_msg($respoMsg,'Insufbalan')==10)
	            {
	                $respoMsg   ="Failed !";
	                $OpDeactive = "UPDATE comm_slab SET Status='DEACTIVE' WHERE Userid='$userid' AND OpCode='$OpCode'";
	                mysqli_query($con,$OpDeactive);
	            }
	
		        require'../LinkFile/rechFailed.php';
		    }   
        }
        else if($status=="1" || $status=="PENDING")
        {
            require'../LinkFile/rechPending.php';
        }
    
?>
	
	
	/*
	$mnum = "9897095971";
	$amount = 10;
	$ApiOpCode = 4;
	$newrechid = 12345678;
    $apiUsrId=3334;
    $apiToken="e696918427bc39de4a0761dbddd35ad9";
    
    $apiHTTPurl = "https://api.rechargebuysale.com/ExchangeTransactionAPI?";
    $apiUrl     = "UserID=$apiUsrId&Token=$apiToken&Account=$mnum&Amount=$amount&SPKey=$ApiOpCode&APIRequestID=$newrechid&Format=1";
	echo $reqUrl     = $apiHTTPurl.$apiUrl;
	//$quApiHit   = "INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','REQUEST','$reqUrl')";
	//mysqli_query($con,$quApiHit);
	
	$ch = curl_init();
	if (!$ch)
    {
        die("Couldn't initialize a cURL handle");
    }
    curl_setopt($ch, CURLOPT_URL,$apiHTTPurl); // Target URL
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS,$apiUrl);
    $result = curl_exec ($ch);
    
    $quApiHit="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','RESULT','$result')";
	mysqli_query($con,$quApiHit);
	
    $data2     = (array)json_decode($result);
	
    $status    = $data2['status'];                                            
		
	
	

/*
    $curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.rechargebuysale.com/ExchangeTransactionAPI?UserID=3334&Token=e696918427bc39de4a0761dbddd35ad9&Account=9897095971&Amount=11&SPKey=4&APIRequestID=3530788&Format=1',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));

echo $response = curl_exec($curl);
    $quApiHit="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','RESULT','$response')";
	if(mysqli_query($con,$quApiHit))
	{
	    echo "success";
	}
	
curl_close($curl);
echo $response;

	
	
	
    /*
	$qu = "SELECT Id, Name FROM operator";
	$re = mysqli_query($con,$qu);
	while($data=mysqli_fetch_array($re))
	{
	    $Id     = $data['Id'];
	    $OpName = $data['Name'];
	    $OPNAME = strtoupper($OpName);
	    
	    $update1 = "UPDATE operator SET Name='$OPNAME' WHERE Id='$Id'";
	    if(mysqli_query($con,$update1))
	    {
	    
	        $update2 = "UPDATE recharge SET OpName='$OPNAME' WHERE OpCode='$Id'";
	        if(mysqli_query($con,$update2))
	        {
	            $update3 = "UPDATE comm_slab SET OpName='$OPNAME' WHERE OpCode='$Id'";
	            if(mysqli_query($con,$update3))
	            {
	                echo "SUCCESS";
	            }
	        }
	    }
	}
	
	/*
	
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://bbps-sb.payu.in/payu-nbc/v2/nbc/getCircleList",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
	
exit();	
	/*
	$email="hm.shaan.computers@gmail.com";
	$uName="Sammer Zareef";
	$newUsrid="AU123123";
	$pwd="123456";
	                    
	                    
	$toMail      = $email;
	$toName      = $uName;
	$subjectMail = "Welcome To LLP Recharge";
	$msgMail     = "Dear $toName , Your Registration Is Successfull. Your Userid is $newUsrid & Password is $pwd , Login Your LLP Account on https://www.llprecharge.in/login.php";
	require'../LinkFile/mail.php';
	
	
	/*
	$data1 = "recharge.Id,";
	$data2 = "wallet.Txn, wallet.TxnType, wallet.TxnId";
	$IJrNw = "INNER JOIN wallet ON wallet.TxnId=recharge.Id";
	$where1 = "wallet.TxnType='RECHARGE'";
	$qu = "SELECT $data1 $data2 FROM recharge $IJrNw WHERE $where1";
    $re = mysqli_query($con,$qu);
    while($data=mysqli_fetch_array($re))
    {
        $rechId = $data['0'];
        $Txn    = abs($data['1']);
        
        $update = "UPDATE recharge SET Debit='$Txn' WHERE Id='$rechId'";
        mysqli_query($con,$update);
        
    }
    echo "SUCCESS";
    /*
    $mnum ="9897095971";
    $apiUrl=": https://www.ytcpay.co.in/apiservice.asmx/GetOperator?apiToken=$apiToken&mn=$mnum"; 
	
	$curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => $apiUrl,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
    ));

    $response = curl_exec($curl);
    echo $result   = simplexml_load_string($response);
    curl_close($curl);
    
    //$quApiHit="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','RESULT','$response')";
	//mysqli_query($con,$quApiHit);
	
    $status    = $result->status;                                            
	$ApiBal    = $result->balance;
    $respoMsg  = $result->remark;   
    $txnId     = $result->field1;   
    $errCode   = $result->ec;
    $partnerId = $result->apirefid;
    







    /*
    $BlkAmt = "12,23,34,45,56";
    $SeperateBlkAmt = explode(',',$BlkAmt);
    $amount=12;
    if (!in_array($amount, $SeperateBlkAmt)) 
    {
        echo "Available";
    } 
    else 
    {
        echo "Not available";
    }
    
    
    /*
    $apiToken = "5304f696e952416f8989e2186bb4dd3b";
    $mnum = "8410930786";
    $amount = 10;
    $ApiOpCode = 001;
    $newrechid = 12341235;
    $api ="Test";
    if($OpCode==5 || $OpCode==4)
    {
        $field1 = $mnum;
    }
    else
    {
        $field1 = "";
    }
    
    $apiUrl="https://www.ytcpay.co.in/apiservice.asmx/Recharge?apiToken=$apiToken&mn=$mnum&amt=$amount&op=$ApiOpCode&reqid=$newrechid&field1=$field1&field2=''"; 
	
	//$quApiHit="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','REQUEST','$apiUrl')";
	//mysqli_query($con,$quApiHit);
	
	
	$curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => $apiUrl,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
    ));

    $response = curl_exec($curl);
    $result = simplexml_load_string($response);
    curl_close($curl);
    
    //$quApiHit="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','RESULT','$response')";
	//mysqli_query($con,$quApiHit);
	
    echo $status    = $result->status;                                            
	echo $ApiBal    = $result->balance;
    echo $respoMsg  = $result->remark;   
    echo $txnId     = $result->field1;   
    echo $errCode   = $result->ec;
    echo $partnerId = $result->apirefid;
    
    */


?>