<?php
include_once ("conn.php");
include_once ("funciones.php");


date_default_timezone_set("America/Panama");

session_start();

$_SESSION['database'] = $_POST['database'];

$_SESSION["c_id"] = $_POST['c_id'];
$_SESSION["c_descripcion"] = $_POST['c_descripcion'];
$_SESSION["pa_id"] = $_POST['pa_id'];
$_SESSION["ciu_id"] = $_POST['ciu_id'];
$_SESSION["c_idfiscal"] = $_POST['c_idfiscal'];
$_SESSION["c_contacto"]=$_POST['c_contacto'];
$_SESSION["c_telefono"]=$_POST['c_telefono'];
$_SESSION["c_credito"]=$_POST['c_credito'];
$_SESSION["c_dias_credito"]=$_POST['c_dias_credito'];
$_SESSION["c_limite_credito"]=$_POST['c_limite_credito'];
$_SESSION["c_vendedor"]=$_POST['c_vendedor'];
$_SESSION["id_contribuyente"]=$_POST['id_contribuyente'];
$_SESSION["c_correo"]=$_POST['c_correo'];
$_SESSION["c_exclusiv_cont"]=$_POST['c_exclusiv_cont'];
$_SESSION["c_apart"]=$_POST['c_apart'];
$_SESSION["c_activo"]=$_POST['c_activo'];
$_SESSION["suc_id"]=$_POST['suc_id'];
$_SESSION["c_ref2"]=$_POST['c_ref2'];
$_SESSION["c_precio"]=$_POST['c_precio'];
$_SESSION["c_credito"]=$_POST['c_credito'];
$_SESSION["c_direccion"]=$_POST['c_direccion'];
$_SESSION["c_u_id_mod"]=$_POST['c_u_id_mod'];
$_SESSION["c_precio"]=$_POST['c_precio'];

$hoynow = getdate();
$timeStamp= $hoynow["year"]."-".$hoynow["mon"]."-".$hoynow["mday"] ;
		
$SQL_Insert=
	"INSERT INTO ".$_SESSION['database'].".clientes (
	c_id			, c_descripcion	, pa_id,
	ciu_id			, c_idfiscal	, c_contacto,
	c_telefono		, c_credito		, c_dias_credito,
	c_limite_credito, c_vendedor	, id_contribuyente	,	
	c_correo		, c_exclusiv_cont,	c_modificacion,
	c_apart			, c_activo		, suc_id,
	c_ref2			, usermodify,
	c_direccion		, useroption	, c_u_id_mod,
	c_precio) VALUES (
	'".$_SESSION['c_id']."','".$_SESSION['c_descripcion']."','".$_SESSION['pa_id']."',
	'".$_SESSION['ciu_id']."','".$_SESSION['c_idfiscal']."','".$_SESSION['c_contacto']."',
	'".$_SESSION['c_telefono']."','".$_SESSION['c_credito']."','".$_SESSION['c_dias_credito']."',
	'".$_SESSION['c_limite_credito']."','".$_SESSION['c_vendedor']."','".$_SESSION['id_contribuyente']."',
	'".$_SESSION['c_correo']."','".$_SESSION['c_exclusiv_cont']."','".$timeStamp."',
	'".$_SESSION['c_apart']."','".$_SESSION['c_activo']."','".$_SESSION['suc_id']."',
	'".$_SESSION['c_ref2']."',1,
	'".$_SESSION['c_direccion']."',1,'".$_SESSION['c_u_id_mod']."',1)";
	//echo "sql: ".$SQL_Insert;

if ($connection->query($SQL_Insert) === TRUE) 
{
    $msg = array("success" => "true", "detalle" => "OK");
} 
else 
{
	$msg = array("success" => "false", "detalle" => $connection);
	// echo "Error: " . $SQL_Insert . "<br>" . $conn->error;
}
 
 print_r( json_encode($msg));
 
@mysqli_close($connection);
?>
