Merge pull request #351 from m0hamed/refactor

code extraction
This commit is contained in:
Michal Čihař 2013-05-08 23:40:57 -07:00
commit 26a7e60400
2 changed files with 110 additions and 73 deletions

View File

@ -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 .= "<h1>" . __('SQL result') . "</h1>";
$header .= "<p>";
$header .= "<strong>" . __('Host:') . "</strong> $hostname<br />";
$header .= "<strong>" . __('Database:') . "</strong> "
. htmlspecialchars($db) . "<br />";
$header .= "<strong>" . __('Generation Time:') . "</strong> "
. PMA_Util::localisedDate() . "<br />";
$header .= "<strong>" . __('Generated by:') . "</strong> $versions<br />";
$header .= "<strong>" . __('SQL query:') . "</strong> "
. htmlspecialchars($sql_query) . ";";
if (isset($num_rows)) {
$header .= "<br />";
$header .= "<strong>" . __('Rows:') . "</strong> $num_rows";
}
$header .= "</p>";
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 .= '<script type="text/javascript">';
$profiling_table .= 'pma_token = \'' . $pma_token . '\';';
$profiling_table .= 'url_query = \'' . $url_query . '\';';
$profiling_table .= 'AJAX.registerOnload(\'sql.js\',makeProfilingChart);';
$profiling_table .= '</script>';
$profiling_table .= '<fieldset><legend>' . __('Profiling') . '</legend>' . "\n";
$profiling_table .= '<div style="float: left;">';
$profiling_table .= '<table>' . "\n";
$profiling_table .= ' <tr>' . "\n";
$profiling_table .= ' <th>' . __('Status')
. PMA_Util::showMySQLDocu(
'general-thread-states', 'general-thread-states'
)
. '</th>' . "\n";
$profiling_table .= ' <th>' . __('Time') . '</th>' . "\n";
$profiling_table .= ' </tr>' . "\n";
$chart_json = Array();
foreach ($profiling_results as $one_result) {
$profiling_table .= ' <tr>' . "\n";
$profiling_table .= '<td>' . ucwords($one_result['Status']) . '</td>' . "\n";
$profiling_table .= '<td class="right">'
. (PMA_Util::formatNumber($one_result['Duration'], 3, 1))
. 's</td>' . "\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 .= '</table>' . "\n";
$profiling_table .= '</div>';
//require_once 'libraries/chart.lib.php';
$profiling_table .= '<div id="profilingChartData" style="display:none;">';
$profiling_table .= json_encode($chart_json);
$profiling_table .= '</div>';
$profiling_table .= '<div id="profilingchart" style="display:none;">';
$profiling_table .= '</div>';
$profiling_table .= '</fieldset>' . "\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

81
sql.php
View File

@ -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&nbsp;" . PMA_VERSION;
$versions .= "&nbsp;/&nbsp;";
$versions .= "MySQL&nbsp;" . PMA_MYSQL_STR_VERSION;
$html_output .= "<h1>" . __('SQL result') . "</h1>";
$html_output .= "<p>";
$html_output .= "<strong>" . __('Host:') . "</strong> $hostname<br />";
$html_output .= "<strong>" . __('Database:') . "</strong> "
. htmlspecialchars($db) . "<br />";
$html_output .= "<strong>" . __('Generation Time:') . "</strong> "
. PMA_Util::localisedDate() . "<br />";
$html_output .= "<strong>" . __('Generated by:') . "</strong> $versions<br />";
$html_output .= "<strong>" . __('SQL query:') . "</strong> "
. htmlspecialchars($full_sql_query) . ";";
if (isset($num_rows)) {
$html_output .= "<br />";
$html_output .= "<strong>" . __('Rows:') . "</strong> $num_rows";
}
$html_output .= "</p>";
$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 .= '<script type="text/javascript">';
$html_output .= 'pma_token = \'' . $_SESSION[' PMA_token '] . '\';';
$html_output .= 'url_query = \''
. (isset($url_query) ? $url_query : PMA_generate_common_url($db))
. '\';';
$html_output .= 'AJAX.registerOnload(\'sql.js\',makeProfilingChart);';
$html_output .= '</script>';
$token = $_SESSION[' PMA_token '];
$url = (isset($url_query) ? $url_query : PMA_generate_common_url($db));
$html_output .= '<fieldset><legend>' . __('Profiling') . '</legend>' . "\n";
$html_output .= '<div style="float: left;">';
$html_output .= '<table>' . "\n";
$html_output .= ' <tr>' . "\n";
$html_output .= ' <th>' . __('Status')
. PMA_Util::showMySQLDocu(
'general-thread-states', 'general-thread-states'
)
. '</th>' . "\n";
$html_output .= ' <th>' . __('Time') . '</th>' . "\n";
$html_output .= ' </tr>' . "\n";
$chart_json = Array();
foreach ($profiling_results as $one_result) {
$html_output .= ' <tr>' . "\n";
$html_output .= '<td>' . ucwords($one_result['Status']) . '</td>' . "\n";
$html_output .= '<td class="right">'
. (PMA_Util::formatNumber($one_result['Duration'], 3, 1))
. 's</td>' . "\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 .= '</table>' . "\n";
$html_output .= '</div>';
//require_once 'libraries/chart.lib.php';
$html_output .= '<div id="profilingChartData" style="display:none;">';
$html_output .= json_encode($chart_json);
$html_output .= '</div>';
$html_output .= '<div id="profilingchart" style="display:none;">';
$html_output .= '</div>';
$html_output .= '</fieldset>' . "\n";
$html_output .= PMA_getHtmlForProfilingChart(
$url, $token, $profiling_results
);
}
// Displays the results in a table