Example #1
0
// Generate parameters from value passed.
$gis_obj = PMA_GIS_Factory::factory($geom_type);
if (isset($_REQUEST['value'])) {
    $gis_data = array_merge($gis_data, $gis_obj->generateParams($_REQUEST['value']));
}
// Generate Well Known Text
$srid = isset($gis_data['srid']) && $gis_data['srid'] != '' ? htmlspecialchars($gis_data['srid']) : 0;
$wkt = $gis_obj->generateWkt($gis_data, 0);
$wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
$result = "'" . $wkt . "'," . $srid;
// Generate PNG or SVG based visualization
$format = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8 ? 'png' : 'svg';
$visualizationSettings = array('width' => 450, 'height' => 300, 'spatialColumn' => 'wkt');
$data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
$visualization = PMA_GIS_visualizationResults($data, $visualizationSettings, $format);
$open_layers = PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
// If the call is to update the WKT and visualization make an AJAX response
if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {
    $extra_data = array('result' => $result, 'visualization' => $visualization, 'openLayers' => $open_layers);
    PMA_ajaxResponse(null, true, $extra_data);
}
// If the call is to get the whole content, start buffering, skipping </head> and <body> tags
if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) {
    ob_start();
} else {
    ?>
</head>
<body>
<?php 
}
?>
    $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);
/**
 * Function to generate HTML for the GIS visualization page
 *
 * @param array   $url_params            url parameters
 * @param array   $labelCandidates       list of candidates for the label
 * @param array   $spatialCandidates     list of candidates for the spatial column
 * @param array   $visualizationSettings visualization settings
 * @param String  $sql_query             the sql query
 * @param String  $visualization         HTML and js code for the visualization
 * @param boolean $svg_support           whether svg download format is supported
 * @param array   $data                  array of visualizing data
 *
 * @return string HTML code for the GIS visualization
 */
