forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_power_distribution.php
224 lines (189 loc) · 6.23 KB
/
report_power_distribution.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
require_once( 'db.inc.php' );
require_once( 'facilities.inc.php' );
define('FPDF_FONTPATH','font/');
require('fpdf.php');
class PDF extends FPDF {
var $outlines=array();
var $OutlineRoot;
var $pdfconfig;
var $pdfDB;
function PDF(){
parent::FPDF();
}
function Header() {
$this->pdfconfig = new Config();
$this->Image( 'images/' . $this->pdfconfig->ParameterArray['PDFLogoFile'],10,8,100);
$this->SetFont($this->pdfconfig->ParameterArray['PDFfont'],'B',12);
$this->Cell(120);
$this->Cell(30,20,'Information Technology Services',0,0,'C');
$this->Ln(20);
$this->SetFont( $this->pdfconfig->ParameterArray['PDFfont'],'',10 );
$this->Cell( 50, 6, 'Power Distribution By Data Center', 0, 1, 'L' );
$this->Cell( 50, 6, 'Date: ' . date( 'm/d/y' ), 0, 1, 'L' );
$this->Ln(10);
}
function Footer() {
$this->SetY(-15);
$this->SetFont($this->pdfconfig->ParameterArray['PDFfont'],'I',8);
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
function Bookmark($txt,$level=0,$y=0) {
if($y==-1)
$y=$this->GetY();
$this->outlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->PageNo());
}
function _putbookmarks() {
$nb=count($this->outlines);
if($nb==0)
return;
$lru=array();
$level=0;
foreach($this->outlines as $i=>$o)
{
if($o['l']>0)
{
$parent=$lru[$o['l']-1];
//Set parent and last pointers
$this->outlines[$i]['parent']=$parent;
$this->outlines[$parent]['last']=$i;
if($o['l']>$level)
{
//Level increasing: set first pointer
$this->outlines[$parent]['first']=$i;
}
}
else
$this->outlines[$i]['parent']=$nb;
if($o['l']<=$level and $i>0)
{
//Set prev and next pointers
$prev=$lru[$o['l']];
$this->outlines[$prev]['next']=$i;
$this->outlines[$i]['prev']=$prev;
}
$lru[$o['l']]=$i;
$level=$o['l'];
}
//Outline items
$n=$this->n+1;
foreach($this->outlines as $i=>$o)
{
$this->_newobj();
$this->_out('<</Title '.$this->_textstring($o['t']));
$this->_out('/Parent '.($n+$o['parent']).' 0 R');
if(isset($o['prev']))
$this->_out('/Prev '.($n+$o['prev']).' 0 R');
if(isset($o['next']))
$this->_out('/Next '.($n+$o['next']).' 0 R');
if(isset($o['first']))
$this->_out('/First '.($n+$o['first']).' 0 R');
if(isset($o['last']))
$this->_out('/Last '.($n+$o['last']).' 0 R');
$this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]',1+2*$o['p'],($this->h-$o['y'])*$this->k));
$this->_out('/Count 0>>');
$this->_out('endobj');
}
//Outline root
$this->_newobj();
$this->OutlineRoot=$this->n;
$this->_out('<</Type /Outlines /First '.$n.' 0 R');
$this->_out('/Last '.($n+$lru[0]).' 0 R>>');
$this->_out('endobj');
}
function _putresources()
{
parent::_putresources();
$this->_putbookmarks();
}
function _putcatalog()
{
parent::_putcatalog();
if(count($this->outlines)>0)
{
$this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
$this->_out('/PageMode /UseOutlines');
}
}
}
//
//
// Begin Report Generation
//
//
$pan = new PowerPanel();
$pdu = new PowerDistribution();
$source = new PowerSource();
$dev = new Device();
$cab = new Cabinet();
$dept = new Department();
$dc = new DataCenter();
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->SetFont($config->ParameterArray['PDFfont'],'',8);
$pdf->SetFillColor( 0, 0, 0 );
$pdf->SetTextColor( 255 );
$pdf->SetDrawColor( 128, 0, 0 );
$pdf->SetLineWidth( .3 );
$pdf->SetfillColor( 224, 235, 255 );
$pdf->SetTextColor( 0 );
$pdf->Bookmark( 'Data Centers' );
$dcList = $dc->GetDCList();
foreach ( $dcList as $dcRow ) {
$pdf->AddPage();
$pdf->BookMark( $dcRow->Name, 1 );
$pdf->SetFont( $config->ParameterArray['PDFfont'], 'BU', 12 );
$pdf->Cell( 80, 5, 'Data Center: ' . $dcRow->Name );
$pdf->SetFont( $config->ParameterArray['PDFfont'], '', 8 );
$source->DataCenterID = $dcRow->DataCenterID;
$sourceList = $source->GetSourcesByDataCenter();
foreach ( $sourceList as $sourceRow ) {
$pdf->BookMark( $sourceRow->SourceName, 2 );
$pdf->Ln();
$pdf->SetFont( $config->ParameterArray['PDFfont'], 'U', 12 );
$pdf->Cell( 80, 5, 'Power Source: ' . $sourceRow->SourceName );
$pdf->SetFont( $config->ParameterArray['PDFfont'], '', 8 );
$pdf->Ln();
$pan->PowerSourceID = $sourceRow->PowerSourceID;
$panList = $pan->GetPanelListBYSource();
foreach ( $panList as $panRow ) {
$pdf->BookMark( $panRow->PanelLabel, 3 );
$pdf->Ln();
$pdf->SetFont( $config->ParameterArray['PDFfont'], 'U', 12 );
$pdf->Cell( 80, 5, 'Panel: ' . $panRow->PanelLabel );
$pdf->SetFont( $config->ParameterArray['PDFfont'], '', 8 );
$pdf->Ln();
$pdu->PanelID=$panRow->PanelID;
$pduList = $pdu->GetPDUbyPanel();
foreach ( $pduList as $pduRow ){
$pdf->BookMark( $pduRow->Label, 4 );
$pdf->Ln();
$pdf->SetFont( $config->ParameterArray['PDFfont'], '', 12 );
$pdf->Cell( 80, 5, 'PDU: ' . $pduRow->Label );
$pdf->SetFont( $config->ParameterArray['PDFfont'], '', 8 );
$pdf->Ln();
$dev->Cabinet=$pduRow->CabinetID;
$devList=$dev->ViewDevicesByCabinet();
$headerTags = array( 'Power Source', 'Panel', 'PDU', 'Device');
$cellWidths = array( 40, 30, 30, 60 );
$maxval = count( $headerTags );
for ( $col = 0; $col < $maxval; $col++ )
$pdf->Cell( $cellWidths[$col], 7, $headerTags[$col], 1, 0, 'C', 1 );
$pdf->Ln();
$fill = 0;
foreach( $devList as $devRow){
$pdf->Cell( $cellWidths[0], 6, $sourceRow->SourceName, 'LBRT', 0, 'L', $fill );
$pdf->Cell( $cellWidths[1], 6, $panRow->PanelLabel, 'LBRT', 0, 'L', $fill );
$pdf->Cell( $cellWidths[2], 6, $pduRow->Label, 'LBRT', 0, 'L', $fill );
$pdf->Cell( $cellWidths[3], 6, $devRow->Label, 'LBRT', 1, 'L', $fill );
$fill =! $fill;
}
$pdf->Ln();
}
$pdf->Ln();
}
$pdf->Ln();
}
}
$pdf->Output();
?>