forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapmaker.php
204 lines (189 loc) · 6.28 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
<?php
require_once( "db.inc.php" );
require_once( "facilities.inc.php" );
$subheader=__("Map Selector");
if(!$person->SiteAdmin){
// No soup for you.
header("Location: ".redirect());
exit;
}
$dc=new DataCenter();
$cab=new Cabinet();
$cab->CabinetID=$_REQUEST["cabinetid"];
$cab->GetCabinet();
$dc->DataCenterID=$cab->DataCenterID;
$dc->GetDataCenter();
if(isset($_REQUEST["action"])&&($_REQUEST["action"]=="Submit")){
$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");
header("Location: $url");
}
$height=0;
$width=0;
if(strlen($dc->DrawingFileName) >0){
$mapfile="drawings/$dc->DrawingFileName";
if(file_exists($mapfile)){
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">
<input type="hidden" name="cabinetid" value="<?php printf( "%d", $cab->CabinetID ); ?>">
<div>
<div><b>X<sub>1</sub>:</b></div>
<div><input type="text" name="x1" id="x1" value="<?php echo $cab->MapX1; ?>"></div>
</div>
<div>
<div><b>Y<sub>1</sub>:</b></div>
<div><input type="text" name="y1" id="y1" value="<?php echo $cab->MapY1; ?>"></div>
</div>
<div>
<div><b>X<sub>2</sub>:</b></div>
<div><input type="text" name="x2" id="x2" value="<?php echo $cab->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 $cab->MapY2; ?>"></div>
<div></div>
<div></div>
</div>
<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>
</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 cabinet"),' ',$cab->Location; ?>.</p>
<div class="frame" style="margin: 0 0.3em; width: 300px; height: 300px;">
<?php
$errors=array();
$mapfile="drawings/$dc->DrawingFileName";
if(!strlen($dc->DrawingFileName)>0){$errors[]=__("You must configure an image for this datacenter 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=\"drawings/$dc->DrawingFileName\">";
}
?>
</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: $cab->MapX1,
x2: $cab->MapX2,
y1: $cab->MapY1,
y2: $cab->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');
expandToItem('datacenters',firstcabinet);
}
}
opentree();
});
</script>
</body>
</html>