Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / gis_data_editor.php
blob23ce037bb0ed9d2b419c5acf2f98eb1ce19fd79c
1 <?php
2 require_once './libraries/common.inc.php';
3 if (! isset($_REQUEST['get_gis_editor']) && ! isset($_REQUEST['generate'])) {
4 require_once './libraries/header_http.inc.php';
5 require_once './libraries/header_meta_style.inc.php';
7 require_once './libraries/gis/pma_gis_factory.php';
8 require_once './libraries/gis_visualization.lib.php';
10 // Get data if any posted
11 $gis_data = array();
12 if (PMA_isValid($_REQUEST['gis_data'], 'array')) {
13 $gis_data = $_REQUEST['gis_data'];
16 $gis_types = array(
17 'POINT',
18 'MULTIPOINT',
19 'LINESTRING',
20 'MULTILINESTRING',
21 'POLYGON',
22 'MULTIPOLYGON',
23 'GEOMETRYCOLLECTION'
26 // Extract type from the initial call and make sure that it's a valid one.
27 // Extract from field's values if availbale, if not use the column type passed.
28 if (! isset($gis_data['gis_type'])) {
29 if (isset($_REQUEST['type']) && $_REQUEST['type'] != '') {
30 $gis_data['gis_type'] = strtoupper($_REQUEST['type']);
32 if (isset($_REQUEST['value']) && trim($_REQUEST['value']) != '') {
33 $start = (substr($_REQUEST['value'], 0, 1) == "'") ? 1 : 0;
34 $gis_data['gis_type'] = substr($_REQUEST['value'], $start, strpos($_REQUEST['value'], "(") - $start);
36 if ((! isset($gis_data['gis_type'])) || (! in_array($gis_data['gis_type'], $gis_types))) {
37 $gis_data['gis_type'] = $gis_types[0];
40 $geom_type = $gis_data['gis_type'];
42 // Generate parameters from value passed.
43 $gis_obj = PMA_GIS_Factory::factory($geom_type);
44 if (isset($_REQUEST['value'])) {
45 $gis_data = array_merge($gis_data, $gis_obj->generateParams($_REQUEST['value']));
48 // Generate Well Known Text
49 $srid = (isset($gis_data['srid']) && $gis_data['srid'] != '') ? htmlspecialchars($gis_data['srid']) : 0;
50 $wkt = $gis_obj->generateWkt($gis_data, 0);
51 $wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
52 $result = "'" . $wkt . "'," . $srid;
54 // Gererate PNG or SVG based visualization
55 $format = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8) ? 'png' : 'svg';
56 $visualizationSettings = array('width' => 450, 'height' => 300, 'spatialColumn' => 'wkt');
57 $data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
58 $visualization = PMA_GIS_visualizationResults($data, $visualizationSettings, $format);
59 $open_layers = PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
61 // If the call is to update the WKT and visualization make an AJAX response
62 if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
63 $extra_data = array(
64 'result' => $result,
65 'visualization' => $visualization,
66 'openLayers' => $open_layers,
68 PMA_ajaxResponse(null, true, $extra_data);
71 // If the call is to get the whole content, start buffering, skipping </head> and <body> tags
72 if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) {
73 ob_start();
74 } else {
76 </head>
77 <body>
78 <?php
81 <form id="gis_data_editor_form" action="gis_data_editor.php" method="post">
82 <input type="hidden" id="pmaThemeImage" value="<?php echo($GLOBALS['pmaThemeImage']); ?>" />
83 <div id="gis_data_editor">
84 <h3><?php printf(__('Value for the column "%s"'), htmlspecialchars($_REQUEST['field'])); ?></h3>
86 <?php echo('<input type="hidden" name="field" value="' . htmlspecialchars($_REQUEST['field']) . '" />');
87 // The input field to which the final result should be added and corresponding null checkbox
88 if (isset($_REQUEST['input_name'])) {
89 echo('<input type="hidden" name="input_name" value="' . htmlspecialchars($_REQUEST['input_name']) . '" />');
91 echo PMA_generate_common_hidden_inputs();
93 <!-- Visualization section -->
94 <div id="placeholder" style="width:450px;height:300px;
95 <?php if ($srid != 0) {
96 echo('display:none;');
98 ?> ">
99 <?php echo ($visualization);
100 ?> </div>
101 <div id="openlayersmap" style="width:450px;height:300px;
102 <?php if ($srid == 0) {
103 echo('display:none;');
105 ?> ">
106 </div>
107 <div class="choice" style="float:right;clear:right;">
108 <input type="checkbox" id="choice" value="useBaseLayer"
109 <?php if ($srid != 0) {
110 echo(' checked="checked"');
112 ?> />
113 <label for="choice"><?php echo __("Use OpenStreetMaps as Base Layer"); ?></label>
114 </div>
115 <script language="javascript" type="text/javascript">
116 <?php echo($open_layers); ?>
117 </script>
118 <!-- End of visualization section -->
120 <!-- Header section - Inclueds GIS type selector and input field for SRID -->
121 <div id="gis_data_header">
122 <select name="gis_data[gis_type]" class="gis_type">
123 <?php
124 foreach ($gis_types as $gis_type) {
125 echo('<option value="' . $gis_type . '"');
126 if ($geom_type == $gis_type) {
127 echo(' selected="selected"');
129 echo('>' . $gis_type . '</option>');
132 </select>
133 <input type="submit" name="gis_data[go]" class="go" value="<?php echo __("Go")?>" />
134 <label for="srid"><?php echo __("SRID"); ?>:&nbsp;</label>
135 <input name="gis_data[srid]" type="text" value="<?php echo($srid); ?>" />
136 </div>
137 <!-- End of header section -->
139 <!-- Data section -->
140 <div id="gis_data">
141 <?php $geom_count = 1;
142 if ($geom_type == 'GEOMETRYCOLLECTION') {
143 $geom_count = (isset($gis_data[$geom_type]['geom_count'])) ? $gis_data[$geom_type]['geom_count'] : 1;
144 if (isset($gis_data[$geom_type]['add_geom'])) {
145 $geom_count++;
147 echo('<input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]" value="' . $geom_count . '">');
149 for ($a = 0; $a < $geom_count; $a++) {
150 if ($geom_type == 'GEOMETRYCOLLECTION') {
151 echo('<br/><br/>'); echo __("Geometry"); echo($a + 1 . ':<br/>');
152 if (isset($gis_data[$a]['gis_type'])) {
153 $type = $gis_data[$a]['gis_type'];
154 } else {
155 $type = $gis_types[0];
157 echo('<select name="gis_data[' . $a . '][gis_type]" class="gis_type">');
158 foreach (array_slice($gis_types, 0, 6) as $gis_type) {
159 echo('<option value="' . $gis_type . '"');
160 if ($type == $gis_type) {
161 echo(' selected="selected"');
163 echo('>' . $gis_type . '</option>');
165 echo('</select>');
166 echo('<input type="submit" name="gis_data[' . $a . '][go]" class="go" value="'); echo __("Go"); echo('">');
167 } else {
168 $type = $geom_type;
171 if ($type == 'POINT') {
172 echo('<br/>'); echo __("Point"); echo(' :');
173 ?> <label for="x"><?php echo __("X"); ?></label>
174 <input name="gis_data[<?php echo($a); ?>][POINT][x]" type="text" value="<?php echo(isset($gis_data[$a]['POINT']['x']) ? htmlspecialchars($gis_data[$a]['POINT']['x']) : ''); ?>" />
175 <label for="y"><?php echo __("Y"); ?></label>
176 <input name="gis_data[<?php echo($a); ?>][POINT][y]" type="text" value="<?php echo(isset($gis_data[$a]['POINT']['y']) ? htmlspecialchars($gis_data[$a]['POINT']['y']) : ''); ?>" />
177 <?php
178 } elseif ($type == 'MULTIPOINT' || $type == 'LINESTRING') {
180 $no_of_points = isset($gis_data[$a][$type]['no_of_points']) ? $gis_data[$a][$type]['no_of_points'] : 1;
181 if ($type == 'LINESTRING' && $no_of_points < 2) {
182 $no_of_points = 2;
184 if ($type == 'MULTIPOINT' && $no_of_points < 1) {
185 $no_of_points = 1;
188 if (isset($gis_data[$a][$type]['add_point'])) {
189 $no_of_points++;
191 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_points]" value="' . $no_of_points . '">');
193 for ($i = 0; $i < $no_of_points; $i++) {
194 echo('<br/>'); echo __("Point"); echo($i + 1 . ':');
195 ?> <label for="x"><?php echo __("X"); ?></label>
196 <input type="text" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][x]" value="<?php echo(isset($gis_data[$a][$type][$i]['x']) ? htmlspecialchars($gis_data[$a][$type][$i]['x']) : ''); ?>" />
197 <label for="y"><?php echo __("Y"); ?></label>
198 <input type="text" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][y]" value="<?php echo(isset($gis_data[$a][$type][$i]['y']) ? htmlspecialchars($gis_data[$a][$type][$i]['y']) : ''); ?>" />
199 <?php
202 <input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_point]" class="add addPoint" value="<?php echo __("Add a point"); ?>">
203 <?php
204 } elseif ($type == 'MULTILINESTRING' || $type == 'POLYGON') {
206 $no_of_lines = isset($gis_data[$a][$type]['no_of_lines']) ? $gis_data[$a][$type]['no_of_lines'] : 1;
207 if ($no_of_lines < 1) {
208 $no_of_lines = 1;
210 if (isset($gis_data[$a][$type]['add_line'])) {
211 $no_of_lines++;
213 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_lines]" value="' . $no_of_lines . '">');
215 for ($i = 0; $i < $no_of_lines; $i++) {
216 echo('<br/>');
217 if ($type == 'MULTILINESTRING') {
218 echo __("Linestring"); echo($i + 1 . ':');
219 } else {
220 if ($i == 0) {
221 echo __("Outer Ring:");
222 } else {
223 echo __("Inner Ring"); echo($i . ':');
227 $no_of_points = isset($gis_data[$a][$type][$i]['no_of_points']) ? $gis_data[$a][$type][$i]['no_of_points'] : 2;
228 if ($type == 'MULTILINESTRING' && $no_of_points < 2) {
229 $no_of_points = 2;
231 if ($type == 'POLYGON' && $no_of_points < 4) {
232 $no_of_points = 4;
234 if (isset($gis_data[$a][$type][$i]['add_point'])) {
235 $no_of_points++;
237 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">');
239 for ($j = 0; $j < $no_of_points; $j++) {
240 echo('<br/>'); echo __("Point"); echo($j + 1 . ':');
241 ?> <label for="x"><?php echo __("X"); ?></label>
242 <input type="text" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][<?php echo($j); ?>][x]" value="<?php echo(isset($gis_data[$a][$type][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$i][$j]['x']) : ''); ?>" />
243 <label for="y"><?php echo __("Y"); ?></label>
244 <input type="text" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][<?php echo($j); ?>][y]" value="<?php echo(isset($gis_data[$a][$type][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$i][$j]['y']) : ''); ?>" />
245 <?php }
246 ?> <input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][add_point]" class="add addPoint" value="<?php echo __("Add a point"); ?>">
247 <?php }
248 $caption = ($type == 'MULTILINESTRING') ? __('Add a linestring') : __('Add an inner ring');
249 ?> <br/><input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_line]" class="add addLine" value="<?php echo($caption); ?>">
250 <?php
251 } elseif ($type == 'MULTIPOLYGON') {
252 $no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons']) ? $gis_data[$a][$type]['no_of_polygons'] : 1;
253 if ($no_of_polygons < 1) {
254 $no_of_polygons = 1;
256 if (isset($gis_data[$a][$type]['add_polygon'])) {
257 $no_of_polygons++;
259 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_polygons]" value="' . $no_of_polygons . '">');
261 for ($k = 0; $k < $no_of_polygons; $k++) {
262 echo('<br/>'); echo __("Polygon"); echo($k + 1 . ':');
263 $no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines']) ? $gis_data[$a][$type][$k]['no_of_lines'] : 1;
264 if ($no_of_lines < 1) {
265 $no_of_lines = 1;
267 if (isset($gis_data[$a][$type][$k]['add_line'])) {
268 $no_of_lines++;
270 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $k . '][no_of_lines]" value="' . $no_of_lines . '">');
272 for ($i = 0; $i < $no_of_lines; $i++) {
273 echo('<br/><br/>');
274 if ($i == 0) {
275 echo __("Outer Ring:");
276 } else {
277 echo __("Inner Ring"); echo($i . ':');
280 $no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points']) ? $gis_data[$a][$type][$k][$i]['no_of_points'] : 4;
281 if ($no_of_points < 4) {
282 $no_of_points = 4;
284 if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
285 $no_of_points++;
287 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">');
289 for ($j = 0; $j < $no_of_points; $j++) {
290 echo('<br/>'); echo __("Point"); echo($j + 1 . ':');
291 ?> <label for="x"><?php echo __("X"); ?></label>
292 <input type="text" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][" . $i . "][" . $j . "][x]"); ?>" value="<?php echo(isset($gis_data[$a][$type][$k][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$k][$i][$j]['x']) : ''); ?>" />
293 <label for="y"><?php echo __("Y"); ?></label>
294 <input type="text" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][" . $i . "][" . $j . "][y]"); ?>" value="<?php echo(isset($gis_data[$a][$type][$k][$i][$j]['y']) ? htmlspecialchars($gis_data[$a][$type][$k][$i][$j]['y']) : ''); ?>" />
295 <?php }
296 ?> <input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][" . $i . "][add_point]"); ?>" class="add addPoint" value="<?php echo __("Add a point"); ?>">
297 <?php }
298 ?> <br/><input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][add_line]"); ?>" class="add addLine" value="<?php echo __('Add an inner ring') ?>"><br/>
299 <?php }
300 ?> <br/><input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][add_polygon]"); ?>" class="add addPolygon" value="<?php echo __('Add a polygon') ?>">
301 <?php }
303 if ($geom_type == 'GEOMETRYCOLLECTION') {
304 ?> <br/><br/><input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]" class="add addGeom" value="<?php echo __("Add geometry"); ?>" />
305 <?php }
306 ?> </div>
307 <!-- End of data section -->
309 <br/><input type="submit" name="gis_data[save]" value="<?php echo __('Go') ?>">
310 <div id="gis_data_output">
311 <h3><?php echo __('Output'); ?></h3>
312 <p><?php echo __('Chose "GeomFromText" from the "Function" column and paste the below string into the "Value" field'); ?></p>
313 <textarea id="gis_data_textarea" cols="95" rows="5">
314 <?php echo($result);
315 ?> </textarea>
316 </div>
317 </div>
318 </form>
319 <?php
321 // If the call is to get the whole content, get the content in the buffer and make and AJAX response.
322 if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) {
323 $extra_data['gis_editor'] = ob_get_contents();
324 PMA_ajaxResponse(null, ob_end_clean(), $extra_data);
327 </body>
329 <?php
331 * Displays the footer
333 require './libraries/footer.inc.php';