forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapmaker.php
271 lines (245 loc) · 7.91 KB
/
mapmaker.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
<?php
require_once( "db.inc.php" );
require_once( "facilities.inc.php" );
$subheader=__("Map Selector");
if ( !$person->SiteAdmin && !isset( $_REQUEST['cabinetid']) && !isset($_REQUEST['panelid'])) {
header("Location: ".redirect());
exit;
}
$dc=new DataCenter();
$cab=new Cabinet();
if ( isset( $_REQUEST['cabinetid'] )) {
$cab=new Cabinet();
$cab->CabinetID=$_REQUEST["cabinetid"];
$cab->GetCabinet();
$MapX1 = $cab->MapX1;
$MapX2 = $cab->MapX2;
$MapY1 = $cab->MapY1;
$MapY2 = $cab->MapY2;
$name = $cab->Location;
$dc->DataCenterID=$cab->DataCenterID;
} else {
$pan = new PowerPanel();
$pan->PanelID = $_REQUEST['panelid'];
$pan->getPanel();
$MapX1 = $pan->MapX1;
$MapX2 = $pan->MapX2;
$MapY1 = $pan->MapY1;
$MapY2 = $pan->MapY2;
$name = $pan->PanelLabel;
$dc->DataCenterID = $pan->MapDataCenterID;
}
$dc->GetDataCenter();
if(isset($_REQUEST["action"])&&($_REQUEST["action"]=="Submit")){
if ( isset( $_REQUEST['cabinetid'] )) {
$cab->MapX1=intval($_REQUEST["x1"]);
$cab->MapX2=intval($_REQUEST["x2"]);
$cab->MapY1=intval($_REQUEST["y1"]);
$cab->MapY2=intval($_REQUEST["y2"]);
$cab->FrontEdge=$_REQUEST["frontedge"];
$cab->UpdateCabinet();
$url=redirect("cabnavigator.php?cabinetid=$cab->CabinetID");
} else {
$pan->MapX1=intval($_REQUEST["x1"]);
$pan->MapX2=intval($_REQUEST["x2"]);
$pan->MapY1=intval($_REQUEST["y1"]);
$pan->MapY2=intval($_REQUEST["y2"]);
$pan->updatePanel();
$url=redirect("power_panel.php?PanelID=$pan->PanelID");
}
header("Location: $url");
}
$height=0;
$width=0;
if(strlen($dc->DrawingFileName) >0){
$mapfile=$config->ParameterArray["drawingpath"] . "$dc->DrawingFileName";
if(file_exists($mapfile)){
if(mime_content_type($mapfile)=='image/svg+xml'){
$svgfile = simplexml_load_file($mapfile);
$width = substr($svgfile['width'],0,4);
$height = substr($svgfile['height'],0,4);
}else{
list($width, $height, $type, $attr)=getimagesize($mapfile);
}
// There is a bug in the excanvas shim that can set the width of the canvas to 10x the width of the image
$ie8fix='
<script type="text/javascript">
function uselessie(){
document.getElementById(\'mapCanvas\').className = "mapCanvasiefix";
}
</script>';
}
}
?>
<!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 Information Management</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/imgareaselect-default.css" type="text/css">
<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.imgareaselect.pack.js"></script>
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css">
<?php if(isset($ie8fix)){echo $ie8fix;} ?>
<![endif]-->
<?php if(isset($screenadjustment)){echo $screenadjustment;} ?>
<script type="text/javascript">
$(document).keydown(function(event){
if (event.ctrlKey && event.keyCode == 83) {
$('input[name=action]').trigger('click');
return false;
}
});
</script>
</head>
<body>
<?php include( 'header.inc.php' ); ?>
<div class="page" id="mapadjust">
<?php
include( "sidebar.inc.php" );
?>
<div class="main">
<div class="mapmaker">
<div>
</div>
<div class="table">
<div class="title"><?php echo __("Coordinates"); ?></div>
<form method="POST">
<div class="table">
<?php
if ( isset($_REQUEST['cabinetid']) ) {
print '<input type="hidden" name="cabinetid" value="'.$cab->CabinetID.'">';
} else {
print '<input type="hidden" name="panelid" value="'.$pan->PanelID.'">';
}
?>
<div>
<div><b>X<sub>1</sub>:</b></div>
<div><input type="text" name="x1" id="x1" value="<?php echo $MapX1; ?>"></div>
</div>
<div>
<div><b>Y<sub>1</sub>:</b></div>
<div><input type="text" name="y1" id="y1" value="<?php echo $MapY1; ?>"></div>
</div>
<div>
<div><b>X<sub>2</sub>:</b></div>
<div><input type="text" name="x2" id="x2" value="<?php echo $MapX2; ?>"></div>
<div></div>
<div></div>
</div>
<div>
<div><b>Y<sub>2</sub>:</b></div>
<div><input type="text" name="y2" id="y2" value="<?php echo $MapY2; ?>"></div>
<div></div>
<div></div>
</div>
<?php
if ( isset( $_REQUEST['cabinetid'])) {
?>
<div>
<div><b><?php print __("Front Edge"); ?></b></div>
<div><select name="frontedge">
<?php
$edgearray=array('Top' => __("Top"),
'Right' => __("Right"),
'Bottom' => __("Bottom"),
'Left' => __("Left"));
foreach($edgearray as $edge => $translation){
$selected=($edge==$cab->FrontEdge)?' SELECTED':'';
print "\t\t\t\t<option value=\"$edge\"$selected>$translation</option>\n";
}
?>
</select></div>
<div></div>
</div>
<div class="caption">
<input type="submit" name="action" value="Submit">
<button type="reset" onclick="document.location.href='cabnavigator.php?cabinetid=<?php echo $cab->CabinetID; ?>'; return false;">Cancel</button>
</div>
<?php
} else {
?>
<div class="caption">
<input type="submit" name="action" value="Submit">
<button type="reset" onclick="document.location.href='power_panel.php?PanelID=<?php echo $pan->PanelID; ?>'; return false;">Cancel</button>
</div>
<?php
}
?>
</div> <!-- END div.table -->
</form>
</div>
</div> <!-- END div.mapmaper -->
<div class="center"><div>
<?php echo "<img src=\"css/blank.gif\" height=$height width=$width>"; ?>
<div class="container demo">
<div style="float: left; width: 70%;">
<p class="instructions"><?php echo __("Click and drag on the image to select an area for "),' ',$name; ?>.</p>
<div class="frame" style="margin: 0 0.3em; width: 300px; height: 300px;">
<?php
$errors=array();
$mapfile=$config->ParameterArray["drawingpath"] . "$dc->DrawingFileName";
if(!strlen($dc->DrawingFileName)>0){$errors[]=__("You must configure an image for this data center before attempting to place a cabinet on its map.");}
if(!is_file($mapfile)){$errors[]=sprintf(__("Please check that "%s" is actually a file."),$dc->DrawingFileName);}
if(!is_readable($mapfile)){$errors[]=sprintf(__("Please check the permissions on %s and make sure it is readable."),$dc->DrawingFileName);}
if(count($errors)>0){
foreach($errors as $error){
print "<p class=\"warning\">$error</p>\n";
}
}else{
print "<img id=\"map\" src=\"$mapfile\">";
}
?>
</div>
</div>
<div style="float: left; width: 30%;">
<p style="font-size: 110%; font-weight: bold; padding-left: 0.1em;"><?php echo __("Selection Preview"); ?></p>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
function preview(img, selection) {
if (!selection.width || !selection.height){
return;
}
$('#x1').val(selection.x1);
$('#y1').val(selection.y1);
$('#x2').val(selection.x2);
$('#y2').val(selection.y2);
}
$('#map').imgAreaSelect( {
<?php
print "\t\tx1: $MapX1,
x2: $MapX2,
y1: $MapY1,
y2: $MapY2,\n";
?>
handles: true,
onSelectChange: preview
});
// Don't attempt to open the datacenter tree until it is loaded
function opentree(){
if($('#datacenters .bullet').length==0){
setTimeout(function(){
opentree();
},500);
}else{
var firstcabinet=$('#dc<?php echo $dc->DataCenterID;?> > ul > li:first-child').attr('id');
// If we have no children,
if (typeof firstcabinet == 'undefined') {
// use the 1st-born child of our parent: may, or may not, be us
firstcabinet=$('#dc<?php echo $dc->DataCenterID;?> ').attr('id');
}
expandToItem('datacenters',firstcabinet);
}
}
opentree();
});
</script>
</body>
</html>