A polygon needs to have atleast 4 points.
[phpmyadmin/crack.git] / gis_data_editor.php
blob21cafc8cdddb0fe337067912adc9148ed2f43c61
1 <?php
3 require_once './libraries/common.inc.php';
4 require_once './libraries/header_http.inc.php';
5 require_once './libraries/header_meta_style.inc.php';
6 require_once './libraries/gis/pma_gis_factory.php';
7 require_once './libraries/gis_visualization.lib.php';
9 // Get data if any posted
10 $gis_data = array();
11 if (PMA_isValid($_REQUEST['gis_data'], 'array')) {
12 $gis_data = $_REQUEST['gis_data'];
15 $gis_types = array(
16 'POINT',
17 'MULTIPOINT',
18 'LINESTRING',
19 'MULTILINESTRING',
20 'POLYGON',
21 'MULTIPOLYGON',
22 'GEOMETRYCOLLECTION'
25 $no_visual = true;
26 if (! isset($gis_data['gis_type'])) {
27 if (isset($_REQUEST['value'])) {
28 $gis_data['gis_type'] = substr($_REQUEST['value'], 1, strpos($_REQUEST['value'], "(") - 1);
29 } else {
30 $gis_data['gis_type'] = $gis_types[0];
31 $no_visual = true;
34 $geom_type = $gis_data['gis_type'];
36 $gis_obj = PMA_GIS_Factory::factory($geom_type);
37 if (isset($_REQUEST['value'])) {
38 $gis_data = array_merge($gis_data, $gis_obj->generateParams($_REQUEST['value']));
41 $srid = isset($gis_data['srid']) ? htmlspecialchars($gis_data['srid']) : '';
42 $wkt = $gis_obj->generateWkt($gis_data, 0);
44 $format = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8) ? 'svg' : 'png';
45 $visualizationSettings = array('width' => 400, 'height' => 400,);
46 $data = array($wkt);
47 if (! $no_visual) {
48 $visualization = PMA_GIS_visualization_results($data, $visualizationSettings, $format);
51 if(isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
52 $extra_data = array(
53 'wkt' => $wkt,
54 'srid' => $srid,
55 'visualization' => $visualization,
57 PMA_ajaxResponse(null, true, $extra_data);
61 </head>
63 <body>
64 <form action="gis_data_editor.php" method="post">
65 <div id="gis_data_editor_no_js">
66 <h3><?php printf(__('Value for the column "%s"'), htmlspecialchars($_REQUEST['field'])); ?></h3>
67 <?php echo('<input type="hidden" name="field" value="' . htmlspecialchars($_REQUEST['field']) . '">');
68 echo PMA_generate_common_hidden_inputs($url_params);
70 <div id="placeholder">
71 <?php if (! $no_visual) {echo $visualization;} ?>
72 </div>
73 <div id="gis_data_header">
74 <select name="gis_data[gis_type]">
75 <?php
76 foreach ($gis_types as $gis_type) {
77 echo('<option value="' . $gis_type . '"');
78 if ($geom_type == $gis_type) {
79 echo(' selected="selected"');
81 echo('>' . $gis_type . '</option>');
84 </select>
85 <input type="submit" name="gis_data[go]" value="<?php echo __("Go")?>" />
86 <label for="srid"><?php echo __("SRID"); ?>:&nbsp;</label>
87 <input name="gis_data[srid]" type="text" value="<?php echo($srid); ?>" />
88 </div>
89 <div id="gis_data">
90 <?php
91 $geom_count = 1;
92 if ($geom_type == 'GEOMETRYCOLLECTION') {
93 $geom_count = (isset($gis_data[$geom_type]['geom_count'])) ? $gis_data[$geom_type]['geom_count'] : 1;
94 if (isset($gis_data[$geom_type]['add_geom'])) {
95 $geom_count++;
97 echo('<input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]" value="' . $geom_count . '">');
99 for ($a = 0; $a < $geom_count; $a++) {
100 if ($geom_type == 'GEOMETRYCOLLECTION') {
101 echo('<br/><br/>'); echo __("Geometry"); echo($a + 1 . ':<br/>');
102 if (isset($gis_data[$a]['gis_type'])) {
103 $type = $gis_data[$a]['gis_type'];
104 } else {
105 $type = $gis_types[0];
107 echo('<select name="gis_data[' . $a . '][gis_type]">');
108 foreach (array_slice($gis_types, 0, 6) as $gis_type) {
109 echo('<option value="' . $gis_type . '"');
110 if ($type == $gis_type) {
111 echo(' selected="selected"');
113 echo('>' . $gis_type . '</option>');
115 echo('</select>');
116 echo('<input type="submit" name="gis_data[' . $a . '][go]" value="'); echo __("Go"); echo('">');
117 } else {
118 $type = $geom_type;
121 if ($type == 'POINT') {
122 echo('<br/>'); echo __("Point");
123 ?> <label for="x"><?php echo __("X"); ?>:&nbsp;</label>
124 <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']) : ''); ?>" />
125 <label for="y"><?php echo __("Y"); ?>:&nbsp;</label>
126 <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']) : ''); ?>" />
127 <?php
128 } elseif ($type == 'MULTIPOINT' || $type == 'LINESTRING') {
130 $no_of_points = isset($gis_data[$a][$type]['no_of_points']) ? $gis_data[$a][$type]['no_of_points'] : 1;
131 if ($type == 'LINESTRING' && $no_of_points < 2) {
132 $no_of_points = 2;
134 if ($type == 'MULTIPOINT' && $no_of_points < 1) {
135 $no_of_points = 1;
138 if (isset($gis_data[$a][$type]['add_point'])) {
139 $no_of_points++;
141 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_points]" value="' . $no_of_points . '">');
143 for ($i = 0; $i < $no_of_points; $i++) {
144 echo('<br/>'); echo __("Point"); echo($i + 1 . ':');
145 ?> <label for="x"><?php echo __("X"); ?></label>
146 <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']) : ''); ?>" />
147 <label for="y"><?php echo __("Y"); ?></label>
148 <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']) : ''); ?>" />
149 <?php
152 <input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_point]" value="<?php echo __("Add a point"); ?>">
153 <?php
154 } elseif ($type == 'MULTILINESTRING' || $type == 'POLYGON') {
156 $no_of_lines = isset($gis_data[$a][$type]['no_of_lines']) ? $gis_data[$a][$type]['no_of_lines'] : 1;
157 if ($no_of_lines < 1) {
158 $no_of_lines = 1;
160 if (isset($gis_data[$a][$type]['add_line'])) {
161 $no_of_lines++;
163 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_lines]" value="' . $no_of_lines . '">');
165 for ($i = 0; $i < $no_of_lines; $i++) {
166 echo('<br/>');
167 if ($type == 'MULTILINESTRING') {
168 echo __("Linestring"); echo($i + 1 . ':');
169 } else {
170 if ($i == 0) {
171 echo __("Outer Ring:");
172 } else {
173 echo __("Inner Ring"); echo($i . ':');
177 $no_of_points = isset($gis_data[$a][$type][$i]['no_of_points']) ? $gis_data[$a][$type][$i]['no_of_points'] : 2;
178 if ($type == 'MULTILINESTRING' && $no_of_points < 2) {
179 $no_of_points = 2;
181 if ($type == 'POLYGON' && $no_of_points < 4) {
182 $no_of_points = 4;
184 if (isset($gis_data[$a][$type][$i]['add_point'])) {
185 $no_of_points++;
187 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">');
189 for ($j = 0; $j < $no_of_points; $j++) {
190 echo('<br/>'); echo __("Point"); echo($j + 1 . ':');
191 ?> <label for="x"><?php echo __("X"); ?></label>
192 <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']) : ''); ?>" />
193 <label for="y"><?php echo __("Y"); ?></label>
194 <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']) : ''); ?>" />
195 <?php }
196 ?> <input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][add_point]" value="<?php echo __("Add a point"); ?>">
197 <?php }
198 $caption = ($type == 'MULTILINESTRING') ? __('Add a linestring') : __('Add an inner ring');
199 ?> <br/><input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_line]" value="<?php echo($caption); ?>">
200 <?php
201 } elseif ($type == 'MULTIPOLYGON') {
202 $no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons']) ? $gis_data[$a][$type]['no_of_polygons'] : 1;
203 if ($no_of_polygons < 1) {
204 $no_of_polygons = 1;
206 if (isset($gis_data[$a][$type]['add_polygon'])) {
207 $no_of_polygons++;
209 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][no_of_polygons]" value="' . $no_of_polygons . '">');
211 for ($k = 0; $k < $no_of_polygons; $k++) {
212 echo('<br/>'); echo __("Polygon"); echo($k + 1 . ':');
213 $no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines']) ? $gis_data[$a][$type][$k]['no_of_lines'] : 1;
214 if ($no_of_lines < 1) {
215 $no_of_lines = 1;
217 if (isset($gis_data[$a][$type][$k]['add_line'])) {
218 $no_of_lines++;
220 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $k . '][no_of_lines]" value="' . $no_of_lines . '">');
222 for ($i = 0; $i < $no_of_lines; $i++) {
223 echo('<br/><br/>');
224 if ($i == 0) {
225 echo __("Outer Ring:");
226 } else {
227 echo __("Inner Ring"); echo($i . ':');
230 $no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points']) ? $gis_data[$a][$type][$k][$i]['no_of_points'] : 3;
231 if ($no_of_points < 3) {
232 $no_of_points = 3;
234 if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
235 $no_of_points++;
237 echo('<input type="hidden" name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">');
239 for ($j = 0; $j < $no_of_points; $j++) {
240 echo('<br/>'); echo __("Point"); echo($j + 1 . ':');
241 ?> <label for="x"><?php echo __("X"); ?></label>
242 <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']) : ''); ?>" />
243 <label for="y"><?php echo __("Y"); ?></label>
244 <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']) : ''); ?>" />
245 <?php }
246 ?> <input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][" . $i . "][add_point]"); ?>" value="<?php echo __("Add a point"); ?>">
247 <?php }
248 ?> <br/><input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][add_line]"); ?>" value="<?php echo __('Add an inner ring') ?>">
249 <?php }
250 ?> <br/><br/><input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][add_polygon]"); ?>" value="<?php echo __('Add a polygon') ?>">
251 <?php }
253 if ($geom_type == 'GEOMETRYCOLLECTION') {
254 ?> <br/><br/><input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]" value="<?php echo __("Add geometry"); ?>" />
255 <?php }
257 </div>
258 <br/><input type="submit" name="gis_data[save]" value="<?php echo __('Go') ?>">
259 <div id="gis_data_output">
260 <h3><?php echo __('Output'); ?></h3>
261 <p><?php echo __('Chose "GeomFromText" from the "Function" column and paste the below string into the "Value" field'); ?></p>
262 <textarea id="gis_data_textarea" cols="95" rows="5">
263 <?php echo("'" . $wkt . "'");
264 if ($srid != '') {
265 echo(',' . $srid);
267 ?> </textarea>
268 </div>
269 </div>
270 </form>
271 </body>
272 <?php
274 * Displays the footer
276 require './libraries/footer.inc.php';