<?php
	require_once("../../includes/bootstrap.php");
	$sesion=new sesion();
	$academia=bootstrap::initBd($sesion->get('anio'));
	/** Error reporting */
	error_reporting(E_ALL);
	ini_set('display_errors', TRUE);
	ini_set('display_startup_errors', TRUE);
	date_default_timezone_set('Europe/London');
	
	if (PHP_SAPI == 'cli')
		die('This example should only be run from a Web Browser');
	
	/** Include PHPExcel */
	require_once("../../includes/phpExcel/PHPExcel.php");
	
	
	// Create new PHPExcel object
	$objPHPExcel = new PHPExcel();
	
	// Set document properties
	$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
								 ->setLastModifiedBy("Maarten Balliauw")
								 ->setTitle("Office 2007 XLSX Test Document")
								 ->setSubject("Office 2007 XLSX Test Document")
								 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
								 ->setKeywords("office 2007 openxml php")
								 ->setCategory("Test result file");
	// Add some data
	$dts=$_GET['dtSo'];
	$i=0;
	$cmps="";
	foreach($dts as $v){
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i++, 1, $dtsLang['mod_cabec_repor'][$v]);
		$cmps.=$v.',';
	}
	$cmps=substr($cmps,0,strlen($cmps)-1);
	$sql="SELECT $cmps FROM view_dts_estudiantes";
	$academia->instruccion($sql);
	$fil=2;
	$tamCmp=count($dts);
	while($reg=$academia->extraer_registro()){
		for($x=0;$x<$tamCmp;$x++)
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($x, $fil, $reg[$dts[$x]]);
		$fil++;
	}	
	// Rename worksheet
	$objPHPExcel->getActiveSheet()->setTitle('Simple');
	
	
	// Set active sheet index to the first sheet, so Excel opens this as the first sheet
	$objPHPExcel->setActiveSheetIndex(0);
	
	
	// Redirect output to a client’s web browser (Excel5)
	header('Content-Type: application/vnd.ms-excel');
	header('Content-Disposition: attachment;filename="01simple.xls"');
	header('Cache-Control: max-age=0');
	
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	$objWriter->save('php://output');
	exit;
?>