function PMA_getHtmlForGisVisualization($url_params, $labelCandidates, $spatialCandidates, $visualizationSettings, $sql_query, $visualization, $svg_support, $data)
{
    $html = '<div id="div_view_options">';
    $html .= '<fieldset>';
    $html .= '<legend>' . __('Display GIS Visualization') . '</legend>';
    $html .= '<div style="width: 400px; float: left;">';
    $html .= '<form method="post" action="tbl_gis_visualization.php">';
    $html .= PMA_URL_getHiddenInputs($url_params);
    $html .= '<table class="gis_table">';
    $html .= PMA_getHtmlForColumn("labelColumn", $labelCandidates, $visualizationSettings);
    $html .= PMA_getHtmlForColumn("spatialColumn", $spatialCandidates, $visualizationSettings);
    $html .= '<tr><td></td>';
    $html .= '<td class="button"><input type="submit"';
    $html .= ' name="displayVisualizationBtn" value="';
    $html .= __('Redraw');
    $html .= '" /></td></tr>';
    if (!$GLOBALS['PMA_Config']->isHttps()) {
        $isSelected = isset($visualizationSettings['choice']) ? true : false;
        $html .= PMA_getHtmlForUseOpenStreetMaps($isSelected);
    }
    $html .= '</table>';
    $html .= '<input type="hidden" name="displayVisualization" value="redraw">';
    $html .= '<input type="hidden" name="sql_query" value="';
    $html .= htmlspecialchars($sql_query) . '" />';
    $html .= '</form>';
    $html .= '</div>';
    $html .= '<div  style="float:left;">';
    $html .= '<form method="post" class="disableAjax"';
    $html .= ' action="tbl_gis_visualization.php">';
    $html .= PMA_URL_getHiddenInputs($url_params);
    $html .= '<table class="gis_table">';
    $html .= '<tr><td><label for="fileName">';
    $html .= __("File name") . '</label></td>';
    $html .= '<td><input type="text" name="fileName" id="fileName" /></td></tr>';
    $html .= '<tr><td><label for="fileFormat">';
    $html .= __("Format") . '</label></td>';
    $html .= '<td><select name="fileFormat" id="fileFormat">';
    $html .= '<option value="png">PNG</option>';
    $html .= '<option value="pdf">PDF</option>';
    if ($svg_support) {
        $html .= '<option value="svg" selected="selected">SVG</option>';
    }
    $html .= '</select></td></tr>';
    $html .= '<tr><td></td>';
    $html .= '<td class="button"><input type="submit" name="saveToFileBtn" value="';
    $html .= __('Download') . '" /></td></tr>';
    $html .= '</table>';
    $html .= '<input type="hidden" name="saveToFile" value="download">';
    $html .= '<input type="hidden" name="sql_query" value="';
    $html .= htmlspecialchars($sql_query) . '" />';
    $html .= '</form>';
    $html .= '</div>';
    $html .= '<div style="clear:both;">&nbsp;</div>';
    $html .= '<div id="placeholder" style="width:';
    $html .= htmlspecialchars($visualizationSettings['width']) . 'px;height:';
    $html .= htmlspecialchars($visualizationSettings['height']) . 'px;">';
    $html .= $visualization;
    $html .= '</div>';
    $html .= '<div id="openlayersmap"></div>';
    $html .= '<input type="hidden" id="pmaThemeImage" value="';
    $html .= $GLOBALS['pmaThemeImage'] . '" />';
    $html .= '<script language="javascript" type="text/javascript">';
    $html .= 'function drawOpenLayers()';
    $html .= '{';
    if (!$GLOBALS['PMA_Config']->isHttps()) {
        $html .= PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
    }
    $html .= '}';
    $html .= '</script>';
    $html .= '</fieldset>';
    $html .= '</div>';
    return $html;
}
/**
 * Function to generate HTML for the GIS visualization page
 *
 * @param array   $url_params            url parameters
 * @param array   $labelCandidates       list of candidates for the label
 * @param array   $spatialCandidates     list of candidates for the spatial column
 * @param array   $visualizationSettings visualization settings
 * @param String  $sql_query             the sql query
 * @param String  $visualization         HTML and js code for the visualization
 * @param boolean $svg_support           whether svg download format is supported
 * @param array   $data                  array of visualizing data
 *
 * @return string HTML code for the GIS visualization
 */
