clsPessoa_.inc.php
10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @author Prefeitura Municipal de Itaja� *
* @updated 29/03/2007 *
* Pacote: i-PLB Software P�blico Livre e Brasileiro *
* *
* Copyright (C) 2006 PMI - Prefeitura Municipal de Itaja� *
* ctima@itajai.sc.gov.br *
* *
* Este programa � software livre, voc� pode redistribu�-lo e/ou *
* modific�-lo sob os termos da Licen�a P�blica Geral GNU, conforme *
* publicada pela Free Software Foundation, tanto a vers�o 2 da *
* Licen�a como (a seu crit�rio) qualquer vers�o mais nova. *
* *
* Este programa � distribu�do na expectativa de ser �til, mas SEM *
* QUALQUER GARANTIA. Sem mesmo a garantia impl�cita de COMERCIALI- *
* ZA��O ou de ADEQUA��O A QUALQUER PROP�SITO EM PARTICULAR. Con- *
* sulte a Licen�a P�blica Geral GNU para obter mais detalhes. *
* *
* Voc� deve ter recebido uma c�pia da Licen�a P�blica Geral GNU *
* junto com este programa. Se n�o, escreva para a Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *
* 02111-1307, USA. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
require_once ("include/clsBanco.inc.php");
class clsPessoa_
{
var $idpes;
var $nome;
var $idpes_cad;
var $data_cad;
var $url;
var $tipo;
var $idpes_rev;
var $data_rev;
var $situacao;
var $origem_gravacao;
var $email;
var $banco = 'gestao_homolog';
var $schema_cadastro = "cadastro";
var $tabela_pessoa = "pessoa";
var $tabela_endereco = "endereco_pessoa";
var $tabela_telefone = "fone_pessoa";
function clsPessoa_($int_idpes = false, $str_nome = false, $int_idpes_cad =false, $str_url = false, $int_tipo = false, $int_idpes_rev =false, $str_data_rev = false, $str_email = false )
{
$this->idpes = $int_idpes;
$this->nome = $str_nome;
$this->idpes_cad = $int_idpes_cad ? $int_idpes_cad : $_SESSION['id_pessoa'];
$this->url = $str_url;
$this->tipo = $int_tipo;
$this->idpes_rev = is_numeric($int_idpes_rev) ? $int_idpes_rev : $_SESSION['id_pessoa'];
$this->data_rev = $str_data_rev;
$this->email = $str_email;
}
function cadastra()
{
if($this->nome && $this->tipo)
{
$campos = "";
$valores = "";
if($this->url)
{
$campos .= ", url";
$valores .= ", '$this->url' ";
}
if($this->email)
{
$campos .= ", email";
$valores .= ", '$this->email' ";
}
if($this->idpes_cad)
{
$campos .= ", idpes_cad";
$valores .= ", '$this->idpes_cad' ";
}
$db = new clsBanco();
$db->Consulta("INSERT INTO {$this->schema_cadastro}.{$this->tabela_pessoa} (nome, data_cad,tipo,situacao,origem_gravacao, idsis_cad, operacao $campos) VALUES ('$this->nome', NOW(), '$this->tipo', 'P', 'U', 17, 'I' $valores)");
$this->idpes = $db->InsertId("{$this->schema_cadastro}.seq_pessoa");
return $this->idpes;
}
}
function edita()
{
//Cadastro de dados na tabela de pessoa
if($this->idpes)
{
$set = "";
$gruda = "";
if($this->url || $this->url==="")
{
$set .= " url = '$this->url' ";
$gruda = ", ";
}
if($this->email || $this->email==="")
{
$set .= "$gruda email = '$this->email' ";
$gruda = ", ";
}
if($this->nome || $this->nome==="")
{
$set .= "$gruda nome = '$this->nome' ";
$gruda = ", ";
}
if($this->idpes_rev)
{
$set .= "$gruda idpes_rev = '$this->idpes_rev'";
}
if($set)
{
$db = new clsBanco();
$db->Consulta("UPDATE {$this->schema_cadastro}.{$this->tabela_pessoa} SET $set, data_rev = 'NOW()' WHERE idpes = $this->idpes");
return true;
}
}
}
function exclui()
{
if($this->idpes)
{
$db = new clsBanco();
$db->Consulta("DELETE FROM $this->schema_cadastro.$this->tabela_pessoa WHERE idpes = $this->idpes");
return true;
}
return false;
}
function lista($str_nome = false, $inicio_limite = false, $qtd_registros = false, $str_orderBy = false, $arrayint_idisin=false, $arrayint_idnotin = false, $str_tipo_pessoa = false, $str_email = false, $str_data_cad_ini = false, $str_data_cad_fim = false )
{
$whereAnd = "WHERE ";
$where = "";
if( is_string( $str_nome ) )
{
$str_nome = str_replace(" ", "%", $str_nome);
$where .= "{$whereAnd} nome ILIKE '%{$str_nome}%' ";
$whereAnd = " AND ";
}
if( is_string( $str_tipo_pessoa ) )
{
$where .= "{$whereAnd}tipo = '$str_tipo_pessoa' ";
$whereAnd = " AND ";
}
if( is_array( $arrayint_idisin ) )
{
$ok = true;
foreach ( $arrayint_idisin AS $val )
{
if( ! is_numeric( $val ) )
{
$ok = false;
}
}
if( $ok )
{
$where .= "{$whereAnd}idpes IN ( " . implode( ",", $arrayint_idisin ) . " )";
$whereAnd = " AND ";
}
}
if( is_array( $arrayint_idnotin ) )
{
$ok = true;
foreach ( $arrayint_idnotin AS $val )
{
if( ! is_numeric( $val ) )
{
$ok = false;
}
}
if( $ok )
{
$where .= "{$whereAnd}idpes NOT IN ( " . implode( ",", $arrayint_idnotin ) . " )";
$whereAnd = " AND ";
}
}
if( $inicio_limite !== false && $qtd_registros )
{
$limite = "LIMIT $qtd_registros OFFSET $inicio_limite ";
}
if(is_string($str_data_cad_ini))
{
if(!$str_data_edicao_fim)
{
$where .= "{$whereAnd}data_cad >= '$str_data_cad_ini 00:00:00' AND data_cad <= '$str_data_cad_ini 23:59:59'";
$whereAnd = " AND ";
}
else
{
$where .= "{$whereAnd}data_cad >= '$str_data_cad_ini'";
$whereAnd = " AND ";
}
}
if(is_string($str_data_cad_fim))
{
$where .= "{$whereAnd}data_cad <= '$str_data_cad_fim'";
$whereAnd = " AND ";
}
$orderBy = " ORDER BY ";
if( $str_orderBy )
{
$orderBy .= "$str_orderBy ";
}
else
{
$orderBy .= "nome ";
}
if( is_string( $str_email) )
{
$where .= "{$whereAnd}email ILIKE '%$str_email%' ";
$whereAnd = " AND ";
}
$db = new clsBanco($this->banco);
$total = $db->UnicoCampo("SELECT count(0) FROM cadastro.pessoa $where");
//echo "SELECT idpes, nome, idpes_cad, data_cad, url, tipo, idpes_rev, data_rev, situacao, origem_gravacao, email FROM cadastro.pessoa $where $orderBy $limite";
$db->Consulta("SELECT idpes, nome, idpes_cad, data_cad, url, tipo, idpes_rev, data_rev, situacao, origem_gravacao, email FROM cadastro.pessoa $where $orderBy $limite");
/*
Ordem de retorno da lista:
1 2 3 4 5 6 7 8 9 10
idpes, nome, idpes_cad, data_cad, url, tipo, data_rev, situacao, origem_grav, email
*/
$resultado = array();
while ($db->ProximoRegistro())
{
$tupla = $db->Tupla();
$nome = strtolower($tupla['nome']);
$arrayNome = explode(" ", $nome);
$nome ="";
foreach ($arrayNome as $parte) {
if( $parte != "de" && $parte != "da" && $parte != "dos" && $parte != "do" && $parte != "das" && $parte != "e")
{
$nome .= strtoupper(substr($parte,0,1)).substr($parte,1)." ";
}
else
{
$nome .= $parte." ";
}
}
$nome = str_replace( array( "�","�","�","�", "�", "�", "�", "�", "�", "�"),
array( "�","�","�","�", "�", "�", "�", "�", "�", "�"), $nome );
$tupla['nome'] = $nome;
$tupla['total']= $total;
$resultado[] = $tupla;
}
if(count($resultado) > 0)
{
return $resultado;
}
return false;
}
function listaCod($str_nome = false, $inicio_limite = false, $qtd_registros = false, $str_orderBy = false, $arrayint_idisin=false, $arrayint_idnotin = false, $str_tipo_pessoa = false )
{
$whereAnd = "WHERE ";
$where = "";
if( is_string( $str_nome ) )
{
$where .= "{$whereAnd} fcn_upper_nrm(nome) ILIKE fcn_upper_nrm('%{$str_nome}%') ";
$whereAnd = " AND ";
}
if( is_string( $str_tipo_pessoa ) )
{
$where .= "{$whereAnd}tipo = '$str_tipo_pessoa' ";
$whereAnd = " AND ";
}
if( is_array( $arrayint_idisin ) )
{
$ok = true;
foreach ( $arrayint_idisin AS $val )
{
if( ! is_numeric( $val ) )
{
$ok = false;
}
}
if( $ok )
{
$where .= "{$whereAnd}idpes IN ( " . implode( ",", $arrayint_idisin ) . " )";
$whereAnd = " AND ";
}
}
if( is_array( $arrayint_idnotin ) )
{
$ok = true;
foreach ( $arrayint_idnotin AS $val )
{
if( ! is_numeric( $val ) )
{
$ok = false;
}
}
if( $ok )
{
$where .= "{$whereAnd}idpes NOT IN ( " . implode( ",", $arrayint_idnotin ) . " )";
$whereAnd = " AND ";
}
}
if( $inicio_limite !== false && $qtd_registros )
{
$limite = "LIMIT $qtd_registros OFFSET $inicio_limite ";
}
$orderBy = " ORDER BY ";
if( $str_orderBy )
{
$orderBy .= "$str_orderBy ";
}
else
{
$orderBy .= "nome ";
}
$db = new clsBanco($this->banco);
$db->Consulta("SELECT idpes FROM cadastro.pessoa $where $orderBy $limite");
$resultado = array();
while ($db->ProximoRegistro())
{
$tupla = $db->Tupla();
$resultado[] = $tupla['idpes'];
}
if(count($resultado) > 0)
{
return $resultado;
}
return false;
}
function detalhe()
{
if( is_numeric( $this->idpes ) )
{
$db = new clsBanco($this->banco);
$db->Consulta("SELECT idpes, nome, idpes_cad, data_cad, url, tipo, idpes_rev, data_rev, situacao, origem_gravacao, email FROM cadastro.pessoa WHERE idpes = $this->idpes ");
if($db->ProximoRegistro())
{
$tupla = $db->Tupla();
$nome = strtolower($tupla['nome']);
$arrayNome = explode(" ", $nome);
$arrNovoNome = array();
foreach ($arrayNome as $parte) {
if( $parte != "de" && $parte != "da" && $parte != "dos" && $parte != "do" && $parte != "das" && $parte != "e")
{
if( $parte != "s.a" && $parte != "ltda" )
{
$arrNovoNome[] = strtoupper(substr($parte,0,1)).substr($parte,1);
}
else
{
$arrNovoNome[] = strtoupper( $parte );
}
}
else
{
$arrNovoNome[] = $parte;
}
}
$nome = implode( " ", $arrNovoNome );
//$nome = str_replace( array( "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "?", "�", "�", "�", "�", "�", "�", "�", "�", "�", "?", "�", "�", "?", "?", "?", "�", "�" ),
// array( "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "?", "�", "�", "�", "�", "�", "�", "�", "�", "�", "?", "�", "�", "?", "?", "y", "�", "�"), $nome );
$tupla['nome'] = $nome;
list($this->idpes, $this->nome, $this->idpes_cad, $this->data_cad, $this->url, $this->tipo, $this->idpes_rev, $this->data_rev, $this->situacao, $this->origem_gravacao, $this->email ) = $tupla;
return $tupla;
}
}
return false;
}
}
?>