1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* handles creation of the GIS visualizations.
*
* @package PhpMyAdmin
*/
require_once 'libraries/common.inc.php';
// Runs common work
require_once 'libraries/db_common.inc.php';
$url_params['goto'] = $cfg['DefaultTabDatabase'];
$url_params['back'] = 'sql.php';
// Import visualization functions
require_once 'libraries/tbl_gis_visualization.lib.php';
$response = PMA_Response::getInstance();
// Throw error if no sql query is set
if (! isset($sql_query) || $sql_query == '') {
$response->isSuccess(false);
$response->addHTML(
PMA_Message::error(__('No SQL query was set to fetch data.'))
);
exit;
}
// Execute the query and return the result
$result = $GLOBALS['dbi']->tryQuery($sql_query);
// Get the meta data of results
$meta = $GLOBALS['dbi']->getFieldsMeta($result);
// Find the candidate fields for label column and spatial column
$labelCandidates = array(); $spatialCandidates = array();
foreach ($meta as $column_meta) {
if ($column_meta->type == 'geometry') {
$spatialCandidates[] = $column_meta->name;
} else {
$labelCandidates[] = $column_meta->name;
}
}
// Get settings if any posted
$visualizationSettings = array();
if (PMA_isValid($_REQUEST['visualizationSettings'], 'array')) {
$visualizationSettings = $_REQUEST['visualizationSettings'];
}
if (! isset($visualizationSettings['labelColumn']) && isset($labelCandidates[0])) {
$visualizationSettings['labelColumn'] = '';
}
// If spatial column is not set, use first geometric column as spatial column
if (! isset($visualizationSettings['spatialColumn'])) {
$visualizationSettings['spatialColumn'] = $spatialCandidates[0];
}
// Convert geometric columns from bytes to text.
$modified_query = PMA_GIS_modifyQuery($sql_query, $visualizationSettings);
$modified_result = $GLOBALS['dbi']->tryQuery($modified_query);
$data = array();
while ($row = $GLOBALS['dbi']->fetchAssoc($modified_result)) {
$data[] = $row;
}
if (isset($_REQUEST['saveToFile'])) {
$response->disable();
$file_name = $visualizationSettings['spatialColumn'];
$save_format = $_REQUEST['fileFormat'];
PMA_GIS_saveToFile($data, $visualizationSettings, $save_format, $file_name);
exit();
}
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('openlayers/OpenLayers.js');
$scripts->addFile('jquery/jquery.svg.js');
$scripts->addFile('tbl_gis_visualization.js');
$scripts->addFile('OpenStreetMap.js');
// If all the rows contain SRID, use OpenStreetMaps on the initial loading.
if (! isset($_REQUEST['displayVisualization'])) {
$visualizationSettings['choice'] = 'useBaseLayer';
foreach ($data as $row) {
if ($row['srid'] == 0) {
unset($visualizationSettings['choice']);
break;
}
}
}
$svg_support = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8)
? false : true;
$format = $svg_support ? 'svg' : 'png';
// get the chart and settings after chart generation
$visualization = PMA_GIS_visualizationResults(
$data, $visualizationSettings, $format
);
/**
* Displays the page
*/
$html = PMA_getHtmlForGisVisualization(
$url_params, $labelCandidates, $spatialCandidates,
$visualizationSettings, $sql_query, $visualization, $svg_support,
$data
);
$response->addHTML($html);
?>
|