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

Revision 5307, 84.1 KB checked in by pereira.jair, 12 years ago (diff)

Ticket #2416 - Inclusao da nova ferramenta de relatorios 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                                                   /* for ($j=1; $j< $cntcheckspan; $j++) {
1460                                                         echo  "<td id='subtotal_" . $idcol . "_$cntagrupamentos' align='right'>&nbsp;</td>";
1461                                                    }*/
1462                                                   
1463                                                   // echo  "<td id='subtotal_" . $idcol . "_" . $cntagrupamentos . "' align='right'>&nbsp;</td>";
1464                                                        if ($this->_temarquivocsv) {
1465                                                                for ($j=1; $j<= $cntcheckspan; $j++) {
1466                                                                        if ($j == $cntcheckspan) {
1467                                                                                $this->_txtarquivo .= $txtarquivotexto;
1468                                                                        }
1469                                                                        $this->_txtarquivo .= ";";
1470                                                                }
1471                                                        }
1472                                                 }
1473                                                 $cntcheckspan = 0;
1474                                                 $addvisivel = "";
1475                                                 if (!$coluna->getVisibilidade()) {
1476                                                     $addvisivel = " style='display: none;' ";
1477                                                 }
1478                                                 if ($coluna->getTipo() == "hora") {
1479                                                      $subtotal_valor = $arrsubtotais[$coluna->getIdColuna()];
1480                                                 } else {
1481                                                     if ($this->_totalizadorprecisao != 0) {
1482                                                         $subtotal_valor = number_format($arrsubtotais[$coluna->getIdColuna()],$this->_totalizadorprecisao,",",".");
1483                                                     } else {
1484                                                         $subtotal_valor = $arrsubtotais[$coluna->getIdColuna()];
1485                                                     }
1486                                                 }
1487                                                 if ($this->_exiberesultados) {
1488                                                    echo  "<td  id='subtotal_" . $idcol . "_$cntagrupamentos' align='right'$addvisivel>$addtexto<h3>" . $subtotal_valor . "</h3>&nbsp;</td>";
1489                                                 }
1490                                                 $this->_txtarquivo .= $subtotal_valor . ";";
1491                                                 $arrsubtotais[$coluna->getIdColuna()] = 0;
1492                                                 $arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()] = 0;
1493                                             } else {
1494                                                 $addvisivel = "";
1495                                                 if (!$coluna->getVisibilidade()) {
1496                                                    $addvisivel = " style='display: none;' ";
1497                                                 }
1498                                                 if ($this->_exiberesultados) {
1499                                                    echo  "<td id='subtotal_$idcol" . "_" . $cntagrupamentos . "' $addvisivel>&nbsp;</td>";
1500                                                 }
1501                                             }
1502                                        }
1503                                       // if ($cntcheckspan) { echo  "<td colspan='$cntcheckspan'>&nbsp;</td>";}
1504                                        if ($this->_exiberesultados) {
1505                                            echo   "\n\t\t</tr>";
1506                                        }
1507                                        if ($this->_temarquivocsv) {
1508                                                $this->_txtarquivo .= "\n";
1509                                            $this->escreveArquivo($handle);
1510                                        }
1511                                    }
1512                                }
1513                            }
1514                           
1515                           
1516                           
1517                            if (($this->_repetirtituloagrupamento) || (!$mostroutituloagrupamento)) {
1518                                if ($this->_exiberesultados) {
1519                                    echo  "\n\t\t<tr>";
1520                                    echo  "\n\t\t\t<td class='tableSubTitulo' colspan='$colspan' align='$align'><h3>" . $tituloagrupamento . "</h3></td>";
1521                                    echo  "\n\t\t</tr>";
1522                                    $class = "tdc";
1523                                }
1524                                    if ($this->_temarquivocsv) {
1525                                        $this->_txtarquivo .= '"' . $tituloagrupamento . '"' . ";\n";
1526                                    }
1527                                    $mostroutituloagrupamento = true;
1528                            }
1529                           
1530                        }
1531                       
1532                    }
1533                   
1534                }
1535               
1536               
1537                if (count($this->colunas)) {
1538                   
1539                    $addvisivellinha = "";
1540                    if ($this->_exibelinhasvazias == false) {
1541                        $exibe_linha = false;
1542                        $addvisivellinha = " style='display: none;' ";
1543                        foreach ($this->colunas as $coluna) {
1544                            $htmlcoluna = $coluna->getHtml($linha,$this->arrindicadores,$class,$idtd);
1545                            if (trim($htmlcoluna) != "") {
1546                                $exibe_linha = true;
1547                                $addvisivellinha = "";
1548                            }
1549                        }
1550                    }
1551                   
1552                    //if ($exibe_linha) {
1553                        if ($this->_exiberesultados) {
1554                            echo  "\n\t\t<tr class='" . $class . "' onmouseout=\"this.className='" . $class . "'\" onmouseover=\"this.className='" . $class . "Over'\" $addvisivellinha>";
1555                        }
1556                        foreach ($this->colunas as $coluna) {
1557                            if ($this->_exiberesultados) {
1558                                $fwidth = $coluna->getWidth(true);
1559                                $falign = $coluna->getVAlign(true);
1560                                $addnowrap = "";
1561                                $align = $coluna->getAlign();
1562                                if ($coluna->getNowrap()) { $addnowrap = " nowrap"; }
1563       
1564                                                        if ($this->issublist) {
1565                                                                $idtd = $cnt -2;
1566                                                        } else {
1567                                                                $idtd = $cnt -1;
1568                                                        }
1569                                $htmlcoluna = $coluna->getHtml($linha,$this->arrindicadores,$class,$idtd);
1570                               
1571                                if (($coluna->getTipo() == "check") && ($htmlcoluna != "")) { $temcheck = true; $this->temcheck = true; }
1572                            }
1573                            if ($this->isTotalizador($coluna->getIdColuna())) {
1574                                $condicaototal = $this->totalizadores[$coluna->getIdColuna()]["condicaototal"];
1575                                $condicaosubtotal = $this->totalizadores[$coluna->getIdColuna()]["condicaosubtotal"];
1576                                $htmlvalorcoluna = $coluna->getValorHTML($linha);
1577                                if ($condicaototal != "1") {
1578                                    $ret_total = $coluna->validaCondicao($condicaototal,$linha,false);
1579                                } else {
1580                                    $ret_total = true;
1581                                }
1582                               
1583                                if ($ret_total) {
1584                                    $tipo_coluna = $coluna->getTipo();
1585                                    if (isset($arrtotais[$coluna->getIdColuna()])) {
1586                                        if ($tipo_coluna != "hora") {
1587                                            $arrtotais[$coluna->getIdColuna()] += $htmlvalorcoluna;
1588                                        } else {
1589                                            $arrhoras = array($arrtotais[$coluna->getIdColuna()],$htmlvalorcoluna);
1590                                            $arrtotais[$coluna->getIdColuna()] = $this->somaIntervaloHoras($arrhoras);
1591                                        }
1592                                    } else {
1593                                        if ($tipo_coluna != "hora") {
1594                                            $arrtotais[$coluna->getIdColuna()] = 0;
1595                                            $arrtotais[$coluna->getIdColuna()] += $htmlvalorcoluna;
1596                                        } else {
1597                                            $arrtotais[$coluna->getIdColuna()] = "00:00:00";
1598                                            $arrhoras = array($arrtotais[$coluna->getIdColuna()],$htmlvalorcoluna);
1599                                            $arrtotais[$coluna->getIdColuna()] = $this->somaIntervaloHoras($arrhoras);
1600                                        }
1601                                    }
1602                                }
1603                                if ($condicaosubtotal != "1") {
1604                                    $ret_subtotal = $coluna->validaCondicao($condicaosubtotal,$linha,false);
1605                                } else {
1606                                        $ret_subtotal = true;
1607                                }
1608                                if ($ret_subtotal) {
1609                                    $tipo_coluna = $coluna->getTipo();
1610                                    if (isset($arrsubtotais[$coluna->getIdColuna()])) {
1611                                        if ($tipo_coluna != "hora") {
1612                                            $arrsubtotais[$coluna->getIdColuna()] +=  $htmlvalorcoluna;
1613                                        } else {
1614                                            $arrhoras = array($arrsubtotais[$coluna->getIdColuna()],$htmlvalorcoluna);
1615                                            $arrsubtotais[$coluna->getIdColuna()] =  $this->somaIntervaloHoras($arrhoras);
1616                                        }
1617                                    } else {
1618                                        if ($tipo_coluna != "hora") {
1619                                                $arrsubtotais[$coluna->getIdColuna()] = 0;
1620                                            $arrsubtotais[$coluna->getIdColuna()] +=  $htmlvalorcoluna;
1621                                        } else {
1622                                            $arrsubtotais[$coluna->getIdColuna()] = "00:00:00";
1623                                            $arrhoras = array($arrsubtotais[$coluna->getIdColuna()],$htmlvalorcoluna);
1624                                            $arrsubtotais[$coluna->getIdColuna()] =  $this->somaIntervaloHoras($arrhoras);
1625                                        }
1626                                    }
1627                                    if (isset($arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()])) {
1628                                        $arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()] += $htmlvalorcoluna;
1629                                    } else {
1630                                        if ($tipo_coluna != "hora") {
1631                                           $arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()] = 0;
1632                                        } else {
1633                                           $arrsubtotais_todos[$cntagrupamentos][$coluna->getIdColuna()] = "00:00:00";
1634                                        }
1635                                    }
1636                                }
1637                            }
1638                            $addvisivel = "";
1639                            if (!$coluna->getVisibilidade()) {
1640                                $addvisivel = " style='display: none;' ";
1641                            }
1642                           
1643                            if ($this->_exiberesultados) {
1644                                echo  "\n\t\t\t<td id='td_" . $coluna->getIdColuna() . "_" . $idtd . "' " . $falign . $fwidth .  " align='$align'" . $addnowrap . $addvisivel .  ">" . nl2br($htmlcoluna)  . "</td>";
1645                            }
1646                        }
1647                       
1648                       
1649   
1650                        //ARQUIVO CSV
1651                        if ($this->_temarquivocsv) {
1652                                foreach ($this->_colunasarquivo as $colunaarq) {
1653                                        foreach ($this->colunas as $coluna) {
1654                                                        if ($coluna->getIdColuna() == $colunaarq) {
1655                                                                $htmlarquivo = $coluna->getTextoArquivo($linha,$this->arrindicadores);
1656                                                                $this->_txtarquivo .= '"' . $htmlarquivo . '"' . ";";
1657                                                        }
1658                                        }
1659                                        }
1660                        }
1661                        if ($this->_exiberesultados) {
1662                            echo  "\n\t\t</tr>";
1663                        }
1664                   // }
1665                } else {
1666                    $this->adicionarErro("Nenhuma coluna foi adicionada.",true);
1667                }
1668               
1669                               
1670                if ($this->_temarquivocsv) {
1671                        $this->_txtarquivo .= "\n";
1672                    $this->escreveArquivo($handle);
1673                }
1674               
1675                //LINHA ADICIONAL DE OBSERVAᅵᅵES, (DETALHAMENTO)
1676                if (count($this->linhasdetalhamento)) {
1677                    foreach ($this->linhasdetalhamento as $coluna) {
1678                        $fwidth = $coluna->getWidth(true);
1679                        $falign = $coluna->getVAlign(true);
1680                        $addnowrap = "";
1681                        $align = $coluna->getAlign();
1682                        if ($coluna->getNowrap()) { $addnowrap = " nowrap"; }
1683                        $htmlcoluna = "";
1684                        $htmlcoluna = $coluna->getHtml($linha,$this->arrindicadores,$class,$qtdlinhas - 1);
1685                       
1686                        if ($this->_exiberesultados) {
1687                            if ($htmlcoluna == "") {
1688                                $addvisivel = " style='display: none;' ";
1689                            }
1690                            echo  "\n\t\t<tr id='tr_" . $coluna->getIdColuna() . "_" . $idtd . "' class='" . $class . "' onmouseout=\"this.className='" . $class . "'\" onmouseover=\"this.className='" . $class . "Over'\"" . $addvisivel. ">";
1691                            echo  "\n\t\t\t<td id='td_" . $coluna->getIdColuna() . "_" . $idtd . "' " . $falign . $fwidth . $addnowrap . " align='$align' colspan='" . count($this->colunas) . "'>" . $htmlcoluna  . "</td>";
1692                            echo  "\n\t\t</tr>";
1693                           
1694                        }
1695                        if ($this->_temarquivocsv) {
1696                                $htmlarquivo = $coluna->getTextoArquivo($linha,$this->arrindicadores);
1697                                if ($htmlarquivo != "") {
1698                                        $this->_txtarquivo .= $htmlarquivo . ";\n";
1699                                }
1700                            }
1701                    }
1702                   
1703                }
1704               
1705                $lastagrupamento = $newagrupamento;
1706                //$lastval = "";
1707            }
1708        }
1709       
1710        $this->escreveArquivo($handle);
1711
1712        if (count($this->totalizadores)) {           
1713            if ($this->exibesubtotais) {
1714                if ($this->_exiberesultados) {
1715                    echo   "\n\t\t<tr class='tableRodapeModelo1'>";
1716                }
1717                $mostrousubtotal = false;
1718                $cntcheckspan = 0;
1719                if ($cntagrupamentos != 1) {
1720                    $cntagrupamentos = $cntagrupamentos + 1;
1721                }
1722                foreach ($this->colunas as $coluna) {
1723                     $idcol = $coluna->getIdColuna();
1724                     if ($this->isTotalizador($coluna->getIdColuna())) {
1725                         
1726                         if (!$mostrousubtotal) {
1727                             $addtexto = "<h3>" . $this->msgsubtotalizador . "</h3>";
1728                             $mostrousubtotal = true;
1729                             $txtarquivotexto = $this->msgsubtotalizador;
1730                         } else {
1731                             $addtexto = "";
1732                         }
1733                         if ($cntcheckspan) {
1734                           
1735                         /*   for ($j=1; $j< $cntcheckspan; $j++) {
1736                                 echo  "<td id='subtotal_$idcol' align='right'>&nbsp;</td>";
1737                            }
1738                           
1739                                echo  "<td id='subtotal_titulo_$idcol' align='right'>&nbsp;$addtexto</td>";*/
1740                                if ($this->_temarquivocsv) {
1741                                for ($j=1; $j<= $cntcheckspan; $j++) {
1742                                        if ($j == $cntcheckspan) {
1743                                                $this->_txtarquivo .= $txtarquivotexto;
1744                                        }
1745                                        $this->_txtarquivo .= ";";
1746                                }
1747                                 }
1748                         }
1749                         $cntcheckspan = 0;
1750                         $addvisivel = "";
1751                             if (!$coluna->getVisibilidade()) {
1752                                $addvisivel = " style='display: none;' ";
1753                             }
1754                             if ($coluna->getTipo() == "hora") {
1755                                $subtotal_valor = $arrsubtotais[$coluna->getIdColuna()];
1756                             } else {
1757                                 if ($this->_totalizadorprecisao != 0) {
1758                                    $subtotal_valor = number_format($arrsubtotais[$coluna->getIdColuna()],$this->_totalizadorprecisao,",",".");
1759                                 } else {
1760                                    $subtotal_valor = $arrsubtotais[$coluna->getIdColuna()];
1761                                 }
1762                             }
1763                             if ($this->_exiberesultados) {
1764                                   echo  "<td id='subtotal_$idcol" . "_" . $cntagrupamentos . "' align='right'$addvisivel>$addtexto&nbsp;<h3>" . $subtotal_valor . "</h3>&nbsp;</td>";
1765                             }
1766                             if (in_array($idcol,$this->_colunasarquivo)) {
1767                                   $this->_txtarquivo .= $subtotal_valor . ";";
1768                             }
1769                     } else {
1770                         $addvisivel = "";
1771                         if (!$coluna->getVisibilidade()) {
1772                            $addvisivel = " style='display: none;' ";
1773                         }
1774                         if ($this->_exiberesultados) {
1775                            echo  "<td id='subtotal_$idcol" . "_" . $cntagrupamentos . "' $addvisivel>&nbsp;</td>";
1776                         }
1777                         if ($this->_temarquivocsv) {
1778                            if (in_array($idcol,$this->_colunasarquivo)) {
1779                                $this->_txtarquivo .= ";";
1780                            }
1781                         }
1782                     }
1783                }
1784                if ($this->_exiberesultados) {
1785                    echo   "\n\t\t</tr>";
1786                }
1787                if ($this->_temarquivocsv) {
1788                        $this->_txtarquivo .= "\n";
1789                }
1790            }
1791           
1792           
1793           
1794            if ($this->_exibetotalizadores) {
1795                if ($this->_exiberesultados) {
1796                    echo   "\n\t\t<tr class='tableRodapeModelo2'>";
1797                }
1798                $mostroutotal = false;
1799                $cntcheckspan = 0;
1800                foreach ($this->colunas as $coluna) {
1801                     
1802
1803                     $idcol = $coluna->getIdColuna();
1804                     if ($this->isTotalizador($coluna->getIdColuna())) {
1805                         if (!$mostroutotal) {
1806                             $addtexto = "<h3>" . $this->msgtotalizador .  "</h3>";
1807                             $mostroutotal = true;
1808                             $txtarquivotexto = $this->msgtotalizador;
1809                         } else {
1810                             $addtexto = "";
1811                         }
1812                         
1813                         if ($cntcheckspan) {
1814                            if ($this->_temarquivocsv) {
1815                                for ($j=1; $j<= $cntcheckspan; $j++) {
1816                                    if ($j == $cntcheckspan) {
1817                                        $this->_txtarquivo .= $txtarquivotexto;
1818                                    }
1819                                    $this->_txtarquivo .= ";";
1820                                }
1821                            }
1822                         }
1823                         $cntcheckspan = 0;
1824                         $addvisivel = "";
1825                         if (!$coluna->getVisibilidade()) {
1826                            $addvisivel = " style='display: none;' ";
1827                         }
1828                         if ($coluna->getTipo() == "hora") {
1829                            $total_valor = $arrtotais[$coluna->getIdColuna()];
1830                         } else {
1831                             if ($this->_totalizadorprecisao != 0) {
1832                                $total_valor = number_format($arrtotais[$coluna->getIdColuna()],$this->_totalizadorprecisao,",",".");
1833                             } else {
1834                                $total_valor = $arrtotais[$coluna->getIdColuna()];
1835                             }
1836                         }
1837                         if ($this->_exiberesultados) {
1838                            echo  "<td id='total_$idcol' align='right'$addvisivel>$addtexto&nbsp;<h3>" . $total_valor . "</h3></td>";
1839                         }
1840                         if ($this->_temarquivocsv) {
1841                            if (in_array($idcol,$this->_colunasarquivo)) {
1842                                $this->_txtarquivo .= $total_valor . ";";
1843                            }
1844                         }
1845                     } else {
1846                         $addvisivel = "";
1847                         if (!$coluna->getVisibilidade()) {
1848                            $addvisivel = " style='display: none;' ";
1849                         }
1850                         if ($this->_exiberesultados) {
1851                            echo  "<td id='total_$idcol' $addvisivel>&nbsp;</td>";
1852                         }
1853                         if ($this->_temarquivocsv) {
1854                            if (in_array($idcol,$this->_colunasarquivo)) {
1855                                $this->_txtarquivo .= ";";
1856                            }
1857                         }
1858                     }
1859                }
1860                if ($this->_exiberesultados) {
1861                    echo   "\n\t\t</tr>";
1862                }
1863                if ($this->_temarquivocsv) {
1864                    $this->_txtarquivo .= "\n";
1865                }
1866            }
1867        }
1868       
1869        $this->escreveArquivo($handle);
1870       
1871       
1872        if (!$this->issublist) {
1873            if (is_object($this->subListagem)) {
1874                if ($this->subListagem->getQuantidadeRegistros()) {
1875                        $this->subListagem->gerarArquivoXLS();
1876                    ob_start();
1877                    $this->subListagem->desenhar();
1878                    $htmllist = ob_get_contents();
1879                    ob_end_clean();
1880                    if ($this->_temarquivocsv) {
1881                        $this->_txtarquivo .= $this->subListagem->getTextoArquivoCSV();
1882                    }
1883                    if ($this->_exiberesultados) {
1884                        echo  "<tr><td colspan='$colspan'>";
1885                        echo  $htmllist;           
1886                        echo  "</td></tr>";
1887                    }
1888                    if ($this->subListagem->getTemCheckBox()) {
1889                        $temcheck = true;
1890                        $this->temcheck = true;
1891                    }
1892                }
1893            }
1894        }
1895       
1896        $this->escreveArquivo($handle);
1897       
1898       
1899   /* 
1900       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. */ 
1901        if (!$this->issublist) {
1902            if ($temcheck) {
1903                if (count($this->colunas)) {
1904                    echo   "\n\t\t<tr class='tableRodapeModelo3'>";
1905                    $cntcheckspan = 0;
1906                    $qtd = $this->getQuantidadeRegistros();
1907                    foreach ($this->colunas as $coluna) {
1908                        if ($coluna->getTipo() == "check") {
1909                            if ($cntcheckspan) { echo  "<td colspan='$cntcheckspan'>&nbsp;</td>";}
1910                            $cntcheckspan = 0;
1911                            $idlistagem = $this->getIdListagem();
1912                            echo  "\n\t\t\t<td align=center nowrap>&nbsp;";
1913                            echo  "<input type='button' class='botao' name='btselecionar' onclick=\"ListagemSelecionachecks(1,'" . $qtd. "','" . $coluna->getIdColuna() . "_" . $idlistagem . "_');\" value='&nbsp;+&nbsp;'>&nbsp;";
1914                            echo  "<input type='button' class='botao' name='btdesselecionar' onclick=\"ListagemSelecionachecks(0,'" . $qtd. "','" . $coluna->getIdColuna() . "_" . $idlistagem . "_');\" value='&nbsp;-&nbsp;'>&nbsp;";
1915                            echo  "\n\t\t\t</td>";
1916                        } else {
1917                            $cntcheckspan = $cntcheckspan + 1;
1918                        }
1919                    }
1920                    if ($cntcheckspan) { echo  "<td colspan='$cntcheckspan'>&nbsp;</td>";}
1921                    echo   "\n\t\t</tr>";
1922                }
1923            }
1924        }
1925       
1926       
1927
1928        if ($this->_exibeqtdregistros) {
1929            if ($this->_exiberesultados) {
1930                echo   "\n\t\t<tr class='tableRodapeModelo3'>\n\t\t\t<td colspan='$colspan' align=center>";
1931            }
1932            $qtd = $this->getQuantidadeRegistros();
1933            if ($cnt == 0) {
1934                if ($this->_exiberesultados) {
1935                    echo   $this->msgnenhumresultado;
1936                }
1937            }  else {
1938                if ($this->_exiberesultados) {
1939                echo   "<b>$qtd</b> " . $this->msgregistros;
1940                }
1941                if ($this->_temarquivocsv) {
1942                        $this->_txtarquivo .= $qtd . " " . $this->msgregistros;
1943                }
1944            }
1945            if ($this->_exiberesultados) {
1946                echo   "</td>\n\t\t</tr>";
1947            }
1948           
1949        }
1950       
1951        $this->escreveArquivo($handle);
1952       
1953
1954        if ($this->_temarquivocsv) {
1955                if (!$this->issublist) {
1956               
1957                       
1958                        fclose($handle);
1959               
1960                        $link=$tmpfname;
1961                       
1962                        if ($cnt != 0) {
1963                                echo   "\n\t\t<tr class='tableRodapeModelo3'>\n\t\t\t<td colspan='$colspan' align=center>";
1964                                //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;">';
1965                    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;">';
1966                                echo   "</td>\n\t\t</tr>";
1967                        } else {
1968                                if ($this->_exibeqtdregistros) {
1969                                        echo   "\n\t\t<tr class='tableRodapeModelo3'>\n\t\t\t<td colspan='$colspan' align=center>";
1970                                        echo   $this->msgnenhumresultado;
1971                                        echo   "</td>\n\t\t</tr>";
1972                                }
1973                        }
1974                }
1975            /*  //FORMULï¿œRIO
1976                $this->form->addButton("btn_arquivo","Arquivo .XLS");
1977                        $this->form->addCampoAcao("btn_arquivo","onclick","window.open('gera_csv_to_excel.php?arquivocsv=" . $link . "');");
1978                        $this->form->addQuadro("quadro_arquivo");
1979                        $this->form->addQuadroButton("quadro_arquivo","btn_arquivo");
1980             */
1981        }
1982       
1983        /*   
1984          FORMULï¿œRIO   
1985        if (!$this->issublist) {
1986            if ($cnt != 0) {
1987                if (($temcheck) || ($this->_temarquivocsv)) {
1988                    echo "\n\t\t<tr>\n\t\t\t<td colspan='$colspan' align=center style='padding: 0px;'>";
1989                    ob_start();
1990                    $this->form->desenhaCampos();
1991                    $this->form->displayErros();
1992                    $htmlform = ob_get_contents();
1993       
1994                    ob_end_clean();
1995                    echo  $htmlform;
1996                }
1997            }
1998            echo   "</td>\n\t\t</tr>";
1999            ob_start();
2000            $this->form->fechaForm();
2001            $htmlform = ob_get_contents();
2002            ob_end_clean();
2003        } */
2004        //echo  $htmlform;
2005       
2006        $this->arrtotais = $arrtotais;
2007        $this->arrsubtotais = $arrsubtotais_todos;
2008        $this->arragrupamentos = $arragrupamentos;
2009       
2010       
2011    }
2012   
2013    public function setDebug($value) {
2014        $this->_debug = $value;
2015    }
2016     
2017    /**
2018     * Funᅵᅵo usada internamente para adicionar um erro ao formulï¿œrio.
2019     *
2020     * @param string $msgerro Mensagem de Erro
2021     * @param boolean $fatal Se ï¿œ um erro Fatal = true ()
2022     * */
2023    protected function adicionarErro($msgerro,$fatal = false) {
2024        if ($fatal) { $this->_errors = array(); }
2025        $erro = array("msgerro" => $msgerro,"fatal" => $fatal);
2026        array_push($this->_errors,$erro);
2027         
2028        if ($fatal) {
2029            $this->escreveErros();
2030            exit;
2031        }
2032         
2033    }
2034
2035
2036    /**
2037     * Funᅵᅵo usada para exibir os erros.
2038     *
2039     * */
2040    protected function escreveErros() {
2041        if ($this->_debug) {
2042            if (count($this->_errors)) {
2043                echo "<style type='text/css'>
2044                         #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; } " .
2045                        " .erro { background: #E6EAEE; color: #000000; font-size: 12px; Verdana,Arial,Helvetica,sans-serif; font-weight: bold; margin: 2px; padding: 5px; text-align: left; }" .
2046                        "</style>";
2047                echo "<div id='erros'>";
2048                foreach ($this->_errors as $erro) {
2049                    echo "<div class=erro>";
2050
2051                    if ($erro["fatal"]) {
2052                        $addmsg = "<span style='color: #990000;'><b>ERRO:</b></span> ";
2053                    } else {
2054                        $addmsg = "ERRO: ";
2055                    }
2056                    echo $addmsg . $erro["msgerro"];
2057                    echo "</div>";
2058                }
2059                echo "</div>";
2060            }
2061        } else {
2062            echo "MODO DEBUG ESTï¿œ DESATIVADO.";
2063        }
2064    }
2065   
2066    public function gerarArquivoXLS($colunasarquivo = "") {
2067        if ($colunasarquivo == "") {
2068                $arcolunas = array();
2069                foreach ($this->colunas as $coluna) {
2070                        if ($coluna->getVisibilidade()) {
2071                          $colunasarquivo .= $coluna->getIdColuna() . ",";
2072                        }
2073                }
2074                $colunasarquivo = substr($colunasarquivo,0,strlen($colunasarquivo)-1);
2075        }
2076        $arcolunas = explode(",",$colunasarquivo);
2077        $txtarquivo = "";
2078        $this->_colunasarquivo = $arcolunas;
2079                $this->_temarquivocsv = true;
2080    }
2081   
2082    /*
2083     * Funᅵᅵo utilizada pra somar intervalos de Horas */
2084    public function somaIntervaloHoras($arrValores){
2085   
2086        // Somando separadamente os valores
2087        foreach($arrValores as $valor){
2088       
2089            $arrTmp = explode(':',$valor);
2090       
2091            $seg += $arrTmp[2];
2092            $min += $arrTmp[1];
2093            $hor += $arrTmp[0];
2094        }
2095       
2096        // Tratando os segundos
2097        if( $seg >= 60){
2098       
2099            $min += floor($seg / 60) ;
2100           
2101            while($seg >= 60){
2102               
2103                $seg = $seg - 60;
2104            }
2105       
2106        }
2107        // Tratando os minutos
2108        if( $min >= 60){
2109       
2110            $hor += floor($min / 60) ;
2111           
2112            while($min >= 60){
2113               
2114                $min = $min - 60;
2115            }
2116       
2117        }
2118       
2119        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);
2120    }
2121   
2122    /**
2123     * Funᅵᅵo que Retorna se a listagem Possui um checkBox adicionado.
2124     */
2125    public function getTemCheckBox() {
2126        return $this->temcheck;
2127    }
2128   
2129    /**
2130     * Funᅵᅵo que retorna o array com os Totalizadores.
2131     */
2132    public function getTotais() {
2133        return $this->arrtotais;
2134    }
2135   
2136    /**
2137     * Funᅵᅵo que Retorna o array com os Sub-Totalizadores.
2138     */
2139    public function getSubTotais() {
2140        return $this->arrsubtotais;
2141    }
2142   
2143    /**
2144     * Funᅵᅵo que Retorna o array com os Sub-Totalizadores.
2145     */
2146    public function getAgrupamentos() {
2147        return $this->arragrupamentos;
2148    }
2149   
2150    /**
2151     * Funᅵᅵo Interna Utilizada quando a Listagem possui uma sublistagem para guardar quantos registros a listagem principal tem.
2152     */
2153    protected function setQuantidadeRegistrosListagemPrincipal($value) {
2154        $this->_qtdregistroslistagemprincipal = $value;
2155    }
2156   
2157    /**
2158     * Funᅵᅵo Interna Utilizada quando a Listagem possui uma sublistagem para retornar quantos registros a listagem principal tem.
2159     */
2160    protected function getQuantidadeRegistrosListagemPrincipal() {
2161        return $this->_qtdregistroslistagemprincipal;
2162    }
2163   
2164    protected function getTextoArquivoCSV() {
2165        return $this->_txtarquivo;
2166    }
2167   
2168    public function autoAdicionarColunas() {
2169        $i = pg_num_fields($this->dados);
2170        for ($j = 0; $j < $i; $j++) {
2171            $fieldname = pg_field_name($this->dados, $j);
2172            $tipo = pg_field_type($this->dados, $j);
2173            $this->adicionarColuna("coluna_" .$j,"$fieldname","{" . $fieldname . "}","text","left"); 
2174        }
2175    }
2176}
2177?>
Note: See TracBrowser for help on using the repository browser.