function PMA_getHtmlForGisVisualization($url_params, $labelCandidates, $spatialCandidates, $visualizationSettings, $sql_query, $visualization, $svg_support, $data)
{
    $html = '<div id="div_view_options">';
    $html .= '<fieldset>';
    $html .= '<legend>' . __('Display GIS Visualization') . '</legend>';
    $html .= '<div id="gis_div" style="position:relative;">';
    $html .= '<form method="post" action="tbl_gis_visualization.php">';
    $html .= PMA_URL_getHiddenInputs($url_params);
    $html .= PMA_getHtmlForSelect("labelColumn", $labelCandidates, $visualizationSettings);
    $html .= PMA_getHtmlForSelect("spatialColumn", $spatialCandidates, $visualizationSettings);
    $html .= '<input type="hidden" name="displayVisualization" value="redraw">';
    $html .= '<input type="hidden" name="sql_query" value="';
    $html .= htmlspecialchars($sql_query) . '" />';
    $html .= '</form>';
    if (!$GLOBALS['PMA_Config']->isHttps()) {
        $isSelected = isset($visualizationSettings['choice']) ? true : false;
        $html .= PMA_getHtmlForUseOpenStreetMaps($isSelected);
    }
    $html .= '<div class="pma_quick_warp" style="width: 50px; position: absolute;' . ' right: 0; top: 0; cursor: pointer;">';
    $html .= '<div class="drop_list">';
    $html .= '<span class="drop_button" style="padding: 0; border: 0;">';
    $html .= PMA_Util::getImage('b_saveimage', __('Save'));
    $html .= '</span>';
    $url_params['sql_query'] = $sql_query;
    $url_params['saveToFile'] = 'download';
    $url = 'tbl_gis_visualization.php' . PMA_URL_getCommon($url_params);
    $html .= '<ul>';
    $html .= PMA_getHtmlForGisDownloadLink($url, 'png', 'PNG');
    $html .= PMA_getHtmlForGisDownloadLink($url, 'pdf', 'PDF');
    if ($svg_support) {
        $html .= PMA_getHtmlForGisDownloadLink($url, 'svg', 'SVG');
    }
    $html .= '</ul>';
    $html .= '</div></div>';
    $html .= '</div>';
    $html .= '<div style="clear:both;">&nbsp;</div>';
    $html .= '<div id="placeholder" style="width:';
    $html .= htmlspecialchars($visualizationSettings['width']) . 'px;height:';
    $html .= htmlspecialchars($visualizationSettings['height']) . 'px;">';
    $html .= $visualization;
    $html .= '</div>';
    $html .= '<div id="openlayersmap"></div>';
    $html .= '<input type="hidden" id="pmaThemeImage" value="';
    $html .= $GLOBALS['pmaThemeImage'] . '" />';
    $html .= '<script language="javascript" type="text/javascript">';
    $html .= 'function drawOpenLayers()';
    $html .= '{';
    if (!$GLOBALS['PMA_Config']->isHttps()) {
        $html .= PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
    }
    $html .= '}';
    $html .= '</script>';
    $html .= '</fieldset>';
    $html .= '</div>';
    return $html;
}
<!-- Display visulalization options -->
<div id="div_view_options">
<form method="post" action="tbl_gis_visualization.php">
<?php echo PMA_generate_common_hidden_inputs($url_params); ?>
<fieldset>
    <legend><?php echo __('Display GIS Visualization'); ?></legend>
    <div id="placeholder" style="width:<?php echo($visualizationSettings['width']); ?>px;height:<?php echo($visualizationSettings['height']); ?>px;">
        <?php echo $visualization; ?>
    </div>
    <div id="openlayersmap"></div>
    <input type="hidden" id="pmaThemeImage" value="<?php echo($GLOBALS['pmaThemeImage']); ?>" />

    <script language="javascript" type="text/javascript">
        function drawOpenLayers()
        {
            <?php echo (PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol')); ?>
        }
    </script>

    <input type="hidden" name="sql_query" id="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />

    <table class="gis_table">
    <tr><td><label for="width"><?php echo __("Width"); ?></label></td>
        <td><input type="text" name="visualizationSettings[width]" id="width" value="<?php echo (isset($visualizationSettings['width']) ? htmlspecialchars($visualizationSettings['width']) : ''); ?>" /></td>
    </tr>

    <tr><td><label for="height"><?php echo __("Height"); ?></label></td>
        <td><input type="text" name="visualizationSettings[height]" id="height" value="<?php echo (isset($visualizationSettings['height']) ? htmlspecialchars($visualizationSettings['height']) : ''); ?>" /></td>
    </tr>

    <tr><td><label for="labelColumn"><?php echo __("Label column"); ?></label></td>
    <div style="clear:both;">&nbsp;</div>

    <div id="placeholder" style="width:<?php 
echo htmlspecialchars($visualizationSettings['width']);
?>
px;height:<?php 
echo htmlspecialchars($visualizationSettings['height']);
?>
px;">
        <?php 
echo $visualization;
?>
    </div>
    <div id="openlayersmap"></div>
    <input type="hidden" id="pmaThemeImage" value="<?php 
echo $GLOBALS['pmaThemeImage'];
?>
" />
    <script language="javascript" type="text/javascript">
        function drawOpenLayers()
        {
            <?php 
if (!$GLOBALS['PMA_Config']->isHttps()) {
    echo PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
}
?>
        }
    </script>
</fieldset>
</div>