<?php

ob_start(); session_start();
include("../session.php");


require('fpdf.php');
$d=date('d_m_Y');

class PDF extends FPDF
{

function Header()
{
    $this->SetFont('Helvetica','',14);
	$this->SetFontSize(20);
	
	$this->SetFillColor(70,130,180);
    //Move to the right
    $this->Cell(40);
    //Line break
    $this->Ln();
}

//Page footer
function Footer()
{
   
}


//require('../session.php');
//Load data
function LoadData($file)
{
	//Read file lines
	$lines=file($file);
	$data=array();
	foreach($lines as $line)
		$data[]=explode(';',chop($line));
	return $data;
}

//Simple table
function BasicTable($header,$data)
{ 

$this->SetFillColor(255,255,255);
//$this->SetDrawColor(255, 0, 0);
$this->SetFillColor(238, 238, 238);
$w=array(77,35,25,28,20);
	
	
	//Header
	$this->SetFont('Arial','B',9);
	for($i=0;$i<count($header);$i++)
		$this->Cell($w[$i],7,$header[$i],1,0,'L',true);
	$this->Ln();
	
	//Data
	
	$this->SetFont('Arial','',10);
	foreach ($data as $eachResult) 
	{ //width
		$this->Cell(10);
	
		$this->Cell(77,6,$eachResult["requestid"],1);
		$this->Cell(35,6,$eachResult["date_sent"],1);
	    $this->Cell(25,6,$eachResult["airtime_sent"],1);
		
				$this->Cell(28,6,$eachResult["recipient"],1);
	    $this->Cell(40,6,$eachResult["status"],1);

		$this->Ln();
		 	 	 	 	
	}
}

//Better table
}



$pdf=new PDF();

	  $g_id=$_GET['g_id'];

$header=array('REQUESTED ID','DATE SENT','AIRTIME SENT','RECEPIENT','STATUS');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","ki223469_temp","m0bi.2018$") or die("Error:Please check your database username & password");
$objDB = mysql_select_db("ki223469_temp");
//where customer_id = '$session_id'
$strSQL = "select * from airtime_sending_records where customer_id = '$session_id' order by r_id DESC limit 2000 ";
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
	$result = mysql_fetch_array($objQuery);
	array_push($resultData,$result);
}
//************************//




//*** Table 1 ***//
$pdf->AddPage();

	$pdf->SetFont('Helvetica','',10);
	$pdf->Cell(60);
	$pdf->Write(5, 'AIRTIME ASSIGNMENT HISTORY');
	$pdf->Ln();
	
	$pdf->Cell(22);
	$pdf->SetFontSize(8);
	$pdf->Cell(57);
	$result=mysql_query("select date_format(now(), '%W, %M %d, %Y') as date");
	while( $row=mysql_fetch_array($result) )
	{
		$pdf->Write(5,$row['date']);
	}
	$pdf->Ln();
	
	//count total numbers of visitors
	$result=mysql_query("select * from airtime_sending_records where customer_id = '67' ") or die ("Database query failed: $query" . mysql_error());
	
	$count = mysql_num_rows($result);
	$pdf->Cell(0);
	$pdf->Write(5, '             Total Airtime Sent : '.$count.'');
	$pdf->Ln();

	$pdf->Ln(5);

$pdf->Ln(0);
$pdf->Cell(10);
$pdf->BasicTable($header,$resultData);
//forme();
//$pdf->Output("$d.pdf","F");
$pdf->Output();

?>