Commit 88918c3c2a7af267278bf0632baa36db5bb64876

Authored by Eriksen Costa Paixão
1 parent 80d95c0c
Exists in master

#18 by Eriksen: Corrigido bug que duplicava o cadastro do cliente de biblioteca …

…quando era para atualizá-lo.


ieducar/intranet/educar_cliente_cad.php
1 <?php 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 /** 2 /**
28 - * @author Adriano Erik Weiguert Nagasava 3 + *
  4 + * @author Prefeitura Municipal de Itajaí
  5 + * @version SVN: $Id$
  6 + *
  7 + * Pacote: i-PLB Software Público Livre e Brasileiro
  8 + *
  9 + * Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí
  10 + * ctima@itajai.sc.gov.br
  11 + *
  12 + * Este programa é software livre, você pode redistribuí-lo e/ou
  13 + * modificá-lo sob os termos da Licença Pública Geral GNU, conforme
  14 + * publicada pela Free Software Foundation, tanto a versão 2 da
  15 + * Licença como (a seu critério) qualquer versão mais nova.
  16 + *
  17 + * Este programa é distribuído na expectativa de ser útil, mas SEM
  18 + * QUALQUER GARANTIA. Sem mesmo a garantia implícita de COMERCIALI-
  19 + * ZAÇÃO ou de ADEQUAÇÃO A QUALQUER PROPÓSITO EM PARTICULAR. Con-
  20 + * sulte a Licença Pública Geral GNU para obter mais detalhes.
  21 + *
  22 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU
  23 + * junto com este programa. Se não, escreva para a Free Software
  24 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  25 + * 02111-1307, USA.
  26 + *
29 */ 27 */
30 -require_once ("include/clsBase.inc.php");  
31 -require_once ("include/clsCadastro.inc.php");  
32 -require_once ("include/clsBanco.inc.php");  
33 -require_once( "include/pmieducar/geral.inc.php" ); 28 +
  29 +require_once 'include/clsBase.inc.php';
  30 +require_once 'include/clsCadastro.inc.php';
  31 +require_once 'include/clsBanco.inc.php';
  32 +require_once 'include/pmieducar/geral.inc.php';
34 33
35 class clsIndexBase extends clsBase 34 class clsIndexBase extends clsBase
36 { 35 {
@@ -66,9 +65,9 @@ class indice extends clsCadastro @@ -66,9 +65,9 @@ class indice extends clsCadastro
66 var $ativo; 65 var $ativo;
67 var $del_cod_cliente; 66 var $del_cod_cliente;
68 var $del_cod_cliente_tipo; 67 var $del_cod_cliente_tipo;
69 -  
70 68
71 - function Inicializar() 69 +
  70 + function Inicializar()
72 { 71 {
73 $retorno = "Novo"; 72 $retorno = "Novo";
74 @session_start(); 73 @session_start();
@@ -93,7 +92,7 @@ class indice extends clsCadastro @@ -93,7 +92,7 @@ class indice extends clsCadastro
93 92
94 $this->login_ = $this->login; 93 $this->login_ = $this->login;
95 $this->senha_ = $this->senha; 94 $this->senha_ = $this->senha;
96 - 95 +
97 $obj_permissoes = new clsPermissoes(); 96 $obj_permissoes = new clsPermissoes();
98 if( $obj_permissoes->permissao_excluir( 603, $this->pessoa_logada, 11 ) ) 97 if( $obj_permissoes->permissao_excluir( 603, $this->pessoa_logada, 11 ) )
99 { 98 {
@@ -105,7 +104,8 @@ class indice extends clsCadastro @@ -105,7 +104,8 @@ class indice extends clsCadastro
105 } 104 }
106 $this->url_cancelar = ($retorno == "Editar") ? "educar_cliente_det.php?cod_cliente={$registro["cod_cliente"]}&ref_cod_biblioteca={$this->ref_cod_biblioteca}" : "educar_cliente_lst.php"; 105 $this->url_cancelar = ($retorno == "Editar") ? "educar_cliente_det.php?cod_cliente={$registro["cod_cliente"]}&ref_cod_biblioteca={$this->ref_cod_biblioteca}" : "educar_cliente_lst.php";
107 $this->nome_url_cancelar = "Cancelar"; 106 $this->nome_url_cancelar = "Cancelar";
108 - return $retorno; 107 +
  108 + return $retorno;
109 } 109 }
110 110
111 function Gerar() 111 function Gerar()
@@ -120,22 +120,24 @@ class indice extends clsCadastro @@ -120,22 +120,24 @@ class indice extends clsCadastro
120 $detalhe = $objTemp->detalhe(); 120 $detalhe = $objTemp->detalhe();
121 $opcoes["{$detalhe["idpes"]}"] = $detalhe["nome"]; 121 $opcoes["{$detalhe["idpes"]}"] = $detalhe["nome"];
122 } 122 }
123 - if ( !$this->cod_cliente ) {  
124 - $parametros = new clsParametrosPesquisas();  
125 - $parametros->setSubmit( 0 );  
126 - $parametros->adicionaCampoSelect( "ref_idpes", "idpes", "nome" );  
127 - $parametros->setPessoa( 'F' );  
128 - $parametros->setPessoaCPF( 'N' );  
129 - $parametros->setCodSistema( 1 );  
130 - $parametros->setPessoaNovo( 'S' );  
131 - $parametros->setPessoaTela( 'frame' );  
132 -  
133 - $this->campoListaPesq( "ref_idpes", "Cliente", $opcoes, $this->ref_idpes, "pesquisa_pessoa_lst.php", "", false, "", "", null, null, "", false, $parametros->serializaCampos() );  
134 - }  
135 - else {  
136 - $this->campoOculto( "ref_idpes", $this->ref_idpes );  
137 - $this->campoRotulo( "nm_cliente", "Cliente", $detalhe["nome"] ); 123 +
  124 + // Caso o cliente não exista, exibe um campo de pesquisa, senão, mostra um rótulo
  125 + if (!$this->cod_cliente) {
  126 + $parametros = new clsParametrosPesquisas();
  127 + $parametros->setSubmit(0);
  128 + $parametros->adicionaCampoSelect('ref_idpes', 'idpes', 'nome');
  129 + $parametros->setPessoa('F');
  130 + $parametros->setPessoaCPF('N');
  131 + $parametros->setCodSistema(1);
  132 + $parametros->setPessoaNovo('S');
  133 + $parametros->setPessoaTela('frame');
  134 +
  135 + $this->campoListaPesq('ref_idpes', 'Cliente', $opcoes, $this->ref_idpes, 'pesquisa_pessoa_lst.php', '', FALSE, '', '', NULL, NULL, '', FALSE, $parametros->serializaCampos());
138 } 136 }
  137 + else {
  138 + $this->campoOculto('ref_idpes', $this->ref_idpes);
  139 + $this->campoRotulo('nm_cliente', 'Cliente', $detalhe['nome']);
  140 + }
