clsPessoaTelefone.inc.php
6.37 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
<?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 clsPessoaTelefone
{
var $idpes;
var $ddd;
var $fone;
var $tipo;
var $idpes_cad;
var $idpes_rev;
var $banco = 'gestao_homolog';
var $schema_cadastro = "cadastro";
var $tabela_telefone = "fone_pessoa";
function clsPessoaTelefone($int_idpes = false, $int_tipo = false, $str_fone=false, $str_ddd=false, $idpes_cad = false, $idpes_rev = false)
{
$this->idpes = $int_idpes;
$this->ddd = $str_ddd;
$this->fone = $str_fone;
$this->tipo = $int_tipo;
$this->idpes_cad = $idpes_cad ? $idpes_cad : $_SESSION['id_pessoa'];
$this->idpes_rev = $idpes_rev ? $idpes_rev : $_SESSION['id_pessoa'];
}
function cadastra()
{
// Cadastro do telefone da pessoa na tabela fone_pessoa
if($this->idpes && $this->tipo && $this->idpes_cad )
{
$db = new clsBanco();
$db->Consulta( "SELECT 1 FROM {$this->schema_cadastro}.{$this->tabela_telefone} WHERE idpes = '$this->idpes' AND tipo = '$this->tipo'" );
// Verifica se ja existe um telefone desse tipo cadastrado para essa pessoa
if( ! $db->Num_Linhas() )
{
// nao tem, cadastra 1 novo
if( $this->ddd && $this->fone )
{
$db->Consulta("INSERT INTO {$this->schema_cadastro}.{$this->tabela_telefone} (idpes, tipo, ddd, fone,origem_gravacao, idsis_cad, data_cad, operacao, idpes_cad) VALUES ('$this->idpes', '$this->tipo', '$this->ddd', '$this->fone','M', 17, NOW(), 'I', '$this->idpes_cad')");
return true;
}
}
else
{
// jah tem, edita
$this->edita();
return true;
}
}
return false;
}
function edita()
{
// Cadastro do telefone da pessoa na tabela fone_pessoa
if($this->idpes && $this->tipo && $this->idpes_rev)
{
$set = false;
$gruda = "";
if($this->ddd)
{
$set = "ddd = '$this->ddd'";
$gruda = ", ";
}
if($this->fone)
{
$set .= "$gruda fone = '$this->fone'";
$gruda = ", ";
}
if($this->idpes_rev)
{
$set .= "$gruda idpes_rev = '$this->idpes_rev'";
$gruda = ", ";
}
if($set && $this->ddd != "" && $this->fone != "" )
{
$db = new clsBanco();
$db->Consulta("UPDATE {$this->schema_cadastro}.{$this->tabela_telefone} SET $set WHERE idpes = $this->idpes AND tipo = $this->tipo");
return true;
}
else
{
if( $this->ddd == "" && $this->fone == "" )
{
$this->exclui();
}
}
}
return false;
}
function exclui()
{
if($this->idpes)
{
$db = new clsBanco();
$db->Consulta("DELETE FROM $this->schema_cadastro.$this->tabela_telefone WHERE idpes = $this->idpes AND tipo = $this->tipo");
return true;
}
return false;
}
function excluiTodos()
{
// exclui todos os telefones da pessoa, nao importa o tipo
if($this->idpes)
{
$db = new clsBanco();
$db->Consulta("DELETE FROM $this->schema_cadastro.$this->tabela_telefone WHERE idpes = $this->idpes");
return true;
}
return false;
}
function lista($int_idpes = false, $str_ordenacao = false, $int_inicio_limite = false, $int_qtd_registros = false, $int_ddd = false, $int_fone = false )
{
$whereAnd = "WHERE ";
$where = "";
if( is_numeric($int_idpes))
{
$where .= "{$whereAnd}idpes = '$int_idpes'";
$whereAnd = " AND ";
}
elseif (is_string($int_idpes))
{
$where .= "{$whereAnd}idpes IN ($int_idpes)";
$whereAnd = " AND ";
}
if( is_string( $str_tipo_pessoa ) )
{
$where .= "{$whereAnd}tipo = '$str_tipo_pessoa' ";
$whereAnd = " AND ";
}
if(is_numeric($int_ddd))
{
$where .= "{$whereAnd}ddd = '$int_ddd' ";
$whereAnd = " AND ";
}
if(is_numeric($int_fone))
{
$where .= "{$whereAnd}fone = '$int_fone' ";
$whereAnd = " AND ";
}
if( $int_inicio_limite !== false && $int_qtd_registros)
{
$limite = "LIMIT $int_qtd_registros OFFSET $int_inicio_limite ";
}
if( $str_orderBy )
{
$orderBy = " ORDERY BY $str_orderBy ";
}
$db = new clsBanco();
$db->Consulta( "SELECT COUNT(0) AS total FROM $this->schema_cadastro.$this->tabela_telefone $where" );
$db->ProximoRegistro();
$total = $db->Campo( "total" );
$db = new clsBanco($this->banco);
$db = new clsBanco();
$db->Consulta("SELECT idpes, tipo, ddd, fone FROM $this->schema_cadastro.$this->tabela_telefone $where $orderBy $limite");
$resultado = array();
while ($db->ProximoRegistro())
{
$tupla = $db->Tupla();
$tupla["total"] = $total;
$resultado[] = $tupla;
}
if(count($resultado) > 0)
{
return $resultado;
}
return false;
}
function detalhe()
{
if($this->idpes && $this->tipo)
{
$db = new clsBanco();
$db->Consulta("SELECT tipo, ddd, fone FROM cadastro.fone_pessoa WHERE idpes = $this->idpes AND tipo = '$this->tipo' " );
if($db->ProximoRegistro())
{
$tupla = $db->Tupla();
return $tupla;
}
}
elseif($this->idpes && !$this->tipo)
{
$db = new clsBanco();
$db->Consulta("SELECT tipo, ddd, fone FROM cadastro.fone_pessoa WHERE idpes = $this->idpes " );
if($db->ProximoRegistro())
{
$tupla = $db->Tupla();
return $tupla;
}
}
return false;
}
}
?>