Translated using Weblate (Persian)
[phpmyadmin.git] / gis_data_editor.php
blobfd4988c3e9ccf16dbebf21d272d4bb4f2a8095db
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(),
90 $data = [
92 'wkt' => $wkt_with_zero,
93 'srid' => $srid,
96 $visualization = GisVisualization::getByData($data, $visualizationSettings)
97 ->toImage('svg');
99 $open_layers = GisVisualization::getByData($data, $visualizationSettings)
100 ->asOl();
102 // If the call is to update the WKT and visualization make an AJAX response
103 if (isset($_POST['generate']) && $_POST['generate'] == true) {
104 $extra_data = [
105 'result' => $result,
106 'visualization' => $visualization,
107 'openLayers' => $open_layers,
109 $response = Response::getInstance();
110 $response->addJSON($extra_data);
111 exit;
114 $geom_count = 1;
115 if ($geom_type == 'GEOMETRYCOLLECTION') {
116 $geom_count = isset($gis_data[$geom_type]['geom_count'])
117 ? intval($gis_data[$geom_type]['geom_count']) : 1;
118 if (isset($gis_data[$geom_type]['add_geom'])) {
119 $geom_count++;
123 $templateOutput = $template->render('gis_data_editor_form', [
124 'width' => $visualizationSettings['width'],
125 'height' => $visualizationSettings['height'],
126 'pma_theme_image' => $GLOBALS['pmaThemeImage'],
127 'field' => $_POST['field'],
128 'input_name' => $_POST['input_name'],
129 'srid' => $srid,
130 'visualization' => $visualization,
131 'open_layers' => $open_layers,
132 'gis_types' => $gis_types,
133 'geom_type' => $geom_type,
134 'geom_count' => $geom_count,
135 'gis_data' => $gis_data,
136 'result' => $result,
138 Response::getInstance()->addJSON('gis_editor', $templateOutput);