From c66fdfeff2cc9dee3bdd12e9037fab8d8aaf4f82 Mon Sep 17 00:00:00 2001 From: Lucas D'Avila Date: Wed, 13 Feb 2013 16:35:13 -0200 Subject: [PATCH] Melhorado cadastro de nova pessoa física, sem CPF closes #5 --- ieducar/intranet/atendidos_cad.php | 499 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ieducar/intranet/include/clsBase.inc.php | 24 ++++++++++++------------ ieducar/intranet/include/clsCadastro.inc.php | 5 +++++ ieducar/intranet/include/pessoa/clsFisica.inc.php | 14 ++++++-------- ieducar/lib/Portabilis/Utils/Validation.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ieducar/modules/Api/Views/PessoaController.php | 37 +++++++++++++++++++++++++++++++++++-- ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ ieducar/modules/Portabilis/Assets/Javascripts/Validator.js | 43 ++++++++++++++++++++++++++++++++++++++++++- ieducar/modules/Portabilis/Assets/Version.php | 2 +- 9 files changed, 495 insertions(+), 328 deletions(-) create mode 100644 ieducar/lib/Portabilis/Utils/Validation.php diff --git a/ieducar/intranet/atendidos_cad.php b/ieducar/intranet/atendidos_cad.php index 26bf0fa..5048ff8 100755 --- a/ieducar/intranet/atendidos_cad.php +++ b/ieducar/intranet/atendidos_cad.php @@ -37,8 +37,9 @@ require_once 'include/pmieducar/clsPmieducarAluno.inc.php'; require_once 'App/Model/ZonaLocalizacao.php'; -require_once 'lib/Portabilis/String/Utils.php'; -require_once 'lib/Portabilis/View/Helper/Application.php'; +require_once 'Portabilis/String/Utils.php'; +require_once 'Portabilis/View/Helper/Application.php'; +require_once 'Portabilis/Utils/Validation.php'; /** * clsIndex class. @@ -109,36 +110,12 @@ class indice extends clsCadastro function Inicializar() { - if ($_REQUEST['busca_pessoa']) { - $this->retorno = 'Novo'; + $this->cod_pessoa_fj = @$_GET['cod_pessoa_fj']; + $this->retorno = 'Novo'; - $cpf = idFederal2int($_REQUEST['busca_pessoa']); - - $this->busca_pessoa = $cpf; - $this->id_federal = $cpf; - - $objPessoa = new clsPessoaFisica(FALSE, $cpf); - $detalhePessoa = $objPessoa->detalhe(); - - $this->cod_pessoa_fj = $detalhePessoa["idpes"]; - } - elseif ($_REQUEST['cod_pessoa_fj'] != '') { - $this->busca_pessoa = TRUE; - - if ($_REQUEST['cod_pessoa_fj'] != 0) { - $this->cod_pessoa_fj = $_REQUEST['cod_pessoa_fj']; - } - else { - $this->retorno = 'Novo'; - } - } - - if ($this->cod_pessoa_fj) { - $this->cod_pessoa_fj = @$_GET['cod_pessoa'] ? - @$_GET['cod_pessoa'] : $this->cod_pessoa_fj; - - $db = new clsBanco(); - $objPessoa = new clsPessoaFisica(); + if (is_numeric($this->cod_pessoa_fj)) { + $this->retorno = 'Editar'; + $objPessoa = new clsPessoaFisica(); list($this->nm_pessoa, $this->id_federal, $this->data_nasc, $this->ddd_telefone_1, $this->telefone_1, $this->ddd_telefone_2, @@ -160,19 +137,17 @@ class indice extends clsCadastro 'idpais_estrangeiro', 'idmun_nascimento' ); + $this->id_federal = is_numeric($this->id_federal) ? int2CPF($this->id_federal) : ''; + $this->cep = is_numeric($this->cep) ? int2Cep($this->cep) : ''; + $this->data_nasc = $this->data_nasc ? dataFromPgToBr($this->data_nasc) : ''; + $this->estado_civil_id = $this->estado_civil->ideciv; $this->pais_origem_id = $this->pais_origem->idpais; $this->naturalidade_id = $this->naturalidade->idmun; - // Cor/Raça. - $raca = new clsCadastroFisicaRaca($this->cod_pessoa_fj); - $raca = $raca->detalhe(); - if (is_array($raca)) { - $this->cod_raca = $raca['ref_cod_raca']; - } - - $this->cep = int2Cep($this->cep); - $this->retorno = 'Editar'; + $raca = new clsCadastroFisicaRaca($this->cod_pessoa_fj); + $raca = $raca->detalhe(); + $this->cod_raca = is_array($raca) ? $raca['ref_cod_raca'] : null; } $this->nome_url_cancelar = 'Cancelar'; @@ -182,284 +157,250 @@ class indice extends clsCadastro function Gerar() { - $this->addBanner('imagens/nvp_top_intranet.jpg', - 'imagens/nvp_vert_intranet.jpg', 'Intranet', FALSE); - - if (! $this->busca_pessoa) { - $this->campoOculto('cod_pessoa_fj', ''); - - $parametros = new clsParametrosPesquisas(); - $parametros->setSubmit(1); - $parametros->adicionaCampoTexto('busca_pessoa', 'id_federal'); - $parametros->adicionaCampoTexto('cod_pessoa_fj', 'idpes'); - $parametros->setPessoa('F'); - $parametros->setPessoaCampo('cod_pessoa_fj'); - $parametros->setPessoaNovo('S'); - $parametros->setPessoaTela('window'); - - $html = sprintf( - '');\"". - '>', - $parametros->serializaCampos() - ); + $this->url_cancelar = $this->retorno == 'Editar' ? + 'atendidos_det.php?cod_pessoa=' . $this->cod_pessoa_fj : 'atendidos_lst.php'; - $this->campoCpf('busca_pessoa', 'CPF', $this->ref_cod_pessoa_fj, TRUE, - $html, FALSE, TRUE); - } - else { - $this->campoOculto('busca_pessoa', $this->busca_pessoa); + $this->campoOculto('cod_pessoa_fj', $this->cod_pessoa_fj); + $this->campoTexto('nm_pessoa', 'Nome', $this->nm_pessoa, '50', '255', TRUE); - $this->url_cancelar = $this->retorno == 'Editar' ? - 'atendidos_det.php?cod_pessoa=' . $this->cod_pessoa_fj : 'atendidos_lst.php'; + $this->campoCpf('id_federal', 'CPF', $this->id_federal, FALSE); - $this->campoOculto('cod_pessoa_fj', $this->cod_pessoa_fj); - $this->campoTexto('nm_pessoa', 'Nome', $this->nm_pessoa, '50', '255', TRUE); - - if ($this->id_federal) { - $this->campoRotulo('id_federal', 'CPF', int2CPF($this->id_federal)); - } - else { - $this->campoCpf('id_federal', 'CPF', '', FALSE); - } - - if ($this->data_nasc) { - $this->data_nasc = dataFromPgToBr($this->data_nasc); - } + $this->campoData('data_nasc', 'Data de Nascimento', $this->data_nasc); - $this->campoData('data_nasc', 'Data de Nascimento', $this->data_nasc); + $lista_sexos = array(); + $lista_sexos[''] = 'Escolha uma opção...'; + $lista_sexos['M'] = 'Masculino'; + $lista_sexos['F'] = 'Feminino'; + $this->campoLista('sexo', 'Sexo', $lista_sexos, $this->sexo); - $lista_sexos = array(); - $lista_sexos[''] = 'Escolha uma opção...'; - $lista_sexos['M'] = 'Masculino'; - $lista_sexos['F'] = 'Feminino'; - $this->campoLista('sexo', 'Sexo', $lista_sexos, $this->sexo); + $this->inputsHelper()->estadoCivil(array('required' => false)); - $this->inputsHelper()->estadoCivil(array('required' => false)); + // pai, mãe - // pai, mãe + $this->addPaiInput(); + $this->addMaeInput(); - $this->addPaiInput(); - $this->addMaeInput(); + // Cor/raça. + $opcoes_raca = array('' => 'Selecione'); + $obj_raca = new clsCadastroRaca(); + $lst_raca = $obj_raca->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE); - // Cor/raça. - $opcoes_raca = array('' => 'Selecione'); - $obj_raca = new clsCadastroRaca(); - $lst_raca = $obj_raca->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE); - - if ($lst_raca) { - foreach ($lst_raca as $raca) { - $opcoes_raca[$raca['cod_raca']] = $raca['nm_raca']; - } + if ($lst_raca) { + foreach ($lst_raca as $raca) { + $opcoes_raca[$raca['cod_raca']] = $raca['nm_raca']; } + } - $this->campoLista('cor_raca', 'Raça', $opcoes_raca, - $this->cod_raca, '', FALSE, '', '', '', FALSE); + $this->campoLista('cor_raca', 'Raça', $opcoes_raca, + $this->cod_raca, '', FALSE, '', '', '', FALSE); - // nacionalidade + // nacionalidade - // tipos - $tiposNacionalidade = array(null => 'Selecione', - '1' => 'Brasileiro', - '2' => 'Naturalizado brasileiro', - '3' => 'Estrangeiro'); + // tipos + $tiposNacionalidade = array(null => 'Selecione', + '1' => 'Brasileiro', + '2' => 'Naturalizado brasileiro', + '3' => 'Estrangeiro'); - $options = array('label' => 'Nacionalidade', - 'resources' => $tiposNacionalidade, - 'required' => false, - 'inline' => true, - 'value' => $this->tipo_nacionalidade); + $options = array('label' => 'Nacionalidade', + 'resources' => $tiposNacionalidade, + 'required' => false, + 'inline' => true, + 'value' => $this->tipo_nacionalidade); - $this->inputsHelper()->select('tipo_nacionalidade', $options); + $this->inputsHelper()->select('tipo_nacionalidade', $options); - // pais origem + // pais origem - $options = array('label' => '', 'required' => true); - $helperOptions = array('objectName' => 'pais_origem', - 'hiddenInputOptions' => array('options' => array('value' => $this->pais_origem_id))); + $options = array('label' => '', 'required' => true); + $helperOptions = array('objectName' => 'pais_origem', + 'hiddenInputOptions' => array('options' => array('value' => $this->pais_origem_id))); - $this->inputsHelper()->simpleSearchPais('nome', $options, $helperOptions); + $this->inputsHelper()->simpleSearchPais('nome', $options, $helperOptions); - // naturalidade + // naturalidade - $options = array('label' => 'Naturalidade', 'required' => false); - $helperOptions = array('objectName' => 'naturalidade', - 'hiddenInputOptions' => array('options' => array('value' => $this->naturalidade_id))); + $options = array('label' => 'Naturalidade', 'required' => false); + $helperOptions = array('objectName' => 'naturalidade', + 'hiddenInputOptions' => array('options' => array('value' => $this->naturalidade_id))); - $this->inputsHelper()->simpleSearchMunicipio('nome', $options, $helperOptions); + $this->inputsHelper()->simpleSearchMunicipio('nome', $options, $helperOptions); - // Detalhes do Endereço + // Detalhes do Endereço - $objTipoLog = new clsTipoLogradouro(); - $listaTipoLog = $objTipoLog->lista(); - $listaTLog = array('0' => 'Selecione'); + $objTipoLog = new clsTipoLogradouro(); + $listaTipoLog = $objTipoLog->lista(); + $listaTLog = array('0' => 'Selecione'); - if ($listaTipoLog) { - foreach ($listaTipoLog as $tipoLog) { - $listaTLog[$tipoLog['idtlog']] = $tipoLog['descricao']; - } + if ($listaTipoLog) { + foreach ($listaTipoLog as $tipoLog) { + $listaTLog[$tipoLog['idtlog']] = $tipoLog['descricao']; } + } - $objUf = new clsUf(); - $listauf = $objUf->lista(); - $listaEstado = array('0' => 'Selecione'); + $objUf = new clsUf(); + $listauf = $objUf->lista(); + $listaEstado = array('0' => 'Selecione'); - if ($listauf) { - foreach ($listauf as $uf) { - $listaEstado[$uf['sigla_uf']] = $uf['sigla_uf']; - } + if ($listauf) { + foreach ($listauf as $uf) { + $listaEstado[$uf['sigla_uf']] = $uf['sigla_uf']; } + } - $this->campoOculto('idbai', $this->idbai); - $this->campoOculto('idlog', $this->idlog); - $this->campoOculto('cep', $this->cep); - $this->campoOculto('ref_sigla_uf', $this->sigla_uf); - $this->campoOculto('ref_idtlog', $this->idtlog); - $this->campoOculto('id_cidade', $this->cidade); + $this->campoOculto('idbai', $this->idbai); + $this->campoOculto('idlog', $this->idlog); + $this->campoOculto('cep', $this->cep); + $this->campoOculto('ref_sigla_uf', $this->sigla_uf); + $this->campoOculto('ref_idtlog', $this->idtlog); + $this->campoOculto('id_cidade', $this->cidade); - $zona = App_Model_ZonaLocalizacao::getInstance(); + $zona = App_Model_ZonaLocalizacao::getInstance(); - if ($this->idlog && $this->idbai && $this->cep && $this->cod_pessoa_fj) { - $this->campoCep('cep_', 'CEP', $this->cep, true, '-', - " ');\">", - TRUE); + if ($this->idlog && $this->idbai && $this->cep && $this->cod_pessoa_fj) { + $this->campoCep('cep_', 'CEP', $this->cep, true, '-', + " ');\">", + TRUE); - $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog, - FALSE, FALSE, FALSE, FALSE, TRUE); + $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog, + FALSE, FALSE, FALSE, FALSE, TRUE); - $this->campoTextoInv('logradouro', 'Logradouro', $this->logradouro, - '50', '255', FALSE); + $this->campoTextoInv('logradouro', 'Logradouro', $this->logradouro, + '50', '255', FALSE); - $this->campoTextoInv('cidade', 'Cidade', $this->cidade, '50', '255', - FALSE); + $this->campoTextoInv('cidade', 'Cidade', $this->cidade, '50', '255', + FALSE); - $this->campoTextoInv('bairro', 'Bairro', $this->bairro, '50', '255', FALSE); + $this->campoTextoInv('bairro', 'Bairro', $this->bairro, '50', '255', FALSE); - $this->campoTexto('complemento', 'Complemento', $this->complemento, '50', '255', - FALSE); + $this->campoTexto('complemento', 'Complemento', $this->complemento, '50', '255', + FALSE); - $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); + $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); - $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); + $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); - $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento, '6', '6', - FALSE); + $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento, '6', '6', + FALSE); - $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE); - $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); + $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE); + $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); - $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf, - FALSE, FALSE, FALSE, FALSE, TRUE); - } - elseif($this->cod_pessoa_fj && $this->cep) { - $this->campoCep('cep_', 'CEP', $this->cep, true, '-', - " ');\">", - $disabled); + $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf, + FALSE, FALSE, FALSE, FALSE, TRUE); + } + elseif($this->cod_pessoa_fj && $this->cep) { + $this->campoCep('cep_', 'CEP', $this->cep, true, '-', + " ');\">", + $disabled); - $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog); + $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog); - $this->campoTexto('logradouro', 'Logradouro', $this->logradouro, '50', - '255', FALSE); + $this->campoTexto('logradouro', 'Logradouro', $this->logradouro, '50', + '255', FALSE); - $this->campoTexto('cidade', 'Cidade', $this->cidade, '50', '255', FALSE); + $this->campoTexto('cidade', 'Cidade', $this->cidade, '50', '255', FALSE); - $this->campoTexto('bairro', 'Bairro', $this->bairro, '50', '255', FALSE); + $this->campoTexto('bairro', 'Bairro', $this->bairro, '50', '255', FALSE); - $this->campoTexto('complemento', 'Complemento', $this->complemento, '50', - '255', FALSE); + $this->campoTexto('complemento', 'Complemento', $this->complemento, '50', + '255', FALSE); - $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); + $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); - $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); + $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); - $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento, - '6', '6', FALSE); + $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento, + '6', '6', FALSE); - $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE); + $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE); - $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); + $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); - $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf); - } - else { - $this->campoCep('cep_', 'CEP', $this->cep, TRUE, '-', - " ');\">", - false - ); + $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf); + } + else { + $this->campoCep('cep_', 'CEP', $this->cep, TRUE, '-', + " ');\">", + false + ); - $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog, - FALSE, FALSE, FALSE, FALSE, FALSE); + $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog, + FALSE, FALSE, FALSE, FALSE, FALSE); - $this->campoTexto('logradouro', 'Logradouro', $this->logradouro, - '50', '255'); + $this->campoTexto('logradouro', 'Logradouro', $this->logradouro, + '50', '255'); - $this->campoTexto('cidade', 'Cidade', $this->cidade, '50', '255'); + $this->campoTexto('cidade', 'Cidade', $this->cidade, '50', '255'); - $this->campoTexto('bairro', 'Bairro', $this->bairro, '50', '255'); + $this->campoTexto('bairro', 'Bairro', $this->bairro, '50', '255'); - $this->campoTexto('complemento', 'Complemento', $this->complemento, - '50', '255', FALSE); + $this->campoTexto('complemento', 'Complemento', $this->complemento, + '50', '255', FALSE); - $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); + $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); - $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); + $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); - $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento, - '6', '6', FALSE); + $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento, + '6', '6', FALSE); - $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE); + $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE); - $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); + $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); - $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf, - FALSE, FALSE, FALSE, FALSE, FALSE); - } + $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf, + FALSE, FALSE, FALSE, FALSE, FALSE); + } - $this->campoLista('zona_localizacao', 'Zona Localização', $zona->getEnums(), - $this->zona_localizacao, FALSE, FALSE, FALSE, FALSE, - ($this->idbai ? TRUE : FALSE) - ); + $this->campoLista('zona_localizacao', 'Zona Localização', $zona->getEnums(), + $this->zona_localizacao, FALSE, FALSE, FALSE, FALSE, + ($this->idbai ? TRUE : FALSE) + ); - $this->campoTexto('ddd_telefone_1', 'DDD Telefone 1', $this->ddd_telefone_1, - '3', '2', FALSE); + $this->campoTexto('ddd_telefone_1', 'DDD Telefone 1', $this->ddd_telefone_1, + '3', '2', FALSE); - $this->campoTexto('telefone_1', 'Telefone 1', $this->telefone_1, '10', - '15', FALSE); + $this->campoTexto('telefone_1', 'Telefone 1', $this->telefone_1, '10', + '15', FALSE); - $this->campoTexto('ddd_telefone_2', 'DDD Telefone 2', $this->ddd_telefone_2, - '3', '2', FALSE); + $this->campoTexto('ddd_telefone_2', 'DDD Telefone 2', $this->ddd_telefone_2, + '3', '2', FALSE); - $this->campoTexto('telefone_2', 'Telefone 2', $this->telefone_2, '10', - '15', FALSE); + $this->campoTexto('telefone_2', 'Telefone 2', $this->telefone_2, '10', + '15', FALSE); - $this->campoTexto('ddd_telefone_mov', 'DDD Celular', - $this->ddd_telefone_mov, '3', '2', FALSE); + $this->campoTexto('ddd_telefone_mov', 'DDD Celular', + $this->ddd_telefone_mov, '3', '2', FALSE); - $this->campoTexto('telefone_mov', 'Celular', $this->telefone_mov, '10', - '15', FALSE); + $this->campoTexto('telefone_mov', 'Celular', $this->telefone_mov, '10', + '15', FALSE); - $this->campoTexto('ddd_telefone_fax', 'DDD Fax', $this->ddd_telefone_fax, - '3', '2', FALSE); + $this->campoTexto('ddd_telefone_fax', 'DDD Fax', $this->ddd_telefone_fax, + '3', '2', FALSE); - $this->campoTexto('telefone_fax', 'Fax', $this->telefone_fax, '10', '15', - FALSE); + $this->campoTexto('telefone_fax', 'Fax', $this->telefone_fax, '10', '15', + FALSE); - $this->campoTexto('http', 'Site', $this->http, '50', '255', FALSE); + $this->campoTexto('http', 'Site', $this->http, '50', '255', FALSE); - $this->campoTexto('email', 'E-mail', $this->email, '50', '255', FALSE); + $this->campoTexto('email', 'E-mail', $this->email, '50', '255', FALSE); - if ($this->cod_pessoa_fj) { - $this->campoRotulo('documentos', 'Documentos', - "cod_pessoa_fj}'); \">"); + if ($this->cod_pessoa_fj) { + $this->campoRotulo('documentos', 'Documentos', + "cod_pessoa_fj}'); \">"); - $this->campoCheck('alterado', 'Alterado', $this->alterado); - } + $this->campoCheck('alterado', 'Alterado', $this->alterado); } - $styles = array('/modules/Portabilis/Assets/Stylesheets/Frontend.css'); + $styles = array( + '/modules/Portabilis/Assets/Stylesheets/Frontend.css', + '/modules/Portabilis/Assets/Stylesheets/Frontend/Resource.css' + ); + Portabilis_View_Helper_Application::loadStylesheet($this, $styles); $script = "/modules/Cadastro/Assets/Javascripts/PessoaFisica.js"; @@ -468,37 +409,17 @@ class indice extends clsCadastro function Novo() { - @session_start(); - $pessoaFj = $_SESSION['id_pessoa']; - session_write_close(); - - $db = new clsBanco(); - $db2 = new clsBanco(); - $ref_cod_sistema = FALSE; - - if ($this->id_federal) { - $this->id_federal = idFederal2int($this->id_federal); - - $objCPF = new clsFisica(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, $this->id_federal); - - $detalhe_fisica = $objCPF->detalhe(); - if ($detalhe_fisica['cpf']) { - $this->erros['id_federal'] = 'CPF já cadastrado.'; - return FALSE; - } - } + if (! $this->validatesCpf($this->id_federal)) + return false; // pessoa - $objPessoa = new clsPessoa_(FALSE, $this->nm_pessoa, $pessoaFj, $this->http, - 'F', FALSE, FALSE, $this->email); + $objPessoa = new clsPessoa_(FALSE, $this->nm_pessoa, $this->currentUserId(), $this->http, + 'F', FALSE, FALSE, $this->email); $idpes = $objPessoa->cadastra(); - // pessoa fisica $fisica = new clsFisica(); @@ -507,7 +428,7 @@ class indice extends clsCadastro $fisica->data_nasc = dataToBanco($this->data_nasc); $fisica->sexo = $this->sexo; $fisica->ref_cod_sistema = 'NULL'; - $fisica->cpf = $this->id_federal; + $fisica->cpf = idFederal2int($this->id_federal); $fisica->ideciv = $this->estado_civil_id; $fisica->idpes_pai = $this->pai_id; $fisica->idpes_mae = $this->mae_id; @@ -570,32 +491,14 @@ class indice extends clsCadastro function Editar() { - @session_start(); - $pessoaFj = $_SESSION['id_pessoa']; - session_write_close(); - - if ($this->id_federal) { - $this->id_federal = idFederal2int($this->id_federal); - - $objFisicaCpf = new clsFisica($this->cod_pessoa_fj); - $detalhe_fisica = $objFisicaCpf->detalhe(); - - if (! $detalhe_fisica['cpf']) { - $objCPF = new clsFisica(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, $this->id_federal); - - if ($objCPF->detalhe()) { - $this->erros['id_federal'] = 'CPF já cadastrado.'; - return FALSE; - } - } - } + if (! $this->validatesCpf($this->id_federal)) + return false; // pessoa $objPessoa = new clsPessoa_($this->cod_pessoa_fj, $this->nm_pessoa, FALSE, - $this->p_http, FALSE, $pessoaFj, date('Y-m-d H:i:s', time()), $this->email); + $this->p_http, FALSE, $this->currentUserId(), + date('Y-m-d H:i:s', time()), $this->email); $objPessoa->edita(); @@ -607,7 +510,7 @@ class indice extends clsCadastro $fisica->data_nasc = dataToBanco($this->data_nasc); $fisica->sexo = $this->sexo; $fisica->ref_cod_sistema = 'NULL'; - $fisica->cpf = $this->id_federal; + $fisica->cpf = $this->id_federal ? idFederal2int($this->id_federal) : 'NULL'; $fisica->ideciv = $this->estado_civil_id; $fisica->idpes_pai = $this->pai_id; @@ -759,6 +662,30 @@ class indice extends clsCadastro $this->inputsHelper()->simpleSearchPessoa('nome', $options, $helperOptions); } + + protected function validatesCpf($cpf) { + $isValid = true; + + if ($cpf && ! Portabilis_Utils_Validation::validatesCpf($cpf)) { + $this->erros['id_federal'] = 'CPF inválido.'; + $isValid = false; + } + elseif($cpf) { + $fisica = new clsFisica(); + $fisica->cpf = idFederal2int($cpf); + $fisica = $fisica->detalhe(); + + if ($fisica['cpf'] && $this->cod_pessoa_fj != $fisica['idpes']) { + $link = "{$fisica['idpes']}"; + + $this->erros['id_federal'] = "CPF já utilizado pela pessoa $link."; + $isValid = false; + } + } + + return $isValid; + } } // Instancia objeto de página diff --git a/ieducar/intranet/include/clsBase.inc.php b/ieducar/intranet/include/clsBase.inc.php index fa96da6..726882f 100755 --- a/ieducar/intranet/include/clsBase.inc.php +++ b/ieducar/intranet/include/clsBase.inc.php @@ -49,8 +49,8 @@ require_once 'include/Geral.inc.php'; require_once 'include/pmicontrolesis/geral.inc.php'; require_once 'include/funcoes.inc.php'; -require_once 'lib/Portabilis/Utils/Database.php'; -require_once 'lib/Portabilis/Utils/User.php'; +require_once 'Portabilis/Utils/Database.php'; +require_once 'Portabilis/Utils/User.php'; require_once 'modules/Error/Mailers/NotificationMailer.php'; @@ -219,7 +219,7 @@ class clsBase extends clsConfig } if ($processo_ap != 0) { - $this->db()->Consulta("SELECT 1 FROM menu_funcionario WHERE ref_cod_menu_submenu = 0 AND ref_ref_cod_pessoa_fj = {$this->_currentUserId()}"); + $this->db()->Consulta("SELECT 1 FROM menu_funcionario WHERE ref_cod_menu_submenu = 0 AND ref_ref_cod_pessoa_fj = {$this->currentUserId()}"); if ($this->db()->ProximoRegistro()) { list($aui) = $this->db()->Tupla(); $sempermissao = FALSE; @@ -229,7 +229,7 @@ class clsBase extends clsConfig // permissão de acesso ao processo. Já a segunda, não existe // sentido para nivel = 2 já que processoAp pode ser de níveis // maiores que 2. - $this->db()->Consulta("SELECT 1 FROM menu_funcionario WHERE (ref_cod_menu_submenu = {$processo_ap} AND ref_ref_cod_pessoa_fj = {$this->_currentUserId()}) OR (SELECT true FROM menu_submenu WHERE cod_menu_submenu = {$processo_ap} AND nivel = 2)"); + $this->db()->Consulta("SELECT 1 FROM menu_funcionario WHERE (ref_cod_menu_submenu = {$processo_ap} AND ref_ref_cod_pessoa_fj = {$this->currentUserId()}) OR (SELECT true FROM menu_submenu WHERE cod_menu_submenu = {$processo_ap} AND nivel = 2)"); if ($this->db()->ProximoRegistro()) { list($aui) = $this->db()->Tupla(); $sempermissao = FALSE; @@ -257,8 +257,8 @@ class clsBase extends clsConfig $variaveis = "POST\n{$posts}GET\n{$gets}SESSION\n{$sessions}"; - if ($this->_currentUserId()) { - $this->db()->Consulta("INSERT INTO intranet_segur_permissao_negada (ref_ref_cod_pessoa_fj, ip_externo, ip_interno, data_hora, pagina, variaveis) VALUES('{$this->_currentUserId()}', '$ip', '$ip_de_rede', NOW(), '$pagina', '$variaveis')"); + if ($this->currentUserId()) { + $this->db()->Consulta("INSERT INTO intranet_segur_permissao_negada (ref_ref_cod_pessoa_fj, ip_externo, ip_interno, data_hora, pagina, variaveis) VALUES('{$this->currentUserId()}', '$ip', '$ip_de_rede', NOW(), '$pagina', '$variaveis')"); } else { $this->db()->Consulta("INSERT INTO intranet_segur_permissao_negada (ref_ref_cod_pessoa_fj, ip_externo, ip_interno, data_hora, pagina, variaveis) VALUES(NULL, '$ip', '$ip_de_rede', NOW(), '$pagina', '$variaveis')"); @@ -544,7 +544,7 @@ class clsBase extends clsConfig $menu_dinamico = $this->makeBanner(); $notificacao = ""; - $this->db()->Consulta("SELECT cod_notificacao, titulo, conteudo, url FROM portal.notificacao WHERE ref_cod_funcionario = '{$this->_currentUserId()}' AND data_hora_ativa < NOW()"); + $this->db()->Consulta("SELECT cod_notificacao, titulo, conteudo, url FROM portal.notificacao WHERE ref_cod_funcionario = '{$this->currentUserId()}' AND data_hora_ativa < NOW()"); if ($this->db()->numLinhas()) { while ($this->db()->ProximoRegistro()) { @@ -560,18 +560,18 @@ class clsBase extends clsConfig "; } $saida = str_replace( "", $notificacao, $saida ); - $this->db()->Consulta("UPDATE portal.notificacao SET visualizacoes = visualizacoes + 1 WHERE ref_cod_funcionario = '{$this->_currentUserId()}' AND data_hora_ativa < NOW()"); + $this->db()->Consulta("UPDATE portal.notificacao SET visualizacoes = visualizacoes + 1 WHERE ref_cod_funcionario = '{$this->currentUserId()}' AND data_hora_ativa < NOW()"); $this->db()->Consulta("DELETE FROM portal.notificacao WHERE visualizacoes > 10"); } // nome completo usuario $nomePessoa = new clsPessoaFisica(); - list($nomePessoa) = $nomePessoa->queryRapida($this->_currentUserId(), "nome"); + list($nomePessoa) = $nomePessoa->queryRapida($this->currentUserId(), "nome"); $nomePessoa = ($nomePessoa) ? $nomePessoa : "Convidado"; // data ultimo acesso - $ultimoAcesso = $this->db()->UnicoCampo("SELECT data_hora FROM acesso WHERE cod_pessoa = {$this->_currentUserId()} ORDER BY data_hora DESC LIMIT 1,1"); + $ultimoAcesso = $this->db()->UnicoCampo("SELECT data_hora FROM acesso WHERE cod_pessoa = {$this->currentUserId()} ORDER BY data_hora DESC LIMIT 1,1"); if($ultimoAcesso) $ultimoAcesso = date("d/m/Y H:i", strtotime(substr($ultimoAcesso,0,19))); @@ -595,7 +595,7 @@ class clsBase extends clsConfig $ip_maquina = $_SERVER['REMOTE_ADDR']; } - $sql = "UPDATE funcionario SET ip_logado = '$ip_maquina' , data_login = NOW() WHERE ref_cod_pessoa_fj = {$this->_currentUserId()}"; + $sql = "UPDATE funcionario SET ip_logado = '$ip_maquina' , data_login = NOW() WHERE ref_cod_pessoa_fj = {$this->currentUserId()}"; $this->db()->Consulta($sql); return $saida; @@ -844,7 +844,7 @@ class clsBase extends clsConfig return Portabilis_Utils_Database::db(); } - function _currentUserId() { + protected function currentUserId() { return Portabilis_Utils_User::currentUserId(); } } diff --git a/ieducar/intranet/include/clsCadastro.inc.php b/ieducar/intranet/include/clsCadastro.inc.php index 272f10b..dd2a1a4 100755 --- a/ieducar/intranet/include/clsCadastro.inc.php +++ b/ieducar/intranet/include/clsCadastro.inc.php @@ -36,6 +36,7 @@ if (class_exists('clsPmiajudaPagina')) { require_once 'Portabilis/View/Helper/Application.php'; require_once 'Portabilis/View/Helper/Inputs.php'; +require_once 'Portabilis/Utils/User.php'; /** * clsCadastro class. @@ -731,4 +732,8 @@ class clsCadastro extends clsCampos return $this->_inputsHelper; } + + protected function currentUserId() { + return Portabilis_Utils_User::currentUserId(); + } } diff --git a/ieducar/intranet/include/pessoa/clsFisica.inc.php b/ieducar/intranet/include/pessoa/clsFisica.inc.php index c804c28..2779a2f 100755 --- a/ieducar/intranet/include/pessoa/clsFisica.inc.php +++ b/ieducar/intranet/include/pessoa/clsFisica.inc.php @@ -288,7 +288,7 @@ class clsFisica $campos .= ", nome_conjuge"; $valores .= ", '$this->nome_conjuge' "; } - if(is_string($this->nome-responsavel)) + if(is_string($this->nome_responsavel)) { $campos .= ", nome_responsavel"; $valores .= ", '$this->nome_responsavel' "; @@ -459,20 +459,18 @@ class clsFisica $set .= "$gruda idpes_rev = '{$this->idpes_rev}'"; $gruda = ", "; } - if($this->cpf) - { - $set .= "$gruda cpf = '{$this->cpf}'"; + + if($this->cpf) { + $set .= "$gruda cpf = {$this->cpf}"; $gruda = ", "; } - if(is_numeric($this->ref_cod_sistema) || $this->ref_cod_sistema == "NULL") - { + if(is_numeric($this->ref_cod_sistema) || $this->ref_cod_sistema == "NULL") { $set .= "$gruda ref_cod_sistema = {$this->ref_cod_sistema}"; $gruda = ", "; } - if(is_numeric($this->ref_cod_religiao)) - { + if(is_numeric($this->ref_cod_religiao)) { $set .= "$gruda ref_cod_religiao = {$this->ref_cod_religiao}"; $gruda = ", "; } diff --git a/ieducar/lib/Portabilis/Utils/Validation.php b/ieducar/lib/Portabilis/Utils/Validation.php new file mode 100644 index 0000000..5d2e007 --- /dev/null +++ b/ieducar/lib/Portabilis/Utils/Validation.php @@ -0,0 +1,80 @@ + + * + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) + * qualquer versão posterior. + * + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU + * ADEQUAÇÃO A UMA FINALIDADE ESPECÃFICA. Consulte a Licença Pública Geral + * do GNU para mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto + * com este programa; se não, escreva para a Free Software Foundation, Inc., no + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. + * + * @author Lucas D'Avila + * @category i-Educar + * @license @@license@@ + * @package Portabilis + * @since Arquivo disponível desde a versão 1.1.0 + * @version $Id$ + */ + +require_once 'lib/Portabilis/Utils/User.php'; + +/** + * Portabilis_Utils_Validation class. + * + * @author Lucas D'Avila + * @category i-Educar + * @license @@license@@ + * @package Portabilis + * @since Classe disponível desde a versão 1.1.0 + * @version @@package_version@@ + */ +class Portabilis_Utils_Validation { + + public static function validatesCpf($cpf) { + $cpf = preg_replace('/[^0-9]/', '', (string)$cpf); + + if (strlen($cpf) != 11) + return false; + + // calcula primeiro dígito verificador + $soma = 0; + + for ($i = 0; $i < 9; $i++) + $soma += ((10 - $i) * $cpf[$i]); + + $primeiroDigito = 11 - ($soma % 11); + + if ($primeiroDigito >= 10) + $primeiroDigito = 0; + + + // calcula segundo dígito verificador + $soma = 0; + + for ($i = 0; $i < 10; $i++) + $soma += ((11 - $i) * $cpf[$i]); + + $segundoDigito = 11 - ($soma % 11); + + if ($segundoDigito >= 10) + $segundoDigito = 0; + + + return ($primeiroDigito == $cpf[9] && $segundoDigito == $cpf[10]); + } +} diff --git a/ieducar/modules/Api/Views/PessoaController.php b/ieducar/modules/Api/Views/PessoaController.php index 829bc23..94e3f78 100644 --- a/ieducar/modules/Api/Views/PessoaController.php +++ b/ieducar/modules/Api/Views/PessoaController.php @@ -39,6 +39,20 @@ require_once 'lib/Portabilis/String/Utils.php'; class PessoaController extends ApiCoreController { + protected function canGet() { + $can = true; + + if (! $this->getRequest()->id && ! $this->getRequest()->cpf) { + $can = false; + $this->messenger->append("É necessário receber uma variavel 'id' ou 'cpf'"); + } + + elseif ($this->getRequest()->id) + $can = $this->validatesResourceId(); + + return $can; + } + // validators // overwrite api core validator @@ -72,6 +86,21 @@ class PessoaController extends ApiCoreController return $pessoa; } + protected function loadPessoaByCpf($cpf = null) { + $cpf = preg_replace('/[^0-9]/', '', (string)$cpf); + + if (! $cpf) + throw new Exception("CPF deve conter caracteres numéricos"); + + $sql = "select pessoa.idpes as id, nome from cadastro.pessoa, fisica + where fisica.idpes = pessoa.idpes and cpf = $1 limit 1"; + + $pessoa = $this->fetchPreparedQuery($sql, $cpf, false, 'first-row'); + $pessoa['nome'] = $this->toUtf8($pessoa['nome'], array('transform' => true)); + + return $pessoa; + } + protected function loadDetails($pessoaId = null) { $alunoId = $this->tryLoadAlunoId($pessoaId); @@ -144,9 +173,13 @@ class PessoaController extends ApiCoreController $pessoa = array(); if ($this->canGet()) { - $attrs = array('id', 'nome'); - $pessoa = $this->loadPessoa($this->getRequest()->id); + if ($this->getRequest()->id) + $pessoa = $this->loadPessoa($this->getRequest()->id); + else + $pessoa = $this->loadPessoaByCpf($this->getRequest()->cpf); + + $attrs = array('id', 'nome'); $pessoa = Portabilis_Array_Utils::filter($pessoa, $attrs); $details = $this->loadDetails($this->getRequest()->id); diff --git a/ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js b/ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js index 6f2b5fb..13241e7 100644 --- a/ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js +++ b/ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js @@ -1,38 +1,121 @@ +(function($) { + $(document).ready(function() { -// simple search options + var $form = $j('#formcadastro'); + var $submitButton = $j('#btn_enviar'); + var $cpfField = $j('#id_federal'); + var $cpfNotice = $j('').html('') + .addClass('error resource-notice') + .hide() + .width($j('#nm_pessoa').outerWidth() - 12) + .appendTo($cpfField.parent()); -/*var simpleSearchPaisOrigemOptions = { - placeholder : safeUtf8Decode('Informe o código ou nome do pais de origem') -};*/ -// when page is ready + var handleGetPersonByCpf = function(dataResponse) { + handleMessages(dataResponse.msgs); + $cpfNotice.hide(); -(function($) { - $(document).ready(function() { + var pessoaId = dataResponse.id; - // hide or show #pais_origem_nome by #tipo_nacionalidade + if (pessoaId && pessoaId != $j('#cod_pessoa_fj').val()) { + $cpfNotice.html(stringUtils.toUtf8('CPF já utilizado pela pessoa código ' + pessoaId + ', ')).slideDown('fast'); + + $j('').addClass('decorated') + .attr('href', '/intranet/atendidos_cad.php?cod_pessoa_fj=' + pessoaId) + .attr('target', '_blank') + .html('acessar cadastro.') + .appendTo($cpfNotice); + + $j('body').animate({ scrollTop: $j('body').offset().top }, 'fast'); + } + + else if ($j(document).data('submit_form_after_ajax_validation')) + formUtils.submit(); + } + + + var getPersonByCpf = function(cpf) { + var options = { + url : getResourceUrlBuilder.buildUrl('/module/Api/pessoa', 'pessoa'), + dataType : 'json', + data : { cpf : cpf }, + success : handleGetPersonByCpf, + + // forçado requisições sincronas, evitando erro com requisições ainda não concluidas, + // como no caso, onde o usuário pressiona cancelar por exemplo. + async : false + }; - var checkTipoNacionalidade = function(){ + getResource(options); + } + + + // hide or show #pais_origem_nome by #tipo_nacionalidade + var checkTipoNacionalidade = function() { if ($j.inArray($j('#tipo_nacionalidade').val(), ['2', '3']) > -1) $j('#pais_origem_nome').show(); else $j('#pais_origem_nome').hide(); } - checkTipoNacionalidade(); - $j('#tipo_nacionalidade').change(checkTipoNacionalidade); + + var validatesCpf = function() { + var valid = true; + var cpf = $cpfField.val(); + + $cpfNotice.hide(); + + if (cpf && ! validationUtils.validatesCpf(cpf)) { + $cpfNotice.html(stringUtils.toUtf8('O CPF informado é inválido')).slideDown('fast'); + + // não usado $cpfField.focus(), pois isto prenderia o usuário a página, + // caso o mesmo tenha informado um cpf invalido e clique em cancelar + $j('body').animate({ scrollTop: $j('body').offset().top }, 'fast'); + + valid = false; + } + + return valid; + } + + + var validatesUniquenessOfCpf = function() { + var cpf = $cpfField.val(); + + if(cpf && validatesCpf()) + getPersonByCpf(cpf); + } + + + var submitForm = function(event) { + + if ($cpfField.val()) { + $j(document).data('submit_form_after_ajax_validation', true); + validatesUniquenessOfCpf(); + } + + else + formUtils.submit(); + } + // style fixup + $('#pais_origem_nome').css('width', '150px'); - var submitForm = function(event) { - formUtils.submit(); - }; // bind events - $j('#btn_enviar').removeAttr('onclick'); - $j('#btn_enviar').click(submitForm); - }); // ready -})(jQuery); + checkTipoNacionalidade(); + $j('#tipo_nacionalidade').change(checkTipoNacionalidade); + + $cpfField.focusout(function() { + $j(document).removeData('submit_form_after_ajax_validation'); + validatesUniquenessOfCpf(); + }); + $submitButton.removeAttr('onclick'); + $submitButton.click(submitForm); + + }); // ready +})(jQuery); \ No newline at end of file diff --git a/ieducar/modules/Portabilis/Assets/Javascripts/Validator.js b/ieducar/modules/Portabilis/Assets/Javascripts/Validator.js index 3c42025..37f173d 100644 --- a/ieducar/modules/Portabilis/Assets/Javascripts/Validator.js +++ b/ieducar/modules/Portabilis/Assets/Javascripts/Validator.js @@ -20,9 +20,50 @@ var validationUtils = { return allValid; }, - validatesFields : function (){ + validatesFields : function () { return validatesPresenseOfValueInRequiredFields() && validationUtils.validatesDateFields(); + }, + + validatesCpf : function(cpf) { + cpf = cpf.replace(/[^0-9]/g, ''); + + if (cpf.length != 11) + return false; + + var soma; + var resto; + + // validacao primeiro digito verificador + + soma = 0; + for (i=1; i<=9; i++) + soma = soma + parseInt(cpf.substring(i-1, i)) * (11 - i); + + resto = (soma * 10) % 11; + + if ((resto == 10) || (resto == 11)) + resto = 0; + + if (resto != parseInt(cpf.substring(9, 10)) ) + return false; + + + // validacao segundo digito verificador + + soma = 0; + for (i = 1; i <= 10; i++) + soma = soma + parseInt(cpf.substring(i-1, i)) * (12 - i); + + resto = (soma * 10) % 11; + + if ((resto == 10) || (resto == 11)) + resto = 0; + + if (resto != parseInt(cpf.substring(10, 11) ) ) + return false; + + return true; } }; diff --git a/ieducar/modules/Portabilis/Assets/Version.php b/ieducar/modules/Portabilis/Assets/Version.php index a59de28..02f0c29 100644 --- a/ieducar/modules/Portabilis/Assets/Version.php +++ b/ieducar/modules/Portabilis/Assets/Version.php @@ -4,7 +4,7 @@ usado pelo metodos loadJavascript e loadStylesheet do helper Portabilis_View_Helper_Application */ class Portabilis_Assets_Version { - const VERSION = "0_0_0_1003"; + const VERSION = "0_0_0_1004"; } ?> -- libgit2 0.21.2