-
Notifications
You must be signed in to change notification settings - Fork 205
/
cabrow.php
208 lines (180 loc) · 6.53 KB
/
cabrow.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
<?php
require_once("db.inc.php");
require_once("facilities.inc.php");
$subheader=__("Rows of Cabinets");
if(!$person->SiteAdmin){
// No soup for you.
header('Location: '.redirect());
exit;
}
$cabrow=new CabRow();
$zone=new Zone();
$DC=new DataCenter();
$zoneList=$zone->GetZoneList();
$formpatch="";
$status="";
if(isset($_POST['action']) && $_POST['action']=='Delete'){
$cabrow->CabRowID=$_POST['cabrowid'];
$cabrow->DeleteCabRow();
header('Location: cabrow.php');
exit;
}
if(isset($_REQUEST["cabrowid"])) {
$cabrow->CabRowID=(isset($_POST['cabrowid'])?$_POST['cabrowid']:$_GET['cabrowid']);
$cabrow->GetCabRow();
if(isset($_POST["action"]) && (($_POST["action"]=="Create") || ($_POST["action"]=="Update"))){
$cabrow->Name=$_POST["name"];
$cabrow->DataCenterID=$_POST["datacenterid"];
$cabrow->ZoneID=$_POST["zoneid"];
if($_POST["action"]=="Create"){
$cabrow->CreateCabRow();
}else{
if ($cabrow->UpdateCabRow())
$status=__("Updated");
}
}
$formpatch="?cabrowid={$_REQUEST['cabrowid']}";
}
$dcList=$DC->GetDCList();
$idcList=$DC->GetDCList(true); //indexed by id
$izoneList=$zone->GetZoneList(true); //indexed by id
$cabrowList=$cabrow->GetCabRowList();
?>
<!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 Rows of Cabinets</title>
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css">
<link rel="stylesheet" href="css/validationEngine.jquery.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/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="scripts/jquery.validationEngine.js"></script>
<script type="text/javascript" src="scripts/common.js?v<?php echo filemtime('scripts/common.js');?>"></script>
<script type="text/javascript">
$(document).ready(function() {
// Enforce datacenter <-> zone relationship
$('#zoneid').on('change',function(){
if(this.value>0){
$('#datacenterid').attr('disabled','');
$('#datacenterid').val($(this.options[this.selectedIndex]).data('dcid'));
}else{
$('#datacenterid').removeAttr('disabled');
}
}).change();
$("#cabrowid").combobox();
$("#datacenterid").combobox();
$("#zoneid").combobox();
$('span.custom-combobox').width($('span.custom-combobox').width()+2);
// Input options that are disabled don't submit
$('.caption > button').on('click',function(e){
$('#datacenterid').removeAttr('disabled');
});
// Don't attempt to open the datacenter tree until it is loaded
function opentree(){
if($('#datacenters .bullet').length==0){
setTimeout(function(){
opentree();
},500);
}else{
expandToItem('datacenters','cr<?php echo $cabrow->CabRowID;?>');
}
}
opentree();
// Delete container confirmation dialog
$('button[value="Delete"]').click(function(e){
var form=$(this).parents('form');
var btn=$(this);
<?php
print " var dialog=$('<div>').prop('title','".__("Verify Delete Row")."').html('<p><span class=\"ui-icon ui-icon-alert\" style=\"float:left; margin:0 7px 20px 0;\"></span><span></span></p>');";
print " dialog.find('span + span').html('".__("This Row will be deleted and there is no undo. Assets within the row will remain as members of the Data Center.")."<br>".__("Are you sure?")."');";
?>
dialog.dialog({
resizable: false,
modal: true,
dialogClass: "no-close",
buttons: {
<?php echo ' ',__("Yes"),': function(){'; ?>
$(this).dialog("destroy");
form.append('<input type="hidden" name="'+btn.attr("name")+'" value="'+btn.val()+'">');
form.submit();
},
<?php echo ' ',__("No"),': function(){'; ?>
$(this).dialog("destroy");
}
}
});
});
});
</script>
</head>
<body>
<?php include( 'header.inc.php' ); ?>
<div class="page cabrow">
<?php
include( "sidebar.inc.php" );
echo '<div class="main">
<h3>',$status,'</h3>
<div class="center"><div>
<form action="',$_SERVER["SCRIPT_NAME"].$formpatch,'" method="POST">
<div class="table">
<div>
<div><label for="cabrowid">',__("Row"),'</label></div>
<div><input type="hidden" name="action" value="query">
<select name="cabrowid" id="cabrowid" onChange="form.submit()">
<option value=0>',__("New Row"),'</option>';
foreach($cabrowList as $cabrowRow){
$selected=($cabrow->CabRowID==$cabrowRow->CabRowID)?" selected":"";
// Suppressing errors because there shouldn't be any value for 0 in the dc and zone lists
@print "<option value=\"$cabrowRow->CabRowID\"$selected>[{$idcList[$cabrowRow->DataCenterID]->Name}/{$izoneList[$cabrowRow->ZoneID]->Description}] $cabrowRow->Name</option>\n";
}
echo ' </select></div>
</div>
<div>
<div><label for="name">',__("Name"),'</label></div>
<div><input type="text" size="50" name="name" id="name" value="',$cabrow->Name,'"></div>
</div>
<div>
<div><label for="datacenterid">',__("Data Center"),'</label></div>
<div><select name="datacenterid" id="datacenterid">
<option value=0></option>';
foreach($dcList as $dc){
$selected=($cabrow->DataCenterID==$dc->DataCenterID)?" selected":"";
print "<option value=\"$dc->DataCenterID\"$selected>$dc->Name</option>\n";
}
echo ' </select></div>
</div>
<div>
<div><label for="zoneid">',__("Data Center Zone"),'</label></div>
<div><select name="zoneid" id="zoneid">
<option value=0></option>';
foreach($zoneList as $zoneRow){
$selected=($cabrow->ZoneID==$zoneRow->ZoneID)?" selected":"";
print "<option data-dcid=$zoneRow->DataCenterID value=\"$zoneRow->ZoneID\"$selected>[{$idcList[$zoneRow->DataCenterID]->Name}] $zoneRow->Description</option>\n";
}
echo ' </select></div>
</div>';
if($cabrow->CabRowID==0){
echo '<div><div> </div><div></div></div>
<div class="caption"><button type="submit" name="action" value="Create">',__("Create"),'</button></div>';
}
else{
echo '<div><div> </div><div></div></div>
<div class="caption"><button type="submit" name="action" value="Update">',__("Update"),'</button>
<button type="button" name="action" value="Delete">',__("Delete"),'</button></div>';
}
?>
</div><!-- END div.table -->
</form>
</div></div>
<?php echo '<a href="index.php">[ ',__("Return to Main Menu"),' ]</a>'; ?>
</div><!-- END div.main -->
</div><!-- END div.page -->
</body>
</html>