95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
|
|
/** Carregamento da classe de gerar PDF */
|
|
require_once('vendor/library/mpdf/vendor/autoload.php');
|
|
|
|
/** Importação de classes */
|
|
use vendor\model\Log;
|
|
use vendor\controller\log\LogValidate;
|
|
use vendor\model\Client;
|
|
|
|
try {
|
|
|
|
/** Instânciamento de classes */
|
|
$Log = new Log();
|
|
$LogValidate = new LogValidate();
|
|
$Client = new Client();
|
|
|
|
/** Parametros de entrada */
|
|
$key = isset($_POST['key']) ? (string)filter_input(INPUT_POST, 'key', FILTER_SANITIZE_SPECIAL_CHARS) : '';
|
|
$file = isset($_POST['file']) ? (string)filter_input(INPUT_POST, 'file', FILTER_SANITIZE_SPECIAL_CHARS) : '';
|
|
$dir = 'rel/';
|
|
$header = '';
|
|
$body = '';
|
|
$i = 0;
|
|
$robot = 0;
|
|
$color = 0;
|
|
$serverName = null;
|
|
$urlRel = $_SERVER['HTTP_HOST'];
|
|
|
|
/** Efetua a verificação dos campos de entrada */
|
|
$LogValidate->setKey($key);
|
|
$LogValidate->setFile($file);
|
|
|
|
/** Verifica se não existem erros a serem informados,
|
|
* caso não haja erro(s) salvo os dados ou
|
|
* efetua o cadastro de um novo*/
|
|
|
|
/** Verifico a existência de erros */
|
|
if (!empty($LogValidate->getErrors())) {
|
|
|
|
/** Informo */
|
|
throw new InvalidArgumentException($LogValidate->getErrors(), 0);
|
|
} else {
|
|
|
|
/** Converte o json em objeto para manipular o mesmo */
|
|
$jsonLog = json_decode($LogValidate->getFile());
|
|
|
|
/** Verifica se o cliente informado existe */
|
|
$ClientResult = $Client->GetCns($jsonLog->cns);
|
|
|
|
/** Caso o cliente não exista, cadastro o mesmo */
|
|
if ($ClientResult->client_id == 0) {
|
|
|
|
/** Caso o cliente não exista, cadastra o novo */
|
|
if (!$Client->Save(
|
|
null,
|
|
$jsonLog->cns,
|
|
$jsonLog->cartorio,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null
|
|
)) {
|
|
|
|
/** Informo */
|
|
throw new InvalidArgumentException('Não foi possível cadastrar o cartório', 0);
|
|
}
|
|
}
|
|
|
|
/** Id do cliente */
|
|
echo $clientId = $ClientResult->client_id > 0 ? $ClientResult->client_id : $Client->getId();
|
|
|
|
/** Grava o arquivo de log */
|
|
$Log->Save($clientId, $LogValidate->getFile());
|
|
|
|
}
|
|
} catch (Exception $exception) {
|
|
|
|
/** Preparo o formulario para retorno **/
|
|
$result = [
|
|
|
|
'cod' => 0,
|
|
'message' => '<div class="alert alert-danger" role="alert">' . $exception->getMessage() . '</div>',
|
|
'title' => 'Atenção',
|
|
'type' => 'exception'
|
|
|
|
];
|
|
|
|
/** Envio **/
|
|
echo json_encode($result);
|
|
|
|
/** Paro o procedimento **/
|
|
exit;
|
|
}
|