2 require_once './libraries/common.inc.php';
3 if (! isset($_REQUEST['get_gis_editor']) && ! isset($_REQUEST['generate'])) {
4 include_once './libraries/header_http.inc.php';
5 include_once './libraries/header_meta_style.inc.php';
7 require_once './libraries/gis/pma_gis_factory.php';
8 require_once './libraries/gis_visualization.lib.php';
10 // Get data if any posted
12 if (PMA_isValid($_REQUEST['gis_data'], 'array')) {
13 $gis_data = $_REQUEST['gis_data'];
26 // Extract type from the initial call and make sure that it's a valid one.
27 // Extract from field's values if availbale, if not use the column type passed.
28 if (! isset($gis_data['gis_type'])) {
29 if (isset($_REQUEST['type']) && $_REQUEST['type'] != '') {
30 $gis_data['gis_type'] = strtoupper($_REQUEST['type']);
32 if (isset($_REQUEST['value']) && trim($_REQUEST['value']) != '') {
33 $start = (substr($_REQUEST['value'], 0, 1) == "'") ?
1 : 0;
34 $gis_data['gis_type'] = substr($_REQUEST['value'], $start, strpos($_REQUEST['value'], "(") - $start);
36 if ((! isset($gis_data['gis_type'])) ||
(! in_array($gis_data['gis_type'], $gis_types))) {
37 $gis_data['gis_type'] = $gis_types[0];
40 $geom_type = $gis_data['gis_type'];
42 // Generate parameters from value passed.
43 $gis_obj = PMA_GIS_Factory
::factory($geom_type);
44 if (isset($_REQUEST['value'])) {
45 $gis_data = array_merge($gis_data, $gis_obj->generateParams($_REQUEST['value']));
48 // Generate Well Known Text
49 $srid = (isset($gis_data['srid']) && $gis_data['srid'] != '') ?
htmlspecialchars($gis_data['srid']) : 0;
50 $wkt = $gis_obj->generateWkt($gis_data, 0);
51 $wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
52 $result = "'" . $wkt . "'," . $srid;
54 // Gererate PNG or SVG based visualization
55 $format = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
<= 8) ?
'png' : 'svg';
56 $visualizationSettings = array('width' => 450, 'height' => 300, 'spatialColumn' => 'wkt');
57 $data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
58 $visualization = PMA_GIS_visualizationResults($data, $visualizationSettings, $format);
59 $open_layers = PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
61 // If the call is to update the WKT and visualization make an AJAX response
62 if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
65 'visualization' => $visualization,
66 'openLayers' => $open_layers,
68 PMA_ajaxResponse(null, true, $extra_data);
71 // If the call is to get the whole content, start buffering, skipping </head> and <body> tags
72 if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) {
81 <form id
="gis_data_editor_form" action
="gis_data_editor.php" method
="post">
82 <input type
="hidden" id
="pmaThemeImage" value
="<?php echo($GLOBALS['pmaThemeImage']); ?>" />
83 <div id
="gis_data_editor">
84 <h3
><?php
printf(__('Value for the column "%s"'), htmlspecialchars($_REQUEST['field'])); ?
></h3
>
86 <?php
echo('<input type="hidden" name="field" value="' . htmlspecialchars($_REQUEST['field']) . '" />');
87 // The input field to which the final result should be added and corresponding null checkbox
88 if (isset($_REQUEST['input_name'])) {
89 echo('<input type="hidden" name="input_name" value="' . htmlspecialchars($_REQUEST['input_name']) . '" />');
91 echo PMA_generate_common_hidden_inputs();
93 <!-- Visualization section
-->
94 <div id
="placeholder" style
="width:450px;height:300px;
95 <?php if ($srid != 0) {
96 echo('display:none;');
99 <?php
echo ($visualization);
101 <div id
="openlayersmap" style
="width:450px;height:300px;
102 <?php if ($srid == 0) {
103 echo('display:none;');
107 <div
class="choice" style
="float:right;clear:right;">
108 <input type
="checkbox" id
="choice" value
="useBaseLayer"
109 <?php
if ($srid != 0) {
110 echo(' checked="checked"');
113 <label
for="choice"><?php
echo __("Use OpenStreetMaps as Base Layer"); ?
></label
>
115 <script language
="javascript" type
="text/javascript">
116 <?php
echo($open_layers); ?
>
118 <!-- End of visualization section
-->
120 <!-- Header section
- Inclueds GIS type selector
and input field
for SRID
-->
121 <div id
="gis_data_header">
122 <select name
="gis_data[gis_type]" class="gis_type">
124 foreach ($gis_types as $gis_type) {
125 echo('<option value="' . $gis_type . '"');
126 if ($geom_type == $gis_type) {
127 echo(' selected="selected"');
129 echo('>' . $gis_type . '</option>');
133 <input type
="submit" name
="gis_data[go]" class="go" value
="<?php echo __("Go
")?>" />
134 <label
for="srid"><?php
echo __("SRID"); ?
>: 
;</label
>
135 <input name
="gis_data[srid]" type
="text" value
="<?php echo($srid); ?>" />
137 <!-- End of header section
-->
139 <!-- Data section
-->
141 <?php
$geom_count = 1;
142 if ($geom_type == 'GEOMETRYCOLLECTION') {
143 $geom_count = (isset($gis_data[$geom_type]['geom_count'])) ?
$gis_data[$geom_type]['geom_count'] : 1;
144 if (isset($gis_data[$geom_type]['add_geom'])) {
147 echo('<input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]" value="' . $geom_count . '">');
149 for ($a = 0; $a < $geom_count; $a++
) {
150 if ($geom_type == 'GEOMETRYCOLLECTION') {
151 echo('<br/><br/>'); echo __("Geometry"); echo($a +
1 . ':<br/>');
152 if (isset($gis_data[$a]['gis_type'])) {
153 $type = $gis_data[$a]['gis_type'];
155 $type = $gis_types[0];
157 echo('<select name="gis_data[' . $a . '][gis_type]" class="gis_type">');
158 foreach (array_slice($gis_types, 0, 6) as $gis_type) {
159 echo('<option value="' . $gis_type . '"');
160 if ($type == $gis_type) {
161 echo(' selected="selected"');
163 echo('>' . $gis_type . '</option>');
166 echo('<input type="submit" name="gis_data[' . $a . '][go]" class="go" value="'); echo __("Go"); echo('">');
171 if ($type == 'POINT') {
172 echo('<br/>'); echo __("Point"); echo(' :');
173 ?
> <label
for="x"><?php
echo __("X"); ?
></label
>
174 <input name
="gis_data[<?php echo($a); ?>][POINT][x]" type
="text" value
="<?php echo(isset($gis_data[$a]['POINT']['x']) ? htmlspecialchars($gis_data[$a]['POINT']['x']) : ''); ?>" />
175 <label
for="y"><?php
echo __("Y"); ?
></label
>
176 <input name
="gis_data[<?php echo($a); ?>][POINT][y]" type
="text" value
="<?php echo(isset($gis_data[$a]['POINT']['y']) ? htmlspecialchars($gis_data[$a]['POINT']['y']) : ''); ?>" />
178 } elseif ($type == 'MULTIPOINT' ||
$type == 'LINESTRING') {
180 $no_of_points = isset($gis_data[$a][$type]['no_of_points']) ?
$gis_data[$a][$type]['no_of_points'] : 1;
181 if ($type == 'LINESTRING' && $no_of_points < 2) {
184 if ($type == 'MULTIPOINT' && $no_of_points < 1) {
188 if (isset($gis_data[$a][$type]['add_point'])) {
191 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_points]" value="' . $no_of_points . '">');
193 for ($i = 0; $i < $no_of_points; $i++
) {
195 printf(__('Point %d'), $i +
1);
197 ?
> <label
for="x"><?php
echo __("X"); ?
></label
>
198 <input type
="text" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][x]" value
="<?php echo(isset($gis_data[$a][$type][$i]['x']) ? htmlspecialchars($gis_data[$a][$type][$i]['x']) : ''); ?>" />
199 <label
for="y"><?php
echo __("Y"); ?
></label
>
200 <input type
="text" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][y]" value
="<?php echo(isset($gis_data[$a][$type][$i]['y']) ? htmlspecialchars($gis_data[$a][$type][$i]['y']) : ''); ?>" />
204 <input type
="submit" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_point]" class="add addPoint" value
="<?php echo __("Add a point
"); ?>">
206 } elseif ($type == 'MULTILINESTRING' ||
$type == 'POLYGON') {
208 $no_of_lines = isset($gis_data[$a][$type]['no_of_lines']) ?
$gis_data[$a][$type]['no_of_lines'] : 1;
209 if ($no_of_lines < 1) {
212 if (isset($gis_data[$a][$type]['add_line'])) {
215 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_lines]" value="' . $no_of_lines . '">');
217 for ($i = 0; $i < $no_of_lines; $i++
) {
219 if ($type == 'MULTILINESTRING') {
220 echo __("Linestring"); echo($i +
1 . ':');
223 echo __("Outer Ring") . ':';
225 echo __("Inner Ring"); echo($i . ':');
229 $no_of_points = isset($gis_data[$a][$type][$i]['no_of_points']) ?
$gis_data[$a][$type][$i]['no_of_points'] : 2;
230 if ($type == 'MULTILINESTRING' && $no_of_points < 2) {
233 if ($type == 'POLYGON' && $no_of_points < 4) {
236 if (isset($gis_data[$a][$type][$i]['add_point'])) {
239 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">');
241 for ($j = 0; $j < $no_of_points; $j++
) {
243 printf(__('Point %d'), $j +
1);
245 ?
> <label
for="x"><?php
echo __("X"); ?
></label
>
246 <input type
="text" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][<?php echo($j); ?>][x]" value
="<?php echo(isset($gis_data[$a][$type][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$i][$j]['x']) : ''); ?>" />
247 <label
for="y"><?php
echo __("Y"); ?
></label
>
248 <input type
="text" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][<?php echo($j); ?>][y]" value
="<?php echo(isset($gis_data[$a][$type][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$i][$j]['y']) : ''); ?>" />
250 ?
> <input type
="submit" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][add_point]" class="add addPoint" value
="<?php echo __("Add a point
"); ?>">
252 $caption = ($type == 'MULTILINESTRING') ?
__('Add a linestring') : __('Add an inner ring');
253 ?
> <br
/><input type
="submit" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_line]" class="add addLine" value
="<?php echo($caption); ?>">
255 } elseif ($type == 'MULTIPOLYGON') {
256 $no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons']) ?
$gis_data[$a][$type]['no_of_polygons'] : 1;
257 if ($no_of_polygons < 1) {
260 if (isset($gis_data[$a][$type]['add_polygon'])) {
263 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_polygons]" value="' . $no_of_polygons . '">');
265 for ($k = 0; $k < $no_of_polygons; $k++
) {
266 echo('<br/>'); echo __("Polygon"); echo($k +
1 . ':');
267 $no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines']) ?
$gis_data[$a][$type][$k]['no_of_lines'] : 1;
268 if ($no_of_lines < 1) {
271 if (isset($gis_data[$a][$type][$k]['add_line'])) {
274 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $k . '][no_of_lines]" value="' . $no_of_lines . '">');
276 for ($i = 0; $i < $no_of_lines; $i++
) {
279 echo __("Outer Ring") . ':';
281 echo __("Inner Ring"); echo($i . ':');
284 $no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points']) ?
$gis_data[$a][$type][$k][$i]['no_of_points'] : 4;
285 if ($no_of_points < 4) {
288 if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
291 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">');
293 for ($j = 0; $j < $no_of_points; $j++
) {
295 printf(__('Point %d'), $j +
1);
297 ?
> <label
for="x"><?php
echo __("X"); ?
></label
>
298 <input type
="text" name
="<?php echo("gis_data
[" . $a . "][" . $type . "][" . $k . "][" . $i . "][" . $j . "][x
]"); ?>" value
="<?php echo(isset($gis_data[$a][$type][$k][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$k][$i][$j]['x']) : ''); ?>" />
299 <label
for="y"><?php
echo __("Y"); ?
></label
>
300 <input type
="text" name
="<?php echo("gis_data
[" . $a . "][" . $type . "][" . $k . "][" . $i . "][" . $j . "][y
]"); ?>" value
="<?php echo(isset($gis_data[$a][$type][$k][$i][$j]['y']) ? htmlspecialchars($gis_data[$a][$type][$k][$i][$j]['y']) : ''); ?>" />
302 ?
> <input type
="submit" name
="<?php echo("gis_data
[" . $a . "][" . $type . "][" . $k . "][" . $i . "][add_point
]"); ?>" class="add addPoint" value
="<?php echo __("Add a point
"); ?>">
304 ?
> <br
/><input type
="submit" name
="<?php echo("gis_data
[" . $a . "][" . $type . "][" . $k . "][add_line
]"); ?>" class="add addLine" value
="<?php echo __('Add an inner ring') ?>"><br
/>
306 ?
> <br
/><input type
="submit" name
="<?php echo("gis_data
[" . $a . "][" . $type . "][add_polygon
]"); ?>" class="add addPolygon" value
="<?php echo __('Add a polygon') ?>">
309 if ($geom_type == 'GEOMETRYCOLLECTION') {
310 ?
> <br
/><br
/><input type
="submit" name
="gis_data[GEOMETRYCOLLECTION][add_geom]" class="add addGeom" value
="<?php echo __("Add geometry
"); ?>" />
313 <!-- End of data section
-->
315 <br
/><input type
="submit" name
="gis_data[save]" value
="<?php echo __('Go') ?>">
316 <div id
="gis_data_output">
317 <h3
><?php
echo __('Output'); ?
></h3
>
318 <p
><?php
echo __('Chose "GeomFromText" from the "Function" column and paste the below string into the "Value" field'); ?
></p
>
319 <textarea id
="gis_data_textarea" cols
="95" rows
="5">
327 // If the call is to get the whole content, get the content in the buffer and make and AJAX response.
328 if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) {
329 $extra_data['gis_editor'] = ob_get_contents();
330 PMA_ajaxResponse(null, ob_end_clean(), $extra_data);
337 * Displays the footer
339 require './libraries/footer.inc.php';