139 141
140 142
141 // text 143 // text
@@ -160,156 +162,178 @@ class indice extends clsCadastro @@ -160,156 +162,178 @@ class indice extends clsCadastro
160 162
161 if($this->cod_cliente && $this->ref_cod_biblioteca) 163 if($this->cod_cliente && $this->ref_cod_biblioteca)
162 { 164 {
163 - //$instituicao_desabilitado = true;  
164 - //$escola_desabilitado = true;  
165 - //$biblioteca_desabilitado = false;  
166 -  
167 $db = new clsBanco(); 165 $db = new clsBanco();
  166 +
  167 + // Cria campo oculto com o ID da biblioteca atual ao qual usuário está cadastrado
  168 + $this->ref_cod_biblioteca_atual = $this->ref_cod_biblioteca;
  169 + $this->campoOculto("ref_cod_biblioteca_atual", $this->ref_cod_biblioteca_atual);
  170 +
168 $this->ref_cod_instituicao = $db->CampoUnico("SELECT ref_cod_instituicao FROM pmieducar.biblioteca, pmieducar.cliente_tipo_cliente ctc, pmieducar.cliente_tipo ct WHERE ref_cod_cliente = '$this->cod_cliente' AND ref_cod_cliente_tipo = cod_cliente_tipo AND ct.ref_cod_biblioteca = cod_biblioteca AND ctc.ref_cod_biblioteca = {$this->ref_cod_biblioteca}"); 171 $this->ref_cod_instituicao = $db->CampoUnico("SELECT ref_cod_instituicao FROM pmieducar.biblioteca, pmieducar.cliente_tipo_cliente ctc, pmieducar.cliente_tipo ct WHERE ref_cod_cliente = '$this->cod_cliente' AND ref_cod_cliente_tipo = cod_cliente_tipo AND ct.ref_cod_biblioteca = cod_biblioteca AND ctc.ref_cod_biblioteca = {$this->ref_cod_biblioteca}");
169 $this->ref_cod_escola = $db->CampoUnico("SELECT ref_cod_escola FROM pmieducar.biblioteca, pmieducar.cliente_tipo_cliente ctc, pmieducar.cliente_tipo ct WHERE ref_cod_cliente = '$this->cod_cliente' AND ref_cod_cliente_tipo = cod_cliente_tipo AND ct.ref_cod_biblioteca = cod_biblioteca AND ctc.ref_cod_biblioteca = {$this->ref_cod_biblioteca}"); 172 $this->ref_cod_escola = $db->CampoUnico("SELECT ref_cod_escola FROM pmieducar.biblioteca, pmieducar.cliente_tipo_cliente ctc, pmieducar.cliente_tipo ct WHERE ref_cod_cliente = '$this->cod_cliente' AND ref_cod_cliente_tipo = cod_cliente_tipo AND ct.ref_cod_biblioteca = cod_biblioteca AND ctc.ref_cod_biblioteca = {$this->ref_cod_biblioteca}");
170 $this->ref_cod_biblioteca = $db->CampoUnico("SELECT cod_biblioteca FROM pmieducar.biblioteca, pmieducar.cliente_tipo_cliente ctc, pmieducar.cliente_tipo ct WHERE ref_cod_cliente = '$this->cod_cliente' AND ref_cod_cliente_tipo = cod_cliente_tipo AND ct.ref_cod_biblioteca = cod_biblioteca AND ctc.ref_cod_biblioteca = {$this->ref_cod_biblioteca}"); 173 $this->ref_cod_biblioteca = $db->CampoUnico("SELECT cod_biblioteca FROM pmieducar.biblioteca, pmieducar.cliente_tipo_cliente ctc, pmieducar.cliente_tipo ct WHERE ref_cod_cliente = '$this->cod_cliente' AND ref_cod_cliente_tipo = cod_cliente_tipo AND ct.ref_cod_biblioteca = cod_biblioteca AND ctc.ref_cod_biblioteca = {$this->ref_cod_biblioteca}");
171 $this->ref_cod_cliente_tipo = $db->CampoUnico("SELECT ref_cod_cliente_tipo FROM pmieducar.cliente_tipo_cliente WHERE ref_cod_cliente = '$this->cod_cliente'");// AND ref_cod_cliente_tipo IN (SELECT cod_cliente_tipo FROM pmieducar.cliente_tipo WHERE ref_cod_biblioteca = )");//IN (SELECT ref_cod_biblioteca FROM pmieducar.biblioteca_usuario WHERE ref_cod_usuario = '$this->pessoa_logada'))"); 174 $this->ref_cod_cliente_tipo = $db->CampoUnico("SELECT ref_cod_cliente_tipo FROM pmieducar.cliente_tipo_cliente WHERE ref_cod_cliente = '$this->cod_cliente'");// AND ref_cod_cliente_tipo IN (SELECT cod_cliente_tipo FROM pmieducar.cliente_tipo WHERE ref_cod_biblioteca = )");//IN (SELECT ref_cod_biblioteca FROM pmieducar.biblioteca_usuario WHERE ref_cod_usuario = '$this->pessoa_logada'))");
172 - $this->ref_cod_biblioteca_atual = $this->ref_cod_biblioteca;  
173 - $this->campoOculto("ref_cod_biblioteca_atual", $this->ref_cod_biblioteca_atual);  
174 } 175 }
175 include( "include/pmieducar/educar_campo_lista.php" ); 176 include( "include/pmieducar/educar_campo_lista.php" );
176 } 177 }
177 178
178 - function Novo()  
179 - {  
180 - @session_start();  
181 - $this->pessoa_logada = $_SESSION['id_pessoa'];  
182 - @session_write_close();  
183 - $senha = md5( $this->senha_."asnk@#*&(23" );  
184 - $obj_permissoes = new clsPermissoes();  
185 - $obj_permissoes->permissao_cadastra( 603, $this->pessoa_logada, 11, "educar_cliente_lst.php" );  
186 - $obj = new clsPmieducarCliente( null, null, null, $this->ref_idpes );  
187 - $detalhe = $obj->detalhe();  
188 - if ( !$detalhe )  
189 - {  
190 - $obj_cliente = new clsPmieducarCliente();  
191 - $lst_cliente = $obj_cliente->lista( null, null, null, null, $this->login_ );  
192 - if ( $lst_cliente && $this->login_ != "") {  
193 - $this->mensagem = "Este login já está sendo utilizado por outra pessoa!<br>";  
194 - echo "<!--\nErro ao cadastrar clsPmieducarCliente\nvalores obrigatorios\nis_numeric( $this->ref_cod_cliente_tipo ) && is_numeric( $this->ref_usuario_cad ) && is_numeric( $this->ref_idpes ) && is_numeric( $this->login_ )\n-->";  
195 - }  
196 - else {  
197 - $obj = new clsPmieducarCliente( $this->cod_cliente, null, $this->pessoa_logada, $this->ref_idpes, $this->login_, $senha, $this->data_cadastro, $this->data_exclusao, 1 );  
198 - $cadastrou = $obj->cadastra();  
199 - if( $cadastrou )  
200 - {  
201 - $this->cod_cliente = $cadastrou;  
202 - $obj_cliente_tipo = new clsPmieducarClienteTipoCliente( $this->ref_cod_cliente_tipo, $this->cod_cliente, null, null, $this->pessoa_logada, $this->pessoa_logada, 1 );  
203 - if ( $obj_cliente_tipo->existeCliente() )  
204 - {  
205 - if ( $obj_cliente_tipo->trocaTipo() )  
206 - {  
207 - $this->mensagem .= "Cadastro efetuado com sucesso.<br>";  
208 - header( "Location: educar_definir_cliente_tipo_lst.php" );  
209 - die();  
210 - return true;  
211 - }  
212 - }  
213 - else  
214 - {  
215 - $obj_cliente_tipo = new clsPmieducarClienteTipoCliente( $this->ref_cod_cliente_tipo, $this->cod_cliente, null, null, $this->pessoa_logada, null, 1 );  
216 - if ( $obj_cliente_tipo->cadastra() )  
217 - {  
218 - $this->mensagem .= "Cadastro efetuado com sucesso.<br>";  
219 - header( "Location: educar_cliente_lst.php" );  
220 - die();  
221 - return true; 179 +
  180 +
  181 + /**
  182 + * Sobrescrita do método clsCadastro::Novo.
  183 + *
  184 + * Insere novo registro nas tabelas pmieducar.cliente e pmieducar.cliente_tipo_cliente.
  185 + */
  186 + public function Novo() {
  187 + session_start();
  188 + $this->pessoa_logada = $_SESSION['id_pessoa'];
  189 + session_write_close();
  190 +
  191 + $senha = md5($this->senha . 'asnk@#*&(23');
  192 +
  193 + $obj_permissoes = new clsPermissoes();
  194 + $obj_permissoes->permissao_cadastra(603, $this->pessoa_logada, 11, 'educar_cliente_lst.php');
  195 +
  196 + $obj = new clsPmieducarCliente(NULL, NULL, NULL, $this->ref_idpes);
  197 + $detalhe = $obj->detalhe();
  198 +
  199 + if (!$detalhe) {
  200 + $obj_cliente = new clsPmieducarCliente();
  201 + $lst_cliente = $obj_cliente->lista(NULL, NULL, NULL, NULL, $this->login);
  202 +
  203 + if ($lst_cliente && $this->login != '') {
  204 + $this->mensagem = "Este login já está sendo utilizado por outra pessoa!<br>";
  205 + }
  206 + else {
  207 + $obj = new clsPmieducarCliente($this->cod_cliente, NULL, $this->pessoa_logada,
  208 + $this->ref_idpes, $this->login, $senha, $this->data_cadastro, $this->data_exclusao, 1);
  209 +
  210 + $cadastrou = $obj->cadastra();
  211 + if ($cadastrou) {
  212 + $this->cod_cliente = $cadastrou;
  213 + $obj_cliente_tipo = new clsPmieducarClienteTipoCliente($this->ref_cod_cliente_tipo,
  214 + $this->cod_cliente, NULL, NULL, $this->pessoa_logada, $this->pessoa_logada, 1);
  215 +
  216 + if ($obj_cliente_tipo->existeCliente()) {
  217 + if ($obj_cliente_tipo->trocaTipo()) {
  218 + $this->mensagem .= 'Cadastro efetuado com sucesso.<br>';
  219 + header('Location: educar_definir_cliente_tipo_lst.php');
  220 + die();
  221 + }
  222 + }
  223 + else {
  224 + $obj_cliente_tipo = new clsPmieducarClienteTipoCliente($this->ref_cod_cliente_tipo,
  225 + $this->cod_cliente, NULL, NULL, $this->pessoa_logada, NULL, 1, $this->ref_cod_biblioteca);
  226 +
  227 + if ($obj_cliente_tipo->cadastra()) {
  228 + $this->mensagem .= 'Cadastro efetuado com sucesso.<br>';
  229 + header('Location: educar_cliente_lst.php');
  230 + die();
222 } 231 }
  232 + }
  233 + }
223 234
224 - } 235 + $this->mensagem = "Cadastro n&atilde;o realizado.<br>";
225 236
226 - } 237 + return FALSE;
  238 + }
  239 + }
  240 + else {
  241 + $obj = new clsPmieducarCliente(NULL, NULL, NULL, $this->ref_idpes);
  242 + $registro = $obj->detalhe();
227 243
228 - $this->mensagem = "Cadastro n&atilde;o realizado.<br>";  
229 - echo "<!--\nErro ao cadastrar clsPmieducarCliente\nvalores obrigatorios\nis_numeric( $this->ref_cod_cliente_tipo ) && is_numeric( $this->pessoa_logada ) && is_numeric( $this->ref_idpes ) && is_numeric( $this->login_ )\n-->";  
230 - return false;  
231 - }  
232 - }  
233 - else {  
234 - $obj = new clsPmieducarCliente( null, null, null, $this->ref_idpes );  
235 - $registro = $obj->detalhe(); 244 + if ($registro) {
  245 + $this->cod_cliente = $registro['cod_cliente'];
  246 + }
236 247
237 - if( $registro )  
238 - $this->cod_cliente = $registro["cod_cliente"];  
239 - $this->ativo = 1; 248 + $this->ativo = 1;
240 249
241 - $sql = "SELECT COUNT(0) FROM pmieducar.cliente_tipo_cliente WHERE ref_cod_cliente_tipo = {$this->cod_cliente}  
242 - AND ref_cod_biblioteca = {$this->ref_cod_biblioteca} AND ativo = 1";  
243 - $db = new clsBanco();  
244 - $possui_biblio = $db->CampoUnico($sql);  
245 - if ($possui_biblio == 0)  
246 - {  
247 - $obj_cliente_tipo_cliente = new clsPmieducarClienteTipoCliente($this->ref_cod_cliente_tipo, $this->cod_cliente, null, null, $this->pessoa_logada, null, null, $this->ref_cod_biblioteca);  
248 - if (!$obj_cliente_tipo_cliente->cadastra())  
249 - {  
250 - $this->mensagem = "Não cadastrou";  
251 - return false;  
252 - }  
253 - else  
254 - {  
255 - header( "Location: educar_cliente_lst.php" );  
256 - return true;  
257 - die();  
258 - }  
259 - }  
260 - else  
261 - {  
262 - $this->Editar();  
263 - $this->mensagem = "O cliente já está cadastrado!<br>";  
264 - echo "<!--\nErro ao cadastrar clsPmieducarCliente\nvalores obrigatorios\nis_numeric( $this->ref_cod_cliente_tipo ) && is_numeric( $this->ref_usuario_cad ) && is_numeric( $this->ref_idpes ) && is_numeric( $this->login_ )\n-->";  
265 - }  
266 - }  
267 - } 250 + $sql = "SELECT COUNT(0) FROM pmieducar.cliente_tipo_cliente WHERE ref_cod_cliente_tipo = {$this->cod_cliente}
  251 + AND ref_cod_biblioteca = {$this->ref_cod_biblioteca} AND ativo = 1";
268 252
269 - function Editar()  
270 - {  
271 - @session_start();  
272 - $this->pessoa_logada = $_SESSION['id_pessoa'];  
273 - @session_write_close(); 253 + $db = new clsBanco();
  254 + $possui_biblio = $db->CampoUnico($sql);
  255 + if ($possui_biblio == 0) {
  256 + $obj_cliente_tipo_cliente = new clsPmieducarClienteTipoCliente($this->ref_cod_cliente_tipo,
  257 + $this->cod_cliente, NULL, NULL, $this->pessoa_logada, NULL, NULL, $this->ref_cod_biblioteca);
274 258
275 - $senha = md5( $this->senha_."asnk@#*&(23" );  
276 - $obj_permissoes = new clsPermissoes();  
277 - $obj_permissoes->permissao_cadastra( 603, $this->pessoa_logada, 11, "educar_cliente_lst.php" ); 259 + if (!$obj_cliente_tipo_cliente->cadastra()) {
  260 + $this->mensagem = "Não cadastrou";
278 261
279 - $obj = new clsPmieducarCliente( $this->cod_cliente, $this->pessoa_logada, $this->pessoa_logada, $this->ref_idpes, $this->login_, $senha, $this->data_cadastro, $this->data_exclusao, $this->ativo );  
280 - $editou = $obj->edita();  
281 - if( $editou )  
282 - {  
283 - $obj_cliente_tipo = new clsPmieducarClienteTipoCliente( $this->ref_cod_cliente_tipo, $this->cod_cliente, null, null, $this->pessoa_logada, $this->pessoa_logada, 1, $this->ref_cod_biblioteca );  
284 - if ( $obj_cliente_tipo->existeClienteBiblioteca($_POST['ref_cod_biblioteca_atual']) )  
285 - {  
286 - if ( $obj_cliente_tipo->trocaTipoBiblioteca($_POST['ref_cod_biblioteca_atual']) )  
287 - {  
288 - $this->mensagem .= "Cadastro efetuado com sucesso.<br>";  
289 - header( "Location: educar_cliente_lst.php" );  
290 - die();  
291 - return true;  
292 - }  
293 - }  
294 - else  
295 - {  
296 - $obj_cliente_tipo = new clsPmieducarClienteTipoCliente( $this->ref_cod_cliente_tipo, $this->cod_cliente, null, null, $this->pessoa_logada, null, 1, $this->ref_cod_biblioteca );  
297 - if ( $obj_cliente_tipo->cadastra() )  
298 - {  
299 - $this->mensagem .= "Edi&ccedil;&atilde;o efetuada com sucesso.<br>";  
300 - header( "Location: educar_cliente_lst.php" );  
301 - die();  
302 - return true; 262 + return FALSE;
303 } 263 }
304 - }  
305 - } 264 + else {
  265 + header('Location: educar_cliente_lst.php');
306 266
307 - $this->mensagem = "Edi&ccedil;&atilde;o n&atilde;o realizada.<br>";  
308 - echo "<!--\nErro ao editar clsPmieducarCliente\nvalores obrigatorios\nif( is_numeric( $this->cod_cliente ) && is_numeric( $this->ref_usuario_exc ) )\n-->"; 267 + return TRUE;
  268 + die();
  269 + }
  270 + }
  271 + else {
  272 + $this->Editar();
  273 + $this->mensagem = "O cliente já está cadastrado!<br>";
  274 + }
  275 + }
  276 + }
  277 +
  278 +
  279 +
  280 + /**
  281 + * Sobrescrita do método clsCadastro::Editar.
  282 + *
  283 + * Verifica:
  284 + * - Se usuário tem permissão de edição
  285 + * - Se usuário existe na biblioteca atual
  286 + * - Se existir, troca pela biblioteca escolhida na interface
  287 + * - Senão, cadastra como cliente da biblioteca
  288 + */
  289 + public function Editar() {
  290 + session_start();
  291 + $this->pessoa_logada = $_SESSION['id_pessoa'];
  292 + session_write_close();
  293 +
  294 + $senha = md5($this->senha . 'asnk@#*&(23');
  295 + $obj_permissoes = new clsPermissoes();
  296 + $obj_permissoes->permissao_cadastra(603, $this->pessoa_logada, 11, 'educar_cliente_lst.php');
  297 +
  298 + $obj = new clsPmieducarCliente($this->cod_cliente, $this->pessoa_logada, $this->pessoa_logada,
  299 + $this->ref_idpes, $this->login, $senha, $this->data_cadastro, $this->data_exclusao, $this->ativo);
  300 +
  301 + $editou = $obj->edita();
  302 +
  303 + if ($editou) {
  304 + // Cria objeto clsPemieducarClienteTipoCliente configurando atributos usados nas queries
  305 + $obj_cliente_tipo = new clsPmieducarClienteTipoCliente(
  306 + $this->ref_cod_cliente_tipo, $this->cod_cliente, NULL, NULL,
  307 + $this->pessoa_logada, $this->pessoa_logada, 1, $this->ref_cod_biblioteca);
  308 +
  309 + // clsPmieducarClienteTipoCliente::trocaTipoBiblioteca recebe o valor antigo para usar
  310 + // na cláusula WHERE
  311 + if ($obj_cliente_tipo->existeClienteBiblioteca($_POST['ref_cod_biblioteca_atual'])) {
  312 + if ($obj_cliente_tipo->trocaTipoBiblioteca($_POST['ref_cod_biblioteca_atual'])) {
  313 + $this->mensagem .= 'Cadastro efetuado com sucesso.<br>';
  314 + header('Location: educar_cliente_lst.php');
  315 + die();
  316 + }
  317 + }
  318 + else {
  319 + $obj_cliente_tipo = new clsPmieducarClienteTipoCliente(
  320 + $this->ref_cod_cliente_tipo, $this->cod_cliente, NULL, NULL,
  321 + $this->pessoa_logada, NULL, 1, $this->ref_cod_biblioteca);
  322 +
  323 + if ($obj_cliente_tipo->cadastra()) {
  324 + $this->mensagem .= 'Edi&ccedil;&atilde;o efetuada com sucesso.<br>';
  325 + header('Location: educar_cliente_lst.php');
  326 + die();
  327 + }
  328 + }
  329 + }
  330 +
  331 + $this->mensagem = 'Edi&ccedil;&atilde;o n&atilde;o realizada.<br>';
309 die(); 332 die();
310 - return false;  
311 } 333 }
312 334
  335 +
  336 +
