<?php 
	include_once '../../model/conexion.php';

	class Empresa_model{
		private $param = array();
	    private $con;

	    public function __construct(){
	    	$this->con = new Conexion();
	    }	


	    public function gestionar($param){
	    	$this->param = $param;
	    	switch ($this->param['param_opcion'])
			{
				case 'guardarEmpresa':
					echo $this->guardarEmpresa();
					break;
				case 'guardarDatosCorreo':
					echo $this->guardarDatosCorreo();
					break;
				case 'obtenerDatosCorreo':
					echo $this->obtenerDatosCorreo();
					break;
			}
	    }
		
	    private function guardarEmpresa(){
	    	$this->con->cerrarAbrir();
			$sql = "call sp_insertUpdateEmpresa(";
			$sql .= "0,";
			$sql .= "'".$this->param['param_ruc']."', ";
			$sql .= "'".$this->param['param_razonSocial']."', ";
			$sql .= "'".$this->param['param_nombreComercial']."', ";
			$sql .= "'".$this->param['param_domicilioFiscal']."', ";
			$sql .= "'".$this->param['param_correo']."', ";
			$sql .= "'".$this->param['param_telefono']."', ";
			$sql .= "'', ";
			$sql .= "'', ";
			$sql .= "'', ";
			$sql .= "'', ";
			$sql .= "'".$_SESSION['usuario']."',";
			$sql .= "'".$_SESSION['usuario']."',";
			$sql .= "1) ";
			

	    	$datos = $this->con->consultaRetorno($sql);
	    	while ($fila = mysqli_fetch_array($datos)) {
            	$respuesta = $fila['respuesta'];
        	}

        	return $respuesta;
	    }

		private function guardarDatosCorreo(){
	    	$this->con->cerrarAbrir();
			$sql = "call sp_insertUpdateEmpresa(";
			$sql .= "0,";
			$sql .= "'', ";
			$sql .= "'', ";
			$sql .= "'', ";
			$sql .= "'', ";
			$sql .= "'', ";
			$sql .= "'', ";
			$sql .= "'".$this->param['param_correoEnvio']."', ";
			$sql .= "'".$this->param['param_passCorreo']."', ";
			$sql .= "'".$this->param['param_cuerpoCT']."', ";
			$sql .= "'".$this->param['param_cuerpoOC']."', ";
			$sql .= "'".$_SESSION['usuario']."',";
			$sql .= "'".$_SESSION['usuario']."',";
			$sql .= "2) ";
			

	    	$datos = $this->con->consultaRetorno($sql);
	    	while ($fila = mysqli_fetch_array($datos)) {
            	$respuesta = $fila['respuesta'];
        	}

        	return $respuesta;
	    }

		private function obtenerDatosCorreo(){
			$this->con->cerrarAbrir();
			$sql = "SELECT ifnull(correoEnvio, '') as correoEnvio, 
											ifnull(passCorreo, '') as passCorreo, 
											ifnull(cuerpoCT, '') as cuerpoCT,
											ifnull(cuerpoOC, '') as cuerpoOC  FROM EMPRESA LIMIT 1";

			$datos = $this->con->consultaRetorno($sql);
           	while($fila = mysqli_fetch_array($datos)){
            	return json_encode($fila);
            } 
		}   
	}
?>