Translated using Weblate (Catalan)
[phpmyadmin.git] / tbl_gis_visualization.php
blobcdc3a40a946f7d0022c9c29af3db9cb029478d01
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 $pos = isset($_REQUEST['pos']) ? $_REQUEST['pos'] : $_SESSION['tmpval']['pos'];
61 if (isset($_REQUEST['session_max_rows'])) {
62 $rows = $_REQUEST['session_max_rows'];
63 } else {
64 if ($_SESSION['tmpval']['max_rows'] != 'all') {
65 $rows = $_SESSION['tmpval']['max_rows'];
66 } else {
67 $rows = $GLOBALS['cfg']['MaxRows'];
70 $modified_query = PMA_GIS_modifyQuery($sql_query, $visualizationSettings, $rows, $pos);
71 $modified_result = $GLOBALS['dbi']->tryQuery($modified_query);
73 $data = array();
74 while ($row = $GLOBALS['dbi']->fetchAssoc($modified_result)) {
75 $data[] = $row;
78 if (isset($_REQUEST['saveToFile'])) {
79 $response->disable();
80 $file_name = $visualizationSettings['spatialColumn'];
81 $save_format = $_REQUEST['fileFormat'];
82 PMA_GIS_saveToFile($data, $visualizationSettings, $save_format, $file_name);
83 exit();
86 $header = $response->getHeader();
87 $scripts = $header->getScripts();
88 $scripts->addFile('openlayers/OpenLayers.js');
89 $scripts->addFile('jquery/jquery.svg.js');
90 $scripts->addFile('tbl_gis_visualization.js');
91 $scripts->addFile('OpenStreetMap.js');
93 // If all the rows contain SRID, use OpenStreetMaps on the initial loading.
94 if (! isset($_REQUEST['displayVisualization'])) {
95 $visualizationSettings['choice'] = 'useBaseLayer';
96 foreach ($data as $row) {
97 if ($row['srid'] == 0) {
98 unset($visualizationSettings['choice']);
99 break;
104 $svg_support = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8)
105 ? false : true;
106 $format = $svg_support ? 'svg' : 'png';
108 // get the chart and settings after chart generation
109 $visualization = PMA_GIS_visualizationResults(
110 $data, $visualizationSettings, $format
114 * Displays the page
117 $html = PMA_getHtmlForGisVisualization(
118 $url_params, $labelCandidates, $spatialCandidates,
119 $visualizationSettings, $sql_query, $visualization, $svg_support,
120 $data
123 $response->addHTML($html);