Commit 80d95c0c6d9880a07029cc19c34a436fb8e8977b

Authored by Eriksen Costa Paixão
1 parent 7777dc5e
Exists in master

r28@erik: eriksen | 2009-04-24 19:57:24 -0300

#17 by Eriksen: Corrigido bug que não listava os clientes de uma bibliteca enquanto não houvesse uma entrada na tabela de suspensão.
 
 Foi criado um método auxiliar na classe clsBanco para fazer a contagem de registros de uma tabela, para facilitar a correção do bug.
 
ieducar/intranet/include/clsBanco.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   -if( ! class_exists( "clsBancoSql_" ) )
28   -{
29   - require_once ( "include/clsBancoPgSql.inc.php" );
30   -}
  2 +/**
  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 + */
31 28  
32   -class clsBanco extends clsBancoSQL_
33   -{
34   -
35   - /*protected*/var $strHost = "localhost"; // Nome ou ip do servidor de dados
36   - /*protected*/var $strBanco = "ieducardb"; // Nome do Banco de Dados
37   - /*protected*/var $strUsuario = "ieducaruser"; // Usu&aacute;rio devidamente autorizado a acessar o Banco
38   - /*protected*/var $strSenha = "ieducar"; // Senha do Usu&aacute;rio do Banco
39   -
40   - /*protected*/var $bLink_ID = 0; // Identificador de Conex&atilde;o
41   - /*protected*/var $bConsulta_ID = 0; // Identificador de Resultado de Consulta
42   - /*protected*/var $arrayStrRegistro = array(); // Tupla resultante de uma consulta
43   - /*protected*/var $iLinha = 0; // Ponteiro interno para a Tupla atual da consulta
44   -
45   - /*protected*/var $bErro_no = 0; // Se ocorreu erro na consulta, retorna Falso
46   - /*protected*/var $strErro = ""; // Frase de descri&ccedil;&atilde;o do Erro Retornado
47   - /*protected*/var $bDepurar = false; // Ativa ou desativa fun&ccedil;oes de depura&ccedil;&atilde;o
48   -
49   - /*protected*/var $bAuto_Limpa = false; //" 1" para limpar o resultado assim que chegar ao &uacute;ltimo registro
50   -
51   - /*private*/var $strStringSQL = "";
52   -
53   - /*protected*/var $strType = "";
54   - /*protected*/var $arrayStrFields = array();
55   - /*protected*/var $arrayStrFrom = array();
56   - /*protected*/var $arrayStrWhere = array();
57   - /*protected*/var $arrayStrOrderBy = array();
58   - /*protected*/var $arrayStrGroupBy = array();
59   - /*protected*/var $iLimitInicio;
60   - /*protected*/var $iLimitQtd;
61   - /*protected*/var $arrayStrArquivo = "";
62   -
63   - function clsBanco( $strDataBase = false )
64   - {
65   - if( $strDataBase )
66   - {
67   - //$this->strBanco = $strDataBase;
68   - }
69   - }
  29 +if (!class_exists('clsBancoSql_')) {
  30 + require_once 'include/clsBancoPgSql.inc.php';
70 31 }
71   -?>
  32 +
  33 +class clsBanco extends clsBancoSQL_ {
  34 +
  35 + public $strHost = "localhost"; // Nome ou endereço IP do servidor do banco de dados
  36 + public $strBanco = "ieducardb"; // Nome do banco de dados
  37 + public $strUsuario = "ieducaruser"; // Usuário devidamente autorizado a acessar o banco
  38 + public $strSenha = "ieducar"; // Senha do usuário do banco
  39 +
  40 + public $bLink_ID = 0; // Identificador da conexão
  41 + public $bConsulta_ID = 0; // Identificador do resultado da consulta
  42 + public $arrayStrRegistro = array(); // Tupla resultante de uma consulta
  43 + public $iLinha = 0; // Ponteiro interno para a tupla atual da consulta
  44 +
  45 + public $bErro_no = 0; // Se ocorreu erro na consulta, retorna FALSE
  46 + public $strErro = ""; // Frase de descrição do erro retornado
  47 + public $bDepurar = FALSE; // Ativa ou desativa funções de depuração
  48 +
  49 + public $bAuto_Limpa = FALSE; // '1' para limpar o resultado assim que chegar ao último registro
  50 +
  51 + public $strStringSQL = "";
  52 +
  53 + var $strType = "";
  54 + var $arrayStrFields = array();
  55 + var $arrayStrFrom = array();
  56 + var $arrayStrWhere = array();
  57 + var $arrayStrOrderBy = array();
  58 + var $arrayStrGroupBy = array();
  59 + var $iLimitInicio;
  60 + var $iLimitQtd;
  61 + var $arrayStrArquivo = "";
  62 +
  63 +
  64 +
  65 + /**
  66 + * Construtor (PHP 4).
  67 + */
  68 + public function clsBanco($strDataBase = FALSE) {}
  69 +
  70 +
  71 +
  72 + /**
  73 + * Retorna a quantidade de registros de uma tabela baseado no objeto que a
  74 + * abstrai. Este deve ter um atributo público Object->_tabela.
  75 + *
  76 + * @param object Objeto que abstrai a tabela
  77 + * @param string Nome da coluna para cálculo COUNT()
  78 + * @return int Quantidade de registros da tabela
  79 + */
  80 + public function doCountFromObj($obj, $column = '*') {
  81 + if ($obj->_tabela == NULL) {
  82 + return FALSE;
  83 + }
  84 +
  85 + $sql = sprintf('SELECT COUNT(%s) FROM %s', $column, $obj->_tabela);
  86 + $this->Consulta($sql);
  87 +
  88 + return (int)$this->UnicoCampo($sql);
  89 + }
  90 +
  91 +}
72 92 \ No newline at end of file
... ...
ieducar/intranet/include/pmieducar/clsPmieducarCliente.inc.php
1 1 <?php
2 2 /**
3 3 *
4   - * @author Prefeitura Municipal de Itajaí
5   - * @updated 29/03/2007
6   - * Pacote: i-PLB Software Público Livre e Brasileiro
  4 + * @author Prefeitura Municipal de Itajaí
  5 + * @version SVN: $Id$
7 6 *
8   - * Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí
9   - * ctima@itajai.sc.gov.br
  7 + * Pacote: i-PLB Software Público Livre e Brasileiro
10 8 *
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.
  9 + * Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí
  10 + * ctima@itajai.sc.gov.br
15 11 *
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.
  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.
20 16 *
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.
  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.
25 26 *
26 27 */
27 28  
28   -/*
29   - * Criado em 17/07/2006 09:18 pelo gerador automatico de classes
30   - */
31   -
32   -require_once( "include/pmieducar/geral.inc.php" );
  29 +require_once 'include/pmieducar/geral.inc.php';
33 30  
34 31 class clsPmieducarCliente
35 32 {
... ... @@ -102,13 +99,16 @@ class clsPmieducarCliente
102 99 var $_campo_order_by;
103 100  
104 101  
  102 +
105 103 /**
106 104 * Construtor (PHP 4)
107 105 *
108 106 * @return object
109 107 */
110   - function clsPmieducarCliente( $cod_cliente = null, $ref_usuario_exc = null, $ref_usuario_cad = null, $ref_idpes = null, $login = null, $senha = null, $data_cadastro = null, $data_exclusao = null, $ativo = null )
111   - {
  108 + function clsPmieducarCliente($cod_cliente = NULL, $ref_usuario_exc = NULL,
  109 + $ref_usuario_cad = NULL, $ref_idpes = NULL, $login = NULL, $senha = NULL, $data_cadastro = NULL,
  110 + $data_exclusao = NULL, $ativo = NULL) {
  111 +
112 112 $db = new clsBanco();
113 113 $this->_schema = "pmieducar.";
114 114 $this->_tabela = "{$this->_schema}cliente";
... ... @@ -479,228 +479,249 @@ class clsPmieducarCliente
479 479 return false;
480 480 }
481 481  
482   - /**
483   - * Retorna uma lista filtrados de acordo com os parametros
484   - *
485   - * @return array
486   - */
487   - function listaCompleta( $int_cod_cliente = null, $int_ref_usuario_exc = null, $int_ref_usuario_cad = null, $int_ref_idpes = null, $int_login = null, $str_senha = null, $date_data_cadastro_ini = null, $date_data_cadastro_fim = null, $date_data_exclusao_ini = null, $date_data_exclusao_fim = null, $int_ativo = 1, $str_nm_cliente = null, $str_suspenso = null, $int_cod_cliente_tipo = null, $int_cod_escola = null, $int_cod_biblioteca = null, $int_cod_instituicao = null )
488   - {
489   - $tab_adicional = '';
490   - $condicao = '';
491   - $camp_adicional = '';
492   -
493   - // Se suspenso não for nulo, seleciona clientes suspensos
494   - if (!is_null($str_suspenso))
495   - {
496   - $camp_adicional .= ", pmieducar.cliente_suspensao cs ";
497   - $condicao .= " AND c.cod_cliente = cs.ref_cod_cliente";
498   - }
499   - else
500   - {
501   - $camp_adicional .= ", pmieducar.cliente_suspensao cs ";
502   - $condicao .= " AND c.cod_cliente <> cs.ref_cod_cliente";
503   - }
504   -
505   - $sql1 = "SELECT c.cod_cliente,
506   - c.ref_idpes,
507   - c.ref_usuario_cad,
508   - c.login,
509   - p.nome,
510   - ct.nm_tipo,
511   - ct.cod_cliente_tipo,
512   - b.nm_biblioteca,
513   - b.cod_biblioteca,
514   - e.cod_escola as cod_escola,
515   - i.cod_instituicao,
516   - (SELECT 'S'::text
517   - FROM pmieducar.cliente_suspensao cs
518   - WHERE cs.ref_cod_cliente = c.cod_cliente
519   - AND cs.data_liberacao IS NULL) AS id_suspensao
520   - FROM pmieducar.cliente c,
521   - pmieducar.cliente_tipo_cliente ctc,
522   - pmieducar.cliente_tipo ct,
523   - pmieducar.biblioteca b,
524   - pmieducar.escola e,
525   - pmieducar.instituicao i,
526   - cadastro.pessoa p{$camp_adicional}
527   - WHERE c.cod_cliente = ctc.ref_cod_cliente
528   - AND ct.cod_cliente_tipo = ctc.ref_cod_cliente_tipo
529   - AND b.cod_biblioteca = ct.ref_cod_biblioteca
530   - AND e.cod_escola = b.ref_cod_escola
531   - AND i.cod_instituicao = b.ref_cod_instituicao
532   - AND e.ref_cod_instituicao = i.cod_instituicao{$condicao}
533   - AND p.idpes = c.ref_idpes
534   - AND c.ativo = '{$int_ativo}'
535   - AND ctc.ativo = '{$int_ativo}'";
536   -
537   - $sql2 = "SELECT c.cod_cliente,
538   - c.ref_idpes,
539   - c.ref_usuario_cad,
540   - c.login,
541   - p.nome,
542   - ct.nm_tipo,
543   - ct.cod_cliente_tipo,
544   - b.nm_biblioteca,
545   - b.cod_biblioteca,
546   - null as cod_escola,
547   - i.cod_instituicao,
548   - (SELECT 'S'::text
549   - FROM pmieducar.cliente_suspensao cs
550   - WHERE cs.ref_cod_cliente = c.cod_cliente
551   - AND cs.data_liberacao IS NULL) AS id_suspensao
552   - FROM pmieducar.cliente c,
553   - pmieducar.cliente_tipo_cliente ctc,
554   - pmieducar.cliente_tipo ct,
555   - pmieducar.biblioteca b,
556   - pmieducar.instituicao i,
557   - cadastro.pessoa p{$camp_adicional}
558   - WHERE c.cod_cliente = ctc.ref_cod_cliente
559   - AND ct.cod_cliente_tipo = ctc.ref_cod_cliente_tipo
560   - AND b.cod_biblioteca = ct.ref_cod_biblioteca
561   - AND i.cod_instituicao = b.ref_cod_instituicao
562   - AND b.ref_cod_escola IS NULL
563   - AND ct.ref_cod_biblioteca = b.cod_biblioteca{$condicao}
564   - AND p.idpes = c.ref_idpes
565   - AND c.ativo = '{$int_ativo}'
566   - AND ctc.ativo = '{$int_ativo}'";
567 482  
568   - $filtros = "";
569   - $whereAnd = " AND ";
570 483  
571   - if( is_numeric( $int_cod_cliente ) )
572   - {
573   - $filtros .= "{$whereAnd} c.cod_cliente = '{$int_cod_cliente}'";
574   - $whereAnd = " AND ";
575   - }
576   - if( is_numeric( $int_ref_usuario_exc ) )
577   - {
578   - $filtros .= "{$whereAnd} c.ref_usuario_exc = '{$int_ref_usuario_exc}'";
579   - $whereAnd = " AND ";
580   - }
581   - if( is_numeric( $int_ref_usuario_cad ) )
582   - {
583   - $filtros .= "{$whereAnd} c.ref_usuario_cad = '{$int_ref_usuario_cad}'";
584   - $whereAnd = " AND ";
585   - }
586   - if( is_numeric( $int_ref_idpes ) )
587   - {
588   - $filtros .= "{$whereAnd} c.ref_idpes = '{$int_ref_idpes}'";
589   - $whereAnd = " AND ";
590   - }
591   - if( is_numeric( $int_login ) )
592   - {
593   - $filtros .= "{$whereAnd} c.login = '{$int_login}'";
594   - $whereAnd = " AND ";
595   - }
596   - if( is_string( $str_senha ) )
597   - {
598   - $filtros .= "{$whereAnd} c.senha = '{$str_senha}'";
599   - $whereAnd = " AND ";
600   - }
601   - if( is_string( $date_data_cadastro_ini ) )
602   - {
603   - $filtros .= "{$whereAnd} c.data_cadastro >= '{$date_data_cadastro_ini}'";
604   - $whereAnd = " AND ";
605   - }
606   - if( is_string( $date_data_cadastro_fim ) )
607   - {
608   - $filtros .= "{$whereAnd} c.data_cadastro <= '{$date_data_cadastro_fim}'";
609   - $whereAnd = " AND ";
610   - }
611   - if( is_string( $date_data_exclusao_ini ) )
612   - {
613   - $filtros .= "{$whereAnd} c.data_exclusao >= '{$date_data_exclusao_ini}'";
614   - $whereAnd = " AND ";
615   - }
616   - if( is_string( $date_data_exclusao_fim ) )
617   - {
618   - $filtros .= "{$whereAnd} c.data_exclusao <= '{$date_data_exclusao_fim}'";
619   - $whereAnd = " AND ";
620   - }
621   - if( is_null( $int_ativo ) || $int_ativo )
622   - {
623   - $filtros .= "{$whereAnd} c.ativo = '1'";
624   - $whereAnd = " AND ";
625   - }
626   - else
627   - {
628   - $filtros .= "{$whereAnd} c.ativo = '0'";
629   - $whereAnd = " AND ";
630   - }
631   - if( is_string( $str_nm_cliente ) )
632   - {
633   - $filtros .= "{$whereAnd} p.nome LIKE '%{$str_nm_cliente}%'";
634   - $whereAnd = " AND ";
635   - }
636   - if ( is_numeric( $int_cod_cliente_tipo ) )
637   - {
638   - $filtros .= "{$whereAnd} ct.cod_cliente_tipo = '{$int_cod_cliente_tipo}'";
639   - $whereAnd = " AND ";
640   - }
641   - if ( is_array( $int_cod_biblioteca ) )
642   - {
643   - $array_biblioteca = implode(", ", $int_cod_biblioteca);
644   - $filtros .= "{$whereAnd} b.cod_biblioteca IN ({$array_biblioteca})";
645   - $whereAnd = " AND ";
646   - }
647   - if ( is_numeric( $int_cod_biblioteca ) )
648   - {
649   - $filtros .= "{$whereAnd} b.cod_biblioteca = '{$int_cod_biblioteca}'";
650   - $whereAnd = " AND ";
651   - }
652   - if ( is_numeric( $int_cod_escola ) )
653   - {
654   - $filtros .= "{$whereAnd} e.cod_escola = '{$int_cod_escola}'";
655   - $whereAnd = " AND ";
656   - }
657   - if ( is_numeric( $int_cod_instituicao ) )
658   - {
659   - $filtros .= "{$whereAnd} i.cod_instituicao = '{$int_cod_instituicao}'";
660   - $whereAnd = " AND ";
661   - }
662   - if( is_string( $str_suspenso ) ) {
663   - $filtros .= "{$whereAnd} cs.data_liberacao IS NULL";
664   - $whereAnd = " AND ";
665   - }
666   -
667   - $db = new clsBanco();
668   - $resultado = array();
669   -
670   - $sql1 .= $filtros; /*. $this->getOrderby() . $this->getLimite();*/
671   - $sql2 .= $filtros;
672   -
673   - if(is_numeric($int_cod_escola))
674   - {
675   - $this->_total = $db->CampoUnico( "SELECT count(0) FROM ( {$sql1} ) AS SUBQUERY" );
676   - }
677   - else
678   - {
679   - $this->_total = $db->CampoUnico( "SELECT count(0) FROM ( ".$sql1." UNION ".$sql2." ) AS SUBQUERY" );
680   - }
681   -
682   - $sql2 .= $this->getOrderby() . $this->getLimite();
683   -
684   - if ( is_numeric( $int_cod_escola ) )
685   - $sql = $sql1;
686   - else
687   - $sql = $sql1." UNION ".$sql2;
688   -
689   - $db->Consulta( $sql );
  484 + /**
  485 + * Retorna uma lista filtrada de acordo com os argumentos.
  486 + *
  487 + * @return Array
  488 + */
  489 + public function listaCompleta($int_cod_cliente = NULL, $int_ref_usuario_exc = NULL,
  490 + $int_ref_usuario_cad = NULL, $int_ref_idpes = NULL, $int_login = NULL, $str_senha = NULL,
  491 + $date_data_cadastro_ini = NULL, $date_data_cadastro_fim = NULL, $date_data_exclusao_ini = NULL,
  492 + $date_data_exclusao_fim = NULL, $int_ativo = 1, $str_nm_cliente = NULL, $str_suspenso = NULL,
  493 + $int_cod_cliente_tipo = NULL, $int_cod_escola = NULL, $int_cod_biblioteca = NULL,
  494 + $int_cod_instituicao = NULL) {
  495 +
  496 + $tab_adicional = '';
  497 + $condicao = '';
  498 + $camp_adicional = '';
  499 +
  500 + // Executa filtragem por clientes suspensos somente quando houver registros na tabela
  501 + $clienteSuspenso = new clsPmieducarClienteSuspensao();
  502 + $db = new clsBanco();
  503 +
  504 + // Se suspenso não for nulo e existirem cliente suspensos, seleciona-os
  505 + // quando ainda estiverem no prazo de suspensão
  506 + if (!is_null($str_suspenso) && $db->doCountFromObj($clienteSuspenso) > 0) {
  507 + $camp_adicional .= ', pmieducar.cliente_suspensao cs ';
  508 + $condicao .= ' AND c.cod_cliente = cs.ref_cod_cliente AND
  509 + (cs.data_suspensao < current_date - cs.dias)';
  510 + }
  511 + else {
  512 + $camp_adicional .= ', pmieducar.cliente_suspensao cs ';
  513 + $condicao .= ' AND (c.cod_cliente <> cs.ref_cod_cliente OR
  514 + (cs.data_suspensao > current_date - cs.dias))';
  515 + }
  516 +
  517 + $sql1 = "
  518 + SELECT
  519 + c.cod_cliente,
  520 + c.ref_idpes,
  521 + c.ref_usuario_cad,
  522 + c.login,
  523 + p.nome,
  524 + ct.nm_tipo,
  525 + ct.cod_cliente_tipo,
  526 + b.nm_biblioteca,
  527 + b.cod_biblioteca,
  528 + e.cod_escola as cod_escola,
  529 + i.cod_instituicao,
  530 + (SELECT 'S'::text
  531 + FROM pmieducar.cliente_suspensao cs
  532 + WHERE cs.ref_cod_cliente = c.cod_cliente
  533 + AND cs.data_liberacao IS NULL) AS id_suspensao
  534 + FROM
  535 + pmieducar.cliente c,
  536 + pmieducar.cliente_tipo_cliente ctc,
  537 + pmieducar.cliente_tipo ct,
  538 + pmieducar.biblioteca b,
  539 + pmieducar.escola e,
  540 + pmieducar.instituicao i,
  541 + cadastro.pessoa p{$camp_adicional}
  542 + WHERE
  543 + c.cod_cliente = ctc.ref_cod_cliente
  544 + AND ct.cod_cliente_tipo = ctc.ref_cod_cliente_tipo
  545 + AND b.cod_biblioteca = ct.ref_cod_biblioteca
  546 + AND e.cod_escola = b.ref_cod_escola
  547 + AND i.cod_instituicao = b.ref_cod_instituicao
  548 + AND e.ref_cod_instituicao = i.cod_instituicao{$condicao}
  549 + AND p.idpes = c.ref_idpes
  550 + AND c.ativo = '{$int_ativo}'
  551 + AND ctc.ativo = '{$int_ativo}'";
  552 +
  553 + $sql2 = "
  554 + SELECT
  555 + c.cod_cliente,
  556 + c.ref_idpes,
  557 + c.ref_usuario_cad,
  558 + c.login,
  559 + p.nome,
  560 + ct.nm_tipo,
  561 + ct.cod_cliente_tipo,
  562 + b.nm_biblioteca,
  563 + b.cod_biblioteca,
  564 + null as cod_escola,
  565 + i.cod_instituicao,
  566 + (SELECT 'S'::text
  567 + FROM pmieducar.cliente_suspensao cs
  568 + WHERE cs.ref_cod_cliente = c.cod_cliente
  569 + AND cs.data_liberacao IS NULL) AS id_suspensao
  570 + FROM
  571 + pmieducar.cliente c,
  572 + pmieducar.cliente_tipo_cliente ctc,
  573 + pmieducar.cliente_tipo ct,
  574 + pmieducar.biblioteca b,
  575 + pmieducar.instituicao i,
  576 + cadastro.pessoa p{$camp_adicional}
  577 + WHERE c.cod_cliente = ctc.ref_cod_cliente
  578 + AND ct.cod_cliente_tipo = ctc.ref_cod_cliente_tipo
  579 + AND b.cod_biblioteca = ct.ref_cod_biblioteca
  580 + AND i.cod_instituicao = b.ref_cod_instituicao
  581 + AND b.ref_cod_escola IS NULL
  582 + AND ct.ref_cod_biblioteca = b.cod_biblioteca{$condicao}
  583 + AND p.idpes = c.ref_idpes
  584 + AND c.ativo = '{$int_ativo}'
  585 + AND ctc.ativo = '{$int_ativo}'";
  586 +
  587 + $filtros = '';
  588 + $whereAnd = ' AND ';
  589 +
  590 + if (is_numeric($int_cod_cliente)) {
  591 + $filtros .= "{$whereAnd} c.cod_cliente = '{$int_cod_cliente}'";
  592 + $whereAnd = " AND ";
  593 + }
  594 +
  595 + if (is_numeric($int_ref_usuario_exc)) {
  596 + $filtros .= "{$whereAnd} c.ref_usuario_exc = '{$int_ref_usuario_exc}'";
  597 + $whereAnd = " AND ";
  598 + }
  599 +
  600 + if (is_numeric($int_ref_usuario_cad)) {
  601 + $filtros .= "{$whereAnd} c.ref_usuario_cad = '{$int_ref_usuario_cad}'";
  602 + $whereAnd = " AND ";
  603 + }
  604 +
  605 + if (is_numeric($int_ref_idpes)) {
  606 + $filtros .= "{$whereAnd} c.ref_idpes = '{$int_ref_idpes}'";
  607 + $whereAnd = " AND ";
  608 + }
  609 +
  610 + if (is_numeric($int_login)) {
  611 + $filtros .= "{$whereAnd} c.login = '{$int_login}'";
  612 + $whereAnd = " AND ";
  613 + }
  614 +
  615 + if (is_string($str_senha)) {
  616 + $filtros .= "{$whereAnd} c.senha = '{$str_senha}'";
  617 + $whereAnd = " AND ";
  618 + }
  619 +
  620 + if (is_string($date_data_cadastro_ini)) {
  621 + $filtros .= "{$whereAnd} c.data_cadastro >= '{$date_data_cadastro_ini}'";
  622 + $whereAnd = " AND ";
  623 + }
  624 +
  625 + if (is_string($date_data_cadastro_fim)) {
  626 + $filtros .= "{$whereAnd} c.data_cadastro <= '{$date_data_cadastro_fim}'";
  627 + $whereAnd = " AND ";
  628 + }
  629 +
  630 + if (is_string($date_data_exclusao_ini)) {
  631 + $filtros .= "{$whereAnd} c.data_exclusao >= '{$date_data_exclusao_ini}'";
  632 + $whereAnd = " AND ";
  633 + }
  634 +
  635 + if (is_string($date_data_exclusao_fim)) {
  636 + $filtros .= "{$whereAnd} c.data_exclusao <= '{$date_data_exclusao_fim}'";
  637 + $whereAnd = " AND ";
  638 + }
  639 +
  640 + if (is_null($int_ativo) || $int_ativo) {
  641 + $filtros .= "{$whereAnd} c.ativo = '1'";
  642 + $whereAnd = " AND ";
  643 + }
  644 + else {
  645 + $filtros .= "{$whereAnd} c.ativo = '0'";
  646 + $whereAnd = " AND ";
  647 + }
  648 +
  649 + if (is_string($str_nm_cliente)) {
  650 + $filtros .= "{$whereAnd} p.nome LIKE '%{$str_nm_cliente}%'";
  651 + $whereAnd = " AND ";
  652 + }
  653 +
  654 + if (is_numeric($int_cod_cliente_tipo)) {
  655 + $filtros .= "{$whereAnd} ct.cod_cliente_tipo = '{$int_cod_cliente_tipo}'";
  656 + $whereAnd = " AND ";
  657 + }
  658 +
  659 + if (is_array($int_cod_biblioteca)) {
  660 + $array_biblioteca = implode(", ", $int_cod_biblioteca);
  661 + $filtros .= "{$whereAnd} b.cod_biblioteca IN ({$array_biblioteca})";
  662 + $whereAnd = " AND ";
  663 + }
  664 +
  665 + if (is_numeric($int_cod_biblioteca)) {
  666 + $filtros .= "{$whereAnd} b.cod_biblioteca = '{$int_cod_biblioteca}'";
  667 + $whereAnd = " AND ";
  668 + }
  669 +
  670 + if (is_numeric($int_cod_escola)) {
  671 + $filtros .= "{$whereAnd} e.cod_escola = '{$int_cod_escola}'";
  672 + $whereAnd = " AND ";
  673 + }
  674 +
  675 + if (is_numeric($int_cod_instituicao)) {
  676 + $filtros .= "{$whereAnd} i.cod_instituicao = '{$int_cod_instituicao}'";
  677 + $whereAnd = " AND ";
  678 + }
  679 +
  680 + if (is_string($str_suspenso)) {
  681 + $filtros .= "{$whereAnd} cs.data_liberacao IS NULL";
  682 + $whereAnd = " AND ";
  683 + }
  684 +
  685 + $db = new clsBanco();
  686 + $resultado = array();
  687 +
  688 + $sql1 .= $filtros;
  689 + $sql2 .= $filtros;
  690 +
  691 + if (is_numeric($int_cod_escola)) {
  692 + $this->_total = $db->CampoUnico("SELECT count(0) FROM ({$sql1}) AS SUBQUERY");
  693 + }
  694 + else {
  695 + $this->_total = $db->CampoUnico("SELECT count(0) FROM (" . $sql1 . " UNION " . $sql2 . ") AS SUBQUERY");
  696 + }
  697 +
  698 + // Aplica ordenação e limite
  699 + $sql2 .= $this->getOrderby() . $this->getLimite();
  700 +
  701 + if (is_numeric($int_cod_escola)) {
  702 + $sql = $sql1;
  703 + }
  704 + else {
  705 + $sql = $sql1 . ' UNION ' . $sql2;
  706 + }
  707 +
  708 + $db->Consulta($sql);
  709 +
  710 + while ($db->ProximoRegistro()) {
  711 + $tupla = $db->Tupla();
  712 +
  713 + $tupla["_total"] = $this->_total;
  714 + $resultado[] = $tupla;
  715 + }
  716 +
  717 + if (count($resultado) > 0) {
  718 + return $resultado;
  719 + }
  720 +
  721 + return FALSE;
  722 + }
690 723  
691   - while ( $db->ProximoRegistro() )
692   - {
693   - $tupla = $db->Tupla();
694 724  
695   - $tupla["_total"] = $this->_total;
696   - $resultado[] = $tupla;
697   - }
698   - if( count( $resultado ) )
699   - {
700   - return $resultado;
701   - }
702   - return false;
703   - }
704 725  
705 726 /**
706 727 * Retorna uma lista filtrados de acordo com os parametros
... ... @@ -991,5 +1012,4 @@ class clsPmieducarCliente
991 1012 return false;
992 1013 }
993 1014  
994   -}
995   -?>
  1015 +}
996 1016 \ No newline at end of file
... ...