<?php 
require_once("../datos/mysqlpersona.php");
 $p = new mysqlpersona();
 require_once("../PHPExcel_1.8.0_doc/Classes/PHPExcel.php");
 $objPHPExcel = new PHPExcel();
 $data = array();
  function add_person( $rut,$nombre,$ape_paterno,$ape_materno,$email,$celular,$tel_oficina,$direccion) {
  global $data;
			  $data []= array(
					'RUT' => $rut,
					'NOMBRE' => $nombre,
					'APE_PATERNO' => $ape_paterno,
					'APE_MATERNO' => $ape_materno ,
					'EMAIL' => $email,
					'CELULAR' => $celular,
					'TEL_OFICINA' => $tel_oficina ,
					'DIRECCION' => $direccion,
			  );
}
if(isset($_FILES['file']['name'])&&$_FILES['file']['name']!=""){
				$name = $_FILES['file']['name'];
				$tname = $_FILES['file']['tmp_name'];
				$inputFileType = PHPExcel_IOFactory::identify($tname);
                $objReader = PHPExcel_IOFactory::createReader($inputFileType);  
                $objReader->setReadDataOnly(true);
                $objPHPExcel = $objReader->load($tname);
                $total_sheets=$objPHPExcel->getSheetCount(); 
                $allSheetName=$objPHPExcel->getSheetNames(); 
                $objWorksheet = $objPHPExcel->setActiveSheetIndex(0); 
                $highestRow = $objWorksheet->getHighestRow(); 
                $highestColumn = $objWorksheet->getHighestColumn();  
                $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); 
                //EMPIECE ROW 2
                for ($row = 2; $row <= $highestRow;++$row){  
            	  	$rut=$objWorksheet->getCellByColumnAndRow(0, $row)->getFormattedValue(); 
            	  	$nombre=$objWorksheet->getCellByColumnAndRow(1, $row)->getFormattedValue(); 
            	  	$ape_paterno=$objWorksheet->getCellByColumnAndRow(2, $row)->getFormattedValue(); 
            	  	$ape_materno=$objWorksheet->getCellByColumnAndRow(3,$row)->getFormattedValue(); 
            	    $email= $objWorksheet->getCellByColumnAndRow(4, $row)->getFormattedValue();
            	  	$celular=$objWorksheet->getCellByColumnAndRow(5, $row)->getFormattedValue(); 
            	  	$tel_oficina=$objWorksheet->getCellByColumnAndRow(6, $row)->getFormattedValue(); 
            	  	$direccion=$objWorksheet->getCellByColumnAndRow(7, $row)->getFormattedValue(); 
            	   	add_person($rut,$nombre,$ape_paterno,$ape_materno,$email,$celular,$tel_oficina,$direccion);
                }
}
    $resultado = $p->UpdateClientes($data);
    if($resultado == 1){
        echo "Procedimiento Realizado con Exito";
    }
?>




