<?php

include('../../../configuracion.php');
include('config.php');
include_once 'class.upload.php'; 



    // Comprobamos si se subió la imagen
            
                
                set_include_path(get_include_path() . PATH_SEPARATOR . 'mago/lib/');
	            include '../../lib/PHPExcel/IOFactory.php';

                $inputFileName = 'documento/cargar-listado.xlsx';	
 
                try {
                    $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
                } catch(Exception $e) {
                    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
                }

                $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
                $arrayCount = count($allDataInSheet);
 
                $datos_base = array();
                

                
                $_SESSION["conteototal"] = 0;

                $autor = $_SESSION['administrador_mago_id'];
                $fecha = date('Y-m-d H:i:s');

                for($i=2;$i<=$arrayCount;$i++){

                   
                    $codigo	  = trim($allDataInSheet[$i]["A"]);
                    $zona	  = trim($allDataInSheet[$i]["B"]);
                    $rango_1	  = str_replace(",","",trim($allDataInSheet[$i]["C"]));
                    $rango_2	  = str_replace(",","",trim($allDataInSheet[$i]["D"]));
                    $rango_3	  = str_replace(",","",trim($allDataInSheet[$i]["E"]));
                    $rango_4	  = str_replace(",","",trim($allDataInSheet[$i]["F"]));
                    $rango_5	  = str_replace(",","",trim($allDataInSheet[$i]["G"]));
                    
                    
                    $resumen = funcion::LimpiaComillaSimple($zona);

                   
                           
                        

                            $datos = array(
                                'zona' => $db->string($zona),
                                'rango_1' => $db->string($rango_1),
                                'rango_2' => $db->string($rango_2),
                                'rango_3' => $db->string($rango_3),
                                'rango_4' => $db->string($rango_4),
                                'rango_5' => $db->string($rango_5),

                            );

                            $db->update("comunas",$datos,"codigo='{$codigo}'");
                            
    
                   // echo "cargado: ".$codigo."<br>";

                    $_SESSION["conteototal"]++;
                
                }
			
	       
			// FIN DE LA CREACIÓN DEL ARCHIVO
			// ===================================================================================
         
            /////////////////////////////////////////////////////////

            header('Location:'.MAGO.'c/'.MODULO);
            exit;
?>