forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrowview.php
More file actions
320 lines (284 loc) · 11.1 KB
/
rowview.php
File metadata and controls
320 lines (284 loc) · 11.1 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
require_once( "db.inc.php" );
require_once( "facilities.inc.php" );
// Get the list of departments that this user is a member of
$viewList = $user->isMemberOf();
/**
* Determines ownership of the cabinet and returns the CSS class in case a
* color unequal white is assigned to the owner
*
* @param Cabinet $cabinet
* @param array &$deptswithcolor
* @return string CSS class or empty string
*/
function get_cabinet_owner_color($cabinet, &$deptswithcolor) {
$cab_color = '';
if ($cabinet->AssignedTo != 0) {
$tempDept = new Department();
$tempDept->DeptID = $cabinet->AssignedTo;
$deptid = $tempDept->DeptID;
$tempDept->GetDeptByID();
if (strtoupper($tempDept->DeptColor) != "#FFFFFF") {
$deptswithcolor[$cabinet->AssignedTo]["color"] = $tempDept->DeptColor;
$deptswithcolor[$cabinet->AssignedTo]["name"]= $tempDept->Name;
$cab_color = "class=\"dept$deptid\"";
}
}
return $cab_color;
}
// This function with no argument will build the front cabinet face. Specify
// rear and it will build the back.
function BuildCabinet($rear=false){
// This is fucking horrible, there has to be a better way to accomplish this.
global $cab_color, $cabinet, $device, $body, $currentHeight, $heighterr,
$devList, $templ, $tempDept, $backside, $deptswithcolor, $tempDept,
$totalWeight, $totalWatts, $totalMoment, $zeroheight,
$noTemplFlag, $noOwnerFlag, $noReservationFlag;
$currentHeight=$cabinet->CabinetHeight;
$body.="<div class=\"cabinet\">\n\t<table>
<tr><th id=\"cabid\" data-cabinetid=$cabinet->CabinetID colspan=2 $cab_color>".__("Cabinet")." $cabinet->Location".($rear?" (".__("Rear").")":"")."</th></tr>
<tr><td class=\"cabpos\">".__("Pos")."</td><td>".__("Device")."</td></tr>\n";
$heighterr="";
while(list($dev_index,$device)=each($devList)){
list($noTemplFlag, $noOwnerFlag, $highlight) =
renderUnassignedTemplateOwnership($noTemplFlag, $noOwnerFlag, $device);
if($device->Height<1 && !$rear){
if($device->Rights!="None"){
$zeroheight.="\t\t\t<a href=\"devices.php?deviceid=$device->DeviceID\" data-deviceid=$device->DeviceID>$highlight $device->Label</a>\n";
}else{
// empty html anchor for a line break
$zeroheight.="\t\t\t$highlight $device->Label\n<a></a>";
}
}
if ((!$device->HalfDepth || !$device->BackSide)&&!$rear || (!$device->HalfDepth || $device->BackSide)&&$rear){
$backside=($device->HalfDepth)?true:$backside;
$devTop=$device->Position + $device->Height - 1;
$templ->TemplateID=$device->TemplateID;
$templ->GetTemplateByID();
$tempDept->DeptID=$device->Owner;
$tempDept->GetDeptByID();
// If a dept has been changed from white then it needs to be added to the stylesheet, legend, and device
if(!$device->Reservation && strtoupper($tempDept->DeptColor)!="#FFFFFF"){
// Fill array with deptid and color so we can process the list once for the legend and style information
$deptswithcolor[$device->Owner]["color"]=$tempDept->DeptColor;
$deptswithcolor[$device->Owner]["name"]=$tempDept->Name;
}
//only computes this device if it is its front side
if (!$device->BackSide && !$rear || $device->BackSide && $rear){
$totalWatts+=$device->GetDeviceTotalPower();
$DeviceTotalWeight=$device->GetDeviceTotalWeight();
$totalWeight+=$DeviceTotalWeight;
$totalMoment+=($DeviceTotalWeight*($device->Position+($device->Height/2)));
}
$reserved="";
if($device->Reservation==true){
$reserved=" reserved";
$noReservationFlag=true;
}
if($devTop<$currentHeight && $currentHeight>0){
for($i=$currentHeight;($i>$devTop);$i--){
$errclass=($i>$cabinet->CabinetHeight)?' error':'';
if($errclass!=''){$heighterr="yup";}
if($i==$currentHeight){
$blankHeight=$currentHeight-$devTop;
if($devTop==-1){--$blankHeight;}
$body.="\t\t<tr><td class=\"cabpos freespace$errclass\">$i</td><td class=\"freespace\" rowspan=$blankHeight> </td></tr>\n";
} else {
$body.="\t\t<tr><td class=\"cabpos freespace$errclass\">$i</td></tr>\n";
if($i==1){break;}
}
}
}
for($i=$devTop;$i>=$device->Position;$i--){
$errclass=($i>$cabinet->CabinetHeight)?' error':'';
if($errclass!=''){$heighterr="yup";}
if($i==$devTop){
// Create the filler for the rack either text or a picture
$picture=(!$device->BackSide && !$rear || $device->BackSide && $rear)?$device->GetDevicePicture():$device->GetDevicePicture("rear");
$devlabel=$device->Label.(((!$device->BackSide && $rear || $device->BackSide && !$rear) && !$device->HalfDepth)?"(".__("Rear").")":"");
$text=($device->Rights!="None")?"<a href=\"devices.php?deviceid=$device->DeviceID\">$highlight $devlabel</a>":$devlabel;
// Put the device in the rack
$body.="\t\t<tr><td class=\"cabpos$reserved dept$device->Owner$errclass\">$i</td><td class=\"dept$device->Owner$reserved\" rowspan=$device->Height data-deviceid=$device->DeviceID>";
$body.=($picture)?$picture:$text;
$body.="</td></tr>\n";
}else{
$body.="\t\t<tr><td class=\"cabpos$reserved dept$device->Owner$errclass\">$i</td></tr>\n";
}
}
$currentHeight=$device->Position - 1;
}elseif(!$rear){
$backside=true;
}
}
// Fill in to the bottom
for($i=$currentHeight;$i>0;$i--){
if($i==$currentHeight){
$blankHeight=$currentHeight;
$body.="\t\t<tr><td class=\"cabpos freespace\">$i</td><td class=\"freespace\" rowspan=$blankHeight> </td></tr>\n";
}else{
$body.="\t\t<tr><td class=\"cabpos freespace\">$i</td></tr>\n";
}
}
$body.="\t</table>\n</div>\n";
reset($devList);
} //END OF BuildCabinet
/**
* Render the indicator that a device has no ownership or template assigned.
*
* @param boolean $noTemplFlag flag indicating no template is assigned to device
* @param boolean $noOwnerFlag flag indicating no ownership is assigned to device
* @param Device $device
* @return (boolean|boolean|string)[] CSS class or empty stringtype
*/
function renderUnassignedTemplateOwnership($noTemplFlag, $noOwnerFlag, $device) {
$retstr=$noTemplate=$noOwnership='';
if ($device->TemplateID == 0) {
$noTemplate = '(T)';
$noTemplFlag = true;
}
if ($device->Owner == 0) {
$noOwnership = '(O)';
$noOwnerFlag = true;
}
if ($noTemplFlag or $noOwnerFlag) {
$retstr = '<span class="hlight">' . $noTemplate . $noOwnership . '</span>';
}
return array($noTemplFlag, $noOwnerFlag, $retstr);
}
$cab=new Cabinet();
$head=$legend=$zeroheight=$body=$deptcolor="";
$deptswithcolor=array();
$dev=new Device();
$templ=new DeviceTemplate();
$tempDept=new Department();
$dc=new DataCenter();
$cabrow=new CabRow();
$cabrow->CabRowID=$_REQUEST['row'];
$cabrow->GetCabRow();
$cab->CabRowID=$cabrow->CabRowID;
$cabinets=$cab->GetCabinetsByRow(isset($_GET["rear"])?"rear":"");
$fe=$cabrow->GetCabRowFrontEdge();
if (isset($_GET["rear"])){
//opposite view
$fe=($fe=="Right")?"Left":(($fe=="Left")?"Right":(($fe=="Top")?"Bottom":(($fe=="Bottom")?"Top":"")));
}
//start loop to parse all cabinets in the row
foreach($cabinets as $index => $cabinet){
$dev->Cabinet=$cabinet->CabinetID;
$devList=$dev->ViewDevicesByCabinet();
$currentHeight=$cabinet->CabinetHeight;
$cab_color=get_cabinet_owner_color($cabinet, $deptswithcolor);
if($config->ParameterArray["ReservedColor"] != "#FFFFFF" || $config->ParameterArray["FreeSpaceColor"] != "#FFFFFF"){
$head.=" <style type=\"text/css\">
.reserved{background-color: {$config->ParameterArray['ReservedColor']};}
.freespace{background-color: {$config->ParameterArray['FreeSpaceColor']};}\n";
}
buildcabinet(($fe==$cabinet->FrontEdge)?"":"rear");
}
$dcID=$cabinets[0]->DataCenterID;
$dc->DataCenterID=$dcID;
$dc->GetDataCenterbyID();
// If $head isn't empty then we must have added some style information so close the tag up.
if($head!=""){
$head.=' </style>';
}
$title=($cabrow->Name!='')?__("Row")." $cabrow->Name".(isset($_GET["rear"])?"(".__("Rear").")":"")." :: ".count($cabinets)." ".__("Cabinets")." :: $dc->Name":__('Facilities Cabinet Maintenance');
?>
<!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><?php echo $title; ?></title>
<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">
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" />
<![endif]-->
<?php
echo $head,' <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">
$(document).ready(function() {
$(".cabinet .error").append("*");
function FlipItGood(){
var container=$("#centeriehack");
container.children().each(function(i,cab){container.prepend(cab)});
resize();
}
$("<button>",{id: "reverse", type: "button"}).text("'.(isset($_GET["rear"])?__("Front View"):__("Rear View")).'").click(function(){
document.location.href="rowview.php?row=',$cabrow->CabRowID.(isset($_GET["rear"])?"":"&rear"),'";
}).prependTo($(".main"));
';
if($config->ParameterArray["ToolTips"]=='enabled'){
?>
$('.cabinet td:has(a):not(:has(img)), #zerou div > a, .cabinet .picture a img, .cabinet .picture a div').mouseenter(function(){
var pos=$(this).offset();
var tooltip=$('<div />').css({
'left':pos.left+this.getBoundingClientRect().width+15+'px',
'top':pos.top+(this.getBoundingClientRect().height/2)-15+'px'
}).addClass('arrow_left border cabnavigator tooltip').attr('id','tt').append('<span class="ui-icon ui-icon-refresh rotate"></span>');
$.post('scripts/ajax_tooltip.php',{tooltip: $(this).data('deviceid'), dev: 1}, function(data){
tooltip.html(data);
});
$('body').append(tooltip);
$(this).mouseleave(function(){
tooltip.remove();
});
});
<?php
}
?>
});
</script>
</head>
<body>
<div id="header"></div>
<div class="page">
<?php
include( "sidebar.inc.php" );
?>
<div class="main cabnavigator">
<h2><?php print $config->ParameterArray["OrgName"]; ?></h2>
<h3><?php print __("Data Center Cabinet Inventory"); ?></h3>
<div class="center"><div>
<div id="centeriehack">
<?php
echo $body;
?>
</div> <!-- END div#centeriehack -->
</div></div>
<?php
if($dcID>0){
print " <br><br><br><a href=\"dc_stats.php?dc=$dcID\">[ ".__('Return to')." $dc->Name ]</a>";
}
?>
</div> <!-- END div.main -->
<div class="clear"></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
// Move the cabinet labels around
$('.cabnavigator div.picture > div.label > div').each(function(){
var offset=this.getBoundingClientRect().height;
var container=$(this).parents('.picture')[0].getBoundingClientRect().height;
$(this).parent('.label').css('top', (container-offset)/2/2);
});
// Don't attempt to open the datacenter tree until it is loaded
function opentree(){
if($('#datacenters .bullet').length==0){
setTimeout(function(){
opentree();
resize();
},500);
}else{
expandToItem('datacenters','cab<?php echo $cabinet->CabinetID;?>');
resize();
}
}
opentree();
});
</script>
</body>
</html>