source: trunk/workflow/inc/report/includes/classes/Listagem.class.php @ 6413

Revision 6413, 80.5 KB checked in by viani, 12 years ago (diff)

Ticket #2416 - Correção em estilos do arquivo css do gerador de relatórios do workflow

Line 
1<?php
2/**
3 * Listagem
4 *
5 * Implementaçao de Listagens padroes do sistema.
6 */
7/**
8 * Listagem
9 *
10 * Implementaçao de Listagens padroes do sistema.
11 *
12 *
13 * @author Jair Pereira <pereira.jair@gmail.com>
14 * @since 01/06/2009
15 *
16 * @package Listagem
17 */
18
19include_once("ListagemColuna.class.php");
20include_once("ListagemIndicador.class.php");
21include_once("SqlParser.class.php");
22
23class Listagem {
24
25    /**
26     * Identificador da Listagem.
27     */
28    private $idlistagem;
29
30    /**
31     * Tï¿œtulo da Listagem
32     */
33    private $titulo;
34
35    /**
36     * Array de Colunas.
37     */
38    private $colunas = array();
39
40    /**
41     * Array de Linhas de Detalhamento.
42     */
43    private $linhasdetalhamento = array();
44
45    /**
46     * Array de Linhas Agrupadas
47     */
48    private $linhasagrupamento = array();
49
50    /**
51     * Array de Dados.
52     */
53    private $dados = array();
54
55    /**
56     * Exibe Header das Tables. (Tï¿œtulos das Colunas).
57     */
58    private $showthead = true;
59
60    /**
61     * Array de Totalizadores.
62     */
63    private $totalizadores = array();
64
65    /**
66     * Alterado para Protegido nï¿œo serï¿œ instanciado na classe.
67     */
68    //protected  $form = Formulario;
69
70    /**
71     * Formulï¿œrio de Pesquisa.
72     */
73    //protected $formpesquisa = Formulario;
74
75    /**
76     * Agrupar Resultados Alfabeticamente (True ou False)
77     */
78    private $agruparAlfabeticamente = false;
79
80        /**
81         * Array de Indicadores
82         */
83    private $arrindicadores = array();
84
85    /**
86     * Array de Parï¿œmetros
87     */
88    private $arrparametros = array();
89
90    /**
91     * Array de Agrupamentos
92     */
93    private $arragrupamentos = array();
94
95    /**
96     * SubListagem.
97     */
98    public $subListagem;
99
100    /**
101     * Indica se este objeto ï¿œ uma SubListagem.
102     */
103    private $issublist = false;
104
105    /**
106     * Conexao com o Banco de Dados.
107     */
108    private $conexao;
109
110    /**
111     * SQL da Listagem.
112     */
113    private $sql;
114
115    /**
116     * Exibir SubTotalizadores
117     */
118    private $exibesubtotais = false;
119
120    private $exibedivcolunas = true;
121
122    /**
123     * Exibir Totalizadores
124     */
125    private $_exibetotalizadores = true;
126
127    /**
128     * Exibir Quantidade de Registros Encontrados
129     */
130    private $_exibeqtdregistros = true;
131
132    /**
133     * Modo DEBUG
134     */
135    private $_debug = true;
136
137    /**
138     * Array de Erros
139     */
140    private $_errors = array();
141
142    /**
143     * Indica se a Listagem Possui algum checkbox
144     */
145    private $temcheck = false;
146
147    /**
148     * Repetir Tï¿œtulo do Agrupamento.
149     */
150    private $_repetirtituloagrupamento = true;
151
152    /**
153     * Quantidade de Registros da Listagem Principal (Usada somente quando a listagem ï¿œ uma sublistagem.)
154     */
155    private $_qtdregistroslistagemprincipal = 0;
156
157    /**
158     * Gerar Arquivo CSV.
159     */
160    private $_temarquivocsv = false;
161
162
163    /**
164     * Exibir Resultados na tela. (Usado quando somente serï¿œ exibido os resultados em CSV).
165     */
166    private $_exiberesultados = true;
167
168    /**
169     * Gerar Automaticamente Arquivo CSV.
170     */
171    private $_exibearquivocsv = false;
172
173    /**
174     * Colunas Arquivo CSV.
175     */
176    private $_colunasarquivo = array();
177
178    /**
179     * Texto do Arquivo CSV.
180     */
181    private $_txtarquivocsv = "";
182
183
184    /**
185     * Array de Totalizadores.
186     */
187    private $arrtotais = array();
188
189    /**
190     * Array de SubTotalizadores
191     */
192    private $arrsubtotais = array();
193
194
195    /**
196     * Mesagem: Nenhum Resultado Encontrado.
197     */
198    public $msgnenhumresultado = "Nenhum resultado encontrado.";
199
200    /**
201     * Mensagem: registro(s) encontrado(s)
202     */
203    public $msgregistros = "registro(s) encontrado(s).";
204
205    /**
206     * Mensagem: TOTAL:
207     */
208    public $msgtotalizador = "TOTAL:";
209
210    /**
211     * Mensagem: SUB-TOTAL;
212     */
213    public $msgsubtotalizador = "SUB-TOTAL:";
214
215    private $_mostraLegendaTopo = true;
216
217    private $_mostraLegendaRodape = false;
218
219    private $_exibelinhasvazias = true;
220
221    private $_colunascsv;
222
223    private $_isarray = false;
224
225    private $_totalizadorprecisao = 2;
226
227    /*
228     * ID da Listagem. que foi carregado.
229     */
230    private $_lstoid = "";
231
232    private $_url_base_path;
233
234    private $_tmp_file_path = "/tmp/";
235
236
237    /**
238     * Construᅵᅵo da Classe.
239     *
240     * @idlistagem Identificador da Listagem.
241     * @titulo Tï¿œtulo da Listagem.
242     * @conexao Conexï¿œo com o Banco de Dados.
243     * @subListagem Indica se a Listagem ï¿œ uma SubListagem. (default: false)
244     */
245    public function __construct($idlistagem,$titulo,$conexao,$subListagem = false) {
246        $this->setTitulo($titulo);
247        $this->setIdListagem($idlistagem);
248        if (!$subListagem) {
249            $novoidlistagem = $idlistagem . "_sublist";
250            $this->subListagem = new Listagem($novoidlistagem,"",$conexao,true);
251            $this->subListagem->setMostrarQuantidadeRegistros(false);
252            $this->subListagem->setIdListagem($novoidlistagem);
253        }
254        $this->setSubListagem($subListagem);
255        $this->setConexao($conexao);
256    }
257
258    /**
259     * Indica se a Listagem ï¿œ uma SubListagem.
260     *
261     * @param $value (true,false)
262     */
263    protected function setSubListagem($value) {
264        $this->issublist = $value;
265    }
266
267    public function setTotalizadorPrecisao($value) {
268        $this->_totalizadorprecisao = $value;
269    }
270
271    /**
272     * Identificador da Listagem.
273     *
274     * @param $value (true,false)
275     */
276    public function setIdListagem($value) {
277        $this->idlistagem = $value;
278    }
279
280    public function setExibirOpcoesDeColunas($value) {
281        $this->exibedivcolunas = $value;
282    }
283
284    /**
285     * Retorna o Identificador da Listagem.
286     */
287    public function getIdListagem() {
288        return $this->idlistagem;
289    }
290
291    public function setUrlBasePath($base_path) {
292        $this->_url_base_path = $base_path;
293    }
294
295    /**
296     * Funᅵᅵo Interna para Alterar a Varï¿œavel de Conexï¿œo com o Banco de Dados.
297     *
298     * @param $conexao
299     * @return unknown_type
300     */
301    protected function setConexao($conexao) {  $this->conexao = $conexao;  }
302
303    /**
304     * Funᅵᅵo Interna para Alterar O SQL que serï¿œ executado na listagem.
305     *
306     * @param $sql
307     * @return unknown_type
308     */
309    protected function setSQL($sql) {  $this->sql = $sql;  }
310
311    /**
312     * Funᅵᅵo Interna para Recuperar o SQL que serï¿œ executado na listagem.
313     *
314     * @return unknown_type
315     */
316    public function getSQL() {  return $this->sql;  }
317
318    /**
319     * Funᅵᅵo para Alterar o Tï¿œtulo da Listagem.
320     *
321     * @param $titulo
322     * @return unknown_type
323     */
324    public function setTitulo($titulo) {  $this->titulo = $titulo;  }
325
326    /**
327     * Funᅵᅵo para Alterar a forma de Exibiᅵᅵo da Listagem
328     *
329     * @param $exiberesultados
330     * @return unknown_type
331     */
332    public function setExibirResultadosTela($exiberesultados) {  $this->_exiberesultados = $exiberesultados;  }
333
334    /**
335     * Funᅵᅵo para Alterar a exibiᅵᅵo de linhas que nï¿œo exibem nenhum resultado, (linhas vazias)
336     *
337     * @param $exiberesultados
338     * @return unknown_type
339     */
340    public function setExibirLinhasVazias($valor) {  $this->_exibelinhasvazias = $valor;  }
341
342    /**
343     * Funᅵᅵo para Alterar o Resultado da SQL executada.
344     *
345     * @param $dados
346     * @return unknown_type
347     */
348    public function setDados($dados) {
349        $this->dados = &$dados;
350        if (is_resource($this->dados)) {
351            $this->_isarray = false;
352        } else {
353            $this->_isarray = true;
354        }
355    }
356
357
358    /**
359     * Funᅵᅵo utilizada para Executar o SQL e Carregar os dados a serem listados.
360     * @param $sql
361     * @return unknown_type
362     */
363    public function carregar($sql) {
364        $parser = new SqlParser($sql);
365        $ret_parser = $parser->verificaSql();
366
367        if ($ret_parser === false) {
368            $msg = $parser->getErro();
369            $this->adicionarErro($msg,true);
370        }
371
372        $ret_parser = $parser->verificaCondicoes();
373        if ($ret_parser === false) {
374            $msg = $parser->getErro();
375            $this->adicionarErro($msg,true);
376        }
377        $sql = $parser->getSql();
378
379        try {
380                $this->setSQL($sql);
381                $res  = pg_query($this->conexao,"begin;");
382                $resu = pg_query($this->conexao,$this->sql);
383                $res  = pg_query($this->conexao,"rollback;");
384                if (!$resu) { throw new Exception($this->sql); }
385                $this->setDados($resu);
386
387                return $resu;
388
389        } catch (exception $e) {
390             $msg = $e->getMessage();
391             $this->adicionarErro("Erro ao Executar a consulta: $msg",true);
392        }
393
394    }
395
396    /**
397     * Funᅵᅵo utilizada para Executar o SQL e Carregar os dados a serem listados.
398     * @param $sql
399     * @return unknown_type
400     */
401    public function carregarIDListagem($idlistagem,$previsualizacao = false) {
402
403        $sql = "select
404                    lstoid,
405                    lstversao,
406                    lstidlistagem,
407                    lstdescricao,
408                    lstnome,
409                    lsttitulo,
410                    lstsql,
411                    lstexibe_header,
412                    lstexibe_totalizadores,
413                    lstexibe_subtotais,
414                    lstexibe_qtdregistros,
415                    lstexibe_checkbox,
416                    lstexibe_csv,
417                    lstexibe_legendatopo,
418                    lstexibe_legendarodape,
419                    lstexibe_titagrupamento,
420                    lstexibe_agrupamento_alfabetico,
421                    lstagrupamento_campo,
422                    lstagrupamento_titulo,
423                    lstmsg_totalizador,
424                    lstmsg_subtotalizador,
425                    lstmsg_registrosencontrados,
426                    lstmsg_nenhumresultado,
427                    lstexclusao,
428                    lstexibe_resultados
429                from
430                    listagem.listagem
431                where lstidlistagem = '$idlistagem'";
432        $resu = pg_query($this->conexao,$sql);
433
434        $this->setIdListagem($idlistagem);
435
436        $arquivo = $_SERVER['PHP_SELF'];
437
438        if (stristr($arquivo,"cad_listagem.php")) {
439           $arquivo = "null";
440        }
441
442        if (pg_num_rows($resu)) {
443            $dados = pg_fetch_object($resu);
444
445            $lstexclusao = $dados->lstexclusao;
446
447            if (($lstexclusao) && ($arquivo != "null")) {
448                $this->_debug = true;
449                $this->adicionarErro("Esta Consulta estï¿œ inativada, contate o suporte tï¿œcnico de sistemas.",true);
450            }
451
452            $lstoid = $dados->lstoid;
453            $this->_lstoid = $lstoid;
454
455
456        /*    if ($arquivo != "null") {
457                $sql = "select lsdoid from listagem_dependencia where lsdlstoid = '$lstoid' and lsdarquivo ilike '%$arquivo%'";
458                $res_dependencia = pg_query($this->conexao,$sql);
459                $qtd_dependencia = pg_num_rows($res_dependencia);
460
461
462                if ($qtd_dependencia == 0) {
463                        $sql = "insert into listagem_dependencia (lsdlstoid,lsdarquivo,lsdacesso) values ($lstoid,'$arquivo',now())";
464                    $atualiza_dependencia = pg_query($this->conexao,$sql);
465                } else {
466                    $listagem_dependencia = pg_fetch_object($res_dependencia);
467                    $lsdoid = $listagem_dependencia->lsdoid;
468                        $sql = "update listagem_dependencia set lsdacesso = now() where lsdoid = $lsdoid";
469                    $atualiza_dependencia = pg_query($this->conexao,$sql);
470                }
471            }
472            */
473
474
475            $sql = html_entity_decode( $dados->lstsql, ENT_QUOTES);
476
477            $this->sql = $sql;
478
479           // if ($previsualizacao) { $addsql = " limit 20"; }
480
481            $sql_par = "select
482                            lspoid,
483                            lsplstoid,
484                            lspidparametro,
485                            lsptipo,
486                            lspvalor_padrao,
487                            lspobrigatorio
488                        from
489                            listagem.listagem_parametro
490                        where
491                            lsplstoid = $lstoid ";
492            $resu_par = pg_query($this->conexao,$sql_par);
493
494            while ($parametro = pg_fetch_object($resu_par)) {
495                $idparametro = $parametro->lspidparametro;
496                $tipo = $parametro->lsptipo;
497                //$valor = $parametro->lspvalor;
498                $valor = "";
499                $obrigatorio = $parametro->lspobrigatorio;
500                $valor_padrao = $parametro->lspvalor_padrao;
501
502                $this->adicionarParametro($idparametro,$tipo,$obrigatorio,$valor,$valor_padrao);
503
504                if ($previsualizacao) {
505                        $this->setParametro($idparametro,$valor_padrao);
506                }
507            }
508
509            $sql_par = "select
510                            lsioid,
511                            lsilstoid,
512                            lsiidindicador,
513                            lsitipo,
514                            lsiimagem,
515                            lsilegenda,
516                            lsilegenda_csv,
517                            lsicondicao
518                        from
519                            listagem.listagem_indicador
520                        where lsilstoid = $lstoid ";
521            $resu_par = pg_query($this->conexao,$sql_par);
522
523            while ($indicador = pg_fetch_object($resu_par)) {
524                $idindicador = $indicador->lsiidindicador;
525                $tipo        = $indicador->lsitipo;
526                $imagem      = $indicador->lsiimagem;
527                $condicao    = html_entity_decode($indicador->lsicondicao, ENT_QUOTES);
528                $legenda_csv = html_entity_decode($indicador->lsilegenda_csv, ENT_QUOTES);
529                $legenda     = html_entity_decode($indicador->lsilegenda, ENT_QUOTES);
530
531
532                if ($legenda_csv == "") {
533                        $legenda_csv = $legenda;
534                }
535                $this->adicionarIndicador($idindicador,$condicao,$tipo,$imagem,$legenda,$legenda_csv);
536            }
537
538
539            $this->setTitulo($dados->lsttitulo);
540            $this->setMensagemTotalizador($dados->lstmsg_totalizador);
541            $this->setMensagemRegistrosEncontrados($dados->lstmsg_registrosencontrados);
542            $this->setMensagemSubTotalizador($dados->lstmsg_subtotalizador);
543            $this->setMensagemNenhumResultado($dados->lstmsg_nenhumresultado);
544
545            if ($dados->lstagrupamento_campo != "") {
546                if ($dados->lstagrupamento_titulo == "") {
547                        $lstagrupamento_titulo = "{" . $dados->lstagrupamento_campo . "}";
548                } else {
549                        $lstagrupamento_titulo = $dados->lstagrupamento_titulo;
550                }
551                if ($dados->lstexibe_titagrupamento == "t") {
552                    $lstexibe_titagrupamento = true;
553                } else {
554                    $lstexibe_titagrupamento = false;
555                }
556
557
558                if ($dados->lstexibe_agrupamento_alfabetico == "t") {
559                        $lstexibe_agrupamento_alfabetico = true;
560                } else {
561                        $lstexibe_agrupamento_alfabetico = false;
562                }
563                $this->setAgrupamento("{" . $dados->lstagrupamento_campo . "}",$lstagrupamento_titulo,$lstexibe_titagrupamento);
564                $this->setAgruparAlfabeticamente($lstexibe_agrupamento_alfabetico);
565            }
566
567            if ($dados->lstexibe_csv == "f") {
568                $lstexibe_csv = false;
569            } else {
570                $lstexibe_csv = true;
571            }
572            if ($dados->lstexibe_resultados == "f") {
573                $lstexibe_resultados = false;
574            } else {
575                $lstexibe_resultados = true;
576            }
577            if ($dados->lstexibe_totalizadores == "f") {
578                $lstexibe_totalizadores = false;
579            } else {
580                $lstexibe_totalizadores = true;
581            }
582            if ($dados->lstexibe_subtotais == "f") {
583                $lstexibe_subtotais = false;
584            } else {
585                $lstexibe_subtotais = true;
586            }
587            if ($dados->lstexibe_header == "f") {
588                $showthead = false;
589            } else {
590                $showthead = true;
591            }
592            if ($dados->lstexibe_qtdregistros == "f") {
593                $lstexibe_qtdregistros = false;
594            } else {
595                $lstexibe_qtdregistros = true;
596            }
597            if ($dados->lstexibe_legendatopo == "f") {
598                $lstexibe_legendatopo = false;
599            } else {
600                $lstexibe_legendatopo = true;
601            }
602            if ($dados->lstexibe_checkbox == "f") {
603                $lstexibe_checkbox = false;
604            } else {
605                $lstexibe_checkbox = true;
606            }
607            if ($dados->lstexibe_legendarodape == "f") {
608                $lstexibe_legendarodape = false;
609            } else {
610                $lstexibe_legendarodape = true;
611            }
612            $this->_exibearquivocsv = $lstexibe_csv;
613            $this->_mostraLegendaTopo = $lstexibe_legendatopo;
614            $this->_mostraLegendaRodape = $lstexibe_legendarodape;
615            $this->exibesubtotais = $lstexibe_subtotais;
616            $this->_exibeqtdregistros = $lstexibe_qtdregistros;
617            $this->showthead = $showthead;
618            $this->_exibetotalizadores = $lstexibe_totalizadores;
619            $this->_exiberesultados = $lstexibe_resultados;
620
621
622
623            $sql_colunas = "select
624                                lslcoid,
625                                lslclstoid,
626                                lslcidcoluna,
627                                lslcordem,
628                                lslctipo,
629                                lslctitulo,
630                                lslchtml,
631                                lslcalign,
632                                lslcwidth,
633                                lslcnowrap,
634                                lslcvisivel,
635                                lslcexibe_csv,
636                                lslccalculada,
637                                lslccheckbox,
638                                lslclink,
639                                lslclink_condicao,
640                                lslclink_blank,
641                                lslctotalizador_condicao,
642                                lslcsubtotalizador_condicao,
643                                lslccheckbox_condicao
644                            from
645                                listagem.listagem_coluna
646                            where
647                                lslclstoid = $lstoid
648                            order by lslcordem";
649            $resu_colunas = pg_query($this->conexao,$sql_colunas);
650
651            while ($coluna = pg_fetch_object($resu_colunas)) {
652               // print_r($coluna);
653                $idcoluna = $coluna->lslcidcoluna;
654                $tipo = $coluna->lslctipo;
655                $titulo = $coluna->lslctitulo;
656                $html = $coluna->lslchtml;
657                $align = $coluna->lslcalign;
658                $width = $coluna->lslcwidth;
659                $condicao_totalizador = $coluna->lslctotalizador_condicao;
660                $condicao_subtotalizador = $coluna->lslcsubtotalizador_condicao;
661                $link = $coluna->lslclink;
662                $link_condicao = $coluna->lslclink_condicao;
663
664                $idcoluna       =  html_entity_decode($idcoluna, ENT_QUOTES);
665                $titulo         =  html_entity_decode($titulo, ENT_QUOTES);
666                $html           =  html_entity_decode($html, ENT_QUOTES);
667                $link           =  html_entity_decode($link, ENT_QUOTES);
668                $link_condicao  =  html_entity_decode($link_condicao, ENT_QUOTES);
669
670                if ($coluna->lslccalculada == "t") {
671                    $lslccalculada = true;
672                } else {
673                    $lslccalculada = false;
674                }
675                if ($coluna->lslccheckbox == "t") {
676                    $lslccheckbox = true;
677                } else {
678                    $lslccheckbox = false;
679                }
680                if ($coluna->lslcnowrap == "t") {
681                    $lslcnowrap = true;
682                } else {
683                    $lslcnowrap = false;
684                }
685                if ($coluna->lslcvisivel == "t") {
686                    $lslcvisivel = true;
687                } else {
688                    $lslcvisivel = false;
689                }
690                if ($coluna->lslclink_blank == "t") {
691                    $lslclink_blank = true;
692                } else {
693                    $lslclink_blank = false;
694                }
695
696                if ($coluna->lslcexibe_csv == "t") {
697                    $lslcexibe_csv = true;
698                } else {
699                    $lslcexibe_csv = false;
700                }
701
702                if ($lslcexibe_csv) {
703                        $this->_colunascsv .= "$idcoluna,";
704                }
705
706
707                if (($tipo == "text") || ($tipo == "data") || ($tipo == "hora") || ($tipo == "int") || ($tipo == "moeda")) {
708
709                    if (($tipo == "int") && ($lslccheckbox)) {
710                        if ($lstexibe_checkbox) {
711                            $this->adicionarColunaCheckBox($idcoluna,$titulo,$html,$coluna->lslccheckbox_condicao);
712                        }
713                    } else {
714                        //echo "idcoluna: $idcoluna -> $lslcnowrap";
715                        $this->adicionarColuna($idcoluna,$titulo,$html,$tipo,$align,$width,$lslcnowrap,$lslcvisivel);
716                    }
717
718                    if ($link != "") {
719                        $this->adicionarLink($idcoluna,$link,$link_condicao,$lslclink_blank);
720                    }
721
722                    if ($lslccalculada) {
723                        $this->adicionarTotalizador($idcoluna,$condicao_totalizador,$condicao_subtotalizador);
724                    }
725                }
726            }
727
728        } else {
729                $this->_debug = true;
730            $this->adicionarErro("Listagem nï¿œo encontrada.");
731        }
732
733
734    }
735
736    public function getQuantidadeRegistros() {
737        if ($this->_isarray) {
738          $ret = count($this->dados);
739        } else {
740           if (count($this->dados)) {
741                $ret = pg_num_rows($this->dados);
742           } else {
743                $ret = 0;
744           }
745        }
746    //    if ($this->issublist) {
747            if (is_object($this->subListagem)) {
748                $ret = $ret + $this->subListagem->getQuantidadeRegistros();
749            }
750      //  }
751        return $ret;
752    }
753
754    /**
755     * Funᅵᅵo para Alterar a Mensagem de Registros Encontrados.
756     *
757     * @param $msg
758     */
759    public function setMensagemRegistrosEncontrados($msg) { $this->msgregistros = $msg; }
760
761    /**
762     * Funᅵᅵo para Alterar a Mensagem de Total de Registros Encontrados.
763     *
764     * @param $msg
765     */
766    public function setMensagemTotalizador($msg) { $this->msgtotalizador = $msg; }
767
768    /**
769     * Funᅵᅵo para Alterar a Mensagem de Sub-Total de Registros Encontrados
770     *
771     * @param $msg
772     */
773    public function setMensagemSubTotalizador($msg) { $this->msgsubtotalizador = $msg; }
774
775    /**
776     * Funᅵᅵo para Alterar a Mensagem de "Nenhum Resultado Encontrado".
777     *
778     * @param $msg
779     */
780    public function setMensagemNenhumResultado($msg) { $this->msgnenhumresultado = $msg; }
781
782        /**
783         * Funᅵᅵo que Indica se a Listagem ï¿œ Agrupada Alfabeticamente
784         *
785         * @param value (true ou false)
786         */
787    public function setAgruparAlfabeticamente($value) {
788        $this->agruparAlfabeticamente = $value;
789    }
790
791    /**
792     * Funᅵᅵo para Alterar a Opᅵᅵo de Exibir os Sub-Totais de uma Listagem.
793     *
794     * @param $value (true ou false)
795     */
796    public function setMostrarSubTotais($value) {
797        $this->exibesubtotais = $value;
798    }
799
800    public function setMostrarTotal($value) {
801        $this->_exibetotalizadores = $value;
802    }
803
804    public function setMostrarLegendaTopo($value) {
805        $this->_mostraLegendaTopo = $value;
806    }
807
808    public function setMostrarLegendaRodape($value) {
809        $this->_mostraLegendaRodape = $value;
810    }
811
812
813    /**
814     * Funᅵᅵo para Alterar a Opᅵᅵo de Exibir a Quantidade de Registros Retornados da Listagem.
815     *
816     * @param $exibir (true ou false)
817     */
818    public function setMostrarQuantidadeRegistros($exibir) {
819        $this->_exibeqtdregistros = $exibir;
820    }
821
822    /**
823     * Funᅵᅵo para adicionar uma Coluna na Listagem.
824     *
825     * @param $idcoluna
826     * @param $tipo
827     * @param $titulo
828     * @param $html
829     * @param $width
830     * @param $nowrap
831     * @param $valign
832     * @param $visivel
833     * @return unknown_type
834     */
835    function adicionarColuna($idcoluna,$titulo,$html,$tipo = "text",$align = "",$width = "",$nowrap = false,$visivel = true) {
836        $erro = false;
837        if ($this->isColuna($idcoluna)) {
838                $erro = true;
839                $this->adicionarErro("addColuna()<br>$idcoluna jï¿œ foi adicionada na Listagem.");
840        }
841        if (!$erro) {
842                $coluna = new ListagemColuna($idcoluna,$tipo,$titulo,$html,$width,$nowrap,$align);
843                $coluna->setVisibilidade($visivel);
844                $coluna->setIdListagem($this->idlistagem);
845                array_push($this->colunas,$coluna);
846        }
847    }
848
849    function adicionarColunaCalculada($idcoluna,$tipo,$html,$condicao_total = "1",$condicao_subtotal = "1") {
850        $erro = false;
851        if ($this->isColuna($idcoluna)) {
852                $erro = true;
853                $this->adicionarErro("addColuna()<br>$idcoluna jï¿œ foi adicionada na Listagem.");
854        }
855        if (!$erro) {
856                $this->adicionarColuna($idcoluna,$tipo,$idcoluna,$html,"",true,"",false);
857                $this->adicionarTotalizador($idcoluna,$condicao_total,$condicao_subtotal);
858        }
859    }
860
861    function adicionarLinhaDetalhamento($idlinha,$tipo,$html,$align = "left") {
862        $width = "";
863        $nowrap = false;
864        $valign = $align;
865        $coluna = new ListagemColuna($idlinha,$tipo,"",$html,$width,$nowrap,$valign);
866        array_push($this->linhasdetalhamento,$coluna);
867    }
868
869    /**
870     * Funᅵᅵo para Adicionar uma Coluna com CheckBoxes.
871     *
872     * @param $idcoluna
873     * @param $titulo
874     * @param $html
875     * @param $condicao
876     * @param $width
877     * @param $nowrap
878     * @param $valign
879     * @return unknown_type
880     */
881    function adicionarColunaCheckBox($idcoluna,$titulo,$value,$condicao = "",$width = "1%",$nowrap = false,$valign = "center") {
882        $tipo = "check";
883        $html = "{" . $value . "}";
884        $coluna = new ListagemColuna($idcoluna,$tipo,$titulo,$html,$width,$nowrap,$valign);
885        $coluna->setCondicao($condicao);
886        $coluna->setIdListagem($this->idlistagem);
887        array_push($this->colunas,$coluna);
888    }
889
890    /**
891     * Funᅵᅵo utilizada Internamente para verificar se o idcoluna passado jï¿œ foi adicionado a listagem.
892     *
893     * @param $idcoluna
894     * @return unknown_type
895     */
896    protected function isColuna($idcoluna) {
897        $ret = false;
898        foreach ($this->colunas as $i => $col) {
899            if ($col->getIdColuna() == $idcoluna) {
900                $ret = true;
901            }
902        }
903        return $ret;
904    }
905
906    /**
907     * Adiciona um Link para uma ou mais Colunas.
908     *
909     * @param $idcolunas (Ids das colunas separados por vï¿œrgula)
910     * @param $link Link para ser redirecionado.
911     * @param $target
912     * @return unknown_type
913     */
914    public function adicionarLink($idcolunas,$link,$condicao = "1",$targetblank = false,$popup = false) {
915        $colunas = explode(",",$idcolunas);
916        foreach ($colunas as $idcoluna) {
917            $erro = false;
918            if (!$this->isColuna($idcoluna)) {
919                $this->adicionarErro("addLink()<br>$idcoluna nï¿œo ï¿œ uma coluna adicionada na Listagem.",false);
920                $erro = true;
921            }
922            if (!$erro) {
923                foreach ($this->colunas as $i => $col) {
924                    if ($col->getIdColuna() == $idcoluna) {
925                        $this->colunas[$i]->setLink($link,$condicao,$targetblank,$popup);
926                    }
927                }
928            }
929        }
930    }
931
932    public function RemoverColuna($idcolunas){
933        $colunas = explode(",",$idcolunas);
934        foreach ($colunas as $idcoluna) {
935            $erro = false;
936            if (!$this->isColuna($idcoluna)) {
937                $this->adicionarErro("addColunaCor()<br>$idcoluna nï¿œo ï¿œ uma coluna adicionada na Listagem.",false);
938                $erro = true;
939            }
940            if (!$erro) {
941                foreach ($this->colunas as $i => $col) {
942                    if ($col->getIdColuna() == $idcoluna) {
943                        unset($this->colunas[$i]);
944                    }
945                }
946            }
947        }
948    }
949
950
951    public function adicionarCor($idcolunas,$cor,$condicao = "1") {
952        $colunas = explode(",",$idcolunas);
953        $cor = str_replace("#","",$cor);
954        foreach ($colunas as $idcoluna) {
955            $erro = false;
956            if (!$this->isColuna($idcoluna)) {
957                $this->adicionarErro("addColunaCor()<br>$idcoluna nï¿œo ï¿œ uma coluna adicionada na Listagem.",false);
958                $erro = true;
959            }
960            if (!$erro) {
961                foreach ($this->colunas as $i => $col) {
962                    if ($col->getIdColuna() == $idcoluna) {
963                        $this->colunas[$i]->setCor($cor,$condicao);
964                    }
965                }
966            }
967        }
968    }
969
970    /**
971     * Funᅵᅵo para Adicionar um Indicador (Legenda).
972     *
973     * @param $idindicador Cï¿œdigo Interno de Identificaᅵᅵo do Identificador
974     * @param $condicao Condiᅵᅵo em PHP para Exibir o Indicador.
975     * @param $tipo R,Q,T (REDONDO,QUADRADO,TRIANGULO)
976     * @param $codigoimagem (1 a 19).
977     * @param $legenda Legenda
978     * @return unknown_type
979     */
980    function adicionarIndicador($idindicador,$condicao,$tipo = "R",$codigoimagem = "1",$legenda = "",$tamanho = "1") {
981        $Indicador = new ListagemIndicador($idindicador,$condicao,$tipo,$codigoimagem,$legenda,$tamanho);
982        $Indicador->setUrlBasePath($this->_url_base_path);
983        if (!isset($this->arrindicadores[$idindicador])) { $this->arrindicadores[$idindicador] = array(); }
984        array_push($this->arrindicadores[$idindicador],$Indicador);
985    }
986
987    /**
988     * Funᅵᅵo para Desenhar a Listagem.
989     *
990     * @return HTML
991     */
992    function desenhar() {
993        $html = "";
994        $this->incluiCssJavaScript($this->_url_base_path);
995        if ($this->_lstoid != "") {
996            $this->formataSQLParametros();
997            $sql = $this->getSQL();
998            $sql =  html_entity_decode($sql, ENT_QUOTES);
999            $this->carregar($sql);
1000
1001        }
1002
1003        if ($this->_exibearquivocsv) {
1004                $this->gerarArquivoXLS($this->_colunascsv);
1005        }
1006        $this->escreveErros();
1007        $this->escreveAbreList();
1008        $this->escreveLinhas();
1009        $this->escreveFechaList();
1010    }
1011
1012    function incluiCssJavascript($addpath = "") {
1013        echo "\n\n<script language=\"Javascript\" type=\"text/javascript\" src=\"$addpath/includes/js/mascaras.js\"></script>\n
1014<script language=\"Javascript\" type=\"text/javascript\" src=\"$addpath/includes/js/validacoes.js\"></script>\n
1015<script language=\"Javascript\" type=\"text/javascript\" src=\"$addpath/includes/js/auxiliares.js\"></script>\n
1016<script language=\"Javascript\" type=\"text/javascript\" src=\"$addpath/includes/js/calendar.js\"></script>\n
1017<script language=\"Javascript\" type=\"text/javascript\" src=\"$addpath/includes/js/FormularioUtil.js\"></script>\n
1018<link rel=\"stylesheet\" href=\"$addpath/includes/css/base_form.css\" media=\"screen\"></link>\n
1019<link rel=\"stylesheet\" href=\"$addpath/includes/css/calendar.css\" media=\"screen\"></link>\n\n";
1020
1021    }
1022
1023    protected function escreveLegenda() {
1024        if ($this->_exiberesultados) {
1025                if (count($this->arrindicadores)) {
1026                $colspan=0;
1027
1028                echo  "\n\t<table width='100%' class='TableMoldura''>
1029                                   \n\t\t<tr class='tableSubTitulo'>
1030                       \n\t\t\t<td><h3>Legenda</h3></td>
1031                       \n\t\t</tr>";
1032                echo "<tr><td align=left colspan='$colspan'>";
1033                foreach ($this->arrindicadores as $idindicador => $indicadores) {
1034                    $exibelinha = false;
1035                    foreach ($indicadores as $indicador) {
1036                         if ($indicador->getLegenda() != "") {
1037                            $exibelinha = true;
1038                         }
1039                    }
1040                    if ($exibelinha) {
1041                        echo "<br>&nbsp;&nbsp;";
1042                        $addlegenda = "";
1043                        foreach ($indicadores as $indicador) {
1044                            if ($indicador->getLegenda() != "") {
1045                                $addlegenda .= str_replace("{indicador_substituirpasta}","",$indicador->getHtml()) . " " . $indicador->getLegenda() . " | ";
1046                            }
1047                        }
1048                        $addlegenda = substr($addlegenda,0,strlen($addlegenda) - 3);
1049                        echo $addlegenda;
1050                        echo "<br>";
1051                    }
1052                }
1053                echo "<br></td></tr></table>";
1054            }
1055        }
1056    }
1057
1058    /**
1059     * Funᅵᅵo que desenha o cabeï¿œalho da Listagem.
1060     *
1061     * @return HTML
1062     */
1063    protected function escreveAbreList() {
1064        $colspan = count($this->colunas);
1065
1066        $htmldivs = "";
1067        $html_icone = "";
1068
1069        if (!$this->issublist) {
1070                if ($this->_mostraLegendaTopo) {
1071                        $this->escreveLegenda();
1072                }
1073            $addclass= " class='TableMoldura'";
1074
1075            if ($this->_exiberesultados) {
1076
1077                if ($this->exibedivcolunas) {
1078                $html_icone = '<b>[<img id="'. $this->idlistagem . '_img_visivel" src="' . $this->_url_base_path . '/images/icones/maisTransparente.gif" OnClick="ListagemShowHide(event,\''. $this->idlistagem . '\',\''. $this->idlistagem . '_img_visivel\');" OnMouseOver="this.style.cursor=\'pointer\';" OnMouseOut="this.style.cursor=\'default\';">]</b>';
1079                $html_icone_2 = '<b>[<img id="'. $this->idlistagem . '_img_visivel_2" src="' . $this->_url_base_path . '/images/icones/menosTransparente.gif" OnClick="ListagemShowHide(event,\''. $this->idlistagem . '\',\''. $this->idlistagem . '_img_visivel\');" OnMouseOver="this.style.cursor=\'pointer\';" OnMouseOut="this.style.cursor=\'default\';">]</b>';
1080
1081               // $html_icone .= '&nbsp;&nbsp;<b>[<img id="'. $this->idlistagem . '_img_grafico_visivel" src="images/icones/t1/fileGrafico.jpg" OnClick="ListagemShowHide(event,\''. $this->idlistagem . '\',\''. $this->idlistagem . '_img_grafico_visivel\');" OnMouseOver="this.style.cursor=\'pointer\';" OnMouseOut="this.style.cursor=\'default\';">]</b>';
1082
1083                $cnt = 0;
1084                $htmlchecks = "";
1085
1086                foreach ($this->colunas as $coluna) {
1087                        $titulo = $coluna->getNome();
1088                    $idcoluna = $coluna->getIdColuna();
1089                    $idlistagem = $this->idlistagem;
1090                    $visivel = $coluna->getVisibilidade();
1091                    $addvisivel = "";
1092                    if ($visivel) { $addvisivel = "checked"; }
1093
1094                    $adddisabled = "";
1095                    if ($cnt == 0) { $adddisabled = " disabled"; $cnt = $cnt + 1; }
1096
1097                    $htmlchecks .= '<input type="checkbox" class="checkbox" name="' . $idlistagem . '_ck_visivel_' . $idcoluna . '" id="' . $idlistagem . '_ck_visivel_' . $idcoluna . '" OnClick=" document.getElementById(\'' . $idlistagem . '_div_visivel\').style.display = \'none\'; document.getElementById(\'' . $idlistagem . '_div_visivel_load\').style.display = \'\'; alinhaDivDir(\'' .$idlistagem. '_div_visivel_load\'); setTimeout(\'ListagemExibeOcultaColuna(\\\'' . $idlistagem. '\\\',\\\'' .$idcoluna . '\\\');\')" value="' .$idcoluna . '" ' . $addvisivel .$adddisabled . '> ' . $titulo . '<br>';
1098
1099                }
1100
1101
1102                $htmldivs = '<div id="' . $idlistagem. '_div_visivel" class="div_visivel" style="display:none;">
1103                                    <table width="100%">
1104                                        <tr>
1105                                            <td align="right">' .$html_icone_2. '</td>
1106                                        </tr>
1107                                        <tr>
1108                                            <td style="padding-left:5px;">'
1109.$htmlchecks .
1110'
1111
1112                                            </td>
1113                                        </tr>
1114                                    </table>
1115                                </div>
1116                                <div id="' . $idlistagem. '_div_visivel_load" class="div_visivel" style="display:none;">
1117                                    <table width="100%">
1118                                        <tr>
1119                                            <td style="padding-left:5px;">
1120                                                <img src="images/progress4.gif"></img> Carregando...
1121                                            </td>
1122                                        </tr>
1123                                    </table>
1124                                </div>';
1125
1126                   }
1127                }
1128
1129
1130        }
1131
1132        echo  "\n\t$htmldivs<table id='Listagem_" . $this->getIdListagem() . "' width='100%'$addclass>
1133                     \n\t\t<tr class='tableSubTitulo'>
1134                     \n\t\t\t<td  colspan='$colspan'><div style='float: right;'>$html_icone&nbsp;&nbsp;</div><h3>"  . $this->titulo . "</h3></td>
1135                     \n\t\t</tr>";
1136    }
1137
1138    /**
1139     * Funᅵᅵo que desenha o HTML que fecha a listagem.
1140     *
1141     * @return HTML
1142     */
1143    protected function escreveFechaList() {
1144        echo  "\n\t</table>";
1145
1146        if (!$this->issublist) {
1147                if ($this->_mostraLegendaRodape) {
1148                        $this->escreveLegenda();
1149                }
1150        }
1151    }
1152
1153    public function setAgrupamento($idagrupamento,$titulo = "",$repetirtitulo = false) {
1154        $width = "";
1155        $nowrap = false;
1156        $align = "left";
1157        //$html = "{" . $idagrupamento .  "}";
1158        $html = $idagrupamento;
1159        if ($titulo == "") {
1160                $titulo = "{" . $idagrupamento . "}";
1161                $repetirtitulo = true;
1162        }
1163        $this->_repetirtituloagrupamento = $repetirtitulo;
1164        $tipo = "";
1165        $coluna = new ListagemColuna($idagrupamento,$tipo,$titulo,$html,$width,$nowrap,$align);
1166        $this->linhasagrupamento = array();
1167        array_push($this->linhasagrupamento,$coluna);
1168    }
1169
1170    public function setParametro($idparametro,$valor) {
1171        foreach ($this->arrparametros as $k => $parametro) {
1172                if ($parametro['idparametro'] == $idparametro) {
1173                $this->arrparametros[$k]["valor"] = $valor;
1174            }
1175        }
1176    }
1177
1178    public function adicionarParametro($idparametro,$tipo,$obrigatorio = false,$valor = "",$valortestes = "") {
1179        $parametros = array();
1180        $parametros["idparametro"] = $idparametro;
1181        $parametros["tipo"] = $tipo;
1182        $parametros["valor"] = $valor;
1183        $parametros["obrigatorio"] = $obrigatorio;
1184        $parametros["valor_testes"] = $valortestes;
1185
1186        if ($this->_debug) {
1187                if (($tipo != "text") && ($tipo != "int") && ($tipo != "data")) {
1188                        $this->adicionarErro("Parï¿œmetro '$idparametro' do tipo '$tipo' nï¿œo ï¿œ vï¿œlido.");
1189                return false;
1190                }
1191        }
1192
1193        if (!$this->isParametro($idparametro)) {
1194            array_push($this->arrparametros,$parametros);
1195        } else {
1196            if ($this->_debug) {
1197                   $this->adicionarErro("Parï¿œmetro '$idparametro' jï¿œ estï¿œ adicionado a Listagem.");
1198            }
1199        }
1200    }
1201
1202    public function getSQLParametros() {
1203        $sql = $this->sql;
1204        $sqlparametros = array();
1205        $abre_chaves = explode("{",$sql);
1206        foreach ($abre_chaves as $chave) {
1207            $_chaves = array();
1208            if (stristr($chave,"}")) {
1209                $_chaves = explode("}",$chave);
1210                $sqlparametros[] = $_chaves[0];
1211            }
1212        }
1213        return $sqlparametros;
1214    }
1215
1216    protected function formataSQLParametros() {
1217        $sql = $this->sql;
1218
1219        $parametrosconsulta = $this->getSQLParametros();
1220
1221        foreach ($parametrosconsulta as $parametro_consulta) {
1222            $achou = false;
1223            $achou_consulta = false;
1224            foreach ($this->arrparametros as $parametro_base) {
1225                if ($parametro_base["idparametro"] == $parametro_consulta) {
1226                        $achou = true;
1227                }
1228                if (in_array($parametro_base["idparametro"],$parametrosconsulta)) {
1229                    $par_base = $parametro_base["idparametro"];
1230                        $achou_consulta = true;
1231                }
1232            }
1233            if (!$achou) {
1234                $this->_debug=true;
1235                $this->adicionarErro("Parï¿œmetro '$parametro_consulta' usado na consulta nï¿œo foi adicionado no cadastro.",true);
1236            }
1237            if (!$achou_consulta) {
1238                $this->_debug=true;
1239                $this->adicionarErro("Parï¿œmetro '$par_base' cadastrado nï¿œo ï¿œ usado na consulta.",true);
1240            }
1241        }
1242
1243
1244        foreach ($this->arrparametros as $parametro) {
1245            $idparametro = $parametro["idparametro"];
1246            $valor = $parametro["valor"];
1247            $obrigatorio = $parametro["obrigatorio"];
1248            if (($obrigatorio == "t") && ($valor == "")) {
1249                $this->_debug=true;
1250                $this->adicionarErro("Parï¿œmetro '$idparametro ' ï¿œ obrigatï¿œrio.",true);
1251            }
1252            if (($parametro["tipo"] == "data") || ($parametro["tipo"] == "text")) {
1253                $valor = "'" . $valor . "'";
1254            }
1255            if (($obrigatorio == "f") && ($parametro["valor"] == "")) {
1256                $valor = "null";
1257            }
1258                $sql = str_replace("{" . $idparametro. "}",$valor,$sql);
1259        }
1260        $this->sql = $sql;
1261    }
1262
1263    protected function isParametro($idparametro) {
1264        $ret = false;
1265        foreach ($this->arrparametros as $parametro) {
1266            if ($parametro['idparametro'] == $idparametro) {
1267                $ret = true;
1268            }
1269        }
1270        return $ret;
1271    }
1272
1273    protected function isTotalizador($idcoluna) {
1274        $ret = false;
1275        foreach ($this->totalizadores as $totalizador) {
1276            if ($totalizador['idcoluna'] == $idcoluna) {
1277                $ret = true;
1278            }
1279        }
1280        return $ret;
1281    }
1282
1283    function adicionarTotalizador($idcolunas,$condicaototal = "1",$condicaosubtotal = "1") {
1284
1285        $colunas = explode(",",$idcolunas);
1286        foreach ($colunas as $idcoluna) {
1287            $erro = false;
1288            if (!$this->isColuna($idcoluna)) {
1289                $this->adicionarErro("adicionarTotalizador()<br>$idcoluna nï¿œo ï¿œ uma coluna adicionada na Listagem.",false);
1290                $erro = true;
1291            }
1292            if (!$erro) {
1293
1294                $totalizador = array();
1295                $totalizador["idcoluna"] = $idcoluna;
1296                $totalizador["condicaototal"] = $condicaototal;
1297                $totalizador["condicaosubtotal"] = $condicaosubtotal;
1298                $this->totalizadores[$idcoluna] = $totalizador;
1299
1300            }
1301        }
1302
1303    }
1304
1305    protected function escreveArquivo($arquivo) {
1306        if ($this->_temarquivocsv) {
1307                fwrite($arquivo, $this->_txtarquivo);
1308            $this->_txtarquivo = "";
1309        }
1310    }
1311
1312
1313    /**
1314     * Funᅵᅵo para desenhar as Linhas da Listagem.
1315     *
1316     * @return HTML
1317     */
1318    protected function escreveLinhas() {
1319        $html = "";
1320        $colspan = count($this->colunas);
1321        $idtd = 0;
1322        $handle = "";
1323        //$nomeform = $this->formpesquisa->getNome();
1324
1325        if ($this->_temarquivocsv) {
1326            if (!$this->issublist) {
1327                $tmpfname = $this->_tmp_file_path . "Listagem_" . $this->idlistagem . "_" . time() . ".csv";
1328                $handle = fopen($tmpfname, "a+");
1329            }
1330        }
1331
1332        if ($this->showthead) {
1333            if ($this->_exiberesultados) {
1334                echo  "\n\t\t<tr class='tableTituloColunas'>";
1335                foreach ($this->colunas as $col) {
1336                    $fwidth = $col->getWidth(true);
1337                    $addvisivel = "";
1338                    if (!$col->getVisibilidade()) {
1339                        $addvisivel = " style='display: none;' ";
1340                    }
1341                   // if ($col->getVisibilidade()) {
1342                        echo  "\n\t\t\t<td id='td_tit_" . $col->getIdColuna() . "' $fwidth align='center'$addvisivel><h3>". $col->getNome() . "</h3></td>";
1343                   // }
1344                }
1345                echo  "\n\t\t</tr>";
1346            }
1347            if ($this->_temarquivocsv) {
1348                    foreach ($this->_colunasarquivo as $idcoluna) {
1349                           foreach ($this->colunas as $coluna) {
1350                                  if ($coluna->getIdColuna() == $idcoluna) {
1351                                        $this->_txtarquivo .= '"' . $coluna->getNome() . '"' . ";";
1352                                  }
1353                           }
1354                        }
1355                        $this->_txtarquivo .= "\n";
1356                $this->escreveArquivo($handle);
1357
1358            }
1359        }
1360
1361        if (!$this->issublist) {
1362            $cnt = 0;
1363            $this->subListagem->setQuantidadeRegistrosListagemPrincipal($this->getQuantidadeRegistros());
1364        } else {
1365            $cnt = $this->getQuantidadeRegistrosListagemPrincipal();
1366        }
1367        $temcheck = false;
1368        if (count($this->dados)) {
1369
1370            $arrtotais = array();
1371            $arrsubtotais = array();
1372            $arrsubtotais_todos = array();
1373            $lastagrupamento = "";
1374            $cntagrupamentos = 0;
1375            $arragrupamentos = array();
1376            $newagrupamento = "";
1377
1378            $mostroutituloagrupamento = false;
1379
1380            if (!$this->_isarray) {
1381                pg_result_seek($this->dados, 0);
1382            }
1383            $class= "";
1384
1385            $qtdlinhas = 0;
1386
1387            $qtd_registros = $this->getQuantidadeRegistros();
1388
1389
1390            for ($qtd_reg = 1;$qtd_reg <= $qtd_registros; $qtd_reg++) {
1391
1392                if ($this->_isarray) {
1393                    if ($qtd_reg == 1) {
1394                        reset($this->dados);
1395                        $linha = current($this->dados);
1396                    } else {
1397                        $linha = next($this->dados);
1398                    }
1399                } else {
1400                    $linha = pg_fetch_array($this->dados);
1401                }
1402
1403                $cnt = $cnt + 1;
1404
1405                $qtdlinhas = $qtdlinhas + 1;
1406
1407                $class = ( $class == "tdc" ) ? "tde" : "tdc";
1408
1409                if (count($this->linhasagrupamento)) {
1410                    foreach ($this->linhasagrupamento as $coluna) {
1411                        $fwidth = $coluna->getWidth(true);
1412                        $falign = $coluna->getVAlign(true);
1413                        $addnowrap = "";
1414                        $align = $coluna->getAlign();
1415                        if ($coluna->getNowrap()) { $addnowrap = "nowrap"; }
1416                        $htmlcoluna = $coluna->getHtml($linha,$this->arrindicadores,$class,$qtdlinhas - 1);
1417                        if ($coluna->getNome() == "") {
1418                                $tituloagrupamento = $htmlcoluna;
1419                        } else {
1420                                $tituloagrupamento = $coluna->replaceValorLinha($coluna->getNome(),$linha);
1421                        }
1422
1423                        if ($this->agruparAlfabeticamente) {
1424                            $tituloagrupamento = strtoupper(substr($tituloagrupamento,0,1));
1425                            $newagrupamento = $tituloagrupamento;
1426                            $align="center";
1427                        } else {
1428                                $newagrupamento = strtoupper($htmlcoluna);
1429                        }
1430
1431
1432
1433                        //AGRUPAMENTO
1434                        $cntcheckspan = 0;
1435                        if ($newagrupamento != $lastagrupamento) {
1436                            $cntagrupamentos = $cntagrupamentos + 1;
1437
1438                            $arragrupamentos[$cntagrupamentos] = $newagrupamento;
1439
1440                            //TOTALIZADOR SUB-TOTAL DO AGRUPAMENTO.
1441                            if ($this->exibesubtotais) {
1442                                if (count($this->totalizadores)) {
1443                                    if ($cntagrupamentos != 1) {
1444                                        if ($this->_exiberesultados) {
1445                                            echo   "\n\t\t<tr class='tableRodapeModelo2'>";
1446                                        }
1447                                        $mostroutotal = false;
1448                                        foreach ($this->colunas as $coluna) {
1449                                             $idcol = $coluna->getIdColuna();
1450                                             if ($this->isTotalizador($coluna->getIdColuna())) {
1451                                                 if (!$mostroutotal) {
1452                                                     $addtexto = "<h3>" . $this->msgsubtotalizador . "</h3>";
1453                                                     $txtarquivotexto = $this->msgsubtotalizador ;
1454                                                     $mostroutotal = true;
1455                                                 } else {
1456                                                     $addtexto = "";
1457                                                 }
1458                                                 if ($cntcheckspan) {
1459                                                        if ($this->_temarquivocsv) {
1460                                                                for ($j=1; $j<= $cntcheckspan; $j++) {
1461                                                                        if ($j == $cntcheckspan) {
1462                                                                                $this->_txtarquivo .= $txtarquivotexto;
1463                                                                        }
1464                                                                        $this->_txtarquivo .= ";";
1465                                                                }
1466                                                        }
1467                                                 }
1468                                                 $cntcheckspan = 0;
1469                                                 $addvisivel = "";
1470                                                 if (!$coluna->getVisibilidade()) {
1471                                                     $addvisivel = " style='display: none;' ";
1472                                                 }
1473                                                 if ($coluna->getTipo() == "hora") {
1474                                                      $subtotal_valor = $arrsubtotais[$coluna->getIdColuna()];
1475                                                 } else {
1476                                                     if ($this->_totalizadorprecisao != 0) {
1477                                                         $subtotal_valor = number_format($arrsubtotais[$coluna->getIdColuna()],$this->_totalizadorprecisao,",",".");
1478                                                     } else {
1479                                                         $subtotal_valor = $arrsubtotais[$coluna->getIdColuna()];
1480                                                     }
1481                                                 }
1482                                                 if ($this->_exiberesultados) {
1483                                                    echo  "<td  id='subtotal_" . $idcol . "_$cntagrupamentos' align='right'$addvisivel>$addtexto<h3>" . $subtotal_valor . "</h3></td>";
1484                                                 }
1485                                                 $this->_txtarquivo .= $subtotal_valor . ";";
1486                                                 $arrsubtotais[$coluna->getIdColuna()] = 0;
1487                                                 $arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()] = 0;
1488                                             } else {
1489                                                 $addvisivel = "";
1490                                                 if (!$coluna->getVisibilidade()) {
1491                                                    $addvisivel = " style='display: none;' ";
1492                                                 }
1493                                                 if ($this->_exiberesultados) {
1494                                                    echo  "<td id='subtotal_$idcol" . "_" . $cntagrupamentos . "' $addvisivel></td>";
1495                                                 }
1496                                             }
1497                                        }
1498                                       // if ($cntcheckspan) { echo  "<td colspan='$cntcheckspan'>&nbsp;</td>";}
1499                                        if ($this->_exiberesultados) {
1500                                            echo   "\n\t\t</tr>";
1501                                        }
1502                                        if ($this->_temarquivocsv) {
1503                                                $this->_txtarquivo .= "\n";
1504                                            $this->escreveArquivo($handle);
1505                                        }
1506                                    }
1507                                }
1508                            }
1509
1510
1511
1512                            if (($this->_repetirtituloagrupamento) || (!$mostroutituloagrupamento)) {
1513                                if ($this->_exiberesultados) {
1514                                    echo  "\n\t\t<tr>";
1515                                    echo  "\n\t\t\t<td class='tableSubTitulo' colspan='$colspan' align='$align'><h3>" . $tituloagrupamento . "</h3></td>";
1516                                    echo  "\n\t\t</tr>";
1517                                    $class = "tdc";
1518                                }
1519                                    if ($this->_temarquivocsv) {
1520                                        $this->_txtarquivo .= '"' . $tituloagrupamento . '"' . ";\n";
1521                                    }
1522                                    $mostroutituloagrupamento = true;
1523                            }
1524
1525                        }
1526
1527                    }
1528
1529                }
1530
1531
1532                if (count($this->colunas)) {
1533
1534                    $addvisivellinha = "";
1535                    if ($this->_exibelinhasvazias == false) {
1536                        $exibe_linha = false;
1537                        $addvisivellinha = " style='display: none;' ";
1538                        foreach ($this->colunas as $coluna) {
1539                            $htmlcoluna = $coluna->getHtml($linha,$this->arrindicadores,$class,$idtd);
1540                            if (trim($htmlcoluna) != "") {
1541                                $exibe_linha = true;
1542                                $addvisivellinha = "";
1543                            }
1544                        }
1545                    }
1546
1547                    //if ($exibe_linha) {
1548                        if ($this->_exiberesultados) {
1549                            echo  "\n\t\t<tr class='" . $class . "' onmouseout=\"this.className='" . $class . "'\" onmouseover=\"this.className='" . $class . "Over'\" $addvisivellinha>";
1550                        }
1551                        foreach ($this->colunas as $coluna) {
1552                            if ($this->_exiberesultados) {
1553                                $fwidth = $coluna->getWidth(true);
1554                                $falign = $coluna->getVAlign(true);
1555                                $addnowrap = "";
1556                                $align = $coluna->getAlign();
1557                                if ($coluna->getNowrap()) { $addnowrap = " nowrap"; }
1558
1559                                                        if ($this->issublist) {
1560                                                                $idtd = $cnt -2;
1561                                                        } else {
1562                                                                $idtd = $cnt -1;
1563                                                        }
1564                                $htmlcoluna = $coluna->getHtml($linha,$this->arrindicadores,$class,$idtd);
1565
1566                                if (($coluna->getTipo() == "check") && ($htmlcoluna != "")) { $temcheck = true; $this->temcheck = true; }
1567                            }
1568                            if ($this->isTotalizador($coluna->getIdColuna())) {
1569                                $condicaototal = $this->totalizadores[$coluna->getIdColuna()]["condicaototal"];
1570                                $condicaosubtotal = $this->totalizadores[$coluna->getIdColuna()]["condicaosubtotal"];
1571                                $htmlvalorcoluna = $coluna->getValorHTML($linha);
1572                                if ($condicaototal != "1") {
1573                                    $ret_total = $coluna->validaCondicao($condicaototal,$linha,false);
1574                                } else {
1575                                    $ret_total = true;
1576                                }
1577
1578                                if ($ret_total) {
1579                                    $tipo_coluna = $coluna->getTipo();
1580                                    if (isset($arrtotais[$coluna->getIdColuna()])) {
1581                                        if ($tipo_coluna != "hora") {
1582                                            $arrtotais[$coluna->getIdColuna()] += $htmlvalorcoluna;
1583                                        } else {
1584                                            $arrhoras = array($arrtotais[$coluna->getIdColuna()],$htmlvalorcoluna);
1585                                            $arrtotais[$coluna->getIdColuna()] = $this->somaIntervaloHoras($arrhoras);
1586                                        }
1587                                    } else {
1588                                        if ($tipo_coluna != "hora") {
1589                                            $arrtotais[$coluna->getIdColuna()] = 0;
1590                                            $arrtotais[$coluna->getIdColuna()] += $htmlvalorcoluna;
1591                                        } else {
1592                                            $arrtotais[$coluna->getIdColuna()] = "00:00:00";
1593                                            $arrhoras = array($arrtotais[$coluna->getIdColuna()],$htmlvalorcoluna);
1594                                            $arrtotais[$coluna->getIdColuna()] = $this->somaIntervaloHoras($arrhoras);
1595                                        }
1596                                    }
1597                                }
1598                                if ($condicaosubtotal != "1") {
1599                                    $ret_subtotal = $coluna->validaCondicao($condicaosubtotal,$linha,false);
1600                                } else {
1601                                        $ret_subtotal = true;
1602                                }
1603                                if ($ret_subtotal) {
1604                                    $tipo_coluna = $coluna->getTipo();
1605                                    if (isset($arrsubtotais[$coluna->getIdColuna()])) {
1606                                        if ($tipo_coluna != "hora") {
1607                                            $arrsubtotais[$coluna->getIdColuna()] +=  $htmlvalorcoluna;
1608                                        } else {
1609                                            $arrhoras = array($arrsubtotais[$coluna->getIdColuna()],$htmlvalorcoluna);
1610                                            $arrsubtotais[$coluna->getIdColuna()] =  $this->somaIntervaloHoras($arrhoras);
1611                                        }
1612                                    } else {
1613                                        if ($tipo_coluna != "hora") {
1614                                                $arrsubtotais[$coluna->getIdColuna()] = 0;
1615                                            $arrsubtotais[$coluna->getIdColuna()] +=  $htmlvalorcoluna;
1616                                        } else {
1617                                            $arrsubtotais[$coluna->getIdColuna()] = "00:00:00";
1618                                            $arrhoras = array($arrsubtotais[$coluna->getIdColuna()],$htmlvalorcoluna);
1619                                            $arrsubtotais[$coluna->getIdColuna()] =  $this->somaIntervaloHoras($arrhoras);
1620                                        }
1621                                    }
1622                                    if (isset($arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()])) {
1623                                        $arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()] += $htmlvalorcoluna;
1624                                    } else {
1625                                        if ($tipo_coluna != "hora") {
1626                                           $arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()] = 0;
1627                                        } else {
1628                                           $arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()] = "00:00:00";
1629                                        }
1630                                    }
1631                                }
1632                            }
1633                            $addvisivel = "";
1634                            if (!$coluna->getVisibilidade()) {
1635                                $addvisivel = " style='display: none;' ";
1636                            }
1637
1638                            if ($this->_exiberesultados) {
1639                                echo  "\n\t\t\t<td id='td_" . $coluna->getIdColuna() . "_" . $idtd . "' " . $falign . $fwidth .  " align='$align'" . $addnowrap . $addvisivel .  ">" . nl2br($htmlcoluna)  . "</td>";
1640                            }
1641                        }
1642
1643
1644
1645                        //ARQUIVO CSV
1646                        if ($this->_temarquivocsv) {
1647                                foreach ($this->_colunasarquivo as $colunaarq) {
1648                                        foreach ($this->colunas as $coluna) {
1649                                                        if ($coluna->getIdColuna() == $colunaarq) {
1650                                                                $htmlarquivo = $coluna->getTextoArquivo($linha,$this->arrindicadores);
1651                                                                $this->_txtarquivo .= '"' . $htmlarquivo . '"' . ";";
1652                                                        }
1653                                        }
1654                                        }
1655                        }
1656                        if ($this->_exiberesultados) {
1657                            echo  "\n\t\t</tr>";
1658                        }
1659                   // }
1660                } else {
1661                    $this->adicionarErro("Nenhuma coluna foi adicionada.",true);
1662                }
1663
1664
1665                if ($this->_temarquivocsv) {
1666                        $this->_txtarquivo .= "\n";
1667                    $this->escreveArquivo($handle);
1668                }
1669
1670                //LINHA ADICIONAL DE OBSERVAᅵᅵES, (DETALHAMENTO)
1671                if (count($this->linhasdetalhamento)) {
1672                    foreach ($this->linhasdetalhamento as $coluna) {
1673                        $fwidth = $coluna->getWidth(true);
1674                        $falign = $coluna->getVAlign(true);
1675                        $addnowrap = "";
1676                        $align = $coluna->getAlign();
1677                        if ($coluna->getNowrap()) { $addnowrap = " nowrap"; }
1678                        $htmlcoluna = "";
1679                        $htmlcoluna = $coluna->getHtml($linha,$this->arrindicadores,$class,$qtdlinhas - 1);
1680
1681                        if ($this->_exiberesultados) {
1682                            if ($htmlcoluna == "") {
1683                                $addvisivel = " style='display: none;' ";
1684                            }
1685                            echo  "\n\t\t<tr id='tr_" . $coluna->getIdColuna() . "_" . $idtd . "' class='" . $class . "' onmouseout=\"this.className='" . $class . "'\" onmouseover=\"this.className='" . $class . "Over'\"" . $addvisivel. ">";
1686                            echo  "\n\t\t\t<td id='td_" . $coluna->getIdColuna() . "_" . $idtd . "' " . $falign . $fwidth . $addnowrap . " align='$align' colspan='" . count($this->colunas) . "'>" . $htmlcoluna  . "</td>";
1687                            echo  "\n\t\t</tr>";
1688
1689                        }
1690                        if ($this->_temarquivocsv) {
1691                                $htmlarquivo = $coluna->getTextoArquivo($linha,$this->arrindicadores);
1692                                if ($htmlarquivo != "") {
1693                                        $this->_txtarquivo .= $htmlarquivo . ";\n";
1694                                }
1695                            }
1696                    }
1697
1698                }
1699
1700                $lastagrupamento = $newagrupamento;
1701                //$lastval = "";
1702            }
1703        }
1704
1705        $this->escreveArquivo($handle);
1706
1707        if (count($this->totalizadores)) {
1708            if ($this->exibesubtotais) {
1709                if ($this->_exiberesultados) {
1710                    echo   "\n\t\t<tr class='tableRodapeModelo1'>";
1711                }
1712                $mostrousubtotal = false;
1713                $cntcheckspan = 0;
1714                if ($cntagrupamentos != 1) {
1715                    $cntagrupamentos = $cntagrupamentos + 1;
1716                }
1717                foreach ($this->colunas as $coluna) {
1718                     $idcol = $coluna->getIdColuna();
1719                     if ($this->isTotalizador($coluna->getIdColuna())) {
1720
1721                         if (!$mostrousubtotal) {
1722                             $addtexto = "<h3>" . $this->msgsubtotalizador . "</h3>";
1723                             $mostrousubtotal = true;
1724                             $txtarquivotexto = $this->msgsubtotalizador;
1725                         } else {
1726                             $addtexto = "";
1727                         }
1728                         if ($cntcheckspan) {
1729
1730                                if ($this->_temarquivocsv) {
1731                                for ($j=1; $j<= $cntcheckspan; $j++) {
1732                                        if ($j == $cntcheckspan) {
1733                                                $this->_txtarquivo .= $txtarquivotexto;
1734                                        }
1735                                        $this->_txtarquivo .= ";";
1736                                }
1737                                 }
1738                         }
1739                         $cntcheckspan = 0;
1740                         $addvisivel = "";
1741                             if (!$coluna->getVisibilidade()) {
1742                                $addvisivel = " style='display: none;' ";
1743                             }
1744                             if ($coluna->getTipo() == "hora") {
1745                                $subtotal_valor = $arrsubtotais[$coluna->getIdColuna()];
1746                             } else {
1747                                 if ($this->_totalizadorprecisao != 0) {
1748                                    $subtotal_valor = number_format($arrsubtotais[$coluna->getIdColuna()],$this->_totalizadorprecisao,",",".");
1749                                 } else {
1750                                    $subtotal_valor = $arrsubtotais[$coluna->getIdColuna()];
1751                                 }
1752                             }
1753                             if ($this->_exiberesultados) {
1754                                   echo  "<td id='subtotal_$idcol" . "_" . $cntagrupamentos . "' align='right'$addvisivel>$addtexto&nbsp;<h3>" . $subtotal_valor . "</h3></td>";
1755                             }
1756                             if (in_array($idcol,$this->_colunasarquivo)) {
1757                                   $this->_txtarquivo .= $subtotal_valor . ";";
1758                             }
1759                     } else {
1760                         $addvisivel = "";
1761                         if (!$coluna->getVisibilidade()) {
1762                            $addvisivel = " style='display: none;' ";
1763                         }
1764                         if ($this->_exiberesultados) {
1765                            echo  "<td id='subtotal_$idcol" . "_" . $cntagrupamentos . "' $addvisivel></td>";
1766                         }
1767                         if ($this->_temarquivocsv) {
1768                            if (in_array($idcol,$this->_colunasarquivo)) {
1769                                $this->_txtarquivo .= ";";
1770                            }
1771                         }
1772                     }
1773                }
1774                if ($this->_exiberesultados) {
1775                    echo   "\n\t\t</tr>";
1776                }
1777                if ($this->_temarquivocsv) {
1778                        $this->_txtarquivo .= "\n";
1779                }
1780            }
1781
1782
1783
1784            if ($this->_exibetotalizadores) {
1785                if ($this->_exiberesultados) {
1786                    echo   "\n\t\t<tr class='tableRodapeModelo2'>";
1787                }
1788                $mostroutotal = false;
1789                $cntcheckspan = 0;
1790                foreach ($this->colunas as $coluna) {
1791
1792
1793                     $idcol = $coluna->getIdColuna();
1794                     if ($this->isTotalizador($coluna->getIdColuna())) {
1795                         if (!$mostroutotal) {
1796                             $addtexto = "<h3>" . $this->msgtotalizador .  "</h3>";
1797                             $mostroutotal = true;
1798                             $txtarquivotexto = $this->msgtotalizador;
1799                         } else {
1800                             $addtexto = "";
1801                         }
1802
1803                         if ($cntcheckspan) {
1804                            if ($this->_temarquivocsv) {
1805                                for ($j=1; $j<= $cntcheckspan; $j++) {
1806                                    if ($j == $cntcheckspan) {
1807                                        $this->_txtarquivo .= $txtarquivotexto;
1808                                    }
1809                                    $this->_txtarquivo .= ";";
1810                                }
1811                            }
1812                         }
1813                         $cntcheckspan = 0;
1814                         $addvisivel = "";
1815                         if (!$coluna->getVisibilidade()) {
1816                            $addvisivel = " style='display: none;' ";
1817                         }
1818                         if ($coluna->getTipo() == "hora") {
1819                            $total_valor = $arrtotais[$coluna->getIdColuna()];
1820                         } else {
1821                             if ($this->_totalizadorprecisao != 0) {
1822                                $total_valor = number_format($arrtotais[$coluna->getIdColuna()],$this->_totalizadorprecisao,",",".");
1823                             } else {
1824                                $total_valor = $arrtotais[$coluna->getIdColuna()];
1825                             }
1826                         }
1827                         if ($this->_exiberesultados) {
1828                            echo  "<td id='total_$idcol' align='right'$addvisivel>$addtexto&nbsp;<h3>" . $total_valor . "</h3></td>";
1829                         }
1830                         if ($this->_temarquivocsv) {
1831                            if (in_array($idcol,$this->_colunasarquivo)) {
1832                                $this->_txtarquivo .= $total_valor . ";";
1833                            }
1834                         }
1835                     } else {
1836                         $addvisivel = "";
1837                         if (!$coluna->getVisibilidade()) {
1838                            $addvisivel = " style='display: none;' ";
1839                         }
1840                         if ($this->_exiberesultados) {
1841                            echo  "<td id='total_$idcol' $addvisivel>&nbsp;</td>";
1842                         }
1843                         if ($this->_temarquivocsv) {
1844                            if (in_array($idcol,$this->_colunasarquivo)) {
1845                                $this->_txtarquivo .= ";";
1846                            }
1847                         }
1848                     }
1849                }
1850                if ($this->_exiberesultados) {
1851                    echo   "\n\t\t</tr>";
1852                }
1853                if ($this->_temarquivocsv) {
1854                    $this->_txtarquivo .= "\n";
1855                }
1856            }
1857        }
1858
1859        $this->escreveArquivo($handle);
1860
1861
1862        if (!$this->issublist) {
1863            if (is_object($this->subListagem)) {
1864                if ($this->subListagem->getQuantidadeRegistros()) {
1865                        $this->subListagem->gerarArquivoXLS();
1866                    ob_start();
1867                    $this->subListagem->desenhar();
1868                    $htmllist = ob_get_contents();
1869                    ob_end_clean();
1870                    if ($this->_temarquivocsv) {
1871                        $this->_txtarquivo .= $this->subListagem->getTextoArquivoCSV();
1872                    }
1873                    if ($this->_exiberesultados) {
1874                        echo  "<tr><td colspan='$colspan'>";
1875                        echo  $htmllist;
1876                        echo  "</td></tr>";
1877                    }
1878                    if ($this->subListagem->getTemCheckBox()) {
1879                        $temcheck = true;
1880                        $this->temcheck = true;
1881                    }
1882                }
1883            }
1884        }
1885
1886        $this->escreveArquivo($handle);
1887
1888
1889   /*
1890       EXIBIR OS BOTï¿œES DE + E - PARA QUANDO POSSUIR COLUNAS COM CHECKBOXES. COMENTADO POR QUE Nï¿œO FUNCIONA SE TIVER MAIS DE UM FORMULï¿œRIO NA MESMA JANELA. */
1891        if (!$this->issublist) {
1892            if ($temcheck) {
1893                if (count($this->colunas)) {
1894                    echo   "\n\t\t<tr class='tableRodapeModelo3'>";
1895                    $cntcheckspan = 0;
1896                    $qtd = $this->getQuantidadeRegistros();
1897                    foreach ($this->colunas as $coluna) {
1898                        if ($coluna->getTipo() == "check") {
1899                            if ($cntcheckspan) { echo  "<td colspan='$cntcheckspan'>&nbsp;</td>";}
1900                            $cntcheckspan = 0;
1901                            $idlistagem = $this->getIdListagem();
1902                            echo  "\n\t\t\t<td align=center nowrap>&nbsp;";
1903                            echo  "<input type='button' class='botao' name='btselecionar' onclick=\"ListagemSelecionachecks(1,'" . $qtd. "','" . $coluna->getIdColuna() . "_" . $idlistagem . "_');\" value='&nbsp;+&nbsp;'>&nbsp;";
1904                            echo  "<input type='button' class='botao' name='btdesselecionar' onclick=\"ListagemSelecionachecks(0,'" . $qtd. "','" . $coluna->getIdColuna() . "_" . $idlistagem . "_');\" value='&nbsp;-&nbsp;'>&nbsp;";
1905                            echo  "\n\t\t\t</td>";
1906                        } else {
1907                            $cntcheckspan = $cntcheckspan + 1;
1908                        }
1909                    }
1910                    if ($cntcheckspan) { echo  "<td colspan='$cntcheckspan'>&nbsp;</td>";}
1911                    echo   "\n\t\t</tr>";
1912                }
1913            }
1914        }
1915
1916
1917
1918        if ($this->_exibeqtdregistros) {
1919            if ($this->_exiberesultados) {
1920                echo   "\n\t\t<tr class='tableRodapeModelo3'>\n\t\t\t<td colspan='$colspan' align=center>";
1921            }
1922            $qtd = $this->getQuantidadeRegistros();
1923            if ($cnt == 0) {
1924                if ($this->_exiberesultados) {
1925                    echo   $this->msgnenhumresultado;
1926                }
1927            }  else {
1928                if ($this->_exiberesultados) {
1929                echo   "<b>$qtd</b> " . $this->msgregistros;
1930                }
1931                if ($this->_temarquivocsv) {
1932                        $this->_txtarquivo .= $qtd . " " . $this->msgregistros;
1933                }
1934            }
1935            if ($this->_exiberesultados) {
1936                echo   "</td>\n\t\t</tr>";
1937            }
1938
1939        }
1940
1941        $this->escreveArquivo($handle);
1942
1943
1944        if ($this->_temarquivocsv) {
1945                if (!$this->issublist) {
1946
1947
1948                        fclose($handle);
1949
1950                        $link=$tmpfname;
1951
1952                        if ($cnt != 0) {
1953                                echo   "\n\t\t<tr class='tableRodapeModelo3'>\n\t\t\t<td colspan='$colspan' align=center>";
1954                                //echo   '<input type="button" name="btn_arquivoxls" value="Versï¿œo em XLS" class="botao" onclick="window.open(\'gera_csv_to_excel.php?arquivocsv=/' . $link . '\');" style="width: 90px;">';
1955                    echo   '&nbsp;<input type="button" name="btn_arquivoxls" value="Download CSV" class="botao" onclick="window.open(\'' . $this->_url_base_path . '/downloads.php?arquivo=' . $link . '\');" style="width:120px;">';
1956                                echo   "</td>\n\t\t</tr>";
1957                        } else {
1958                                if ($this->_exibeqtdregistros) {
1959                                        echo   "\n\t\t<tr class='tableRodapeModelo3'>\n\t\t\t<td colspan='$colspan' align=center>";
1960                                        echo   $this->msgnenhumresultado;
1961                                        echo   "</td>\n\t\t</tr>";
1962                                }
1963                        }
1964                }
1965            /*  //FORMULï¿œRIO
1966                $this->form->addButton("btn_arquivo","Arquivo .XLS");
1967                        $this->form->addCampoAcao("btn_arquivo","onclick","window.open('gera_csv_to_excel.php?arquivocsv=" . $link . "');");
1968                        $this->form->addQuadro("quadro_arquivo");
1969                        $this->form->addQuadroButton("quadro_arquivo","btn_arquivo");
1970             */
1971        }
1972
1973        /*
1974          FORMULï¿œRIO
1975        if (!$this->issublist) {
1976            if ($cnt != 0) {
1977                if (($temcheck) || ($this->_temarquivocsv)) {
1978                    echo "\n\t\t<tr>\n\t\t\t<td colspan='$colspan' align=center style='padding: 0px;'>";
1979                    ob_start();
1980                    $this->form->desenhaCampos();
1981                    $this->form->displayErros();
1982                    $htmlform = ob_get_contents();
1983
1984                    ob_end_clean();
1985                    echo  $htmlform;
1986                }
1987            }
1988            echo   "</td>\n\t\t</tr>";
1989            ob_start();
1990            $this->form->fechaForm();
1991            $htmlform = ob_get_contents();
1992            ob_end_clean();
1993        } */
1994        //echo  $htmlform;
1995
1996        $this->arrtotais = $arrtotais;
1997        $this->arrsubtotais = $arrsubtotais_todos;
1998        $this->arragrupamentos = $arragrupamentos;
1999
2000
2001    }
2002
2003    public function setDebug($value) {
2004        $this->_debug = $value;
2005    }
2006
2007    /**
2008     * Funᅵᅵo usada internamente para adicionar um erro ao formulï¿œrio.
2009     *
2010     * @param string $msgerro Mensagem de Erro
2011     * @param boolean $fatal Se ï¿œ um erro Fatal = true ()
2012     * */
2013    protected function adicionarErro($msgerro,$fatal = false) {
2014        if ($fatal) { $this->_errors = array(); }
2015        $erro = array("msgerro" => $msgerro,"fatal" => $fatal);
2016        array_push($this->_errors,$erro);
2017
2018        if ($fatal) {
2019            $this->escreveErros();
2020            exit;
2021        }
2022
2023    }
2024
2025
2026    /**
2027     * Funᅵᅵo usada para exibir os erros.
2028     *
2029     * */
2030    protected function escreveErros() {
2031        if ($this->_debug) {
2032            if (count($this->_errors)) {
2033                echo "<style type='text/css'>
2034                         #erros { background: #BAD0E5; color: #000000; font-size: 12px; Verdana,Arial,Helvetica,sans-serif; font-weight: bold; margin: 15px; padding: 0px; padding-top: 3px; padding-bottom: 3px;  text-align: left; } " .
2035                        " .erro { background: #E6EAEE; color: #000000; font-size: 12px; Verdana,Arial,Helvetica,sans-serif; font-weight: bold; margin: 2px; padding: 5px; text-align: left; }" .
2036                        "</style>";
2037                echo "<div id='erros'>";
2038                foreach ($this->_errors as $erro) {
2039                    echo "<div class=erro>";
2040
2041                    if ($erro["fatal"]) {
2042                        $addmsg = "<span style='color: #990000;'><b>ERRO:</b></span> ";
2043                    } else {
2044                        $addmsg = "ERRO: ";
2045                    }
2046                    echo $addmsg . $erro["msgerro"];
2047                    echo "</div>";
2048                }
2049                echo "</div>";
2050            }
2051        } else {
2052            echo "MODO DEBUG ESTï¿œ DESATIVADO.";
2053        }
2054    }
2055
2056    public function gerarArquivoXLS($colunasarquivo = "") {
2057        if ($colunasarquivo == "") {
2058                $arcolunas = array();
2059                foreach ($this->colunas as $coluna) {
2060                        if ($coluna->getVisibilidade()) {
2061                          $colunasarquivo .= $coluna->getIdColuna() . ",";
2062                        }
2063                }
2064                $colunasarquivo = substr($colunasarquivo,0,strlen($colunasarquivo)-1);
2065        }
2066        $arcolunas = explode(",",$colunasarquivo);
2067        $txtarquivo = "";
2068        $this->_colunasarquivo = $arcolunas;
2069                $this->_temarquivocsv = true;
2070    }
2071
2072    /*
2073     * Funᅵᅵo utilizada pra somar intervalos de Horas */
2074    public function somaIntervaloHoras($arrValores){
2075
2076        // Somando separadamente os valores
2077        foreach($arrValores as $valor){
2078
2079            $arrTmp = explode(':',$valor);
2080
2081            $seg += $arrTmp[2];
2082            $min += $arrTmp[1];
2083            $hor += $arrTmp[0];
2084        }
2085
2086        // Tratando os segundos
2087        if( $seg >= 60){
2088
2089            $min += floor($seg / 60) ;
2090
2091            while($seg >= 60){
2092
2093                $seg = $seg - 60;
2094            }
2095
2096        }
2097        // Tratando os minutos
2098        if( $min >= 60){
2099
2100            $hor += floor($min / 60) ;
2101
2102            while($min >= 60){
2103
2104                $min = $min - 60;
2105            }
2106
2107        }
2108
2109        return str_pad($hor,2,'0',STR_PAD_LEFT).':'.str_pad($min,2,'0',STR_PAD_LEFT).':'.str_pad($seg,2,'0',STR_PAD_LEFT);
2110    }
2111
2112    /**
2113     * Funᅵᅵo que Retorna se a listagem Possui um checkBox adicionado.
2114     */
2115    public function getTemCheckBox() {
2116        return $this->temcheck;
2117    }
2118
2119    /**
2120     * Funᅵᅵo que retorna o array com os Totalizadores.
2121     */
2122    public function getTotais() {
2123        return $this->arrtotais;
2124    }
2125
2126    /**
2127     * Funᅵᅵo que Retorna o array com os Sub-Totalizadores.
2128     */
2129    public function getSubTotais() {
2130        return $this->arrsubtotais;
2131    }
2132
2133    /**
2134     * Funᅵᅵo que Retorna o array com os Sub-Totalizadores.
2135     */
2136    public function getAgrupamentos() {
2137        return $this->arragrupamentos;
2138    }
2139
2140    /**
2141     * Funᅵᅵo Interna Utilizada quando a Listagem possui uma sublistagem para guardar quantos registros a listagem principal tem.
2142     */
2143    protected function setQuantidadeRegistrosListagemPrincipal($value) {
2144        $this->_qtdregistroslistagemprincipal = $value;
2145    }
2146
2147    /**
2148     * Funᅵᅵo Interna Utilizada quando a Listagem possui uma sublistagem para retornar quantos registros a listagem principal tem.
2149     */
2150    protected function getQuantidadeRegistrosListagemPrincipal() {
2151        return $this->_qtdregistroslistagemprincipal;
2152    }
2153
2154    protected function getTextoArquivoCSV() {
2155        return $this->_txtarquivo;
2156    }
2157
2158    public function autoAdicionarColunas() {
2159        $i = pg_num_fields($this->dados);
2160        for ($j = 0; $j < $i; $j++) {
2161            $fieldname = pg_field_name($this->dados, $j);
2162            $tipo = pg_field_type($this->dados, $j);
2163            $this->adicionarColuna("coluna_" .$j,"$fieldname","{" . $fieldname . "}","text","left");
2164        }
2165    }
2166}
2167?>
Note: See TracBrowser for help on using the repository browser.