<?php
/**
 * PHPExcel
 *
 * Copyright (c) 2006 - 2015 PHPExcel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPExcel
 * @package    PHPExcel
 * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
 * @version    ##VERSION##, ##DATE##
 */

include_once("../../../php/sessionStart.php"); 
include_once("../../../php/db/dbExec.php");
include_once("../../../php/fpdf/functions.php");
include_once('../../../php/timezone.php');
include_once('../../../php/maxExecTime.php');
include_once('../../../php/functions.php');

$empCod=utf8_decode($_SESSION["empCod"]);
$empNom=utf8_decode($_SESSION["empNom"]);
$empNomc=utf8_decode($_SESSION["empNomc"]);

# QUERYS
function iCuentas($cta,$nom) {
	return "INSERT INTO cuentas(cta_emp,cta,cta_nom) VALUES ('150','$cta','$nom')";
}
# EJECUCION DE QUERYS
$db = new dbExec();

/** 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');

require_once dirname(__FILE__) . '/../../../php/PHPExcel/Classes/PHPExcel.php';
require_once dirname(__FILE__) . '/../../../php/PHPExcel/Classes/PHPExcel/IOFactory.php';

$objPHPExcel = new PHPExcel();

// Esto es para abrir y leer el Excel
$archivo = $_FILES['file']['tmp_name'];
$inputFileType = PHPExcel_IOFactory::identify($archivo);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($archivo);

// Indicamos que usaremos la primera hoja del excel
$objPHPExcel->setActiveSheetIndex(0);

// Revisa cual es la ultima fila y columna trabajada
$highestRow = $objPHPExcel->getActiveSheet()->getHighestRow(); 
$highestColumn = $objPHPExcel->getActiveSheet()->getHighestColumn();

echo $highestRow;
$nom="prueba";
// Aqui se obtienen los valores de cada celda, hasta el ultimo valor
for ($row = 2; $row <= $highestRow; $row++){ 
/*	echo $objPHPExcel->getActiveSheet()->getCell("A".$row)->getValue()." - ";
	echo $objPHPExcel->getActiveSheet()->getCell("B".$row)->getValue()." - ";
	echo $objPHPExcel->getActiveSheet()->getCell("C".$row)->getValue(); */
	$cta= $objPHPExcel->getActiveSheet()->getCell("I".$row)->getCalculatedValue();
	$nom= utf8_decode($objPHPExcel->getActiveSheet()->getCell("J".$row)->getValue());
	$resp = $db->iEx(iCuentas($cta,$nom));
} 

$resp["nombre"] = $nom;
return json_encode($resp);

//exit;
?>