[Phpmyadmin-git] [SCM] phpMyAdmin branch, master, updated. RELEASE_3_3_7-10555-g81d6112

Marc Delisle lem9 at users.sourceforge.net
Mon Oct 11 15:35:15 CEST 2010


The branch, master has been updated
       via  81d61125ccaf15fc27d22c3393cd43029e24afb8 (commit)
      from  da339cd5ffa85e51cb6942d80f88b5790e01734b (commit)


- Log -----------------------------------------------------------------
commit 81d61125ccaf15fc27d22c3393cd43029e24afb8
Author: Marc Delisle <marc at infomarc.info>
Date:   Mon Oct 11 09:34:51 2010 -0400

    bug #3072495 Creating new database on Databases tab messed layout

-----------------------------------------------------------------------

Summary of changes:
 db_create.php                             |   57 +++++------
 js/functions.js                           |   13 ++-
 libraries/build_html_for_db.lib.php       |  158 +++++++++++++++++++++++++++++
 libraries/display_create_database.lib.php |    4 +
 libraries/replication.inc.php             |   21 ++++
 server_databases.php                      |  122 +---------------------
 6 files changed, 226 insertions(+), 149 deletions(-)
 create mode 100644 libraries/build_html_for_db.lib.php

diff --git a/db_create.php b/db_create.php
index 64a8acb..3609bf6 100644
--- a/db_create.php
+++ b/db_create.php
@@ -13,6 +13,8 @@ $GLOBALS['js_include'][] = 'functions.js';
 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
 
 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'));
 
@@ -30,6 +32,7 @@ if (!empty($db_collation)) {
     if (in_array($db_charset, $mysql_charsets) && in_array($db_collation, $mysql_collations[$db_charset])) {
         $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
     }
+    $db_collation_for_ajax = $db_collation;
     unset($db_charset, $db_collation);
 }
 $sql_query .= ';';
