2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 require_once 'libraries/common.inc.php';
4 if (! isset($_REQUEST['get_gis_editor']) && ! isset($_REQUEST['generate'])) {
5 include_once 'libraries/header_http.inc.php';
6 include_once 'libraries/header_meta_style.inc.php';
8 require_once 'libraries/gis/pma_gis_factory.php';
9 require_once 'libraries/gis_visualization.lib.php';
11 // Get data if any posted
13 if (PMA_isValid($_REQUEST['gis_data'], 'array')) {
14 $gis_data = $_REQUEST['gis_data'];
27 // Extract type from the initial call and make sure that it's a valid one.
28 // Extract from field's values if availbale, if not use the column type passed.
29 if (! isset($gis_data['gis_type'])) {
30 if (isset($_REQUEST['type']) && $_REQUEST['type'] != '') {
31 $gis_data['gis_type'] = strtoupper($_REQUEST['type']);
33 if (isset($_REQUEST['value']) && trim($_REQUEST['value']) != '') {
34 $start = (substr($_REQUEST['value'], 0, 1) == "'") ?
1 : 0;
35 $gis_data['gis_type'] = substr($_REQUEST['value'], $start, strpos($_REQUEST['value'], "(") - $start);
37 if ((! isset($gis_data['gis_type'])) ||
(! in_array($gis_data['gis_type'], $gis_types))) {
38 $gis_data['gis_type'] = $gis_types[0];
41 $geom_type = $gis_data['gis_type'];
43 // Generate parameters from value passed.
44 $gis_obj = PMA_GIS_Factory
::factory($geom_type);
45 if (isset($_REQUEST['value'])) {
46 $gis_data = array_merge($gis_data, $gis_obj->generateParams($_REQUEST['value']));
49 // Generate Well Known Text
50 $srid = (isset($gis_data['srid']) && $gis_data['srid'] != '') ?
htmlspecialchars($gis_data['srid']) : 0;
51 $wkt = $gis_obj->generateWkt($gis_data, 0);
52 $wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
53 $result = "'" . $wkt . "'," . $srid;
55 // Generate PNG or SVG based visualization
56 $format = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
<= 8) ?
'png' : 'svg';
57 $visualizationSettings = array('width' => 450, 'height' => 300, 'spatialColumn' => 'wkt');
58 $data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
59 $visualization = PMA_GIS_visualizationResults($data, $visualizationSettings, $format);
60 $open_layers = PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
62 // If the call is to update the WKT and visualization make an AJAX response
63 if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
66 'visualization' => $visualization,
67 'openLayers' => $open_layers,
69 PMA_ajaxResponse(null, true, $extra_data);
72 // If the call is to get the whole content, start buffering, skipping </head> and <body> tags
73 if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) {
82 <form id
="gis_data_editor_form" action
="gis_data_editor.php" method
="post">
83 <input type
="hidden" id
="pmaThemeImage" value
="<?php echo($GLOBALS['pmaThemeImage']); ?>" />
84 <div id
="gis_data_editor">
85 <h3
><?php
printf(__('Value for the column "%s"'), htmlspecialchars($_REQUEST['field'])); ?
></h3
>
87 <?php
echo('<input type="hidden" name="field" value="' . htmlspecialchars($_REQUEST['field']) . '" />');
88 // The input field to which the final result should be added and corresponding null checkbox
89 if (isset($_REQUEST['input_name'])) {
90 echo('<input type="hidden" name="input_name" value="' . htmlspecialchars($_REQUEST['input_name']) . '" />');
92 echo PMA_generate_common_hidden_inputs();
94 <!-- Visualization section
-->
95 <div id
="placeholder" style
="width:450px;height:300px;
96 <?php if ($srid != 0) {
97 echo('display:none;');
100 <?php
echo ($visualization);
102 <div id
="openlayersmap" style
="width:450px;height:300px;
103 <?php if ($srid == 0) {
104 echo('display:none;');
108 <div
class="choice" style
="float:right;clear:right;">
109 <input type
="checkbox" id
="choice" value
="useBaseLayer"
110 <?php
if ($srid != 0) {
111 echo(' checked="checked"');
114 <label
for="choice"><?php
echo __("Use OpenStreetMaps as Base Layer"); ?
></label
>
116 <script language
="javascript" type
="text/javascript">
117 <?php
echo($open_layers); ?
>
119 <!-- End of visualization section
-->
121 <!-- Header section
- Inclueds GIS type selector
and input field
for SRID
-->
122 <div id
="gis_data_header">
123 <select name
="gis_data[gis_type]" class="gis_type">
125 foreach ($gis_types as $gis_type) {
126 echo('<option value="' . $gis_type . '"');
127 if ($geom_type == $gis_type) {
128 echo(' selected="selected"');
130 echo('>' . $gis_type . '</option>');
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>');
170 if ($type == 'POINT') {
171 echo('<br/>'); echo __("Point"); echo(' :');
172 ?
> <label
for="x"><?php
echo __("X"); ?
></label
>
173 <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']) : ''); ?>" />
174 <label
for="y"><?php
echo __("Y"); ?
></label
>
175 <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']) : ''); ?>" />
177 } elseif ($type == 'MULTIPOINT' ||
$type == 'LINESTRING') {
179 $no_of_points = isset($gis_data[$a][$type]['no_of_points']) ?
$gis_data[$a][$type]['no_of_points'] : 1;
180 if ($type == 'LINESTRING' && $no_of_points < 2) {
183 if ($type == 'MULTIPOINT' && $no_of_points < 1) {
187 if (isset($gis_data[$a][$type]['add_point'])) {
190 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_points]" value="' . $no_of_points . '">');
192 for ($i = 0; $i < $no_of_points; $i++
) {
194 printf(__('Point %d'), $i +
1);
196 ?
> <label
for="x"><?php
echo __("X"); ?
></label
>
197 <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']) : ''); ?>" />
198 <label
for="y"><?php
echo __("Y"); ?
></label
>
199 <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']) : ''); ?>" />
203 <input type
="submit" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_point]" class="add addPoint" value
="<?php echo __("Add a point
"); ?>">
205 } elseif ($type == 'MULTILINESTRING' ||
$type == 'POLYGON') {
207 $no_of_lines = isset($gis_data[$a][$type]['no_of_lines']) ?
$gis_data[$a][$type]['no_of_lines'] : 1;
208 if ($no_of_lines < 1) {
211 if (isset($gis_data[$a][$type]['add_line'])) {
214 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_lines]" value="' . $no_of_lines . '">');
216 for ($i = 0; $i < $no_of_lines; $i++
) {
218 if ($type == 'MULTILINESTRING') {
219 echo __("Linestring"); echo($i +
1 . ':');
222 echo __("Outer Ring") . ':';
224 echo __("Inner Ring"); echo($i . ':');
228 $no_of_points = isset($gis_data[$a][$type][$i]['no_of_points']) ?
$gis_data[$a][$type][$i]['no_of_points'] : 2;
229 if ($type == 'MULTILINESTRING' && $no_of_points < 2) {
232 if ($type == 'POLYGON' && $no_of_points < 4) {
235 if (isset($gis_data[$a][$type][$i]['add_point'])) {
238 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">');
240 for ($j = 0; $j < $no_of_points; $j++
) {
242 printf(__('Point %d'), $j +
1);
244 ?
> <label
for="x"><?php
echo __("X"); ?
></label
>
245 <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']) : ''); ?>" />
246 <label
for="y"><?php
echo __("Y"); ?
></label
>
247 <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']) : ''); ?>" />
249 ?
> <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
"); ?>">
251 $caption = ($type == 'MULTILINESTRING') ?
__('Add a linestring') : __('Add an inner ring');
252 ?
> <br
/><input type
="submit" name
="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_line]" class="add addLine" value
="<?php echo($caption); ?>">
254 } elseif ($type == 'MULTIPOLYGON') {
255 $no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons']) ?
$gis_data[$a][$type]['no_of_polygons'] : 1;
256 if ($no_of_polygons < 1) {
259 if (isset($gis_data[$a][$type]['add_polygon'])) {
262 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_polygons]" value="' . $no_of_polygons . '">');
264 for ($k = 0; $k < $no_of_polygons; $k++
) {
265 echo('<br/>'); echo __("Polygon"); echo($k +
1 . ':');
266 $no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines']) ?
$gis_data[$a][$type][$k]['no_of_lines'] : 1;
267 if ($no_of_lines < 1) {
270 if (isset($gis_data[$a][$type][$k]['add_line'])) {
273 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $k . '][no_of_lines]" value="' . $no_of_lines . '">');
275 for ($i = 0; $i < $no_of_lines; $i++
) {
278 echo __("Outer Ring") . ':';
280 echo __("Inner Ring"); echo($i . ':');
283 $no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points']) ?
$gis_data[$a][$type][$k][$i]['no_of_points'] : 4;
284 if ($no_of_points < 4) {
287 if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
290 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">');
292 for ($j = 0; $j < $no_of_points; $j++
) {
294 printf(__('Point %d'), $j +
1);
296 ?
> <label
for="x"><?php
echo __("X"); ?
></label
>
297 <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']) : ''); ?>" />
298 <label
for="y"><?php
echo __("Y"); ?
></label
>
299 <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']) : ''); ?>" />
301 ?
> <input type
="submit" name
="<?php echo("gis_data
[" . $a . "][" . $type . "][" . $k . "][" . $i . "][add_point
]"); ?>" class="add addPoint" value
="<?php echo __("Add a point
"); ?>">
303 ?
> <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
/>
305 ?
> <br
/><input type
="submit" name
="<?php echo("gis_data
[" . $a . "][" . $type . "][add_polygon
]"); ?>" class="add addPolygon" value
="<?php echo __('Add a polygon') ?>">
308 if ($geom_type == 'GEOMETRYCOLLECTION') {
309 ?
> <br
/><br
/><input type
="submit" name
="gis_data[GEOMETRYCOLLECTION][add_geom]" class="add addGeom" value
="<?php echo __("Add geometry
"); ?>" />
312 <!-- End of data section
-->
314 <br
/><input type
="submit" name
="gis_data[save]" value
="<?php echo __('Go') ?>">
315 <div id
="gis_data_output">
316 <h3
><?php
echo __('Output'); ?
></h3
>
317 <p
><?php
echo __('Chose "GeomFromText" from the "Function" column and paste the below string into the "Value" field'); ?
></p
>
318 <textarea id
="gis_data_textarea" cols
="95" rows
="5">
326 // If the call is to get the whole content, get the content in the buffer and make and AJAX response.
327 if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) {
328 $extra_data['gis_editor'] = ob_get_contents();
329 PMA_ajaxResponse(null, ob_end_clean(), $extra_data);
336 * Displays the footer
338 require 'libraries/footer.inc.php';