forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_panel.php
471 lines (431 loc) · 15.5 KB
/
power_panel.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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<?php
require_once("db.inc.php");
require_once("facilities.inc.php");
$subheader=__("Data Center Detail");
if(!$person->SiteAdmin){
// No soup for you.
header('Location: '.redirect());
exit;
}
$panel=new PowerPanel();
$pdu=new PowerDistribution();
$cab=new Cabinet();
$tmpl = new CDUTemplate();
$tmpList = $tmpl->GetTemplateList();
$script="";
// AJAX
if(isset($_POST['deletepanel'])){
$panel->PanelID=$_POST["PanelID"];
$return='no';
if($panel->getPanel()){
$panel->deletePanel();
$return='ok';
}
echo $return;
exit;
}
// Set a default panel voltage based upon the configuration screen
$panel->PanelVoltage=$config->ParameterArray["DefaultPanelVoltage"];
if(isset($_POST["action"])&&(($_POST["action"]=="Create")||($_POST["action"]=="Update"))){
foreach($panel as $prop => $val){
$panel->$prop=trim($_POST[$prop]);
}
if($_POST["action"]=="Create"){
if($panel->createPanel()){
header('Location: '.redirect("power_panel.php?PanelID=$panel->PanelID"));
}
} else {
$panel->updatePanel();
}
}
if(isset($_REQUEST["PanelID"])&&($_REQUEST["PanelID"] >0)){
$panel->PanelID=(isset($_POST['PanelID']) ? $_POST['PanelID'] : $_GET['PanelID']);
$panel->getPanel();
$pdu->PanelID = $panel->PanelID;
$pduList=$pdu->GetPDUbyPanel();
$panelLoad = sprintf( "%01.2F", $panel->GetPanelLoad() / 1000 );
$panelCap = $panel->PanelVoltage * $panel->MainBreakerSize * sqrt(3);
$dataMajorTicks = "";
for ( $i = 0; $i < $panelCap; $i+=( $panelCap / 10 ) ) {
$dataMajorTicks .= sprintf( "%d ", $i / 1000 );
}
$dataMajorTicks .= sprintf( "%d", $panelCap / 1000 );
$dataMaxValue = sprintf( "%d", $panelCap / 1000 );
$dataHighlights = sprintf( "0 %d #eee, %d %d #fffacd, %d %d #eaa", $panelCap / 1000 * .6, $panelCap / 1000 * .6, $panelCap / 1000 * .8, $panelCap / 1000 * .8, $panelCap / 1000);
$mtarray=implode(",",explode(" ",$dataMajorTicks));
$hilights = sprintf( "{from: 0, to: %d, color: '#eee'}, {from: %d, to: %d, color: '#fffacd'}, {from: %d, to: %d, color: '#eaa'}", $panelCap / 1000 * .6, $panelCap / 1000 * .6, $panelCap / 1000 * .8, $panelCap / 1000 * .8, $panelCap / 1000);
// Generate JS for load display
$script="
var gauge=new Gauge({
renderTo: 'power-gauge',
type: 'canv-gauge',
title: 'Load',
minValue: '0',
maxValue: '$dataMaxValue',
majorTicks: [ $mtarray ],
minorTicks: '2',
strokeTicks: false,
units: 'kW',
valueFormat: { int : 3, dec : 2 },
glow: false,
animation: {
delay: 10,
duration: 200,
fn: 'bounce'
},
colors: {
needle: {start: '#f00', end: '#00f' },
title: '#00f',
},
highlights: [ $hilights ],
});
gauge.draw().setValue($panelLoad);
";
/*
Example for updating the gauge later. This will start an endless loop that will update
the gauge once a second.
setInterval( function() {
gauge.setValue($.get('api/v1/power/whateverhere'));
}, 1000);
*/
}
$panelList=$panel->getPanelList();
?>
<!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 Data Center Management</title>
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<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]-->
<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/gauge.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#PanelID').change(function(e){
location.href='power_panel.php?PanelID='+this.value;
});
});
</script>
</head>
<body>
<?php include( 'header.inc.php' ); ?>
<div class="page panelmgr">
<?php
include( "sidebar.inc.php" );
echo '<div class="main">
<div class="center"><div>
<form method="POST">
<div class="table">
<div>
<div><label for="PanelID">',__("Power Panel ID"),'</label></div>
<div><select name="PanelID" id="PanelID">
<option value="0">',__("New Panel"),'</option>';
foreach($panelList as $panelRow){
if($panelRow->PanelID == $panel->PanelID){$selected=" selected";}else{$selected="";}
print " <option value=\"$panelRow->PanelID\"$selected>$panelRow->PanelLabel</option>\n";
}
echo ' </select>
</div>
</div>
<div>
<div><label for="PanelLabel">',__("Panel Name"),'</label></div>
<div><input type="text" size="40" name="PanelLabel" id="PanelLabel" value="',$panel->PanelLabel,'"></div>
</div>
<div>
<div><label for="NumberOfPoles">',__("Number of Poles"),'</label></div>
<div><input type="number" name="NumberOfPoles" id="NumberOfPoles" size="3" value="',$panel->NumberOfPoles,'"></div>
</div>
<div>
<div><label for="MainBreakerSize">',__("Main Breaker Amperage"),'</label></div>
<div><input type="number" name="MainBreakerSize" id="MainBreakerSize" size="4" value="',$panel->MainBreakerSize,'"></div>
</div>
<div>
<div><label for="PanelVoltage">',__("Panel Voltage"),'</label></div>
<div><input type="number" name="PanelVoltage" id="PanelVoltage" size="4" value="',$panel->PanelVoltage,'"></div>
</div>
<div>
<div><label for="NumberScheme">',__("Numbering Scheme"),'</label></div>
<div><select name="NumberScheme" id="NumberScheme">';
// This is messy but since we are actually storing this value in the db and we use it elsewhere this
// worked out best
if($panel->NumberScheme=="Odd/Even"){$selected=" selected";}else{$selected="";}
print "<option value=\"Odd/Even\"$selected>".__("Odd/Even")."</option>\n";
if($panel->NumberScheme=="Sequential"){$selected=" selected";}else{$selected="";}
print "<option value=\"Sequential\"$selected>".__("Sequential")."</option>\n";
?>
</select>
</div>
</div>
<div>
<div><label for="ParentPanelID"><?php print __("Parent Panel"); ?></label></div>
<div><select name="ParentPanelID" id="ParentPanelID">
<option value=0></option>
<?php
foreach($panelList as $pnl){
$selected=($pnl->PanelID==$panel->ParentPanelID)?" selected":"";
// Avoid making medieval royalty - panels that are children of themselves
if($panel->PanelID!=$pnl->PanelID){
print "\t\t<option value=$pnl->PanelID$selected>$pnl->PanelLabel</option>\n";
}
}
echo ' </select></div>
</div>
<div>
<div><label for="ParentBreakerName">',__("Parent Breaker Name"),'</label></div>
<div><input type="text" name="ParentBreakerName" id="ParentBreakerName" size="40" value="',$panel->ParentBreakerName,'"></div>
</div>
<div>
<div><label for="PanelIPAddress">',__("Panel Meter IP Address"),'</label></div>
<div><input type="text" name="PanelIPAddress" id="PanelIPAddress" size="30" value="',$panel->PanelIPAddress,'"></div>
</div>
<div>
<div><label for="TemplateID">',__("CDU/Meter Template"),'</label></div>
<div>
<select name="TemplateID" id="TemplateID">
<option value=0></option>';
foreach($tmpList as $tmp){
$selected=($panel->TemplateID==$tmp->TemplateID)?' selected':'';
print "\n\t\t\t<option value=$tmp->TemplateID$selected>$tmp->Model</option>";
}
?>
</select>
</div>
</div>
<div class="caption">
<?php
if($panel->PanelID >0){
echo ' <button type="submit" name="action" value="Update">',__("Update"),'</button>
<button type="button" name="action" value="Delete">',__("Delete"),'</button>';
}else{
echo ' <button type="submit" name="action" value="Create">',__("Create"),'</button>';
}
?>
</div>
</div><!-- END div.table -->
</form>
<?php
// Build a panel schedule if this is not a new panel being created
// Also show the power gauge
if($panel->PanelID >0){
echo '<div><canvas id="power-gauge" width="200" height="200"></canvas></div>';
/* Loop through PDUs and find all that are attached to this panel and build a temp array to hold them.
Array is indexed by circuit IDs. Each ID is an array of objects that are connected there. This
allows for multiple PDUs to be connected to a single breaker.
Structure:
$pduarray[$panel->PanelPole]->ArrayofPDUs[]->PowerDistribution Object
*/
$pduarray=array();
foreach($pduList as $pnlPDU){
if($pnlPDU->PanelID == $panel->PanelID){
$pduarray[$pnlPDU->PanelPole][]=$pnlPDU;
}elseif($pnlPDU->PanelID2 == $panel->PanelID){
$pduarray[$pnlPDU->PanelPole2][]=$pnlPDU;
}
}
print "<center><h2>".__("Panel Schedule")."</h2></center>\n<table>";
$nextPole=1;
$odd=$even=0;
if($panel->NumberScheme=="Sequential"){
while($nextPole <= $panel->NumberOfPoles){
print "<tr><td class=\"polenumber\">$nextPole</td>";
// Someone input a pole number wrong and this one would have been skipped
// store the value and deal with it later.
if(isset($pduarray[$nextPole])&&$odd!=0){
foreach($pduarray[$nextPole] as $pduvar){
$errors[]="<a href=\"devices.php?DeviceID=$pduvar->PDUID\">$pduvar->Label</a>";
}
}
// Get info for pdu on this pole if it is populated.
$lastCabinet=0;
if($odd==0){
if(isset($pduarray[$nextPole])){
$pn="";
foreach($pduarray[$nextPole] as $pduvar) {
$cab->CabinetID=$pduvar->CabinetID;
$cab->GetCabinet( );
if ($lastCabinet<>$pduvar->CabinetID)
$pn.="<a href=\"cabnavigator.php?cabinetid=$pduvar->CabinetID\">$cab->Location</a>";
$pn.="<a href=\"devices.php?DeviceID=$pduvar->PDUID\"><span>$pduvar->Label</span></a>";
$lastCabinet=$pduvar->CabinetID;
switch($pduvar->BreakerSize){
case '3': $odd=3; break;
case '2': $odd=2; break;
default: $odd=0;
}
}
}else{
$pn="";
}
if($odd==0){
print "<td class=\"polelabel\">$pn</td></tr>";
}else{
print "<td class=\"polelabel\" rowspan=$odd>$pn</td></tr>";
--$odd;
}
}else{ // we've already started to display a circuit. no new circuits will be drawn til this count hits zero.
--$odd;
}
++$nextPole;
}
}else{
// Build single table with four colums to represent an odd/even panel layout
// $odd and $even will be travel counters to ensure the table is built in a sane manner
while($nextPole <= $panel->NumberOfPoles){
print "<tr><td class=\"polenumber\">$nextPole</td>";
// Someone input a pole number wrong and this one would have been skipped
// store the value and deal with it later.
if(isset($pduarray[$nextPole])&&$odd!=0){
foreach($pduarray[$nextPole] as $pduvar){
$errors[]="<a href=\"devices.php?DeviceID=$pduvar->PDUID\">$pduvar->Label</a>";
}
}
// Get info for pdu on this pole if it is populated.
$lastCabinet=0;
if($odd==0){
if(isset($pduarray[$nextPole])){
$pn="";
foreach($pduarray[$nextPole] as $pduvar) {
$cab->CabinetID=$pduvar->CabinetID;
$cab->GetCabinet( );
if ($lastCabinet<>$pduvar->CabinetID)
$pn.="<a href=\"cabnavigator.php?cabinetid=$pduvar->CabinetID\">$cab->Location</a>";
$pn.="<a href=\"devices.php?DeviceID=$pduvar->PDUID\"><span>$pduvar->Label</span></a>";
$lastCabinet=$pduvar->CabinetID;
switch($pduvar->BreakerSize){
case '3': $odd=3; break;
case '2': $odd=2; break;
default: $odd=0;
}
}
}else{
$pn="";
}
if($odd==0){
print "<td class=\"polelabel\">$pn</td>";
}else{
print "<td class=\"polelabel\" rowspan=$odd>$pn</td>";
--$odd;
}
}else{ // we've already started to display a circuit. no new circuits will be drawn til this count hits zero.
--$odd;
}
//Odd side done. Print even side circuit id then check for connected device.
++$nextPole;
print "<td class=\"polenumber\">$nextPole</td>";
// Someone input a pole number wrong and this one would have been skipped
// store the value and deal with it later.
if(isset($pduarray[$nextPole])&&$even!=0){
foreach($pduarray[$nextPole] as $pduvar){
$errors[]="<a href=\"devices.php?DeviceID=".$pduvar->PDUID."\">".$pduvar->Label."</a>";
}
}
if($even==0){
if(isset($pduarray[$nextPole])){
$pn="";
foreach($pduarray[$nextPole] as $pduvar) {
$cab->CabinetID=$pduvar->CabinetID;
$cab->GetCabinet( );
if ($lastCabinet<>$pduvar->CabinetID)
$pn.="<a href=\"cabnavigator.php?cabinetid=$pduvar->CabinetID\">$cab->Location</a>";
$pn.="<a href=\"devices.php?DeviceID=$pduvar->PDUID\"><span>$pduvar->Label</span></a>";
$lastCabinet=$pduvar->CabinetID;
switch($pduvar->BreakerSize){
case '3': $even=3; break;
case '2': $even=2; break;
default: $even=0;
}
}
}else{
$pn="";
}
if($even==0){
print "<td class=\"polelabel\">$pn</td></tr>\n";
}else{
print "<td class=\"polelabel\" rowspan=$even>$pn</td>";
--$even;
}
}else{ // we've already started to display a circuit. no new circuits will be drawn til this count hits zero.
--$even;
}
//Even side done. Incriment counter and restart loop for next row.
++$nextPole;
}
}
}
print "</table>";
// Okay so someone didn't get correct information from the breaker panel
if(isset($errors)){
print "<div class=\"table error\">\n <div>\n <div>\n <fieldset>\n <legend>".__("Errors")."</legend>\n <div class=\"table\">\n";
foreach($errors as $err){
print " <div><div>$err</div></div>\n";
}
print " </div><!-- END div.table -->\n </fieldset>\n </div>\n <div>".__("PDUs displayed here could not be drawn on the panel because of an overlapping circuit ID assignment. Please check the pole positions on the panels again.")."</div>\n </div>\n</div><!-- END div.table -->\n";
}
?>
</div></div>
<?php echo '<a href="index.php">[ ',__("Return to Main Menu"),' ]</a>
<!-- hiding modal dialogs here so they can be translated easily -->
<div class="hide">
<div title="',__("Power panel delete confirmation"),'" id="deletemodal">
<div id="modaltext"><span style="float:left; margin:0 7px 20px 0;" class="ui-icon ui-icon-alert"></span>',__("Are you sure that you want to delete this power panel?"),'
</div>
</div>
</div>'; ?>
</div><!-- END div.main -->
</div><!-- END div.page -->
<script type="text/javascript">
$('button[value=Delete]').click(function(){
var defaultbutton={
"<?php echo __("Yes"); ?>": function(){
$.post('', {PanelID: $('#PanelID').val(),deletepanel: '' }, function(data){
if(data.trim()=='ok'){
self.location=$('.main > a').last().attr('href');
$(this).dialog("destroy");
}else{
alert("Danger, Will Robinson! DANGER! Something didn't go as planned.");
}
});
}
}
var cancelbutton={
"<?php echo __("No"); ?>": function(){
$(this).dialog("destroy");
}
}
var modal=$('#deletemodal').dialog({
dialogClass: 'no-close',
modal: true,
width: 'auto',
buttons: $.extend({}, defaultbutton, cancelbutton)
});
});
<?php
if( $config->ParameterArray["ToolTips"]=='enabled' ){
?>
$('.polelabel > a > span').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.parentNode.search.split('=').pop(), dev: 1}, function(data){
tooltip.html(data);
});
$('body').append(tooltip);
$(this).mouseleave(function(){
tooltip.remove();
});
});
<?php
}
echo $script;
?>
</script>
</body>
</html>