Commit 8dfb61e332f32db22c8c516b6e40eca157680234
1 parent
2078b8e7
Exists in
master
and in
1 other branch
Revisao do modulo para exportacao de relatorios nos formatos PDF, ODS, CSV e HTML.
git-svn-id: http://svn.softwarepublico.gov.br/svn/cacic/cacic/trunk/gerente@633 fecfc0c7-e812-0410-ae72-849f08638ee7
Showing
5 changed files
with
255 additions
and
235 deletions
Show diff stats
include/Relatorio.php
... | ... | @@ -4,6 +4,8 @@ abstract class Relatorio |
4 | 4 | private $m_titulo; |
5 | 5 | private $m_header; |
6 | 6 | private $m_body = array(); |
7 | + private $m_rowAttr = array(); | |
8 | + private $m_cellColor = array(); | |
7 | 9 | |
8 | 10 | public function setTitulo($titulo) |
9 | 11 | { |
... | ... | @@ -15,6 +17,30 @@ abstract class Relatorio |
15 | 17 | return $this->m_titulo; |
16 | 18 | } |
17 | 19 | |
20 | + public function setRowColor($row, $r, $g, $b) | |
21 | + { | |
22 | + $this->m_rowAttr[$row] = array($r, $g, $b); | |
23 | + } | |
24 | + | |
25 | + public function getRowColor($row) | |
26 | + { | |
27 | + return $this->m_rowAttr[$row]; | |
28 | + } | |
29 | + | |
30 | + public function setCellColor($row, $col, $rgb) | |
31 | + { | |
32 | + $this->m_cellColor[$row][$col] = $rgb; | |
33 | + } | |
34 | + | |
35 | + public function getCellColor($row, $col) | |
36 | + { | |
37 | + if (!isset($this->m_cellColor[$row][$col])) | |
38 | + { | |
39 | + return FALSE; | |
40 | + } | |
41 | + return $this->m_cellColor[$row][$col]; | |
42 | + } | |
43 | + | |
18 | 44 | public function setTableHeader(array $header) |
19 | 45 | { |
20 | 46 | $this->m_header = $header; | ... | ... |
include/RelatorioHTML.php
... | ... | @@ -3,52 +3,71 @@ require_once('Relatorio.php'); |
3 | 3 | |
4 | 4 | class RelatorioHTML extends Relatorio |
5 | 5 | { |
6 | + public function rgb2html($r, $g=-1, $b=-1) | |
7 | + { | |
8 | + if (is_array($r) && sizeof($r) == 3) | |
9 | + list($r, $g, $b) = $r; | |
10 | + | |
11 | + $r = intval($r); $g = intval($g); | |
12 | + $b = intval($b); | |
13 | + | |
14 | + $r = dechex($r<0?0:($r>255?255:$r)); | |
15 | + $g = dechex($g<0?0:($g>255?255:$g)); | |
16 | + $b = dechex($b<0?0:($b>255?255:$b)); | |
17 | + | |
18 | + $color = (strlen($r) < 2?'0':'').$r; | |
19 | + $color .= (strlen($g) < 2?'0':'').$g; | |
20 | + $color .= (strlen($b) < 2?'0':'').$b; | |
21 | + return '#'.$color; | |
22 | + } | |
23 | + | |
6 | 24 | public function output() |
7 | 25 | { |
8 | 26 | $cor = FALSE; |
9 | 27 | $titulo = $this->getTitulo(); |
10 | 28 | ?> |
11 | - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
12 | - <html> | |
29 | + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
30 | + <html> | |
13 | 31 | <head> |
14 | - <?php | |
32 | + <?php | |
15 | 33 | echo "<title>$titulo</title>"; |
16 | - ?> | |
17 | - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
18 | - <script language="JavaScript" type="text/JavaScript"> | |
19 | - <!-- | |
20 | - function MM_openBrWindow(theURL,winName,features) { //v2.0 | |
21 | - window.open(theURL,winName,features); | |
22 | - } | |
23 | - //--> | |
24 | - </script> | |
25 | - </head> | |
26 | - | |
27 | - <body bgcolor="#FFFFFF" topmargin="5"> | |
28 | - <table border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#999999"> | |
29 | - <tr bgcolor="#E1E1E1"> | |
30 | - <td rowspan="5" bgcolor="#FFFFFF"><img src="../../imgs/cacic_logo.png" width="50" height="50"></td> | |
31 | - <td rowspan="5" bgcolor="#FFFFFF"></td> | |
32 | - <td bgcolor="#FFFFFF"> </td> | |
33 | - </tr> | |
34 | + ?> | |
35 | + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
36 | + <script language="JavaScript" type="text/JavaScript"> | |
37 | + <!-- | |
38 | + function MM_openBrWindow(theURL,winName,features) { //v2.0 | |
39 | + window.open(theURL,winName,features); | |
40 | + } | |
41 | + //--> | |
42 | + </script> | |
43 | + </head> | |
44 | + | |
45 | + <body bgcolor="#FFFFFF" topmargin="5"> | |
46 | + <table border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#999999"> | |
47 | + <tr bgcolor="#E1E1E1"> | |
48 | + <td rowspan="5" bgcolor="#FFFFFF"><img src="../../imgs/cacic_logo.png" width="50" height="50"></td> | |
49 | + <td rowspan="5" bgcolor="#FFFFFF"></td> | |
50 | + <td bgcolor="#FFFFFF"> </td> | |
51 | + </tr> | |
34 | 52 | <tr width="100%" bgcolor="#E1E1E1"> |
35 | 53 | <td nowrap bgcolor="#FFFFFF"><font color="#333333" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong><?=$titulo;?></strong></font></td> |
36 | - | |
37 | - </tr> | |
38 | - <tr> | |
39 | - <td height="1" bgcolor="#333333"></td> | |
40 | - <tr> | |
41 | - <td><p align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Gerado | |
42 | - em <? echo date("d/m/Y à\s H:i"); ?></font></p></td> | |
54 | + | |
55 | + </tr> | |
56 | + <tr> | |
57 | + <td height="1" bgcolor="#333333"></td> | |
58 | + | |
59 | + <tr> | |
60 | + <td><p align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Gerado | |
61 | + em <? echo date("d/m/Y à\s H:i"); ?></font></p></td> | |
62 | + </tr> | |
63 | + <tr cellpadding="10" > | |
64 | + <td></td> | |
43 | 65 | </tr> |
44 | - <tr cellpadding="10" > | |
45 | - <td></td> | |
46 | - </tr> | |
47 | 66 | </table> |
48 | - <br> | |
49 | - <br> | |
50 | 67 | <br> |
51 | - <font size="1" face="Verdana, Arial, Helvetica, sans-serif"></tr>Exportar: <a href="?formato=pdf">PDF</a> | <a href="?formato=ods">ODS</a> | <a href="?formato=csv">CSV</a></font> | |
68 | + <br> | |
69 | + <br> | |
70 | + <font size="1" face="Verdana, Arial, Helvetica, sans-serif"></tr>Exportar: <a href="?formato=pdf">PDF</a> | <a href="?formato=ods">ODS</a> | <a href="?formato=csv">CSV</a></font> | |
52 | 71 | <br> |
53 | 72 | <br> |
54 | 73 | <?php |
... | ... | @@ -63,14 +82,22 @@ class RelatorioHTML extends Relatorio |
63 | 82 | echo '</tr>'; |
64 | 83 | |
65 | 84 | //Data |
85 | + $i = 0; | |
66 | 86 | foreach ($this->getBody() as $row) |
67 | 87 | { |
68 | - echo '<tr '; | |
69 | - if ($cor) | |
88 | + $attr = $this->getRowColor($i++); | |
89 | + if (!$attr) | |
70 | 90 | { |
71 | - echo 'bgcolor="#E1E1E1"'; | |
72 | - } | |
73 | - echo '>'; | |
91 | + if ($cor) | |
92 | + { | |
93 | + $attr = 'bgcolor="#E1E1E1"'; | |
94 | + } | |
95 | + } | |
96 | + else | |
97 | + { | |
98 | + $attr = 'bgcolor="'.$this->rgb2html($attr[0], $attr[1], $attr[2]).'"'; | |
99 | + } | |
100 | + echo "<tr $attr>"; | |
74 | 101 | |
75 | 102 | foreach ($row as $cell) |
76 | 103 | { |
... | ... | @@ -84,11 +111,11 @@ class RelatorioHTML extends Relatorio |
84 | 111 | ?> |
85 | 112 | </table> |
86 | 113 | <br><br> |
87 | - <p align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Relatório | |
88 | - gerado pelo <strong>CACIC</strong> - Configurador Automático e Coletor | |
89 | - de Informações Computacionais</font><br> | |
90 | - <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Software desenvolvido pela Dataprev - Unidade Regional Espírito Santo</font></p> | |
91 | - </body> | |
114 | + <p align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Relatório | |
115 | + gerado pelo <strong>CACIC</strong> - Configurador Automático e Coletor | |
116 | + de Informações Computacionais</font><br> | |
117 | + <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Software desenvolvido pela Dataprev - Unidade Regional Espírito Santo</font></p> | |
118 | + </body> | |
92 | 119 | </html> |
93 | 120 | <?php |
94 | 121 | } | ... | ... |
include/RelatorioPDF.php
... | ... | @@ -6,24 +6,21 @@ class PDFMTable extends FPDF |
6 | 6 | { |
7 | 7 | private $widths; |
8 | 8 | private $aligns; |
9 | - private $fill; | |
10 | - | |
11 | - public function PDFMTable() | |
12 | - { | |
13 | - parent::__construct('L', 'mm', 'a3'); | |
14 | - } | |
9 | + | |
10 | + public function PDFMTable() | |
11 | + { | |
12 | + parent::__construct('L', 'mm', 'a3'); | |
13 | + } | |
15 | 14 | |
16 | 15 | function SetWidths($w) |
17 | 16 | { |
18 | 17 | //Set the array of column widths |
19 | - $this->widths=$w; | |
20 | - $fullwidth = 0; | |
21 | - foreach ($w as $wh) | |
22 | - { | |
23 | - $fullwidth += $wh; | |
24 | - } | |
25 | - #$this->hPt=$this->fwPt; | |
26 | - #$this->w = $fullwidth; | |
18 | + $this->widths=$w; | |
19 | + $fullwidth = 0; | |
20 | + foreach ($w as $wh) | |
21 | + { | |
22 | + $fullwidth += $wh; | |
23 | + } | |
27 | 24 | $this->fhPt = ($fullwidth + $this->lMargin + $this->rMargin) * $this->k; |
28 | 25 | } |
29 | 26 | |
... | ... | @@ -33,12 +30,11 @@ class PDFMTable extends FPDF |
33 | 30 | $this->aligns=$a; |
34 | 31 | } |
35 | 32 | |
36 | - function Row($data) | |
33 | + function Row($data, $fillcolor, $fill, $cellColors) | |
37 | 34 | { |
35 | + $this->SetFillColor($fillcolor[0], $fillcolor[1], $fillcolor[2]); | |
38 | 36 | //Calculate the height of the row |
39 | 37 | $nb=0; |
40 | - #for($i=0;$i<count($data);$i++) | |
41 | - # $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i])); | |
42 | 38 | $i = 0; |
43 | 39 | foreach ($data as $value) |
44 | 40 | { |
... | ... | @@ -48,18 +44,17 @@ class PDFMTable extends FPDF |
48 | 44 | $h=5*$nb; |
49 | 45 | //Issue a page break first if needed |
50 | 46 | $this->CheckPageBreak($h); |
51 | - //Draw the cells of the row | |
52 | - #for($i=0;$i<count($data);$i++) | |
53 | - #{ | |
47 | + | |
54 | 48 | $i = 0; |
55 | 49 | foreach ($data as $value) |
56 | 50 | { |
51 | + $this->SetTextColor($cellColors[$i][0], $cellColors[$i][1], $cellColors[$i][2]); | |
57 | 52 | $w=$this->widths[$i]; |
58 | 53 | $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L'; |
59 | 54 | //Save the current position |
60 | 55 | $x=$this->GetX(); |
61 | 56 | $y=$this->GetY(); |
62 | - if ($this->fill) | |
57 | + if ($fill) | |
63 | 58 | { |
64 | 59 | $style = 'DF'; |
65 | 60 | } |
... | ... | @@ -70,12 +65,11 @@ class PDFMTable extends FPDF |
70 | 65 | //Draw the border |
71 | 66 | $this->Rect($x,$y,$w,$h, $style); |
72 | 67 | //Print the text |
73 | - $this->MultiCell($w,5,$value,0,$a/*, $this->fill*/); | |
68 | + $this->MultiCell($w,5,$value,0,$a); | |
74 | 69 | //Put the position to the right of the cell |
75 | 70 | $this->SetXY($x+$w,$y); |
76 | 71 | $i++; |
77 | 72 | } |
78 | - $this->fill = !$this->fill; | |
79 | 73 | //Go to the next line |
80 | 74 | $this->Ln($h); |
81 | 75 | } |
... | ... | @@ -145,9 +139,9 @@ class RelatorioPDF extends Relatorio |
145 | 139 | private function getMaxTextWidth($fpdf) |
146 | 140 | { |
147 | 141 | $maxWidths = array(); |
148 | - $mstr = array(); | |
149 | - $arrays = array(array($this->getHeader()), $this->getBody()); | |
150 | - foreach ($arrays as $array) | |
142 | + $mstr = array(); | |
143 | + $arrays = array(array($this->getHeader()), $this->getBody()); | |
144 | + foreach ($arrays as $array) | |
151 | 145 | { |
152 | 146 | foreach ($array as $row) |
153 | 147 | { |
... | ... | @@ -186,11 +180,30 @@ class RelatorioPDF extends Relatorio |
186 | 180 | } |
187 | 181 | $i++; |
188 | 182 | } |
189 | - } | |
183 | + } | |
190 | 184 | } |
191 | 185 | return $maxWidths; |
192 | 186 | } |
193 | 187 | |
188 | + public function html2rgb($color) | |
189 | + { | |
190 | + if ($color[0] == '#') | |
191 | + $color = substr($color, 1); | |
192 | + | |
193 | + if (strlen($color) == 6) | |
194 | + list($r, $g, $b) = array($color[0].$color[1], | |
195 | + $color[2].$color[3], | |
196 | + $color[4].$color[5]); | |
197 | + elseif (strlen($color) == 3) | |
198 | + list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]); | |
199 | + else | |
200 | + return false; | |
201 | + | |
202 | + $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); | |
203 | + | |
204 | + return array($r, $g, $b); | |
205 | + } | |
206 | + | |
194 | 207 | public function output() |
195 | 208 | { |
196 | 209 | $pdf = new PDFMTable(); |
... | ... | @@ -203,8 +216,8 @@ class RelatorioPDF extends Relatorio |
203 | 216 | $pdf->SetLineWidth(.3); |
204 | 217 | $pdf->SetFont('Arial'); |
205 | 218 | //Header |
206 | - $w = $this->getMaxTextWidth($pdf); | |
207 | - $fullwidth = array_sum($w); | |
219 | + $w = $this->getMaxTextWidth($pdf); | |
220 | + $fullwidth = array_sum($w); | |
208 | 221 | $pdf->AddPage('L'); |
209 | 222 | $pdf->SetWidths($w); |
210 | 223 | |
... | ... | @@ -222,7 +235,9 @@ class RelatorioPDF extends Relatorio |
222 | 235 | $pdf->Ln(); |
223 | 236 | //Color and font restoration |
224 | 237 | $pdf->SetFillColor(224, 235, 255); |
225 | - $pdf->SetTextColor(0); | |
238 | + $defaultFillColor = array(224, 235, 255); | |
239 | + $defaultTextColor = 0; | |
240 | + $pdf->SetTextColor($defaultTextColor); | |
226 | 241 | $pdf->SetFont('Arial'); |
227 | 242 | //Data |
228 | 243 | $fill = 0; |
... | ... | @@ -231,31 +246,26 @@ class RelatorioPDF extends Relatorio |
231 | 246 | $size = count($body); |
232 | 247 | for ($i = 0; $i < $size; $i++) |
233 | 248 | { |
234 | - #echo 'ROW: '.$i.'<BR>'; | |
235 | 249 | $row = &$body[$i]; |
236 | - //unset($body[$i]); | |
237 | - //$px = $pdf->GetX(); | |
238 | - //$py = $pdf->GetY(); | |
239 | - //for ($i = 0; $i < count($row); $i++) | |
240 | - //{ | |
241 | - // $pn = $pdf->PageNo(); | |
242 | - // $pdf->MultiCell($w[$i], 6, iconv('utf-8' ,'iso-8859-1', /*'X: '.$px.*/'Y: '.$py/*$row[$i]*/), 1, 'L', $fill); | |
243 | - // $px += $w[$i]; | |
244 | - // if ($pdf->PageNo() > $pn) | |
245 | - // { | |
246 | - // $py = 0; | |
247 | - // } | |
248 | - // $pdf->SetXY($px, $py); | |
249 | - //} | |
250 | + $fillcolor = $defaultFillColor; | |
251 | + $color = $this->getRowColor($i); | |
252 | + if ($color) | |
253 | + { | |
254 | + $fillcolor = $color; | |
255 | + $fill = 1; | |
256 | + } | |
250 | 257 | $count = count($row); |
258 | + $j = 0; | |
259 | + $cellColors = array(); | |
251 | 260 | foreach ($row as $key => $value) |
252 | 261 | { |
262 | + $cellColors[$j] = $this->getCellColor($i, $j); | |
253 | 263 | $row[$key] = $this->relstrip($value);// iconv('utf-8' ,'iso-8859-1', 'AAA'/*strip_tags($row[$j])*/); |
264 | + $j++; | |
254 | 265 | } |
255 | - $pdf->Row($row); | |
266 | + $pdf->Row($row, $fillcolor, $fill, $cellColors); | |
256 | 267 | $fill = !$fill; |
257 | 268 | } |
258 | - //$pdf->Cell(array_sum($w), 0, '', 'T'); | |
259 | 269 | |
260 | 270 | $pdf->Output('relatorio.pdf', 'D'); |
261 | 271 | } | ... | ... |
include/fpdf.php
... | ... | @@ -1036,7 +1036,7 @@ function Output($name='',$dest='') |
1036 | 1036 | else |
1037 | 1037 | header('Content-Type: application/octet-stream'); |
1038 | 1038 | if(headers_sent()) |
1039 | - $this->Error('Saome data has already been output to browser, cant send PDF file'); | |
1039 | + $this->Error('Some data has already been output to browser, cant send PDF file'); | |
1040 | 1040 | header('Content-Length: '.strlen($this->buffer)); |
1041 | 1041 | header('Content-disposition: attachment; filename="'.$name.'"'); |
1042 | 1042 | echo $this->buffer; | ... | ... |
relatorios/patrimonio/rel_patrimonio.php
... | ... | @@ -19,73 +19,34 @@ session_start(); |
19 | 19 | */ |
20 | 20 | if(!isset($_SESSION['id_usuario'])) |
21 | 21 | die('Acesso negado (Access denied)!'); |
22 | -else { // Inserir regras para outras verificações (ex: permissões do usuário)! | |
23 | -} | |
22 | +else | |
23 | + { // Inserir regras para outras verificações (ex: permissões do usuário)! | |
24 | + } | |
25 | +require_once('../../include/library.php'); | |
24 | 26 | |
25 | 27 | if($_POST['submit']) |
26 | 28 | { |
27 | - $_SESSION["list2"] = $_POST['list2']; | |
28 | - $_SESSION["list4"] = $_POST['list4']; | |
29 | - $_SESSION["list6"] = $_POST['list6']; | |
30 | - $_SESSION["list6o"] = $_POST['list6']; | |
31 | - $_SESSION["list8"] = $_POST['list8']; | |
32 | - $_SESSION["list12"] = $_POST['list12']; | |
33 | - $_SESSION["cs_situacao"] = $_POST["cs_situacao"]; | |
34 | - $_SESSION['orderby'] = ''; | |
35 | - $_SESSION['post'] = $_POST; | |
36 | -} | |
29 | + $_SESSION["list2"] = $_POST['list2']; | |
30 | + $_SESSION["list4"] = $_POST['list4']; | |
31 | + $_SESSION["list6"] = $_POST['list6']; | |
32 | + $_SESSION["list6o"] = $_POST['list6']; | |
33 | + $_SESSION["list8"] = $_POST['list8']; | |
34 | + $_SESSION["list12"] = $_POST['list12']; | |
35 | + $_SESSION["cs_situacao"] = $_POST["cs_situacao"]; | |
36 | + $_SESSION['orderby'] = ''; | |
37 | + $_SESSION['post'] = $_POST; | |
38 | + } | |
37 | 39 | else |
38 | -{ | |
39 | - $_SESSION["list6"] = $_SESSION['list6o']; | |
40 | -} | |
41 | - | |
42 | -?> | |
43 | -<html> | |
44 | -<head> | |
45 | -<title>Relatório de informações de Patrimônio e Localização Física </title> | |
46 | -<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
47 | -<script language="JavaScript" type="text/JavaScript"> | |
48 | -<!-- | |
49 | -function MM_openBrWindow(theURL,winName,features) { //v2.0 | |
50 | - window.open(theURL,winName,features); | |
51 | -} | |
52 | -//--> | |
53 | -</script> | |
54 | -</head> | |
55 | - | |
56 | -<body bgcolor="#FFFFFF" topmargin="5"> | |
57 | -<table border="0" align="default" cellpadding="0" cellspacing="0" bordercolor="#999999"> | |
58 | - <tr bgcolor="#E1E1E1"> | |
59 | - <td rowspan="5" bgcolor="#FFFFFF"> </td> | |
60 | - <td rowspan="5" bgcolor="#FFFFFF"><img src="../../imgs/cacic_logo.png" width="50" height="50"></td> | |
61 | - <td bgcolor="#FFFFFF"> </td> | |
62 | - </tr> | |
63 | - <tr bgcolor="#E1E1E1"> | |
64 | - <td nowrap bgcolor="#FFFFFF"><font color="#333333" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>CACIC | |
65 | - - Relatório de informações de Patrimônio e Localização | |
66 | - Física </strong></font></td> | |
67 | - </tr> | |
68 | - <tr> | |
69 | - <td height="1" bgcolor="#333333"></td> | |
70 | - </tr> | |
71 | - <tr> | |
72 | - <td><p><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Gerado | |
73 | - em <? echo date("d/m/Y à\s H:i"); ?></font></p></td> | |
74 | - </tr> | |
75 | -</table> | |
76 | -<br> | |
77 | -<? | |
78 | -require_once('../../include/library.php'); | |
79 | -require_once('../../include/RelatorioHTML.php'); | |
80 | -require_once('../../include/RelatorioPDF.php'); | |
81 | -require_once('../../include/RelatorioODS.php'); | |
82 | -require_once('../../include/RelatorioCSV.php'); | |
40 | + { | |
41 | + GravaTESTES('Entrei 2...'); | |
42 | + $_SESSION["list6"] = $_SESSION['list6o']; | |
43 | + GravaTESTES('Entrei 2a...'); | |
44 | + } | |
83 | 45 | conecta_bd_cacic(); |
84 | 46 | |
85 | 47 | $redes_selecionadas = ''; |
86 | 48 | if ($_SESSION['cs_nivel_administracao']<>1 && $_SESSION['cs_nivel_administracao']<>2) |
87 | 49 | { |
88 | - | |
89 | 50 | //if($_SESSION["cs_situacao"] == 'S') |
90 | 51 | //{ |
91 | 52 | // Aqui pego todas as redes selecionadas e faço uma query p/ condição de redes |
... | ... | @@ -348,19 +309,32 @@ else |
348 | 309 | |
349 | 310 | $relatorio->setTitulo('CACIC - Relatório de informações de Patrimônio e Localização Física'); |
350 | 311 | |
312 | + // String com nomes dos campos que não devem ser mostrados, concatenando-os com # para fins de busca em substring. | |
313 | + $strNaoMostrarCamposNomes = '#dt_hr_alteracao#'; | |
314 | + | |
315 | + // String para indices das colunas que não serão mostradas, concatenando-os com # para fins de busca em substring. | |
316 | + $strNaoMostrarCamposIndices = ''; | |
317 | + | |
351 | 318 | $in_destacar_duplicidade_tmp = ''; |
319 | + | |
352 | 320 | $header = array('#'); |
321 | + | |
322 | + //Table Header | |
353 | 323 | for ($i=4; $i < mysql_num_fields($result); $i++) |
354 | - { //Table Header | |
355 | - $header[] = '<font size="1" face="Verdana, Arial"><b><a href="?orderby=' . ($i + 1) . '">'. mysql_field_name($result, $i) .'</a></b></font>'; | |
356 | - if ($in_destacar_duplicidade_total && in_array(mysql_field_name($result, $i), $arr_in_destacar_duplicidade_total)) | |
357 | 324 | { |
358 | - if ($in_destacar_duplicidade_tmp) $in_destacar_duplicidade_tmp .= '#'; | |
359 | - $in_destacar_duplicidade_tmp .= $i; | |
325 | + $boolNaoMostrar = stripos2($strNaoMostrarCamposNomes,'#'.mysql_field_name($result, $i).'#',false); | |
326 | + if (!$boolNaoMostrar) | |
327 | + { | |
328 | + $header[] = '<font size="1" face="Verdana, Arial"><b><a href="?orderby=' . ($i + 1) . '">'. mysql_field_name($result, $i) .'</a></b></font>'; | |
329 | + if ($in_destacar_duplicidade_total && in_array(mysql_field_name($result, $i), $arr_in_destacar_duplicidade_total)) | |
330 | + { | |
331 | + if ($in_destacar_duplicidade_tmp) $in_destacar_duplicidade_tmp .= '#'; | |
332 | + $in_destacar_duplicidade_tmp .= $i; | |
333 | + } | |
334 | + } | |
335 | + else | |
336 | + $strNaoMostrarCamposIndices .= '#'.$i.'#'; | |
360 | 337 | } |
361 | - } | |
362 | -else | |
363 | - { | |
364 | 338 | |
365 | 339 | $relatorio->setTableHeader($header); |
366 | 340 | |
... | ... | @@ -368,30 +342,23 @@ else |
368 | 342 | @mysql_data_seek($result,0); |
369 | 343 | $table = array(); |
370 | 344 | while ($row = mysql_fetch_row($result)) |
371 | - {//pre Table body | |
345 | + {//pre Table body | |
372 | 346 | |
373 | 347 | // ja existe entrada para este MAC? |
374 | 348 | if (isset($table[$row[0]])) |
375 | - { | |
349 | + { | |
376 | 350 | // acesso mais rencente? |
377 | 351 | if ($row[2] > $table[$row[0]][2]) |
378 | - { | |
379 | 352 | $table[$row[0]] = $row; |
380 | - } | |
353 | + | |
354 | + // desempatar pela entrada de patrimonio mais recente | |
381 | 355 | if ($row[2] == $table[$row[0]][2]) |
382 | - { | |
383 | - // desempatar pela entrada de patrimonio mais recente | |
384 | 356 | if ($row[3] > $table[$row[0]][3]) |
385 | - { | |
386 | 357 | $table[$row[0]] = $row; |
387 | - } | |
388 | 358 | } |
389 | - } | |
390 | 359 | else |
391 | - { | |
392 | 360 | $table[$row[0]] = $row; |
393 | 361 | } |
394 | - } | |
395 | 362 | |
396 | 363 | if ($in_destacar_duplicidade_tmp) |
397 | 364 | { |
... | ... | @@ -399,99 +366,89 @@ else |
399 | 366 | $v_arr_campos_valores = array(); |
400 | 367 | $num_registro = 1; |
401 | 368 | foreach ($table as $row) |
402 | - { | |
403 | - for ($i = 5; $i < $fields; $i++) | |
404 | 369 | { |
370 | + for ($i = 5; $i < $fields; $i++) | |
405 | 371 | if (trim($row[$i])<>'' && in_array($i,$arr_in_destacar_duplicidade)) |
406 | - { | |
407 | 372 | array_push($v_arr_campos_valores,$i . ',' . trim(strtolower($row[$i]))); |
408 | - } | |
409 | 373 | } |
410 | - $num_registro ++; | |
411 | 374 | } |
412 | - $v_arr_total_campos_valores = array(); | |
413 | - $v_arr_total_campos_valores = array_count_values($v_arr_campos_valores); | |
375 | + $v_arr_total_campos_valores = array(); | |
376 | + $v_arr_total_campos_valores = array_count_values($v_arr_campos_valores); | |
414 | 377 | |
415 | - $num_registro = 1; | |
416 | - $registros_valores_duplicados = array(); | |
417 | - foreach ($table as $row) | |
378 | + $num_registro = 1; | |
379 | + $registros_valores_duplicados = array(); | |
380 | + | |
381 | + foreach ($table as $row) | |
418 | 382 | { |
419 | - for ($i = 5; $i < $fields; $i++) | |
383 | + for ($i = 5; $i < $fields; $i++) | |
420 | 384 | { |
421 | - if (trim($row[$i]) != '' && in_array($i, $arr_in_destacar_duplicidade)) | |
385 | + if (trim($row[$i]) != '' && in_array($i, $arr_in_destacar_duplicidade)) | |
422 | 386 | { |
423 | - $v_chave = $i . ',' . trim($row[$i]); | |
424 | - // se o valor aparece mais de 1 vez | |
425 | - if ($v_arr_total_campos_valores[strtolower($v_chave)] > 1) | |
387 | + $v_chave = $i . ',' . trim($row[$i]); | |
388 | + // se o valor aparece mais de 1 vez | |
389 | + if ($v_arr_total_campos_valores[strtolower($v_chave)] > 1) | |
426 | 390 | { |
427 | - if (!isset($registros_valores_duplicados[$num_registro])) | |
428 | - { | |
429 | - $registros_valores_duplicados[$num_registro] = array(); | |
430 | - } | |
431 | - $registros_valores_duplicados[$num_registro][] = $i; | |
391 | + if (!isset($registros_valores_duplicados[$num_registro])) | |
392 | + $registros_valores_duplicados[$num_registro] = array(); | |
393 | + | |
394 | + $registros_valores_duplicados[$num_registro][] = $i; | |
432 | 395 | } |
433 | 396 | } |
434 | 397 | } |
435 | - $num_registro++; | |
398 | + $num_registro++; | |
436 | 399 | } |
437 | - } | |
438 | 400 | |
439 | 401 | $cor = FALSE; |
440 | 402 | $num_registro = 1; |
441 | 403 | foreach ($table as $key => $row) |
442 | - { //Table body | |
443 | - $possuiCampoDuplicado = isset($registros_valores_duplicados[$num_registro]); | |
444 | - if ($possuiCampoDuplicado) | |
445 | - { | |
446 | - $relatorio->setRowColor($num_registro - 1, 0xFF, 0xFF, 0x99); //'bgcolor="#FFFF99"'); | |
447 | - } | |
448 | - | |
404 | + { //Table body | |
449 | 405 | $c1 = '<font size="1" face="Verdana, Arial">' . $num_registro . '</font>'; |
450 | 406 | $c2 = "<font size='1' face='Verdana, Arial'><a href='../computador/computador.php?te_node_address=". $row[0] ."&id_so=". $row[1] ."' target='_blank'>" . $row[4] ."</a>"; |
451 | - | |
452 | 407 | unset($row[0]); |
453 | 408 | unset($row[1]); |
454 | 409 | unset($row[2]); |
455 | 410 | unset($row[3]); |
456 | 411 | unset($row[4]); |
457 | - for ($i=5; $i < $fields; $i++) | |
458 | - { | |
459 | - $cell = '<font size="1" face="Verdana, Arial"'; | |
460 | - $campoDuplicado = FALSE; | |
461 | - | |
462 | - if ($possuiCampoDuplicado) | |
463 | - { | |
464 | - if (in_array($i, $registros_valores_duplicados[$num_registro])) | |
465 | - { | |
466 | - $cell .= 'color="#FF0000" '; | |
467 | - $campoDuplicado = TRUE; | |
468 | - $relatorio->setCellColor($num_registro - 1, $i - 3, array(0xFF, 0, 0)); | |
469 | - } | |
470 | - } | |
471 | - | |
472 | - $cell .= '>'; | |
473 | - if ($campoDuplicado) | |
474 | - { | |
475 | - $cell .= '<b>'; | |
476 | - } | |
477 | - $cell .= $row[$i]; | |
478 | - | |
479 | - if ($campoDuplicado) | |
480 | - { | |
481 | - $cell .= '</b>'; | |
482 | - } | |
483 | - | |
484 | - $row[$i] = $cell; | |
485 | - } | |
486 | - | |
412 | + | |
413 | + for ($i=4; $i < $fields; $i++) | |
414 | + { | |
415 | + $campoDuplicado = FALSE; | |
416 | + $boolNaoMostrar = stripos2($strNaoMostrarCamposIndices,'#'.$i.'#',false); | |
417 | + if (!$boolNaoMostrar) | |
418 | + { | |
419 | + $possuiCampoDuplicado = isset($registros_valores_duplicados[$num_registro]); | |
420 | + if ($possuiCampoDuplicado) | |
421 | + $relatorio->setRowColor($num_registro - 1, 0xFF, 0xFF, 0x99); //'bgcolor="#FFFF99"'); | |
422 | + | |
423 | + $cell = '<font size="1" face="Verdana, Arial"'; | |
424 | + | |
425 | + if ($possuiCampoDuplicado) | |
426 | + if (in_array($i, $registros_valores_duplicados[$num_registro])) | |
427 | + { | |
428 | + $cell .= 'color="#FF0000" '; | |
429 | + $campoDuplicado = TRUE; | |
430 | + $relatorio->setCellColor($num_registro - 1, $i - 3, array(0xFF, 0, 0)); | |
431 | + } | |
432 | + | |
433 | + $cell .= '>'; | |
434 | + if ($campoDuplicado) | |
435 | + $cell .= '<b>'; | |
436 | + | |
437 | + $cell .= $row[$i]; | |
438 | + if ($campoDuplicado) | |
439 | + $cell .= '</b>'; | |
440 | + $row[$i] = $cell; | |
441 | + $cell = ''; | |
442 | + } | |
443 | + else | |
444 | + unset($row[$i]); | |
445 | + } | |
487 | 446 | array_unshift($row, $c1, $c2); |
488 | 447 | $relatorio->addRow($row); |
489 | 448 | $cor = !$cor; |
490 | - $num_registro++; | |
491 | - | |
492 | - | |
493 | - } | |
449 | + $num_registro++; | |
450 | + } | |
494 | 451 | |
495 | 452 | $relatorio->output(); |
496 | -} | |
497 | -?> | |
453 | + } | |
454 | + ?> | |
498 | 455 | \ No newline at end of file | ... | ... |