<?php
include("conexion/conexion.php");
class Exportar{

	function xlsBOF(){
		echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
		return;
	}// Excel end of file footer
	function xlsEOF(){ 
		echo pack("ss", 0x0A, 0x00);
		return;
	}// Function to write a Number (double) into Row, Col
	function xlsWriteNumber($Row, $Col, $Value){
		echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
		echo pack("d", $Value);
		return;
	}// Function to write a label (text) into Row, Col
	function xlsWriteLabel($Row, $Col, $Value ){
		$L = strlen($Value);
		echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
		echo $Value;
		return;
	}
	function alfa($rst,$titulos){
		$this->conexionObj2=new conexion();
		$this->conexionObj2->conectarse();
		// Excel begin of file header
		header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
		header ("Cache-Control: no-cache, must-revalidate");
		header ("Pragma: no-cache");
		header ("Content-type: application/x-msexcel");
		header ("Content-Disposition: attachment; filename=".$_SESSION['nom_xls'].".xls" );
		header ("Content-Description: PHP/INTERBASE Generated Data" );
		$this->xlsBOF(); // begin Excel stream
		$rst_select_lotes=$this->conexionObj2->consultar($rst);		
		for($i=0; $i<=count($titulos)-1; $i++){
			$this->xlsWriteLabel(0,$i,$titulos[$i]);
			$total_campos=$total_campos+1;
		}
		//$this->xlsWriteLabel(0,0,$rst);
		$i=1;
		do {
			for($j=0; $j<=$total_campos-1; $j++){
				$variable=$row_Rs[$j];
                if (empty($variable)){$variable=' ';}
				if($i==1){

				}else{
					$this->xlsWriteLabel($i-1,$j,$variable);
				}
				

			}
			//$this->xlsWriteLabel($i-1,$j,$variable);
			$i=$i+1;
			
		}while ($row_Rs = mysql_fetch_array($rst_select_lotes));
 		// write a number B1
		$this->xlsEOF(); // close the stream
	}
}
$alfaobj=new Exportar();
$cant=$alfaobj->alfa($_SESSION['sql_nomina'],$_SESSION['titulos']);
?>