313 function Excluir() 337 function Excluir()
314 { 338 {
315 @session_start(); 339 @session_start();
ieducar/intranet/include/pmieducar/clsPmieducarClienteTipoCliente.inc.php
1 <?php 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 /** 2 /**
28 -* @author Prefeitura Municipal de Itajaí  
29 -*  
30 -* Criado em 20/07/2006 11:49 pelo gerador automatico de classes  
31 -*/  
32 -  
33 -require_once( "include/pmieducar/geral.inc.php" ); 3 + *
  4 + * @author Prefeitura Municipal de Itajaí
  5 + * @version SVN: $Id$
  6 + *
  7 + * Pacote: i-PLB Software Público Livre e Brasileiro
  8 + *
  9 + * Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí
  10 + * ctima@itajai.sc.gov.br
  11 + *
  12 + * Este programa é software livre, você pode redistribuí-lo e/ou
  13 + * modificá-lo sob os termos da Licença Pública Geral GNU, conforme
  14 + * publicada pela Free Software Foundation, tanto a versão 2 da
  15 + * Licença como (a seu critério) qualquer versão mais nova.
  16 + *
  17 + * Este programa é distribuído na expectativa de ser útil, mas SEM
  18 + * QUALQUER GARANTIA. Sem mesmo a garantia implícita de COMERCIALI-
  19 + * ZAÇÃO ou de ADEQUAÇÃO A QUALQUER PROPÓSITO EM PARTICULAR. Con-
  20 + * sulte a Licença Pública Geral GNU para obter mais detalhes.
  21 + *
  22 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU
  23 + * junto com este programa. Se não, escreva para a Free Software
  24 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  25 + * 02111-1307, USA.
  26 + *
  27 + */
  28 +
  29 +require_once 'include/pmieducar/geral.inc.php';
34 30
35 class clsPmieducarClienteTipoCliente 31 class clsPmieducarClienteTipoCliente
36 { 32 {
37 - var $ref_cod_cliente_tipo;  
38 - var $ref_cod_cliente;  
39 - var $data_cadastro;  
40 - var $data_exclusao;  
41 - var $ref_usuario_cad;  
42 - var $ref_usuario_exc;  
43 - var $ativo;  
44 - var $ref_cod_biblioteca; 33 + // Campos da tabela
  34 + var $ref_cod_cliente_tipo;
  35 + var $ref_cod_cliente;
  36 + var $data_cadastro;
  37 + var $data_exclusao;
  38 + var $ref_usuario_cad;
  39 + var $ref_usuario_exc;
  40 + var $ativo;
  41 + var $ref_cod_biblioteca;
45 42
46 // propriedades padrao 43 // propriedades padrao
47 44
@@ -105,99 +102,81 @@ class clsPmieducarClienteTipoCliente @@ -105,99 +102,81 @@ class clsPmieducarClienteTipoCliente
105 /** 102 /**
106 * Construtor (PHP 4) 103 * Construtor (PHP 4)
107 * 104 *
108 - * @return object 105 + * @return clsPmieducarClienteTipoCliente
109 */ 106 */
110 - function clsPmieducarClienteTipoCliente( $ref_cod_cliente_tipo = null, $ref_cod_cliente = null, $data_cadastro = null, $data_exclusao = null, $ref_usuario_cad = null, $ref_usuario_exc = null, $ativo = 1, $ref_cod_biblioteca = null )  
111 - {  
112 - $db = new clsBanco();  
113 - $this->_schema = "pmieducar.";  
114 - $this->_tabela = "{$this->_schema}cliente_tipo_cliente";  
115 -  
116 - $this->_campos_lista = $this->_todos_campos = "ctc.ref_cod_cliente_tipo, ctc.ref_cod_cliente, ctc.data_cadastro, ctc.data_exclusao, ctc.ref_usuario_cad, ctc.ref_usuario_exc, ctc.ativo";  
117 -  
118 - if( is_numeric( $ref_cod_cliente_tipo ) )  
119 - {  
120 - if( class_exists( "clsPmieducarClienteTipo" ) )  
121 - {  
122 - $tmp_obj = new clsPmieducarClienteTipo( $ref_cod_cliente_tipo );  
123 - if( method_exists( $tmp_obj, "existe") )  
124 - {  
125 - if( $tmp_obj->existe() )  
126 - {  
127 - $this->ref_cod_cliente_tipo = $ref_cod_cliente_tipo;  
128 - }  
129 - }  
130 - else if( method_exists( $tmp_obj, "detalhe") )  
131 - {  
132 - if( $tmp_obj->detalhe() )  
133 - {  
134 - $this->ref_cod_cliente_tipo = $ref_cod_cliente_tipo;  
135 - }  
136 - }  
137 - }  
138 - else  
139 - {  
140 - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.cliente_tipo WHERE cod_cliente_tipo = '{$ref_cod_cliente_tipo}'" ) )  
141 - {  
142 - $this->ref_cod_cliente_tipo = $ref_cod_cliente_tipo;  
143 - }  
144 - }  
145 - }  
146 - if( is_numeric( $ref_cod_cliente ) )  
147 - {  
148 - if( class_exists( "clsPmieducarCliente" ) )  
149 - {  
150 - $tmp_obj = new clsPmieducarCliente( $ref_cod_cliente );  
151 - if( method_exists( $tmp_obj, "existe") )  
152 - {  
153 - if( $tmp_obj->existe() )  
154 - {  
155 - $this->ref_cod_cliente = $ref_cod_cliente; 107 + function clsPmieducarClienteTipoCliente($ref_cod_cliente_tipo = NULL, $ref_cod_cliente = NULL,
  108 + $data_cadastro = NULL, $data_exclusao = NULL, $ref_usuario_cad = NULL, $ref_usuario_exc = NULL,
  109 + $ativo = 1, $ref_cod_biblioteca = NULL) {
  110 +
  111 + $db = new clsBanco();
  112 + $this->_schema = 'pmieducar.';
  113 + $this->_tabela = "{$this->_schema}cliente_tipo_cliente";
  114 +
  115 + $this->_campos_lista = $this->_todos_campos = 'ctc.ref_cod_cliente_tipo, ctc.ref_cod_cliente, ctc.data_cadastro, ctc.data_exclusao, ctc.ref_usuario_cad, ctc.ref_usuario_exc, ctc.ativo';
  116 +
  117 + if (is_numeric( $ref_cod_cliente_tipo)) {
  118 + if (class_exists('clsPmieducarClienteTipo')) {
  119 + $tmp_obj = new clsPmieducarClienteTipo($ref_cod_cliente_tipo);
  120 + if (method_exists($tmp_obj, 'existe')) {
  121 + if ($tmp_obj->existe()) {
  122 + $this->ref_cod_cliente_tipo = $ref_cod_cliente_tipo;
156 } 123 }
157 } 124 }
158 - else if( method_exists( $tmp_obj, "detalhe") )  
159 - {  
160 - if( $tmp_obj->detalhe() )  
161 - {  
162 - $this->ref_cod_cliente = $ref_cod_cliente; 125 + elseif (method_exists($tmp_obj, 'detalhe')) {
  126 + if ($tmp_obj->detalhe()) {
  127 + $this->ref_cod_cliente_tipo = $ref_cod_cliente_tipo;
163 } 128 }
  129 + }
  130 + }
  131 + else {
  132 + if ($db->CampoUnico("SELECT 1 FROM pmieducar.cliente_tipo WHERE cod_cliente_tipo = '{$ref_cod_cliente_tipo}'")) {
  133 + $this->ref_cod_cliente_tipo = $ref_cod_cliente_tipo;
  134 + }
  135 + }
  136 + }
  137 +
  138 + if (is_numeric($ref_cod_cliente)) {
  139 + if (class_exists('clsPmieducarCliente')) {
  140 + $tmp_obj = new clsPmieducarCliente($ref_cod_cliente);
  141 + if (method_exists($tmp_obj, 'existe')) {
  142 + if ($tmp_obj->existe()) {
  143 + $this->ref_cod_cliente = $ref_cod_cliente;
  144 + }
164 } 145 }
165 - }  
166 - else  
167 - {  
168 - if( $db->CampoUnico( "SELECT 1 FROM pmieducar.cliente WHERE cod_cliente = '{$ref_cod_cliente}'" ) )  
169 - {  
170 - $this->ref_cod_cliente = $ref_cod_cliente;  
171 - }  
172 - }  
173 - } 146 + elseif (method_exists( $tmp_obj, 'detalhe')) {
  147 + if ($tmp_obj->detalhe()) {
  148 + $this->ref_cod_cliente = $ref_cod_cliente;
  149 + }
  150 + }
  151 + }
  152 + else {
  153 + if ($db->CampoUnico("SELECT 1 FROM pmieducar.cliente WHERE cod_cliente = '{$ref_cod_cliente}'")) {
  154 + $this->ref_cod_cliente = $ref_cod_cliente;
  155 + }
  156 + }
  157 + }
  158 +
  159 + if (is_string($data_cadastro)) {
  160 + $this->data_cadastro = $data_cadastro;
  161 + }
  162 + if (is_string($data_exclusao)) {
  163 + $this->data_exclusao = $data_exclusao;
  164 + }
  165 + if (is_numeric($ref_usuario_cad)) {
  166 + $this->ref_usuario_cad = $ref_usuario_cad;
  167 + }
  168 + if (is_numeric($ref_usuario_exc)) {
  169 + $this->ref_usuario_exc = $ref_usuario_exc;
  170 + }
  171 + if (is_numeric($ativo)) {
  172 + $this->ativo = $ativo;
  173 + }
  174 + if (is_numeric($ref_cod_biblioteca)) {
  175 + $this->ref_cod_biblioteca = $ref_cod_biblioteca;
  176 + }
  177 + }
174 178
175 179
176 - if( is_string( $data_cadastro ) )  
177 - {  
178 - $this->data_cadastro = $data_cadastro;  
179 - }  
180 - if( is_string( $data_exclusao ) )  
181 - {  
182 - $this->data_exclusao = $data_exclusao;  
183 - }  
184 - if( is_numeric( $ref_usuario_cad ) )  
185 - {  
186 - $this->ref_usuario_cad = $ref_usuario_cad;  
187 - }  
188 - if( is_numeric( $ref_usuario_exc ) )  
189 - {  
190 - $this->ref_usuario_exc = $ref_usuario_exc;  
191 - }  
192 - if( is_numeric( $ativo ) )  
193 - {  
194 - $this->ativo = $ativo;  
195 - }  
196 - if (is_numeric($ref_cod_biblioteca))  
197 - {  
198 - $this->ref_cod_biblioteca = $ref_cod_biblioteca;  
199 - }  
200 - }  
201 180
202 /** 181 /**
203 * Cria um novo registro 182 * Cria um novo registro
@@ -323,7 +302,13 @@ class clsPmieducarClienteTipoCliente @@ -323,7 +302,13 @@ class clsPmieducarClienteTipoCliente
323 } 302 }
324 return false; 303 return false;
325 } 304 }
326 - 305 +
  306 +
  307 +
  308 + /**
  309 + * Recebe valor antigo para utilizar na cláusula WHERE e atualiza o registro com os novos dados,
  310 + * vindos dos atributos.
  311 + */
327 function trocaTipoBiblioteca($ref_cod_biblioteca_atual) 312 function trocaTipoBiblioteca($ref_cod_biblioteca_atual)
328 { 313 {
329 if( is_numeric( $this->ref_cod_cliente_tipo ) && is_numeric( $this->ref_cod_cliente ) && is_numeric( $this->ref_usuario_exc ) && is_numeric( $this->ativo ) && is_numeric($this->ref_cod_biblioteca) && $ref_cod_biblioteca_atual ) 314 if( is_numeric( $this->ref_cod_cliente_tipo ) && is_numeric( $this->ref_cod_cliente ) && is_numeric( $this->ref_usuario_exc ) && is_numeric( $this->ativo ) && is_numeric($this->ref_cod_biblioteca) && $ref_cod_biblioteca_atual )
@@ -362,7 +347,7 @@ class clsPmieducarClienteTipoCliente @@ -362,7 +347,7 @@ class clsPmieducarClienteTipoCliente
362 } 347 }
363 return false; 348 return false;
364 } 349 }
365 - 350 +
366 /** 351 /**
367 * Retorna uma lista filtrados de acordo com os parametros 352 * Retorna uma lista filtrados de acordo com os parametros
368 * 353 *
@@ -514,24 +499,26 @@ class clsPmieducarClienteTipoCliente @@ -514,24 +499,26 @@ class clsPmieducarClienteTipoCliente
514 } 499 }
515 return false; 500 return false;
516 } 501 }
517 - 502 +
518 /** 503 /**
519 * Retorna um array com os dados de um registro 504 * Retorna um array com os dados de um registro
520 * 505 *
521 * @return array 506 * @return array
522 */ 507 */
523 - function existeClienteBiblioteca($ref_cod_biblioteca_atual)  
524 - {  
525 - if( is_numeric( $this->ref_cod_cliente ) && is_numeric($ref_cod_biblioteca_atual) )  
526 - { 508 + function existeClienteBiblioteca($ref_cod_biblioteca_atual) {
  509 + if (is_numeric($this->ref_cod_cliente) && is_numeric($ref_cod_biblioteca_atual)) {
  510 + $db = new clsBanco();
  511 + $db->Consulta("SELECT 1 FROM {$this->_tabela} WHERE ref_cod_cliente = '{$this->ref_cod_cliente}' AND ref_cod_biblioteca = {$ref_cod_biblioteca_atual}");
  512 + $db->ProximoRegistro();
527 513
528 - $db = new clsBanco();  
529 - $db->Consulta( "SELECT 1 FROM {$this->_tabela} WHERE ref_cod_cliente = '{$this->ref_cod_cliente}' AND ref_cod_biblioteca = {$ref_cod_biblioteca_atual}" );  
530 - $db->ProximoRegistro();  
531 - return $db->Tupla(); 514 + return $db->Tupla();
532 } 515 }
533 - return false; 516 +
  517 + return FALSE;
534 } 518 }
  519 +
  520 +
  521 +
535 /** 522 /**
536 * Exclui um registro 523 * Exclui um registro
537 * 524 *
@@ -628,5 +615,4 @@ class clsPmieducarClienteTipoCliente @@ -628,5 +615,4 @@ class clsPmieducarClienteTipoCliente
628 return ""; 615 return "";
629 } 616 }
630 617
631 -}  
632 -?>  
633 \ No newline at end of file 618 \ No newline at end of file
  619 +}
634 \ No newline at end of file 620 \ No newline at end of file