Translation update done using Pootle.
[phpmyadmin/madhuracj.git] / tbl_gis_visualization.php
blob16cc379d110e350e601e25e38cd829fe06eb1962
1 <?php
2 /**
3 * handles creation of the GIS visualizations.
5 * @package PhpMyAdmin
6 */
8 /**
9 * do not import request variable into global scope
10 * @ignore
12 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
13 define('PMA_NO_VARIABLES_IMPORT', true);
16 require_once './libraries/common.inc.php';
18 $GLOBALS['js_include'][] = 'openlayers/OpenLayers.js';
19 $GLOBALS['js_include'][] = 'jquery/jquery.svg.js';
20 $GLOBALS['js_include'][] = 'jquery/jquery.mousewheel.js';
21 $GLOBALS['js_include'][] = 'jquery/jquery.event.drag-2.0.min.js';
22 $GLOBALS['js_include'][] = 'tbl_gis_visualization.js';
23 $GLOBALS['js_include'][] = 'OpenStreetMap.js';
25 // Allows for resending headers even after sending some data
26 ob_start();
28 // Runs common work
29 require_once './libraries/db_common.inc.php';
30 $url_params['goto'] = $cfg['DefaultTabDatabase'];
31 $url_params['back'] = 'sql.php';
33 // Import visualization functions
34 require_once './libraries/gis_visualization.lib.php';
36 // Execute the query and return the result
37 $result = PMA_DBI_try_query($sql_query);
38 // Get the meta data of results
39 $meta = PMA_DBI_get_fields_meta($result);
41 // Find the candidate fields for label column and spatial column
42 $labelCandidates = array(); $spatialCandidates = array();
43 foreach ($meta as $column_meta) {
44 if ($column_meta->type == 'geometry') {
45 $spatialCandidates[] = $column_meta->name;
46 } else {
47 $labelCandidates[] = $column_meta->name;
51 // Get settings if any posted
52 $visualizationSettings = array();
53 if (PMA_isValid($_REQUEST['visualizationSettings'], 'array')) {
54 $visualizationSettings = $_REQUEST['visualizationSettings'];
57 if (! isset($visualizationSettings['labelColumn']) && isset($labelCandidates[0])) {
58 $visualizationSettings['labelColumn'] = '';
61 // If spatial column is not set, use first geometric colum as spatial column
62 if (! isset($visualizationSettings['spatialColumn'])) {
63 $visualizationSettings['spatialColumn'] = $spatialCandidates[0];
66 // Convert geometric columns from bytes to text.
67 $modified_query = PMA_GIS_modifyQuery($sql_query, $visualizationSettings);
68 $modified_result = PMA_DBI_try_query($modified_query);
70 $data = array();
71 while ($row = PMA_DBI_fetch_assoc($modified_result)) {
72 $data[] = $row;
75 // If all the rows contain SRID, use OpenStreetMaps on the initial loading.
76 if (! isset($_REQUEST['displayVisualization'])) {
77 $visualizationSettings['choice'] = 'useBaseLayer';
78 foreach ($data as $row) {
79 if ($row['srid'] == 0) {
80 unset($visualizationSettings['choice']);
81 break;
86 if (isset($_REQUEST['saveToFile'])) {
87 $file_name = $_REQUEST['fileName'];
88 if ($file_name == '') {
89 $file_name = $visualizationSettings['spatialColumn'];
92 $save_format = $_REQUEST['fileFormat'];
93 PMA_GIS_saveToFile($data, $visualizationSettings, $save_format, $file_name);
94 exit();
97 $svg_support = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8) ? false : true;
98 $format = $svg_support ? 'svg' : 'png';
100 // get the chart and settings after chart generation
101 $visualization = PMA_GIS_visualizationResults($data, $visualizationSettings, $format);
104 * Displays the page
107 <!-- Display visulalization options -->
108 <div id="div_view_options">
109 <form method="post" action="tbl_gis_visualization.php">
110 <?php echo PMA_generate_common_hidden_inputs($url_params); ?>
111 <fieldset>
112 <legend><?php echo __('Display GIS Visualization'); ?></legend>
113 <div id="placeholder" style="width:<?php echo($visualizationSettings['width']); ?>px;height:<?php echo($visualizationSettings['height']); ?>px;">
114 <?php echo $visualization; ?>
115 </div>
116 <div id="openlayersmap"></div>
117 <input type="hidden" id="pmaThemeImage" value="<?php echo($GLOBALS['pmaThemeImage']); ?>" />
119 <script language="javascript" type="text/javascript">
120 function drawOpenLayers() {
121 <?php echo (PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol')); ?>
123 </script>
125 <input type="hidden" name="sql_query" id="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
127 <table class="gis_table">
128 <tr><td><label for="width"><?php echo __("Width"); ?></label></td>
129 <td><input type="text" name="visualizationSettings[width]" id="width" value="<?php echo (isset($visualizationSettings['width']) ? htmlspecialchars($visualizationSettings['width']) : ''); ?>" /></td>
130 </tr>
132 <tr><td><label for="height"><?php echo __("Height"); ?></label></td>
133 <td><input type="text" name="visualizationSettings[height]" id="height" value="<?php echo (isset($visualizationSettings['height']) ? htmlspecialchars($visualizationSettings['height']) : ''); ?>" /></td>
134 </tr>
136 <tr><td><label for="labelColumn"><?php echo __("Label column"); ?></label></td>
137 <td><select name="visualizationSettings[labelColumn]" id="labelColumn">
138 <option value=""><?php echo __("-- None --"); ?></option>
139 <?php
140 foreach ($labelCandidates as $labelCandidate) {
141 echo('<option value="' . htmlspecialchars($labelCandidate) . '"');
142 if ($labelCandidate == $visualizationSettings['labelColumn']) {
143 echo(' selected="selected"');
145 echo('>' . htmlspecialchars($labelCandidate) . '</option>');
148 </select></td>
149 </tr>
151 <tr><td><label for="spatial Column"><?php echo __("Spatial column"); ?></label></td>
152 <td><select name="visualizationSettings[spatialColumn]" id="spatialColumn">
153 <?php
154 foreach ($spatialCandidates as $spatialCandidate) {
155 echo('<option value="' . htmlspecialchars($spatialCandidate) . '"');
156 if ($spatialCandidate == $visualizationSettings['spatialColumn']) {
157 echo(' selected="selected"');
159 echo('>' . htmlspecialchars($spatialCandidate) . '</option>');
162 </select></td>
163 </tr>
164 <tr><td class="choice" colspan="2">
165 <input type="checkbox" name="visualizationSettings[choice]" id="choice" value="useBaseLayer"
166 <?php
167 if (isset($visualizationSettings['choice'])) {
168 echo(' checked="checked"');
172 <label for="choice"><?php echo __("Use OpenStreetMaps as Base Layer"); ?></label>
173 </td></tr>
174 <tr><td></td>
175 <td class="button"><input type="submit" name="displayVisualization" value="<?php echo __('Redraw'); ?>" /></td>
176 </tr>
177 <tr><td class="save"><?php echo __("Save to file"); ?></td></tr>
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
186 if ($svg_support) {
187 echo ('<option value="svg" selected="selected">SVG</option>');
190 </select></td>
191 </tr>
192 <tr><td></td>
193 <td class="button"><input type="submit" name="saveToFile" value="<?php echo __('Save'); ?>" /></td>
194 </tr>
195 </table>
196 </fieldset>
197 </form>
198 </div>
199 <?php
201 * Displays the footer
203 require './libraries/footer.inc.php';