-
Notifications
You must be signed in to change notification settings - Fork 2
/
datacenter.php
executable file
·438 lines (385 loc) · 14 KB
/
datacenter.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
<?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;
}
$status="";
$dc=new DataCenter();
// AJAX Action
if(isset($_POST['confirmdelete']) && isset($_POST['datacenterid'])){
// About the nuke this place from orbit
$junkremoval=($_POST['junkremoval']=='delete')?true:false;
$dc->DataCenterID=$_POST['datacenterid'];
if($dc->DeleteDataCenter($junkremoval)){
echo 'ok';
}else{
echo 'no';
}
exit;
}
if(isset($_POST['action'])&&(($_POST['action']=='Create')||($_POST['action']=='Update'))){
$dc->DataCenterID=$_POST['datacenterid'];
$dc->Name=trim($_POST['name']);
$dc->SquareFootage=$_POST['squarefootage'];
$dc->DeliveryAddress=$_POST['deliveryaddress'];
$dc->Administrator=$_POST['administrator'];
$dc->DrawingFileName=$_POST['drawingfilename'];
$dc->MaxkW=$_POST['maxkw'];
$dc->ContainerID=$_POST['container'];
$dc->MapX=$_POST['x'];
$dc->MapY=$_POST['y'];
if($dc->Name!=""){
if($_POST['action']=='Create'){
$dc->CreateDataCenter();
}else{
$status=__("Updated");
$dc->UpdateDataCenter();
}
}
}
if(isset($_POST['cambio_cont'])&& $_POST['cambio_cont']=='SI'){
$dc->DataCenterID=$_POST['datacenterid'];
$dc->Name=trim($_POST['name']);
$dc->SquareFootage=$_POST['squarefootage'];
$dc->DeliveryAddress=$_POST['deliveryaddress'];
$dc->Administrator=$_POST['administrator'];
$dc->DrawingFileName=$_POST['drawingfilename'];
$dc->MaxkW=$_POST['maxkw'];
$dc->ContainerID=$_POST['container'];
if ($dc->ContainerID==0){
$dc->MapX=0;
$dc->MapY=0;
}else{
$dc->MapX=$_POST['x'];
$dc->MapY=$_POST['y'];
}
}
elseif(isset($_REQUEST['datacenterid'])&&$_REQUEST['datacenterid'] >0){
$dc->DataCenterID=(isset($_POST['datacenterid']) ? $_POST['datacenterid'] : $_GET['datacenterid']);
$dc->GetDataCenter();
}
$dcList=$dc->GetDCList();
if ( $config->ParameterArray["mUnits"] == "english" )
$vol = __("Square Feet");
else
$vol = __("Square Meters");
$imageselect='<div id="preview"></div><div id="filelist">';
$path='./drawings';
$dir=scandir($path);
foreach($dir as $i => $f){
if(is_file($path.DIRECTORY_SEPARATOR.$f)){
$mimeType=mime_content_type($path.DIRECTORY_SEPARATOR.$f);
if(preg_match('/^image/i', $mimeType)){
$imageselect.="<span>$f</span>\n";
}
}
}
$imageselect.="</div>";
?>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>VIO DCIM Data Center Inventory</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() {
$('#datacenterform').validationEngine({});
$('#drawingfilename').click(function(){
$("#imageselection").dialog({
resizable: false,
height:500,
width: 600,
modal: true,
buttons: {
<?php echo ' ',__("Select"),': function() {'; ?>
if($('#imageselection #preview').attr('image')!=""){
$('#drawingfilename').val($('#imageselection #preview').attr('image'));
}
$(this).dialog("close");
}
}
});
$("#imageselection span").each(function(){
var preview=$('#imageselection #preview');
$(this).click(function(){
preview.css({'border-width': '5px', 'width': '380px', 'height': '380px'});
preview.html('<img src="drawings/'+$(this).text()+'" alt="preview">').attr('image',$(this).text());
preview.children('img').load(function(){
var topmargin=0;
var leftmargin=0;
if($(this).height()<$(this).width()){
$(this).width(preview.innerHeight());
$(this).css({'max-width': preview.innerWidth()+'px'});
topmargin=Math.floor((preview.innerHeight()-$(this).height())/2);
}else{
$(this).height(preview.innerHeight());
$(this).css({'max-height': preview.innerWidth()+'px'});
leftmargin=Math.floor((preview.innerWidth()-$(this).width())/2);
}
$(this).css({'margin-top': topmargin+'px', 'margin-left': leftmargin+'px'});
});
$("#imageselection span").each(function(){
$(this).removeAttr('style');
});
$(this).css('border','1px dotted black')
});
if($('#drawingfilename').val()==$(this).text()){
$(this).click();
}
});
});
$('#delete-btn').click(function(){
var defaultbutton={
"<?php echo __("Yes"); ?>": function(){
$.post('', {datacenterid: $('#datacenterid').val(),confirmdelete: '',junkremoval: $('#deletemodal select').val()}, function(data){
if(data.trim()=='ok'){
self.location="datacenter.php";
console.log(self.location);
$(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)
});
});
});
function coords(evento){
mievento = evento || window.event;
yo=document.getElementById("yo");
x=mievento.layerX;
y=mievento.layerY;
yo.style.left=(x-12)+"px";
yo.style.top=(y-12)+"px";
yo.hidden=false;
CoorX=document.getElementById("x");
CoorX.value=x*2;
CoorY=document.getElementById("y");
CoorY.value=y*2;
}
function mueve(){
tam=50;
red=.5;
tam=tam*red;
yo=document.getElementById("yo");
cont=document.getElementById("containerimg");
CoorX=document.getElementById("x");
CoorY=document.getElementById("y");
if (CoorX.value<0) CoorX.value=0;
if (CoorX.value*red>cont.offsetWidth) CoorX.value=cont.offsetWidth/red;
if (CoorY.value<0) CoorY.value=0;
if (CoorY.value*red>cont.offsetHeight) CoorY.value=cont.offsetHeight/red;
yo.style.left=(CoorX.value*red-tam/2)+"px";
yo.style.top=(CoorY.value*red-tam/2)+"px";
if (CoorX.value<0 || CoorX.value*red>cont.offsetWidth
|| CoorY.value<0 || CoorY.value*red>cont.offsetHeight)
yo.hidden=true;
else
yo.hidden=false;
}
function cambio_container(){
document.getElementById("cambio_cont").value="SI";
document.getElementById("datacenterform").submit();
}
</script>
<style type="text/css">
.container2{height:300px}
#status{position:fixed;left:0px;top:0px;width:100%;height:140px;overflow:hidden}
#status div{background-color:rgba(13, 13, 13, 0.5);width:100%;height:100%;padding:10px 10px 10px 10px;font:13px bold sans-serif;color:#fff}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/maptalks.css">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/maptalks.min.js"></script>
</head>
<body>
<?php include( 'header.inc.php' ); ?>
<div class="backgroundpage">
<div class="page1">
<div class="makecenter">
<?php
// include( 'sidebar.inc.php' );
echo '<div class="main">
<h3>',$status,'</h3>
<div class="center"><div>
<form id="datacenterform" method="POST">
<div class="table">
<div>
<div><label for="datacenterid">',__("Data Center ID"),'</label></div>
<div><select name="datacenterid" id="datacenterid" onChange="form.submit()">
<option value="0">',__("New Data Center"),'</option>';
foreach($dcList as $dcRow){
if($dcRow->DataCenterID == $dc->DataCenterID){$selected=" selected";}else{$selected="";}
print "<option value=\"$dcRow->DataCenterID\"$selected>$dcRow->Name</option>\n";
}
echo ' </select></div>
</div>
<div>
<div><label for="dcname">',__("Name"),'</label></div>
<div><input class="validate[required,minSize[3],maxSize[80]]" type="text" name="name" id="dcname" size="50" maxlength="80" value="',$dc->Name,'"></div>
</div>
<div>
<div><label for="sqfootage">',$vol,'</label></div>
<div><input class="validate[optional,custom[onlyNumberSp]]" type="text" name="squarefootage" id="sqfootage" size="10" maxlength="11" value="',$dc->SquareFootage,'"></div>
</div>
<div>
<div><label for="deliveryaddress">',__("Delivery Address"),'</label></div>
<div><input class="validate[optional,minSize[1],maxSize[200]]" type="text" name="deliveryaddress" id="deliveryaddress" size="60" maxlength="200" value="',$dc->DeliveryAddress,'"></div>
</div>
<div>
<div><label for="administrator">',__("Administrator"),'</label></div>
<div><input class="validate[optional,minSize[1],maxSize[80]]" type="text" type="text" name="administrator" id="administrator" size=60 maxlength="80" value="',$dc->Administrator,'"></div>
</div>
<div>
<div><label for="drawingfilename">',__("Drawing URL"),'</label></div>
<div><input type="text" name="drawingfilename" id="drawingfilename" size=60 value="',$dc->DrawingFileName,'"></div>
</div>
<div>
<div><label for="maxkw">',__("Design Maximum (kW)"),'</label></div>
<div><input class="validate[optional,custom[onlyNumberSp]]" type="text" name="maxkw" id="maxkw" size="8" maxlength="8" value="',$dc->MaxkW,'"></div>
</div>
<div><input type="hidden" name="cambio_cont" id="cambio_cont" value=""></div>
<div>
<div><label for="container">',__("Container"),'</label></div>
<div><select name="container" id="container" onChange="cambio_container()">
<option value="0">',__("None"),'</option>';
$container=new Container();
$cList=$container->GetContainerList();
foreach($cList as $cRow){
if($cRow->ContainerID == $dc->ContainerID){$selected=" selected";}else{$selected="";}
print "<option value=\"$cRow->ContainerID\"$selected>$cRow->Name</option>\n";
}
echo ' </select></div>
</div>
<div>
<div><b>Longitude</b></div>
<div><input type="number" name="x" id="x" step="any" value="',$dc->MapX,'"></div>
</div>
<div>
<div><b>Latitude</b></div>
<div><input type="number" name="y" id="y" step="any" value="',$dc->MapY,'"></div>
</div>';
if ($dc->ContainerID>0){
print "<div id=map class=container2>\n";
print "</div>";
// $container->ContainerID=$dc->ContainerID;
// $container->GetContainer();
// print $container->MakeContainerMiniImage("dc",$dc->DataCenterID);
$db = new mysqli('localhost', 'root', 'root', 'dcim');
$sql = "SELECT MapX as 'lat', MapY as 'lng' FROM `fac_DataCenter` WHERE DataCenterID='$dc->DataCenterID'";
$res = $db->query( $sql );
$places=array();
// if( $res ) while( $rs=$res->fetch_object() ) $tempat=array_push($places,'name'=>$rs->name, 'latitude'=>$rs->lat, 'longitude'=>$rs->lng);
while($row = $res->fetch_assoc()) {
$places[] = $row;
}
$mapping="[";
foreach ($places as $key) {
$mapping.=$key['lat'].",";
$mapping.=$key['lng']."]".",";
// echo "["."'".$key['name']."'".",";
// echo $key['lat'].",";
// echo $key['lng']."]".",";
// echo "<br>";
}
$mapping= substr_replace($mapping ,"",-1);
}
echo '<div class="caption">';
if($dc->DataCenterID >0){
echo ' <button type="submit" name="action" value="Update">',__("Update"),'</button>';
}else{
echo ' <button type="submit" name="action" value="Create">',__("Create"),'</button>';
}
if ( $person->SiteAdmin && $dc->DataCenterID > 0 ) {
echo ' <button type="button" id="delete-btn" name="action" value="Delete">',__("Delete"),'</button>';
}
?>
</div>
</div> <!-- END div.table -->
</form>
<?php echo '
<div id="imageselection" title="Image file selector">
',$imageselect,'
</div>
</div></div>
<!-- hiding modal dialogs here so they can be translated easily -->
<div class="hide">
<div title="',__("Data Center Deletion Confirmation"),'" id="deletemodal">
<div id="modaltext"><img src="images/mushroom_cloud.jpg" class="floatleft">',__("Are you sure that you want to delete this data center and all contents within it?"),'
<select><option value="delete">',__("Delete"),'</option></select></p>
</div>
</div>
</div>
'; ?>
</div><!-- END div.main -->
</div><!-- END div.page -->
</div>
</div>
<script>
var mapping = <?php echo json_encode($mapping) ?>;
var mapping= JSON.parse(mapping);
var map = new maptalks.Map('map', {
center: mapping,
zoom: 17,
centerCross: true,
zoomControl : true,
baseLayer: new maptalks.TileLayer('base', {
urlTemplate: 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: ['a','b','c','d'],
attribution: '© <a href="http://vioint.co.id">VIO DCIM</a> '
}),
layers: [
new maptalks.VectorLayer('v')
]
});
map.on('zoomend moving moveend', getStatus);
getStatus();
function getStatus() {
var extent = map.getExtent(),
ex = [
'{',
'xmin:' + extent.xmin.toFixed(5),
', ymin:' + extent.ymin.toFixed(5),
', xmax:' + extent.xmax.toFixed(5),
', ymax:' + extent.xmax.toFixed(5),
'}'
].join('');
var center = map.getCenter();
var mapStatus = [
'Center : [' + [center.x.toFixed(5), center.y.toFixed(5)].join() + ']',
];
CoorX=document.getElementById("x");
CoorX.value=center.x.toFixed(5);
CoorY=document.getElementById("y");
CoorY.value=center.y.toFixed(5);
// document.getElementById('status').innerHTML = '<div>' + mapStatus.join('<br>') + '</div>';
}
</script>
</body>
</html>