forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_export.php
199 lines (185 loc) · 6.4 KB
/
search_export.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
<?php
require_once('db.inc.php');
require_once('facilities.inc.php');
$datacenter=new DataCenter();
$dcList=$datacenter->GetDCList();
$templ=new DeviceTemplate();
$dept=new Department();
$dev=new Device();
$body="";
if(isset($_REQUEST['datacenterid'])){
$dc=isset($_POST['datacenterid'])?$_POST['datacenterid']:$_GET['datacenterid'];
if($dc!=''){
$dc=intval($dc);
if($dc==0){
$sql="select a.Name as DataCenter, b.DeviceID, c.Location, b.Position, b.Height, b.Label, b.DeviceType, b.AssetTag, b.SerialNo, b.InstallDate, b.TemplateID, b.Owner from fac_DataCenter a, fac_Device b, fac_Cabinet c where b.Cabinet=c.CabinetID and c.DataCenterID=a.DataCenterID order by DataCenter ASC, Location ASC, Position ASC";
}else{
$sql="select a.Name as DataCenter, b.DeviceID, c.Location, b.Position, b.Height, b.Label, b.DeviceType, b.AssetTag, b.SerialNo, b.InstallDate, b.TemplateID, b.Owner from fac_DataCenter a, fac_Device b, fac_Cabinet c where b.Cabinet=c.CabinetID and c.DataCenterID=a.DataCenterID and c.DataCenterID=$dc order by Location ASC, Position ASC";
}
$result=$dbh->query($sql);
}else{
$result=array();
}
// Left these expanded in case we need to add or remove columns. Otherwise I would have just collapsed entirely.
$body="<table id=\"export\" class=\"display\">\n\t<thead>\n\t\t<tr>\n
\t<th>".__("Data Center")."</th>
\t<th>".__("Location")."</th>
\t<th>".__("Position")."</th>
\t<th>".__("Height")."</th>
\t<th>".__("Name")."</th>
\t<th>".__("Serial Number")."</th>
\t<th>".__("Asset Tag")."</th>
\t<th>".__("Device Type")."</th>
\t<th>".__("Template")."</th>
\t<th>".__("Tags")."</th>
\t<th>".__("Owner")."</th>
\t<th>".__("Installation Date")."</th>
</tr>\n\t</thead>\n\t<tbody>\n";
// suppressing errors for when there is a fake data set in place
foreach($result as $row){
// insert date formating later for regionalization settings
$date=date("d M Y",strtotime($row["InstallDate"]));
$Model="";
$Department="";
if($row["TemplateID"] >0){
$templ->TemplateID=$row["TemplateID"];
$templ->GetTemplateByID();
$Model=$templ->Model;
}
if($row["Owner"] >0){
$dept->DeptID=$row["Owner"];
$dept->GetDeptByID();
$Department=$dept->Name;
}
$dev->DeviceID=$row["DeviceID"];
$tags=implode(",", $dev->GetTags());
$body.="\t\t<tr>
\t<td>{$row["DataCenter"]}</td>
\t<td>{$row["Location"]}</td>
\t<td>{$row["Position"]}</td>
\t<td>{$row["Height"]}</td>
\t<td>{$row["Label"]}</td>
\t<td>{$row["SerialNo"]}</td>
\t<td>{$row["AssetTag"]}</td>
\t<td>{$row["DeviceType"]}</td>
\t<td>$Model</td>
\t<td>$tags</td>
\t<td>$Department</td>
\t<td>$date</td>\n\t\t</tr>\n";
if($row["DeviceType"]=="Chassis"){
// Find all of the children!
$childList=$dev->GetDeviceChildren();
foreach($childList as $child){
$cdate=date("d M Y",strtotime($child->InstallDate));
$cModel="";
$cDepartment="";
$ctags=implode(",", $child->GetTags());
if($child->TemplateID >0){
$templ->TemplateID=$child->TemplateID;
$templ->GetTemplateByID();
$cModel=$templ->Model;
}
if($child->Owner >0){
$dept->DeptID=$child->Owner;
$dept->GetDeptByID();
$cDepartment=$dept->Name;
}
$body .= "\t\t<tr>
\t<td>{$row["DataCenter"]}</td>
\t<td>{$row["Location"]}</td>
\t<td>{$row["Position"]}</td>
\t<td>[-Child-]</td>
\t<td>$child->Label</td>
\t<td>$child->SerialNo</td>
\t<td>$child->AssetTag</td>
\t<td>$child->DeviceType</td>
\t<td>$cModel</td>
\t<td>$ctags</td>
\t<td>$cDepartment</td>
\t<td>$cdate</td>\n\t\t</tr>\n";
}
}
}
$body.="\t\t</tbody>\n\t</table>\n";
if(isset($_REQUEST['ajax'])){
echo $body;
exit;
}
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<link rel="stylesheet" href="css/print.css" type="text/css" media="print">
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css">
<link rel="stylesheet" href="css/jquery.dataTables.css" type="text/css">
<link rel="stylesheet" href="css/ColVis.css" type="text/css">
<link rel="stylesheet" href="css/TableTools.css" type="text/css">
<style type="text/css"></style>
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" />
<![endif]-->
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery-ui.min.js"></script>
<script type="text/javascript" src="scripts/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="scripts/ColVis.min.js"></script>
<script type="text/javascript" src="scripts/TableTools.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var rows;
function dt(){
$('#export').dataTable({
"iDisplayLength": 25,
"sDom": 'CT<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "scripts/copy_csv_xls.swf",
"aButtons": ["copy","csv","xls","print"]
}
});
redraw();
}
function redraw(){
if(($('#export').outerWidth()+$('#sidebar').outerWidth()+10)<$('.page').innerWidth()){
$('.main').width($('#header').innerWidth()-$('#sidebar').outerWidth()-16);
}else{
$('.main').width($('#export').outerWidth()+40);
}
$('.page').width($('.main').outerWidth()+$('#sidebar').outerWidth()+10);
}
dt();
$('#datacenterid').change(function(){
$.post('', {datacenterid: $(this).val(), ajax: ''}, function(data){
$('#tablecontainer').html(data);
dt();
});
});
});
</script>
</head>
<body>
<div id="header"></div>
<div class="page">
<?php
include('sidebar.inc.php');
echo ' <div class="main">
<h2>',$config->ParameterArray['OrgName'],'</h2>
<h3>',__("Data Center View/Export"),'</h3>
<label for="datacenterid">',__("Data Center:"),'</label>
<select name="datacenterid" id="datacenterid">
<option value="">',__("Select data center"),'</option>
<option value="0">',__("All Data Centers"),'</option>';
foreach($dcList as $dc){print "\t\t\t\t<option value=\"$dc->DataCenterID\">$dc->Name</option>\n";} ?>
</select>
<br><br>
<div class="center">
<div id="tablecontainer">
<?php echo $body; ?>
</div>
</div>
</div><!-- END div.main -->
</div><!-- END div.page -->
</body>
</html>