<?php
require_once(__DIR__."/../includes/sysinit.php");
include("client.php");
$_client = new Client; //new class instance

$_client->hddnClientId			= isset($_POST['hddnClientId']) ? $_POST['hddnClientId'] : 0;
$_client->selClientTypeId		= isset($_POST['selClientTypeId']) ? $_POST['selClientTypeId'] : 0;
$_client->selIdTypeId			= isset($_POST['selIdTypeId']) ? $_POST['selIdTypeId'] : 0;

//Individuals
$_client->edtClientIdNo			= isset($_POST['edtClientIdNo']) ? $_POST['edtClientIdNo'] : 0;
$_client->edtClientName			= isset($_POST['edtClientName']) ? $_POST['edtClientName'] : 0;
$_client->edtClientSurname		= isset($_POST['edtClientSurname']) ? $_POST['edtClientSurname'] : 0;


//Businesses
$_client->edtClientName		    = isset($_POST['edtClientName']) ? $_POST['edtClientName'] : 0;
$_client->edtClientVatNo		= isset($_POST['edtClientVatNo']) ? $_POST['edtClientVatNo'] : 0;
$_client->edtClientRegNo		= isset($_POST['edtClientRegNo']) ? $_POST['edtClientRegNo'] : 0;

//if ($_POST['selBusinessNature'] ?? 0)
if (isset($_POST['selBusinessNature']) ? $_POST['selBusinessNature'] : 0)
{
	$_client->selClientNatureId	= isset($_POST['selBusinessNature']) ? $_POST['selBusinessNature'] : 0;
}
else
{
//	$_client->selClientNatureId	= $_POST['selClientGender'] ?? 0;
	$_client->selClientNatureId	= isset($_POST['selClientGender']) ? $_POST['selClientGender'] : 0;
}

//Proxys
$_client->selClientParentId		= isset($_POST['selClientParentId']) ? $_POST['selClientParentId'] : 0;


$_client->edtClientEmail		= isset($_POST['edtClientEmail']) ? $_POST['edtClientEmail'] : 0;
$_client->txtClientAddress		= isset($_POST['txtClientAddress']) ? $_POST['txtClientAddress'] : 0;
$_client->edtClientPhone		= isset($_POST['edtClientPhone']) ? $_POST['edtClientPhone'] : 0;

$_client->addressLat			= isset($_POST['latitude']) ? $_POST['latitude'] : 0;
$_client->addressLng			= isset($_POST['longitude']) ? $_POST['longitude'] : 0;

$_client->vehicles				= json_decode(isset($_POST['vehicles']) ? $_POST['vehicles'] : 0, true);
$_client->addresses				= json_decode(isset($_POST['addresses']) ? $_POST['addresses'] : 0, true);

if ($_POST['action']=='0') $_client->addClient();
if ($_POST['action']=='1') $_client->addClient();
if ($_POST['action']=='2') $_client->viewClient();
if ($_POST['action']=='3') $_client->editClient();
if ($_POST['action']=='4') $_client->deleteClient();
unset($_client);
