<?php

require_once("../../includes/bootstrap2.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('America/Bogota');
//echo ini_get("memory_limit");
ini_set('memory_limit', '1024M');
ini_set('max_execution_time', 60 * 10);

if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');

$anio = 2013;

require_once("../../includes/phpExcel/PHPExcel.php");
$objPHPExcel = new PHPExcel();

// Set document properties
$objPHPExcel->getProperties()->setCreator("Academia Web")
        ->setLastModifiedBy(date('Y-m-d H:m:s'))
        ->setDescription("Anexo 6A")
        ->setKeywords("Academia 2013")
        ->setCategory("Reportes Academia");

$iduser = $sesion->get('ac_userid');
$hojaActiva = $objPHPExcel->getActiveSheet();
//$dtsColegio = $sesion->get('info_colegio');
//$hojaActiva->setCellValue('A1', $dtsColegio['nombre']);
//$hojaActiva->setCellValue('A2', "NIT. " . $dtsColegio['nit']);
//$hojaActiva->setCellValue('A3', empty($dtsColegio['resolucion']) ? $dtsColegio['decreto'] : $dtsColegio['resolucion'] );
//$hojaActiva->setCellValue('A4', "vigencia" . $anio);

$sql = "CALL SP_ANEXO_6A(0,$anio,'$iduser')";
$academia->instruccion($sql, 0, 1);

$reg = $academia->extraer_registro();
$fil = 6;
$filOrg = $fil;
$col = 0;
$colOrg=$col;
$titulos = array_keys($reg);
foreach ($titulos as $key) {
    
    $rango=$dtsLang['mod_forma_nom_cel'][$col];
    $hojaActiva->getColumnDimension($rango)->setAutoSize(true);
    $hojaActiva->getStyle($dtsLang['mod_forma_nom_cel'][$col])->getNumberFormat()->setFormatCode("@");
    $hojaActiva->setCellValueByColumnAndRow($col++, $fil, $key);
}
$fil++;
$RANGO=$rango=$dtsLang['mod_forma_nom_cel'][$colOrg].$filOrg .":".$dtsLang['mod_forma_nom_cel'][100]."5000";


do {
    $col=0; 
    foreach ($reg as $cmp) { 
        #$hojaActiva->setCellValueByColumnAndRow($col++, $fil, $cmp);
        $hojaActiva->setCellValue($dtsLang['mod_forma_nom_cel'][$col++].$fil,$cmp);
    }
    $fil++; 
} while ($reg = $academia->extraer_registro());
  

$nomdoc = "Anexo 6A $anio.xlsx";
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $nomdoc . '"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
unset($objPHPExcel);
unset($objWriter);
exit;
