2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * handles creation of the GIS visualizations.
9 require_once 'libraries/common.inc.php';
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);
24 PMA_Message
::error(__('No SQL query was set to fetch data.'))
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
;
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);
64 while ($row = PMA_DBI_fetch_assoc($modified_result)) {
68 if (isset($_REQUEST['saveToFile'])) {
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);
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']);
98 $svg_support = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
<= 8)
100 $format = $svg_support ?
'svg' : 'png';
102 // get the chart and settings after chart generation
103 $visualization = PMA_GIS_visualizationResults(
104 $data, $visualizationSettings, $format
111 <!-- Display visualization options
-->
112 <div id
="div_view_options">
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
>
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>');
135 <tr
><td
><label
for="spatial Column"><?php
echo __("Spatial column"); ?
></label
></td
>
136 <td
><select name
="visualizationSettings[spatialColumn]" id
="spatialColumn">
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>');
150 <td
class="button"><input type
="submit" name
="displayVisualizationBtn" value
="<?php echo __('Redraw'); ?>" /></td
>
153 if (! $GLOBALS['PMA_Config']->isHttps()) {
155 <tr
><td
class="choice" colspan
="2">
156 <input type
="checkbox" name
="visualizationSettings[choice]" id
="choice" value
="useBaseLayer"
158 if (isset($visualizationSettings['choice'])) {
159 echo(' checked="checked"');
163 <label
for="choice"><?php
echo __("Use OpenStreetMaps as Base Layer"); ?
></label
>
169 <input type
="hidden" name
="displayVisualization" value
="redraw">
170 <input type
="hidden" name
="sql_query" value
="<?php echo htmlspecialchars($sql_query); ?>" />
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
>
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
>
188 echo ('<option value="svg" selected="selected">SVG</option>');
194 <td
class="button"><input type
="submit" name
="saveToFileBtn" value
="<?php echo __('Download'); ?>" /></td
>
197 <input type
="hidden" name
="saveToFile" value
="download">
198 <input type
="hidden" name
="sql_query" value
="<?php echo htmlspecialchars($sql_query); ?>" />
202 <div style
="clear:both;"> 
;</div
>
204 <div id
="placeholder" style
="width:<?php echo htmlspecialchars($visualizationSettings['width']); ?>px;height:<?php echo htmlspecialchars($visualizationSettings['height']); ?>px;">
205 <?php
echo $visualization; ?
>
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()
213 if (! $GLOBALS['PMA_Config']->isHttps()) {
214 echo (PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol'));