<?php

	require_once 'excelwriter.inc.php';

	$excel=new ExcelWriter("arquivoExcel.xls");

	if($excel==false)	
		echo $excel->error;

	function testaVazio ($string) {
		if (!isset($string)) {
			$string = " - ";
			return $string;
		}
		if (isset($string)) {
			return $string;
		}
	}

	// function dataPTBR ($data) {
	// 	if (!isset($data)) { return false; }
	// 	$dataFormatada = date("d/m/Y", strtotime($data));
	// 	return $dataFormatada;
	// }

	$myArr=array("iD","Nome");
	$excel->writeLine($myArr);

	$queryClientes = "SELECT 
										  id,
										  empresa 
										FROM
										  crm_cliente 
										WHERE statusCliente = 1 
										ORDER BY empresa ASC ";

	$buscaClientes = mysql_query($queryClientes);

	if ($buscaClientes) {
		for ($i=0; $i < mysql_num_rows($buscaClientes); $i++) {

			$arrClientes = mysql_fetch_array($buscaClientes);

			$id = testaVazio($arrClientes['id']);
			$nome = testaVazio($arrClientes['empresa']);

			$myArr=array($id, $nome);
			$excel->writeLine($myArr);			
		}
	}

	// $myArr=array("Sriram","Pandit","23 mayur vihar",24);
	// $excel->writeLine($myArr);
	
	// $excel->writeRow();
	// $excel->writeCol("Manoj");
	// $excel->writeCol("Tiwari");
	// $excel->writeCol("80 Preet Vihar");
	// $excel->writeCol(24);
	
	// $excel->writeRow();
	// $excel->writeCol("Harish");
	// $excel->writeCol("Chauhan");
	// $excel->writeCol("115 Shyam Park Main");
	// $excel->writeCol(22);

	// $myArr=array("Tapan","Chauhan","1st Floor Vasundhra",25);
	// $excel->writeLine($myArr);
	
	$excel->close();
?>

<table>
	<?php if($excel != false) { ?>
  <tr>
		<td>Arquivo gerado com successo</td>
	</tr>	
	<?php } ?>
	<tr>
	  <td height="60" colspan="4" width="100%" align="center" valign="middle" bgcolor="#EFEFEF">
			<a href="arquivoExcel.xls">
		    <input type="button" value="Baixar">
		  </a>
		</td> 
  </tr>
</table>

<script type="text/javascript">
	$(document).ready(function() {
		$("input[type='button']").prop('enaebled', 'true');
	});
</script>