diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index ecea4ae4e7..c664417b95 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -431,6 +431,108 @@ function PMA_getHtmlForRelationalColumnDropdown($db, $table, $column, $curr_valu return $dropdown; } +/** + * Get the HTML for the header of the page in print view + * + * @param string $db current database + * @param string $sql_query current sql query + * @param int $num_rows the number of rows in result + * + * @return string $header html for the header + */ +function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) +{ + $hostname = ''; + if ($cfg['Server']['verbose']) { + $hostname = $cfg['Server']['verbose']; + } else { + $hostname = $cfg['Server']['host']; + if (! empty($cfg['Server']['port'])) { + $hostname .= $cfg['Server']['port']; + } + } + + $versions = "phpMyAdmin " . PMA_VERSION; + $versions .= " / "; + $versions .= "MySQL " . PMA_MYSQL_STR_VERSION; + + $header .= "

" . __('SQL result') . "

"; + $header .= "

"; + $header .= "" . __('Host:') . " $hostname
"; + $header .= "" . __('Database:') . " " + . htmlspecialchars($db) . "
"; + $header .= "" . __('Generation Time:') . " " + . PMA_Util::localisedDate() . "
"; + $header .= "" . __('Generated by:') . " $versions
"; + $header .= "" . __('SQL query:') . " " + . htmlspecialchars($sql_query) . ";"; + if (isset($num_rows)) { + $header .= "
"; + $header .= "" . __('Rows:') . " $num_rows"; + } + $header .= "

"; + + return $header; +} + +/** + * Get the HTML for the profiling table and accompanying chart + * + * @param string $url_query the url query + * @param string $pma_token the pma token + * @param array $profiling_results array containing the profiling info + * + * @return string $profiling_table html for the profiling table and chart + */ +function PMA_getHtmlForProfilingChart($url_query, $pma_token, $profiling_results) +{ + $profiling_table .= ''; + + $profiling_table .= '
' . __('Profiling') . '' . "\n"; + $profiling_table .= '
'; + $profiling_table .= '' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + + $chart_json = Array(); + foreach ($profiling_results as $one_result) { + $profiling_table .= ' ' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; + if (isset($chart_json[ucwords($one_result['Status'])])) { + $chart_json[ucwords($one_result['Status'])] + += $one_result['Duration']; + } else { + $chart_json[ucwords($one_result['Status'])] + = $one_result['Duration']; + } + } + + $profiling_table .= '
' . __('Status') + . PMA_Util::showMySQLDocu( + 'general-thread-states', 'general-thread-states' + ) + . '' . __('Time') . '
' . ucwords($one_result['Status']) . '' + . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) + . 's
' . "\n"; + $profiling_table .= '
'; + //require_once 'libraries/chart.lib.php'; + $profiling_table .= ''; + $profiling_table .= ''; + $profiling_table .= '
' . "\n"; + + return $profiling_table; +} + /** * Get the HTML for the enum column dropdown * During grid edit, if we have a enum field, returns the html for the diff --git a/sql.php b/sql.php index 0daeae4c5d..7f03feef3a 100644 --- a/sql.php +++ b/sql.php @@ -1015,35 +1015,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $header = $response->getHeader(); $header->enablePrintView(); - $hostname = ''; - if ($cfg['Server']['verbose']) { - $hostname = $cfg['Server']['verbose']; - } else { - $hostname = $cfg['Server']['host']; - if (! empty($cfg['Server']['port'])) { - $hostname .= $cfg['Server']['port']; - } - } - - $versions = "phpMyAdmin " . PMA_VERSION; - $versions .= " / "; - $versions .= "MySQL " . PMA_MYSQL_STR_VERSION; - - $html_output .= "

" . __('SQL result') . "

"; - $html_output .= "

"; - $html_output .= "" . __('Host:') . " $hostname
"; - $html_output .= "" . __('Database:') . " " - . htmlspecialchars($db) . "
"; - $html_output .= "" . __('Generation Time:') . " " - . PMA_Util::localisedDate() . "
"; - $html_output .= "" . __('Generated by:') . " $versions
"; - $html_output .= "" . __('SQL query:') . " " - . htmlspecialchars($full_sql_query) . ";"; - if (isset($num_rows)) { - $html_output .= "
"; - $html_output .= "" . __('Rows:') . " $num_rows"; - } - $html_output .= "

"; + $html_output .= PMA_getHtmlForPrintViewHeader( + $db, $full_sql_query, $num_rows + ); } else { $response = PMA_Response::getInstance(); $header = $response->getHeader(); @@ -1093,51 +1067,12 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { if (isset($profiling_results)) { // pma_token/url_query needed for chart export - $html_output .= ''; + $token = $_SESSION[' PMA_token ']; + $url = (isset($url_query) ? $url_query : PMA_generate_common_url($db)); - $html_output .= '
' . __('Profiling') . '' . "\n"; - $html_output .= '
'; - $html_output .= '' . "\n"; - $html_output .= ' ' . "\n"; - $html_output .= ' ' . "\n"; - $html_output .= ' ' . "\n"; - $html_output .= ' ' . "\n"; - - $chart_json = Array(); - foreach ($profiling_results as $one_result) { - $html_output .= ' ' . "\n"; - $html_output .= '' . "\n"; - $html_output .= '' . "\n"; - if (isset($chart_json[ucwords($one_result['Status'])])) { - $chart_json[ucwords($one_result['Status'])] - += $one_result['Duration']; - } else { - $chart_json[ucwords($one_result['Status'])] - = $one_result['Duration']; - } - } - - $html_output .= '
' . __('Status') - . PMA_Util::showMySQLDocu( - 'general-thread-states', 'general-thread-states' - ) - . '' . __('Time') . '
' . ucwords($one_result['Status']) . '' - . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) - . 's
' . "\n"; - $html_output .= '
'; - //require_once 'libraries/chart.lib.php'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
' . "\n"; + $html_output .= PMA_getHtmlForProfilingChart( + $url, $token, $profiling_results + ); } // Displays the results in a table