Commit c0d931e20fee978bd68d00deeea8608e0a02cff1
1 parent
796b1a55
Exists in
master
Refactoring para coding standards
Showing
1 changed file
with
372 additions
and
371 deletions
Show diff stats
ieducar/intranet/include/pessoa/clsEnderecoPessoa.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"); | |
| 2 | + | |
| 3 | +require_once 'include/clsBanco.inc.php'; | |
| 28 | 4 | |
| 29 | 5 | class clsPessoaEndereco |
| 30 | 6 | { |
| 31 | - var $idpes; | |
| 32 | - var $idpes_cad; | |
| 33 | - var $idpes_rev; | |
| 34 | - var $tipo; | |
| 35 | - var $cep; | |
| 36 | - var $idlog; | |
| 37 | - var $idbai; | |
| 38 | - var $numero; | |
| 39 | - var $complemento; | |
| 40 | - var $reside_desde; | |
| 41 | - var $letra; | |
| 42 | - var $bloco; | |
| 43 | - var $apartamento; | |
| 44 | - var $andar; | |
| 45 | - | |
| 46 | - var $banco = 'gestao_homolog'; | |
| 47 | - var $schema_cadastro = "cadastro"; | |
| 48 | - var $tabela = "endereco_pessoa"; | |
| 49 | - | |
| 50 | - | |
| 51 | - function clsPessoaEndereco($int_idpes = false, $numeric_cep = false, $int_idlog = false, $int_idbai =false, $numeric_numero=false, $str_complemento=false, $date_reside_desde=false, $str1_letra=false, $str_bloco = false, $int_apartamento = false, $int_andar = false, $idpes_cad = false, $idpes_rev = false) | |
| 52 | - { | |
| 53 | - $this->idpes = $int_idpes; | |
| 54 | - $numeric_cep = idFederal2Int($numeric_cep); | |
| 55 | - $obj = new clsCepLogradouroBairro($int_idlog, $numeric_cep, $int_idbai); | |
| 56 | - if($obj->detalhe()) | |
| 57 | - { | |
| 58 | - $this->idbai = $int_idbai; | |
| 59 | - $this->idlog = $int_idlog; | |
| 60 | - $this->cep = $numeric_cep; | |
| 61 | - } | |
| 62 | - | |
| 63 | - $this->numero = $numeric_numero; | |
| 64 | - $this->complemento = $str_complemento; | |
| 65 | - $this->reside_desde = $date_reside_desde; | |
| 66 | - $this->letra = $str1_letra; | |
| 67 | - $this->bloco = $str_bloco; | |
| 68 | - $this->apartamento = $int_apartamento; | |
| 69 | - $this->andar = $int_andar; | |
| 70 | - $this->idpes_cad = $idpes_cad? $idpes_cad : $_SESSION['id_pessoa']; | |
| 71 | - $this->idpes_rev = $idpes_rev? $idpes_rev : $_SESSION['id_pessoa']; | |
| 72 | - | |
| 73 | - } | |
| 74 | - | |
| 75 | - function cadastra() | |
| 76 | - { | |
| 77 | - // Cadastro do endereço da pessoa na tabela endereco_pessoa | |
| 78 | - if($this->idpes && $this->cep && $this->idlog && $this->idbai && $this->idpes_cad) | |
| 79 | - { | |
| 80 | - $campos = ""; | |
| 81 | - $valores = ""; | |
| 82 | - | |
| 83 | - if($this->numero) | |
| 84 | - { | |
| 85 | - $campos .= ", numero"; | |
| 86 | - $valores .= ", '$this->numero' "; | |
| 87 | - } | |
| 88 | - if($this->letra) | |
| 89 | - { | |
| 90 | - $campos .= ", letra"; | |
| 91 | - $valores .= ", '$this->letra' "; | |
| 92 | - } | |
| 93 | - if($this->complemento) | |
| 94 | - { | |
| 95 | - $campos .= ", complemento"; | |
| 96 | - $valores .= ", '$this->complemento' "; | |
| 97 | - } | |
| 98 | - if($this->reside_desde) | |
| 99 | - { | |
| 100 | - $campos .= ", reside_desde"; | |
| 101 | - $valores .= ", '$this->reside_desde' "; | |
| 102 | - } | |
| 103 | - if($this->bloco) | |
| 104 | - { | |
| 105 | - $campos .= ", bloco"; | |
| 106 | - $valores .= ", '$this->bloco' "; | |
| 107 | - } | |
| 108 | - if($this->apartamento) | |
| 109 | - { | |
| 110 | - $campos .= ", apartamento"; | |
| 111 | - $valores .= ", '$this->apartamento' "; | |
| 112 | - } | |
| 113 | - if($this->andar) | |
| 114 | - { | |
| 115 | - $campos .= ", andar"; | |
| 116 | - $valores .= ", '$this->andar' "; | |
| 117 | - } | |
| 118 | - $db = new clsBanco(); | |
| 119 | - $db->Consulta("INSERT INTO {$this->schema_cadastro}.{$this->tabela} (idpes, tipo, cep, idlog, idbai, origem_gravacao, idsis_cad, data_cad, operacao, idpes_cad $campos) VALUES ('$this->idpes', '1', '$this->cep', '$this->idlog', '$this->idbai', 'M', 17, NOW(), 'I', '$this->idpes_cad' $valores)"); | |
| 120 | - RETURN TRUE; | |
| 121 | - } | |
| 122 | - RETURN FALSE; | |
| 123 | - } | |
| 124 | - | |
| 125 | - | |
| 126 | - | |
| 127 | - function edita() | |
| 128 | - { | |
| 129 | - // Cadastro do endereço da pessoa na tabela endereco_pessoa | |
| 130 | - if($this->idpes && $this->idpes_rev) | |
| 131 | - { | |
| 132 | - $setVir = "SET "; | |
| 133 | - $set = ""; | |
| 134 | - if($this->numero) | |
| 135 | - { | |
| 136 | - $set .= "$setVir numero = '$this->numero' "; | |
| 137 | - $setVir = ", "; | |
| 138 | - }else | |
| 139 | - { | |
| 140 | - $set .= "$setVir numero = NULL "; | |
| 141 | - $setVir = ", "; | |
| 142 | - } | |
| 143 | - if($this->letra) | |
| 144 | - { | |
| 145 | - $set .= "$setVir letra = '$this->letra' "; | |
| 146 | - $setVir = ", "; | |
| 147 | - }else | |
| 148 | - { | |
| 149 | - $set .= "$setVir letra = NULL "; | |
| 150 | - $setVir = ", "; | |
| 151 | - } | |
| 152 | - if($this->complemento) | |
| 153 | - { | |
| 154 | - $set .= "$setVir complemento = '$this->complemento' "; | |
| 155 | - $setVir = ", "; | |
| 156 | - }else | |
| 157 | - { | |
| 158 | - $set .= "$setVir complemento = NULL "; | |
| 159 | - $setVir = ", "; | |
| 160 | - } | |
| 161 | - if($this->reside_desde) | |
| 162 | - { | |
| 163 | - $set .= "$setVir reside_desde = '$this->reside_desde' "; | |
| 164 | - $setVir = ", "; | |
| 165 | - }else | |
| 166 | - { | |
| 167 | - $set .= "$setVir reside_desde = NULL "; | |
| 168 | - $setVir = ", "; | |
| 169 | - } | |
| 170 | - if($this->bloco) | |
| 171 | - { | |
| 172 | - $set .= "$setVir bloco = '$this->bloco' "; | |
| 173 | - $setVir = ", "; | |
| 174 | - }else | |
| 175 | - { | |
| 176 | - $set .= "$setVir bloco = NULL "; | |
| 177 | - $setVir = ", "; | |
| 178 | - } | |
| 179 | - if($this->apartamento) | |
| 180 | - { | |
| 181 | - $set .= "$setVir apartamento = '$this->apartamento' "; | |
| 182 | - $setVir = ", "; | |
| 183 | - }else | |
| 184 | - { | |
| 185 | - $set .= "$setVir apartamento = NULL "; | |
| 186 | - $setVir = ", "; | |
| 187 | - } | |
| 188 | - if($this->andar) | |
| 189 | - { | |
| 190 | - $set .= "$setVir andar = '$this->andar' "; | |
| 191 | - $setVir = ", "; | |
| 192 | - }else | |
| 193 | - { | |
| 194 | - $set .= "$setVir andar = NULL "; | |
| 195 | - $setVir = ", "; | |
| 196 | - } | |
| 197 | - if($this->cep && $this->idbai && $this->idlog) | |
| 198 | - { | |
| 199 | - $set .= "$setVir cep = '$this->cep', idbai = '$this->idbai', idlog = '$this->idlog'"; | |
| 200 | - $setVir = ", "; | |
| 201 | - } | |
| 202 | - if($this->idpes_rev) | |
| 203 | - { | |
| 204 | - $set .= "$setVir idpes_rev ='$this->idpes_rev'"; | |
| 205 | - } | |
| 206 | - | |
| 207 | - if($set) | |
| 208 | - { | |
| 209 | - $db = new clsBanco(); | |
| 210 | - $db->Consulta("UPDATE {$this->schema_cadastro}.{$this->tabela} $set WHERE idpes = $this->idpes"); | |
| 211 | - return true; | |
| 212 | - } | |
| 213 | - } | |
| 214 | - return false; | |
| 215 | - } | |
| 216 | - | |
| 217 | - function exclui() | |
| 218 | - { | |
| 219 | - if($this->idpes) | |
| 220 | - { | |
| 221 | - $db = new clsBanco(); | |
| 222 | - $db->Consulta("DELETE FROM $this->schema_cadastro.$this->tabela WHERE idpes = $this->idpes"); | |
| 223 | - } | |
| 224 | - | |
| 225 | - } | |
| 226 | - | |
| 227 | - function lista($int_idpes = false, $str_ordenacao = false ,$int_inicio_limite = false, $int_qtd_limite = false, $int_cep =false, $int_idlog = false, $int_idbai =false, $int_numero =false, $str_bloco = false, $int_apartamento = false, $int_andar = false, $str_letra = false, $str_complemento = false) | |
| 228 | - { | |
| 229 | - $whereAnd = "AND "; | |
| 230 | - $where = ""; | |
| 231 | - | |
| 232 | - if( is_numeric( $int_idpes) ) | |
| 233 | - { | |
| 234 | - $where .= "{$whereAnd}idpes = '$int_idpes' "; | |
| 235 | - $whereAnd = " AND "; | |
| 236 | - } | |
| 237 | - elseif (is_string($int_idpes)) | |
| 238 | - { | |
| 239 | - $where .= "{$whereAnd}idpes IN ({$int_idpes}) "; | |
| 240 | - $whereAnd = " AND "; | |
| 241 | - } | |
| 242 | - | |
| 243 | - if( is_numeric( $int_cep) ) | |
| 244 | - { | |
| 245 | - $where .= "{$whereAnd}cep = '$int_cep' "; | |
| 246 | - $whereAnd = " AND "; | |
| 247 | - } | |
| 248 | - | |
| 249 | - if( is_numeric( $int_idlog) ) | |
| 250 | - { | |
| 251 | - $where .= "{$whereAnd}idlog = '$int_idlog' "; | |
| 252 | - $whereAnd = " AND "; | |
| 253 | - } | |
| 254 | - | |
| 255 | - if( is_numeric( $int_idbai) ) | |
| 256 | - { | |
| 257 | - $where .= "{$whereAnd}idbai = '$int_idbai' "; | |
| 258 | - $whereAnd = " AND "; | |
| 259 | - } | |
| 260 | - | |
| 261 | - if( is_numeric( $int_numero) ) | |
| 262 | - { | |
| 263 | - $where .= "{$whereAnd}numero = '$int_numero' "; | |
| 264 | - $whereAnd = " AND "; | |
| 265 | - } | |
| 266 | - | |
| 267 | - if( $str_bloco ) | |
| 268 | - { | |
| 269 | - $where .= "{$whereAnd}bloco = '$str_bloco' "; | |
| 270 | - $whereAnd = " AND "; | |
| 271 | - } | |
| 272 | - | |
| 273 | - if( is_numeric( $int_apartamento) ) | |
| 274 | - { | |
| 275 | - $where .= "{$whereAnd}apartamento = '$int_apartamento' "; | |
| 276 | - $whereAnd = " AND "; | |
| 277 | - } | |
| 278 | - | |
| 279 | - if( is_numeric( $int_andar ) ) | |
| 280 | - { | |
| 281 | - $where .= "{$whereAnd}andar = '$int_andar' "; | |
| 282 | - $whereAnd = " AND "; | |
| 283 | - } | |
| 284 | - | |
| 285 | - if(is_string($str_letra)) | |
| 286 | - { | |
| 287 | - $where .= "{$whereAnd}letra = '$str_letra' "; | |
| 288 | - $whereAnd = " AND "; | |
| 289 | - } | |
| 290 | - | |
| 291 | - if(is_string($str_complemento)) | |
| 292 | - { | |
| 293 | - $where .= "{$whereAnd}complemento ILIKE '%$str_complemento%' "; | |
| 294 | - $whereAnd = " AND "; | |
| 295 | - } | |
| 296 | - | |
| 297 | - if( $inicio_limite !== false && $qtd_registros ) | |
| 298 | - { | |
| 299 | - $limite = "LIMIT $qtd_registros OFFSET $inicio_limite "; | |
| 300 | - } | |
| 301 | - | |
| 302 | - if( $str_orderBy ) | |
| 303 | - { | |
| 304 | - $orderBy .= " ORDER BY $str_orderBy "; | |
| 305 | - } | |
| 306 | - | |
| 307 | - $db = new clsBanco(); | |
| 308 | - $db->Consulta( "SELECT COUNT(0) AS total FROM $this->schema_cadastro.$this->tabela WHERE tipo=1 $where" ); | |
| 309 | - $db->ProximoRegistro(); | |
| 310 | - $total = $db->Campo( "total" ); | |
| 311 | - | |
| 312 | - $db = new clsBanco($this->banco); | |
| 313 | - //echo "SELECT idpes, tipo, cep, idlog, numero, letra, complemento, reside_desde, idbai, bloco, apartamento, andar FROM $this->schema_cadastro.$this->tabela WHERE tipo=1 $where $orderBy $limite"."<br>"; die(); | |
| 314 | - $db->Consulta("SELECT idpes, tipo, cep, idlog, numero, letra, complemento, reside_desde, idbai, bloco, apartamento, andar FROM $this->schema_cadastro.$this->tabela WHERE tipo=1 $where $orderBy $limite"); | |
| 315 | - $resultado = array(); | |
| 316 | - while ($db->ProximoRegistro()) | |
| 317 | - { | |
| 318 | - $tupla = $db->Tupla(); | |
| 319 | - $tupla['cep'] = new clsCepLogradouro($tupla['cep'],$tupla['idlog']); | |
| 320 | - $tupla['idlog'] = new clsCepLogradouro($tupla['cep'],$tupla['idlog']); | |
| 321 | - $tupla['idbai'] = new clsBairro($tupla['idbai']); | |
| 322 | - | |
| 323 | - $tupla["total"] = $total; | |
| 324 | - | |
| 325 | - $resultado[] = $tupla; | |
| 326 | - | |
| 327 | - } | |
| 328 | - if(count($resultado) > 0) | |
| 329 | - { | |
| 330 | - return $resultado; | |
| 331 | - } | |
| 332 | - return false; | |
| 333 | - } | |
| 334 | - | |
| 335 | - function detalhe() | |
| 336 | - { | |
| 337 | - if($this->idpes) | |
| 338 | - { | |
| 339 | - $db = new clsBanco($this->banco); | |
| 340 | - $db->Consulta("SELECT idpes, tipo, cep, idlog, numero, letra, complemento, reside_desde, idbai, bloco, apartamento, andar FROM $this->schema_cadastro.$this->tabela WHERE idpes = $this->idpes"); | |
| 341 | - | |
| 342 | - if($db->ProximoRegistro()) | |
| 343 | - { | |
| 344 | - $tupla = $db->Tupla(); | |
| 345 | - $cep = $tupla['cep']; | |
| 346 | - $tupla['cep'] = new clsCepLogradouro($cep,$tupla['idlog']); | |
| 347 | - $tupla['idlog'] = new clsCepLogradouro($cep,$tupla['idlog']); | |
| 348 | - $tupla['idbai'] = new clsBairro($tupla['idbai']); | |
| 349 | - return $tupla; | |
| 350 | - } | |
| 351 | - } | |
| 352 | - return false; | |
| 353 | - } | |
| 354 | - | |
| 355 | - /** | |
| 356 | - * Retorna um array com os dados de um registro | |
| 357 | - * | |
| 358 | - * @return array | |
| 359 | - */ | |
| 360 | - function existe() | |
| 361 | - { | |
| 362 | - if( is_numeric( $this->idpes ) ) | |
| 363 | - { | |
| 364 | - | |
| 365 | - $db = new clsBanco(); | |
| 366 | - $db->Consulta( "SELECT 1 FROM {$this->schema_cadastro}.{$this->tabela} WHERE IDPES = '{$this->idpes}'" ); | |
| 367 | - $db->ProximoRegistro(); | |
| 368 | - return $db->Tupla(); | |
| 369 | - } | |
| 370 | - return false; | |
| 371 | - } | |
| 372 | - | |
| 373 | - | |
| 374 | -} | |
| 375 | -?> | |
| 7 | + var $idpes; | |
| 8 | + var $idpes_cad; | |
| 9 | + var $idpes_rev; | |
| 10 | + var $tipo; | |
| 11 | + var $cep; | |
| 12 | + var $idlog; | |
| 13 | + var $idbai; | |
| 14 | + var $numero; | |
| 15 | + var $complemento; | |
| 16 | + var $reside_desde; | |
| 17 | + var $letra; | |
| 18 | + var $bloco; | |
| 19 | + var $apartamento; | |
| 20 | + var $andar; | |
| 21 | + | |
| 22 | + var $banco = 'gestao_homolog'; | |
| 23 | + var $schema_cadastro = 'cadastro'; | |
| 24 | + var $tabela = 'endereco_pessoa'; | |
| 25 | + | |
| 26 | + function clsPessoaEndereco($int_idpes = FALSE, $numeric_cep = FALSE, | |
| 27 | + $int_idlog = FALSE, $int_idbai = FALSE, $numeric_numero = FALSE, | |
| 28 | + $str_complemento = FALSE, $date_reside_desde = FALSE, $str1_letra = FALSE, | |
| 29 | + $str_bloco = FALSE, $int_apartamento = FALSE, $int_andar = FALSE, | |
| 30 | + $idpes_cad = FALSE, $idpes_rev = FALSE) | |
| 31 | + { | |
| 32 | + $this->idpes = $int_idpes; | |
| 33 | + $numeric_cep = idFederal2Int($numeric_cep); | |
| 34 | + | |
| 35 | + $obj = new clsCepLogradouroBairro($int_idlog, $numeric_cep, $int_idbai); | |
| 36 | + | |
| 37 | + if ($obj->detalhe()) { | |
| 38 | + $this->idbai = $int_idbai; | |
| 39 | + $this->idlog = $int_idlog; | |
| 40 | + $this->cep = $numeric_cep; | |
| 41 | + } | |
| 42 | + | |
| 43 | + $this->numero = $numeric_numero; | |
| 44 | + $this->complemento = $str_complemento; | |
| 45 | + $this->reside_desde = $date_reside_desde; | |
| 46 | + $this->letra = $str1_letra; | |
| 47 | + $this->bloco = $str_bloco; | |
| 48 | + $this->apartamento = $int_apartamento; | |
| 49 | + $this->andar = $int_andar; | |
| 50 | + $this->idpes_cad = $idpes_cad ? $idpes_cad : $_SESSION['id_pessoa']; | |
| 51 | + $this->idpes_rev = $idpes_rev ? $idpes_rev : $_SESSION['id_pessoa']; | |
| 52 | + } | |
| 53 | + | |
| 54 | + function cadastra() | |
| 55 | + { | |
| 56 | + if ($this->idpes && $this->cep && $this->idlog && $this->idbai && | |
| 57 | + $this->idpes_cad) { | |
| 58 | + | |
| 59 | + $campos = ''; | |
| 60 | + $valores = ''; | |
| 61 | + | |
| 62 | + if ($this->numero) { | |
| 63 | + $campos .= ', numero'; | |
| 64 | + $valores .= ", '$this->numero' "; | |
| 65 | + } | |
| 66 | + | |
| 67 | + if ($this->letra) { | |
| 68 | + $campos .= ', letra'; | |
| 69 | + $valores .= ", '$this->letra' "; | |
| 70 | + } | |
| 71 | + | |
| 72 | + if ($this->complemento) { | |
| 73 | + $campos .= ', complemento'; | |
| 74 | + $valores .= ", '$this->complemento' "; | |
| 75 | + } | |
| 76 | + | |
| 77 | + if ($this->reside_desde) { | |
| 78 | + $campos .= ', reside_desde'; | |
| 79 | + $valores .= ", '$this->reside_desde' "; | |
| 80 | + } | |
| 81 | + | |
| 82 | + if ($this->bloco) { | |
| 83 | + $campos .= ', bloco'; | |
| 84 | + $valores .= ", '$this->bloco' "; | |
| 85 | + } | |
| 86 | + | |
| 87 | + if ($this->apartamento) { | |
| 88 | + $campos .= ', apartamento'; | |
| 89 | + $valores .= ", '$this->apartamento' "; | |
| 90 | + } | |
| 91 | + | |
| 92 | + if ($this->andar) { | |
| 93 | + $campos .= ', andar'; | |
| 94 | + $valores .= ", '$this->andar' "; | |
| 95 | + } | |
| 96 | + | |
| 97 | + $sql = sprintf( | |
| 98 | + 'INSERT INTO %s.%s (idpes, tipo, cep, idlog, idbai, origem_gravacao, ' . | |
| 99 | + 'idsis_cad, data_cad, operacao, idpes_cad %s) VALUES (\'%d\', \'1\', ' . | |
| 100 | + '\'%s\', \'%s\', \'%d\', \'M\', 17, NOW(), \'I\', \'%d\' %s)', | |
| 101 | + $this->schema_cadastro, $this->tabela, $campos, $this->idpes, | |
| 102 | + $this->cep, $this->idlog, $this->idbai, $this->idpes_cad, $valores | |
| 103 | + ); | |
| 104 | + | |
| 105 | + $db = new clsBanco(); | |
| 106 | + $db->Consulta($sql); | |
| 107 | + | |
| 108 | + return TRUE; | |
| 109 | + } | |
| 110 | + | |
| 111 | + return FALSE; | |
| 112 | + } | |
| 113 | + | |
| 114 | + function edita() | |
| 115 | + { | |
| 116 | + if ($this->idpes && $this->idpes_rev) { | |
| 117 | + $setVir = ' SET '; | |
| 118 | + $set = ''; | |
| 119 | + | |
| 120 | + if ($this->numero) { | |
| 121 | + $set .= "$setVir numero = '$this->numero' "; | |
| 122 | + $setVir = ', '; | |
| 123 | + } | |
| 124 | + else { | |
| 125 | + $set .= "$setVir numero = NULL "; | |
| 126 | + $setVir = ', '; | |
| 127 | + } | |
| 128 | + | |
| 129 | + if ($this->letra) { | |
| 130 | + $set .= "$setVir letra = '$this->letra' "; | |
| 131 | + $setVir = ', '; | |
| 132 | + } | |
| 133 | + else { | |
| 134 | + $set .= "$setVir letra = NULL "; | |
| 135 | + $setVir = ', '; | |
| 136 | + } | |
| 137 | + | |
| 138 | + if ($this->complemento) { | |
| 139 | + $set .= "$setVir complemento = '$this->complemento' "; | |
| 140 | + $setVir = ', '; | |
| 141 | + } | |
| 142 | + else { | |
| 143 | + $set .= "$setVir complemento = NULL "; | |
| 144 | + $setVir = ', '; | |
| 145 | + } | |
| 146 | + | |
| 147 | + if ($this->reside_desde) { | |
| 148 | + $set .= "$setVir reside_desde = '$this->reside_desde' "; | |
| 149 | + $setVir = ', '; | |
| 150 | + } | |
| 151 | + else { | |
| 152 | + $set .= "$setVir reside_desde = NULL "; | |
| 153 | + $setVir = ', '; | |
| 154 | + } | |
| 155 | + | |
| 156 | + if ($this->bloco) { | |
| 157 | + $set .= "$setVir bloco = '$this->bloco' "; | |
| 158 | + $setVir = ', '; | |
| 159 | + } | |
| 160 | + else { | |
| 161 | + $set .= "$setVir bloco = NULL "; | |
| 162 | + $setVir = ', '; | |
| 163 | + } | |
| 164 | + | |
| 165 | + if ($this->apartamento) { | |
| 166 | + $set .= "$setVir apartamento = '$this->apartamento' "; | |
| 167 | + $setVir = ', '; | |
| 168 | + } | |
| 169 | + else { | |
| 170 | + $set .= "$setVir apartamento = NULL "; | |
| 171 | + $setVir = ', '; | |
| 172 | + } | |
| 173 | + | |
| 174 | + if ($this->andar) { | |
| 175 | + $set .= "$setVir andar = '$this->andar' "; | |
| 176 | + $setVir = ', '; | |
| 177 | + } | |
| 178 | + else { | |
| 179 | + $set .= "$setVir andar = NULL "; | |
| 180 | + $setVir = ', '; | |
| 181 | + } | |
| 182 | + | |
| 183 | + if ($this->cep && $this->idbai && $this->idlog) { | |
| 184 | + $set .= "$setVir cep = '$this->cep', idbai = '$this->idbai', idlog = '$this->idlog'"; | |
| 185 | + $setVir = ', '; | |
| 186 | + } | |
| 187 | + | |
| 188 | + if ($this->idpes_rev) { | |
| 189 | + $set .= "$setVir idpes_rev ='$this->idpes_rev'"; | |
| 190 | + } | |
| 191 | + | |
| 192 | + if ($set) { | |
| 193 | + $db = new clsBanco(); | |
| 194 | + $db->Consulta("UPDATE {$this->schema_cadastro}.{$this->tabela} $set WHERE idpes = $this->idpes"); | |
| 195 | + return TRUE; | |
| 196 | + } | |
| 197 | + } | |
| 198 | + | |
| 199 | + return FALSE; | |
| 200 | + } | |
| 201 | + | |
| 202 | + function exclui() | |
| 203 | + { | |
| 204 | + if ($this->idpes) { | |
| 205 | + $db = new clsBanco(); | |
| 206 | + $db->Consulta(sprintf( | |
| 207 | + 'DELETE FROM $this->schema_cadastro.$this->tabela WHERE idpes = %d', | |
| 208 | + $this->idpes | |
| 209 | + )); | |
| 210 | + } | |
| 211 | + } | |
| 212 | + | |
| 213 | + function lista($int_idpes = FALSE, $str_ordenacao = FALSE, | |
| 214 | + $int_inicio_limite = FALSE, $int_qtd_limite = FALSE, $int_cep = FALSE, | |
| 215 | + $int_idlog = FALSE, $int_idbai = FALSE, $int_numero = FALSE, | |
| 216 | + $str_bloco = FALSE, $int_apartamento = FALSE, $int_andar = FALSE, | |
| 217 | + $str_letra = FALSE, $str_complemento = FALSE) | |
| 218 | + { | |
| 219 | + $whereAnd = ' AND '; | |
| 220 | + $where = ''; | |
| 221 | + | |
| 222 | + if (is_numeric($int_idpes)) { | |
| 223 | + $where .= "{$whereAnd}idpes = '$int_idpes' "; | |
| 224 | + $whereAnd = ' AND '; | |
| 225 | + } | |
| 226 | + elseif (is_string($int_idpes)) | |
| 227 | + { | |
| 228 | + $where .= "{$whereAnd}idpes IN ({$int_idpes}) "; | |
| 229 | + $whereAnd = ' AND '; | |
| 230 | + } | |
| 231 | + | |
| 232 | + if (is_numeric($int_cep)) { | |
| 233 | + $where .= "{$whereAnd}cep = '$int_cep' "; | |
| 234 | + $whereAnd = ' AND '; | |
| 235 | + } | |
| 236 | + | |
| 237 | + if (is_numeric($int_idlog)) { | |
| 238 | + $where .= "{$whereAnd}idlog = '$int_idlog' "; | |
| 239 | + $whereAnd = ' AND '; | |
| 240 | + } | |
| 241 | + | |
| 242 | + if (is_numeric($int_idbai)) { | |
| 243 | + $where .= "{$whereAnd}idbai = '$int_idbai' "; | |
| 244 | + $whereAnd = ' AND '; | |
| 245 | + } | |
| 246 | + | |
| 247 | + if (is_numeric($int_numero)) { | |
| 248 | + $where .= "{$whereAnd}numero = '$int_numero' "; | |
| 249 | + $whereAnd = ' AND '; | |
| 250 | + } | |
| 251 | + | |
| 252 | + if ($str_bloco) { | |
| 253 | + $where .= "{$whereAnd}bloco = '$str_bloco' "; | |
| 254 | + $whereAnd = ' AND '; | |
| 255 | + } | |
| 256 | + | |
| 257 | + if (is_numeric($int_apartamento)) { | |
| 258 | + $where .= "{$whereAnd}apartamento = '$int_apartamento' "; | |
| 259 | + $whereAnd = ' AND '; | |
| 260 | + } | |
| 261 | + | |
| 262 | + if (is_numeric($int_andar)) { | |
| 263 | + $where .= "{$whereAnd}andar = '$int_andar' "; | |
| 264 | + $whereAnd = ' AND '; | |
| 265 | + } | |
| 266 | + | |
| 267 | + if (is_string($str_letra)) { | |
| 268 | + $where .= "{$whereAnd}letra = '$str_letra' "; | |
| 269 | + $whereAnd = ' AND '; | |
| 270 | + } | |
| 271 | + | |
| 272 | + if (is_string($str_complemento)) { | |
| 273 | + $where .= "{$whereAnd}complemento ILIKE '%$str_complemento%' "; | |
| 274 | + $whereAnd = ' AND '; | |
| 275 | + } | |
| 276 | + | |
| 277 | + if ($inicio_limite !== FALSE && $qtd_registros) { | |
| 278 | + $limite = "LIMIT $qtd_registros OFFSET $inicio_limite "; | |
| 279 | + } | |
| 280 | + | |
| 281 | + if ($str_orderBy) { | |
| 282 | + $orderBy .= " ORDER BY $str_orderBy "; | |
| 283 | + } | |
| 284 | + | |
| 285 | + $db = new clsBanco(); | |
| 286 | + | |
| 287 | + $sql = sprintf( | |
| 288 | + 'SELECT COUNT(0) AS total FROM %s.%s WHERE tipo = 1 %s', | |
| 289 | + $this->schema_cadastro, $this->tabela, $where | |
| 290 | + ); | |
| 291 | + | |
| 292 | + $db->Consulta($sql); | |
| 293 | + $db->ProximoRegistro(); | |
| 294 | + $total = $db->Campo('total'); | |
| 295 | + | |
| 296 | + $db = new clsBanco($this->banco); | |
| 297 | + | |
| 298 | + $sql = sprintf( | |
| 299 | + 'SELECT idpes, tipo, cep, idlog, numero, letra, complemento, reside_desde, ' . | |
| 300 | + 'idbai, bloco, apartamento, andar FROM %s.%s WHERE tipo = 1 %s %s %s', | |
| 301 | + $this->schema_cadastro, $this->tabela, $where, $orderBy, $limite | |
| 302 | + ); | |
| 303 | + | |
| 304 | + $db->Consulta($sql); | |
| 305 | + $resultado = array(); | |
| 306 | + | |
| 307 | + while ($db->ProximoRegistro()) { | |
| 308 | + $tupla = $db->Tupla(); | |
| 309 | + $tupla['cep'] = new clsCepLogradouro($tupla['cep'], $tupla['idlog']); | |
| 310 | + $tupla['idlog'] = new clsCepLogradouro($tupla['cep'], $tupla['idlog']); | |
| 311 | + $tupla['idbai'] = new clsBairro($tupla['idbai']); | |
| 312 | + | |
| 313 | + $tupla['total'] = $total; | |
| 314 | + | |
| 315 | + $resultado[] = $tupla; | |
| 316 | + } | |
| 317 | + | |
| 318 | + if (count($resultado) > 0) { | |
| 319 | + return $resultado; | |
| 320 | + } | |
| 321 | + | |
| 322 | + return FALSE; | |
| 323 | + } | |
| 324 | + | |
| 325 | + function detalhe() | |
| 326 | + { | |
| 327 | + if ($this->idpes) { | |
| 328 | + $db = new clsBanco($this->banco); | |
| 329 | + | |
| 330 | + $sql = sprintf( | |
| 331 | + 'SELECT idpes, tipo, cep, idlog, numero, letra, complemento, ' . | |
| 332 | + 'reside_desde, idbai, bloco, apartamento, andar ' . | |
| 333 | + 'FROM %s.%s WHERE idpes = %d', | |
| 334 | + $this->schema_cadastro, $this->tabela, $this->idpes | |
| 335 | + ); | |
| 336 | + | |
| 337 | + $db->Consulta($sql); | |
| 338 | + | |
| 339 | + if ($db->ProximoRegistro()) { | |
| 340 | + $tupla = $db->Tupla(); | |
| 341 | + | |
| 342 | + $cep = $tupla['cep']; | |
| 343 | + | |
| 344 | + $tupla['cep'] = new clsCepLogradouro($cep, $tupla['idlog']); | |
| 345 | + $tupla['idlog'] = new clsCepLogradouro($cep, $tupla['idlog']); | |
| 346 | + $tupla['idbai'] = new clsBairro($tupla['idbai']); | |
| 347 | + | |
| 348 | + return $tupla; | |
| 349 | + } | |
| 350 | + } | |
| 351 | + | |
| 352 | + return FALSE; | |
| 353 | + } | |
| 354 | + | |
| 355 | + /** | |
| 356 | + * Retorna um array com os dados de um registro. | |
| 357 | + * @return array | |
| 358 | + */ | |
| 359 | + function existe() | |
| 360 | + { | |
| 361 | + if (is_numeric($this->idpes)) { | |
| 362 | + $db = new clsBanco(); | |
| 363 | + | |
| 364 | + $sql = sprintf( | |
| 365 | + 'SELECT 1 FROM %s.%s WHERE idpes = %d', | |
| 366 | + $this->schema_cadastro, $this->tabela, $this->idpes | |
| 367 | + ); | |
| 368 | + | |
| 369 | + $db->Consulta($sql); | |
| 370 | + $db->ProximoRegistro(); | |
| 371 | + return $db->Tupla(); | |
| 372 | + } | |
| 373 | + | |
| 374 | + return FALSE; | |
| 375 | + } | |
| 376 | +} | |
| 376 | 377 | \ No newline at end of file | ... | ... |