verifyToken()){
/** Instânciamento de classes */
$Client = new Client();
$ClientValidate = new ClientValidate();
/** Parametros de entrada */
$clientId = isset($_POST['client_id']) ? (int)filter_input(INPUT_POST, 'client_id', FILTER_SANITIZE_SPECIAL_CHARS) : 0 ;
$cns = isset($_POST['cns']) ? (string)filter_input(INPUT_POST, 'cns', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$name = isset($_POST['name']) ? (string)filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$state = isset($_POST['state']) ? (string)filter_input(INPUT_POST, 'state', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$city = isset($_POST['city']) ? (string)filter_input(INPUT_POST, 'city', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$responsible = isset($_POST['responsible']) ? (string)filter_input(INPUT_POST, 'responsible', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$consultant = isset($_POST['consultant']) ? (string)filter_input(INPUT_POST, 'consultant', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$typeContract = isset($_POST['type_contract']) ? (string)filter_input(INPUT_POST, 'type_contract', FILTER_SANITIZE_SPECIAL_CHARS) : '';
/** Validando os campos de entrada */
$ClientValidate->setClientId($clientId);
$ClientValidate->setCns($cns);
$ClientValidate->setName($name);
$ClientValidate->setState($state);
$ClientValidate->setCity($city);
$ClientValidate->setResponsible($responsible);
$ClientValidate->setConsultant($consultant);
$ClientValidate->setTypeContract($typeContract);
/** Verifico a existência de erros */
if (!empty($ClientValidate->getErrors())) {
/** Preparo o formulario para retorno **/
$result = [
'cod' => 0,
'title' => 'Atenção',
'message' => '
'.$ClientValidate->getErrors().'
',
];
} else {
/** Efetua um novo cadastro ou salva os novos dados */
if ($Client->Save($ClientValidate->getClientId(),
$ClientValidate->getCns(),
$ClientValidate->getName(),
$ClientValidate->getState(),
$ClientValidate->getCity(),
$ClientValidate->getResponsible(),
$ClientValidate->getConsultant(),
$ClientValidate->getTypeContract())){
/** Adição de elementos na array */
$message = ' '.($ClientValidate->getClientId() > 0 ? 'Cadastro atualizado com sucesso' : 'Cadastro efetuado com sucesso').'
';
/** Result **/
$result = [
'cod' => 200,
'title' => 'Atenção',
'message' => $message,
'redirect' => '',
];
} else {
/** Verifica se houve erros no SQL */
if($Client->getErrors()){
/** Adição de elementos na array */
$message = '' . $Client->getErrors() .'
';
} else {
/** Adição de elementos na array */
$message = '' . ($ClientValidate->getClientid() > 0 ? 'Não foi possível atualizar o cadastro' : 'Não foi possível efetuar o cadastro') .'
';
}
/** Result **/
$result = [
'cod' => 0,
'title' => 'Atenção',
'message' => $message,
];
}
}
/** Envio **/
echo json_encode($result);
/** Paro o procedimento **/
exit;
/** Caso o token de acesso seja inválido, informo */
}else{
/** Informa que o usuário precisa efetuar autenticação junto ao sistema */
$authenticate = true;
/** Informo */
throw new InvalidArgumentException('Sua sessão expirou é necessário efetuar nova autenticação junto ao sistema', 0);
}
} catch (Exception $exception) {
/** Controle de mensagens */
/*$message = 'Detalhes.: ' . 'código = ' . $exception->getCode() . ' - linha = ' . $exception->getLine() . ' - arquivo = ' . $exception->getFile() . '';
$message .= 'Mensagem.: ' . $exception->getMessage();*/
/** Preparo o formulario para retorno **/
$result = [
'cod' => 500,
'message' => ''.$exception->getMessage().'
',
'title' => 'Atenção',
'type' => 'exception',
'authenticate' => $authenticate
];
/** Envio **/
echo json_encode($result);
/** Paro o procedimento **/
exit;
}