1 | <?php |
---|
2 | /** |
---|
3 | * ListagemColuna |
---|
4 | * |
---|
5 | * Implementação de Colunas das Listagems Padrões do Sistema. |
---|
6 | */ |
---|
7 | /** |
---|
8 | * ListagemColuna |
---|
9 | * |
---|
10 | * Implementação de Colunas das Listagems Padrões do Sistema. |
---|
11 | * |
---|
12 | * |
---|
13 | * @author Jair Pereira <pereira.jair@gmail.com> |
---|
14 | * @since 01/06/2009 |
---|
15 | * |
---|
16 | */ |
---|
17 | |
---|
18 | class ListagemColuna { |
---|
19 | private $idcoluna; |
---|
20 | private $idlistagem; |
---|
21 | private $nome; |
---|
22 | private $align; |
---|
23 | private $html; |
---|
24 | private $width; |
---|
25 | private $tipo; |
---|
26 | private $nowrap; |
---|
27 | private $valign; |
---|
28 | private $link; |
---|
29 | private $popup = false; |
---|
30 | private $target; |
---|
31 | private $condicao; |
---|
32 | private $linkcondicao; |
---|
33 | private $cor; |
---|
34 | private $corcondicao; |
---|
35 | private $visivel = true; |
---|
36 | |
---|
37 | |
---|
38 | public function getValorHTML($linha) { |
---|
39 | $newhtml = ""; |
---|
40 | $newhtml .= $this->html; |
---|
41 | $newhtml = $this->replaceValorLinha($newhtml,$linha); |
---|
42 | |
---|
43 | if ($this->tipo == "php") { |
---|
44 | ob_start(); |
---|
45 | echo eval($newhtml); |
---|
46 | $novohtml = ob_get_contents(); |
---|
47 | ob_end_clean(); |
---|
48 | $newhtml = $novohtml; |
---|
49 | } |
---|
50 | |
---|
51 | if ($this->tipo == "php-moeda") { |
---|
52 | ob_start(); |
---|
53 | echo eval($newhtml); |
---|
54 | $novohtml = ob_get_contents(); |
---|
55 | ob_end_clean(); |
---|
56 | $newhtml = $novohtml; |
---|
57 | } |
---|
58 | |
---|
59 | return $newhtml; |
---|
60 | } |
---|
61 | |
---|
62 | public function getTextoArquivo($linha,$todososindicadores) { |
---|
63 | $newhtml = $this->html; |
---|
64 | foreach ($todososindicadores as $idindicador => $indicadores) { |
---|
65 | foreach ($indicadores as $indicador) { |
---|
66 | $nomeindicador = $indicador->getIdIndicador(); |
---|
67 | $condicao = $indicador->getCondicao(); |
---|
68 | $ret = $this->validaCondicao($condicao,$linha); |
---|
69 | if ($ret) { |
---|
70 | $newhtml = str_replace("{" . $nomeindicador . "}",$indicador->getLegendaArquivo() ,$newhtml); |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | foreach ($todososindicadores as $idindicador => $indicadores) { |
---|
75 | foreach ($indicadores as $indicador) { |
---|
76 | $nomeindicador = $indicador->getIdIndicador(); |
---|
77 | $newhtml = str_replace("{" . $nomeindicador . "}","" ,$newhtml); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | $newhtml = $this->replaceValorLinha($newhtml,$linha); |
---|
82 | if ($this->tipo == "data") { |
---|
83 | if ($newhtml != "") { |
---|
84 | $newhtml = date("d/m/Y",strtotime($newhtml)); |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | if ($this->tipo == "moeda") { |
---|
89 | if ($newhtml == "") { $newhtml = 0; } |
---|
90 | $newhtml = number_format($newhtml,2,",","."); |
---|
91 | } |
---|
92 | |
---|
93 | if ($this->tipo == "php") { |
---|
94 | ob_start(); |
---|
95 | echo eval($newhtml); |
---|
96 | $novohtml = ob_get_contents(); |
---|
97 | ob_end_clean(); |
---|
98 | $newhtml = $novohtml; |
---|
99 | } |
---|
100 | |
---|
101 | if ($this->tipo == "php-moeda") { |
---|
102 | ob_start(); |
---|
103 | echo eval($newhtml); |
---|
104 | $novohtml = ob_get_contents(); |
---|
105 | ob_end_clean(); |
---|
106 | $newhtml = $novohtml; |
---|
107 | $newhtml = number_format($newhtml,2,",","."); |
---|
108 | } |
---|
109 | |
---|
110 | return $newhtml; |
---|
111 | } |
---|
112 | |
---|
113 | public function validaCondicao($condicao,$linha,$debug = false) { |
---|
114 | foreach (array_keys($linha) as $col) { |
---|
115 | $condicao = str_replace("{" . $col . "}","'" . $linha[$col] . "'",$condicao); |
---|
116 | } |
---|
117 | $condicao = html_entity_decode($condicao, ENT_QUOTES); |
---|
118 | $fcondicao = ' if (' . $condicao . ') { $ret = true; } else { $ret = false; }'; |
---|
119 | if ($condicao != "") { |
---|
120 | if ($debug) { echo "<br>" . $fcondicao ; } |
---|
121 | eval($fcondicao); |
---|
122 | } else { |
---|
123 | $ret = false; |
---|
124 | } |
---|
125 | return $ret; |
---|
126 | } |
---|
127 | |
---|
128 | public function getHtml($linha,$todososindicadores,$classe,$i) { |
---|
129 | $newhtml = ""; |
---|
130 | $newhtml .= $this->html; |
---|
131 | if ($classe == "tdc") { |
---|
132 | $fundo = false; |
---|
133 | } else { |
---|
134 | $fundo = true; |
---|
135 | } |
---|
136 | |
---|
137 | foreach ($todososindicadores as $idindicador => $indicadores) { |
---|
138 | foreach ($indicadores as $indicador) { |
---|
139 | $nomeindicador = $indicador->getIdIndicador(); |
---|
140 | $condicao = $indicador->getCondicao(); |
---|
141 | |
---|
142 | $ret = $this->validaCondicao($condicao,$linha); |
---|
143 | if ($ret) { |
---|
144 | $newhtml = str_replace("{" . $nomeindicador . "}",$indicador->getHtml($fundo) . "{" . $nomeindicador . "}",$newhtml); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | $newhtml = str_replace("{this_num_linha}",$i,$newhtml); |
---|
151 | |
---|
152 | foreach ($todososindicadores as $idindicador => $indicadores) { |
---|
153 | foreach ($indicadores as $indicador) { |
---|
154 | $nomeindicador = $indicador->getIdIndicador(); |
---|
155 | $newhtml = str_replace("{" . $nomeindicador . "}","",$newhtml); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | $newhtml = $this->replaceValorLinha($newhtml,$linha); |
---|
160 | |
---|
161 | if ($this->tipo == "check") { |
---|
162 | $condicao = $this->getCondicao(); |
---|
163 | $ret = $this->validaCondicao($condicao,$linha); |
---|
164 | if ($ret) { |
---|
165 | $checked = ""; |
---|
166 | if (isset($_POST[$this->idcoluna])) { |
---|
167 | if (is_array($newhtml)) { |
---|
168 | if (in_array($newhtml,$_POST[$this->idcoluna])) { |
---|
169 | $checked = " checked"; |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|
173 | $newhtml = "<input id='" . $this->idcoluna ."_" . $this->idlistagem . "_" .$i . "' type='checkbox' name='" . $this->idcoluna . "[]' value='" . $newhtml . "' class='obrigatorio'" . $checked .">"; |
---|
174 | } else { |
---|
175 | $newhtml = ""; |
---|
176 | } |
---|
177 | |
---|
178 | } |
---|
179 | |
---|
180 | if ($this->tipo == "data") { |
---|
181 | if ($newhtml != "") { |
---|
182 | $newhtml = date("d/m/Y",strtotime($newhtml)); |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | if ($this->tipo == "moeda") { |
---|
187 | if ($newhtml == "") { $newhtml = 0; } |
---|
188 | $newhtml = number_format($newhtml,2,",","."); |
---|
189 | } |
---|
190 | |
---|
191 | if ($this->tipo == "php") { |
---|
192 | ob_start(); |
---|
193 | echo eval($newhtml); |
---|
194 | $novohtml = ob_get_contents(); |
---|
195 | ob_end_clean(); |
---|
196 | $newhtml = $novohtml; |
---|
197 | } |
---|
198 | |
---|
199 | if ($this->tipo == "php-moeda") { |
---|
200 | ob_start(); |
---|
201 | echo eval($newhtml); |
---|
202 | $novohtml = ob_get_contents(); |
---|
203 | ob_end_clean(); |
---|
204 | $newhtml = $novohtml; |
---|
205 | $newhtml = number_format($newhtml,2,",","."); |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | if ($this->link != "") { |
---|
210 | $condicao = $this->linkcondicao; |
---|
211 | //echo $this->linkcondicao; |
---|
212 | $ret = $this->validaCondicao($condicao,$linha); |
---|
213 | if ($ret) { |
---|
214 | $novolink = $this->replaceValorLinha($this->link,$linha); |
---|
215 | $novolink = str_replace("{this_num_linha}",$i,$novolink); |
---|
216 | $addtarget = ""; |
---|
217 | if ($this->target) { |
---|
218 | $addtarget = " target='_blank'"; |
---|
219 | } |
---|
220 | if ($this->popup) { |
---|
221 | $addonclick = " onClick=\"window.open('$novolink','Popup','width=600,top=50,left=50, scrollbars=yes');\" "; |
---|
222 | $novolink = "#"; |
---|
223 | } |
---|
224 | $newhtml = "<a href=\"" . $novolink . "\"" . $addtarget . $addonclick . ">" . $newhtml . "</a>"; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | if ($this->cor != "") { |
---|
229 | $condicao = $this->corcondicao; |
---|
230 | $ret = $this->validaCondicao($condicao,$linha); |
---|
231 | if ($ret) { |
---|
232 | $newhtml = "<span style='color: #" . $this->cor . ";'>" . $newhtml . "</span>"; |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | return $newhtml; |
---|
237 | } |
---|
238 | |
---|
239 | public function replaceValorLinha($html,$linha) { |
---|
240 | $newhtml = $html; |
---|
241 | foreach (array_keys($linha) as $col) { |
---|
242 | $newhtml = str_replace("{" . $col . "}",$linha[$col],$newhtml); |
---|
243 | } |
---|
244 | return $newhtml; |
---|
245 | } |
---|
246 | |
---|
247 | function setCondicao($condicao) { |
---|
248 | $this->condicao = $condicao; |
---|
249 | } |
---|
250 | |
---|
251 | function setIdListagem($idlistagem) { |
---|
252 | $this->idlistagem = $idlistagem; |
---|
253 | } |
---|
254 | |
---|
255 | function setLinkCondicao($condicao) { |
---|
256 | $this->linkcondicao = $condicao; |
---|
257 | } |
---|
258 | |
---|
259 | function getCondicao() { |
---|
260 | return $this->condicao; |
---|
261 | } |
---|
262 | |
---|
263 | function getLinkCondicao() { |
---|
264 | return $this->condicao; |
---|
265 | } |
---|
266 | |
---|
267 | function getVAlign($formatado = false) { |
---|
268 | if ($formatado) { |
---|
269 | if ($this->valign != "") { |
---|
270 | $addvalign = " valign='" . $this->valign . "' "; |
---|
271 | } else { |
---|
272 | $addvalign = ""; |
---|
273 | } |
---|
274 | return $addvalign; |
---|
275 | } else { |
---|
276 | return $this->valign; |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | public function __construct($idcoluna,$tipo,$nome,$html,$width = "",$nowrap = false,$align = "") { |
---|
281 | $this->idcoluna = $idcoluna; |
---|
282 | $this->nome = $nome; |
---|
283 | $this->html = $html; |
---|
284 | $this->width = $width; |
---|
285 | $this->setTipo($tipo); |
---|
286 | if ($align != "") { |
---|
287 | $this->align = $align; |
---|
288 | } |
---|
289 | $this->nowrap = $nowrap; |
---|
290 | $this->valign= "center"; |
---|
291 | } |
---|
292 | |
---|
293 | public function setTipo($tipo) { |
---|
294 | $align = ""; |
---|
295 | if ($tipo == "imagem") { $align = "center"; } |
---|
296 | if ($tipo == "int") { $align = "right"; } |
---|
297 | if ($tipo == "check") { $align = "center"; } |
---|
298 | if ($tipo == "moeda") { $align = "right"; } |
---|
299 | if ($tipo == "php-moeda") { $align = "right"; } |
---|
300 | if ($tipo == "text") { $align = "left"; } |
---|
301 | if ($tipo == "data") { $align = "center"; } |
---|
302 | if ($tipo == "hora") { $align = "center"; } |
---|
303 | /* if ($tipo == "center") { $align = "center"; } |
---|
304 | if ($tipo == "left") { $align = "left"; } |
---|
305 | if ($tipo == "right") { $align = "right"; } */ |
---|
306 | $this->align = $align; |
---|
307 | $this->tipo = $tipo; |
---|
308 | } |
---|
309 | |
---|
310 | public function setLink($link,$condicao,$target = "",$popup = false) { |
---|
311 | $this->link = $link; |
---|
312 | $this->target = $target; |
---|
313 | $this->linkcondicao = $condicao; |
---|
314 | $this->popup = $popup; |
---|
315 | } |
---|
316 | |
---|
317 | public function setCor($cor,$condicao) { |
---|
318 | $this->cor = $cor; |
---|
319 | $this->corcondicao = $condicao; |
---|
320 | } |
---|
321 | |
---|
322 | public function getWidth($formatado = false) { |
---|
323 | if ($formatado) { |
---|
324 | if ($this->width != "") { |
---|
325 | $addwidth = " width='" . $this->width . "' "; |
---|
326 | } else { |
---|
327 | $addwidth = ""; |
---|
328 | } |
---|
329 | return $addwidth; |
---|
330 | } else { |
---|
331 | return $this->width; |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | public function getIdColuna() { |
---|
336 | return $this->idcoluna; |
---|
337 | } |
---|
338 | |
---|
339 | public function getNome() { |
---|
340 | return $this->nome; |
---|
341 | } |
---|
342 | |
---|
343 | public function getTipo() { |
---|
344 | return $this->tipo; |
---|
345 | } |
---|
346 | |
---|
347 | public function getNowrap() { |
---|
348 | return $this->nowrap; |
---|
349 | } |
---|
350 | |
---|
351 | public function getAlign() { |
---|
352 | return $this->align; |
---|
353 | } |
---|
354 | |
---|
355 | public function setVisibilidade($value) { |
---|
356 | $this->visivel = $value; |
---|
357 | } |
---|
358 | public function getVisibilidade() { |
---|
359 | return $this->visivel; |
---|
360 | } |
---|
361 | |
---|
362 | } |
---|
363 | ?> |
---|