@@ -78,6 +81,8 @@ if (! $result) {
         $db_url_params['db'] = $new_db;
 
         $is_superuser = PMA_isSuperuser();
+        $column_order = PMA_getColumnOrder();
+        $url_query = PMA_generate_common_url($new_db);
 
         /**
          * String that will contain the output HTML
@@ -85,41 +90,33 @@ if (! $result) {
          */
         $new_db_string = '<tr>';
 
-        /**
-         * Is user allowed to drop the database?
-         */
-        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>';
+        if (empty($db_collation_for_ajax)) {
+            $db_collation_for_ajax = PMA_getServerCollation();
         }
 
-        /**
-         * Link to the database's page
-         */
-        $new_db_string .= '<td class="name">';
-        $new_db_string .= '<a target="_parent" title="Jump to database" href="index.php' . PMA_generate_common_url($db_url_params) . '">';
-        $new_db_string .= $new_db . '</a>';
-        $new_db_string .= '</td>';
-
-        /**
-         * If the user has privileges, let him check privileges for the DB
-         */
-        if($is_superuser) {
-            
-            $db_url_params['checkprivs'] = $new_db;
-
-            $new_db_string .= '<td class="tool">';
-            $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>';
+        // $dbstats comes from the create table dialog
+        if (! empty($dbstats)) {
+            $current = array(
+                'SCHEMA_NAME' => $new_db,
+                'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax,
+                'SCHEMA_TABLES' => '0',
+                'SCHEMA_TABLE_ROWS' => '0',
+                'SCHEMA_DATA_LENGTH' => '0',
+                'SCHEMA_MAX_DATA_LENGTH' => '0',
+                'SCHEMA_INDEX_LENGTH' => '0',
+                'SCHEMA_LENGTH' => '0',
+                'SCHEMA_DATA_FREE' => '0'
+            );
+        } else {
+            $current = array(
+                'SCHEMA_NAME' => $new_db
+            );
         }
 
-        $new_db_string .= '</tr>';
+        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;
 
-        /** @todo Statistics for newly created DB! */
+        $new_db_string .= '</tr>';
 
         $extra_data['new_db_string'] = $new_db_string;
 
diff --git a/js/functions.js b/js/functions.js
index 24f6c12..2fe8530 100644
--- a/js/functions.js
+++ b/js/functions.js
@@ -2299,10 +2299,15 @@ $(document).ready(function() {
     $('#create_database_form').live('submit', function(event) {
         event.preventDefault();
 
+        $form = $(this);
+
         PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
-        $(this).append('<input type="hidden" name="ajax_request" value="true" />');
 
-        $.post($(this).attr('action'), $(this).serialize(), function(data) {
+        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) {
                 PMA_ajaxShowMessage(data.message);
 
@@ -2314,6 +2319,10 @@ $(document).ready(function() {
                 .find('#db_summary_row')
                 .appendTo('#tabledatabases tbody')
                 .removeClass('odd even');
+
+                var $databases_count_object = $('#databases_count');
+                var databases_count = parseInt($databases_count_object.text()); 
+                $databases_count_object.text(++databases_count);
             }
             else {
                 PMA_ajaxShowMessage(data.error);
diff --git a/libraries/build_html_for_db.lib.php b/libraries/build_html_for_db.lib.php
new file mode 100644
index 0000000..6f4357c
--- /dev/null
+++ b/libraries/build_html_for_db.lib.php
@@ -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 && window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
+           . '" href="index.php?' . $url_query . '&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
+               . '&checkprivs=' . urlencode($current['SCHEMA_NAME'])
+               . '" title="' . sprintf(__('Check privileges for database "%s".'), htmlspecialchars($current['SCHEMA_NAME']))
+               . '">'
+               . ' '
+               . PMA_getIcon('s_rights.png', __('Check Privileges'))
+               . '</a></td>';
+    }
+    return array($column_order, $out);
+}
+?>
diff --git a/libraries/display_create_database.lib.php b/libraries/display_create_database.lib.php
index e6caec5..17ebfae 100644
--- a/libraries/display_create_database.lib.php
+++ b/libraries/display_create_database.lib.php
@@ -25,6 +25,10 @@ if ($is_create_db_priv) {
     <?php
     require_once './libraries/mysql_charsets.lib.php';
     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" />
         </form>
diff --git a/libraries/replication.inc.php b/libraries/replication.inc.php
index 3669a4e..45fd07d 100644
--- a/libraries/replication.inc.php
+++ b/libraries/replication.inc.php
@@ -90,25 +90,46 @@ $slave_variables_oks = array(
 );
 
 // 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) {
     if (count(${"server_{$type}_replication"}) > 0) {
         ${"server_{$type}_status"} = true;
+        $replication_info[$type]['status'] = true;
     } else {
         ${"server_{$type}_status"} = false;
+        $replication_info[$type]['status'] = false;
     }
     if (${"server_{$type}_status"}) {
         if ($type == "master") {
             ${"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"]);
+            $replication_info[$type]['Ignore_DB'] = ${"server_{$type}_Ignore_DB"}; 
         } elseif ($type == "slave") {
             ${"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"]);
+            $replication_info[$type]['Ignore_DB'] = ${"server_{$type}_Ignore_DB"}; 
 
             ${"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"]);
+            $replication_info[$type]['Ignore_Table'] = ${"server_{$type}_Ignore_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"]);
+            $replication_info[$type]['Wild_Ignore_Table'] = ${"server_{$type}_Wild_Ignore_Table"}; 
         }
     }
 }
diff --git a/server_databases.php b/server_databases.php
index 8ce1f8e..a0b5705 100644
--- a/server_databases.php
+++ b/server_databases.php
@@ -12,6 +12,7 @@ require_once './libraries/common.inc.php';
 
 require './libraries/server_common.inc.php';
 require './libraries/replication.inc.php';
+require './libraries/build_html_for_db.lib.php';
 
 /**
  * avoids 'undefined index' errors
@@ -118,42 +119,7 @@ if ($databases_count > 0) {
     reset($databases);
     $first_database = current($databases);
     // table col order
-    $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,
-    );
+    $column_order = PMA_getColumnOrder();
 
     $_url_params = array(
         'pos' => $pos,
@@ -223,88 +189,10 @@ if ($databases_count > 0) {
         echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
         $odd_row = ! $odd_row;
 
-        if ($is_superuser || $cfg['AllowUserDropDatabase']) {
-            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 && window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
-           . '" href="index.php?' . $url_query . '&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) {
-            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>';
-            }
-        }
+        list($column_order, $generated_html) = PMA_buildHtmlForDb($current, $is_superuser, (isset($checkall) ? $checkall : ''), $url_query, $column_order, $replication_types, $replication_info);
+
+        echo $generated_html;
 
-        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
-               . '&checkprivs=' . urlencode($current['SCHEMA_NAME'])
-               . '" title="' . sprintf(__('Check privileges for database "%s".'), 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";
     } // end foreach ($databases as $key => $current)
     unset($current, $odd_row);
@@ -313,7 +201,7 @@ if ($databases_count > 0) {
     if ($is_superuser || $cfg['AllowUserDropDatabase']) {
         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) {
         if (array_key_exists($stat_name, $first_database)) {
             if ($stat['format'] === 'byte') {


hooks/post-receive
-- 
phpMyAdmin




More information about the Git mailing list