Translated using Weblate (Greek)
[phpmyadmin.git] / gis_data_editor.php
blob229e36bdbe2c7951f79690d8d290f21a0e90e047
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 escaped variable
17 function escape($variable)
19 return isset($variable) ? htmlspecialchars($variable) : '';
22 require_once 'libraries/common.inc.php';
23 require_once 'libraries/gis/pma_gis_factory.php';
24 require_once 'libraries/gis_visualization.lib.php';
26 // Get data if any posted
27 $gis_data = array();
28 if (PMA_isValid($_REQUEST['gis_data'], 'array')) {
29 $gis_data = $_REQUEST['gis_data'];
32 $gis_types = array(
33 'POINT',
34 'MULTIPOINT',
35 'LINESTRING',
36 'MULTILINESTRING',
37 'POLYGON',
38 'MULTIPOLYGON',
39 'GEOMETRYCOLLECTION'
42 // Extract type from the initial call and make sure that it's a valid one.
43 // Extract from field's values if availbale, if not use the column type passed.
44 if (! isset($gis_data['gis_type'])) {
45 if (isset($_REQUEST['type']) && $_REQUEST['type'] != '') {
46 $gis_data['gis_type'] = strtoupper($_REQUEST['type']);
48 if (isset($_REQUEST['value']) && trim($_REQUEST['value']) != '') {
49 $start = (substr($_REQUEST['value'], 0, 1) == "'") ? 1 : 0;
50 $gis_data['gis_type'] = substr(
51 $_REQUEST['value'], $start, strpos($_REQUEST['value'], "(") - $start
54 if ((! isset($gis_data['gis_type']))
55 || (! in_array($gis_data['gis_type'], $gis_types))
56 ) {
57 $gis_data['gis_type'] = $gis_types[0];
60 $geom_type = $gis_data['gis_type'];
62 // Generate parameters from value passed.
63 $gis_obj = PMA_GIS_Factory::factory($geom_type);
64 if (isset($_REQUEST['value'])) {
65 $gis_data = array_merge(
66 $gis_data, $gis_obj->generateParams($_REQUEST['value'])
70 // Generate Well Known Text
71 $srid = (isset($gis_data['srid']) && $gis_data['srid'] != '')
72 ? htmlspecialchars($gis_data['srid']) : 0;
73 $wkt = $gis_obj->generateWkt($gis_data, 0);
74 $wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
75 $result = "'" . $wkt . "'," . $srid;
77 // Generate PNG or SVG based visualization
78 $format = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8)
79 ? 'png' : 'svg';
80 $visualizationSettings = array(
81 'width' => 450,
82 'height' => 300,
83 'spatialColumn' => 'wkt'
85 $data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
86 $visualization = PMA_GIS_visualizationResults(
87 $data, $visualizationSettings, $format
89 $open_layers = PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
91 // If the call is to update the WKT and visualization make an AJAX response
92 if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
93 $extra_data = array(
94 'result' => $result,
95 'visualization' => $visualization,
96 'openLayers' => $open_layers,
98 $response = PMA_Response::getInstance();
99 $response->addJSON($extra_data);
100 exit;
103 ob_start();
105 echo '<form id="gis_data_editor_form" action="gis_data_editor.php" method="post">';
106 echo '<input type="hidden" id="pmaThemeImage"'
107 . ' value="' . $GLOBALS['pmaThemeImage'] . '" />';
108 echo '<div id="gis_data_editor">';
110 echo '<h3>';
111 printf(
112 __('Value for the column "%s"'),
113 htmlspecialchars($_REQUEST['field'])
115 echo '</h3>';
117 echo '<input type="hidden" name="field" value="'
118 . htmlspecialchars($_REQUEST['field']) . '" />';
119 // The input field to which the final result should be added
120 // and corresponding null checkbox
121 if (isset($_REQUEST['input_name'])) {
122 echo '<input type="hidden" name="input_name" value="'
123 . htmlspecialchars($_REQUEST['input_name']) . '" />';
125 echo PMA_generate_common_hidden_inputs();
127 echo '<!-- Visualization section -->';
128 echo '<div id="placeholder" style="width:450px;height:300px;'
129 . ($srid != 0 ? 'display:none;' : '') . '">';
130 echo $visualization;
131 echo '</div>';
133 echo '<div id="openlayersmap" style="width:450px;height:300px;'
134 . ($srid == 0 ? 'display:none;' : '') . '">';
135 echo '</div>';
137 echo '<div class="choice" style="float:right;clear:right;">';
138 echo '<input type="checkbox" id="choice" value="useBaseLayer"'
139 . ($srid != 0 ? ' checked="checked"' : '') . '/>';
140 echo '<label for="choice">' . __("Use OpenStreetMaps as Base Layer") . '</label>';
141 echo '</div>';
143 echo '<script language="javascript" type="text/javascript">';
144 echo $open_layers;
145 echo '</script>';
146 echo '<!-- End of visualization section -->';
149 echo '<!-- Header section - Inclueds GIS type selector and input field for SRID -->';
150 echo '<div id="gis_data_header">';
151 echo '<select name="gis_data[gis_type]" class="gis_type">';
152 foreach ($gis_types as $gis_type) {
153 echo '<option value="' . $gis_type . '"';
154 if ($geom_type == $gis_type) {
155 echo ' selected="selected"';
157 echo '>' . $gis_type . '</option>';
159 echo '</select>';
160 echo '&nbsp;&nbsp;&nbsp;&nbsp;';
161 echo '<label for="srid">' . __("SRID") . ':</label>';
162 echo '<input name="gis_data[srid]" type="text" value="' . $srid . '" />';
163 echo '</div>';
164 echo '<!-- End of header section -->';
166 echo '<!-- Data section -->';
167 echo '<div id="gis_data">';
169 $geom_count = 1;
170 if ($geom_type == 'GEOMETRYCOLLECTION') {
171 $geom_count = (isset($gis_data[$geom_type]['geom_count']))
172 ? $gis_data[$geom_type]['geom_count'] : 1;
173 if (isset($gis_data[$geom_type]['add_geom'])) {
174 $geom_count++;
176 echo '<input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]"'
177 . ' value="' . $geom_count . '" />';
180 for ($a = 0; $a < $geom_count; $a++) {
182 if ($geom_type == 'GEOMETRYCOLLECTION') {
183 echo '<br/><br/>';
184 echo __("Geometry") . ' ' . ($a + 1) . ': ';
185 echo '<br/>';
186 if (isset($gis_data[$a]['gis_type'])) {
187 $type = $gis_data[$a]['gis_type'];
188 } else {
189 $type = $gis_types[0];
191 echo '<select name="gis_data[' . $a . '][gis_type]" class="gis_type">';
192 foreach (array_slice($gis_types, 0, 6) as $gis_type) {
193 echo '<option value="' . $gis_type . '"';
194 if ($type == $gis_type) {
195 echo ' selected="selected"';
197 echo '>' . $gis_type . '</option>';
199 echo '</select>';
200 } else {
201 $type = $geom_type;
204 if ($type == 'POINT') {
205 echo '<br/>';
206 echo __("Point") . ': ';
207 echo '<label for="x">' . __("X") . '</label>';
208 echo '<input name="gis_data[' . $a . '][POINT][x]" type="text"'
209 . ' value="' . escape($gis_data[$a]['POINT']['x']) . '" />';
210 echo '<label for="y">' . __("Y") . '</label>';
211 echo '<input name="gis_data[' . $a . '][POINT][y]" type="text"'
212 . ' value="' . escape($gis_data[$a]['POINT']['y']) . '" />';
214 } elseif ($type == 'MULTIPOINT' || $type == 'LINESTRING') {
215 $no_of_points = isset($gis_data[$a][$type]['no_of_points'])
216 ? $gis_data[$a][$type]['no_of_points'] : 1;
217 if ($type == 'LINESTRING' && $no_of_points < 2) {
218 $no_of_points = 2;
220 if ($type == 'MULTIPOINT' && $no_of_points < 1) {
221 $no_of_points = 1;
224 if (isset($gis_data[$a][$type]['add_point'])) {
225 $no_of_points++;
227 echo '<input type="hidden" value="' . $no_of_points . '"'
228 . ' name="gis_data[' . $a . '][' . $type . '][no_of_points]" />';
230 for ($i = 0; $i < $no_of_points; $i++) {
231 echo '<br/>';
232 printf(__('Point %d'), $i + 1);
233 echo ': ';
234 echo '<label for="x">' . __("X") . '</label>';
235 echo '<input type="text"'
236 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][x]"'
237 . ' value="' . escape($gis_data[$a][$type][$i]['x']) . '" />';
238 echo '<label for="y">' . __("Y") . '</label>';
239 echo '<input type="text"'
240 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][y]"'
241 . ' value="' . escape($gis_data[$a][$type][$i]['y']). '" />';
243 echo '<input type="submit"'
244 . ' name="gis_data[' . $a . '][' . $type . '][add_point]"'
245 . ' class="add addPoint" value="' . __("Add a point") . '" />';
247 } elseif ($type == 'MULTILINESTRING' || $type == 'POLYGON') {
248 $no_of_lines = isset($gis_data[$a][$type]['no_of_lines'])
249 ? $gis_data[$a][$type]['no_of_lines'] : 1;
250 if ($no_of_lines < 1) {
251 $no_of_lines = 1;
253 if (isset($gis_data[$a][$type]['add_line'])) {
254 $no_of_lines++;
256 echo '<input type="hidden" value="' . $no_of_lines . '"'
257 . ' name="gis_data[' . $a . '][' . $type . '][no_of_lines]" />';
259 for ($i = 0; $i < $no_of_lines; $i++) {
260 echo '<br/>';
261 if ($type == 'MULTILINESTRING') {
262 echo __("Linestring") . ' ' . ($i + 1) . ':';
263 } else {
264 if ($i == 0) {
265 echo __("Outer Ring") . ':';
266 } else {
267 echo __("Inner Ring") . ' ' . $i . ':';
271 $no_of_points = isset($gis_data[$a][$type][$i]['no_of_points'])
272 ? $gis_data[$a][$type][$i]['no_of_points'] : 2;
273 if ($type == 'MULTILINESTRING' && $no_of_points < 2) {
274 $no_of_points = 2;
276 if ($type == 'POLYGON' && $no_of_points < 4) {
277 $no_of_points = 4;
279 if (isset($gis_data[$a][$type][$i]['add_point'])) {
280 $no_of_points++;
282 echo '<input type="hidden" value="' . $no_of_points . '"'
283 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][no_of_points]" />';
285 for ($j = 0; $j < $no_of_points; $j++) {
286 echo('<br/>');
287 printf(__('Point %d'), $j + 1);
288 echo ': ';
289 echo '<label for="x">' . __("X") . '</label>';
290 echo '<input type="text"'
291 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][' . $j . '][x]"'
292 . ' value="' . escape($gis_data[$a][$type][$i][$j]['x']) . '" />';
293 echo '<label for="y">' . __("Y") . '</label>';
294 echo '<input type="text"'
295 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][' . $j . '][y]"'
296 . ' value="' . escape($gis_data[$a][$type][$i][$j]['x']) . '" />';
298 echo '<input type="submit"'
299 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][add_point]"'
300 . ' class="add addPoint" value="' . __("Add a point") . '" />';
302 $caption = ($type == 'MULTILINESTRING')
303 ? __('Add a linestring')
304 : __('Add an inner ring');
305 echo '<br/>';
306 echo '<input type="submit"'
307 . ' name="gis_data[' . $a . '][' . $type . '][add_line]"'
308 . ' class="add addLine" value="' . $caption . '" />';
310 } elseif ($type == 'MULTIPOLYGON') {
311 $no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons'])
312 ? $gis_data[$a][$type]['no_of_polygons'] : 1;
313 if ($no_of_polygons < 1) {
314 $no_of_polygons = 1;
316 if (isset($gis_data[$a][$type]['add_polygon'])) {
317 $no_of_polygons++;
319 echo '<input type="hidden"'
320 . ' name="gis_data[' . $a . '][' . $type . '][no_of_polygons]"'
321 . ' value="' . $no_of_polygons . '" />';
323 for ($k = 0; $k < $no_of_polygons; $k++) {
324 echo '<br/>';
325 echo __("Polygon") . ' ' . ($k + 1) . ':';
326 $no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines'])
327 ? $gis_data[$a][$type][$k]['no_of_lines'] : 1;
328 if ($no_of_lines < 1) {
329 $no_of_lines = 1;
331 if (isset($gis_data[$a][$type][$k]['add_line'])) {
332 $no_of_lines++;
334 echo '<input type="hidden"'
335 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][no_of_lines]"'
336 . ' value="' . $no_of_lines . '" />';
338 for ($i = 0; $i < $no_of_lines; $i++) {
339 echo '<br/><br/>';
340 if ($i == 0) {
341 echo __("Outer Ring") . ':';
342 } else {
343 echo __("Inner Ring") . ' ' . $i . ':';
346 $no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points'])
347 ? $gis_data[$a][$type][$k][$i]['no_of_points'] : 4;
348 if ($no_of_points < 4) {
349 $no_of_points = 4;
351 if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
352 $no_of_points++;
354 echo '<input type="hidden"'
355 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][no_of_points]"'
356 . ' value="' . $no_of_points . '" />';
358 for ($j = 0; $j < $no_of_points; $j++) {
359 echo '<br/>';
360 printf(__('Point %d'), $j + 1);
361 echo ': ';
362 echo '<label for="x">' . __("X") . '</label>';
363 echo '<input type="text"'
364 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][' . $j . '][x]"'
365 . ' value="' . escape($gis_data[$a][$type][$k][$i][$j]['x']). '" />';
366 echo '<label for="y">' . __("Y") . '</label>';
367 echo '<input type="text"'
368 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][' . $j . '][y]"'
369 . ' value="' . escape($gis_data[$a][$type][$k][$i][$j]['y']) . '" />';
371 echo '<input type="submit"'
372 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][add_point]"'
373 . ' class="add addPoint" value="' . __("Add a point") . '" />';
375 echo '<br/>';
376 echo '<input type="submit"'
377 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][add_line]"'
378 . ' class="add addLine" value="' . __('Add an inner ring'). '" />';
379 echo '<br/>';
381 echo '<br/>';
382 echo '<input type="submit"'
383 . ' name="gis_data[' . $a . '][' . $type . '][add_polygon]"'
384 . ' class="add addPolygon" value="' . __('Add a polygon') . '" />';
387 if ($geom_type == 'GEOMETRYCOLLECTION') {
388 echo '<br/><br/>';
389 echo '<input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]"'
390 . 'class="add addGeom" value="' . __("Add geometry") . '" />';
392 echo '</div>';
393 echo '<!-- End of data section -->';
395 echo '<br/>';
396 echo '<input type="submit" name="gis_data[save]" value="' . __('Go') . '" />';
398 echo '<div id="gis_data_output">';
399 echo '<h3>' . __('Output') . '</h3>';
400 echo '<p>';
401 echo __(
402 'Choose "GeomFromText" from the "Function" column and paste the'
403 . ' string below into the "Value" field'
405 echo '</p>';
406 echo '<textarea id="gis_data_textarea" cols="95" rows="5">';
407 echo $result;
408 echo '</textarea>';
409 echo '</div>';
411 echo '</div>';
412 echo '</form>';
414 PMA_Response::getInstance()->addJSON('gis_editor', ob_get_contents());
415 ob_end_clean();