improve the transitioning from one mouseover area to another
[openemr.git] / phpmyadmin / gis_data_editor.php
blobbe13aeeb0ed4d21ba16d54d54761457fd01493eb
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';
26 if (! isset($_REQUEST['field'])) {
27 PMA_Util::checkParameters(array('field'));
30 // Get data if any posted
31 $gis_data = array();
32 if (PMA_isValid($_REQUEST['gis_data'], 'array')) {
33 $gis_data = $_REQUEST['gis_data'];
36 $gis_types = array(
37 'POINT',
38 'MULTIPOINT',
39 'LINESTRING',
40 'MULTILINESTRING',
41 'POLYGON',
42 'MULTIPOLYGON',
43 'GEOMETRYCOLLECTION'
46 /** @var PMA_String $pmaString */
47 $pmaString = $GLOBALS['PMA_String'];
49 // Extract type from the initial call and make sure that it's a valid one.
50 // Extract from field's values if available, if not use the column type passed.
51 if (! isset($gis_data['gis_type'])) {
52 if (isset($_REQUEST['type']) && $_REQUEST['type'] != '') {
53 $gis_data['gis_type'] = /*overload*/mb_strtoupper($_REQUEST['type']);
55 if (isset($_REQUEST['value']) && trim($_REQUEST['value']) != '') {
56 $start = (substr($_REQUEST['value'], 0, 1) == "'") ? 1 : 0;
57 $gis_data['gis_type'] = /*overload*/mb_substr(
58 $_REQUEST['value'],
59 $start,
60 /*overload*/mb_strpos($_REQUEST['value'], "(") - $start
63 if ((! isset($gis_data['gis_type']))
64 || (! in_array($gis_data['gis_type'], $gis_types))
65 ) {
66 $gis_data['gis_type'] = $gis_types[0];
69 $geom_type = $gis_data['gis_type'];
71 // Generate parameters from value passed.
72 $gis_obj = PMA_GIS_Factory::factory($geom_type);
73 if (isset($_REQUEST['value'])) {
74 $gis_data = array_merge(
75 $gis_data, $gis_obj->generateParams($_REQUEST['value'])
79 // Generate Well Known Text
80 $srid = (isset($gis_data['srid']) && $gis_data['srid'] != '')
81 ? htmlspecialchars($gis_data['srid']) : 0;
82 $wkt = $gis_obj->generateWkt($gis_data, 0);
83 $wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
84 $result = "'" . $wkt . "'," . $srid;
86 // Generate PNG or SVG based visualization
87 $format = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8)
88 ? 'png' : 'svg';
89 $visualizationSettings = array(
90 'width' => 450,
91 'height' => 300,
92 'spatialColumn' => 'wkt'
94 $data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
95 $visualization = PMA_GIS_Visualization::getByData($data, $visualizationSettings)
96 ->toImage($format);
98 $open_layers = PMA_GIS_Visualization::getByData($data, $visualizationSettings)
99 ->asOl();
101 // If the call is to update the WKT and visualization make an AJAX response
102 if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
103 $extra_data = array(
104 'result' => $result,
105 'visualization' => $visualization,
106 'openLayers' => $open_layers,
108 $response = PMA_Response::getInstance();
109 $response->addJSON($extra_data);
110 exit;
113 ob_start();
115 echo '<form id="gis_data_editor_form" action="gis_data_editor.php" method="post">';
116 echo '<input type="hidden" id="pmaThemeImage"'
117 . ' value="' . $GLOBALS['pmaThemeImage'] . '" />';
118 echo '<div id="gis_data_editor">';
120 echo '<h3>';
121 printf(
122 __('Value for the column "%s"'),
123 htmlspecialchars($_REQUEST['field'])
125 echo '</h3>';
127 echo '<input type="hidden" name="field" value="'
128 . htmlspecialchars($_REQUEST['field']) . '" />';
129 // The input field to which the final result should be added
130 // and corresponding null checkbox
131 if (isset($_REQUEST['input_name'])) {
132 echo '<input type="hidden" name="input_name" value="'
133 . htmlspecialchars($_REQUEST['input_name']) . '" />';
135 echo PMA_URL_getHiddenInputs();
137 echo '<!-- Visualization section -->';
138 echo '<div id="placeholder" style="width:450px;height:300px;'
139 . ($srid != 0 ? 'display:none;' : '') . '">';
140 echo $visualization;
141 echo '</div>';
143 echo '<div id="openlayersmap" style="width:450px;height:300px;'
144 . ($srid == 0 ? 'display:none;' : '') . '">';
145 echo '</div>';
147 echo '<div class="choice" style="float:right;clear:right;">';
148 echo '<input type="checkbox" id="choice" value="useBaseLayer"'
149 . ($srid != 0 ? ' checked="checked"' : '') . '/>';
150 echo '<label for="choice">' . __("Use OpenStreetMaps as Base Layer") . '</label>';
151 echo '</div>';
153 echo '<script language="javascript" type="text/javascript">';
154 echo $open_layers;
155 echo '</script>';
156 echo '<!-- End of visualization section -->';
159 echo '<!-- Header section - Inclueds GIS type selector and input field for SRID -->';
160 echo '<div id="gis_data_header">';
161 echo '<select name="gis_data[gis_type]" class="gis_type">';
162 foreach ($gis_types as $gis_type) {
163 echo '<option value="' . $gis_type . '"';
164 if ($geom_type == $gis_type) {
165 echo ' selected="selected"';
167 echo '>' . $gis_type . '</option>';
169 echo '</select>';
170 echo '&nbsp;&nbsp;&nbsp;&nbsp;';
171 /* l10n: Spatial Reference System Identifier */
172 echo '<label for="srid">' . __('SRID:') . '</label>';
173 echo '<input name="gis_data[srid]" type="text" value="' . $srid . '" />';
174 echo '</div>';
175 echo '<!-- End of header section -->';
177 echo '<!-- Data section -->';
178 echo '<div id="gis_data">';
180 $geom_count = 1;
181 if ($geom_type == 'GEOMETRYCOLLECTION') {
182 $geom_count = (isset($gis_data[$geom_type]['geom_count']))
183 ? $gis_data[$geom_type]['geom_count'] : 1;
184 if (isset($gis_data[$geom_type]['add_geom'])) {
185 $geom_count++;
187 echo '<input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]"'
188 . ' value="' . $geom_count . '" />';
191 for ($a = 0; $a < $geom_count; $a++) {
192 if (! isset($gis_data[$a])) {
193 continue;
196 if ($geom_type == 'GEOMETRYCOLLECTION') {
197 echo '<br/><br/>';
198 printf(__('Geometry %d:'), $a + 1);
199 echo '<br/>';
200 if (isset($gis_data[$a]['gis_type'])) {
201 $type = $gis_data[$a]['gis_type'];
202 } else {
203 $type = $gis_types[0];
205 echo '<select name="gis_data[' . $a . '][gis_type]" class="gis_type">';
206 foreach (array_slice($gis_types, 0, 6) as $gis_type) {
207 echo '<option value="' . $gis_type . '"';
208 if ($type == $gis_type) {
209 echo ' selected="selected"';
211 echo '>' . $gis_type . '</option>';
213 echo '</select>';
214 } else {
215 $type = $geom_type;
218 if ($type == 'POINT') {
219 echo '<br/>';
220 echo __('Point:');
221 echo '<label for="x">' . __("X") . '</label>';
222 echo '<input name="gis_data[' . $a . '][POINT][x]" type="text"'
223 . ' value="' . escape($gis_data[$a]['POINT']['x']) . '" />';
224 echo '<label for="y">' . __("Y") . '</label>';
225 echo '<input name="gis_data[' . $a . '][POINT][y]" type="text"'
226 . ' value="' . escape($gis_data[$a]['POINT']['y']) . '" />';
228 } elseif ($type == 'MULTIPOINT' || $type == 'LINESTRING') {
229 $no_of_points = isset($gis_data[$a][$type]['no_of_points'])
230 ? $gis_data[$a][$type]['no_of_points'] : 1;
231 if ($type == 'LINESTRING' && $no_of_points < 2) {
232 $no_of_points = 2;
234 if ($type == 'MULTIPOINT' && $no_of_points < 1) {
235 $no_of_points = 1;
238 if (isset($gis_data[$a][$type]['add_point'])) {
239 $no_of_points++;
241 echo '<input type="hidden" value="' . $no_of_points . '"'
242 . ' name="gis_data[' . $a . '][' . $type . '][no_of_points]" />';
244 for ($i = 0; $i < $no_of_points; $i++) {
245 echo '<br/>';
246 printf(__('Point %d'), $i + 1);
247 echo ': ';
248 echo '<label for="x">' . __("X") . '</label>';
249 echo '<input type="text"'
250 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][x]"'
251 . ' value="' . escape($gis_data[$a][$type][$i]['x']) . '" />';
252 echo '<label for="y">' . __("Y") . '</label>';
253 echo '<input type="text"'
254 . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][y]"'
255 . ' value="' . escape($gis_data[$a][$type][$i]['y']) . '" />';
257 echo '<input type="submit"'
258 . ' name="gis_data[' . $a . '][' . $type . '][add_point]"'
259 . ' class="add addPoint" value="' . __("Add a point") . '" />';
261 } elseif ($type == 'MULTILINESTRING' || $type == 'POLYGON') {
262 $no_of_lines = isset($gis_data[$a][$type]['no_of_lines'])
263 ? $gis_data[$a][$type]['no_of_lines'] : 1;
264 if ($no_of_lines < 1) {
265 $no_of_lines = 1;
267 if (isset($gis_data[$a][$type]['add_line'])) {
268 $no_of_lines++;
270 echo '<input type="hidden" value="' . $no_of_lines . '"'
271 . ' name="gis_data[' . $a . '][' . $type . '][no_of_lines]" />';
273 for ($i = 0; $i < $no_of_lines; $i++) {
274 echo '<br/>';
275 if ($type == 'MULTILINESTRING') {
276 printf(__('Linestring %d:'), $i + 1);
277 } else {
278 if ($i == 0) {
279 echo __('Outer ring:');
280 } else {
281 printf(__('Inner ring %d:'), $i);
285 $no_of_points = isset($gis_data[$a][$type][$i]['no_of_points'])
286 ? $gis_data[$a][$type][$i]['no_of_points'] : 2;
287 if ($type == 'MULTILINESTRING' && $no_of_points < 2) {
288 $no_of_points = 2;
290 if ($type == 'POLYGON' && $no_of_points < 4) {
291 $no_of_points = 4;
293 if (isset($gis_data[$a][$type][$i]['add_point'])) {
294 $no_of_points++;
296 echo '<input type="hidden" value="' . $no_of_points . '"'
297 . ' name="gis_data[' . $a . '][' . $type . '][' . $i
298 . '][no_of_points]" />';
300 for ($j = 0; $j < $no_of_points; $j++) {
301 echo('<br/>');
302 printf(__('Point %d'), $j + 1);
303 echo ': ';
304 echo '<label for="x">' . __("X") . '</label>';
305 echo '<input type="text" name="gis_data[' . $a . '][' . $type . ']['
306 . $i . '][' . $j . '][x]" value="'
307 . escape($gis_data[$a][$type][$i][$j]['x']) . '" />';
308 echo '<label for="y">' . __("Y") . '</label>';
309 echo '<input type="text" name="gis_data[' . $a . '][' . $type . ']['
310 . $i . '][' . $j . '][y]"' . ' value="'
311 . escape($gis_data[$a][$type][$i][$j]['y']) . '" />';
313 echo '<input type="submit" name="gis_data[' . $a . '][' . $type . ']['
314 . $i . '][add_point]"'
315 . ' class="add addPoint" value="' . __("Add a point") . '" />';
317 $caption = ($type == 'MULTILINESTRING')
318 ? __('Add a linestring')
319 : __('Add an inner ring');
320 echo '<br/>';
321 echo '<input type="submit"'
322 . ' name="gis_data[' . $a . '][' . $type . '][add_line]"'
323 . ' class="add addLine" value="' . $caption . '" />';
325 } elseif ($type == 'MULTIPOLYGON') {
326 $no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons'])
327 ? $gis_data[$a][$type]['no_of_polygons'] : 1;
328 if ($no_of_polygons < 1) {
329 $no_of_polygons = 1;
331 if (isset($gis_data[$a][$type]['add_polygon'])) {
332 $no_of_polygons++;
334 echo '<input type="hidden"'
335 . ' name="gis_data[' . $a . '][' . $type . '][no_of_polygons]"'
336 . ' value="' . $no_of_polygons . '" />';
338 for ($k = 0; $k < $no_of_polygons; $k++) {
339 echo '<br/>';
340 printf(__('Polygon %d:'), $k + 1);
341 $no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines'])
342 ? $gis_data[$a][$type][$k]['no_of_lines'] : 1;
343 if ($no_of_lines < 1) {
344 $no_of_lines = 1;
346 if (isset($gis_data[$a][$type][$k]['add_line'])) {
347 $no_of_lines++;
349 echo '<input type="hidden"'
350 . ' name="gis_data[' . $a . '][' . $type . '][' . $k
351 . '][no_of_lines]"' . ' value="' . $no_of_lines . '" />';
353 for ($i = 0; $i < $no_of_lines; $i++) {
354 echo '<br/><br/>';
355 if ($i == 0) {
356 echo __('Outer ring:');
357 } else {
358 printf(__('Inner ring %d:'), $i);
361 $no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points'])
362 ? $gis_data[$a][$type][$k][$i]['no_of_points'] : 4;
363 if ($no_of_points < 4) {
364 $no_of_points = 4;
366 if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
367 $no_of_points++;
369 echo '<input type="hidden"'
370 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i
371 . '][no_of_points]"' . ' value="' . $no_of_points . '" />';
373 for ($j = 0; $j < $no_of_points; $j++) {
374 echo '<br/>';
375 printf(__('Point %d'), $j + 1);
376 echo ': ';
377 echo '<label for="x">' . __("X") . '</label>';
378 echo '<input type="text"'
379 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . ']['
380 . $i . '][' . $j . '][x]"'
381 . ' value="' . escape($gis_data[$a][$type][$k][$i][$j]['x'])
382 . '" />';
383 echo '<label for="y">' . __("Y") . '</label>';
384 echo '<input type="text"'
385 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . ']['
386 . $i . '][' . $j . '][y]"'
387 . ' value="' . escape($gis_data[$a][$type][$k][$i][$j]['y'])
388 . '" />';
390 echo '<input type="submit"'
391 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i
392 . '][add_point]"'
393 . ' class="add addPoint" value="' . __("Add a point") . '" />';
395 echo '<br/>';
396 echo '<input type="submit"'
397 . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][add_line]"'
398 . ' class="add addLine" value="' . __('Add an inner ring') . '" />';
399 echo '<br/>';
401 echo '<br/>';
402 echo '<input type="submit"'
403 . ' name="gis_data[' . $a . '][' . $type . '][add_polygon]"'
404 . ' class="add addPolygon" value="' . __('Add a polygon') . '" />';
407 if ($geom_type == 'GEOMETRYCOLLECTION') {
408 echo '<br/><br/>';
409 echo '<input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]"'
410 . 'class="add addGeom" value="' . __("Add geometry") . '" />';
412 echo '</div>';
413 echo '<!-- End of data section -->';
415 echo '<br/>';
416 echo '<input type="submit" name="gis_data[save]" value="' . __('Go') . '" />';
418 echo '<div id="gis_data_output">';
419 echo '<h3>' . __('Output') . '</h3>';
420 echo '<p>';
421 echo __(
422 'Choose "GeomFromText" from the "Function" column and paste the'
423 . ' string below into the "Value" field.'
425 echo '</p>';
426 echo '<textarea id="gis_data_textarea" cols="95" rows="5">';
427 echo $result;
428 echo '</textarea>';
429 echo '</div>';
431 echo '</div>';
432 echo '</form>';
434 PMA_Response::getInstance()->addJSON('gis_editor', ob_get_contents());
435 ob_end_clean();