<?php 
header("Access-Control-Allow-Origin: *");
header("Content-Type:application/json; charset=UTF-8");
header("Access-Control-Allow-Methods:POST");
header("Access-Control-Max-Age:3600");
header("Access-Control-Allow-Headers:Content-Type,Access-Control-Allow-Headers,Authorization,X-Requested-With");

include_once '../Database.php';
include_once 'cliente.php';

$database = new DataBase();
$db = $database->getConnection();

$client = new CLIENTE($db);
try{
	$data = json_decode(file_get_contents("php://input"));
	
	$query = "INSERT INTO ".$client->table_name." SET nombre=:nombre,apellidop=:paterno,apellidom=:materno,correo=:email,clave=SHA(:password),status=:estado,licencia=:licencia,nivel=2,logo=:logo,fkadmin=:admin";
	$stm = $client->conn->prepare($query);
	$stm->bindParam(":nombre",$data->nombre);
	$stm->bindParam(":paterno",$data->apellidop);
	$stm->bindParam(":materno",$data->apellidom);
	$stm->bindParam(":email",$data->email);
	$stm->bindParam(":password",$data->password);
	$stm->bindParam(":estado",$data->estado);
	$stm->bindParam(":licencia",$data->licencia);
	$stm->bindParam(":logo",$data->logo);
	$stm->bindParam(":admin",$data->fkadmin);
	$stmt = $client->Insert($stm);
	if($stmt !==false){
		echo json_encode(array("Id"=>$stmt));
	}else{
		echo json_encode(array("Error"=>"No se ha creado el registro"));
	}
}catch(Exception $ex){
	echo json_encode(array("Error"=>"No se ha podido procesar la solicitud"));
}

?>