function lista($str_nome = FALSE, $numeric_cpf = FALSE, $inicio_limite = FALSE, $qtd_registros = FALSE, $str_orderBy = FALSE, $int_ref_cod_sistema = FALSE, $int_idpes = FALSE) { $whereAnd = ''; $where = ''; if (is_string($str_nome) && $str_nome != '') { $str_nome = addslashes($str_nome); $str_nome = str_replace(' ', '%', $str_nome); $where .= "{$whereAnd} nome ILIKE E'%{$str_nome}%' "; $whereAnd = ' AND '; } if (is_string($numeric_cpf)) { $numeric_cpf = addslashes($numeric_cpf); $where .= "{$whereAnd} cpf ILIKE E'%{$numeric_cpf}%' "; $whereAnd = ' AND '; } if (is_numeric($int_ref_cod_sistema)) { $where .= "{$whereAnd} (ref_cod_sistema = '{$int_ref_cod_sistema}' OR cpf is not null )"; $whereAnd = ' AND '; } if (is_numeric($int_idpes)) { $where .= "{$whereAnd} idpes = '{$int_idpes}'"; $whereAnd = ' AND '; } if (is_numeric($this->tipo_endereco)) { if ($this->tipo_endereco == 1) { // Interno $where .= "{$whereAnd} idpes IN (SELECT idpes FROM cadastro.endereco_pessoa)"; $whereAnd = ' AND '; } elseif ($this->tipo_endereco == 2) { // Externo $where .= "{$whereAnd} idpes IN (SELECT idpes FROM cadastro.endereco_externo)"; $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(); $dba = new clsBanco(); if ($where) { $where = "WHERE " . $where; } if (!$where) { $total = $db->CampoUnico('SELECT COUNT(0) FROM cadastro.fisica ' . $where); } else { $total = $db->CampoUnico('SELECT COUNT(0) FROM cadastro.v_pessoa_fisica ' . $where); } $db->Consulta(sprintf('SELECT idpes, nome, url, \'F\' AS tipo, email, cpf FROM cadastro.v_pessoa_fisica %s %s %s', $where, $orderBy, $limite)); $resultado = array(); while ($db->ProximoRegistro()) { $tupla = $db->Tupla(); $tupla['nome'] = transforma_minusculo($tupla['nome']); $tupla['total'] = $total; $dba->Consulta(sprintf("SELECT\n ddd_1, fone_1, ddd_2, fone_2, ddd_mov, fone_mov, ddd_fax, fone_fax\n FROM\n cadastro.v_fone_pessoa\n WHERE idpes = %d", $tupla['idpes'])); if ($dba->ProximoRegistro()) { $tupla_fone = $dba->Tupla(); } else { $tupla_fone = ''; } $tupla['ddd_1'] = $tupla_fone['ddd_1']; $tupla['fone_1'] = $tupla_fone['fone_1']; $tupla['ddd_2'] = $tupla_fone['ddd_2']; $tupla['fone_2'] = $tupla_fone['fone_2']; $tupla['ddd_mov'] = $tupla_fone['ddd_mov']; $tupla['fone_mov'] = $tupla_fone['fone_mov']; $tupla['ddd_fax'] = $tupla_fone['ddd_fax']; $tupla['fone_fax'] = $tupla_fone['fone_fax']; $resultado[] = $tupla; } if (count($resultado) > 0) { return $resultado; } return FALSE; }
function lista($str_nome = false, $numeric_cpf = false, $inicio_limite = false, $qtd_registros = false, $str_orderBy = false, $int_ref_cod_sistema = false, $int_idpes = false) { $whereAnd = ""; $where = ""; if (is_string($str_nome) && $str_nome != '') { $str_nome = str_replace(" ", "%", $str_nome); $where .= "{$whereAnd} nome ILIKE '%{$str_nome}%' "; $whereAnd = " AND "; } if (is_string($numeric_cpf)) { $where .= "{$whereAnd} cpf ILIKE '%{$numeric_cpf}%' "; $whereAnd = " AND "; } if (is_numeric($int_ref_cod_sistema)) { $where .= "{$whereAnd} (ref_cod_sistema = '{$int_ref_cod_sistema}' OR cpf is not null )"; $whereAnd = " AND "; } if (is_numeric($int_idpes)) { $where .= "{$whereAnd} idpes = '{$int_idpes}'"; $whereAnd = " AND "; } if (is_numeric($this->tipo_endereco)) { if ($this->tipo_endereco == 1) { //interno $where .= "{$whereAnd} idpes IN (SELECT idpes FROM cadastro.endereco_pessoa)"; $whereAnd = " AND "; } elseif ($this->tipo_endereco == 2) { //externo $where .= "{$whereAnd} idpes IN (SELECT idpes FROM cadastro.endereco_externo)"; $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(); $dba = new clsBanco(); if ($where) { $where = "AND " . $where; } if (!$where) { $total = $db->CampoUnico("Select count(0) FROM cadastro.fisica WHERE (alterado != 'TRUE' OR alterado IS NULL) {$where}"); } else { $total = $db->CampoUnico("Select count(0) FROM cadastro.v_pessoa_fisica WHERE idpes IN (SELECT idpes FROM cadastro.fisica WHERE (alterado != 'TRUE' OR alterado IS NULL)) {$where}"); } // $db->Consulta("Select idpes, nome, url,'F' as tipo, email, cpf FROM cadastro.v_pessoa_fisica $where $orderBy $limite"); //$where = " AND ".$where; $db->Consulta("Select idpes, nome, url,'F' as tipo, email, cpf FROM cadastro.v_pessoa_fisica WHERE idpes IN (SELECT idpes FROM cadastro.fisica WHERE (alterado != 'TRUE' OR alterado IS NULL)) {$where} {$orderBy} {$limite}"); $resultado = array(); while ($db->ProximoRegistro()) { $tupla = $db->Tupla(); $tupla['nome'] = transforma_minusculo($tupla['nome']); $tupla['total'] = $total; $tupla['alterado'] = $tupla['alterado']; $dba->Consulta("Select ddd_1, fone_1, ddd_2, fone_2, ddd_mov, fone_mov, ddd_fax, fone_fax from cadastro.v_fone_pessoa where idpes ={$tupla['idpes']}"); if ($dba->ProximoRegistro()) { $tupla_fone = $dba->Tupla(); } else { $tupla_fone = ""; } $tupla['ddd_1'] = $tupla_fone['ddd_1']; $tupla['fone_1'] = $tupla_fone['fone_1']; $tupla['ddd_2'] = $tupla_fone['ddd_2']; $tupla['fone_2'] = $tupla_fone['fone_2']; $tupla['ddd_mov'] = $tupla_fone['ddd_mov']; $tupla['fone_mov'] = $tupla_fone['fone_mov']; $tupla['ddd_fax'] = $tupla_fone['ddd_fax']; $tupla['fone_fax'] = $tupla_fone['fone_fax']; $resultado[] = $tupla; } if (count($resultado) > 0) { return $resultado; } return false; }