forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_port_connections.php
217 lines (177 loc) · 7.39 KB
/
export_port_connections.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
<?php
require_once( "db.inc.php" );
require_once( "facilities.inc.php" );
require_once( "PHPExcel/PHPExcel.php" );
require_once( "PHPExcel/PHPExcel/Writer/Excel2007.php" );
$user=new User();
$user->UserID=$_SERVER["REMOTE_USER"];
$user->GetUserRights();
if((isset($_REQUEST["deviceid"]) && ($_REQUEST["deviceid"]=="" || $_REQUEST["deviceid"]==null)) || !isset($_REQUEST["deviceid"])){
// No soup for you.
header('Location: '.redirect());
exit;
}
$devTmpl = new DeviceTemplate();
$cab = new Cabinet();
$mfg = new Manufacturer();
$devList = array();
if ( $_REQUEST["deviceid"] == "wo" ) {
// Special case, we are printing all connections for a work order, which has a cookie associated with it
$woList = json_decode( $_COOKIE["workOrder"] );
foreach($woList as $woDev){
$dev=new Device();
$dev->DeviceID=$woDev;
if($dev->GetDevice()){
$devList[]=$dev;
}
}
} else {
$devList[0] = new Device();
$devList[0]->DeviceID = $_REQUEST["deviceid"];
if ( ! $devList[0]->GetDevice() ) {
// Not a valid device ID
header('Location: '.redirect());
exit;
}
}
$sheet = new PHPExcel();
$sheet->getProperties()->setCreator("openDCIM");
$sheet->getProperties()->setLastModifiedBy("openDCIM");
$sheet->getProperties()->setTitle(__("Device Port Connections"));
$sheet->getProperties()->setSubject(__("Device Port Detail"));
$sheet->setActiveSheetIndex(0);
$sheet->getActiveSheet()->SetCellValue('A1',__("SourceDevice"));
$sheet->getActiveSheet()->SetCellValue('B1',__("SourcePort"));
$sheet->getActiveSheet()->SetCellValue('C1',__("TargetDevice"));
$sheet->getActiveSheet()->SetCellValue('D1',__("TargetPort"));
$sheet->getActiveSheet()->SetCellValue('E1',__("Notes"));
$sheet->getActiveSheet()->SetCellValue('F1',__("MediaType"));
$sheet->getActiveSheet()->SetCellValue('G1',__("Color"));
$sheet->getActiveSheet()->setTitle(__("Connections"));
$row = 2;
$devNum = 1;
foreach ( $devList as $dev ) {
// Create a worksheet for each device with details
$sheet->createSheet($devNum);
$sheet->setActiveSheetIndex($devNum);
$cab->CabinetID = $dev->Cabinet;
$cab->GetCabinet();
$devTmpl->TemplateID = $dev->TemplateID;
$devTmpl->GetTemplateByID();
$mfg->ManufacturerID = $devTmpl->ManufacturerID;
$mfg->GetManufacturerByID();
$sheet->getActiveSheet()->SetCellValue('A1',__("Device Label"));
$sheet->getActiveSheet()->SetCellValue('B1', $dev->Label );
$sheet->getActiveSheet()->SetCellValue('A2',__("Manufacturer"));
$sheet->getActiveSheet()->SetCellValue('B2', $mfg->Name );
$sheet->getActiveSheet()->SetCellValue('A3',__("Model"));
$sheet->getActiveSheet()->SetCellValue('B3', $devTmpl->Model );
$sheet->getActiveSheet()->SetCellValue('A4',__("Serial Number"));
$sheet->getActiveSheet()->SetCellValue('B4', $dev->SerialNo );
$sheet->getActiveSheet()->SetCellValue('A5',__("Asset Tag"));
$sheet->getActiveSheet()->SetCellValue('B5', $dev->AssetTag );
$sheet->getActiveSheet()->SetCellValue('A6',__("Target Cabinet"));
$sheet->getActiveSheet()->SetCellValue('B6', $cab->Location );
$sheet->getActiveSheet()->SetCellValue('A7',__("Position"));
$sheet->getActiveSheet()->SetCellValue('B7', $dev->Position );
$sheet->getActiveSheet()->setTitle($dev->Label);
// Insert a picture into the device specific worksheet
if ( file_exists( "pictures/".$devTmpl->FrontPictureFile ) ) {
$img = new PHPExcel_Worksheet_Drawing();
$img->setWorksheet($sheet->setActiveSheetIndex($devNum));
$img->setName($dev->Label);
$img->setPath("pictures/".$devTmpl->FrontPictureFile);
$img->setCoordinates('B9');
$img->setOffsetX(1);
$img->setOffsetY(5);
}
foreach( range('A','B') as $columnID) {
$sheet->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
$sheet->setActiveSheetIndex(0);
$port = new DevicePorts();
$port->DeviceID = $dev->DeviceID;
$portList = $port->getPorts();
/*
if ( sizeof( $portList ) < 1 ) {
// No ports for this device
header('Location: '.redirect());
exit;
}
*/
foreach ( $portList as $devPort ) {
// These are created inside the loop, because they need to be clean instances each time
$targetDev = new Device();
$targetPort = new DevicePorts();
$color = new ColorCoding();
$mediaType = new MediaTypes();
if ( $devPort->ConnectedDeviceID > 0 || $devPort->Notes != "" ) {
$targetDev->DeviceID = $devPort->ConnectedDeviceID;
$targetDev->GetDevice();
$targetPort->DeviceID = $targetDev->DeviceID;
$targetPort->PortNumber = $devPort->ConnectedPort;
$targetPort->getPort();
if ( $targetPort->Label == '' ) {
$targetPort->Label = $devPort->ConnectedDeviceID > 0 ? $devPort->ConnectedPort : '';
}
$color->ColorID = $devPort->ColorID;
$color->GetCode();
$mediaType->MediaID = $devPort->MediaID;
$mediaType->GetType();
$sheet->getActiveSheet()->SetCellValue('A' . $row, $dev->Label);
$sheet->getActiveSheet()->SetCellValue('B' . $row, $devPort->Label);
$sheet->getActiveSheet()->SetCellValue('C' . $row, $targetDev->Label);
$sheet->getActiveSheet()->SetCellValue('D' . $row, $targetPort->Label);
$sheet->getActiveSheet()->SetCellValue('E' . $row, $devPort->Notes);
$sheet->getActiveSheet()->SetCellValue('F' . $row, $mediaType->MediaType);
$sheet->getActiveSheet()->SetCellValue('G' . $row, $color->Name);
$row++;
}
if ( $targetDev->DeviceType == "Patch Panel" ) {
$path = DevicePorts::followPathToEndPoint( $devPort->ConnectedDeviceID, -$devPort->ConnectedPort );
$pDev = new Device();
$tDev = new Device();
$pPort = new DevicePorts();
$tPort = new DevicePorts();
foreach ( $path as $p ) {
// Skip any rear port connections
if ( $p->PortNumber > 0 && $p->ConnectedPort > 0 ) {
$pDev->DeviceID = $p->DeviceID;
$pDev->GetDevice();
$tDev->DeviceID = $p->ConnectedDeviceID;
$tDev->GetDevice();
$pPort->DeviceID = $p->DeviceID;
$pPort->PortNumber = $p->PortNumber;
$pPort->getPort();
if ( $pPort->Label == "" )
$pPort->Label = $pPort->PortNumber;
$tPort->DeviceID = $p->ConnectedDeviceID;
$tPort->PortNumber = $p->ConnectedPort;
$tPort->getPort();
if ( $tPort->Label == "" )
$tPort->Label = $tPort->PortNumber;
$sheet->getActiveSheet()->SetCellValue('A' . $row, $pDev->Label);
$sheet->getActiveSheet()->SetCellValue('B' . $row, $pPort->Label);
$sheet->getActiveSheet()->SetCellValue('C' . $row, $tDev->Label);
$sheet->getActiveSheet()->SetCellValue('D' . $row, $tPort->Label);
$sheet->getActiveSheet()->SetCellValue('E' . $row, $pPort->Notes);
$sheet->getActiveSheet()->SetCellValue('F' . $row, $mediaType->MediaType);
$sheet->getActiveSheet()->SetCellValue('G' . $row, $color->Name);
$row++;
}
}
}
}
}
foreach( range('A','G') as $columnID) {
$sheet->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
if ( $_REQUEST["deviceid"] == "wo" ) {
header( sprintf( "Content-Disposition: attachment;filename=\"openDCIM-workorder-%s-connections.xlsx\"", date( "YmdHis" ) ) );
} else {
header( "Content-Disposition: attachment;filename=\"openDCIM-dev" . $dev->DeviceID . "-connections.xlsx\"" );
}
$writer = new PHPExcel_Writer_Excel2007($sheet);
$writer->save('php://output');
?>