forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_port_connections.php
98 lines (76 loc) · 3.23 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
<?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;
}
$dev = new Device();
$dev->DeviceID = $_REQUEST["deviceid"];
if ( ! $dev->GetDevice() ) {
// Not a valid device ID
header('Location: '.redirect());
exit;
}
$port = new DevicePorts();
$port->DeviceID = $dev->DeviceID;
$portList = $port->getPorts();
if ( sizeof( $portList ) < 1 ) {
// No ports for this device
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->getProperties()->setDescription("Detailed port connection information for " . $dev->Label . ".");
$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;
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();
$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++;
}
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header( sprintf( "Content-Disposition: attachment;filename=\"openDCIM-dev" . $dev->DeviceID . "-connections.xlsx\"", date( "YmdHis" ) ) );
$writer = new PHPExcel_Writer_Excel2007($sheet);
$writer->save('php://output');
?>