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

  require_once('OLEwriter.php');
  require_once('BIFFwriter.php');
  require_once('Worksheet.php');
  require_once('Workbook.php');

   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('MyContacts.xls');// Creating a workbook
$workbook = new excel("-");
// Creating the first worksheet
$worksheet1 =& $workbook->add_worksheet('Contacts');
$worksheet1->freeze_panes(1, 0);
  $worksheet1->set_column(0, 0, 25);
  $worksheet1->set_column(1, 1, 20);
  $worksheet1->set_column(1, 2, 20);

  
   $worksheet1->write_string(0,0,"Name");
   $worksheet1->write_string(0,1,"Contact");
   $worksheet1->write_string(0,2,"Group");
  


/////////////////
	
   $qryreport = mysql_query("select * from airtime_contacts where customer_id = '$session_id' order by contact_id ASC ");
	
	$sqlrows=mysql_num_rows($qryreport);
	$j=0;
	if($sqlrows > 0 ){
		WHILE ($reportdisp=mysql_fetch_array($qryreport)) {
		$j=$j+1;
			    $gid = $reportdisp['group_id'];	
					$grup = "";
				if($reportdisp['group_id'] == 0 ){
					$grup = "Not Allocated";
				}else{
					$s2 = mysql_query("select * from airtime_groups where group_id = '$gid' and customer_id = '$session_id' ");
					$rw= mysql_fetch_array($s2);
					$grup = $rw['name'];
				}
				
			$FirstName = $reportdisp['fname'];
			$LastName = $reportdisp['contact'];
		    $stts  = $grup;
		    
			 $worksheet1->write_string($j,0,"$FirstName");
			 $worksheet1->write_string($j,1,"$LastName");
			 $worksheet1->write_string($j,2,"$stts");
		}
	
	}	
	
/////////////////
  
  

  
$workbook->close();
?>