<?php
ob_start(); session_start(); 
include_once('../dbcon.php');
include_once('../session.php');

  
	$phne = $_GET['no'];
	$name = $_GET['nm'];
	
		 $no_ckeck = substr($phne, 0, 1);
			if ($no_ckeck == "0"){
				$pno = substr($phne, 1);
				$pno2 = "+254".$pno;
			}elseif($no_ckeck == "2"){
				//$pno = substr($phone, 3);
				$pno2 = "+".$phne;
			}elseif($no_ckeck == "7"){
				$pno2 = "+254".$phne;
			}

   function HeaderingExcel($filename) {
      header("Content-type: application/vnd.ms-excel");
      header("Content-Disposition: attachment; filename=$filename" );
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
      header("Pragma: public");
      }
	  
	  // HTTP headers
    HeaderingExcel('User_Report.xlsx');// Creating a workbook
    
    //////////////
	
   $getmemberrecords = mysql_query("select * from airtime_sending_records where recipient = '$phne' or recipient = '$pno2' order by date_sent DESC ");
	
	$sqlrows=mysql_num_rows($getmemberrecords);
	$j=0;
	if($sqlrows > 0 ){
	    $showColoumn=false;
		while ($reportdisp=mysql_fetch_array($getmemberrecords)) {
		$j=$j+1;
				
			$cols['Name and Number'] = $name." - ".$phne;
			$cols['Date'] = $reportdisp['date_sent'];
			$cols['Airtime Sent'] = $reportdisp['airtime_sent'];
		    $cols['Status']  = $reportdisp['status'];
		    $cols['Requestid']  = $reportdisp['requestid'];
		    
			//  WRITTING OUT TO BE PRINTED IN EXCEL
		    if(!$showColoumn) {		 
    		  echo implode("\t", array_keys($cols)) . "\n";
    		  $showColoumn = true;
    		}
    		echo implode("\t", array_values($cols)) . "\n";
		}
	
	}	
	
?>