From 28a91c941decd4a93b2512eb4c31d278c6fbe544 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Wed, 8 May 2013 18:49:17 +0200 Subject: [PATCH 1/3] Moved code that creates the header for the print view in to method --- libraries/sql.lib.php | 44 +++++++++++++++++++++++++++++++++++++++++++ sql.php | 30 +---------------------------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index ecea4ae4e7..3ea5da39e1 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -431,6 +431,50 @@ 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 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 f3794e01fd..f699d6608d 100644 --- a/sql.php +++ b/sql.php @@ -1009,35 +1009,7 @@ 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(); From 9c63a2b5f364bb74b1b248efbcd4b87baa3c8814 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Wed, 8 May 2013 18:50:34 +0200 Subject: [PATCH 2/3] Moved code that creates the profiling chart in to a method --- libraries/sql.lib.php | 58 +++++++++++++++++++++++++++++++++++++++++++ sql.php | 49 ++++-------------------------------- 2 files changed, 63 insertions(+), 44 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 3ea5da39e1..c664417b95 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -475,6 +475,64 @@ function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) 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 f699d6608d..10b3a7e1b5 100644 --- a/sql.php +++ b/sql.php @@ -1059,51 +1059,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 From 02076ada31b180901901103d93e0cf10526eac5f Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Wed, 8 May 2013 18:59:49 +0200 Subject: [PATCH 3/3] Fixing errors --- sql.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sql.php b/sql.php index 10b3a7e1b5..166b7b5254 100644 --- a/sql.php +++ b/sql.php @@ -1009,7 +1009,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $header = $response->getHeader(); $header->enablePrintView(); - $html_output .= PMA_getHtmlForPrintViewHeader($db, $full_sql_query, $num_rows) + $html_output .= PMA_getHtmlForPrintViewHeader( + $db, $full_sql_query, $num_rows + ); } else { $response = PMA_Response::getInstance(); $header = $response->getHeader(); @@ -1060,7 +1062,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { if (isset($profiling_results)) { // pma_token/url_query needed for chart export $token = $_SESSION[' PMA_token ']; - $url = (isset($url_query) ? $url_query : PMA_generate_common_url($db)) + $url = (isset($url_query) ? $url_query : PMA_generate_common_url($db)); $html_output .= PMA_getHtmlForProfilingChart( $url, $token, $profiling_results