Translated using Weblate (Hungarian)
[phpmyadmin.git] / tbl_gis_visualization.php
blob3448ba103ce6e1652a73bcdac2b08f792620ceac
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/tbl_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 = $GLOBALS['dbi']->tryQuery($sql_query);
31 // Get the meta data of results
32 $meta = $GLOBALS['dbi']->getFieldsMeta($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 column 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 = $GLOBALS['dbi']->tryQuery($modified_query);
63 $data = array();
64 while ($row = $GLOBALS['dbi']->fetchAssoc($modified_result)) {
65 $data[] = $row;
68 if (isset($_REQUEST['saveToFile'])) {
69 $response->disable();
70 $file_name = $visualizationSettings['spatialColumn'];
71 $save_format = $_REQUEST['fileFormat'];
72 PMA_GIS_saveToFile($data, $visualizationSettings, $save_format, $file_name);
73 exit();
76 $header = $response->getHeader();
77 $scripts = $header->getScripts();
78 $scripts->addFile('openlayers/OpenLayers.js');
79 $scripts->addFile('jquery/jquery.svg.js');
80 $scripts->addFile('tbl_gis_visualization.js');
81 $scripts->addFile('OpenStreetMap.js');
83 // If all the rows contain SRID, use OpenStreetMaps on the initial loading.
84 if (! isset($_REQUEST['displayVisualization'])) {
85 $visualizationSettings['choice'] = 'useBaseLayer';
86 foreach ($data as $row) {
87 if ($row['srid'] == 0) {
88 unset($visualizationSettings['choice']);
89 break;
94 $svg_support = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8)
95 ? false : true;
96 $format = $svg_support ? 'svg' : 'png';
98 // get the chart and settings after chart generation
99 $visualization = PMA_GIS_visualizationResults(
100 $data, $visualizationSettings, $format
104 * Displays the page
107 $html = PMA_getHtmlForGisVisualization(
108 $url_params, $labelCandidates, $spatialCandidates,
109 $visualizationSettings, $sql_query, $visualization, $svg_support,
110 $data
113 $response->addHTML($html);