Translated using Weblate (Hungarian)
[phpmyadmin.git] / gis_data_editor.php
blobf14e4662d2621853030cbd24a32f6f2db86bb9cf
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Editor for Geometry data types.
6 * @package PhpMyAdmin
7 */
9 /**
10 * Escapes special characters if the variable is set.
11 * Returns an empty string otherwise.
13 * @param string $variable variable to be escaped
15 * @return string escaped variable
17 function escape($variable)
19 return isset($variable) ? htmlspecialchars($variable) : '';
22 require_once 'libraries/common.inc.php';
23 require_once 'libraries/gis/GIS_Factory.class.php';
24 require_once 'libraries/gis/GIS_Visualization.class.php';
25 require_once 'libraries/tbl_gis_visualization.lib.php';
27 // Get data if any posted
28 $gis_data = array();
29 if (PMA_isValid($_REQUEST['gis_data'], 'array')) {
30 $gis_data = $_REQUEST['gis_data'];
33 $gis_types = array(
34 'POINT',
35 'MULTIPOINT',
36 'LINESTRING',
37 'MULTILINESTRING',
38 'POLYGON',
39 'MULTIPOLYGON',
40 'GEOMETRYCOLLECTION'
43 /** @var PMA_String $pmaString */
44 $pmaString = $GLOBALS['PMA_String'];
46 // Extract type from the initial call and make sure that it's a valid one.
47 // Extract from field's values if available, if not use the column type passed.
48 if (! isset($gis_data['gis_type'])) {
49 if (isset($_REQUEST['type']) && $_REQUEST['type'] != '') {
50 $gis_data['gis_type'] = /*overload*/mb_strtoupper($_REQUEST['type']);
52 if (isset($_REQUEST['value']) && trim($_REQUEST['value']) != '') {
53 $start = (substr($_REQUEST['value'], 0, 1) == "'") ? 1 : 0;
54 $gis_data['gis_type'] = /*overload*/mb_substr(
55 $_REQUEST['value'],
56 $start,
57 /*overload*/mb_strpos($_REQUEST['value'], "(") - $start
60 if ((! isset($gis_data['gis_type']))
61 || (! in_array($gis_data['gis_type'], $gis_types))
62 ) {
63 $gis_data['gis_type'] = $gis_types[0];
66 $geom_type = $gis_data['gis_type'];
68 // Generate parameters from value passed.
69 $gis_obj = PMA_GIS_Factory::factory($geom_type);
70 if (isset($_REQUEST['value'])) {
71 $gis_data = array_merge(
72 $gis_data, $gis_obj->generateParams($_REQUEST['value'])
76 // Generate Well Known Text
77 $srid = (isset($gis_data['srid']) && $gis_data['srid'] != '')
78 ? htmlspecialchars($gis_data['srid']) : 0;
79 $wkt = $gis_obj->generateWkt($gis_data, 0);
80 $wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
81 $result = "'" . $wkt . "'," . $srid;
83 // Generate PNG or SVG based visualization
84 $format = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8)
85 ? 'png' : 'svg';
86 $visualizationSettings = array(
87 'width' => 450,
88 'height' => 300,
89 'spatialColumn' => 'wkt'
91 $data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
92 $visualization = PMA_GIS_visualizationResults(
93 $data, $visualizationSettings, $format
95 $open_layers = PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
97 // If the call is to update the WKT and visualization make an AJAX response
98 if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
99 $extra_data = array(
100 'result' => $result,
101 'visualization' => $visualization,
102 'openLayers' => $open_layers,
104 $response = PMA_Response::getInstance();
105 $response->addJSON($extra_data);
106 exit;
109 ob_start();
111 echo '<form id="gis_data_editor_form" action="gis_data_editor.php" method="post">';
112 echo '<input type="hidden" id="pmaThemeImage"'
113 . ' value="' . $GLOBALS['pmaThemeImage'] . '" />';
114 echo '<div id="gis_data_editor">';
116 echo '<h3>';
117 printf(
118 __('Value for the column "%s"'),
119 htmlspecialchars($_REQUEST['field'])
121 echo '</h3>';
123 echo '<input type="hidden" name="field" value="'
124 . htmlspecialchars($_REQUEST['field']) . '" />';
125 // The input field to which the final result should be added
126 // and corresponding null checkbox
127 if (isset($_REQUEST['input_name'])) {
128 echo '<input type="hidden" name="input_name" value="'
129 . htmlspecialchars($_REQUEST['input_name']) . '" />';
131 echo PMA_URL_getHiddenInputs();
133 echo '<!-- Visualization section -->';
134 echo '<div id="placeholder" style="width:450px;height:300px;'
135 . ($srid != 0 ? 'display:none;' : '') . '">';
136 echo $visualization;
137 echo '</div>';
139 echo '<div id="openlayersmap" style="width:450px;height:300px;'
140 . ($srid == 0 ? 'display:none;' : '') . '">';
141 echo '</div>';
143 echo '<div class="choice" style="float:right;clear:right;">';
144 echo '<input type="checkbox" id="choice" value="useBaseLayer"'
145 . ($srid != 0 ? ' checked="checked"' : '') . '/>';
146 echo '<label for="choice">' . __("Use OpenStreetMaps as Base Layer") . '</label>';
147 echo '</div>';
149 echo '<script language="javascript" type="text/javascript">';
150 echo $open_layers;
151 echo '</script>';
152 echo '<!-- End of visualization section -->';
155 echo '<!-- Header section - Inclueds GIS type selector and input field for SRID -->';
156 echo '<div id="gis_data_header">';
157 echo '<select name="gis_data[gis_type]" class="gis_type">';
158 foreach ($gis_types as $gis_type) {
159 echo '<option value="' . $gis_type . '"';
160 if ($geom_type == $gis_type) {
161 echo ' selected="selected"';
163 echo '>' . $gis_type . '</option>';
165 echo '</select>';
166 echo '&nbsp;&nbsp;&nbsp;&nbsp;';
167 /* l10n: Spatial Reference System Identifier */
168 echo '<label for="srid">' . __('SRID:') . '</label>';
169 echo '<input name="gis_data[srid]" type="text" value="' . $srid . '" />';
170 echo '</div>';
171 echo '<!-- End of header section -->';
173 echo '<!-- Data section -->';
174 echo '<div id="gis_data">';
176 $geom_count = 1;
177 if ($geom_type == 'GEOMETRYCOLLECTION') {
178 $geom_count = (isset($gis_data[$geom_type]['geom_count']))
179 ? $gis_data[$geom_type]['geom_count'] : 1;
180 if (isset($gis_data[$geom_type]['add_geom'])) {
181 $geom_count++;
183 echo '<input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]"'
184 . ' value="' . $geom_count . '" />';
187 for ($a = 0; $a < $geom_count; $a++) {
189 if ($geom_type == 'GEOMETRYCOLLECTION') {
190 echo '<br/><br/>';
191 printf(__('Geometry %d:'), $a + 1);
192 echo '<br/>';
193 if (isset($gis_data[$a]['gis_type'])) {
194 $type = $gis_data[$a]['gis_type'];
195 } else {
196 $type = $gis_types[0];
198 echo '<select name="gis_data[' . $a . '][gis_type]" class="gis_type">';
199 foreach (array_slice($gis_types, 0, 6) as $gis_type) {
200 echo '<option value="' . $gis_type . '"';
201 if ($type == $gis_type) {
202 echo ' selected="selected"';
204 echo '>' . $gis_type . '</option>';
206 echo '</select>';
207 } else {
208 $type = $geom_type;
211 if ($type == 'POINT') {
212 echo '<br/>';
213 echo __('Point:');
214 echo '<label for="x">' . __("X") . '</label>';
215 echo '<input name="gis_data[' . $a . '][POINT][x]" type="text"'
216 . ' value="' . escape($gis_data[$a]['POINT']['x']) . '" />';
217 echo '<label for="y">' . __("Y") . '</label>';
218 echo '<input name="gis_data[' . $a . '][POINT][y]" type="text"'
219 . ' value="' . escape($gis_data[$a]['POINT']['y']) . '" />';
221 } elseif ($type == 'MULTIPOINT' || $type == 'LINESTRING') {
222 $no_of_points = isset($gis_data[$a][$type]['no_of_points'])
223 ? $gis_data[$a][$type]['no_of_points'] : 1;
224 if ($type == 'LINESTRING' && $no_of_points < 2) {
225 $no_of_points = 2;
227 if ($type == 'MULTIPOINT' && $no_of_points < 1) {
228 $no_of_points = 1;
231 if (isset($gis_data[$a][$type]['add_point'])) {
232 $no_of_points++;
234 echo '<input type="hidden" value="' . $no_of_points . '"'
235 . ' name="gis_data[' . $a . '][' . $type . '][no_of_points]" />';
237 for ($i = 0; $i < $no_of_points; $i++) {
238 echo '<br/>';
239 printf(__('Point %d'), $i + 1);
240 echo ': ';
241 echo '<label for="x">' . __("X") . '</label>';
242 echo '<input type="text"'
243 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][x]"'
244 . ' value="' . escape($gis_data[$a][$type][$i]['x']) . '" />';
245 echo '<label for="y">' . __("Y") . '</label>';
246 echo '<input type="text"'
247 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][y]"'
248 . ' value="' . escape($gis_data[$a][$type][$i]['y']) . '" />';
250 echo '<input type="submit"'
251 . ' name="gis_data[' . $a . '][' . $type . '][add_point]"'
252 . ' class="add addPoint" value="' . __("Add a point") . '" />';
254 } elseif ($type == 'MULTILINESTRING' || $type == 'POLYGON') {
255 $no_of_lines = isset($gis_data[$a][$type]['no_of_lines'])
256 ? $gis_data[$a][$type]['no_of_lines'] : 1;
257 if ($no_of_lines < 1) {
258 $no_of_lines = 1;
260 if (isset($gis_data[$a][$type]['add_line'])) {
261 $no_of_lines++;
263 echo '<input type="hidden" value="' . $no_of_lines . '"'
264 . ' name="gis_data[' . $a . '][' . $type . '][no_of_lines]" />';
266 for ($i = 0; $i < $no_of_lines; $i++) {
267 echo '<br/>';
268 if ($type == 'MULTILINESTRING') {
269 printf(__('Linestring %d:'), $i + 1);
270 } else {
271 if ($i == 0) {
272 echo __('Outer ring:');
273 } else {
274 printf(__('Inner ring %d:'), $i);
278 $no_of_points = isset($gis_data[$a][$type][$i]['no_of_points'])
279 ? $gis_data[$a][$type][$i]['no_of_points'] : 2;
280 if ($type == 'MULTILINESTRING' && $no_of_points < 2) {
281 $no_of_points = 2;
283 if ($type == 'POLYGON' && $no_of_points < 4) {
284 $no_of_points = 4;
286 if (isset($gis_data[$a][$type][$i]['add_point'])) {
287 $no_of_points++;
289 echo '<input type="hidden" value="' . $no_of_points . '"'
290 . ' name="gis_data[' . $a . '][' . $type . '][' . $i
291 . '][no_of_points]" />';
293 for ($j = 0; $j < $no_of_points; $j++) {
294 echo('<br/>');
295 printf(__('Point %d'), $j + 1);
296 echo ': ';
297 echo '<label for="x">' . __("X") . '</label>';
298 echo '<input type="text" name="gis_data[' . $a . '][' . $type . ']['
299 . $i . '][' . $j . '][x]" value="'
300 . escape($gis_data[$a][$type][$i][$j]['x']) . '" />';
301 echo '<label for="y">' . __("Y") . '</label>';
302 echo '<input type="text" name="gis_data[' . $a . '][' . $type . ']['
303 . $i . '][' . $j . '][y]"' . ' value="'
304 . escape($gis_data[$a][$type][$i][$j]['x']) . '" />';
306 echo '<input type="submit" name="gis_data[' . $a . '][' . $type . ']['
307 . $i . '][add_point]"'
308 . ' class="add addPoint" value="' . __("Add a point") . '" />';
310 $caption = ($type == 'MULTILINESTRING')
311 ? __('Add a linestring')
312 : __('Add an inner ring');
313 echo '<br/>';
314 echo '<input type="submit"'
315 . ' name="gis_data[' . $a . '][' . $type . '][add_line]"'
316 . ' class="add addLine" value="' . $caption . '" />';
318 } elseif ($type == 'MULTIPOLYGON') {
319 $no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons'])
320 ? $gis_data[$a][$type]['no_of_polygons'] : 1;
321 if ($no_of_polygons < 1) {
322 $no_of_polygons = 1;
324 if (isset($gis_data[$a][$type]['add_polygon'])) {
325 $no_of_polygons++;
327 echo '<input type="hidden"'
328 . ' name="gis_data[' . $a . '][' . $type . '][no_of_polygons]"'
329 . ' value="' . $no_of_polygons . '" />';
331 for ($k = 0; $k < $no_of_polygons; $k++) {
332 echo '<br/>';
333 printf(__('Polygon %d:'), $k + 1);
334 $no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines'])
335 ? $gis_data[$a][$type][$k]['no_of_lines'] : 1;
336 if ($no_of_lines < 1) {
337 $no_of_lines = 1;
339 if (isset($gis_data[$a][$type][$k]['add_line'])) {
340 $no_of_lines++;
342 echo '<input type="hidden"'
343 . ' name="gis_data[' . $a . '][' . $type . '][' . $k
344 . '][no_of_lines]"' . ' value="' . $no_of_lines . '" />';
346 for ($i = 0; $i < $no_of_lines; $i++) {
347 echo '<br/><br/>';
348 if ($i == 0) {
349 echo __('Outer ring:');
350 } else {
351 printf(__('Inner ring %d:'), $i);
354 $no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points'])
355 ? $gis_data[$a][$type][$k][$i]['no_of_points'] : 4;
356 if ($no_of_points < 4) {
357 $no_of_points = 4;
359 if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
360 $no_of_points++;
362 echo '<input type="hidden"'
363 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i
364 . '][no_of_points]"' . ' value="' . $no_of_points . '" />';
366 for ($j = 0; $j < $no_of_points; $j++) {
367 echo '<br/>';
368 printf(__('Point %d'), $j + 1);
369 echo ': ';
370 echo '<label for="x">' . __("X") . '</label>';
371 echo '<input type="text"'
372 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . ']['
373 . $i . '][' . $j . '][x]"'
374 . ' value="' . escape($gis_data[$a][$type][$k][$i][$j]['x'])
375 . '" />';
376 echo '<label for="y">' . __("Y") . '</label>';
377 echo '<input type="text"'
378 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . ']['
379 . $i . '][' . $j . '][y]"'
380 . ' value="' . escape($gis_data[$a][$type][$k][$i][$j]['y'])
381 . '" />';
383 echo '<input type="submit"'
384 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i
385 . '][add_point]"'
386 . ' class="add addPoint" value="' . __("Add a point") . '" />';
388 echo '<br/>';
389 echo '<input type="submit"'
390 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][add_line]"'
391 . ' class="add addLine" value="' . __('Add an inner ring') . '" />';
392 echo '<br/>';
394 echo '<br/>';
395 echo '<input type="submit"'
396 . ' name="gis_data[' . $a . '][' . $type . '][add_polygon]"'
397 . ' class="add addPolygon" value="' . __('Add a polygon') . '" />';
400 if ($geom_type == 'GEOMETRYCOLLECTION') {
401 echo '<br/><br/>';
402 echo '<input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]"'
403 . 'class="add addGeom" value="' . __("Add geometry") . '" />';
405 echo '</div>';
406 echo '<!-- End of data section -->';
408 echo '<br/>';
409 echo '<input type="submit" name="gis_data[save]" value="' . __('Go') . '" />';
411 echo '<div id="gis_data_output">';
412 echo '<h3>' . __('Output') . '</h3>';
413 echo '<p>';
414 echo __(
415 'Choose "GeomFromText" from the "Function" column and paste the'
416 . ' string below into the "Value" field.'
418 echo '</p>';
419 echo '<textarea id="gis_data_textarea" cols="95" rows="5">';
420 echo $result;
421 echo '</textarea>';
422 echo '</div>';
424 echo '</div>';
425 echo '</form>';
427 PMA_Response::getInstance()->addJSON('gis_editor', ob_get_contents());
428 ob_end_clean();