Translated using Weblate (Korean)
[phpmyadmin.git] / gis_data_editor.php
blob7d38a3648fcf58a05f1ecdd5e81728f9ebb4ac67
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Editor for Geometry data types.
6 * @package PhpMyAdmin
7 */
9 use PhpMyAdmin\Core;
10 use PhpMyAdmin\Gis\GisFactory;
11 use PhpMyAdmin\Gis\GisVisualization;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Url;
15 /**
16 * Escapes special characters if the variable is set.
17 * Returns an empty string otherwise.
19 * @param string $variable variable to be escaped
21 * @return string escaped variable
23 function escape($variable)
25 return isset($variable) ? htmlspecialchars($variable) : '';
28 require_once 'libraries/common.inc.php';
30 if (! isset($_REQUEST['field'])) {
31 PhpMyAdmin\Util::checkParameters(array('field'));
34 // Get data if any posted
35 $gis_data = array();
36 if (Core::isValid($_REQUEST['gis_data'], 'array')) {
37 $gis_data = $_REQUEST['gis_data'];
40 $gis_types = array(
41 'POINT',
42 'MULTIPOINT',
43 'LINESTRING',
44 'MULTILINESTRING',
45 'POLYGON',
46 'MULTIPOLYGON',
47 'GEOMETRYCOLLECTION'
50 // Extract type from the initial call and make sure that it's a valid one.
51 // Extract from field's values if available, if not use the column type passed.
52 if (! isset($gis_data['gis_type'])) {
53 if (isset($_REQUEST['type']) && $_REQUEST['type'] != '') {
54 $gis_data['gis_type'] = mb_strtoupper($_REQUEST['type']);
56 if (isset($_REQUEST['value']) && trim($_REQUEST['value']) != '') {
57 $start = (substr($_REQUEST['value'], 0, 1) == "'") ? 1 : 0;
58 $gis_data['gis_type'] = mb_substr(
59 $_REQUEST['value'],
60 $start,
61 mb_strpos($_REQUEST['value'], "(") - $start
64 if ((! isset($gis_data['gis_type']))
65 || (! in_array($gis_data['gis_type'], $gis_types))
66 ) {
67 $gis_data['gis_type'] = $gis_types[0];
70 $geom_type = htmlspecialchars($gis_data['gis_type']);
72 // Generate parameters from value passed.
73 $gis_obj = GisFactory::factory($geom_type);
74 if (isset($_REQUEST['value'])) {
75 $gis_data = array_merge(
76 $gis_data, $gis_obj->generateParams($_REQUEST['value'])
80 // Generate Well Known Text
81 $srid = (isset($gis_data['srid']) && $gis_data['srid'] != '')
82 ? htmlspecialchars($gis_data['srid']) : 0;
83 $wkt = $gis_obj->generateWkt($gis_data, 0);
84 $wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
85 $result = "'" . $wkt . "'," . $srid;
87 // Generate SVG based visualization
88 $visualizationSettings = array(
89 'width' => 450,
90 'height' => 300,
91 'spatialColumn' => 'wkt'
93 $data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
94 $visualization = GisVisualization::getByData($data, $visualizationSettings)
95 ->toImage('svg');
97 $open_layers = GisVisualization::getByData($data, $visualizationSettings)
98 ->asOl();
100 // If the call is to update the WKT and visualization make an AJAX response
101 if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
102 $extra_data = array(
103 'result' => $result,
104 'visualization' => $visualization,
105 'openLayers' => $open_layers,
107 $response = Response::getInstance();
108 $response->addJSON($extra_data);
109 exit;
112 ob_start();
114 echo '<form id="gis_data_editor_form" action="gis_data_editor.php" method="post">';
115 echo '<input type="hidden" id="pmaThemeImage"'
116 , ' value="' , $GLOBALS['pmaThemeImage'] , '" />';
117 echo '<div id="gis_data_editor">';
119 echo '<h3>';
120 printf(
121 __('Value for the column "%s"'),
122 htmlspecialchars($_REQUEST['field'])
124 echo '</h3>';
126 echo '<input type="hidden" name="field" value="'
127 , htmlspecialchars($_REQUEST['field']) , '" />';
128 // The input field to which the final result should be added
129 // and corresponding null checkbox
130 if (isset($_REQUEST['input_name'])) {
131 echo '<input type="hidden" name="input_name" value="'
132 , htmlspecialchars($_REQUEST['input_name']) , '" />';
134 echo Url::getHiddenInputs();
136 echo '<!-- Visualization section -->';
137 echo '<div id="placeholder" style="width:450px;height:300px;'
138 , ($srid != 0 ? 'display:none;' : '') , '">';
139 echo $visualization;
140 echo '</div>';
142 echo '<div id="openlayersmap" style="width:450px;height:300px;'
143 , ($srid == 0 ? 'display:none;' : '') , '">';
144 echo '</div>';
146 echo '<div class="choice floatright" style="clear:right;">';
147 echo '<input type="checkbox" id="choice" value="useBaseLayer"'
148 , ($srid != 0 ? ' checked="checked"' : '') , '/>';
149 echo '<label for="choice">' , __("Use OpenStreetMaps as Base Layer") , '</label>';
150 echo '</div>';
152 echo '<script language="javascript" type="text/javascript">';
153 echo $open_layers;
154 echo '</script>';
155 echo '<!-- End of visualization section -->';
158 echo '<!-- Header section - Inclueds GIS type selector and input field for SRID -->';
159 echo '<div id="gis_data_header">';
160 echo '<select name="gis_data[gis_type]" class="gis_type">';
161 foreach ($gis_types as $gis_type) {
162 echo '<option value="' , $gis_type , '"';
163 if ($geom_type == $gis_type) {
164 echo ' selected="selected"';
166 echo '>' , $gis_type , '</option>';
168 echo '</select>';
169 echo '&nbsp;&nbsp;&nbsp;&nbsp;';
170 /* l10n: Spatial Reference System Identifier */
171 echo '<label for="srid">' , __('SRID:') , '</label>';
172 echo '<input name="gis_data[srid]" type="text" value="' , $srid , '" />';
173 echo '</div>';
174 echo '<!-- End of header section -->';
176 echo '<!-- Data section -->';
177 echo '<div id="gis_data">';
179 $geom_count = 1;
180 if ($geom_type == 'GEOMETRYCOLLECTION') {
181 $geom_count = (isset($gis_data[$geom_type]['geom_count']))
182 ? intval($gis_data[$geom_type]['geom_count']) : 1;
183 if (isset($gis_data[$geom_type]['add_geom'])) {
184 $geom_count++;
186 echo '<input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]"'
187 , ' value="' , $geom_count , '" />';
190 for ($a = 0; $a < $geom_count; $a++) {
191 if (! isset($gis_data[$a])) {
192 continue;
195 if ($geom_type == 'GEOMETRYCOLLECTION') {
196 echo '<br/><br/>';
197 printf(__('Geometry %d:'), $a + 1);
198 echo '<br/>';
199 if (isset($gis_data[$a]['gis_type'])) {
200 $type = htmlspecialchars($gis_data[$a]['gis_type']);
201 } else {
202 $type = $gis_types[0];
204 echo '<select name="gis_data[' , $a , '][gis_type]" class="gis_type">';
205 foreach (array_slice($gis_types, 0, 6) as $gis_type) {
206 echo '<option value="' , $gis_type , '"';
207 if ($type == $gis_type) {
208 echo ' selected="selected"';
210 echo '>' , $gis_type , '</option>';
212 echo '</select>';
213 } else {
214 $type = $geom_type;
217 if ($type == 'POINT') {
218 echo '<br/>';
219 echo __('Point:');
220 echo '<label for="x">' , __("X") , '</label>';
221 echo '<input name="gis_data[' , $a , '][POINT][x]" type="text"'
222 , ' value="' , escape($gis_data[$a]['POINT']['x']) , '" />';
223 echo '<label for="y">' , __("Y") , '</label>';
224 echo '<input name="gis_data[' , $a , '][POINT][y]" type="text"'
225 , ' value="' , escape($gis_data[$a]['POINT']['y']) , '" />';
227 } elseif ($type == 'MULTIPOINT' || $type == 'LINESTRING') {
228 $no_of_points = isset($gis_data[$a][$type]['no_of_points'])
229 ? intval($gis_data[$a][$type]['no_of_points']) : 1;
230 if ($type == 'LINESTRING' && $no_of_points < 2) {
231 $no_of_points = 2;
233 if ($type == 'MULTIPOINT' && $no_of_points < 1) {
234 $no_of_points = 1;
237 if (isset($gis_data[$a][$type]['add_point'])) {
238 $no_of_points++;
240 echo '<input type="hidden" value="' , $no_of_points , '"'
241 , ' name="gis_data[' , $a , '][' , $type , '][no_of_points]" />';
243 for ($i = 0; $i < $no_of_points; $i++) {
244 echo '<br/>';
245 printf(__('Point %d'), $i + 1);
246 echo ': ';
247 echo '<label for="x">' , __("X") , '</label>';
248 echo '<input type="text"'
249 , ' name="gis_data[' , $a , '][' , $type , '][' , $i , '][x]"'
250 , ' value="' , escape($gis_data[$a][$type][$i]['x']) , '" />';
251 echo '<label for="y">' , __("Y") , '</label>';
252 echo '<input type="text"'
253 , ' name="gis_data[' , $a , '][' , $type , '][' , $i , '][y]"'
254 , ' value="' , escape($gis_data[$a][$type][$i]['y']) , '" />';
256 echo '<input type="submit"'
257 , ' name="gis_data[' , $a , '][' , $type , '][add_point]"'
258 , ' class="add addPoint" value="' , __("Add a point") , '" />';
260 } elseif ($type == 'MULTILINESTRING' || $type == 'POLYGON') {
261 $no_of_lines = isset($gis_data[$a][$type]['no_of_lines'])
262 ? intval($gis_data[$a][$type]['no_of_lines']) : 1;
263 if ($no_of_lines < 1) {
264 $no_of_lines = 1;
266 if (isset($gis_data[$a][$type]['add_line'])) {
267 $no_of_lines++;
269 echo '<input type="hidden" value="' , $no_of_lines , '"'
270 , ' name="gis_data[' , $a , '][' , $type , '][no_of_lines]" />';
272 for ($i = 0; $i < $no_of_lines; $i++) {
273 echo '<br/>';
274 if ($type == 'MULTILINESTRING') {
275 printf(__('Linestring %d:'), $i + 1);
276 } else {
277 if ($i == 0) {
278 echo __('Outer ring:');
279 } else {
280 printf(__('Inner ring %d:'), $i);
284 $no_of_points = isset($gis_data[$a][$type][$i]['no_of_points'])
285 ? intval($gis_data[$a][$type][$i]['no_of_points']) : 2;
286 if ($type == 'MULTILINESTRING' && $no_of_points < 2) {
287 $no_of_points = 2;
289 if ($type == 'POLYGON' && $no_of_points < 4) {
290 $no_of_points = 4;
292 if (isset($gis_data[$a][$type][$i]['add_point'])) {
293 $no_of_points++;
295 echo '<input type="hidden" value="' , $no_of_points , '"'
296 , ' name="gis_data[' , $a , '][' , $type , '][' , $i
297 , '][no_of_points]" />';
299 for ($j = 0; $j < $no_of_points; $j++) {
300 echo('<br/>');
301 printf(__('Point %d'), $j + 1);
302 echo ': ';
303 echo '<label for="x">' , __("X") , '</label>';
304 echo '<input type="text" name="gis_data[' , $a , '][' , $type . ']['
305 , $i , '][' , $j , '][x]" value="'
306 , escape($gis_data[$a][$type][$i][$j]['x']) , '" />';
307 echo '<label for="y">' , __("Y") , '</label>';
308 echo '<input type="text" name="gis_data[' , $a , '][' , $type , ']['
309 , $i , '][' , $j , '][y]"' , ' value="'
310 , escape($gis_data[$a][$type][$i][$j]['y']) , '" />';
312 echo '<input type="submit" name="gis_data[' , $a , '][' , $type , ']['
313 , $i , '][add_point]"'
314 , ' class="add addPoint" value="' , __("Add a point") , '" />';
316 $caption = ($type == 'MULTILINESTRING')
317 ? __('Add a linestring')
318 : __('Add an inner ring');
319 echo '<br/>';
320 echo '<input type="submit"'
321 , ' name="gis_data[' , $a , '][' , $type , '][add_line]"'
322 , ' class="add addLine" value="' , $caption , '" />';
324 } elseif ($type == 'MULTIPOLYGON') {
325 $no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons'])
326 ? intval($gis_data[$a][$type]['no_of_polygons']) : 1;
327 if ($no_of_polygons < 1) {
328 $no_of_polygons = 1;
330 if (isset($gis_data[$a][$type]['add_polygon'])) {
331 $no_of_polygons++;
333 echo '<input type="hidden"'
334 , ' name="gis_data[' , $a , '][' , $type , '][no_of_polygons]"'
335 , ' value="' , $no_of_polygons , '" />';
337 for ($k = 0; $k < $no_of_polygons; $k++) {
338 echo '<br/>';
339 printf(__('Polygon %d:'), $k + 1);
340 $no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines'])
341 ? intval($gis_data[$a][$type][$k]['no_of_lines']) : 1;
342 if ($no_of_lines < 1) {
343 $no_of_lines = 1;
345 if (isset($gis_data[$a][$type][$k]['add_line'])) {
346 $no_of_lines++;
348 echo '<input type="hidden"'
349 , ' name="gis_data[' , $a , '][' , $type , '][' , $k
350 , '][no_of_lines]"' , ' value="' , $no_of_lines , '" />';
352 for ($i = 0; $i < $no_of_lines; $i++) {
353 echo '<br/><br/>';
354 if ($i == 0) {
355 echo __('Outer ring:');
356 } else {
357 printf(__('Inner ring %d:'), $i);
360 $no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points'])
361 ? intval($gis_data[$a][$type][$k][$i]['no_of_points']) : 4;
362 if ($no_of_points < 4) {
363 $no_of_points = 4;
365 if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
366 $no_of_points++;
368 echo '<input type="hidden"'
369 , ' name="gis_data[' , $a , '][' , $type , '][' , $k , '][' , $i
370 , '][no_of_points]"' , ' value="' , $no_of_points , '" />';
372 for ($j = 0; $j < $no_of_points; $j++) {
373 echo '<br/>';
374 printf(__('Point %d'), $j + 1);
375 echo ': ';
376 echo '<label for="x">' , __("X") , '</label>';
377 echo '<input type="text"'
378 , ' name="gis_data[' , $a , '][' , $type , '][' , $k , ']['
379 , $i , '][' , $j , '][x]"'
380 , ' value="' , escape($gis_data[$a][$type][$k][$i][$j]['x'])
381 , '" />';
382 echo '<label for="y">' , __("Y") , '</label>';
383 echo '<input type="text"'
384 , ' name="gis_data[' , $a , '][' , $type , '][' , $k , ']['
385 , $i , '][' , $j , '][y]"'
386 , ' value="' , escape($gis_data[$a][$type][$k][$i][$j]['y'])
387 , '" />';
389 echo '<input type="submit"'
390 , ' name="gis_data[' , $a , '][' , $type , '][' , $k , '][' , $i
391 , '][add_point]"'
392 , ' class="add addPoint" value="' , __("Add a point") , '" />';
394 echo '<br/>';
395 echo '<input type="submit"'
396 , ' name="gis_data[' , $a , '][' , $type , '][' , $k , '][add_line]"'
397 , ' class="add addLine" value="' , __('Add an inner ring') , '" />';
398 echo '<br/>';
400 echo '<br/>';
401 echo '<input type="submit"'
402 , ' name="gis_data[' , $a , '][' , $type , '][add_polygon]"'
403 , ' class="add addPolygon" value="' , __('Add a polygon') , '" />';
406 if ($geom_type == 'GEOMETRYCOLLECTION') {
407 echo '<br/><br/>';
408 echo '<input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]"'
409 , 'class="add addGeom" value="' , __("Add geometry") , '" />';
411 echo '</div>';
412 echo '<!-- End of data section -->';
414 echo '<br/>';
415 echo '<input type="submit" name="gis_data[save]" value="' , __('Go') , '" />';
417 echo '<div id="gis_data_output">';
418 echo '<h3>' , __('Output') , '</h3>';
419 echo '<p>';
420 echo __(
421 'Choose "GeomFromText" from the "Function" column and paste the'
422 . ' string below into the "Value" field.'
424 echo '</p>';
425 echo '<textarea id="gis_data_textarea" cols="95" rows="5">';
426 echo htmlspecialchars($result);
427 echo '</textarea>';
428 echo '</div>';
430 echo '</div>';
431 echo '</form>';
433 Response::getInstance()->addJSON('gis_editor', ob_get_contents());
434 ob_end_clean();