Commit c66fdfeff2cc9dee3bdd12e9037fab8d8aaf4f82

Authored by Lucas D'Avila
1 parent 897ce8af
Exists in master

Melhorado cadastro de nova pessoa física, sem CPF closes #5

ieducar/intranet/atendidos_cad.php
@@ -37,8 +37,9 @@ require_once 'include/pmieducar/clsPmieducarAluno.inc.php'; @@ -37,8 +37,9 @@ require_once 'include/pmieducar/clsPmieducarAluno.inc.php';
37 37
38 require_once 'App/Model/ZonaLocalizacao.php'; 38 require_once 'App/Model/ZonaLocalizacao.php';
39 39
40 -require_once 'lib/Portabilis/String/Utils.php';  
41 -require_once 'lib/Portabilis/View/Helper/Application.php'; 40 +require_once 'Portabilis/String/Utils.php';
  41 +require_once 'Portabilis/View/Helper/Application.php';
  42 +require_once 'Portabilis/Utils/Validation.php';
42 43
43 /** 44 /**
44 * clsIndex class. 45 * clsIndex class.
@@ -109,36 +110,12 @@ class indice extends clsCadastro @@ -109,36 +110,12 @@ class indice extends clsCadastro
109 110
110 function Inicializar() 111 function Inicializar()
111 { 112 {
112 - if ($_REQUEST['busca_pessoa']) {  
113 - $this->retorno = 'Novo'; 113 + $this->cod_pessoa_fj = @$_GET['cod_pessoa_fj'];
  114 + $this->retorno = 'Novo';
114 115
115 - $cpf = idFederal2int($_REQUEST['busca_pessoa']);  
116 -  
117 - $this->busca_pessoa = $cpf;  
118 - $this->id_federal = $cpf;  
119 -  
120 - $objPessoa = new clsPessoaFisica(FALSE, $cpf);  
121 - $detalhePessoa = $objPessoa->detalhe();  
122 -  
123 - $this->cod_pessoa_fj = $detalhePessoa["idpes"];  
124 - }  
125 - elseif ($_REQUEST['cod_pessoa_fj'] != '') {  
126 - $this->busca_pessoa = TRUE;  
127 -  
128 - if ($_REQUEST['cod_pessoa_fj'] != 0) {  
129 - $this->cod_pessoa_fj = $_REQUEST['cod_pessoa_fj'];  
130 - }  
131 - else {  
132 - $this->retorno = 'Novo';  
133 - }  
134 - }  
135 -  
136 - if ($this->cod_pessoa_fj) {  
137 - $this->cod_pessoa_fj = @$_GET['cod_pessoa'] ?  
138 - @$_GET['cod_pessoa'] : $this->cod_pessoa_fj;  
139 -  
140 - $db = new clsBanco();  
141 - $objPessoa = new clsPessoaFisica(); 116 + if (is_numeric($this->cod_pessoa_fj)) {
  117 + $this->retorno = 'Editar';
  118 + $objPessoa = new clsPessoaFisica();
142 119
143 list($this->nm_pessoa, $this->id_federal, $this->data_nasc, 120 list($this->nm_pessoa, $this->id_federal, $this->data_nasc,
144 $this->ddd_telefone_1, $this->telefone_1, $this->ddd_telefone_2, 121 $this->ddd_telefone_1, $this->telefone_1, $this->ddd_telefone_2,
@@ -160,19 +137,17 @@ class indice extends clsCadastro @@ -160,19 +137,17 @@ class indice extends clsCadastro
160 'idpais_estrangeiro', 'idmun_nascimento' 137 'idpais_estrangeiro', 'idmun_nascimento'
161 ); 138 );
162 139
  140 + $this->id_federal = is_numeric($this->id_federal) ? int2CPF($this->id_federal) : '';
  141 + $this->cep = is_numeric($this->cep) ? int2Cep($this->cep) : '';
  142 + $this->data_nasc = $this->data_nasc ? dataFromPgToBr($this->data_nasc) : '';
  143 +
163 $this->estado_civil_id = $this->estado_civil->ideciv; 144 $this->estado_civil_id = $this->estado_civil->ideciv;
164 $this->pais_origem_id = $this->pais_origem->idpais; 145 $this->pais_origem_id = $this->pais_origem->idpais;
165 $this->naturalidade_id = $this->naturalidade->idmun; 146 $this->naturalidade_id = $this->naturalidade->idmun;
166 147
167 - // Cor/Raça.  
168 - $raca = new clsCadastroFisicaRaca($this->cod_pessoa_fj);  
169 - $raca = $raca->detalhe();  
170 - if (is_array($raca)) {  
171 - $this->cod_raca = $raca['ref_cod_raca'];  
172 - }  
173 -  
174 - $this->cep = int2Cep($this->cep);  
175 - $this->retorno = 'Editar'; 148 + $raca = new clsCadastroFisicaRaca($this->cod_pessoa_fj);
  149 + $raca = $raca->detalhe();
  150 + $this->cod_raca = is_array($raca) ? $raca['ref_cod_raca'] : null;
176 } 151 }
177 152
178 $this->nome_url_cancelar = 'Cancelar'; 153 $this->nome_url_cancelar = 'Cancelar';
@@ -182,284 +157,250 @@ class indice extends clsCadastro @@ -182,284 +157,250 @@ class indice extends clsCadastro
182 157
183 function Gerar() 158 function Gerar()
184 { 159 {
185 - $this->addBanner('imagens/nvp_top_intranet.jpg',  
186 - 'imagens/nvp_vert_intranet.jpg', 'Intranet', FALSE);  
187 -  
188 - if (! $this->busca_pessoa) {  
189 - $this->campoOculto('cod_pessoa_fj', '');  
190 -  
191 - $parametros = new clsParametrosPesquisas();  
192 - $parametros->setSubmit(1);  
193 - $parametros->adicionaCampoTexto('busca_pessoa', 'id_federal');  
194 - $parametros->adicionaCampoTexto('cod_pessoa_fj', 'idpes');  
195 - $parametros->setPessoa('F');  
196 - $parametros->setPessoaCampo('cod_pessoa_fj');  
197 - $parametros->setPessoaNovo('S');  
198 - $parametros->setPessoaTela('window');  
199 -  
200 - $html = sprintf(  
201 - '<img id="lupa" src="imagens/lupa.png" border="0" ' .  
202 - "onclick=\"showExpansivel(500, 500, '<iframe name=\'miolo\' id=\'miolo\' frameborder=\'0\' height=\'100%%\' width=\'500\' marginheight=\'0\' marginwidth=\'0\' src=\'pesquisa_pessoa_lst.php?campos=%s\'></iframe>');\"".  
203 - '>',  
204 - $parametros->serializaCampos()  
205 - ); 160 + $this->url_cancelar = $this->retorno == 'Editar' ?
  161 + 'atendidos_det.php?cod_pessoa=' . $this->cod_pessoa_fj : 'atendidos_lst.php';
206 162
207 - $this->campoCpf('busca_pessoa', 'CPF', $this->ref_cod_pessoa_fj, TRUE,  
208 - $html, FALSE, TRUE);  
209 - }  
210 - else {  
211 - $this->campoOculto('busca_pessoa', $this->busca_pessoa); 163 + $this->campoOculto('cod_pessoa_fj', $this->cod_pessoa_fj);
  164 + $this->campoTexto('nm_pessoa', 'Nome', $this->nm_pessoa, '50', '255', TRUE);
212 165
213 - $this->url_cancelar = $this->retorno == 'Editar' ?  
214 - 'atendidos_det.php?cod_pessoa=' . $this->cod_pessoa_fj : 'atendidos_lst.php'; 166 + $this->campoCpf('id_federal', 'CPF', $this->id_federal, FALSE);
215 167
216 - $this->campoOculto('cod_pessoa_fj', $this->cod_pessoa_fj);  
217 - $this->campoTexto('nm_pessoa', 'Nome', $this->nm_pessoa, '50', '255', TRUE);  
218 -  
219 - if ($this->id_federal) {  
220 - $this->campoRotulo('id_federal', 'CPF', int2CPF($this->id_federal));  
221 - }  
222 - else {  
223 - $this->campoCpf('id_federal', 'CPF', '', FALSE);  
224 - }  
225 -  
226 - if ($this->data_nasc) {  
227 - $this->data_nasc = dataFromPgToBr($this->data_nasc);  
228 - } 168 + $this->campoData('data_nasc', 'Data de Nascimento', $this->data_nasc);
229 169
230 - $this->campoData('data_nasc', 'Data de Nascimento', $this->data_nasc); 170 + $lista_sexos = array();
  171 + $lista_sexos[''] = 'Escolha uma opção...';
  172 + $lista_sexos['M'] = 'Masculino';
  173 + $lista_sexos['F'] = 'Feminino';
  174 + $this->campoLista('sexo', 'Sexo', $lista_sexos, $this->sexo);
231 175
232 - $lista_sexos = array();  
233 - $lista_sexos[''] = 'Escolha uma opção...';  
234 - $lista_sexos['M'] = 'Masculino';  
235 - $lista_sexos['F'] = 'Feminino';  
236 - $this->campoLista('sexo', 'Sexo', $lista_sexos, $this->sexo); 176 + $this->inputsHelper()->estadoCivil(array('required' => false));
237 177
238 - $this->inputsHelper()->estadoCivil(array('required' => false)); 178 + // pai, mãe
239 179
240 - // pai, mãe 180 + $this->addPaiInput();
  181 + $this->addMaeInput();
241 182
242 - $this->addPaiInput();  
243 - $this->addMaeInput(); 183 + // Cor/raça.
  184 + $opcoes_raca = array('' => 'Selecione');
  185 + $obj_raca = new clsCadastroRaca();
  186 + $lst_raca = $obj_raca->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE);
244 187
245 - // Cor/raça.  
246 - $opcoes_raca = array('' => 'Selecione');  
247 - $obj_raca = new clsCadastroRaca();  
248 - $lst_raca = $obj_raca->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE);  
249 -  
250 - if ($lst_raca) {  
251 - foreach ($lst_raca as $raca) {  
252 - $opcoes_raca[$raca['cod_raca']] = $raca['nm_raca'];  
253 - } 188 + if ($lst_raca) {
  189 + foreach ($lst_raca as $raca) {
  190 + $opcoes_raca[$raca['cod_raca']] = $raca['nm_raca'];
254 } 191 }
  192 + }
255 193
256 - $this->campoLista('cor_raca', 'Raça', $opcoes_raca,  
257 - $this->cod_raca, '', FALSE, '', '', '', FALSE); 194 + $this->campoLista('cor_raca', 'Raça', $opcoes_raca,
  195 + $this->cod_raca, '', FALSE, '', '', '', FALSE);
258 196
259 - // nacionalidade 197 + // nacionalidade
260 198
261 - // tipos  
262 - $tiposNacionalidade = array(null => 'Selecione',  
263 - '1' => 'Brasileiro',  
264 - '2' => 'Naturalizado brasileiro',  
265 - '3' => 'Estrangeiro'); 199 + // tipos
  200 + $tiposNacionalidade = array(null => 'Selecione',
  201 + '1' => 'Brasileiro',
  202 + '2' => 'Naturalizado brasileiro',
  203 + '3' => 'Estrangeiro');
266 204
267 - $options = array('label' => 'Nacionalidade',  
268 - 'resources' => $tiposNacionalidade,  
269 - 'required' => false,  
270 - 'inline' => true,  
271 - 'value' => $this->tipo_nacionalidade); 205 + $options = array('label' => 'Nacionalidade',
  206 + 'resources' => $tiposNacionalidade,
  207 + 'required' => false,
  208 + 'inline' => true,
  209 + 'value' => $this->tipo_nacionalidade);
272 210
273 - $this->inputsHelper()->select('tipo_nacionalidade', $options); 211 + $this->inputsHelper()->select('tipo_nacionalidade', $options);
274 212
275 - // pais origem 213 + // pais origem
276 214
277 - $options = array('label' => '', 'required' => true);  
278 - $helperOptions = array('objectName' => 'pais_origem',  
279 - 'hiddenInputOptions' => array('options' => array('value' => $this->pais_origem_id))); 215 + $options = array('label' => '', 'required' => true);
  216 + $helperOptions = array('objectName' => 'pais_origem',
  217 + 'hiddenInputOptions' => array('options' => array('value' => $this->pais_origem_id)));
280 218
281 - $this->inputsHelper()->simpleSearchPais('nome', $options, $helperOptions); 219 + $this->inputsHelper()->simpleSearchPais('nome', $options, $helperOptions);
282 220
283 221
284 - // naturalidade 222 + // naturalidade
285 223
286 - $options = array('label' => 'Naturalidade', 'required' => false);  
287 - $helperOptions = array('objectName' => 'naturalidade',  
288 - 'hiddenInputOptions' => array('options' => array('value' => $this->naturalidade_id))); 224 + $options = array('label' => 'Naturalidade', 'required' => false);
  225 + $helperOptions = array('objectName' => 'naturalidade',
  226 + 'hiddenInputOptions' => array('options' => array('value' => $this->naturalidade_id)));
289 227
290 - $this->inputsHelper()->simpleSearchMunicipio('nome', $options, $helperOptions); 228 + $this->inputsHelper()->simpleSearchMunicipio('nome', $options, $helperOptions);
291 229
292 230
293 - // Detalhes do Endereço 231 + // Detalhes do Endereço
294 232
295 - $objTipoLog = new clsTipoLogradouro();  
296 - $listaTipoLog = $objTipoLog->lista();  
297 - $listaTLog = array('0' => 'Selecione'); 233 + $objTipoLog = new clsTipoLogradouro();
  234 + $listaTipoLog = $objTipoLog->lista();
  235 + $listaTLog = array('0' => 'Selecione');
298 236
299 - if ($listaTipoLog) {  
300 - foreach ($listaTipoLog as $tipoLog) {  
301 - $listaTLog[$tipoLog['idtlog']] = $tipoLog['descricao'];  
302 - } 237 + if ($listaTipoLog) {
  238 + foreach ($listaTipoLog as $tipoLog) {
  239 + $listaTLog[$tipoLog['idtlog']] = $tipoLog['descricao'];
303 } 240 }
  241 + }
304 242
305 - $objUf = new clsUf();  
306 - $listauf = $objUf->lista();  
307 - $listaEstado = array('0' => 'Selecione'); 243 + $objUf = new clsUf();
  244 + $listauf = $objUf->lista();
  245 + $listaEstado = array('0' => 'Selecione');
308 246
309 - if ($listauf) {  
310 - foreach ($listauf as $uf) {  
311 - $listaEstado[$uf['sigla_uf']] = $uf['sigla_uf'];  
312 - } 247 + if ($listauf) {
  248 + foreach ($listauf as $uf) {
  249 + $listaEstado[$uf['sigla_uf']] = $uf['sigla_uf'];
313 } 250 }
  251 + }
314 252
315 - $this->campoOculto('idbai', $this->idbai);  
316 - $this->campoOculto('idlog', $this->idlog);  
317 - $this->campoOculto('cep', $this->cep);  
318 - $this->campoOculto('ref_sigla_uf', $this->sigla_uf);  
319 - $this->campoOculto('ref_idtlog', $this->idtlog);  
320 - $this->campoOculto('id_cidade', $this->cidade); 253 + $this->campoOculto('idbai', $this->idbai);
  254 + $this->campoOculto('idlog', $this->idlog);
  255 + $this->campoOculto('cep', $this->cep);
  256 + $this->campoOculto('ref_sigla_uf', $this->sigla_uf);
  257 + $this->campoOculto('ref_idtlog', $this->idtlog);
  258 + $this->campoOculto('id_cidade', $this->cidade);
321 259
322 - $zona = App_Model_ZonaLocalizacao::getInstance(); 260 + $zona = App_Model_ZonaLocalizacao::getInstance();
323 261
324 - if ($this->idlog && $this->idbai && $this->cep && $this->cod_pessoa_fj) {  
325 - $this->campoCep('cep_', 'CEP', $this->cep, true, '-',  
326 - "&nbsp;<img id='lupa' src=\"imagens/lupa.png\" border=\"0\" onclick=\"showExpansivel( 500,500, '<iframe name=\'miolo\' id=\'miolo\' frameborder=\'0\' height=\'100%\' width=\'500\' marginheight=\'0\' marginwidth=\'0\' src=\'educar_pesquisa_cep_log_bairro.php?campo1=bairro&campo2=idbai&campo3=cep&campo4=logradouro&campo5=idlog&campo6=ref_sigla_uf&campo7=cidade&campo8=ref_idtlog&campo9=isEnderecoExterno&campo10=cep_&campo11=sigla_uf&campo12=idtlog&campo13=id_cidade\'></iframe>');\">",  
327 - TRUE); 262 + if ($this->idlog && $this->idbai && $this->cep && $this->cod_pessoa_fj) {
  263 + $this->campoCep('cep_', 'CEP', $this->cep, true, '-',
  264 + "&nbsp;<img id='lupa' src=\"imagens/lupa.png\" border=\"0\" onclick=\"showExpansivel( 500,500, '<iframe name=\'miolo\' id=\'miolo\' frameborder=\'0\' height=\'100%\' width=\'500\' marginheight=\'0\' marginwidth=\'0\' src=\'educar_pesquisa_cep_log_bairro.php?campo1=bairro&campo2=idbai&campo3=cep&campo4=logradouro&campo5=idlog&campo6=ref_sigla_uf&campo7=cidade&campo8=ref_idtlog&campo9=isEnderecoExterno&campo10=cep_&campo11=sigla_uf&campo12=idtlog&campo13=id_cidade\'></iframe>');\">",
  265 + TRUE);
328 266
329 - $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog,  
330 - FALSE, FALSE, FALSE, FALSE, TRUE); 267 + $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog,
  268 + FALSE, FALSE, FALSE, FALSE, TRUE);
331 269
332 - $this->campoTextoInv('logradouro', 'Logradouro', $this->logradouro,  
333 - '50', '255', FALSE); 270 + $this->campoTextoInv('logradouro', 'Logradouro', $this->logradouro,
  271 + '50', '255', FALSE);
334 272
335 - $this->campoTextoInv('cidade', 'Cidade', $this->cidade, '50', '255',  
336 - FALSE); 273 + $this->campoTextoInv('cidade', 'Cidade', $this->cidade, '50', '255',
  274 + FALSE);
337 275
338 - $this->campoTextoInv('bairro', 'Bairro', $this->bairro, '50', '255', FALSE); 276 + $this->campoTextoInv('bairro', 'Bairro', $this->bairro, '50', '255', FALSE);
339 277
340 - $this->campoTexto('complemento', 'Complemento', $this->complemento, '50', '255',  
341 - FALSE); 278 + $this->campoTexto('complemento', 'Complemento', $this->complemento, '50', '255',
  279 + FALSE);
342 280
343 - $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); 281 + $this->campoTexto('numero', 'Número', $this->numero, '10', '10');
344 282
345 - $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); 283 + $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE);
346 284
347 - $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento, '6', '6',  
348 - FALSE); 285 + $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento, '6', '6',
  286 + FALSE);
349 287
350 - $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE);  
351 - $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); 288 + $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE);
  289 + $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE);
352 290
353 - $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf,  
354 - FALSE, FALSE, FALSE, FALSE, TRUE);  
355 - }  
356 - elseif($this->cod_pessoa_fj && $this->cep) {  
357 - $this->campoCep('cep_', 'CEP', $this->cep, true, '-',  
358 - "&nbsp;<img id='lupa' src=\"imagens/lupa.png\" border=\"0\" onclick=\"showExpansivel( 500,500, '<iframe name=\'miolo\' id=\'miolo\' frameborder=\'0\' height=\'100%\' width=\'500\' marginheight=\'0\' marginwidth=\'0\' src=\'educar_pesquisa_cep_log_bairro.php?campo1=bairro&campo2=idbai&campo3=cep&campo4=logradouro&campo5=idlog&campo6=ref_sigla_uf&campo7=cidade&campo8=ref_idtlog&campo9=isEnderecoExterno&campo10=cep_&campo11=sigla_uf&campo12=idtlog&campo13=id_cidade\'></iframe>');\">",  
359 - $disabled); 291 + $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf,
  292 + FALSE, FALSE, FALSE, FALSE, TRUE);
  293 + }
  294 + elseif($this->cod_pessoa_fj && $this->cep) {
  295 + $this->campoCep('cep_', 'CEP', $this->cep, true, '-',
  296 + "&nbsp;<img id='lupa' src=\"imagens/lupa.png\" border=\"0\" onclick=\"showExpansivel( 500,500, '<iframe name=\'miolo\' id=\'miolo\' frameborder=\'0\' height=\'100%\' width=\'500\' marginheight=\'0\' marginwidth=\'0\' src=\'educar_pesquisa_cep_log_bairro.php?campo1=bairro&campo2=idbai&campo3=cep&campo4=logradouro&campo5=idlog&campo6=ref_sigla_uf&campo7=cidade&campo8=ref_idtlog&campo9=isEnderecoExterno&campo10=cep_&campo11=sigla_uf&campo12=idtlog&campo13=id_cidade\'></iframe>');\">",
  297 + $disabled);
360 298
361 - $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog); 299 + $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog);
362 300
363 - $this->campoTexto('logradouro', 'Logradouro', $this->logradouro, '50',  
364 - '255', FALSE); 301 + $this->campoTexto('logradouro', 'Logradouro', $this->logradouro, '50',
  302 + '255', FALSE);
365 303
366 - $this->campoTexto('cidade', 'Cidade', $this->cidade, '50', '255', FALSE); 304 + $this->campoTexto('cidade', 'Cidade', $this->cidade, '50', '255', FALSE);
367 305
368 - $this->campoTexto('bairro', 'Bairro', $this->bairro, '50', '255', FALSE); 306 + $this->campoTexto('bairro', 'Bairro', $this->bairro, '50', '255', FALSE);
369 307
370 - $this->campoTexto('complemento', 'Complemento', $this->complemento, '50',  
371 - '255', FALSE); 308 + $this->campoTexto('complemento', 'Complemento', $this->complemento, '50',
  309 + '255', FALSE);
372 310
373 - $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); 311 + $this->campoTexto('numero', 'Número', $this->numero, '10', '10');
374 312
375 - $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); 313 + $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE);
376 314
377 - $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento,  
378 - '6', '6', FALSE); 315 + $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento,
  316 + '6', '6', FALSE);
379 317
380 - $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE); 318 + $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE);
381 319
382 - $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); 320 + $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE);
383 321
384 - $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf);  
385 - }  
386 - else {  
387 - $this->campoCep('cep_', 'CEP', $this->cep, TRUE, '-',  
388 - "&nbsp;<img id='lupa' src=\"imagens/lupa.png\" border=\"0\"  
389 - onclick=\"showExpansivel(500, 500, '<iframe name=\'miolo\' id=\'miolo\' frameborder=\'0\' height=\'100%\' width=\'500\' marginheight=\'0\' marginwidth=\'0\' src=\'educar_pesquisa_cep_log_bairro.php?campo1=bairro&campo2=idbai&campo3=cep&campo4=logradouro&campo5=idlog&campo6=ref_sigla_uf&campo7=cidade&campo8=ref_idtlog&campo9=isEnderecoExterno&campo10=cep_&campo11=sigla_uf&campo12=idtlog&campo13=id_cidade&campo14=zona_localizacao\'></iframe>');\">",  
390 - false  
391 - ); 322 + $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf);
  323 + }
  324 + else {
  325 + $this->campoCep('cep_', 'CEP', $this->cep, TRUE, '-',
  326 + "&nbsp;<img id='lupa' src=\"imagens/lupa.png\" border=\"0\"
  327 + onclick=\"showExpansivel(500, 500, '<iframe name=\'miolo\' id=\'miolo\' frameborder=\'0\' height=\'100%\' width=\'500\' marginheight=\'0\' marginwidth=\'0\' src=\'educar_pesquisa_cep_log_bairro.php?campo1=bairro&campo2=idbai&campo3=cep&campo4=logradouro&campo5=idlog&campo6=ref_sigla_uf&campo7=cidade&campo8=ref_idtlog&campo9=isEnderecoExterno&campo10=cep_&campo11=sigla_uf&campo12=idtlog&campo13=id_cidade&campo14=zona_localizacao\'></iframe>');\">",
  328 + false
  329 + );
392 330
393 - $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog,  
394 - FALSE, FALSE, FALSE, FALSE, FALSE); 331 + $this->campoLista('idtlog', 'Tipo Logradouro', $listaTLog, $this->idtlog,
  332 + FALSE, FALSE, FALSE, FALSE, FALSE);
395 333
396 - $this->campoTexto('logradouro', 'Logradouro', $this->logradouro,  
397 - '50', '255'); 334 + $this->campoTexto('logradouro', 'Logradouro', $this->logradouro,
  335 + '50', '255');
398 336
399 - $this->campoTexto('cidade', 'Cidade', $this->cidade, '50', '255'); 337 + $this->campoTexto('cidade', 'Cidade', $this->cidade, '50', '255');
400 338
401 - $this->campoTexto('bairro', 'Bairro', $this->bairro, '50', '255'); 339 + $this->campoTexto('bairro', 'Bairro', $this->bairro, '50', '255');
402 340
403 - $this->campoTexto('complemento', 'Complemento', $this->complemento,  
404 - '50', '255', FALSE); 341 + $this->campoTexto('complemento', 'Complemento', $this->complemento,
  342 + '50', '255', FALSE);
405 343
406 - $this->campoTexto('numero', 'Número', $this->numero, '10', '10'); 344 + $this->campoTexto('numero', 'Número', $this->numero, '10', '10');
407 345
408 - $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE); 346 + $this->campoTexto('letra', 'Letra', $this->letra, '1', '1', FALSE);
409 347
410 - $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento,  
411 - '6', '6', FALSE); 348 + $this->campoTexto('apartamento', 'Número Apartamento', $this->apartamento,
  349 + '6', '6', FALSE);
412 350
413 - $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE); 351 + $this->campoTexto('bloco', 'Bloco', $this->bloco, '20', '20', FALSE);
414 352
415 - $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE); 353 + $this->campoTexto('andar', 'Andar', $this->andar, '2', '2', FALSE);
416 354
417 - $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf,  
418 - FALSE, FALSE, FALSE, FALSE, FALSE);  
419 - } 355 + $this->campoLista('sigla_uf', 'Estado', $listaEstado, $this->sigla_uf,
  356 + FALSE, FALSE, FALSE, FALSE, FALSE);
  357 + }
420 358
421 - $this->campoLista('zona_localizacao', 'Zona Localização', $zona->getEnums(),  
422 - $this->zona_localizacao, FALSE, FALSE, FALSE, FALSE,  
423 - ($this->idbai ? TRUE : FALSE)  
424 - ); 359 + $this->campoLista('zona_localizacao', 'Zona Localização', $zona->getEnums(),
  360 + $this->zona_localizacao, FALSE, FALSE, FALSE, FALSE,
  361 + ($this->idbai ? TRUE : FALSE)
  362 + );
425 363
426 - $this->campoTexto('ddd_telefone_1', 'DDD Telefone 1', $this->ddd_telefone_1,  
427 - '3', '2', FALSE); 364 + $this->campoTexto('ddd_telefone_1', 'DDD Telefone 1', $this->ddd_telefone_1,
  365 + '3', '2', FALSE);
428 366
429 - $this->campoTexto('telefone_1', 'Telefone 1', $this->telefone_1, '10',  
430 - '15', FALSE); 367 + $this->campoTexto('telefone_1', 'Telefone 1', $this->telefone_1, '10',
  368 + '15', FALSE);
431 369
432 - $this->campoTexto('ddd_telefone_2', 'DDD Telefone 2', $this->ddd_telefone_2,  
433 - '3', '2', FALSE); 370 + $this->campoTexto('ddd_telefone_2', 'DDD Telefone 2', $this->ddd_telefone_2,
  371 + '3', '2', FALSE);
434 372
435 - $this->campoTexto('telefone_2', 'Telefone 2', $this->telefone_2, '10',  
436 - '15', FALSE); 373 + $this->campoTexto('telefone_2', 'Telefone 2', $this->telefone_2, '10',
  374 + '15', FALSE);
437 375
438 - $this->campoTexto('ddd_telefone_mov', 'DDD Celular',  
439 - $this->ddd_telefone_mov, '3', '2', FALSE); 376 + $this->campoTexto('ddd_telefone_mov', 'DDD Celular',
  377 + $this->ddd_telefone_mov, '3', '2', FALSE);
440 378
441 - $this->campoTexto('telefone_mov', 'Celular', $this->telefone_mov, '10',  
442 - '15', FALSE); 379 + $this->campoTexto('telefone_mov', 'Celular', $this->telefone_mov, '10',
  380 + '15', FALSE);
443 381
444 - $this->campoTexto('ddd_telefone_fax', 'DDD Fax', $this->ddd_telefone_fax,  
445 - '3', '2', FALSE); 382 + $this->campoTexto('ddd_telefone_fax', 'DDD Fax', $this->ddd_telefone_fax,
  383 + '3', '2', FALSE);
446 384
447 - $this->campoTexto('telefone_fax', 'Fax', $this->telefone_fax, '10', '15',  
448 - FALSE); 385 + $this->campoTexto('telefone_fax', 'Fax', $this->telefone_fax, '10', '15',
  386 + FALSE);
449 387
450 - $this->campoTexto('http', 'Site', $this->http, '50', '255', FALSE); 388 + $this->campoTexto('http', 'Site', $this->http, '50', '255', FALSE);
451 389
452 - $this->campoTexto('email', 'E-mail', $this->email, '50', '255', FALSE); 390 + $this->campoTexto('email', 'E-mail', $this->email, '50', '255', FALSE);
453 391
454 - if ($this->cod_pessoa_fj) {  
455 - $this->campoRotulo('documentos', '<b><i>Documentos</i></b>',  
456 - "<a href='#' onclick=\"windowUtils.open('adicionar_documentos_cad.php?id_pessoa={$this->cod_pessoa_fj}'); \"><img src='imagens/nvp_bot_ad_doc.png' border='0'></a>"); 392 + if ($this->cod_pessoa_fj) {
  393 + $this->campoRotulo('documentos', '<b><i>Documentos</i></b>',
  394 + "<a href='#' onclick=\"windowUtils.open('adicionar_documentos_cad.php?id_pessoa={$this->cod_pessoa_fj}'); \"><img src='imagens/nvp_bot_ad_doc.png' border='0'></a>");
457 395
458 - $this->campoCheck('alterado', 'Alterado', $this->alterado);  
459 - } 396 + $this->campoCheck('alterado', 'Alterado', $this->alterado);
460 } 397 }
461 398
462 - $styles = array('/modules/Portabilis/Assets/Stylesheets/Frontend.css'); 399 + $styles = array(
  400 + '/modules/Portabilis/Assets/Stylesheets/Frontend.css',
  401 + '/modules/Portabilis/Assets/Stylesheets/Frontend/Resource.css'
  402 + );
  403 +
463 Portabilis_View_Helper_Application::loadStylesheet($this, $styles); 404 Portabilis_View_Helper_Application::loadStylesheet($this, $styles);
464 405
465 $script = "/modules/Cadastro/Assets/Javascripts/PessoaFisica.js"; 406 $script = "/modules/Cadastro/Assets/Javascripts/PessoaFisica.js";
@@ -468,37 +409,17 @@ class indice extends clsCadastro @@ -468,37 +409,17 @@ class indice extends clsCadastro
468 409
469 function Novo() 410 function Novo()
470 { 411 {
471 - @session_start();  
472 - $pessoaFj = $_SESSION['id_pessoa'];  
473 - session_write_close();  
474 -  
475 - $db = new clsBanco();  
476 - $db2 = new clsBanco();  
477 412
478 - $ref_cod_sistema = FALSE;  
479 -  
480 - if ($this->id_federal) {  
481 - $this->id_federal = idFederal2int($this->id_federal);  
482 -  
483 - $objCPF = new clsFisica(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,  
484 - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,  
485 - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, $this->id_federal);  
486 -  
487 - $detalhe_fisica = $objCPF->detalhe();  
488 - if ($detalhe_fisica['cpf']) {  
489 - $this->erros['id_federal'] = 'CPF já cadastrado.';  
490 - return FALSE;  
491 - }  
492 - } 413 + if (! $this->validatesCpf($this->id_federal))
  414 + return false;
493 415
494 // pessoa 416 // pessoa
495 417
496 - $objPessoa = new clsPessoa_(FALSE, $this->nm_pessoa, $pessoaFj, $this->http,  
497 - 'F', FALSE, FALSE, $this->email); 418 + $objPessoa = new clsPessoa_(FALSE, $this->nm_pessoa, $this->currentUserId(), $this->http,
  419 + 'F', FALSE, FALSE, $this->email);
498 420
499 $idpes = $objPessoa->cadastra(); 421 $idpes = $objPessoa->cadastra();
500 422
501 -  
502 // pessoa fisica 423 // pessoa fisica
503 424
504 $fisica = new clsFisica(); 425 $fisica = new clsFisica();
@@ -507,7 +428,7 @@ class indice extends clsCadastro @@ -507,7 +428,7 @@ class indice extends clsCadastro
507 $fisica->data_nasc = dataToBanco($this->data_nasc); 428 $fisica->data_nasc = dataToBanco($this->data_nasc);
508 $fisica->sexo = $this->sexo; 429 $fisica->sexo = $this->sexo;
509 $fisica->ref_cod_sistema = 'NULL'; 430 $fisica->ref_cod_sistema = 'NULL';
510 - $fisica->cpf = $this->id_federal; 431 + $fisica->cpf = idFederal2int($this->id_federal);
511 $fisica->ideciv = $this->estado_civil_id; 432 $fisica->ideciv = $this->estado_civil_id;
512 $fisica->idpes_pai = $this->pai_id; 433 $fisica->idpes_pai = $this->pai_id;
513 $fisica->idpes_mae = $this->mae_id; 434 $fisica->idpes_mae = $this->mae_id;
@@ -570,32 +491,14 @@ class indice extends clsCadastro @@ -570,32 +491,14 @@ class indice extends clsCadastro
570 491
571 function Editar() 492 function Editar()
572 { 493 {
573 - @session_start();  
574 - $pessoaFj = $_SESSION['id_pessoa'];  
575 - session_write_close();  
576 -  
577 - if ($this->id_federal) {  
578 - $this->id_federal = idFederal2int($this->id_federal);  
579 -  
580 - $objFisicaCpf = new clsFisica($this->cod_pessoa_fj);  
581 - $detalhe_fisica = $objFisicaCpf->detalhe();  
582 -  
583 - if (! $detalhe_fisica['cpf']) {  
584 - $objCPF = new clsFisica(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,  
585 - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,  
586 - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, $this->id_federal);  
587 -  
588 - if ($objCPF->detalhe()) {  
589 - $this->erros['id_federal'] = 'CPF já cadastrado.';  
590 - return FALSE;  
591 - }  
592 - }  
593 - } 494 + if (! $this->validatesCpf($this->id_federal))
  495 + return false;
594 496
595 // pessoa 497 // pessoa
596 498
597 $objPessoa = new clsPessoa_($this->cod_pessoa_fj, $this->nm_pessoa, FALSE, 499 $objPessoa = new clsPessoa_($this->cod_pessoa_fj, $this->nm_pessoa, FALSE,
598 - $this->p_http, FALSE, $pessoaFj, date('Y-m-d H:i:s', time()), $this->email); 500 + $this->p_http, FALSE, $this->currentUserId(),
  501 + date('Y-m-d H:i:s', time()), $this->email);
599 502
600 $objPessoa->edita(); 503 $objPessoa->edita();
601 504
@@ -607,7 +510,7 @@ class indice extends clsCadastro @@ -607,7 +510,7 @@ class indice extends clsCadastro
607 $fisica->data_nasc = dataToBanco($this->data_nasc); 510 $fisica->data_nasc = dataToBanco($this->data_nasc);
608 $fisica->sexo = $this->sexo; 511 $fisica->sexo = $this->sexo;
609 $fisica->ref_cod_sistema = 'NULL'; 512 $fisica->ref_cod_sistema = 'NULL';
610 - $fisica->cpf = $this->id_federal; 513 + $fisica->cpf = $this->id_federal ? idFederal2int($this->id_federal) : 'NULL';
611 $fisica->ideciv = $this->estado_civil_id; 514 $fisica->ideciv = $this->estado_civil_id;
612 515
613 $fisica->idpes_pai = $this->pai_id; 516 $fisica->idpes_pai = $this->pai_id;
@@ -759,6 +662,30 @@ class indice extends clsCadastro @@ -759,6 +662,30 @@ class indice extends clsCadastro
759 662
760 $this->inputsHelper()->simpleSearchPessoa('nome', $options, $helperOptions); 663 $this->inputsHelper()->simpleSearchPessoa('nome', $options, $helperOptions);
761 } 664 }
  665 +
  666 + protected function validatesCpf($cpf) {
  667 + $isValid = true;
  668 +
  669 + if ($cpf && ! Portabilis_Utils_Validation::validatesCpf($cpf)) {
  670 + $this->erros['id_federal'] = 'CPF inválido.';
  671 + $isValid = false;
  672 + }
  673 + elseif($cpf) {
  674 + $fisica = new clsFisica();
  675 + $fisica->cpf = idFederal2int($cpf);
  676 + $fisica = $fisica->detalhe();
  677 +
  678 + if ($fisica['cpf'] && $this->cod_pessoa_fj != $fisica['idpes']) {
  679 + $link = "<a class='decorated' target='__blank' href='/intranet/atendidos_cad.php?cod_pessoa_fj=" .
  680 + "{$fisica['idpes']}'>{$fisica['idpes']}</a>";
  681 +
  682 + $this->erros['id_federal'] = "CPF já utilizado pela pessoa $link.";
  683 + $isValid = false;
  684 + }
  685 + }
  686 +
  687 + return $isValid;
  688 + }
762 } 689 }
763 690
764 // Instancia objeto de página 691 // Instancia objeto de página
ieducar/intranet/include/clsBase.inc.php
@@ -49,8 +49,8 @@ require_once &#39;include/Geral.inc.php&#39;; @@ -49,8 +49,8 @@ require_once &#39;include/Geral.inc.php&#39;;
49 require_once 'include/pmicontrolesis/geral.inc.php'; 49 require_once 'include/pmicontrolesis/geral.inc.php';
50 require_once 'include/funcoes.inc.php'; 50 require_once 'include/funcoes.inc.php';
51 51
52 -require_once 'lib/Portabilis/Utils/Database.php';  
53 -require_once 'lib/Portabilis/Utils/User.php'; 52 +require_once 'Portabilis/Utils/Database.php';
  53 +require_once 'Portabilis/Utils/User.php';
54 54
55 require_once 'modules/Error/Mailers/NotificationMailer.php'; 55 require_once 'modules/Error/Mailers/NotificationMailer.php';
56 56
@@ -219,7 +219,7 @@ class clsBase extends clsConfig @@ -219,7 +219,7 @@ class clsBase extends clsConfig
219 } 219 }
220 220
221 if ($processo_ap != 0) { 221 if ($processo_ap != 0) {
222 - $this->db()->Consulta("SELECT 1 FROM menu_funcionario WHERE ref_cod_menu_submenu = 0 AND ref_ref_cod_pessoa_fj = {$this->_currentUserId()}"); 222 + $this->db()->Consulta("SELECT 1 FROM menu_funcionario WHERE ref_cod_menu_submenu = 0 AND ref_ref_cod_pessoa_fj = {$this->currentUserId()}");
223 if ($this->db()->ProximoRegistro()) { 223 if ($this->db()->ProximoRegistro()) {
224 list($aui) = $this->db()->Tupla(); 224 list($aui) = $this->db()->Tupla();
225 $sempermissao = FALSE; 225 $sempermissao = FALSE;
@@ -229,7 +229,7 @@ class clsBase extends clsConfig @@ -229,7 +229,7 @@ class clsBase extends clsConfig
229 // permissão de acesso ao processo. Já a segunda, não existe 229 // permissão de acesso ao processo. Já a segunda, não existe
230 // sentido para nivel = 2 já que processoAp pode ser de níveis 230 // sentido para nivel = 2 já que processoAp pode ser de níveis
231 // maiores que 2. 231 // maiores que 2.
232 - $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)"); 232 + $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)");
233 if ($this->db()->ProximoRegistro()) { 233 if ($this->db()->ProximoRegistro()) {
234 list($aui) = $this->db()->Tupla(); 234 list($aui) = $this->db()->Tupla();
235 $sempermissao = FALSE; 235 $sempermissao = FALSE;
@@ -257,8 +257,8 @@ class clsBase extends clsConfig @@ -257,8 +257,8 @@ class clsBase extends clsConfig
257 257
258 $variaveis = "POST\n{$posts}GET\n{$gets}SESSION\n{$sessions}"; 258 $variaveis = "POST\n{$posts}GET\n{$gets}SESSION\n{$sessions}";
259 259
260 - if ($this->_currentUserId()) {  
261 - $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')"); 260 + if ($this->currentUserId()) {
  261 + $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')");
262 } 262 }
263 else { 263 else {
264 $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')"); 264 $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 @@ -544,7 +544,7 @@ class clsBase extends clsConfig
544 $menu_dinamico = $this->makeBanner(); 544 $menu_dinamico = $this->makeBanner();
545 545
546 $notificacao = ""; 546 $notificacao = "";
547 - $this->db()->Consulta("SELECT cod_notificacao, titulo, conteudo, url FROM portal.notificacao WHERE ref_cod_funcionario = '{$this->_currentUserId()}' AND data_hora_ativa < NOW()"); 547 + $this->db()->Consulta("SELECT cod_notificacao, titulo, conteudo, url FROM portal.notificacao WHERE ref_cod_funcionario = '{$this->currentUserId()}' AND data_hora_ativa < NOW()");
548 548
549 if ($this->db()->numLinhas()) { 549 if ($this->db()->numLinhas()) {
550 while ($this->db()->ProximoRegistro()) { 550 while ($this->db()->ProximoRegistro()) {
@@ -560,18 +560,18 @@ class clsBase extends clsConfig @@ -560,18 +560,18 @@ class clsBase extends clsConfig
560 </div>"; 560 </div>";
561 } 561 }
562 $saida = str_replace( "<!-- #&NOTIFICACOES&# -->", $notificacao, $saida ); 562 $saida = str_replace( "<!-- #&NOTIFICACOES&# -->", $notificacao, $saida );
563 - $this->db()->Consulta("UPDATE portal.notificacao SET visualizacoes = visualizacoes + 1 WHERE ref_cod_funcionario = '{$this->_currentUserId()}' AND data_hora_ativa < NOW()"); 563 + $this->db()->Consulta("UPDATE portal.notificacao SET visualizacoes = visualizacoes + 1 WHERE ref_cod_funcionario = '{$this->currentUserId()}' AND data_hora_ativa < NOW()");
564 $this->db()->Consulta("DELETE FROM portal.notificacao WHERE visualizacoes > 10"); 564 $this->db()->Consulta("DELETE FROM portal.notificacao WHERE visualizacoes > 10");
565 } 565 }
566 566
567 // nome completo usuario 567 // nome completo usuario
568 $nomePessoa = new clsPessoaFisica(); 568 $nomePessoa = new clsPessoaFisica();
569 - list($nomePessoa) = $nomePessoa->queryRapida($this->_currentUserId(), "nome"); 569 + list($nomePessoa) = $nomePessoa->queryRapida($this->currentUserId(), "nome");
570 $nomePessoa = ($nomePessoa) ? $nomePessoa : "<span style='color: #DD0000; '>Convidado</span>"; 570 $nomePessoa = ($nomePessoa) ? $nomePessoa : "<span style='color: #DD0000; '>Convidado</span>";
571 571
572 572
573 // data ultimo acesso 573 // data ultimo acesso
574 - $ultimoAcesso = $this->db()->UnicoCampo("SELECT data_hora FROM acesso WHERE cod_pessoa = {$this->_currentUserId()} ORDER BY data_hora DESC LIMIT 1,1"); 574 + $ultimoAcesso = $this->db()->UnicoCampo("SELECT data_hora FROM acesso WHERE cod_pessoa = {$this->currentUserId()} ORDER BY data_hora DESC LIMIT 1,1");
575 575
576 if($ultimoAcesso) 576 if($ultimoAcesso)
577 $ultimoAcesso = date("d/m/Y H:i", strtotime(substr($ultimoAcesso,0,19))); 577 $ultimoAcesso = date("d/m/Y H:i", strtotime(substr($ultimoAcesso,0,19)));
@@ -595,7 +595,7 @@ class clsBase extends clsConfig @@ -595,7 +595,7 @@ class clsBase extends clsConfig
595 $ip_maquina = $_SERVER['REMOTE_ADDR']; 595 $ip_maquina = $_SERVER['REMOTE_ADDR'];
596 } 596 }
597 597
598 - $sql = "UPDATE funcionario SET ip_logado = '$ip_maquina' , data_login = NOW() WHERE ref_cod_pessoa_fj = {$this->_currentUserId()}"; 598 + $sql = "UPDATE funcionario SET ip_logado = '$ip_maquina' , data_login = NOW() WHERE ref_cod_pessoa_fj = {$this->currentUserId()}";
599 $this->db()->Consulta($sql); 599 $this->db()->Consulta($sql);
600 600
601 return $saida; 601 return $saida;
@@ -844,7 +844,7 @@ class clsBase extends clsConfig @@ -844,7 +844,7 @@ class clsBase extends clsConfig
844 return Portabilis_Utils_Database::db(); 844 return Portabilis_Utils_Database::db();
845 } 845 }
846 846
847 - function _currentUserId() { 847 + protected function currentUserId() {
848 return Portabilis_Utils_User::currentUserId(); 848 return Portabilis_Utils_User::currentUserId();
849 } 849 }
850 } 850 }
ieducar/intranet/include/clsCadastro.inc.php
@@ -36,6 +36,7 @@ if (class_exists(&#39;clsPmiajudaPagina&#39;)) { @@ -36,6 +36,7 @@ if (class_exists(&#39;clsPmiajudaPagina&#39;)) {
36 36
37 require_once 'Portabilis/View/Helper/Application.php'; 37 require_once 'Portabilis/View/Helper/Application.php';
38 require_once 'Portabilis/View/Helper/Inputs.php'; 38 require_once 'Portabilis/View/Helper/Inputs.php';
  39 +require_once 'Portabilis/Utils/User.php';
39 40
40 /** 41 /**
41 * clsCadastro class. 42 * clsCadastro class.
@@ -731,4 +732,8 @@ class clsCadastro extends clsCampos @@ -731,4 +732,8 @@ class clsCadastro extends clsCampos
731 732
732 return $this->_inputsHelper; 733 return $this->_inputsHelper;
733 } 734 }
  735 +
  736 + protected function currentUserId() {
  737 + return Portabilis_Utils_User::currentUserId();
  738 + }
734 } 739 }
ieducar/intranet/include/pessoa/clsFisica.inc.php
@@ -288,7 +288,7 @@ class clsFisica @@ -288,7 +288,7 @@ class clsFisica
288 $campos .= ", nome_conjuge"; 288 $campos .= ", nome_conjuge";
289 $valores .= ", '$this->nome_conjuge' "; 289 $valores .= ", '$this->nome_conjuge' ";
290 } 290 }
291 - if(is_string($this->nome-responsavel)) 291 + if(is_string($this->nome_responsavel))
292 { 292 {
293 $campos .= ", nome_responsavel"; 293 $campos .= ", nome_responsavel";
294 $valores .= ", '$this->nome_responsavel' "; 294 $valores .= ", '$this->nome_responsavel' ";
@@ -459,20 +459,18 @@ class clsFisica @@ -459,20 +459,18 @@ class clsFisica
459 $set .= "$gruda idpes_rev = '{$this->idpes_rev}'"; 459 $set .= "$gruda idpes_rev = '{$this->idpes_rev}'";
460 $gruda = ", "; 460 $gruda = ", ";
461 } 461 }
462 - if($this->cpf)  
463 - {  
464 - $set .= "$gruda cpf = '{$this->cpf}'"; 462 +
  463 + if($this->cpf) {
  464 + $set .= "$gruda cpf = {$this->cpf}";
465 $gruda = ", "; 465 $gruda = ", ";
466 } 466 }
467 467
468 - if(is_numeric($this->ref_cod_sistema) || $this->ref_cod_sistema == "NULL")  
469 - { 468 + if(is_numeric($this->ref_cod_sistema) || $this->ref_cod_sistema == "NULL") {
470 $set .= "$gruda ref_cod_sistema = {$this->ref_cod_sistema}"; 469 $set .= "$gruda ref_cod_sistema = {$this->ref_cod_sistema}";
471 $gruda = ", "; 470 $gruda = ", ";
472 } 471 }
473 472
474 - if(is_numeric($this->ref_cod_religiao))  
475 - { 473 + if(is_numeric($this->ref_cod_religiao)) {
476 $set .= "$gruda ref_cod_religiao = {$this->ref_cod_religiao}"; 474 $set .= "$gruda ref_cod_religiao = {$this->ref_cod_religiao}";
477 $gruda = ", "; 475 $gruda = ", ";
478 } 476 }
ieducar/lib/Portabilis/Utils/Validation.php 0 → 100644
@@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
  1 +<?php
  2 +
  3 +#error_reporting(E_ALL);
  4 +#ini_set("display_errors", 1);
  5 +
  6 +/**
  7 + * i-Educar - Sistema de gestão escolar
  8 + *
  9 + * Copyright (C) 2006 Prefeitura Municipal de Itajaí
  10 + * <ctima@itajai.sc.gov.br>
  11 + *
  12 + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
  13 + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free
  14 + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
  15 + * qualquer versão posterior.
  16 + *
  17 + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM
  18 + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU
  19 + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
  20 + * do GNU para mais detalhes.
  21 + *
  22 + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
  23 + * com este programa; se não, escreva para a Free Software Foundation, Inc., no
  24 + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  25 + *
  26 + * @author Lucas D'Avila <lucasdavila@portabilis.com.br>
  27 + * @category i-Educar
  28 + * @license @@license@@
  29 + * @package Portabilis
  30 + * @since Arquivo disponível desde a versão 1.1.0
  31 + * @version $Id$
  32 + */
  33 +
  34 +require_once 'lib/Portabilis/Utils/User.php';
  35 +
  36 +/**
  37 + * Portabilis_Utils_Validation class.
  38 + *
  39 + * @author Lucas D'Avila <lucasdavila@portabilis.com.br>
  40 + * @category i-Educar
  41 + * @license @@license@@
  42 + * @package Portabilis
  43 + * @since Classe disponível desde a versão 1.1.0
  44 + * @version @@package_version@@
  45 + */
  46 +class Portabilis_Utils_Validation {
  47 +
  48 + public static function validatesCpf($cpf) {
  49 + $cpf = preg_replace('/[^0-9]/', '', (string)$cpf);
  50 +
  51 + if (strlen($cpf) != 11)
  52 + return false;
  53 +
  54 + // calcula primeiro dígito verificador
  55 + $soma = 0;
  56 +
  57 + for ($i = 0; $i < 9; $i++)
  58 + $soma += ((10 - $i) * $cpf[$i]);
  59 +
  60 + $primeiroDigito = 11 - ($soma % 11);
  61 +
  62 + if ($primeiroDigito >= 10)
  63 + $primeiroDigito = 0;
  64 +
  65 +
  66 + // calcula segundo dígito verificador
  67 + $soma = 0;
  68 +
  69 + for ($i = 0; $i < 10; $i++)
  70 + $soma += ((11 - $i) * $cpf[$i]);
  71 +
  72 + $segundoDigito = 11 - ($soma % 11);
  73 +
  74 + if ($segundoDigito >= 10)
  75 + $segundoDigito = 0;
  76 +
  77 +
  78 + return ($primeiroDigito == $cpf[9] && $segundoDigito == $cpf[10]);
  79 + }
  80 +}
