Translated using Weblate (Korean)
[phpmyadmin.git] / tbl_gis_visualization.php
blobf27241767dc329c91990d3a25671bbef13979191
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * handles creation of the GIS visualizations.
6 * @package PhpMyAdmin
7 */
9 require_once 'libraries/common.inc.php';
11 // Runs common work
12 require_once 'libraries/db_common.inc.php';
13 $url_params['goto'] = $cfg['DefaultTabDatabase'];
14 $url_params['back'] = 'sql.php';
16 // Import visualization functions
17 require_once 'libraries/gis_visualization.lib.php';
19 $response = PMA_Response::getInstance();
20 // Throw error if no sql query is set
21 if (! isset($sql_query) || $sql_query == '') {
22 $response->isSuccess(false);
23 $response->addHTML(
24 PMA_Message::error(__('No SQL query was set to fetch data.'))
26 exit;
29 // Execute the query and return the result
30 $result = PMA_DBI_try_query($sql_query);
31 // Get the meta data of results
32 $meta = PMA_DBI_get_fields_meta($result);
34 // Find the candidate fields for label column and spatial column
35 $labelCandidates = array(); $spatialCandidates = array();
36 foreach ($meta as $column_meta) {
37 if ($column_meta->type == 'geometry') {
38 $spatialCandidates[] = $column_meta->name;
39 } else {
40 $labelCandidates[] = $column_meta->name;
44 // Get settings if any posted
45 $visualizationSettings = array();
46 if (PMA_isValid($_REQUEST['visualizationSettings'], 'array')) {
47 $visualizationSettings = $_REQUEST['visualizationSettings'];
50 if (! isset($visualizationSettings['labelColumn']) && isset($labelCandidates[0])) {
51 $visualizationSettings['labelColumn'] = '';
54 // If spatial column is not set, use first geometric colum as spatial column
55 if (! isset($visualizationSettings['spatialColumn'])) {
56 $visualizationSettings['spatialColumn'] = $spatialCandidates[0];
59 // Convert geometric columns from bytes to text.
60 $modified_query = PMA_GIS_modifyQuery($sql_query, $visualizationSettings);
61 $modified_result = PMA_DBI_try_query($modified_query);
63 $data = array();
64 while ($row = PMA_DBI_fetch_assoc($modified_result)) {
65 $data[] = $row;
68 if (isset($_REQUEST['saveToFile'])) {
69 $response->disable();
70 $file_name = $_REQUEST['fileName'];
71 if ($file_name == '') {
72 $file_name = $visualizationSettings['spatialColumn'];
75 $save_format = $_REQUEST['fileFormat'];
76 PMA_GIS_saveToFile($data, $visualizationSettings, $save_format, $file_name);
77 exit();
80 $header = $response->getHeader();
81 $scripts = $header->getScripts();
82 $scripts->addFile('openlayers/OpenLayers.js');
83 $scripts->addFile('jquery/jquery.svg.js');
84 $scripts->addFile('tbl_gis_visualization.js');
85 $scripts->addFile('OpenStreetMap.js');
87 // If all the rows contain SRID, use OpenStreetMaps on the initial loading.
88 if (! isset($_REQUEST['displayVisualization'])) {
89 $visualizationSettings['choice'] = 'useBaseLayer';
90 foreach ($data as $row) {
91 if ($row['srid'] == 0) {
92 unset($visualizationSettings['choice']);
93 break;
98 $svg_support = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8)
99 ? false : true;
100 $format = $svg_support ? 'svg' : 'png';
102 // get the chart and settings after chart generation
103 $visualization = PMA_GIS_visualizationResults(
104 $data, $visualizationSettings, $format
108 * Displays the page
111 <!-- Display visualization options -->
112 <div id="div_view_options">
113 <fieldset>
114 <legend><?php echo __('Display GIS Visualization'); ?></legend>
115 <div style="width: 400px; float: left;">
116 <form method="post" action="tbl_gis_visualization.php">
117 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
118 <table class="gis_table">
119 <tr><td><label for="labelColumn"><?php echo __("Label column"); ?></label></td>
120 <td><select name="visualizationSettings[labelColumn]" id="labelColumn">
121 <option value=""><?php echo __("-- None --"); ?></option>
122 <?php
124 foreach ($labelCandidates as $labelCandidate) {
125 echo('<option value="' . htmlspecialchars($labelCandidate) . '"');
126 if ($labelCandidate == $visualizationSettings['labelColumn']) {
127 echo(' selected="selected"');
129 echo('>' . htmlspecialchars($labelCandidate) . '</option>');
132 </select></td>
133 </tr>
135 <tr><td><label for="spatial Column"><?php echo __("Spatial column"); ?></label></td>
136 <td><select name="visualizationSettings[spatialColumn]" id="spatialColumn">
137 <?php
139 foreach ($spatialCandidates as $spatialCandidate) {
140 echo('<option value="' . htmlspecialchars($spatialCandidate) . '"');
141 if ($spatialCandidate == $visualizationSettings['spatialColumn']) {
142 echo(' selected="selected"');
144 echo('>' . htmlspecialchars($spatialCandidate) . '</option>');
147 </select></td>
148 </tr>
149 <tr><td></td>
150 <td class="button"><input type="submit" name="displayVisualizationBtn" value="<?php echo __('Redraw'); ?>" /></td>
151 </tr>
152 <?php
153 if (! $GLOBALS['PMA_Config']->isHttps()) {
155 <tr><td class="choice" colspan="2">
156 <input type="checkbox" name="visualizationSettings[choice]" id="choice" value="useBaseLayer"
157 <?php
158 if (isset($visualizationSettings['choice'])) {
159 echo(' checked="checked"');
163 <label for="choice"><?php echo __("Use OpenStreetMaps as Base Layer"); ?></label>
164 </td></tr>
165 <?php
168 </table>
169 <input type="hidden" name="displayVisualization" value="redraw">
170 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
171 </form>
172 </div>
174 <div style="float:left;">
175 <form method="post" class="disableAjax" action="tbl_gis_visualization.php">
176 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
177 <table class="gis_table">
178 <tr><td><label for="fileName"><?php echo __("File name"); ?></label></td>
179 <td><input type="text" name="fileName" id="fileName" /></td>
180 </tr>
181 <tr><td><label for="fileFormat"><?php echo __("Format"); ?></label></td>
182 <td><select name="fileFormat" id="fileFormat">
183 <option value="png">PNG</option>
184 <option value="pdf">PDF</option>
185 <?php
187 if ($svg_support) {
188 echo ('<option value="svg" selected="selected">SVG</option>');
191 </select></td>
192 </tr>
193 <tr><td></td>
194 <td class="button"><input type="submit" name="saveToFileBtn" value="<?php echo __('Download'); ?>" /></td>
195 </tr>
196 </table>
197 <input type="hidden" name="saveToFile" value="download">
198 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
199 </form>
200 </div>
202 <div style="clear:both;">&nbsp;</div>
204 <div id="placeholder" style="width:<?php echo htmlspecialchars($visualizationSettings['width']); ?>px;height:<?php echo htmlspecialchars($visualizationSettings['height']); ?>px;">
205 <?php echo $visualization; ?>
206 </div>
207 <div id="openlayersmap"></div>
208 <input type="hidden" id="pmaThemeImage" value="<?php echo($GLOBALS['pmaThemeImage']); ?>" />
209 <script language="javascript" type="text/javascript">
210 function drawOpenLayers()
212 <?php
213 if (! $GLOBALS['PMA_Config']->isHttps()) {
214 echo (PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol'));
218 </script>
219 </fieldset>
220 </div>