Commit 796b1a5503f208e497dd2591267ea425ca3a11e6

Authored by Eriksen Costa
1 parent ea8713b3
Exists in master

Refactoring para coding standards

ieducar/intranet/include/pessoa/clsEnderecoExterno.inc.php
1 1 <?php
2   -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3   -* *
4   -* @author Prefeitura Municipal de Itajaí *
5   -* @updated 29/03/2007 *
6   -* Pacote: i-PLB Software Público Livre e Brasileiro *
7   -* *
8   -* Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí *
9   -* ctima@itajai.sc.gov.br *
10   -* *
11   -* Este programa é software livre, você pode redistribuí-lo e/ou *
12   -* modificá-lo sob os termos da Licença Pública Geral GNU, conforme *
13   -* publicada pela Free Software Foundation, tanto a versão 2 da *
14   -* Licença como (a seu critério) qualquer versão mais nova. *
15   -* *
16   -* Este programa é distribuído na expectativa de ser útil, mas SEM *
17   -* QUALQUER GARANTIA. Sem mesmo a garantia implícita de COMERCIALI- *
18   -* ZAÇÃO ou de ADEQUAÇÃO A QUALQUER PROPÓSITO EM PARTICULAR. Con- *
19   -* sulte a Licença Pública Geral GNU para obter mais detalhes. *
20   -* *
21   -* Você deve ter recebido uma cópia da Licença Pública Geral GNU *
22   -* junto com este programa. Se não, escreva para a Free Software *
23   -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *
24   -* 02111-1307, USA. *
25   -* *
26   -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27   -require_once ("include/clsBanco.inc.php");
28   -require_once ("include/Geral.inc.php");
29   -
30 2  
  3 +/**
  4 + * i-Educar - Sistema de gestão escolar
  5 + *
  6 + * Copyright (C) 2006 Prefeitura Municipal de Itajaí
  7 + * <ctima@itajai.sc.gov.br>
  8 + *
  9 + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
  10 + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free
  11 + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
  12 + * qualquer versão posterior.
  13 + *
  14 + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM
  15 + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU
  16 + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
  17 + * do GNU para mais detalhes.
  18 + *
  19 + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
  20 + * com este programa; se não, escreva para a Free Software Foundation, Inc., no
  21 + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  22 + *
  23 + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
  24 + * @category i-Educar
  25 + * @license @@license@@
  26 + * @package iEd_Pessoa
  27 + * @since Arquivo disponível desde a versão 1.0.0
  28 + * @version $Id$
  29 + */
  30 +
  31 +require_once 'include/clsBanco.inc.php';
  32 +require_once 'include/Geral.inc.php';
  33 +
  34 +/**
  35 + * clsEnderecoExterno class.
  36 + *
  37 + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
  38 + * @category i-Educar
  39 + * @license @@license@@
  40 + * @package iEd_Pessoa
  41 + * @since Classe disponível desde a versão 1.0.0
  42 + * @version @@package_version@@
  43 + */
