forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_panel.php
456 lines (405 loc) · 15.2 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
<?php
require_once("db.inc.php");
require_once("facilities.inc.php");
if(!$user->SiteAdmin){
// No soup for you.
header('Location: '.redirect());
exit;
}
$panel=new PowerPanel();
$pdu=new PowerDistribution();
$cab=new Cabinet();
// 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"))){
$panel->PanelID=$_POST["panelid"];
$panel->PowerSourceID=$_POST["powersourceid"];
$panel->PanelLabel=trim($_POST["panellabel"]);
$panel->NumberOfPoles=$_POST["numberofpoles"];
$panel->MainBreakerSize=$_POST["mainbreakersize"];
$panel->PanelVoltage=$_POST["panelvoltage"];
$panel->NumberScheme=$_POST["numberscheme"];
$panel->Managed=isset($_POST['managed'])?1:0;
$panel->IPAddress=$_POST["ipaddress"];
$panel->SNMPCommunity=$_POST["snmpcommunity"];
$panel->PanelOID=$_POST["paneloid"];
$panel->SNMPVersion = $_POST['snmpversion'];
$panel->Multiplier = $_POST['multiplier'];
$panel->ProcessingProfile = $_POST['processingprofile'];
if($_POST["action"]=="Create"){
$panel->CreatePanel();
} 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();
}
$panelList=$panel->GetPanelList();
$ps=new PowerSource();
$psList=$ps->GetPSList();
$managed=($panel->Managed)?" checked":"";
?>
<!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>
</head>
<body>
<div id="header"></div>
<div class="page panelmgr">
<?php
include( "sidebar.inc.php" );
echo '<div class="main">
<h2>',$config->ParameterArray["OrgName"],' Power Panels</h2>
<h3>',__("Data Center Detail"),'</h3>
<div class="center"><div>
<form action="',$_SERVER["PHP_SELF"],'" method="POST">
<div class="table">
<div>
<div><label for="panelid">',__("Power Panel ID"),'</label></div>
<div><select name="panelid" id="panelid" onChange="form.submit()">
<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="powersourceid">',__("Power Source"),'</label></div>
<div><select name="powersourceid" id="powersourceid">';
foreach($psList as $psRow){
print "<option value=\"$psRow->PowerSourceID\"";
if($psRow->PowerSourceID == $panel->PowerSourceID){
echo ' selected="selected"';
}
print ">$psRow->SourceName</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>
<?php
echo '
<div>
<div><label for="Managed">',__("Managed"),'</label></div>
<div><input type="checkbox" name="managed" id="managed"', $managed, '></div>
</div>
<div>
<div><label for="IPAddress">',__("IP Address"),'</label></div>
<div><input type="text" size="15" name="ipaddress" id="ipaddress" value="',$panel->IPAddress,'"></div>
</div>
<div>
<div><label for="SNMPCommunity">',__("SNMP Community"),'</label></div>
<div><input type="text" size="15" name="snmpcommunity" id="snmpcommunity" value="',$panel->SNMPCommunity,'"></div>
</div>
<div>
<div><label for="snmpversion">',__("SNMP Version"),'</label></div>
<div><select name="snmpversion" id="snmpversion">';
$snmpv = array( "1", "2c" );
foreach ( $snmpv as $unit ) {
$selected = ( $unit == $panel->SNMPVersion ) ? 'selected':'';
print "\t\t<option value=\"$unit\" $selected>$unit</option>\n";
}
echo '</select>
</div>
</div>
<div>
<div><label for="PanelOID">',__("Panel OID"),'</label></div>
<div><input type="text" size="25" name="paneloid" id="paneloid" value="',$panel->PanelOID,'"></div>
</div>
<div>
<div><label for="processingprofile">',__("Processing Scheme"),'</label></div>
<div><select name="processingprofile" id="processingprofile">';
$ProfileList=array("SingleOIDWatts","SingleOIDAmperes","Combine3OIDWatts","Combine3OIDAmperes","Convert3PhAmperes");
foreach($ProfileList as $prof){
$selected=($prof == $panel->ProcessingProfile)?' selected':'';
print "<option value=\"$prof\"$selected>$prof</option>";
}
echo ' </select></div>
</div>
<div>
<div><label for="multiplier">',__("Multiplier"),'</label></div>
<div><select name="multiplier" id="multiplier">';
$Multi=array("0.1", "1","10","100","1000");
$mult = 1;
// Loop to find the panel default multiplier, if any
foreach($Multi as $unit) {
//$selected = ($unit==$panel->Multiplier)?' selected' : '';
if ($unit == $panel->Multiplier) {
$mult = $panel->Multiplier;
break;
}
}
// Set the "selected" option, using $mult as set above
foreach($Multi as $unit){
$selected = ( $unit == $mult ) ? ' selected' : '';
print "\t\t<option value=\"$unit\"$selected>$unit</option>\n";
}
echo ' </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
if($panel->PanelID >0){
/* 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=\"power_pdu.php?pduid=$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=\"power_pdu.php?pduid=$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=\"power_pdu.php?pduid=$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.="<B>x " . $pduvar->InputAmperage . "</B> ";
$pn.="<a href=\"cabnavigator.php?cabinetid=$pduvar->CabinetID\">$cab->Location</a>";
$pn.="<a href=\"power_pdu.php?pduid=$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=\"power_pdu.php?pduid=".$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=\"power_pdu.php?pduid=$pduvar->PDUID\">$pduvar->Label</a> ";
$pn.="<B><I>" . $pduvar->InputAmperage . "A</I></B> ";
$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)
});
});
</script>
</body>
</html>