bug #3072495 Creating new database on Databases tab messed layout

This commit is contained in:
Marc Delisle
2010-10-11 09:34:51 -04:00
parent da339cd5ff
commit 81d61125cc
6 changed files with 227 additions and 150 deletions

View File

@@ -13,6 +13,8 @@ $GLOBALS['js_include'][] = 'functions.js';
$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js'; $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
require_once './libraries/mysql_charsets.lib.php'; require_once './libraries/mysql_charsets.lib.php';
require './libraries/replication.inc.php';
require './libraries/build_html_for_db.lib.php';
PMA_checkParameters(array('new_db')); PMA_checkParameters(array('new_db'));
@@ -30,6 +32,7 @@ if (!empty($db_collation)) {
if (in_array($db_charset, $mysql_charsets) && in_array($db_collation, $mysql_collations[$db_charset])) { if (in_array($db_charset, $mysql_charsets) && in_array($db_collation, $mysql_collations[$db_charset])) {
$sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation); $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
} }
$db_collation_for_ajax = $db_collation;
unset($db_charset, $db_collation); unset($db_charset, $db_collation);
} }
$sql_query .= ';'; $sql_query .= ';';
@@ -78,6 +81,8 @@ if (! $result) {
$db_url_params['db'] = $new_db; $db_url_params['db'] = $new_db;
$is_superuser = PMA_isSuperuser(); $is_superuser = PMA_isSuperuser();
$column_order = PMA_getColumnOrder();
$url_query = PMA_generate_common_url($new_db);
/** /**
* String that will contain the output HTML * String that will contain the output HTML
@@ -85,42 +90,34 @@ if (! $result) {
*/ */
$new_db_string = '<tr>'; $new_db_string = '<tr>';
/** if (empty($db_collation_for_ajax)) {
* Is user allowed to drop the database? $db_collation_for_ajax = PMA_getServerCollation();
*/
if ($is_superuser || $cfg['AllowUserDropDatabase']) {
$new_db_string .= '<td class="tool">';
$new_db_string .= '<input type="checkbox" title="'. $new_db .'" value="' . $new_db . '" name="selected_dbs[]" />';
$new_db_string .='</td>';
} }
/** // $dbstats comes from the create table dialog
* Link to the database's page if (! empty($dbstats)) {
*/ $current = array(
$new_db_string .= '<td class="name">'; 'SCHEMA_NAME' => $new_db,
$new_db_string .= '<a target="_parent" title="Jump to database" href="index.php' . PMA_generate_common_url($db_url_params) . '">'; 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
$new_db_string .= $new_db . '</a>'; 'SCHEMA_TABLES' => '0',
$new_db_string .= '</td>'; 'SCHEMA_TABLE_ROWS' => '0',
'SCHEMA_DATA_LENGTH' => '0',
/** 'SCHEMA_MAX_DATA_LENGTH' => '0',
* If the user has privileges, let him check privileges for the DB 'SCHEMA_INDEX_LENGTH' => '0',
*/ 'SCHEMA_LENGTH' => '0',
if($is_superuser) { 'SCHEMA_DATA_FREE' => '0'
);
$db_url_params['checkprivs'] = $new_db; } else {
$current = array(
$new_db_string .= '<td class="tool">'; 'SCHEMA_NAME' => $new_db
$new_db_string .= '<a title="Check privileges for database" href="server_privileges.php' . PMA_generate_common_url($db_url_params) . '">'; );
$new_db_string .= ($cfg['PropertiesIconic']
? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' . __('Check Privileges') . '" /> '
: __('Check Privileges')) . '</a>';
$new_db_string .= '</td>';
} }
list($column_order, $generated_html) = PMA_buildHtmlForDb($current, $is_superuser, (isset($checkall) ? $checkall : ''), $url_query, $column_order, $replication_types, $replication_info);
$new_db_string .= $generated_html;
$new_db_string .= '</tr>'; $new_db_string .= '</tr>';
/** @todo Statistics for newly created DB! */
$extra_data['new_db_string'] = $new_db_string; $extra_data['new_db_string'] = $new_db_string;
PMA_ajaxResponse($message, true, $extra_data); PMA_ajaxResponse($message, true, $extra_data);

View File

