forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_source.php
176 lines (158 loc) · 5.63 KB
/
power_source.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
<?php
require_once('db.inc.php');
require_once('facilities.inc.php');
if(!$user->SiteAdmin){
// No soup for you.
header('Location: '.redirect());
exit;
}
$ps=new PowerSource();
// AJAX
if(isset($_POST['deletepowersource'])){
$ps->PowerSourceID=$_POST["powersourceid"];
$return='no';
if($ps->GetSource()){
$ps->DeletePowerSource();
$return='ok';
}
echo $return;
exit;
}
if(isset($_REQUEST['action']) && (($_REQUEST['action']=='Create')||($_REQUEST['action']=='Update'))){
$ps->PowerSourceID=$_REQUEST['powersourceid'];
$ps->SourceName=$_REQUEST['sourcename'];
$ps->DataCenterID=$_REQUEST['datacenterid'];
$ps->IPAddress=$_REQUEST['ipaddress'];
$ps->Community=$_REQUEST['community'];
$ps->LoadOID=$_REQUEST['loadoid'];
$ps->Capacity=$_REQUEST['capacity'];
if($_REQUEST['action']=='Create'){
$ps->CreatePowerSource();
}else{
$ps->UpdatePowerSource();
}
}
if(isset($_REQUEST['powersourceid']) && $_REQUEST['powersourceid'] >0){
$ps->PowerSourceID=$_REQUEST['powersourceid'];
$ps->GetSource();
}
$psList=$ps->GetPSList();
$dc=new DataCenter();
$dcList=$dc->GetDCList();
?>
<!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 Mangement</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">
<?php
include( 'sidebar.inc.php' );
echo ' <div class="main">
<h2>',$config->ParameterArray['OrgName'],' Power Sources</h2>
<h3>',__("Data Center Detail"),'</h3>
<div class="center"><div>
<form action="',$_SERVER['PHP_SELF'],'" method="POST">
<div class="table">
<div>
<div><label for="powersourceid">',__("Power Source ID"),'</label></div>
<div><select name="powersourceid" id="powersourceid" onChange="form.submit()">
<option value="0">',__("New Power Source"),'</option>';
foreach($psList as $psRow){
if($psRow->PowerSourceID==$ps->PowerSourceID){$selected=' selected';}else{$selected='';}
print "\t\t\t\t\t\t\t\t<option value=\"$psRow->PowerSourceID\"$selected>$psRow->SourceName</option>\n";
}
echo ' </select></div>
</div>
<div>
<div><label for="sourcename">'.__("Name"),'</label></div>
<div><input type="text" name="sourcename" id="sourcename" size="50" value="',$ps->SourceName,'"></div>
</div>
<div>
<div><label for="datacenterid">',__("Data Center"),'</label></div>
<div><select name="datacenterid" id="datacenterid">';
foreach($dcList as $dcRow){
if($dcRow->DataCenterID==$ps->DataCenterID){$selected=' selected';}else{$selected='';}
print "\t\t\t\t\t\t\t\t<option value=\"$dcRow->DataCenterID\"$selected>$dcRow->Name</option>\n";
}
echo ' </select></div>
</div>
<div>
<div><label for="ipaddress">',__("IP Address / Host Name"),'</label></div>
<div><input type="text" name="ipaddress" id="ipaddress" size="20" value="',$ps->IPAddress,'"></div>
</div>
<div>
<div><label for="community">',__("SNMP Community"),'</label></div>
<div><input type="text" name="community" id="community" size=40 value="',$ps->Community,'"></div>
</div>
<div>
<div><label for="loadoid">',__("Load OID"),'</label></div>
<div><input type="text" name="loadoid" id="loadoid" size=60 value="',$ps->LoadOID,'"></div>
</div>
<div>
<div><label for="capacity">',__("Capacity"),' (kW)</label></div>
<div><input type="number" name="capacity" id="capacity" size=8 value="',$ps->Capacity,'"></div>
</div>
<div class="caption">';
if($ps->PowerSourceID >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>
</div></div>
<?php echo ' <a href="index.php">[ ',__("Return to Main Menu"),' ]</a>'; ?>
<?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 Source 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 source and all panels fed from it?"),'
</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('', {powersourceid: $('#powersourceid').val(),deletepowersource: '' }, 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>