ieducar/modules/Api/Views/PessoaController.php
@@ -39,6 +39,20 @@ require_once &#39;lib/Portabilis/String/Utils.php&#39;; @@ -39,6 +39,20 @@ require_once &#39;lib/Portabilis/String/Utils.php&#39;;
39 class PessoaController extends ApiCoreController 39 class PessoaController extends ApiCoreController
40 { 40 {
41 41
  42 + protected function canGet() {
  43 + $can = true;
  44 +
  45 + if (! $this->getRequest()->id && ! $this->getRequest()->cpf) {
  46 + $can = false;
  47 + $this->messenger->append("É necessário receber uma variavel 'id' ou 'cpf'");
  48 + }
  49 +
  50 + elseif ($this->getRequest()->id)
  51 + $can = $this->validatesResourceId();
  52 +
  53 + return $can;
  54 + }
  55 +
42 // validators 56 // validators
43 57
44 // overwrite api core validator 58 // overwrite api core validator
@@ -72,6 +86,21 @@ class PessoaController extends ApiCoreController @@ -72,6 +86,21 @@ class PessoaController extends ApiCoreController
72 return $pessoa; 86 return $pessoa;
73 } 87 }
74 88
  89 + protected function loadPessoaByCpf($cpf = null) {
  90 + $cpf = preg_replace('/[^0-9]/', '', (string)$cpf);
  91 +
  92 + if (! $cpf)
  93 + throw new Exception("CPF deve conter caracteres numéricos");
  94 +
  95 + $sql = "select pessoa.idpes as id, nome from cadastro.pessoa, fisica
  96 + where fisica.idpes = pessoa.idpes and cpf = $1 limit 1";
  97 +
  98 + $pessoa = $this->fetchPreparedQuery($sql, $cpf, false, 'first-row');
  99 + $pessoa['nome'] = $this->toUtf8($pessoa['nome'], array('transform' => true));
  100 +
  101 + return $pessoa;
  102 + }
  103 +