@@ -2299,10 +2299,15 @@ $(document).ready(function() {
$('#create_database_form').live('submit', function(event) { $('#create_database_form').live('submit', function(event) {
event.preventDefault(); event.preventDefault();
PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); $form = $(this);
$(this).append('<input type="hidden" name="ajax_request" value="true" />');
$.post($(this).attr('action'), $(this).serialize(), function(data) { PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.post($form.attr('action'), $form.serialize(), function(data) {
if(data.success == true) { if(data.success == true) {
PMA_ajaxShowMessage(data.message); PMA_ajaxShowMessage(data.message);
@@ -2314,6 +2319,10 @@ $(document).ready(function() {
.find('#db_summary_row') .find('#db_summary_row')
.appendTo('#tabledatabases tbody') .appendTo('#tabledatabases tbody')
.removeClass('odd even'); .removeClass('odd even');
var $databases_count_object = $('#databases_count');
var databases_count = parseInt($databases_count_object.text());
$databases_count_object.text(++databases_count);
} }
else { else {
PMA_ajaxShowMessage(data.error); PMA_ajaxShowMessage(data.error);

View File

@@ -0,0 +1,158 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
*
* @package phpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
* Prepares the $column_order array
*
* @return array
*/
function PMA_getColumnOrder() {
$column_order['DEFAULT_COLLATION_NAME'] = array(
'disp_name' => __('Collation'),
'description_function' => 'PMA_getCollationDescr',
'format' => 'string',
'footer' => PMA_getServerCollation(),
);
$column_order['SCHEMA_TABLES'] = array(
'disp_name' => __('Tables'),
'format' => 'number',
'footer' => 0,
);
$column_order['SCHEMA_TABLE_ROWS'] = array(
'disp_name' => __('Rows'),
'format' => 'number',
'footer' => 0,
);
$column_order['SCHEMA_DATA_LENGTH'] = array(
'disp_name' => __('Data'),
'format' => 'byte',
'footer' => 0,
);
$column_order['SCHEMA_INDEX_LENGTH'] = array(
'disp_name' => __('Indexes'),
'format' => 'byte',
'footer' => 0,
);
$column_order['SCHEMA_LENGTH'] = array(
'disp_name' => __('Total'),
'format' => 'byte',
'footer' => 0,
);
$column_order['SCHEMA_DATA_FREE'] = array(
'disp_name' => __('Overhead'),
'format' => 'byte',
'footer' => 0,
);
return $column_order;
}
/*
* Builds the HTML td elements for one database to display in the list
* of databases from server_databases.php (which can be modified by
* db_create.php)
*
* @param array $current
* @param boolean $is_superuser
* @param string $checkall
* @param string $url_query
* @param array $column_order
* @param array $replication_types
* @param array $replication_info
*
* @return array $column_order, $out
*/
function PMA_buildHtmlForDb($current, $is_superuser, $checkall, $url_query, $column_order, $replication_types, $replication_info) {
$out = '';
if ($is_superuser || $GLOBALS['cfg']['AllowUserDropDatabase']) {
$out .= '<td class="tool">';
$out .= '<input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ';
if ($current['SCHEMA_NAME'] != 'mysql'
&& $current['SCHEMA_NAME'] != 'information_schema') {
$out .= (empty($checkall) ? '' : 'checked="checked" ') . '/>';
} else {
$out .= ' disabled="disabled" />';
}
$out .= '</td>';
}
$out .= '<td class="name">'
. ' <a onclick="'
. 'if (window.parent.openDb &amp;&amp; window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
. '" href="index.php?' . $url_query . '&amp;db='
. urlencode($current['SCHEMA_NAME']) . '" title="'
. sprintf(__('Jump to database'), htmlspecialchars($current['SCHEMA_NAME']))
. '" target="_parent">'
. ' ' . htmlspecialchars($current['SCHEMA_NAME'])
. '</a>'
. '</td>';
foreach ($column_order as $stat_name => $stat) {
if (array_key_exists($stat_name, $current)) {
if (is_numeric($stat['footer'])) {
$column_order[$stat_name]['footer'] += $current[$stat_name];
}
if ($stat['format'] === 'byte') {
list($value, $unit) = PMA_formatByteDown($current[$stat_name], 3, 1);
} elseif ($stat['format'] === 'number') {
$value = PMA_formatNumber($current[$stat_name], 0);
} else {
$value = htmlentities($current[$stat_name], 0);
}
$out .= '<td class="value">';
if (isset($stat['description_function'])) {
$out .= '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
}
$out .= $value;
if (isset($stat['description_function'])) {
$out .= '</dfn>';
}
$out .= '</td>';
if ($stat['format'] === 'byte') {
$out .= '<td class="unit">' . $unit . '</td>';
}
}
}
foreach ($replication_types as $type) {
if ($replication_info[$type]['status']) {
$out .= '<td class="tool" style="text-align: center;">';
if (strlen(array_search($current["SCHEMA_NAME"], $replication_info[$type]['Ignore_DB'])) > 0) {
$out .= PMA_getIcon('s_cancel.png', __('Not replicated'));
} else {
$key = array_search($current["SCHEMA_NAME"], $replication_info[$type]['Do_DB']);
if (strlen($key) > 0 || ($replication_info[$type]['Do_DB'][0] == "" && count($replication_info[$type]['Do_DB']) == 1)) {
// if ($key != null) did not work for index "0"
$out .= PMA_getIcon('s_success.png', __('Replicated'));
}
}
$out .= '</td>';
}
}
if ($is_superuser) {
$out .= '<td class="tool">'
. '<a onclick="'
. 'if (window.parent.setDb) window.parent.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');'
. '" href="./server_privileges.php?' . $url_query
. '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME'])
. '" title="' . sprintf(__('Check privileges for database &quot;%s&quot;.'), htmlspecialchars($current['SCHEMA_NAME']))
. '">'
. ' '
. PMA_getIcon('s_rights.png', __('Check Privileges'))
. '</a></td>';
}
return array($column_order, $out);
}
?>

View File

@@ -25,6 +25,10 @@ if ($is_create_db_priv) {
<?php <?php
require_once './libraries/mysql_charsets.lib.php'; require_once './libraries/mysql_charsets.lib.php';
echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', null, null, TRUE, 5); echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', null, null, TRUE, 5);
if (! empty($dbstats)) {
echo '<input type="hidden" name="dbstats" value="1" />';
}
?> ?>
<input type="submit" value="<?php echo __('Create'); ?>" id="buttonGo" /> <input type="submit" value="<?php echo __('Create'); ?>" id="buttonGo" />
</form> </form>

View File

@@ -90,25 +90,46 @@ $slave_variables_oks = array(
); );
// check which replication is available and set $server_{master/slave}_status and assign values // check which replication is available and set $server_{master/slave}_status and assign values
// replication info is more easily passed to functions
/*
* @todo use $replication_info everywhere instead of the generated variable names
*/
$replication_info = array();
foreach ($replication_types as $type) { foreach ($replication_types as $type) {
if (count(${"server_{$type}_replication"}) > 0) { if (count(${"server_{$type}_replication"}) > 0) {
${"server_{$type}_status"} = true; ${"server_{$type}_status"} = true;
$replication_info[$type]['status'] = true;
} else { } else {
${"server_{$type}_status"} = false; ${"server_{$type}_status"} = false;
$replication_info[$type]['status'] = false;
} }
if (${"server_{$type}_status"}) { if (${"server_{$type}_status"}) {
if ($type == "master") { if ($type == "master") {
${"server_{$type}_Do_DB"} = explode(",", $server_master_replication[0]["Binlog_Do_DB"]); ${"server_{$type}_Do_DB"} = explode(",", $server_master_replication[0]["Binlog_Do_DB"]);
$replication_info[$type]['Do_DB'] = ${"server_{$type}_Do_DB"};
${"server_{$type}_Ignore_DB"} = explode(",", $server_master_replication[0]["Binlog_Ignore_DB"]); ${"server_{$type}_Ignore_DB"} = explode(",", $server_master_replication[0]["Binlog_Ignore_DB"]);
$replication_info[$type]['Ignore_DB'] = ${"server_{$type}_Ignore_DB"};
} elseif ($type == "slave") { } elseif ($type == "slave") {
${"server_{$type}_Do_DB"} = explode(",", $server_slave_replication[0]["Replicate_Do_DB"]); ${"server_{$type}_Do_DB"} = explode(",", $server_slave_replication[0]["Replicate_Do_DB"]);
$replication_info[$type]['Do_DB'] = ${"server_{$type}_Do_DB"};
${"server_{$type}_Ignore_DB"} = explode(",", $server_slave_replication[0]["Replicate_Ignore_DB"]); ${"server_{$type}_Ignore_DB"} = explode(",", $server_slave_replication[0]["Replicate_Ignore_DB"]);
$replication_info[$type]['Ignore_DB'] = ${"server_{$type}_Ignore_DB"};
${"server_{$type}_Do_Table"} = explode(",", $server_slave_replication[0]["Replicate_Do_Table"]); ${"server_{$type}_Do_Table"} = explode(",", $server_slave_replication[0]["Replicate_Do_Table"]);
$replication_info[$type]['Do_Table'] = ${"server_{$type}_Do_Table"};
${"server_{$type}_Ignore_Table"} = explode(",", $server_slave_replication[0]["Replicate_Ignore_Table"]); ${"server_{$type}_Ignore_Table"} = explode(",", $server_slave_replication[0]["Replicate_Ignore_Table"]);
$replication_info[$type]['Ignore_Table'] = ${"server_{$type}_Ignore_Table"};
${"server_{$type}_Wild_Do_Table"} = explode(",", $server_slave_replication[0]["Replicate_Wild_Do_Table"]); ${"server_{$type}_Wild_Do_Table"} = explode(",", $server_slave_replication[0]["Replicate_Wild_Do_Table"]);
$replication_info[$type]['Wild_Do_Table'] = ${"server_{$type}_Wild_Do_Table"};
${"server_{$type}_Wild_Ignore_Table"} = explode(",", $server_slave_replication[0]["Replicate_Wild_Ignore_Table"]); ${"server_{$type}_Wild_Ignore_Table"} = explode(",", $server_slave_replication[0]["Replicate_Wild_Ignore_Table"]);
$replication_info[$type]['Wild_Ignore_Table'] = ${"server_{$type}_Wild_Ignore_Table"};
} }
} }
} }

View File

@@ -12,6 +12,7 @@ require_once './libraries/common.inc.php';
require './libraries/server_common.inc.php'; require './libraries/server_common.inc.php';
require './libraries/replication.inc.php'; require './libraries/replication.inc.php';
require './libraries/build_html_for_db.lib.php';
/** /**
* avoids 'undefined index' errors * avoids 'undefined index' errors
@@ -118,42 +119,7 @@ if ($databases_count > 0) {
reset($databases); reset($databases);
$first_database = current($databases); $first_database = current($databases);
// table col order // table col order
$column_order['DEFAULT_COLLATION_NAME'] = array( $column_order = PMA_getColumnOrder();
'disp_name' => __('Collation'),
'description_function' => 'PMA_getCollationDescr',
'format' => 'string',
'footer' => PMA_getServerCollation(),
);
$column_order['SCHEMA_TABLES'] = array(
'disp_name' => __('Tables'),
'format' => 'number',
'footer' => 0,
);
$column_order['SCHEMA_TABLE_ROWS'] = array(
'disp_name' => __('Rows'),
'format' => 'number',
'footer' => 0,
);
$column_order['SCHEMA_DATA_LENGTH'] = array(
'disp_name' => __('Data'),
'format' => 'byte',
'footer' => 0,
);
$column_order['SCHEMA_INDEX_LENGTH'] = array(
'disp_name' => __('Indexes'),
'format' => 'byte',
'footer' => 0,
);
$column_order['SCHEMA_LENGTH'] = array(
'disp_name' => __('Total'),
'format' => 'byte',
'footer' => 0,
);
$column_order['SCHEMA_DATA_FREE'] = array(
'disp_name' => __('Overhead'),
'format' => 'byte',
'footer' => 0,
);
$_url_params = array( $_url_params = array(
'pos' => $pos, 'pos' => $pos,
@@ -223,88 +189,10 @@ if ($databases_count > 0) {
echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"; echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
$odd_row = ! $odd_row; $odd_row = ! $odd_row;
if ($is_superuser || $cfg['AllowUserDropDatabase']) { list($column_order, $generated_html) = PMA_buildHtmlForDb($current, $is_superuser, (isset($checkall) ? $checkall : ''), $url_query, $column_order, $replication_types, $replication_info);
echo ' <td class="tool">' . "\n";
if ($current['SCHEMA_NAME'] != 'mysql'
&& $current['SCHEMA_NAME'] != 'information_schema') {
echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n";
} else {
echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n";
}
echo ' </td>' . "\n";
}
echo ' <td class="name">' . "\n"
. ' <a onclick="'
. 'if (window.parent.openDb &amp;&amp; window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
. '" href="index.php?' . $url_query . '&amp;db='
. urlencode($current['SCHEMA_NAME']) . '" title="'
. sprintf(__('Jump to database'), htmlspecialchars($current['SCHEMA_NAME']))
. '" target="_parent">' . "\n"
. ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
. ' </a>' . "\n"
. ' </td>' . "\n";
foreach ($column_order as $stat_name => $stat) { echo $generated_html;
if (array_key_exists($stat_name, $current)) {
if (is_numeric($stat['footer'])) {
$column_order[$stat_name]['footer'] += $current[$stat_name];
}
if ($stat['format'] === 'byte') {
list($value, $unit) = PMA_formatByteDown($current[$stat_name], 3, 1);
} elseif ($stat['format'] === 'number') {
$value = PMA_formatNumber($current[$stat_name], 0);
} else {
$value = htmlentities($current[$stat_name], 0);
}
echo ' <td class="value">';
if (isset($stat['description_function'])) {
echo '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
}
echo $value;
if (isset($stat['description_function'])) {
echo '</dfn>';
}
echo '</td>' . "\n";
if ($stat['format'] === 'byte') {
echo ' <td class="unit">' . $unit . '</td>' . "\n";
}
}
}
foreach ($replication_types as $type) {
if (${"server_{$type}_status"}) {
echo '<td class="tool" style="text-align: center;">' . "\n";
if (strlen(array_search($current["SCHEMA_NAME"], ${"server_{$type}_Ignore_DB"}))>0) {
echo '<img class="icon" src="' . $pmaThemeImage . 's_cancel.png" width="16" height="16" alt="' . __('Not replicated') . '" />' . "\n";
} else {
$key = array_search($current["SCHEMA_NAME"], ${"server_{$type}_Do_DB"});
if (strlen($key) > 0 || (${"server_{$type}_Do_DB"}[0] == "" && count(${"server_{$type}_Do_DB"}) == 1)) {
// if ($key != null) did not work for index "0"
echo '<img class="icon" src="' . $pmaThemeImage . 's_success.png" width="16" height="16" alt="' . __('Replicated') . '" />' . "\n";
} else {
echo '';
}
}
echo '</td>';
}
}
if ($is_superuser) {
echo ' <td class="tool">' . "\n"
. ' <a onclick="'
. 'if (window.parent.setDb) window.parent.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');'
. '" href="./server_privileges.php?' . $url_query
. '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME'])
. '" title="' . sprintf(__('Check privileges for database &quot;%s&quot;.'), htmlspecialchars($current['SCHEMA_NAME']))
. '">'. "\n"
. ' '
. ($cfg['PropertiesIconic']
? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' . __('Check Privileges') . '" /> '
: __('Check Privileges')) . "\n"
. ' </a></td>' . "\n";
}
echo '</tr>' . "\n"; echo '</tr>' . "\n";
} // end foreach ($databases as $key => $current) } // end foreach ($databases as $key => $current)
unset($current, $odd_row); unset($current, $odd_row);
@@ -313,7 +201,7 @@ if ($databases_count > 0) {
if ($is_superuser || $cfg['AllowUserDropDatabase']) { if ($is_superuser || $cfg['AllowUserDropDatabase']) {
echo ' <th></th>' . "\n"; echo ' <th></th>' . "\n";
} }
echo ' <th>' . __('Total') . ': ' . $databases_count . '</th>' . "\n"; echo ' <th>' . __('Total') . ': <span id="databases_count">' . $databases_count . '</span></th>' . "\n";
foreach ($column_order as $stat_name => $stat) { foreach ($column_order as $stat_name => $stat) {
if (array_key_exists($stat_name, $first_database)) { if (array_key_exists($stat_name, $first_database)) {
if ($stat['format'] === 'byte') { if ($stat['format'] === 'byte') {