Translated using Weblate (Slovenian)
[phpmyadmin.git] / gis_data_editor.php
blobc86309f13c4c447ec6c1b36d82295089fdbfd544
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Editor for Geometry data types.
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Core;
11 use PhpMyAdmin\Gis\GisFactory;
12 use PhpMyAdmin\Gis\GisVisualization;
13 use PhpMyAdmin\Response;
14 use PhpMyAdmin\Template;
15 use PhpMyAdmin\Util;
17 if (! defined('ROOT_PATH')) {
18 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
21 require_once ROOT_PATH . 'libraries/common.inc.php';
23 /** @var Template $template */
24 $template = $containerBuilder->get('template');
26 if (! isset($_POST['field'])) {
27 Util::checkParameters(['field']);
30 // Get data if any posted
31 $gis_data = [];
32 if (Core::isValid($_POST['gis_data'], 'array')) {
33 $gis_data = $_POST['gis_data'];
36 $gis_types = [
37 'POINT',
38 'MULTIPOINT',
39 'LINESTRING',
40 'MULTILINESTRING',
41 'POLYGON',
42 'MULTIPOLYGON',
43 'GEOMETRYCOLLECTION',
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($_POST['type']) && $_POST['type'] != '') {
50 $gis_data['gis_type'] = mb_strtoupper($_POST['type']);
52 if (isset($_POST['value']) && trim($_POST['value']) != '') {
53 $start = (substr($_POST['value'], 0, 1) == "'") ? 1 : 0;
54 $gis_data['gis_type'] = mb_substr(
55 $_POST['value'],
56 $start,
57 mb_strpos($_POST['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 = GisFactory::factory($geom_type);
70 if (isset($_POST['value'])) {
71 $gis_data = array_merge(
72 $gis_data,
73 $gis_obj->generateParams($_POST['value'])
77 // Generate Well Known Text
78 $srid = (isset($gis_data['srid']) && $gis_data['srid'] != '') ? $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 SVG based visualization
84 $visualizationSettings = [
85 'width' => 450,
86 'height' => 300,
87 'spatialColumn' => 'wkt',
88 'mysqlVersion' => $GLOBALS['dbi']->getVersion(),
89 'isMariaDB' => $GLOBALS['dbi']->isMariaDB(),
91 $data = [
93 'wkt' => $wkt_with_zero,
94 'srid' => $srid,
97 $visualization = GisVisualization::getByData($data, $visualizationSettings)
98 ->toImage('svg');
100 $open_layers = GisVisualization::getByData($data, $visualizationSettings)
101 ->asOl();
103 // If the call is to update the WKT and visualization make an AJAX response
104 if (isset($_POST['generate']) && $_POST['generate'] == true) {
105 $extra_data = [
106 'result' => $result,
107 'visualization' => $visualization,
108 'openLayers' => $open_layers,
110 $response = Response::getInstance();
111 $response->addJSON($extra_data);
112 exit;
115 $geom_count = 1;
116 if ($geom_type == 'GEOMETRYCOLLECTION') {
117 $geom_count = isset($gis_data[$geom_type]['geom_count'])
118 ? intval($gis_data[$geom_type]['geom_count']) : 1;
119 if (isset($gis_data[$geom_type]['add_geom'])) {
120 $geom_count++;
124 $templateOutput = $template->render('gis_data_editor_form', [
125 'width' => $visualizationSettings['width'],
126 'height' => $visualizationSettings['height'],
127 'pma_theme_image' => $GLOBALS['pmaThemeImage'],
128 'field' => $_POST['field'],
129 'input_name' => $_POST['input_name'],
130 'srid' => $srid,
131 'visualization' => $visualization,
132 'open_layers' => $open_layers,
133 'gis_types' => $gis_types,
134 'geom_type' => $geom_type,
135 'geom_count' => $geom_count,
136 'gis_data' => $gis_data,
137 'result' => $result,
139 Response::getInstance()->addJSON('gis_editor', $templateOutput);