From ce5c6e9e524f0d24cc3260a75a7f2265eb990bbc Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Tue, 9 Jul 2013 10:52:21 +0530 Subject: [PATCH 001/101] Use a drop down as only one check option can be selected. --- view_create.php | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/view_create.php b/view_create.php index af53a5550c..90f25a8841 100644 --- a/view_create.php +++ b/view_create.php @@ -56,41 +56,40 @@ if (isset($_REQUEST['createview'])) { $sql_query .= $sep . ' AS ' . $_REQUEST['view']['as']; if (isset($_REQUEST['view']['with'])) { - $options = array_intersect($_REQUEST['view']['with'], $view_with_options); - if (count($options)) { - $sql_query .= $sep . ' WITH ' . implode(' ', $options); + if (in_array($_REQUEST['view']['with'], $view_with_options)) { + $sql_query .= $sep . ' WITH ' . $_REQUEST['view']['with']; } } if ($GLOBALS['dbi']->tryQuery($sql_query)) { - + include_once './libraries/tbl_views.lib.php'; - + // If different column names defined for VIEW $view_columns = array(); if (isset($_REQUEST['view']['column_names'])) { $view_columns = explode(',', $_REQUEST['view']['column_names']); } - + $column_map = PMA_getColumnMap($_REQUEST['view']['as'], $view_columns); $pma_tranformation_data = PMA_getExistingTranformationData($GLOBALS['db']); - + if ($pma_tranformation_data !== false) { - + // SQL for store new transformation details of VIEW $new_transformations_sql = PMA_getNewTransformationDataSql( $pma_tranformation_data, $column_map, $_REQUEST['view']['name'], $GLOBALS['db'] - ); - + ); + // Store new transformations if ($new_transformations_sql != '') { $GLOBALS['dbi']->tryQuery($new_transformations_sql); } - + } unset($pma_tranformation_data); - + if ($GLOBALS['is_ajax_request'] != true) { $message = PMA_Message::success(); include './' . $cfg['DefaultTabDatabase']; @@ -103,9 +102,9 @@ if (isset($_REQUEST['createview'])) { ) ); } - + exit; - + } else { if ($GLOBALS['is_ajax_request'] != true) { $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); @@ -202,18 +201,16 @@ $htmlString .= '>' . htmlspecialchars($view['as']) . '' . 'WITH' . ''; +$htmlString .= '' - . '
'; + $htmlString .= '>' . htmlspecialchars($option) . ''; } +$htmlString .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= ''; - $html .= PMA_Util::getIcon( - 'b_bookmark.png', __('Bookmark this SQL query'), true - ); - $html .= ''; - $html .= '
'; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - $html .= '
'; - $html .= '
'; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= ''; - +function PMA_getHtmlForBookmark($disp_mode, $cfgBookmark, $sql_query, $db, $table, + $complete_query, $bkm_user +) { + if ($disp_mode[7] == '1' + && (! empty($cfgBookmark) && empty($_GET['id_bookmark'])) + && ! empty($sql_query) + ) { + $html = "\n"; + $goto = 'sql.php?' + . PMA_generate_common_url($db, $table) + . '&sql_query=' . urlencode($sql_query) + . '&id_bookmark=1'; + $bkm_sql_query = urlencode( + isset($complete_query) ? $complete_query : $sql_query + ); + $html = '
'; + $html .= PMA_generate_common_hidden_inputs(); + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= PMA_Util::getIcon( + 'b_bookmark.png', __('Bookmark this SQL query'), true + ); + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= '
'; + + } else { + $html = null; + } + return $html; } @@ -1807,13 +1828,14 @@ function PMA_sendResponseOrGetHtmlForTableMaintenance($disp_mode, $db, $message, * @param string $table_html html for the table for displaying sql * results * @param string $indexes_problems_html html for displaying errors in indexes + * @param string $bookmark_support_html html for displaying bookmark form * @param string $print_button_html html for the print button in printview * * @return string $html_output */ function PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, - $table_html, $indexes_problems_html, $print_button_html + $table_html, $indexes_problems_html, $bookmark_support_html, $print_button_html ) { //begin the sqlqueryresults div here. container div $html_output = '
'; @@ -1825,7 +1847,8 @@ function PMA_getHtmlForSqlQueryResults($previous_update_query_html, $html_output .= isset($bookmark_created_msg) ? $bookmark_created_msg->getDisplay() : ''; $html_output .= $table_html; - $html_output .= isset($indexes_problems_html) ? $index_problems_html : ''; + $html_output .= isset($indexes_problems_html) ? $indexes_problems_html : ''; + $html_output .= isset($bookmark_support_html) ? $bookmark_support_html : ''; $html_output .= isset($print_button_html) ? $print_button_html : ''; $html_output .= '
'; // end sqlqueryresults div diff --git a/sql.php b/sql.php index de0a8bf89f..f0840de860 100644 --- a/sql.php +++ b/sql.php @@ -335,31 +335,17 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($selected) ? $selected : null ); - // Bookmark support if required - if ($disp_mode[7] == '1' - && (! empty($cfg['Bookmark']) && empty($_GET['id_bookmark'])) - && ! empty($sql_query) - ) { - $bookmark_support_html = "\n"; - $goto = 'sql.php?' - . PMA_generate_common_url($db, $table) - . '&sql_query=' . urlencode($sql_query) - . '&id_bookmark=1'; - $bkm_sql_query = urlencode( - isset($complete_query) ? $complete_query : $sql_query - ); - $bookmark_support_html .= PMA_getHtmlForBookmark( - $db, $goto, $bkm_sql_query, $cfg['Bookmark']['user'] - ); - } else { - $bookmark_support_html = null; - } + $bookmark_support_html = PMA_getHtmlForBookmark($disp_mode, + isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $html_output, + $sql_limit_to_append, $err_url, $goto, $cfg['Bookmark']['user'] + ); $print_button_html = PMA_getHtmlForPrintButton(); $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, - $table_html, $indexes_problems_html, $print_button_html + $table_html, $indexes_problems_html, $bookmark_support_html, + $print_button_html ); $response->addHTML($html_output); From 419876ee4c37b9397be560042ad4955eadf736a5 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 21:03:16 +0530 Subject: [PATCH 010/101] changed method PMA_getHtmlForProfilingChart --- libraries/sql.lib.php | 225 ++++++++++++++++++++++-------------------- sql.php | 14 +-- 2 files changed, 119 insertions(+), 120 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index e132101e61..b89bfd6faa 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -426,133 +426,140 @@ function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) } /** - * Get the HTML for the profiling table and accompanying chart + * Get the HTML for the profiling table and accompanying chart if profiling is set. + * Ptherwise returns null * - * @param string $url_query the url query - * @param string $pma_token the pma token + * @param string $url_query url query + * @param string $db current database * @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) +function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) { - $profiling_stats = array( - 'total_time' => 0, - 'states' => array(), - ); - $profiling_table = ''; - - $profiling_table .= '
' . __('Profiling') . '' . "\n"; - $profiling_table .= '
'; - $profiling_table .= '

' . __('Detailed profile') . '

'; - $profiling_table .= '' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - - $chart_json = Array(); - $i = 1; - foreach ($profiling_results as $one_result) { - if (isset($profiling_stats['states'][ucwords($one_result['Status'])])) { - $profiling_stats['states'][ucwords($one_result['Status'])]['time'] - += $one_result['Duration']; - $profiling_stats['states'][ucwords($one_result['Status'])]['calls']++; - } else { - $profiling_stats['states'][ucwords($one_result['Status'])] = array( - 'total_time' => $one_result['Duration'], - 'calls' => 1, - ); - } - $profiling_stats['total_time'] += $one_result['Duration']; + if (isset($profiling_results)) { + $pma_token = $_SESSION[' PMA_token ']; + $url_query = (isset($url_query) ? $url_query : PMA_generate_common_url($db)); + + $profiling_stats = array( + 'total_time' => 0, + 'states' => array(), + ); + $profiling_table = ''; + $profiling_table .= '
' . __('Profiling') . '' . "\n"; + $profiling_table .= '
'; + $profiling_table .= '

' . __('Detailed profile') . '

'; + $profiling_table .= '
' . __('Order') - . '
' . __('State') - . PMA_Util::showMySQLDocu( - 'general-thread-states', 'general-thread-states' - ) - . '
' . __('Time') - . '
' . "\n"; $profiling_table .= ' ' . "\n"; - $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 .= '
' . $i++ . '' . ucwords($one_result['Status']) . '' - . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) - . 's
' . "\n"; - $profiling_table .= '
'; - - $profiling_table .= '
'; - $profiling_table .= '

' . __('Summary by state') . '

'; - $profiling_table .= '' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - $profiling_table .= ' ' . "\n"; - foreach ($profiling_stats['states'] as $name => $stats) { - $profiling_table .= ' ' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + + $chart_json = Array(); + $i = 1; + foreach ($profiling_results as $one_result) { + if (isset($profiling_stats['states'][ucwords($one_result['Status'])])) { + $profiling_stats['states'][ucwords($one_result['Status'])]['time'] + += $one_result['Duration']; + $profiling_stats['states'][ucwords($one_result['Status'])]['calls']++; + } else { + $profiling_stats['states'][ucwords($one_result['Status'])] = array( + 'total_time' => $one_result['Duration'], + 'calls' => 1, + ); + } + $profiling_stats['total_time'] += $one_result['Duration']; + + $profiling_table .= ' ' . "\n"; + $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 .= '
' . __('State') - . PMA_Util::showMySQLDocu( - 'general-thread-states', 'general-thread-states' - ) - . '
' . __('Total Time') - . '
' . __('% Time') - . '
' . __('Calls') - . '
' . __('ø Time') - . '
' . $name . '' - . PMA_Util::formatNumber($stats['total_time'], 3, 1) - . 's' - . PMA_Util::formatNumber( - 100 * ($stats['total_time'] / $profiling_stats['total_time']), 0, 2 + $profiling_table .= ' ' . __('Order') + . '
' . __('State') + . PMA_Util::showMySQLDocu( + 'general-thread-states', 'general-thread-states' ) + . '
' . __('Time') + . '
' . $i++ . '' . ucwords($one_result['Status']) . '' + . (PMA_Util::formatNumber($one_result['Duration'], 3, 1)) + . 's
' . "\n"; + $profiling_table .= '
'; + + $profiling_table .= '
'; + $profiling_table .= '

' . __('Summary by state') . '

'; + $profiling_table .= '' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + $profiling_table .= ' ' . "\n"; + foreach ($profiling_stats['states'] as $name => $stats) { + $profiling_table .= ' ' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= '' . "\n"; - $profiling_table .= ' ' . "\n"; - } + $profiling_table .= '' . "\n"; + $profiling_table .= '' . "\n"; + $profiling_table .= ' ' . "\n"; + } - $profiling_table .= '
' . __('State') + . PMA_Util::showMySQLDocu( + 'general-thread-states', 'general-thread-states' + ) + . '
' . __('Total Time') + . '
' . __('% Time') + . '
' . __('Calls') + . '
' . __('ø Time') + . '
' . $name . '' + . PMA_Util::formatNumber($stats['total_time'], 3, 1) + . 's' + . PMA_Util::formatNumber( + 100 * ($stats['total_time'] / $profiling_stats['total_time']), 0, 2 + ) . '%' . $stats['calls'] . '' - . PMA_Util::formatNumber($stats['total_time'] / $stats['calls'], 3, 1) - . 's
' . $stats['calls'] . '' + . PMA_Util::formatNumber($stats['total_time'] / $stats['calls'], 3, 1) + . 's
' . "\n"; + $profiling_table .= '' . "\n"; - $profiling_table .= << pma_token = '$pma_token'; url_query = '$url_query'; EOT; - $profiling_table .= "
"; - - //require_once 'libraries/chart.lib.php'; - $profiling_table .= ''; - $profiling_table .= ''; - $profiling_table .= ''; - $profiling_table .= '
' . "\n"; + $profiling_table .= ""; + //require_once 'libraries/chart.lib.php'; + $profiling_table .= ''; + $profiling_table .= ''; + $profiling_table .= ''; + $profiling_table .= '' . "\n"; + } else { + $profiling_table = null; + } return $profiling_table; } diff --git a/sql.php b/sql.php index f0840de860..b27f10ab63 100644 --- a/sql.php +++ b/sql.php @@ -304,17 +304,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($disp_message) ? $disp_message : null ); - 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)); - - $profiling_chart_html = PMA_getHtmlForProfilingChart( - $url, $token, $profiling_results - ); - } else { - $profiling_chart_html = null; - } + $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $html_output, + isset($profiling_results) ? $profiling_results : null + ); $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $disp_mode From 07cd7234cf073565263d6c0d654421e0dd01b33c Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 21:12:00 +0530 Subject: [PATCH 011/101] removed method PMA_getHtmlForPrintView and changed the method PMA_getHtmlForPrintViewHeader --- libraries/sql.lib.php | 88 ++++++++++++++++++++----------------------- sql.php | 6 ++- 2 files changed, 44 insertions(+), 50 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index b89bfd6faa..2b6570aee8 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -381,7 +381,8 @@ function PMA_getHtmlForRelationalColumnDropdown($db, $table, $column, $curr_valu } /** - * Get the HTML for the header of the page in print view + * Get the HTML for the header of the page in print view if print view is selected. + * Otherwise returns null. * * @param string $db current database * @param string $sql_query current sql query @@ -391,38 +392,46 @@ function PMA_getHtmlForRelationalColumnDropdown($db, $table, $column, $curr_valu */ function PMA_getHtmlForPrintViewHeader($db, $sql_query, $num_rows) { - $hostname = ''; - if ( $GLOBALS['cfg']['Server']['verbose']) { - $hostname = $GLOBALS['cfg']['Server']['verbose']; - } else { - $hostname = $GLOBALS['cfg']['Server']['host']; - if (! empty( $GLOBALS['cfg']['Server']['port'])) { - $hostname .= $GLOBALS['cfg']['Server']['port']; + $response = PMA_Response::getInstance(); + $header = $response->getHeader(); + if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { + PMA_Util::checkParameters(array('db', 'full_sql_query')); + $header->enablePrintView(); + $hostname = ''; + if ( $GLOBALS['cfg']['Server']['verbose']) { + $hostname = $GLOBALS['cfg']['Server']['verbose']; + } else { + $hostname = $GLOBALS['cfg']['Server']['host']; + if (! empty( $GLOBALS['cfg']['Server']['port'])) { + $hostname .= $GLOBALS['cfg']['Server']['port']; + } } + + $versions = "phpMyAdmin " . PMA_VERSION; + $versions .= " / "; + $versions .= "MySQL " . PMA_MYSQL_STR_VERSION; + + $print_view_header = ''; + $print_view_header .= "

" . __('SQL result') . "

"; + $print_view_header .= "

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

"; + }else{ + $print_view_header = null; } - - $versions = "phpMyAdmin " . PMA_VERSION; - $versions .= " / "; - $versions .= "MySQL " . PMA_MYSQL_STR_VERSION; - - $header = ''; - $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; + + return $print_view_header; } /** @@ -2043,21 +2052,4 @@ function PMA_getHtmlForPrintButton() return $print_button_html; } - -function PMA_getHtmlForPrintView($db, $full_sql_query, $num_rows) -{ - $response = PMA_Response::getInstance(); - $header = $response->getHeader(); - if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { - PMA_Util::checkParameters(array('db', 'full_sql_query')); - $header->enablePrintView(); - $print_view_html = PMA_getHtmlForPrintViewHeader( - $db, $full_sql_query, $num_rows - ); - }else{ - $print_view_html = null; - } - - return $print_view_html; -} ?> diff --git a/sql.php b/sql.php index b27f10ab63..ce0c7d2b50 100644 --- a/sql.php +++ b/sql.php @@ -295,8 +295,10 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $disp_mode = 'nnnn110111'; } - $print_view_html = PMA_getHtmlForPrintView($db, $full_sql_query, $num_rows); - $html_output .= isset($print_view_html) ? $print_view_html : ''; + $print_view_header_html = PMA_getHtmlForPrintViewHeader($db, $full_sql_query, + $num_rows + ); + $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery( isset($disp_query) ? $disp_query : null, From 4acc14051e77b5f98803550d99f1456a6411c735 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Tue, 9 Jul 2013 21:35:26 +0530 Subject: [PATCH 012/101] error corrected --- sql.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sql.php b/sql.php index ce0c7d2b50..ffadf9ba32 100644 --- a/sql.php +++ b/sql.php @@ -248,7 +248,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); - + if (isset($_REQUEST['table_maintenance'])) { $html_output .= PMA_sendResponseOrGetHtmlForTableMaintenance( isset($disp_mode) ? $disp_mode : null, $db, @@ -259,7 +259,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $querytime, $analyzed_sql_results ); } - + if (!isset($_REQUEST['printview']) || $_REQUEST['printview'] != '1') { $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); @@ -268,7 +268,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { //set a global variable and check against it in the function $GLOBALS['buffer_message'] = false; } - + // hide edit and delete links: // - for information_schema // - if the result set does not contain all the columns of a unique key @@ -289,8 +289,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // see the "PMA_setDisplayMode()" function in // libraries/DisplayResults.class.php $disp_mode = 'urdr111101'; - } - + } if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $disp_mode = 'nnnn110111'; } @@ -298,7 +297,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $print_view_header_html = PMA_getHtmlForPrintViewHeader($db, $full_sql_query, $num_rows ); - $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery( isset($disp_query) ? $disp_query : null, @@ -306,7 +304,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { isset($disp_message) ? $disp_message : null ); - $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $html_output, + $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $db, isset($profiling_results) ? $profiling_results : null ); @@ -330,12 +328,14 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { ); $bookmark_support_html = PMA_getHtmlForBookmark($disp_mode, - isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $html_output, + isset($cfg['Bookmark']) ? $cfg['Bookmark'] : '', $sql_query, $sql_limit_to_append, $err_url, $goto, $cfg['Bookmark']['user'] ); $print_button_html = PMA_getHtmlForPrintButton(); + $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; + $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, $table_html, $indexes_problems_html, $bookmark_support_html, From d5a531f7b35a50af62279008f4e209060a5f2f48 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Wed, 10 Jul 2013 11:40:33 +0530 Subject: [PATCH 013/101] Match UI style of trigger, routine etc AJAX dialogs --- js/functions.js | 3 +-- js/messages.php | 2 ++ view_create.php | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/functions.js b/js/functions.js index c83b06e319..c010a4ad77 100644 --- a/js/functions.js +++ b/js/functions.js @@ -3733,12 +3733,11 @@ function PMA_createViewDialog($this) maxWidth: 620, modal: true, buttons: buttonOptions, - title: $('legend', $(data.message)).html(), + title: PMA_messages.strCreateView, close: function () { $(this).remove(); } }); - $dialog.find('legend').remove(); // Attach syntax highlited editor if (typeof CodeMirror !== 'undefined') { var $elm = $dialog.find('textarea'); diff --git a/js/messages.php b/js/messages.php index fb103a1859..445901bdd4 100644 --- a/js/messages.php +++ b/js/messages.php @@ -376,6 +376,8 @@ $js_messages['strNewerVersion'] = __('A newer version of phpMyAdmin is available $js_messages['strLatestAvailable'] = __(', latest stable version:'); $js_messages['strUpToDate'] = __('up to date'); +$js_messages['strCreateView'] = __('Create view'); + echo "var PMA_messages = new Array();\n"; foreach ($js_messages as $name => $js_message) { diff --git a/view_create.php b/view_create.php index 90f25a8841..a79a190791 100644 --- a/view_create.php +++ b/view_create.php @@ -148,8 +148,7 @@ $htmlString = '' . '
' . PMA_generate_common_hidden_inputs($url_params) . '
' - . '' . __('Create view') - . PMA_Util::showMySQLDocu('SQL-Syntax', 'CREATE_VIEW') . '' + . '' . __('Details') . '' . '' . '' . '
Date: Wed, 10 Jul 2013 14:53:54 +0530 Subject: [PATCH 014/101] Use ajax dialog for view editing --- js/functions.js | 11 +++---- js/messages.php | 2 +- libraries/structure.lib.php | 43 ++++++++++++++++-------- view_create.php | 66 ++++++++++++++++++++++--------------- 4 files changed, 76 insertions(+), 46 deletions(-) diff --git a/js/functions.js b/js/functions.js index c010a4ad77..65498b4451 100644 --- a/js/functions.js +++ b/js/functions.js @@ -3675,7 +3675,7 @@ function printPage() */ AJAX.registerTeardown('functions.js', function () { $('input#print').unbind('click'); - $('span a.create_view.ajax').die('click'); + $('a.create_view.ajax, a.alter_view.ajax').die('click'); $('#createViewDialog').find('input, select').die('keydown'); }); @@ -3684,7 +3684,7 @@ AJAX.registerOnload('functions.js', function () { /** * Ajaxification for the "Create View" action */ - $('span a.create_view.ajax').live('click', function (e) { + $('a.create_view.ajax, a.alter_view.ajax').live('click', function (e) { e.preventDefault(); PMA_createViewDialog($(this)); }); @@ -3704,7 +3704,7 @@ function PMA_createViewDialog($this) { var $msg = PMA_ajaxShowMessage(); var syntaxHighlighter = null; - $.get($this.attr('href') + '&ajax_request=1', function (data) { + $.get($this.attr('href') + '&ajax_request=1&ajax_dialog=1', function (data) { if (data.success === true) { PMA_ajaxRemoveMessage($msg); var buttonOptions = {}; @@ -3729,11 +3729,10 @@ function PMA_createViewDialog($this) }; var $dialog = $('
').attr('id', 'createViewDialog').append(data.message).dialog({ width: 500, - minWidth: 300, - maxWidth: 620, + minWidth: 400, modal: true, buttons: buttonOptions, - title: PMA_messages.strCreateView, + title: $this.is('.create_view') ? PMA_messages.strCreateView : PMA_messages.strEditView, close: function () { $(this).remove(); } diff --git a/js/messages.php b/js/messages.php index 445901bdd4..3df253a468 100644 --- a/js/messages.php +++ b/js/messages.php @@ -377,7 +377,7 @@ $js_messages['strLatestAvailable'] = __(', latest stable version:'); $js_messages['strUpToDate'] = __('up to date'); $js_messages['strCreateView'] = __('Create view'); - +$js_messages['strEditView'] = __('Edit view'); echo "var PMA_messages = new Array();\n"; foreach ($js_messages as $name => $js_message) { diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 8bec377eee..035be91303 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1449,19 +1449,36 @@ function PMA_getHtmlDivForMoveColumnsDialog() */ function PMA_getHtmlForEditView($url_params) { - $create_view = $GLOBALS['dbi']->getDefinition( - $GLOBALS['db'], 'VIEW', $GLOBALS['table'] + $retval = array(); + $query = "SELECT `VIEW_DEFINITION`, `CHECK_OPTION`" + . " FROM `INFORMATION_SCHEMA`.`VIEWS`" + . " WHERE TABLE_SCHEMA='" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "'" + . " AND TABLE_NAME='" . PMA_Util::sqlAddSlashes($GLOBALS['table']) . "';"; + $item = $GLOBALS['dbi']->fetchSingleRow($query); + + $view = array( + 'operation' => 'alter', + 'name' => $GLOBALS['table'], + 'as' => $item['VIEW_DEFINITION'], + 'with' => $item['CHECK_OPTION'], + ); + $url = 'view_create.php' . PMA_generate_common_url($url_params) . '&'; + $url .= implode( + '&', + array_map( + function($key, $val) { + return 'view[' . urlencode($key) . ']=' . urlencode($val); + }, + array_keys($view), + $view + ) ); - $create_view = preg_replace('@^CREATE@', 'ALTER', $create_view); $html_output = PMA_Util::linkOrButton( - 'tbl_sql.php' . PMA_generate_common_url( - $url_params + - array( - 'sql_query' => $create_view, - 'show_query' => '1', - ) - ), - PMA_Util::getIcon('b_edit.png', __('Edit view'), true) + $url, + PMA_Util::getIcon('b_edit.png', __('Edit view'), true), + array( + 'class' => 'alter_view ajax' + ) ); return $html_output; } @@ -1722,10 +1739,10 @@ function getHtmlForRowStatsTable($showtable, $tbl_collation, && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0 ) { - list($avg_row_length_value, $avg_row_length_unit) + list($avg_row_length_value, $avg_row_length_unit) = PMA_Util::formatByteDown( $showtable['Avg_row_length'], - 6, + 6, 1 ); $html_output .= PMA_getHtmlForRowStatsTableRow( diff --git a/view_create.php b/view_create.php index a79a190791..d46c5c328c 100644 --- a/view_create.php +++ b/view_create.php @@ -27,20 +27,23 @@ $view_algorithm_options = array( ); $view_with_options = array( - 'CASCADED CHECK OPTION', - 'LOCAL CHECK OPTION' + 'CASCADED', + 'LOCAL' ); -if (isset($_REQUEST['createview'])) { +if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { /** * Creates the view */ $sep = "\r\n"; - $sql_query = 'CREATE'; - - if (isset($_REQUEST['view']['or_replace'])) { - $sql_query .= ' OR REPLACE'; + if (isset($_REQUEST['createview'])) { + $sql_query = 'CREATE'; + if (isset($_REQUEST['view']['or_replace'])) { + $sql_query .= ' OR REPLACE'; + } + } else { + $sql_query = 'ALTER'; } if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) { @@ -90,7 +93,7 @@ if (isset($_REQUEST['createview'])) { } unset($pma_tranformation_data); - if ($GLOBALS['is_ajax_request'] != true) { + if (! isset($_REQUEST['ajax_dialog'])) { $message = PMA_Message::success(); include './' . $cfg['DefaultTabDatabase']; } else { @@ -106,7 +109,7 @@ if (isset($_REQUEST['createview'])) { exit; } else { - if ($GLOBALS['is_ajax_request'] != true) { + if (! isset($_REQUEST['ajax_dialog'])) { $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } else { $response = PMA_Response::getInstance(); @@ -125,12 +128,13 @@ if (isset($_REQUEST['createview'])) { // prefill values if not already filled from former submission $view = array( + 'operation' => 'create', 'or_replace' => '', 'algorithm' => '', 'name' => '', 'column_names' => '', 'as' => $sql_query, - 'with' => array(), + 'with' => '', ); if (PMA_isValid($_REQUEST['view'], 'array')) { @@ -148,17 +152,23 @@ $htmlString = '' . '' . PMA_generate_common_hidden_inputs($url_params) . '
' - . '' . __('Details') . '' - . '' - . '' - . '' - . ''; + $htmlString .= ' value="1" />'; } $htmlString .= '' . '' . '' - . '' - . '' - . '' - . '' - . '' + . ''; + +$htmlString .= '' + . ''; + +$htmlString .= '' . '' - . '' - . '' + . ''; + +$htmlString .= '' + . ''; + +$htmlString .= '' + . ''; + +$htmlString .= '' . '' - . '' - . '' - . ''; -$htmlString .= '' + . ''; -$htmlString .= '' - . '' - . '
' + . (isset($_REQUEST['ajax_dialog']) ? __('Details') : ($view['operation'] == 'create' ? __('Create view') : __('Edit view'))) + . '' + . ''; + +if ($view['operation'] == 'create') { + $htmlString .= '' + . '' + . '' - . '' - . '' + +$htmlString .= '' . '' . '' . '' - . '' + . '' . '' . '
'; } -$htmlString .= ' value="1" />' - . '
WITH
WITH CHECK OPTION'; $htmlString .= '
' . ''; -if ($GLOBALS['is_ajax_request'] != true) { +if (! isset($_REQUEST['ajax_dialog'])) { $htmlString .= '
' - . '' + . '' . '
'; } else { - $htmlString .= '' - . ''; + $htmlString .= '' + . ''; } $htmlString .= '' From 18dfc07367cb22d6ff4486c3044d139e9e1131b5 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 11 Jul 2013 15:20:59 +0530 Subject: [PATCH 015/101] Add definer field --- libraries/structure.lib.php | 3 ++- view_create.php | 43 ++++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 035be91303..d11e02e492 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1450,7 +1450,7 @@ function PMA_getHtmlDivForMoveColumnsDialog() function PMA_getHtmlForEditView($url_params) { $retval = array(); - $query = "SELECT `VIEW_DEFINITION`, `CHECK_OPTION`" + $query = "SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`" . " FROM `INFORMATION_SCHEMA`.`VIEWS`" . " WHERE TABLE_SCHEMA='" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "'" . " AND TABLE_NAME='" . PMA_Util::sqlAddSlashes($GLOBALS['table']) . "';"; @@ -1458,6 +1458,7 @@ function PMA_getHtmlForEditView($url_params) $view = array( 'operation' => 'alter', + 'definer' => $item['DEFINER'], 'name' => $GLOBALS['table'], 'as' => $item['VIEW_DEFINITION'], 'with' => $item['CHECK_OPTION'], diff --git a/view_create.php b/view_create.php index d46c5c328c..10a537707c 100644 --- a/view_create.php +++ b/view_create.php @@ -50,6 +50,10 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { $sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm']; } + if (! empty($_REQUEST['view']['definer'])) { + $sql_query .= $sep . ' DEFINER ' . $_REQUEST['view']['definer']; + } + $sql_query .= $sep . ' VIEW ' . PMA_Util::backquote($_REQUEST['view']['name']); if (! empty($_REQUEST['view']['column_names'])) { @@ -131,6 +135,7 @@ $view = array( 'operation' => 'create', 'or_replace' => '', 'algorithm' => '', + 'definer' => '', 'name' => '', 'column_names' => '', 'as' => $sql_query, @@ -164,14 +169,12 @@ if ($view['operation'] == 'create') { if ($view['or_replace']) { $htmlString .= ' checked="checked"'; } - $htmlString .= ' value="1" />
' - . '
' . __('VIEW name') . '' - . '
' . __('Column names') . '
' . __('Definer') . '' + . '
' . __('Column names') . '' - . '
AS
' . __('VIEW name') . '' + . '
' . __('Column names') . '' + . '
AS' . '' - . '
WITH CHECK OPTION'; + . '
WITH CHECK OPTION'; +$htmlString .= '
' +$htmlString .= '
' . '
'; if (! isset($_REQUEST['ajax_dialog'])) { From 7e2efa97b4bb361189c75e385f2eb68701fef12d Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 11 Jul 2013 18:02:59 +0530 Subject: [PATCH 017/101] Do line wrapping for Codemirror editor --- js/functions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/functions.js b/js/functions.js index 39e9e6e944..f2923cd1b7 100644 --- a/js/functions.js +++ b/js/functions.js @@ -3740,7 +3740,7 @@ function PMA_createViewDialog($this) // Attach syntax highlited editor if (typeof CodeMirror !== 'undefined') { var $elm = $dialog.find('textarea'); - var opts = {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql"}; + var opts = {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql", lineWrapping: true}; syntaxHighlighter = CodeMirror.fromTextArea($elm[0], opts); } $('input:visible[type=text]', $dialog).first().focus(); From 846ead2f909dcbd7399c05d53131483ba3376d09 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 11 Jul 2013 18:35:09 +0530 Subject: [PATCH 018/101] Fix typos --- view_create.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/view_create.php b/view_create.php index 4c60ec2c91..88c453a5ef 100644 --- a/view_create.php +++ b/view_create.php @@ -56,7 +56,7 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { } if (! empty($_REQUEST['view']['definer'])) { - $sql_query .= $sep . ' DEFINER ' . $_REQUEST['view']['definer']; + $sql_query .= $sep . ' DEFINER = ' . $_REQUEST['view']['definer']; } if (isset($_REQUEST['view']['sql_security'])) { @@ -119,6 +119,7 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { PMA_Message::success(), $sql_query ) ); + $response->isSuccess(true); } exit; @@ -203,7 +204,7 @@ $htmlString .= '' . __('Definer') . '' . ''; $htmlString .= 'SQL SECURITY' - . '' . ''; foreach ($view_sql_security_options as $option) { $htmlString .= '