-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathreport_vendor_model.php
277 lines (221 loc) · 10.3 KB
/
report_vendor_model.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
require_once "db.inc.php";
require_once "facilities.inc.php";
$person = People::Current();
// Get the parameters for the report of none have been specified
if (!isset($_REQUEST['action'])){
?>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>openDCIM Vendor/Model Reporting</title>
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css">
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery-ui.min.js"></script>
</head>
<body>
<?php include( 'header.inc.php' ); ?>
<?php
include( 'sidebar.inc.php' );
$m = new Manufacturer();
$manList = $m->GetManufacturerList();
?>
</div>
<div class="main">
<h2>openDCIM</h2>
<h3>Vendor Model Report</h3>
<form method="post">
<div class="table">
<div>
<div></div>
<?php
print "<div>" . __("Please select the values to limit the report scope as indicated below.") . "</div></div>";
print "<div><div>" . __("Manufacturer") . "</div><div>";
print "<select name=\"manufacturerid\"><option value=0>All</option>";
foreach ( $manList as $man ) {
printf( "<option value=%d>%s</option>\n", $man->ManufacturerID, $man->Name );
}
print "</select></div></div>";
print "<div><div>" . __("Device Type") . "</div><div>";
print "<select name=\"devicetype\"><option value=\"all\">All</option>";
foreach ( array( "Server", "Appliance", "Storage Array", "Switch", "Chassis", "Patch Panel", "Physical Infrastructure", "CDU", "Sensor" ) as $devType ) {
printf( "<option value=\"%s\">%s</option>\n", $devType, $devType );
}
print "</select></div></div>";
?>
<div>
<div></div>
<div><input type="submit" name="action" value="Submit"></div>
</div>
</form>
<?php
} else {
// Check to see if someone tried to pass the URL through but forgot the important stuff
if ( ! isset( $_REQUEST['manufacturerid'] ) || ! isset( $_REQUEST['devicetype'])) {
// Redirect to the same page, but strip off the invalid parameters
echo "<meta http-equiv='refresh' content='0; url=report_vendor_model.php'>";
exit;
}
$man = new Manufacturer();
$manID = intval( $_REQUEST['manufacturerid'] );
$dType = in_array( $_REQUEST['devicetype'], array( "Server", "Appliance", "Storage Array", "Switch", "Chassis", "Patch Panel", "Physical Infrastructure", "CDU", "Sensor", "All"))?$_REQUEST['devicetype']:"All";
if ( $manID > 0 ) {
$man->ManufacturerID = $manID;
$man->GetManufacturerByID();
$mfgName = $man->Name;
} else {
$mfgName = "All";
}
$workBook = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$workBook->getProperties()->setCreator("openDCIM");
$workBook->getProperties()->setLastModifiedBy("openDCIM");
$workBook->getProperties()->setTitle("Data Center Inventory Export");
$workBook->getProperties()->setSubject("Vendor Model Export");
$workBook->getProperties()->setDescription("Export of the openDCIM database based upon user filtered criteria.");
// Start off with the TPS Cover Page
$workBook->setActiveSheetIndex(0);
$sheet = $workBook->getActiveSheet();
$sheet->SetTitle('Front Page');
// add logo
$objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$objDrawing->setWorksheet($sheet);
$objDrawing->setName("Logo");
$objDrawing->setDescription("Logo");
$apath = __DIR__ . DIRECTORY_SEPARATOR ;
$objDrawing->setPath($apath . $config->ParameterArray['PDFLogoFile'], true);
$objDrawing->setCoordinates('A1');
$objDrawing->setOffsetX(5);
$objDrawing->setOffsetY(5);
$logoHeight = getimagesize( $apath . $config->ParameterArray['PDFLogoFile']);
$sheet->getRowDimension('1')->setRowHeight($logoHeight[1]);
// set the header of the print out
$header_range = "A1:B2";
$fillcolor = $config->ParameterArray['HeaderColor'];
$fillcolor = (strpos($fillcolor, '#') == 0) ? substr($fillcolor, 1) : $fillcolor;
$sheet->getStyle($header_range)
->getFill()
->getStartColor()
->setRGB($fillcolor);
$org_font_size = 20;
$sheet->setCellValue('A2', $config->ParameterArray['OrgName']);
$sheet->getStyle('A2')
->getFont()
->setSize($org_font_size);
$sheet->getStyle('A2')
->getFont()
->setBold(true);
$sheet->getRowDimension('2')->setRowHeight($org_font_size + 2);
$sheet->setCellValue('A4', 'Report generated by \''
. $person->UserID
. '\' on ' . date('Y-m-d H:i:s'));
// Add text about the report itself
$sheet->setCellValue('A7', 'Notes');
$sheet->getStyle('A7')
->getFont()
->setSize(14);
$sheet->getStyle('A7')
->getFont()
->setBold(true);
$remarks = array( __("This is the Vendor(Manufacturer)/Model report from openDCIM."),
__("Each manufacturer is listed in a separate worksheet, with devices listed lexicographically by Label."),
__("The criteria given for this report is:"),
__("Manufacturer:") . $mfgName,
__("Device Type:") . $dType );
$max_remarks = count($remarks);
$offset = 8;
for ($idx = 0; $idx < $max_remarks; $idx ++) {
$row = $offset + $idx;
$sheet->setCellValueExplicit('B' . ($row),
$remarks[$idx],
\PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
}
$sheet->getStyle('B' . $offset . ':B' . ($offset + $max_remarks - 1))
->getAlignment()
->setWrapText(true);
$sheet->getColumnDimension('B')->setWidth(120);
$sheet->getTabColor()->setRGB($fillcolor);
// Now the real data for the report
$dev = new Device();
$cab = new Cabinet();
$dc = new DataCenter();
$dep = new Department();
$dcList = $dc->Search( true );
$cabList = $cab->Search( true );
$depList = $dep->Search( true );
if ( $manID == 0 ) {
$manList = $man->GetManufacturerList();
} else {
$man->ManufacturerID = $manID;
$man->GetManufacturerByID();
$manList = array( $man );
}
// Build out the column mapping
$columnList = array( "Label"=>"A", "Model"=>"B", "DeviceType"=>"C", "DataCenter"=>"D", "Cabinet"=>"E", "Position"=>"F", "Height"=>"G", "Department"=>"H", "SerialNo"=>"I", "AssetTag"=>"J", "Status"=>"K", "InstallDate"=>"L", "Hypervisor"=>"M" );
$DCAList = DeviceCustomAttribute::GetDeviceCustomAttributeList();
// In case we tweak the number of base columns before the Custom Attributes, this keeps us from having to update the math
$columnNum = count($columnList);
foreach( $DCAList as $dca ) {
$colName = getNameFromNumber(++$columnNum);
$labelName = $dca->Label;
$columnList[$labelName] = $colName;
}
foreach( $manList as $mfg ) {
$dt = new DeviceTemplate();
$dt->ManufacturerID = $mfg->ManufacturerID;
$templateList = $dt->Search();
if ( sizeof($templateList) > 0 ) {
$sheet = $workBook->createSheet(null);
$sheet->setTitle( $mfg->Name );
foreach( $columnList as $fieldName=>$columnName ) {
$cellAddr = $columnName."1";
$sheet->setCellValue( $cellAddr, $fieldName );
}
$currRow = 2;
foreach ( $templateList as $t ) {
$dev = new Device();
$dev->TemplateID = $t->TemplateID;
if ( $dType != "All" ) {
$dev->DeviceType = $dType;
}
$devList = $dev->Search();
foreach ( $devList as $d ) {
foreach( $d as $prop=>$val ) {
if ( array_key_exists( $prop, $columnList )) {
$sheet->setCellValue( $columnList[$prop].$currRow, $val );
}
}
$sheet->setCellValue( $columnList["Model"].$currRow, $t->Model );
if ( $d->Cabinet == -1 ) {
$sheet->setCellValue( $columnList["Cabinet"].$currRow, "Storage" );
$sheet->setCellValue( $columnList["DataCenter"].$currRow, $dcList[$d->Position]->Name);
} else {
$thisCab = $cabList[$d->Cabinet];
$sheet->setCellValue( $columnList["Cabinet"].$currRow, $thisCab->Location);
$sheet->setCellValue( $columnList["DataCenter"].$currRow, $dcList[$thisCab->DataCenterID]->Name);
}
$sheet->setCellValue( $columnList["Department"].$currRow, $depList[$d->Owner]->Name );
$currRow++;
}
}
foreach( $columnList as $i => $v ) {
$sheet->getColumnDimension($v)->setAutoSize(true);
}
if ( $currRow == 2 ) {
// Nothing got added, so delete this sheet
$workBook->removeSheetByIndex(
$workBook->getIndex(
$workBook->getSheetByName($mfg->Name)));
}
}
}
// Now finalize it and send to the client
$workBook->setActiveSheetIndex(0);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header( sprintf( "Content-Disposition: attachment;filename=\"opendcim-%s.xlsx\"", date( "YmdHis" ) ) );
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($workBook);
$writer->save('php://output');
}
?>