31 44 class clsEnderecoExterno
32 45 {
33   - var $idpes;
34   - var $idpes_cad;
35   - var $idpes_rev;
36   - var $tipo;
37   - var $idtlog;
38   - var $logradouro;
39   - var $numero;
40   - var $letra;
41   - var $complemento;
42   - var $bairro;
43   - var $cep;
44   - var $cidade;
45   - var $sigla_uf;
46   - var $reside_desde;
47   - var $bloco;
48   - var $apartamento;
49   - var $andar;
50   -
51   -
52   -
53   - var $tabela;
54   - var $schema = "cadastro";
55   -
56   - /**
57   - * Construtor
58   - *
59   - * @return Object:clsEnderecoExterno
60   - */
61   - function clsEnderecoExterno( $idpes = false, $tipo = false, $idtlog = false, $logradouro = false, $numero = false, $letra = false, $complemento = false, $bairro = false, $cep = false, $cidade = false, $sigla_uf = false, $reside_desde = false, $bloco = false, $apartamento = false, $andar = false, $idpes_cad = false, $idpes_rev = false)
62   - {
63   - $idtlog = urldecode($idtlog);
64   -
65   - $objPessoa = new clsPessoa_($idpes);
66   - if($objPessoa->detalhe())
67   - {
68   - $this->idpes = $idpes;
69   - }
70   -
71   - $this->tipo = $tipo;
72   -
73   - $objTipoLog = new clsTipoLogradouro($idtlog);
74   - if($objTipoLog->detalhe())
75   - {
76   - $this->idtlog = $idtlog;
77   - }
78   -
79   - $this->logradouro = $logradouro;
80   - $this->numero = $numero;
81   - $this->letra = $letra;
82   - $this->complemento = $complemento;
83   - $this->bairro = $bairro;
84   - $this->cep = $cep;
85   - $this->cidade = $cidade;
86   -
87   - $objSiglaUf = new clsUf($sigla_uf);
88   - if($objPessoa->detalhe())
89   - {
90   - $this->sigla_uf = $sigla_uf;
91   - }
92   - $this->idpes_cad = $idpes_cad ? $idpes_cad : $_SESSION['id_pessoa'];
93   - $this->idpes_rev = $idpes_rev ? $idpes_rev : $_SESSION['id_pessoa'];
94   - $this->reside_desde = $reside_desde;
95   - $this->bloco = $bloco;
96   - $this->apartamento = $apartamento;
97   - $this->andar = $andar;
98   -
99   - $this->tabela = "endereco_externo";
100   - }
101   -
102   - /**
103   - * Funcao que cadastra um novo registro com os valores atuais
104   - *
105   - * @return bool
106   - */
107   - function cadastra()
108   - {
109   - $db = new clsBanco();
110   - // verificacoes de campos obrigatorios para insercao
111   - // echo "is_numeric( $this->tipo ) && is_string( $this->idtlog ) && is_string( $this->logradouro ) && is_string( $this->cidade ) && is_string( $this->sigla_uf ) && is_numeric($this->idpes_cad) ";die;
112   -
113   - if( is_numeric( $this->tipo ) && is_string( $this->idtlog ) && is_string( $this->logradouro ) && is_string( $this->cidade ) && is_string( $this->sigla_uf ) && is_numeric($this->idpes_cad) )
114   - {
115   - $campos = "";
116   - $values = "";
117   -
118   - if(is_numeric($this->numero))
119   - {
120   - $campos .= ", numero";
121   - $values .= ", '{$this->numero}'";
122   - }
123   - if(is_string($this->letra))
124   - {
125   - $campos .= ", letra";
126   - $values .= ", '{$this->letra}'";
127   - }
128   - if(is_string($this->complemento))
129   - {
130   - $campos .= ", complemento";
131   - $values .= ", '{$this->complemento}'";
132   - }
133   - if(is_string($this->bairro))
134   - {
135   - $campos .= ", bairro";
136   - $values .= ", '{$this->bairro}'";
137   - }
138   - if($this->cep)
139   - {
140   - $campos .= ", cep";
141   - $values .= ", '{$this->cep}'";
142   - }
143   - if(is_string($this->reside_desde))
144   - {
145   - $campos .= ", reside_desde";
146   - $values .= ", '{$this->reside_desde}'";
147   - }
148   - if(is_string($this->bloco))
149   - {
150   - $campos .= ", bloco";
151   - $values .= ", '{$this->bloco}'";
152   - }
153   - if(is_numeric($this->apartamento))
154   - {
155   - $campos .= ", apartamento";
156   - $values .= ", '{$this->apartamento}'";
157   - }
158   - if(is_numeric($this->andar))
159   - {
160   - $campos .= ", andar";
161   - $values .= ", '{$this->andar}'";
162   - }
163   - $db->Consulta( "INSERT INTO {$this->schema}.{$this->tabela} ( idpes, tipo, idtlog, logradouro, cidade, sigla_uf, origem_gravacao, idsis_cad, data_cad, operacao, idpes_cad $campos ) VALUES ( '{$this->idpes}', 1, '{$this->idtlog}', '{$this->logradouro}', '{$this->cidade}', '{$this->sigla_uf}', 'M', 17, NOW(), 'I', '$this->idpes_cad' $values )" );
164   -
165   - return true;
166   - }
167   - return false;
168   - }
169   -
170   - /**
171   - * Edita o registro atual
172   - *
173   - * @return bool
174   - */
175   - function edita()
176   - {
177   - // verifica campos obrigatorios para edicao
178   - //die("$this->tipo , $this->idtlog , $this->logradouro , $this->cidade , $this->sigla_uf , $this->idpes_rev" );
179   - //die ( (is_numeric( $this->tipo ) && is_string( $this->idtlog ) && is_string( $this->logradouro ) && is_string( $this->cidade ) && is_string( $this->sigla_uf ) && is_numeric($this->idpes_rev)) );
180   - if( is_numeric( $this->tipo ) && is_string( $this->idtlog ) && is_string( $this->logradouro ) && is_string( $this->cidade ) && is_string( $this->sigla_uf ) && is_numeric($this->idpes_rev) )
181   - {
182   -
183   -
184   - $set = "SET tipo = '{$this->tipo}', idtlog = '{$this->idtlog}', logradouro = '{$this->logradouro}', cidade = '{$this->cidade}', sigla_uf = '{$this->sigla_uf}'";
185   -
186   - if(is_numeric($this->numero))
187   - {
188   - $set .= ", numero = '{$this->numero}'";
189   - }
190   - else
191   - {
192   - $set .= ", numero = NULL";
193   - }
194   -
195   - if(is_string($this->letra))
196   - {
197   - $set .= ", letra = '{$this->letra}'";
198   - }
199   - else
200   - {
201   - $set .= ", letra = NULL";
202   - }
203   -
204   - if(is_string($this->complemento))
205   - {
206   - $set .= ", complemento = '{$this->complemento}'";
207   - }
208   - else
209   - {
210   - $set .= ", complemento = NULL";
211   - }
212   -
213   - if(is_string($this->bairro))
214   - {
215   - $set .= ", bairro = '{$this->bairro}'";
216   - }
217   - else
218   - {
219   - $set .= ", bairro = NULL";
220   - }
221   -
222   - if(is_numeric($this->cep))
223   - {
224   - $set .= ", cep = '{$this->cep}'";
225   - }
226   - else
227   - {
228   - $set .= ", cep = NULL";
229   - }
230   -
231   - if(is_string($this->reside_desde))
232   - {
233   - $set .= ", reside_desde = '{$this->reside_desde}'";
234   - }
235   - else
236   - {
237   - $set .= ", reside_desde = NULL";
238   - }
239   -
240   - if(is_string($this->bloco))
241   - {
242   - $set .= ", bloco = '{$this->bloco}'";
243   - }
244   - else
245   - {
246   - $set .= ", bloco = NULL";
247   - }
248   -
249   - if(is_numeric($this->apartamento))
250   - {
251   - $set .= ", apartamento = '{$this->apartamento}'";
252   - }
253   - else
254   - {
255   - $set .= ", apartamento = NULL";
256   - }
257   -
258   - if(is_numeric($this->andar))
259   - {
260   - $set .= ", andar = '{$this->andar}'";
261   - }
262   - else
263   - {
264   - $set .= ", andar = NULL";
265   - }
266   - if(is_numeric($this->idpes_rev))
267   - {
268   - $set .= ", idpes_rev = '$this->idpes_rev'";
269   - }
270   - //die("UPDATE {$this->schema}.{$this->tabela} $set WHERE idpes = '$this->idpes' AND tipo = 1" );
271   - $db = new clsBanco();
272   - $db->Consulta( "UPDATE {$this->schema}.{$this->tabela} $set WHERE idpes = '$this->idpes' AND tipo = 1" );
273   - return true;die;
274   - }
275   -
276   - return false;
277   - }
278   -
279   - /**
280   - * Remove o registro atual
281   - *
282   - * @return bool
283   - */
284   - function exclui()
285   - {
286   - // verifica se existe um ID definido para delecao
287   - if( is_numeric( $this->idpes ) )
288   - {
289   - $db = new clsBanco();
290   - $db->Consulta("DELETE FROM {$this->schema}.{$this->tabela} WHERE idpes ='{$this->idpes}' ");
291   - return true;
292   - }
293   - return false;
294   - }
295   -
296   - /**
297   - * Exibe uma lista baseada nos parametros de filtragem passados
298   - *
299   - * @return Array
300   - */
301   - function lista( $str_idtlog = false, $str_logradouro = false, $int_numero = false, $str_letra = false, $str_complemento = false, $str_bairro = false, $int_cep = false, $str_cidade = false, $sigla_uf = false, $str_reside_desde = false, $str_bloco = false, $int_apartamento = false, $int_andar = false, $int_limite_ini=0, $int_limite_qtd=20, $str_orderBy = false, $int_idpes = false )
302   - {
303   - // verificacoes de filtros a serem usados
304   - $whereAnd = "WHERE ";
305   -
306   - if(is_string($int_idpes))
307   - {
308   - $where .= "{$whereAnd}idpes IN ({$int_idpes})";
309   - $whereAnd = " AND ";
310   - }
311   -
312   - if( is_string( $str_idtlog ) )
313   - {
314   - $where .= "{$whereAnd}idtlog LIKE '%$str_idtlog%'";
315   - $whereAnd = " AND ";
316   - }
317   - if( is_string( $str_logradouro ) )
318   - {
319   - $where .= "{$whereAnd}logradouro LIKE '%$str_logradouro%'";
320   - $whereAnd = " AND ";
321   - }
322   - if( is_numeric( $int_numero ) )
323   - {
324   - $where .= "{$whereAnd}numero = '$int_numero'";
325   - $whereAnd = " AND ";
326   - }
327   - if( is_string( $str_letra ) )
328   - {
329   - $where .= "{$whereAnd}letra LIKE '%$str_letra%'";
330   - $whereAnd = " AND ";
331   - }
332   - if( is_string( $str_complemento ) )
333   - {
334   - $where .= "{$whereAnd}complemento LIKE '%$str_complemento%'";
335   - $whereAnd = " AND ";
336   - }
337   - if( is_string( $str_bairro ) )
338   - {
339   - $where .= "{$whereAnd}bairro LIKE '%$str_bairro%'";
340   - $whereAnd = " AND ";
341   - }
342   - if( is_numeric( $int_cep ) )
343   - {
344   - $where .= "{$whereAnd}cep = '$int_cep'";
345   - $whereAnd = " AND ";
346   - }
347   - if( is_string( $str_cidade ) )
348   - {
349   - $where .= "{$whereAnd}cidade LIKE '%$str_cidade%'";
350   - $whereAnd = " AND ";
351   - }
352   - if( is_string( $sigla_uf ) )
353   - {
354   - $where .= "{$whereAnd}sigla_uf LIKE '%$sigla_uf%'";
355   - $whereAnd = " AND ";
356   - }
357   - if( is_string( $str_reside_desde ) )
358   - {
359   - $where .= "{$whereAnd}reside_desde LIKE '%$str_reside_desde%'";
360   - $whereAnd = " AND ";
361   - }
362   - if( is_string( $str_bloco ) )
363   - {
364   - $where .= "{$whereAnd}bloco = '$str_bloco'";
365   - $whereAnd = " AND ";
366   - }
367   - if( is_numeric( $int_apartamento) )
368   - {
369   - $where .= "{$whereAnd}apartamento = '$int_apartamento'";
370   - $whereAnd = " AND ";
371   - }
372   - if( is_numeric( $int_andar) )
373   - {
374   - $where .= "{$whereAnd}andar = '$int_andar'";
375   - $whereAnd = " AND ";
376   - }
377   -
378   - if($str_orderBy)
379   - {
380   - $orderBy = "ORDER BY $str_orderBy";
381   - }
382   -
383   - $limit = "";
384   - if( is_numeric( $int_limite_ini ) && is_numeric( $int_limite_qtd ) )
385   - {
386   - $limit = " LIMIT $int_limite_ini,$int_limite_qtd";
387   - }
388   -
389   - $db = new clsBanco();
390   - $db->Consulta( "SELECT COUNT(0) AS total FROM {$this->schema}.{$this->tabela} $where" );
391   - $db->ProximoRegistro();
392   - $total = $db->Campo( "total" );
393   - //echo "SELECT idpes, tipo, idtlog, logradouro, numero, letra, complemento, bairro, cep, cidade, sigla_uf, reside_desde, bloco, apartamento, andar FROM {$this->schema}.{$this->tabela} $where $orderBy $limit"; die();
394   - $db->Consulta( "SELECT idpes, tipo, idtlog, logradouro, numero, letra, complemento, bairro, cep, cidade, sigla_uf, reside_desde, bloco, apartamento, andar FROM {$this->schema}.{$this->tabela} $where $orderBy $limit" );
395   - $resultado = array();
396   - while ( $db->ProximoRegistro() )
397   - {
398   - $tupla = $db->Tupla();
399   - $tupla["idpes"] = new clsPessoa_( $tupla["idpes"] );
400   - $tupla["idtlog"] = new clsTipoLogradouro( $tupla["idtlog"]);
401   - $tupla["sigla_uf"] = new clsUf( $tupla["sigla_uf"]);
402   - $tupla["total"] = $total;
403   - $resultado[] = $tupla;
404   - }
405   - if( count( $resultado ) )
406   - {
407   - return $resultado;
408   - }
409   - return false;
410   - }
411   -
412   - /**
413   - * Retorna um array com os detalhes do objeto
414   - *
415   - * @return Array
416   - */
417   - function detalhe()
418   - {
419   - if($this->idpes)
420   - {
421   - $db = new clsBanco();
422   - $db->Consulta("SELECT idpes, tipo, idtlog, logradouro, numero, letra, complemento, bairro, cep, cidade, sigla_uf, reside_desde, bloco, apartamento, andar FROM {$this->schema}.{$this->tabela} WHERE idpes='{$this->idpes}'");
423   - if( $db->ProximoRegistro() )
424   - {
425   - $tupla = $db->Tupla();
426   - $this->idpes = $tupla["idpes"];
427   - $this->tipo = $tupla["tipo"];
428   - $this->idtlog = $tupla["idtlog"];
429   - $this->logradouro = $tupla["logradouro"];
430   - $this->numero = $tupla["numero"];
431   - $this->letra = $tupla["letra"];
432   - $this->complemento = $tupla["complemento"];
433   - $this->bairro = $tupla["bairro"];
434   - $this->cep = $tupla["cep"];
435   - $this->cidade = $tupla["cidade"];
436   - $this->sigla_uf = $tupla["sigla_uf"];
437   - $this->reside_desde = $tupla["reside_desde"];
438   - $this->bloco = $tupla["bloco"];
439   - $this->apartamento = $tupla["apartamento"];
440   - $this->andar = $tupla["andar"];
441   -
442   - $tupla["idpes"] = new clsPessoa_( $tupla["idpes"] );
443   - $tupla["idtlog"] = new clsTipoLogradouro( $tupla["idtlog"]);
444   - $tupla["sigla_uf"] = new clsUf( $tupla["sigla_uf"]);
445   -
446   - return $tupla;
447   - }
448   - }
449   - return false;
450   - }
451   -
452   - /**
453   - * Retorna um array com os dados de um registro
454   - *
455   - * @return array
456   - */
457   - function existe()
458   - {
459   - if( is_numeric( $this->idpes ) )
460   - {
461   -
462   - $db = new clsBanco();
463   - $db->Consulta( "SELECT 1 FROM {$this->schema}.{$this->tabela} WHERE IDPES = '{$this->idpes}'" );
464   - $db->ProximoRegistro();
465   - return $db->Tupla();
466   - }
467   - return false;
468   - }
469   -}
470   -?>
471 46 \ No newline at end of file
  47 + var $idpes;
  48 + var $idpes_cad;
  49 + var $idpes_rev;
  50 + var $tipo;
  51 + var $idtlog;
  52 + var $logradouro;
  53 + var $numero;
  54 + var $letra;
  55 + var $complemento;
  56 + var $bairro;
  57 + var $cep;
  58 + var $cidade;
  59 + var $sigla_uf;
  60 + var $reside_desde;
  61 + var $bloco;
  62 + var $apartamento;
  63 + var $andar;
  64 +
  65 + var $tabela;
  66 + var $schema = 'cadastro';
  67 +
  68 + /**
  69 + * Construtor.
  70 + */
  71 + function clsEnderecoExterno($idpes = FALSE, $tipo = FALSE, $idtlog = FALSE,
  72 + $logradouro = FALSE, $numero = FALSE, $letra = FALSE, $complemento = FALSE,
  73 + $bairro = FALSE, $cep = FALSE, $cidade = FALSE, $sigla_uf = FALSE,
  74 + $reside_desde = FALSE, $bloco = FALSE, $apartamento = FALSE, $andar = FALSE,
  75 + $idpes_cad = FALSE, $idpes_rev = FALSE)
  76 + {
  77 + $idtlog = urldecode($idtlog);
  78 +
  79 + $objPessoa = new clsPessoa_($idpes);
  80 + if ($objPessoa->detalhe()) {
  81 + $this->idpes = $idpes;
  82 + }
  83 +
  84 + $this->tipo = $tipo;
  85 +
  86 + $objTipoLog = new clsTipoLogradouro($idtlog);
  87 + if ($objTipoLog->detalhe()) {
  88 + $this->idtlog = $idtlog;
  89 + }
  90 +
  91 + $this->logradouro = $logradouro;
  92 + $this->numero = $numero;
  93 + $this->letra = $letra;
  94 + $this->complemento = $complemento;
  95 + $this->bairro = $bairro;
  96 + $this->cep = $cep;
  97 + $this->cidade = $cidade;
  98 +
  99 + $objSiglaUf = new clsUf($sigla_uf);
  100 + if ($objPessoa->detalhe()) {
  101 + $this->sigla_uf = $sigla_uf;
  102 + }
  103 +
  104 + $this->idpes_cad = $idpes_cad ? $idpes_cad : $_SESSION['id_pessoa'];
  105 + $this->idpes_rev = $idpes_rev ? $idpes_rev : $_SESSION['id_pessoa'];
  106 + $this->reside_desde = $reside_desde;
  107 + $this->bloco = $bloco;
  108 + $this->apartamento = $apartamento;
  109 + $this->andar = $andar;
  110 +
  111 + $this->tabela = 'endereco_externo';
  112 + }
  113 +
  114 + /**
  115 + * Cria um novo registro.
  116 + * @return bool
  117 + */
  118 + function cadastra()
  119 + {
  120 + $db = new clsBanco();
  121 +
  122 + if (
  123 + is_numeric($this->tipo) && is_string($this->idtlog) &&
  124 + is_string($this->logradouro) && is_string($this->cidade) &&
  125 + is_string($this->sigla_uf) && is_numeric($this->idpes_cad))
  126 + {
  127 + $campos = '';
  128 + $values = '';
  129 +
  130 + if (is_numeric($this->numero)) {
  131 + $campos .= ', numero';
  132 + $values .= ", '{$this->numero}'";
  133 + }
  134 +
  135 + if (is_string($this->letra)) {
  136 + $campos .= ', letra';
  137 + $values .= ", '{$this->letra}'";
  138 + }
  139 +
  140 + if (is_string($this->complemento)) {
  141 + $campos .= ', complemento';
  142 + $values .= ", '{$this->complemento}'";
  143 + }
  144 +
  145 + if (is_string($this->bairro)) {
  146 + $campos .= ', bairro';
  147 + $values .= ", '{$this->bairro}'";
  148 + }
  149 +
  150 + if ($this->cep) {
  151 + $campos .= ', cep';
  152 + $values .= ", '{$this->cep}'";
  153 + }
  154 +
  155 + if (is_string($this->reside_desde)) {
  156 + $campos .= ', reside_desde';
  157 + $values .= ", '{$this->reside_desde}'";
  158 + }
  159 +
  160 + if (is_string($this->bloco)) {
  161 + $campos .= ', bloco';
  162 + $values .= ", '{$this->bloco}'";
  163 + }
  164 +
  165 + if (is_numeric($this->apartamento)) {
  166 + $campos .= ', apartamento';
  167 + $values .= ", '{$this->apartamento}'";
  168 + }
  169 +
  170 + if (is_numeric($this->andar)) {
  171 + $campos .= ', andar';
  172 + $values .= ", '{$this->andar}'";
  173 + }
  174 +
  175 + $sql = sprintf(
  176 + 'INSERT INTO %s.%s (idpes, tipo, idtlog, logradouro, cidade, sigla_uf, ' .
  177 + 'origem_gravacao, idsis_cad, data_cad, operacao, idpes_cad %s) ' .
  178 + 'VALUES (\'%d\', 1, \'%s\', \'%s\', \'%s\', \'%s\', \'M\', 17, NOW(), \'I\', \'%d\' %s)',
  179 + $this->schema, $this->tabela, $campos, $this->idpes, $this->idtlog,
  180 + $this->logradouro, $this->cidade, $this->sigla_uf, $this->idpes_cad,
  181 + $values
  182 + );
  183 +
  184 + $db->Consulta($sql);
  185 + return TRUE;
  186 + }
  187 +
  188 + return FALSE;
  189 + }
  190 +
  191 + /**
  192 + * Edita os dados de um registro.
  193 + * @return bool
  194 + */
  195 + function edita()
  196 + {
  197 + if (
  198 + is_numeric($this->tipo) && is_string($this->idtlog) &&
  199 + is_string($this->logradouro) && is_string($this->cidade) &&
  200 + is_string($this->sigla_uf) && is_numeric($this->idpes_rev)
  201 + )
  202 + {
  203 + $set = sprintf(
  204 + 'SET tipo = \'%d\', idtlog = \'%s\', logradouro = \'%s\', cidade = \'%s\', sigla_uf = \'%s\'',
  205 + $this->tipo, $this->idtlog, $this->logradouro, $this->cidade, $this->sigla_uf
  206 + );
  207 +
  208 + if (is_numeric($this->numero)) {
  209 + $set .= ", numero = '{$this->numero}'";
  210 + }
  211 + else {
  212 + $set .= ", numero = NULL";
  213 + }
  214 +
  215 + if (is_string($this->letra)) {
  216 + $set .= ", letra = '{$this->letra}'";
  217 + }
  218 + else {
  219 + $set .= ", letra = NULL";
  220 + }
  221 +
  222 + if (is_string($this->complemento)) {
  223 + $set .= ", complemento = '{$this->complemento}'";
  224 + }
  225 + else {
  226 + $set .= ", complemento = NULL";
  227 + }
  228 +
  229 + if (is_string($this->bairro)) {
  230 + $set .= ", bairro = '{$this->bairro}'";
  231 + }
  232 + else {
  233 + $set .= ", bairro = NULL";
  234 + }
  235 +
  236 + if (is_numeric($this->cep)) {
  237 + $set .= ", cep = '{$this->cep}'";
  238 + }
  239 + else {
  240 + $set .= ", cep = NULL";
  241 + }
  242 +
  243 + if (is_string($this->reside_desde)) {
  244 + $set .= ", reside_desde = '{$this->reside_desde}'";
  245 + }
  246 + else {
  247 + $set .= ", reside_desde = NULL";
  248 + }
  249 +
  250 + if (is_string($this->bloco)) {
  251 + $set .= ", bloco = '{$this->bloco}'";
  252 + }
  253 + else {
  254 + $set .= ", bloco = NULL";
  255 + }
  256 +
  257 + if (is_numeric($this->apartamento)) {
  258 + $set .= ", apartamento = '{$this->apartamento}'";
  259 + }
  260 + else {
  261 + $set .= ", apartamento = NULL";
  262 + }
  263 +
  264 + if (is_numeric($this->andar)) {
  265 + $set .= ", andar = '{$this->andar}'";
  266 + }
  267 + else {
  268 + $set .= ", andar = NULL";
  269 + }
  270 +
  271 + if (is_numeric($this->idpes_rev)) {
  272 + $set .= ", idpes_rev = '$this->idpes_rev'";
  273 + }
  274 +
  275 + $sql = sprintf(
  276 + 'UPDATE %s.%s %s WHERE idpes = \'%d\' AND tipo = 1',
  277 + $this->schema, $this->tabela, $set, $this->idpes
  278 + );
  279 +
  280 + $db = new clsBanco();
  281 + $db->Consulta($sql);
  282 + return TRUE;
  283 + }
  284 +
  285 + return FALSE;
  286 + }
  287 +
  288 + /**
  289 + * Exclui um registro.
  290 + * @return bool
  291 + */
  292 + function exclui()
  293 + {
  294 + if (is_numeric($this->idpes)) {
  295 + $db = new clsBanco();
  296 +
  297 + $db->Consulta(sprintf(
  298 + 'DELETE FROM %s.%s WHERE idpes = \'%d\'',
  299 + $this->schema, $this->tabela, $this->idpes
  300 + ));
  301 +
  302 + return TRUE;
  303 + }
  304 +
  305 + return FALSE;
  306 + }
  307 +
  308 + /**
  309 + * Retorna uma lista de registros filtrados de acordo com os parâmetros.
  310 + * @return array
  311 + */
  312 + function lista($str_idtlog = FALSE, $str_logradouro = FALSE,
  313 + $int_numero = FALSE, $str_letra = FALSE, $str_complemento = FALSE,
  314 + $str_bairro = FALSE, $int_cep = FALSE, $str_cidade = FALSE, $sigla_uf = FALSE,
  315 + $str_reside_desde = FALSE, $str_bloco = FALSE, $int_apartamento = FALSE,
  316 + $int_andar = FALSE, $int_limite_ini = 0, $int_limite_qtd = 20,
  317 + $str_orderBy = FALSE, $int_idpes = FALSE
  318 + )
  319 + {
  320 + $whereAnd = ' WHERE ';
  321 +
  322 + if (is_string($int_idpes)) {
  323 + $where .= "{$whereAnd}idpes IN ({$int_idpes})";
  324 + $whereAnd = ' AND ';
  325 + }
  326 +
  327 + if (is_string($str_idtlog)) {
  328 + $where .= "{$whereAnd}idtlog LIKE '%$str_idtlog%'";
  329 + $whereAnd = ' AND ';
  330 + }
  331 +
  332 + if (is_string($str_logradouro)) {
  333 + $where .= "{$whereAnd}logradouro LIKE '%$str_logradouro%'";
  334 + $whereAnd = ' AND ';
  335 + }
  336 +
  337 + if (is_numeric($int_numero)) {
  338 + $where .= "{$whereAnd}numero = '$int_numero'";
  339 + $whereAnd = ' AND ';
  340 + }
  341 +
  342 + if (is_string($str_letra)) {
  343 + $where .= "{$whereAnd}letra LIKE '%$str_letra%'";
  344 + $whereAnd = ' AND ';
  345 + }
  346 +
  347 + if (is_string($str_complemento)) {
  348 + $where .= "{$whereAnd}complemento LIKE '%$str_complemento%'";
  349 + $whereAnd = ' AND ';
  350 + }
  351 +
  352 + if (is_string($str_bairro)) {
  353 + $where .= "{$whereAnd}bairro LIKE '%$str_bairro%'";
  354 + $whereAnd = ' AND ';
  355 + }
  356 +
  357 + if (is_numeric($int_cep)) {
  358 + $where .= "{$whereAnd}cep = '$int_cep'";
  359 + $whereAnd = ' AND ';
  360 + }
  361 +
  362 + if (is_string($str_cidade)) {
  363 + $where .= "{$whereAnd}cidade LIKE '%$str_cidade%'";
  364 + $whereAnd = ' AND ';
  365 + }
  366 +
  367 + if (is_string($sigla_uf)) {
  368 + $where .= "{$whereAnd}sigla_uf LIKE '%$sigla_uf%'";
  369 + $whereAnd = ' AND ';
  370 + }
  371 +
  372 + if (is_string($str_reside_desde)) {
  373 + $where .= "{$whereAnd}reside_desde LIKE '%$str_reside_desde%'";
  374 + $whereAnd = ' AND ';
  375 + }
  376 +
  377 + if (is_string($str_bloco)) {
  378 + $where .= "{$whereAnd}bloco = '$str_bloco'";
  379 + $whereAnd = ' AND ';
  380 + }
  381 +
  382 + if (is_numeric($int_apartamento)) {
  383 + $where .= "{$whereAnd}apartamento = '$int_apartamento'";
  384 + $whereAnd = ' AND ';
  385 + }
  386 +
  387 + if (is_numeric($int_andar)) {
  388 + $where .= "{$whereAnd}andar = '$int_andar'";
  389 + $whereAnd = ' AND ';
  390 + }
  391 +
  392 + if ($str_orderBy) {
  393 + $orderBy = "ORDER BY $str_orderBy";
  394 + }
  395 +
  396 + $limit = '';
  397 +
  398 + if (is_numeric($int_limite_ini) && is_numeric($int_limite_qtd)) {
  399 + $limit = " LIMIT $int_limite_ini, $int_limite_qtd";
  400 + }
  401 +
  402 + $db = new clsBanco();
  403 +
  404 + $db->Consulta("SELECT COUNT(0) AS total FROM {$this->schema}.{$this->tabela} $where");
  405 + $db->ProximoRegistro();
  406 + $total = $db->Campo('total');
  407 +
  408 + $sql = sprintf(
  409 + 'SELECT idpes, tipo, idtlog, logradouro, numero, letra, complemento, ' .
  410 + 'bairro, cep, cidade, sigla_uf, reside_desde, bloco, apartamento, andar ' .
  411 + 'FROM %s.%s %s %s %s',
  412 + $this->schema, $this->tabela, $where, $orderBy, $limit
  413 + );
  414 +
  415 + $db->Consulta($sql);
  416 +
  417 + $resultado = array();
  418 + while ($db->ProximoRegistro()) {
  419 + $tupla = $db->Tupla();
  420 +
  421 + $tupla['idpes'] = new clsPessoa_($tupla["idpes"]);
  422 + $tupla['idtlog'] = new clsTipoLogradouro($tupla['idtlog']);
  423 + $tupla['sigla_uf'] = new clsUf($tupla['sigla_uf']);
  424 + $tupla['total'] = $total;
  425 +
  426 + $resultado[] = $tupla;
  427 + }
  428 +
  429 + if (count($resultado)) {
  430 + return $resultado;
  431 + }
  432 +
  433 + return FALSE;
  434 + }
  435 +
  436 + /**
  437 + * Retorna um array com os dados de um registro
  438 + * @return array
  439 + */
  440 + function detalhe()
  441 + {
  442 + if ($this->idpes) {
  443 + $db = new clsBanco();
  444 +
  445 + $sql = sprintf(
  446 + 'SELECT idpes, tipo, idtlog, logradouro, numero, letra, complemento, ' .
  447 + 'bairro, cep, cidade, sigla_uf, reside_desde, bloco, apartamento, '.
  448 + 'andar FROM %s.%s WHERE idpes = %d',
  449 + $this->schema, $this->tabela, $this->idpes
  450 + );
  451 +
  452 + $db->Consulta($sql);
  453 +
  454 + if ($db->ProximoRegistro()) {
  455 + $tupla = $db->Tupla();
  456 + $this->idpes = $tupla['idpes'];
  457 + $this->tipo = $tupla['tipo'];
  458 + $this->idtlog = $tupla['idtlog'];
  459 + $this->logradouro = $tupla['logradouro'];
  460 + $this->numero = $tupla['numero'];
  461 + $this->letra = $tupla['letra'];
  462 + $this->complemento = $tupla['complemento'];
  463 + $this->bairro = $tupla['bairro'];
  464 + $this->cep = $tupla['cep'];
  465 + $this->cidade = $tupla['cidade'];
  466 + $this->sigla_uf = $tupla['sigla_uf'];
  467 + $this->reside_desde = $tupla['reside_desde'];
  468 + $this->bloco = $tupla['bloco'];
  469 + $this->apartamento = $tupla['apartamento'];
  470 + $this->andar = $tupla['andar'];
  471 +
  472 + $tupla['idpes'] = new clsPessoa_($tupla['idpes']);
  473 + $tupla['idtlog'] = new clsTipoLogradouro($tupla['idtlog']);
  474 + $tupla['sigla_uf'] = new clsUf($tupla['sigla_uf']);
  475 +
  476 + return $tupla;
  477 + }
  478 + }
  479 +
  480 + return FALSE;
  481 + }
  482 +
  483 + /**
  484 + * Retorna um array com os dados de um registro.
  485 + * @return array
  486 + */
  487 + function existe()
  488 + {
  489 + if (is_numeric($this->idpes)) {
  490 + $db = new clsBanco();
  491 +
  492 + $sql = sprintf(
  493 + 'SELECT 1 FROM %s.%s WHERE idpes = %d',
  494 + $this->schema, $this->tabela, $this->idpes
  495 + );
  496 +
  497 + $db->Consulta($sql);
  498 +
  499 + $db->ProximoRegistro();
  500 + return $db->Tupla();
  501 + }
  502 +
  503 + return FALSE;
  504 + }
  505 +}
472 506 \ No newline at end of file
... ...