<?php
		$finish_timeb = time();		
		$texto_finishb= date("d/m/y", $finish_timeb);
		require_once 'PHPExcel/Classes/PHPExcel.php';
		$filename = 'Reporte_Usuarios_'.$texto_finishb; //your file name
		
		
$dbhost = 'localhost';  
$dbuser = 'trafika_bkpromo';  
$dbpass = "bkpromo@2017";  
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');  
$dbname = "trafika_bkpromofinal";
$connection = mysql_select_db($dbname); 
$limit = $_GET['limit'];
$filter= $_GET['filter'];
$order= $_GET['order'];
  
mysql_query("SET NAMES 'utf8'");
//print first employee table

$sql = "SELECT * FROM facebook_oauth WHERE activo = 1 ORDER BY $filter $order";
$rs_result = mysql_query ($sql);

$objPHPExcel = new PHPExcel();
/*********************Add column headings START**********************/
		$objPHPExcel->setActiveSheetIndex(0) 
					->setCellValue('A1', 'ID DE USUARIO')
					->setCellValue('B1', 'NOMBRE')
					->setCellValue('C1', 'EMAIL')
					->setCellValue('D1', 'TELEFONO')
					->setCellValue('E1', 'TICKETS REGISTRADOS')
					->setCellValue('F1', 'MONTO ACUMULADO')
					->setCellValue('G1', 'FECHA DE REGISTRO');
		/*********************Add column headings END**********************/
		
		
$row = 2;
while($subrow = mysql_fetch_assoc($rs_result))
{
	
	
    $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $subrow['UID']);
    $objPHPExcel->getActiveSheet()->setCellValue('B'.$row, ucwords($subrow["nombre"]));
    $objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $subrow['email']);
    $objPHPExcel->getActiveSheet()->setCellValue('D'.$row, $subrow['telefono']);
   
	$objPHPExcel->getActiveSheet()->setCellValue('E'.$row, $subrow['registrados']);
    $objPHPExcel->getActiveSheet()->setCellValue('F'.$row, '$'.$subrow['acumulado']);
	 $objPHPExcel->getActiveSheet()->setCellValue('G'.$row, $subrow['fecha']);
    $row++;
}
/*********************Autoresize column width depending upon contents START**********************/
        foreach(range('A','G') as $columnID) {
			$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
		}
		/*********************Autoresize column width depending upon contents END***********************/
		
		$objPHPExcel->getActiveSheet()->getStyle('A1:G1')->getFont()->setBold(true); //Make heading font bold
		
		/*********************Add color to heading START**********************/
		$styleArray = array(
    'font'  => array(
        'bold'  => true,
        'color' => array('rgb' => 'F0F0F0'),
        'size'  => 10,
        'name'  => 'Century Gothic',

    ),
	'fill'  => array(
    'type' => PHPExcel_Style_Fill::FILL_SOLID,
    'color' => array('rgb' => 'DD1B2B')
	),
	'alignment' => array(
            'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
        )
	
	);
		$objPHPExcel->getActiveSheet()
					->getStyle('A1:G1')->applyFromArray($styleArray);
		/*********************Add color to heading END***********************/
		
		$objPHPExcel->getActiveSheet()->setTitle('Usuarios Registrados'); //give title to sheet
		$objPHPExcel->setActiveSheetIndex(0);
		header('Content-Type: application/vnd.ms-excel');
		header("Content-Disposition: attachment;Filename=$filename.xls");
		header('Cache-Control: max-age=0');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
		exit;
?>