private function _getResultsOperations($displayParts, $analyzed_sql_results, $only_view = false)
{
global $printview;
$results_operations_html = '';
$fields_meta = $this->__get('fields_meta');
// To safe use in foreach
$header_shown = false;
$header = '<fieldset class="print_ignore" ><legend>' . __('Query results operations') . '</legend>';
$_url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'printview' => '1', 'sql_query' => $this->__get('sql_query'));
$url_query = URL::getCommon($_url_params);
if (!$header_shown) {
$results_operations_html .= $header;
$header_shown = true;
}
// if empty result set was produced we need to
// show only view and not other options
if ($only_view) {
$results_operations_html .= $this->_getLinkForCreateView($analyzed_sql_results, $url_query);
if ($header_shown) {
$results_operations_html .= '</fieldset><br />';
}
return $results_operations_html;
}
// Displays "printable view" link if required
if ($displayParts['pview_lnk'] == '1') {
$results_operations_html .= $this->_getPrintviewLinks();
$results_operations_html .= $this->_getCopytoclipboardLinks();
}
// end displays "printable view"
// Export link
// (the url_query has extra parameters that won't be used to export)
// (the single_table parameter is used in PMA_getExportDisplay()
// to hide the SQL and the structure export dialogs)
// If the parser found a PROCEDURE clause
// (most probably PROCEDURE ANALYSE()) it makes no sense to
// display the Export link).
if ($analyzed_sql_results['querytype'] == self::QUERY_TYPE_SELECT && !isset($printview) && empty($analyzed_sql_results['procedure'])) {
if (count($analyzed_sql_results['select_tables']) == 1) {
$_url_params['single_table'] = 'true';
}
if (!$header_shown) {
$results_operations_html .= $header;
$header_shown = true;
}
$_url_params['unlim_num_rows'] = $this->__get('unlim_num_rows');
/**
* At this point we don't know the table name; this can happen
* for example with a query like
* SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
* As a workaround we set in the table parameter the name of the
* first table of this database, so that tbl_export.php and
* the script it calls do not fail
*/
if (empty($_url_params['table']) && !empty($_url_params['db'])) {
$_url_params['table'] = $GLOBALS['dbi']->fetchValue("SHOW TABLES");
/* No result (probably no database selected) */
if ($_url_params['table'] === false) {
unset($_url_params['table']);
}
}
$results_operations_html .= Util::linkOrButton('tbl_export.php' . URL::getCommon($_url_params), Util::getIcon('b_tblexport.png', __('Export'), true), '', true, true, '') . "\n";
// prepare chart
$results_operations_html .= Util::linkOrButton('tbl_chart.php' . URL::getCommon($_url_params), Util::getIcon('b_chart.png', __('Display chart'), true), '', true, true, '') . "\n";
// prepare GIS chart
$geometry_found = false;
// If at least one geometry field is found
foreach ($fields_meta as $meta) {
if ($meta->type == self::GEOMETRY_FIELD) {
$geometry_found = true;
break;
}
}
if ($geometry_found) {
$results_operations_html .= Util::linkOrButton('tbl_gis_visualization.php' . URL::getCommon($_url_params), Util::getIcon('b_globe.gif', __('Visualize GIS data'), true), '', true, true, '') . "\n";
}
}
// CREATE VIEW
/**
*
* @todo detect privileges to create a view
* (but see 2006-01-19 note in display_create_table.lib.php,
* I think we cannot detect db-specific privileges reliably)
* Note: we don't display a Create view link if we found a PROCEDURE clause
*/
if (!$header_shown) {
$results_operations_html .= $header;
$header_shown = true;
}
$results_operations_html .= $this->_getLinkForCreateView($analyzed_sql_results, $url_query);
if ($header_shown) {
$results_operations_html .= '</fieldset><br />';
}
return $results_operations_html;
}