75 protected function loadDetails($pessoaId = null) { 104 protected function loadDetails($pessoaId = null) {
76 $alunoId = $this->tryLoadAlunoId($pessoaId); 105 $alunoId = $this->tryLoadAlunoId($pessoaId);
77 106
@@ -144,9 +173,13 @@ class PessoaController extends ApiCoreController @@ -144,9 +173,13 @@ class PessoaController extends ApiCoreController
144 $pessoa = array(); 173 $pessoa = array();
145 174
146 if ($this->canGet()) { 175 if ($this->canGet()) {
147 - $attrs = array('id', 'nome');  
148 176
149 - $pessoa = $this->loadPessoa($this->getRequest()->id); 177 + if ($this->getRequest()->id)
  178 + $pessoa = $this->loadPessoa($this->getRequest()->id);
  179 + else
  180 + $pessoa = $this->loadPessoaByCpf($this->getRequest()->cpf);
  181 +
  182 + $attrs = array('id', 'nome');
150 $pessoa = Portabilis_Array_Utils::filter($pessoa, $attrs); 183 $pessoa = Portabilis_Array_Utils::filter($pessoa, $attrs);
151 184
152 $details = $this->loadDetails($this->getRequest()->id); 185 $details = $this->loadDetails($this->getRequest()->id);
ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js
  1 +(function($) {
  2 + $(document).ready(function() {
1 3
2 -// simple search options 4 + var $form = $j('#formcadastro');
  5 + var $submitButton = $j('#btn_enviar');
  6 + var $cpfField = $j('#id_federal');
  7 + var $cpfNotice = $j('<span>').html('')
  8 + .addClass('error resource-notice')
  9 + .hide()
  10 + .width($j('#nm_pessoa').outerWidth() - 12)
  11 + .appendTo($cpfField.parent());
3 12
4 -/*var simpleSearchPaisOrigemOptions = {  
5 - placeholder : safeUtf8Decode('Informe o código ou nome do pais de origem')  
6 -};*/  
7 13
8 -// when page is ready 14 + var handleGetPersonByCpf = function(dataResponse) {
  15 + handleMessages(dataResponse.msgs);
  16 + $cpfNotice.hide();
9 17
10 -(function($) {  
11 - $(document).ready(function() { 18 + var pessoaId = dataResponse.id;
12 19
13 - // hide or show #pais_origem_nome by #tipo_nacionalidade 20 + if (pessoaId && pessoaId != $j('#cod_pessoa_fj').val()) {
  21 + $cpfNotice.html(stringUtils.toUtf8('CPF já utilizado pela pessoa código ' + pessoaId + ', ')).slideDown('fast');
  22 +
  23 + $j('<a>').addClass('decorated')
  24 + .attr('href', '/intranet/atendidos_cad.php?cod_pessoa_fj=' + pessoaId)
  25 + .attr('target', '_blank')
  26 + .html('acessar cadastro.')
  27 + .appendTo($cpfNotice);
  28 +
  29 + $j('body').animate({ scrollTop: $j('body').offset().top }, 'fast');
  30 + }
  31 +
  32 + else if ($j(document).data('submit_form_after_ajax_validation'))
  33 + formUtils.submit();
  34 + }
  35 +
  36 +
  37 + var getPersonByCpf = function(cpf) {
  38 + var options = {
  39 + url : getResourceUrlBuilder.buildUrl('/module/Api/pessoa', 'pessoa'),
  40 + dataType : 'json',
  41 + data : { cpf : cpf },
  42 + success : handleGetPersonByCpf,
  43 +
  44 + // forçado requisições sincronas, evitando erro com requisições ainda não concluidas,
  45 + // como no caso, onde o usuário pressiona cancelar por exemplo.
  46 + async : false
  47 + };
14 48
15 - var checkTipoNacionalidade = function(){ 49 + getResource(options);
  50 + }
  51 +
  52 +
  53 + // hide or show #pais_origem_nome by #tipo_nacionalidade
  54 + var checkTipoNacionalidade = function() {
16 if ($j.inArray($j('#tipo_nacionalidade').val(), ['2', '3']) > -1) 55 if ($j.inArray($j('#tipo_nacionalidade').val(), ['2', '3']) > -1)
17 $j('#pais_origem_nome').show(); 56 $j('#pais_origem_nome').show();
18 else 57 else
19 $j('#pais_origem_nome').hide(); 58 $j('#pais_origem_nome').hide();
20 } 59 }
21 60
22 - checkTipoNacionalidade();  
23 - $j('#tipo_nacionalidade').change(checkTipoNacionalidade); 61 +
  62 + var validatesCpf = function() {
  63 + var valid = true;
  64 + var cpf = $cpfField.val();
  65 +
  66 + $cpfNotice.hide();
  67 +
  68 + if (cpf && ! validationUtils.validatesCpf(cpf)) {
  69 + $cpfNotice.html(stringUtils.toUtf8('O CPF informado é inválido')).slideDown('fast');
  70 +
  71 + // não usado $cpfField.focus(), pois isto prenderia o usuário a página,
  72 + // caso o mesmo tenha informado um cpf invalido e clique em cancelar
  73 + $j('body').animate({ scrollTop: $j('body').offset().top }, 'fast');
  74 +
  75 + valid = false;
  76 + }
  77 +
  78 + return valid;
  79 + }
  80 +
  81 +
  82 + var validatesUniquenessOfCpf = function() {
  83 + var cpf = $cpfField.val();
  84 +
  85 + if(cpf && validatesCpf())
  86 + getPersonByCpf(cpf);
  87 + }
  88 +
  89 +
  90 + var submitForm = function(event) {
  91 +
  92 + if ($cpfField.val()) {
  93 + $j(document).data('submit_form_after_ajax_validation', true);
  94 + validatesUniquenessOfCpf();
  95 + }
  96 +
  97 + else
  98 + formUtils.submit();
  99 + }
  100 +
24 101
25 // style fixup 102 // style fixup
  103 +
26 $('#pais_origem_nome').css('width', '150px'); 104 $('#pais_origem_nome').css('width', '150px');
27 105
28 - var submitForm = function(event) {  
29 - formUtils.submit();  
30 - };  
31 106
32 // bind events 107 // bind events
33 - $j('#btn_enviar').removeAttr('onclick');  
34 - $j('#btn_enviar').click(submitForm);  
35 108
36 - }); // ready  
37 -})(jQuery); 109 + checkTipoNacionalidade();
  110 + $j('#tipo_nacionalidade').change(checkTipoNacionalidade);
  111 +
  112 + $cpfField.focusout(function() {
  113 + $j(document).removeData('submit_form_after_ajax_validation');
  114 + validatesUniquenessOfCpf();
  115 + });
38 116
  117 + $submitButton.removeAttr('onclick');
  118 + $submitButton.click(submitForm);
  119 +
  120 + }); // ready
  121 +})(jQuery);
39 \ No newline at end of file 122 \ No newline at end of file
ieducar/modules/Portabilis/Assets/Javascripts/Validator.js
@@ -20,9 +20,50 @@ var validationUtils = { @@ -20,9 +20,50 @@ var validationUtils = {
20 return allValid; 20 return allValid;
21 }, 21 },
22 22
23 - validatesFields : function (){ 23 + validatesFields : function () {
24 return validatesPresenseOfValueInRequiredFields() && 24 return validatesPresenseOfValueInRequiredFields() &&
25 validationUtils.validatesDateFields(); 25 validationUtils.validatesDateFields();
  26 + },
  27 +
  28 + validatesCpf : function(cpf) {
  29 + cpf = cpf.replace(/[^0-9]/g, '');
  30 +
  31 + if (cpf.length != 11)
  32 + return false;
  33 +
  34 + var soma;
  35 + var resto;
  36 +
  37 + // validacao primeiro digito verificador
  38 +
  39 + soma = 0;
  40 + for (i=1; i<=9; i++)
  41 + soma = soma + parseInt(cpf.substring(i-1, i)) * (11 - i);
  42 +
  43 + resto = (soma * 10) % 11;
  44 +
  45 + if ((resto == 10) || (resto == 11))
  46 + resto = 0;
  47 +
  48 + if (resto != parseInt(cpf.substring(9, 10)) )
  49 + return false;
  50 +
  51 +
  52 + // validacao segundo digito verificador
  53 +
  54 + soma = 0;
  55 + for (i = 1; i <= 10; i++)
  56 + soma = soma + parseInt(cpf.substring(i-1, i)) * (12 - i);
  57 +
  58 + resto = (soma * 10) % 11;
  59 +
  60 + if ((resto == 10) || (resto == 11))
  61 + resto = 0;
  62 +
  63 + if (resto != parseInt(cpf.substring(10, 11) ) )
  64 + return false;
  65 +
  66 + return true;
26 } 67 }
27 }; 68 };
28 69
ieducar/modules/Portabilis/Assets/Version.php
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 usado pelo metodos loadJavascript e loadStylesheet do helper Portabilis_View_Helper_Application */ 4 usado pelo metodos loadJavascript e loadStylesheet do helper Portabilis_View_Helper_Application */
5 5
6 class Portabilis_Assets_Version { 6 class Portabilis_Assets_Version {
7 - const VERSION = "0_0_0_1003"; 7 + const VERSION = "0_0_0_1004";
8 } 8 }
9 9
10 ?> 10 ?>