1 | <?php |
---|
2 | |
---|
3 | $form = new Formulario("FrmCadListagem"); |
---|
4 | $form->setAction($BASE_URL); |
---|
5 | $listagem = new Listagem("listResultado","Listagens",$conn); |
---|
6 | $listagem->setUrlBasePath($GLOBALS['phpgw_info']['server']['webserver_url'] . "/workflow/inc/report"); |
---|
7 | |
---|
8 | $acao = $_POST['FrmCadListagem_acao']; |
---|
9 | if ($acao == "") { $acao = $_GET['acao']; } |
---|
10 | if ($acao == "") { $acao = $_POST['acao']; } |
---|
11 | $lstoid = $_POST['lstoid']; |
---|
12 | if ($lstoid == "") { $lstoid = $_GET['lstoid']; } |
---|
13 | |
---|
14 | |
---|
15 | if ($acao == "alterarStatus") { |
---|
16 | $lstidlistagem = $_POST['lstidlistagem']; |
---|
17 | $novostatus = $_POST['novostatus']; |
---|
18 | $ret = atualizaStatus(array("$lstidlistagem"),$novostatus); |
---|
19 | $msg = "Status Alterado com Sucesso!"; |
---|
20 | $acao = "editar"; |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | if (($acao == "editar") || ($form->isSubmit("atualizar_listagem",true))) { |
---|
25 | |
---|
26 | $lstidlistagem = $_POST['lstidlistagem']; |
---|
27 | $lstversao = $_POST['lstversao']; |
---|
28 | $lstnome = $_POST['lstnome']; |
---|
29 | $lsttitulo = $_POST['lsttitulo']; |
---|
30 | $lstsql = $_POST['lstsql']; |
---|
31 | |
---|
32 | $lstmsg_totalizador = $_POST['lstmsg_totalizador']; |
---|
33 | $lstmsg_subtotalizador = $_POST['lstmsg_subtotalizador']; |
---|
34 | $lstmsg_registrosencontrados = $_POST['lstmsg_registrosencontrados']; |
---|
35 | $lstmsg_nenhumresultado = $_POST['lstmsg_nenhumresultado']; |
---|
36 | $lstdescricao = $_POST['lstdescricao']; |
---|
37 | |
---|
38 | $lstagrupamento_campo = $_POST['lstagrupamento_campo']; |
---|
39 | $lstagrupamento_titulo = $_POST['lstagrupamento_titulo']; |
---|
40 | $lstexclusao = $_POST['lstexclusao']; |
---|
41 | |
---|
42 | if ($lstmsg_totalizador == "") { $lstmsg_totalizador = "TOTAL:"; } |
---|
43 | if ($lstmsg_subtotalizador == "") { $lstmsg_subtotalizador = "SUB-TOTAL:"; } |
---|
44 | if ($lstmsg_registrosencontrados == "") { $lstmsg_registrosencontrados = "registro(s) encontrado(s)."; } |
---|
45 | if ($lstmsg_nenhumresultado == "") { $lstmsg_nenhumresultado = "Nenhum resultado encontrado."; } |
---|
46 | if ($lsttitulo == "") { $lsttitulo = "Resultado da Pesquisa."; } |
---|
47 | |
---|
48 | if ($lstoid == "") { |
---|
49 | $lstexibe_resultados = true; |
---|
50 | $lstexibe_header = true; |
---|
51 | $lstexibe_totalizadores = true; |
---|
52 | $lstexibe_subtotais = true; |
---|
53 | $lstexibe_qtdregistros = true; |
---|
54 | $lstexibe_legendatopo = true; |
---|
55 | $lstexibe_titagrupamento = true; |
---|
56 | $lstexibe_agrupamento_alfabetico = false; |
---|
57 | $lstexclusao = true; |
---|
58 | } |
---|
59 | |
---|
60 | $arrOpcVisualizacao[] = array('lstexibe_resultados', ' Exibir resultados na tela.', $lstexibe_resultados); |
---|
61 | $arrOpcVisualizacao[] = array('lstexibe_header', ' Exibir titulos das colunas', $lstexibe_header); |
---|
62 | $arrOpcVisualizacao[] = array('lstexibe_totalizadores', ' Exibir totalizadores', $lstexibe_totalizadores); |
---|
63 | $arrOpcVisualizacao[] = array('lstexibe_subtotais', ' Exibir sub-totalizadores', $lstexibe_subtotais); |
---|
64 | $arrOpcVisualizacao[] = array('lstexibe_qtdregistros', ' Exibir Quantidade de registros encontrados', $lstexibe_qtdregistros); |
---|
65 | $arrOpcVisualizacao[] = array('lstexibe_checkbox', ' Exibir colunas com checkbox.', $lstexibe_checkbox); |
---|
66 | $arrOpcVisualizacao[] = array('lstexibe_csv', ' Gerar CSV', $lstexibe_csv); |
---|
67 | $arrOpcVisualizacao[] = array('lstexibe_legendatopo', ' Exibir legenda no topo', $lstexibe_legendatopo); |
---|
68 | $arrOpcVisualizacao[] = array('lstexibe_legendarodape', ' Exibir legenda no rodape', $lstexibe_legendarodape); |
---|
69 | $arrOpcVisualizacao[] = array('lstexibe_titagrupamento', ' Re-exibir titulos de agrupamento', $lstexibe_titagrupamento); |
---|
70 | $arrOpcVisualizacao[] = array('lstexibe_agrupamento_alfabetico', ' Exibir agrupamento alfabetico', $lstexibe_agrupamento_alfabetico); |
---|
71 | $arrOpcVisualizacao[] = array('lstexclusao', ' Ativa', $lstexclusao); |
---|
72 | foreach ($arrOpcVisualizacao as $opc) { |
---|
73 | $$opc[0] = "false"; |
---|
74 | } |
---|
75 | $opcvisualizacao = $_POST['opcvisualizacao']; |
---|
76 | if (is_array($opcvisualizacao)) { |
---|
77 | foreach ($opcvisualizacao as $opc) { |
---|
78 | $$opc = "true"; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | if ($lstexclusao == "false") { |
---|
83 | $flstexclusao = "now()"; |
---|
84 | } |
---|
85 | if ($lstexclusao == "true") { |
---|
86 | $flstexclusao = "null"; |
---|
87 | } |
---|
88 | |
---|
89 | if (($acao == "editar") && ($lstoid != "")) { |
---|
90 | $sql = "select |
---|
91 | lstoid, |
---|
92 | lstversao, |
---|
93 | lstidlistagem, |
---|
94 | lstdescricao, |
---|
95 | lstnome, |
---|
96 | lsttitulo, |
---|
97 | lstsql, |
---|
98 | lstexibe_header, |
---|
99 | lstexibe_totalizadores, |
---|
100 | lstexibe_subtotais, |
---|
101 | lstexibe_qtdregistros, |
---|
102 | lstexibe_checkbox, |
---|
103 | lstexibe_csv, |
---|
104 | lstexibe_legendatopo, |
---|
105 | lstexibe_legendarodape, |
---|
106 | lstexibe_titagrupamento, |
---|
107 | lstexibe_agrupamento_alfabetico, |
---|
108 | lstagrupamento_campo, |
---|
109 | lstagrupamento_titulo, |
---|
110 | lstmsg_totalizador, |
---|
111 | lstmsg_subtotalizador, |
---|
112 | lstmsg_registrosencontrados, |
---|
113 | lstmsg_nenhumresultado, |
---|
114 | lstexclusao, |
---|
115 | lstexibe_resultados |
---|
116 | from |
---|
117 | listagem.listagem |
---|
118 | where |
---|
119 | lstoid = $lstoid"; |
---|
120 | $res = pg_query($sql); |
---|
121 | $linha = pg_fetch_object($res); |
---|
122 | $lstidlistagem = ""; |
---|
123 | foreach ($linha as $chave => $valor) { |
---|
124 | if ($valor == "f") { |
---|
125 | $valor = false; |
---|
126 | } |
---|
127 | if ($valor == "t") { |
---|
128 | $valor = true; |
---|
129 | } |
---|
130 | // $$chave= str_replace("[-]","'",$valor);; |
---|
131 | $$chave= html_entity_decode($valor, ENT_QUOTES); |
---|
132 | } |
---|
133 | if ($lstexclusao == "") { |
---|
134 | $f_lstexclusao = true; |
---|
135 | } else { |
---|
136 | $f_lstexclusao = false; |
---|
137 | } |
---|
138 | |
---|
139 | //$lstsql = str_replace("[-]","'",$lstsql); |
---|
140 | unset ($arrOpcVisualizacao); |
---|
141 | $arrOpcVisualizacao[] = array('lstexibe_resultados', ' Exibir resultados na tela.', $lstexibe_resultados); |
---|
142 | $arrOpcVisualizacao[] = array('lstexibe_header', ' Exibir titulos das colunas', $lstexibe_header); |
---|
143 | $arrOpcVisualizacao[] = array('lstexibe_totalizadores', ' Exibir totalizadores', $lstexibe_totalizadores); |
---|
144 | $arrOpcVisualizacao[] = array('lstexibe_subtotais', ' Exibir sub-totalizadores', $lstexibe_subtotais); |
---|
145 | $arrOpcVisualizacao[] = array('lstexibe_qtdregistros', ' Exibir Quantidade de registros encontrados', $lstexibe_qtdregistros); |
---|
146 | $arrOpcVisualizacao[] = array('lstexibe_checkbox', ' Exibir colunas com checkbox.', $lstexibe_checkbox); |
---|
147 | $arrOpcVisualizacao[] = array('lstexibe_csv', ' Gerar CSV', $lstexibe_csv); |
---|
148 | $arrOpcVisualizacao[] = array('lstexibe_legendatopo', ' Exibir legenda no topo', $lstexibe_legendatopo); |
---|
149 | $arrOpcVisualizacao[] = array('lstexibe_legendarodape', ' Exibir legenda no rodape', $lstexibe_legendarodape); |
---|
150 | $arrOpcVisualizacao[] = array('lstexibe_titagrupamento', ' Re-exibir titulos de agrupamento', $lstexibe_titagrupamento); |
---|
151 | $arrOpcVisualizacao[] = array('lstexibe_agrupamento_alfabetico', ' Exibir agrupamento alfabetico', $lstexibe_agrupamento_alfabetico); |
---|
152 | |
---|
153 | |
---|
154 | $arrOpcVisualizacao[] = array('lstexclusao', ' Ativa', $f_lstexclusao); |
---|
155 | |
---|
156 | $lstexclusao = $linha->lstexclusao; |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | if ($acao == "atualizar_listagem") { |
---|
161 | |
---|
162 | if ($lstoid != "") { |
---|
163 | $sql = "select |
---|
164 | lstidlistagem |
---|
165 | from |
---|
166 | listagem.listagem |
---|
167 | where |
---|
168 | lstoid = $lstoid"; |
---|
169 | $res = pg_query($sql); |
---|
170 | $linha = pg_fetch_object($res); |
---|
171 | |
---|
172 | $lstidlistagem = $linha->lstidlistagem; |
---|
173 | |
---|
174 | } |
---|
175 | |
---|
176 | //$lstsql = str_replace("\\'","[-]",$lstsql); |
---|
177 | //$lstsql = str_replace("'","[-]",$lstsql); |
---|
178 | |
---|
179 | $lstdescricao = htmlspecialchars($lstdescricao,ENT_QUOTES); |
---|
180 | $lstnome = htmlspecialchars($lstnome,ENT_QUOTES); |
---|
181 | $lstsql = htmlspecialchars($lstsql,ENT_QUOTES); |
---|
182 | |
---|
183 | try { |
---|
184 | pg_query($conn,"BEGIN;"); |
---|
185 | if ($lstoid == "") { |
---|
186 | |
---|
187 | $sql = "INSERT INTO listagem.listagem ( lstidlistagem, |
---|
188 | lstnome, |
---|
189 | lsttitulo, |
---|
190 | lstsql, |
---|
191 | lstexibe_header, |
---|
192 | lstexibe_totalizadores, |
---|
193 | lstexibe_qtdregistros, |
---|
194 | lstexibe_subtotais, |
---|
195 | lstexibe_checkbox, |
---|
196 | lstexibe_csv, |
---|
197 | lstexibe_legendatopo, |
---|
198 | lstexibe_legendarodape, |
---|
199 | lstexibe_titagrupamento, |
---|
200 | lstmsg_totalizador, |
---|
201 | lstmsg_subtotalizador, |
---|
202 | lstmsg_registrosencontrados, |
---|
203 | lstmsg_nenhumresultado, |
---|
204 | lstversao, |
---|
205 | lstagrupamento_campo, |
---|
206 | lstagrupamento_titulo, |
---|
207 | lstdescricao, |
---|
208 | lstexibe_agrupamento_alfabetico, |
---|
209 | lstexibe_resultados, |
---|
210 | lstexclusao |
---|
211 | ) |
---|
212 | VALUES |
---|
213 | ( '$lstidlistagem', |
---|
214 | '$lstnome', |
---|
215 | '$lsttitulo', |
---|
216 | '$lstsql', |
---|
217 | $lstexibe_header, |
---|
218 | $lstexibe_totalizadores, |
---|
219 | $lstexibe_qtdregistros, |
---|
220 | $lstexibe_subtotais, |
---|
221 | $lstexibe_checkbox, |
---|
222 | $lstexibe_csv, |
---|
223 | $lstexibe_legendatopo, |
---|
224 | $lstexibe_legendarodape, |
---|
225 | $lstexibe_titagrupamento, |
---|
226 | '$lstmsg_totalizador', |
---|
227 | '$lstmsg_subtotalizador', |
---|
228 | '$lstmsg_registrosencontrados', |
---|
229 | '$lstmsg_nenhumresultado', |
---|
230 | 1, |
---|
231 | '$lstagrupamento_campo', |
---|
232 | '$lstagrupamento_titulo', |
---|
233 | '$lstdescricao', |
---|
234 | $lstexibe_agrupamento_alfabetico, |
---|
235 | $lstexibe_resultados, |
---|
236 | $flstexclusao |
---|
237 | )"; |
---|
238 | |
---|
239 | // echo $sql; |
---|
240 | $result = pg_query($conn,$sql); |
---|
241 | if (!$result) { throw new Exception("ERRO: Inserindo listagem."); } |
---|
242 | |
---|
243 | $sql = "SELECT max(lstoid) as lstoid from listagem.listagem "; |
---|
244 | $result = pg_query($conn,$sql); |
---|
245 | |
---|
246 | $dados = pg_fetch_array($result); |
---|
247 | $lstoid = $dados['lstoid']; |
---|
248 | |
---|
249 | echo "<script>document.frm.lstoid.value='$lstoid';</script>"; |
---|
250 | $acao = "editar"; |
---|
251 | |
---|
252 | $msg = "Registro Inserido com Sucesso!"; |
---|
253 | |
---|
254 | } else { |
---|
255 | |
---|
256 | $sql = "UPDATE listagem.listagem SET |
---|
257 | lstnome = '$lstnome', |
---|
258 | lsttitulo = '$lsttitulo', |
---|
259 | lstsql = '$lstsql', |
---|
260 | lstexibe_header = $lstexibe_header, |
---|
261 | lstexibe_totalizadores = $lstexibe_totalizadores, |
---|
262 | lstexibe_qtdregistros = $lstexibe_qtdregistros, |
---|
263 | lstexibe_subtotais = $lstexibe_subtotais, |
---|
264 | lstexibe_checkbox = $lstexibe_checkbox, |
---|
265 | lstexibe_csv = $lstexibe_csv, |
---|
266 | lstexibe_legendatopo = $lstexibe_legendatopo, |
---|
267 | lstexibe_legendarodape = $lstexibe_legendarodape, |
---|
268 | lstexibe_titagrupamento = $lstexibe_titagrupamento, |
---|
269 | lstexibe_agrupamento_alfabetico = $lstexibe_agrupamento_alfabetico, |
---|
270 | lstmsg_totalizador = '$lstmsg_totalizador', |
---|
271 | lstmsg_subtotalizador = '$lstmsg_subtotalizador', |
---|
272 | lstmsg_registrosencontrados = '$lstmsg_registrosencontrados', |
---|
273 | lstmsg_nenhumresultado = '$lstmsg_nenhumresultado', |
---|
274 | lstversao = lstversao + 1, |
---|
275 | lstagrupamento_campo = '$lstagrupamento_campo', |
---|
276 | lstagrupamento_titulo = '$lstagrupamento_titulo', |
---|
277 | lstdescricao = '$lstdescricao', |
---|
278 | lstexibe_resultados = $lstexibe_resultados, |
---|
279 | lstexclusao = $flstexclusao |
---|
280 | WHERE lstoid = $lstoid"; |
---|
281 | $result = pg_query($conn,$sql); |
---|
282 | if (!$result) { throw new Exception("ERRO: Inserindo listagem."); } |
---|
283 | $msg = "Registro Atualizado com Sucesso!"; |
---|
284 | } |
---|
285 | |
---|
286 | pg_query($conn,"COMMIT;"); |
---|
287 | |
---|
288 | } catch (exception $e) { |
---|
289 | $msg = $e->getMessage(); |
---|
290 | pg_query($conn,"ROLLBACK;"); |
---|
291 | } |
---|
292 | |
---|
293 | } |
---|
294 | |
---|
295 | $lstsql = html_entity_decode($lstsql, ENT_QUOTES); |
---|
296 | $lstnome = html_entity_decode($lstnome, ENT_QUOTES); |
---|
297 | $lstdescricao = html_entity_decode($lstdescricao, ENT_QUOTES); |
---|
298 | |
---|
299 | $form->adicionarHidden("lstoid",$lstoid); |
---|
300 | $form->adicionarHidden("abaMenu",$abaMenu); |
---|
301 | $form->adicionarHidden("acao","editar"); |
---|
302 | $form->adicionarCampo("lstidlistagem","lstidlistagem","ID da Listagem","Identificador da Listagem",$lstidlistagem,true); |
---|
303 | |
---|
304 | $form->adicionarCampo("lstnome","lstnome","Nome:","Nome:",$lstnome,true,"80"); |
---|
305 | |
---|
306 | $form->adicionarTextarea("lstdescricao","Descricao:",$lstdescricao,true,"80","8"); |
---|
307 | $form->adicionarSubtitulo("Consulta"); |
---|
308 | |
---|
309 | $form->adicionarTextarea("lstsql","",$lstsql,true,"120","15"); |
---|
310 | |
---|
311 | $form->adicionarSubtitulo("Opcoes de Visualizacao"); |
---|
312 | $form->adicionarCheckBox("opcvisualizacao","",$arrOpcVisualizacao,false); |
---|
313 | |
---|
314 | $form->adicionarSubtitulo("Agrupamento"); |
---|
315 | $form->adicionarCampo("lstagrupamento_campo","lstagrupamento_campo","Campo de Agrupamento:","Campo de Agrupamento:",$lstagrupamento_campo,false,"","","Campo que sera usado para agrupar os sub-totalizadores (Nao usar {})."); |
---|
316 | $form->adicionarCampo("lstagrupamento_titulo","lstagrupamento_titulo","Titulo do Agrupamento:","Titulo do Agrupamento:",$lstagrupamento_titulo,false,"50","300","Ex.: Cliente: {clinome}"); |
---|
317 | |
---|
318 | $form->adicionarSubtitulo("Mensagens Personalizadas"); |
---|
319 | $form->adicionarCampo("lsttitulo","lsttitulo","Titulo:","Titulo:",$lsttitulo,true,"50"); |
---|
320 | $form->adicionarCampo("lstmsg_totalizador","lstmsg_totalizador","Mensagem Totalizador:","Mensagem Totalizador:",$lstmsg_totalizador,true); |
---|
321 | $form->adicionarCampo("lstmsg_subtotalizador","lstmsg_subtotalizador","Mensagem Sub-Totalizador:","Mensagem Sub-Totalizador:",$lstmsg_subtotalizador,true); |
---|
322 | $form->adicionarCampo("lstmsg_registrosencontrados","lstmsg_registrosencontrados","Mensagem Registros Encontrados:","Mensagem Registros Encontrados:",$lstmsg_registrosencontrados,true); |
---|
323 | $form->adicionarCampo("lstmsg_nenhumresultado","lstmsg_nenhumresultado","Mensagem Nenhum Resultado:","Mensagem Nenhum Resultado:",$lstmsg_nenhumresultado,true); |
---|
324 | $form->agruparCampos("lstmsg_totalizador,lstmsg_subtotalizador;lstmsg_registrosencontrados,lstmsg_nenhumresultado"); |
---|
325 | |
---|
326 | if ($lstexclusao) { |
---|
327 | $novostatus = "1"; |
---|
328 | $titulo = "Ativar"; |
---|
329 | } else { |
---|
330 | $novostatus = "0"; |
---|
331 | $titulo = "Inativar"; |
---|
332 | } |
---|
333 | $form->adicionarHidden("novostatus",$novostatus); |
---|
334 | |
---|
335 | $form->adicionarQuadro("quadro1","Cadastro de Listagem"); |
---|
336 | |
---|
337 | $form->adicionarSubmit("quadro1","btn_cadastrar","Atualizar","atualizar_listagem"); |
---|
338 | /*if ($lstoid != "") { |
---|
339 | $form->adicionarSubmit("quadro1","btn_status",$titulo,"alterarStatus"); |
---|
340 | }*/ |
---|
341 | |
---|
342 | } |
---|
343 | |
---|
344 | if ($msg != "") { |
---|
345 | echo "<script>ExibirMensagem('$msg')</script>"; |
---|
346 | } |
---|
347 | $form->desenhar(); |
---|
348 | |
---|
349 | if ($lstoid) { |
---|
350 | echo "<script>bloquear_campo('id_lstidlistagem');</script>"; |
---|
351 | } |
---|
352 | ?> |
---|