From be32b88ec0d30e79d5e523aa5d425d0187963a92 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 24 May 2011 13:49:00 +0700 Subject: [PATCH 01/13] Remember table sorting in session variable --- sql.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/sql.php b/sql.php index d07022b568..6190e42e67 100644 --- a/sql.php +++ b/sql.php @@ -356,6 +356,30 @@ if ($is_select) { // see line 141 $is_maint = true; } +// Assign the full sql query +$full_sql_query = $sql_query; + +// Handle remembered sorting order, only for single table query +if (count($analyzed_sql[0][table_ref]) == 1) { + if (empty($analyzed_sql[0]['order_by_clause']) + && isset($_SESSION['tmp_user_values']['table_sorting'][$table])) { + // retrieve the remembered sorting order for current table + $sql_order_to_append = ' ORDER BY ' . $_SESSION['tmp_user_values']['table_sorting'][$table] . ' '; + $full_sql_query = $analyzed_sql[0]['section_before_limit'] . $sql_order_to_append . $analyzed_sql[0]['section_after_limit']; + + // update the $analyzed_sql + $analyzed_sql[0]['section_before_limit'] .= $sql_order_to_append; + $analyzed_sql[0]['order_by_clause'] = $_SESSION['tmp_user_values']['table_sorting'][$table]; + + /** + * @TODO: pretty printing of the modified query + */ + } else if (! empty($analyzed_sql[0]['order_by_clause'])) { + // store the remembered table into session + $_SESSION['tmp_user_values']['table_sorting'][$table] = $analyzed_sql[0]['order_by_clause']; + } +} + // Do append a "LIMIT" clause? if ((! $cfg['ShowAll'] || $_SESSION['tmp_user_values']['max_rows'] != 'all') && ! ($is_count || $is_export || $is_func || $is_analyse) @@ -380,9 +404,7 @@ if ((! $cfg['ShowAll'] || $_SESSION['tmp_user_values']['max_rows'] != 'all') } } -} else { - $full_sql_query = $sql_query; -} // end if...else +} if (strlen($db)) { PMA_DBI_select_db($db); From 81f95377787abe9ffbc901ad07adb24f4e9110e0 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 24 May 2011 14:50:47 +0700 Subject: [PATCH 02/13] Add new configuration field for RememberSorting --- Documentation.html | 3 +++ libraries/config.default.php | 7 +++++++ libraries/config/messages.inc.php | 2 ++ libraries/config/setup.forms.php | 3 ++- libraries/config/user_preferences.forms.php | 3 ++- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation.html b/Documentation.html index 3bbb832dd4..ac8f903821 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1934,6 +1934,9 @@ $cfg['TrustedProxies'] = each row on a vertical lineup. +
$cfg['RememberSorting'] boolean
+
If enabled, when browsing tables, the sorting of each table is remembered.
+
$cfg['HeaderFlipType'] string
The HeaderFlipType can be set to 'auto', 'css' or 'fake'. When using diff --git a/libraries/config.default.php b/libraries/config.default.php index 5c0b1b2d14..b6061e8f2a 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -2264,6 +2264,13 @@ $cfg['ModifyDeleteAtRight'] = false; */ $cfg['DefaultDisplay'] = 'horizontal'; +/** + * remember the last way a table sorted + * + * @global string $cfg['RememberSorting'] + */ +$cfg['RememberSorting'] = false; + /** * default display direction for altering/creating columns (tbl_properties) * (horizontal|vertical|) diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index e8ce0df96b..61e66e6d9f 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -346,6 +346,8 @@ $strConfigQueryWindowWidth_desc = __('Query window width (in pixels)'); $strConfigQueryWindowWidth_name = __('Query window width'); $strConfigRecodingEngine_desc = __('Select which functions will be used for character set conversion'); $strConfigRecodingEngine_name = __('Recoding engine'); +$strConfigRememberSorting_desc = __('When browsing tables, the sorting of each table is remembered'); +$strConfigRememberSorting_name = __('Remember table\'s sorting'); $strConfigRepeatCells_desc = __('Repeat the headers every X cells, [kbd]0[/kbd] deactivates this feature'); $strConfigRepeatCells_name = __('Repeat headers'); $strConfigReplaceHelpImg_desc = __('Show help button instead of Documentation text'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index 7269823d2d..773bddb5fa 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -200,7 +200,8 @@ $forms['Main_frame']['Browse'] = array( 'LimitChars', 'ModifyDeleteAtLeft', 'ModifyDeleteAtRight', - 'DefaultDisplay'); + 'DefaultDisplay', + 'RememberSorting'); $forms['Main_frame']['Edit'] = array( 'ProtectBinary', 'ShowFunctionFields', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index ffe036632f..68619c9f43 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -111,7 +111,8 @@ $forms['Main_frame']['Browse'] = array( 'LimitChars', 'ModifyDeleteAtLeft', 'ModifyDeleteAtRight', - 'DefaultDisplay'); + 'DefaultDisplay', + 'RememberSorting'); $forms['Main_frame']['Edit'] = array( 'ProtectBinary', 'ShowFunctionFields', From 07de5495c424bb1aa888d897ac02f4a201a979d5 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 24 May 2011 15:11:39 +0700 Subject: [PATCH 03/13] RememberSorting: add some checking before retrieving/remembering sorting --- sql.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sql.php b/sql.php index 6190e42e67..ba64fc2855 100644 --- a/sql.php +++ b/sql.php @@ -360,7 +360,11 @@ if ($is_select) { // see line 141 $full_sql_query = $sql_query; // Handle remembered sorting order, only for single table query -if (count($analyzed_sql[0][table_ref]) == 1) { +if ($GLOBALS['cfg']['RememberSorting'] + && ! ($is_count || $is_export || $is_func || $is_analyse) + && isset($analyzed_sql[0]['queryflags']['select_from']) + && count($analyzed_sql[0][table_ref]) == 1 + ) { if (empty($analyzed_sql[0]['order_by_clause']) && isset($_SESSION['tmp_user_values']['table_sorting'][$table])) { // retrieve the remembered sorting order for current table From c1cd10a14ff54d8d3d321b27c1a95a8fb7f410da Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 24 May 2011 16:41:51 +0700 Subject: [PATCH 04/13] Only remember sorting in Browse tab, modify the so SQL pretty printer works --- sql.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sql.php b/sql.php index ba64fc2855..127d5f0ea8 100644 --- a/sql.php +++ b/sql.php @@ -356,11 +356,9 @@ if ($is_select) { // see line 141 $is_maint = true; } -// Assign the full sql query -$full_sql_query = $sql_query; - // Handle remembered sorting order, only for single table query if ($GLOBALS['cfg']['RememberSorting'] + && basename($GLOBALS['PMA_PHP_SELF']) == 'sql.php' && ! ($is_count || $is_export || $is_func || $is_analyse) && isset($analyzed_sql[0]['queryflags']['select_from']) && count($analyzed_sql[0][table_ref]) == 1 @@ -369,21 +367,20 @@ if ($GLOBALS['cfg']['RememberSorting'] && isset($_SESSION['tmp_user_values']['table_sorting'][$table])) { // retrieve the remembered sorting order for current table $sql_order_to_append = ' ORDER BY ' . $_SESSION['tmp_user_values']['table_sorting'][$table] . ' '; - $full_sql_query = $analyzed_sql[0]['section_before_limit'] . $sql_order_to_append . $analyzed_sql[0]['section_after_limit']; + $sql_query = $analyzed_sql[0]['section_before_limit'] . $sql_order_to_append . $analyzed_sql[0]['section_after_limit']; // update the $analyzed_sql $analyzed_sql[0]['section_before_limit'] .= $sql_order_to_append; $analyzed_sql[0]['order_by_clause'] = $_SESSION['tmp_user_values']['table_sorting'][$table]; - - /** - * @TODO: pretty printing of the modified query - */ + } else if (! empty($analyzed_sql[0]['order_by_clause'])) { // store the remembered table into session $_SESSION['tmp_user_values']['table_sorting'][$table] = $analyzed_sql[0]['order_by_clause']; } } +echo '
'.$sql_query.'
'; + // Do append a "LIMIT" clause? if ((! $cfg['ShowAll'] || $_SESSION['tmp_user_values']['max_rows'] != 'all') && ! ($is_count || $is_export || $is_func || $is_analyse) @@ -408,7 +405,9 @@ if ((! $cfg['ShowAll'] || $_SESSION['tmp_user_values']['max_rows'] != 'all') } } -} +} else { + $full_sql_query = $sql_query; +} // end if...else if (strlen($db)) { PMA_DBI_select_db($db); From 96a253bfccfbb48102d83998282537a759956842 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 24 May 2011 16:51:30 +0700 Subject: [PATCH 05/13] Remove debugging message --- sql.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/sql.php b/sql.php index 127d5f0ea8..79a5655862 100644 --- a/sql.php +++ b/sql.php @@ -379,8 +379,6 @@ if ($GLOBALS['cfg']['RememberSorting'] } } -echo '
'.$sql_query.'
'; - // Do append a "LIMIT" clause? if ((! $cfg['ShowAll'] || $_SESSION['tmp_user_values']['max_rows'] != 'all') && ! ($is_count || $is_export || $is_func || $is_analyse) From 20f2e2011d9d732b3144f88c9ed894c0374fafc0 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 24 May 2011 16:57:01 +0700 Subject: [PATCH 06/13] Change default value for RememberSorting to true, for testing in the demo server --- libraries/config.default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/config.default.php b/libraries/config.default.php index b6061e8f2a..ea5c88b74d 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -2269,7 +2269,7 @@ $cfg['DefaultDisplay'] = 'horizontal'; * * @global string $cfg['RememberSorting'] */ -$cfg['RememberSorting'] = false; +$cfg['RememberSorting'] = true; /** * default display direction for altering/creating columns (tbl_properties) From cc7eade6a5d4b17b67b0ec22ff5df0876d906d56 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Wed, 25 May 2011 09:01:07 +0700 Subject: [PATCH 07/13] Remember table sorting: Fix for table_ref error --- sql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql.php b/sql.php index 79a5655862..93176e7aa1 100644 --- a/sql.php +++ b/sql.php @@ -361,7 +361,7 @@ if ($GLOBALS['cfg']['RememberSorting'] && basename($GLOBALS['PMA_PHP_SELF']) == 'sql.php' && ! ($is_count || $is_export || $is_func || $is_analyse) && isset($analyzed_sql[0]['queryflags']['select_from']) - && count($analyzed_sql[0][table_ref]) == 1 + && count($analyzed_sql[0]['table_ref']) == 1 ) { if (empty($analyzed_sql[0]['order_by_clause']) && isset($_SESSION['tmp_user_values']['table_sorting'][$table])) { From e98446c6c9f1098e7ffc147426dcb4bea0ac5b87 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Wed, 25 May 2011 09:08:18 +0700 Subject: [PATCH 08/13] Recent tables: Fix for frame_navigation reference not found --- js/functions.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/functions.js b/js/functions.js index f745e8c106..0380a3d41b 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2287,9 +2287,11 @@ $(document).ready(function() { } }); - $('#update_recent_tables').ready(function() { + $('#update_recent_tables').ready(function() { + if (window.parent.frame_navigation != undefined) { window.parent.frame_navigation.PMA_reloadRecentTable(); - }); + } + }); }) // end of $(document).ready() From a55873c9871bfb05bac8a3f42b6c30e23c88677d Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Wed, 25 May 2011 20:01:16 +0700 Subject: [PATCH 09/13] Recent tables: Additional fix for frame_navigation.PMA_reloadRecentTable() not found --- js/functions.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/functions.js b/js/functions.js index 0380a3d41b..c9f6112dff 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2288,7 +2288,9 @@ $(document).ready(function() { }); $('#update_recent_tables').ready(function() { - if (window.parent.frame_navigation != undefined) { + if (window.parent.frame_navigation != undefined + && window.parent.frame_navigation.PMA_reloadRecentTable != undefined) + { window.parent.frame_navigation.PMA_reloadRecentTable(); } }); From e4ba1dc06605fd81718d1991ad509d8e47f159fc Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Fri, 27 May 2011 18:52:00 +0700 Subject: [PATCH 10/13] Add table pma_ui_prefs for remembering table sorting persistently --- Documentation.html | 19 ++++ config.sample.inc.php | 1 + libraries/Table.class.php | 146 ++++++++++++++++++++++++++++++ libraries/config.default.php | 7 ++ libraries/config/messages.inc.php | 2 + libraries/config/setup.forms.php | 1 + libraries/relation.lib.php | 19 +++- scripts/create_tables.sql | 15 +++ sql.php | 24 ++--- 9 files changed, 220 insertions(+), 14 deletions(-) diff --git a/Documentation.html b/Documentation.html index ac8f903821..2ff0881ba0 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1077,6 +1077,25 @@ ALTER TABLE `pma_column_comments`
+
+ $cfg['Servers'][$i]['table_uiprefs'] string +
+
+ Since release 3.5.0 phpMyAdmin can be configured to remember several things + (table sorting + $cfg['RememberSorting'] + , etc.) for browsing tables. + Without configuring the storage, these features still can be used, + but the values will disappear after you logout.

+ + To allow the usage of these functionality persistently: + +
    +
  • set up pmadb and the phpMyAdmin configuration storage
  • +
  • put the table name in $cfg['Servers'][$i]['table_uiprefs'] (e.g. 'pma_table_uiprefs')
  • +
+
+
$cfg['Servers'][$i]['tracking'] string
diff --git a/config.sample.inc.php b/config.sample.inc.php index 95d3a1a911..edffd03345 100644 --- a/config.sample.inc.php +++ b/config.sample.inc.php @@ -53,6 +53,7 @@ $cfg['Servers'][$i]['AllowNoPassword'] = false; // $cfg['Servers'][$i]['column_info'] = 'pma_column_info'; // $cfg['Servers'][$i]['history'] = 'pma_history'; // $cfg['Servers'][$i]['recent'] = 'pma_recent'; +// $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs'; // $cfg['Servers'][$i]['tracking'] = 'pma_tracking'; // $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords'; // $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig'; diff --git a/libraries/Table.class.php b/libraries/Table.class.php index d41eadc8d9..c73eb31e5a 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -11,6 +11,10 @@ */ class PMA_Table { + /** + * UI preferences property: sorted column + */ + const PROP_SORTED_COLUMN = 'sorted_col'; static $cache = array(); @@ -39,6 +43,11 @@ class PMA_Table */ var $settings = array(); + /** + * @var array UI preferences + */ + var $uiprefs; + /** * @var array errors occured */ @@ -1185,5 +1194,142 @@ class PMA_Table return $return; } + + /** + * Return UI preferences for this table from phpMyAdmin database. + * + * @uses PMA_query_as_controluser() + * @uses PMA_DBI_fetch_array() + * @uses json_decode() + * + * @return array + */ + protected function getUiPrefsFromDb() + { + $pma_table = PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) .".". + PMA_backquote($GLOBALS['cfg']['Server']['table_uiprefs']); + + // Read from phpMyAdmin database + $sql_query = + " SELECT `prefs` FROM " . $pma_table . + " WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'" . + " AND `db_name` = '" . $this->db_name . "'" . + " AND `table_name` = '" . $this->name . "'"; + + $row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); + if (isset($row[0])) { + return json_decode($row[0], true); + } else { + return array(); + } + } + + /** + * Save this table's UI preferences into phpMyAdmin database. + * + * @uses PMA_DBI_try_query() + * @uses json_decode() + * @uses PMA_Message + * + * @return true|PMA_Message + */ + protected function saveUiPrefsToDb() + { + $pma_table = PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) .".". + PMA_backquote($GLOBALS['cfg']['Server']['table_uiprefs']); + + $username = $GLOBALS['cfg']['Server']['user']; + $sql_query = + " REPLACE INTO " . $pma_table . + " VALUES ('" . $username . "', '" . $this->db_name . "', '" . + $this->name . "', '" . PMA_sqlAddslashes(json_encode($this->uiprefs)) . "')"; + + $success = PMA_DBI_try_query($sql_query, $GLOBALS['controllink']); + + if (!$success) { + $message = PMA_Message::error(__('Could not save table UI preferences')); + $message->addMessage('

'); + $message->addMessage(PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink']))); + return $message; + } + return true; + } + + /** + * Loads the UI preferences for this table. + * If pmadb and table_uiprefs is set, it will load the UI preferences from + * phpMyAdmin database. + * + * @uses getUiPrefsFromDb() + */ + protected function loadUiPrefs() + { + // set session variable if it's still undefined + if (! isset($_SESSION['tmp_user_values']['table_uiprefs'][$this->db_name][$this->name])) { + $_SESSION['tmp_user_values']['table_uiprefs'][$this->db_name][$this->name] = + // check whether we can get from pmadb + (strlen($GLOBALS['cfg']['Server']['pmadb']) + && strlen($GLOBALS['cfg']['Server']['table_uiprefs'])) ? + $this->getUiPrefsFromDb() : array(); + } + $this->uiprefs =& $_SESSION['tmp_user_values']['table_uiprefs'][$this->db_name][$this->name]; + } + + /** + * Get UI preferences array for this table. + * If pmadb and table_uiprefs is set, it will get the UI preferences from + * phpMyAdmin database. + * + * @return array + */ + public function getUiPrefs() + { + if (! isset($this->uiprefs)) { + $this->loadUiPrefs(); + } + return $this->uiprefs; + } + + /** + * Get a property from UI preferences. + * Return false if the property is not found. + * Available property: + * - PROP_SORTED_COLUMN + * + * @uses loadUiPrefs() + * + * @param string $property + * @return mixed + */ + public function getUiProp($property) + { + if (! isset($this->uiprefs)) { + $this->loadUiPrefs(); + } + return isset($this->uiprefs[$property]) ? $this->uiprefs[$property] : false; + } + + /** + * Set a property from UI preferences. + * If pmadb and table_uiprefs is set, it will save the UI preferences to + * phpMyAdmin database. + * + * @param string $property + * @param mixed $value + * @return true|PMA_Message + */ + public function setUiProp($property, $value) + { + if (! isset($this->uiprefs)) { + $this->loadUiPrefs(); + } + $this->uiprefs[$property] = $value; + // check if pmadb is set + if (strlen($GLOBALS['cfg']['Server']['pmadb']) + && strlen($GLOBALS['cfg']['Server']['table_uiprefs'])) { + return $this->saveUiprefsToDb(); + } + return true; + } } ?> diff --git a/libraries/config.default.php b/libraries/config.default.php index ea5c88b74d..aa883d2dc7 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -345,6 +345,13 @@ $cfg['Servers'][$i]['designer_coords'] = ''; */ $cfg['Servers'][$i]['recent'] = ''; +/** + * table to store UI preferences for tables + * - leave blank for no "persistent" UI preferences + * SUGGESTED: 'pma_table_uiprefs' + */ +$cfg['Servers'][$i]['table_uiprefs'] = ''; + /** * table to store SQL tracking * - leave blank for no SQL tracking diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 61e66e6d9f..034214c4c2 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -422,6 +422,8 @@ $strConfigServers_table_coords_desc = __('Leave blank for no PDF schema support, $strConfigServers_table_coords_name = __('PDF schema: table coordinates'); $strConfigServers_table_info_desc = __('Table to describe the display columns, leave blank for no support; suggested: [kbd]pma_table_info[/kbd]'); $strConfigServers_table_info_name = __('Display columns table'); +$strConfigServers_table_uiprefs_desc = __('Leave blank for no "persistent" tables\'UI preferences across sessions, suggested: [kbd]pma_table_uiprefs[/kbd]'); +$strConfigServers_table_uiprefs_name = __('UI preferences table'); $strConfigServers_tracking_add_drop_database_desc = __('Whether a DROP DATABASE IF EXISTS statement will be added as first line to the log when creating a database.'); $strConfigServers_tracking_add_drop_database_name = __('Add DROP DATABASE'); $strConfigServers_tracking_add_drop_table_desc = __('Whether a DROP TABLE IF EXISTS statement will be added as first line to the log when creating a table.'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index 773bddb5fa..5cf5111ce2 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -74,6 +74,7 @@ $forms['Servers']['Server_pmadb'] = array('Servers' => array(1 => array( 'column_info' => 'pma_column_info', 'history' => 'pma_history', 'recent' => 'pma_recent', + 'table_uiprefs' => 'pma_table_uiprefs', 'tracking' => 'pma_tracking', 'table_coords' => 'pma_table_coords', 'pdf_pages' => 'pma_pdf_pages', diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 87521a9131..20ddf97b7b 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -142,6 +142,10 @@ function PMA_printRelationsParamDiagnostic($cfgRelation) PMA_printDiagMessageForFeature(__('Persistent recently used tables'), 'recentwork', $messages); + PMA_printDiagMessageForParameter('table_uiprefs', isset($cfgRelation['table_uiprefs']), $messages, 'table_uiprefs'); + + PMA_printDiagMessageForFeature(__('Persistent tables\' UI preferences'), 'uiprefswork', $messages); + PMA_printDiagMessageForParameter('tracking', isset($cfgRelation['tracking']), $messages, 'tracking'); PMA_printDiagMessageForFeature(__('Tracking'), 'trackingwork', $messages); @@ -225,6 +229,7 @@ function PMA__getRelationsParam() $cfgRelation['mimework'] = false; $cfgRelation['historywork'] = false; $cfgRelation['recentwork'] = false; + $cfgRelation['uiprefswork'] = false; $cfgRelation['trackingwork'] = false; $cfgRelation['designerwork'] = false; $cfgRelation['userconfigwork'] = false; @@ -278,6 +283,8 @@ function PMA__getRelationsParam() $cfgRelation['history'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) { $cfgRelation['recent'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) { + $cfgRelation['table_uiprefs'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) { $cfgRelation['tracking'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { @@ -292,9 +299,11 @@ function PMA__getRelationsParam() $cfgRelation['displaywork'] = true; } } + if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { $cfgRelation['pdfwork'] = true; } + if (isset($cfgRelation['column_info'])) { $cfgRelation['commwork'] = true; @@ -336,6 +345,10 @@ function PMA__getRelationsParam() $cfgRelation['recentwork'] = true; } + if (isset($cfgRelation['table_uiprefs'])) { + $cfgRelation['uiprefswork'] = true; + } + if (isset($cfgRelation['tracking'])) { $cfgRelation['trackingwork'] = true; } @@ -357,9 +370,9 @@ function PMA__getRelationsParam() if ($cfgRelation['relwork'] && $cfgRelation['displaywork'] && $cfgRelation['pdfwork'] && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfgRelation['historywork'] - && $cfgRelation['recentwork'] && $cfgRelation['trackingwork'] - && $cfgRelation['userconfigwork'] && $cfgRelation['bookmarkwork'] - && $cfgRelation['designerwork']) { + && $cfgRelation['recentwork'] && $cfgRelation['uiprefswork'] + && $cfgRelation['trackingwork'] && $cfgRelation['userconfigwork'] + && $cfgRelation['bookmarkwork'] && $cfgRelation['designerwork']) { $cfgRelation['allworks'] = true; } diff --git a/scripts/create_tables.sql b/scripts/create_tables.sql index 2d6cb56886..a537462229 100644 --- a/scripts/create_tables.sql +++ b/scripts/create_tables.sql @@ -117,6 +117,21 @@ CREATE TABLE IF NOT EXISTS `pma_recent` ( -- -------------------------------------------------------- +-- +-- Table structure for table `pma_table_uiprefs` +-- + +CREATE TABLE IF NOT EXISTS `pma_table_uiprefs` ( + `username` varchar(64) COLLATE utf8_bin NOT NULL, + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `prefs` blob NOT NULL, + PRIMARY KEY (`username`,`db_name`,`table_name`) +) ENGINE=MyISAM COMMENT='tables'' UI preferences' + DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- -------------------------------------------------------- + -- -- Table structure for table `pma_relation` -- diff --git a/sql.php b/sql.php index 93176e7aa1..1053a9d5f2 100644 --- a/sql.php +++ b/sql.php @@ -363,19 +363,21 @@ if ($GLOBALS['cfg']['RememberSorting'] && isset($analyzed_sql[0]['queryflags']['select_from']) && count($analyzed_sql[0]['table_ref']) == 1 ) { - if (empty($analyzed_sql[0]['order_by_clause']) - && isset($_SESSION['tmp_user_values']['table_sorting'][$table])) { - // retrieve the remembered sorting order for current table - $sql_order_to_append = ' ORDER BY ' . $_SESSION['tmp_user_values']['table_sorting'][$table] . ' '; - $sql_query = $analyzed_sql[0]['section_before_limit'] . $sql_order_to_append . $analyzed_sql[0]['section_after_limit']; + $pmatable = new PMA_Table($table, $db); + if (empty($analyzed_sql[0]['order_by_clause'])) { + $sorted_col = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN); + if ($sorted_col) { + // retrieve the remembered sorting order for current table + $sql_order_to_append = ' ORDER BY ' . $sorted_col . ' '; + $sql_query = $analyzed_sql[0]['section_before_limit'] . $sql_order_to_append . $analyzed_sql[0]['section_after_limit']; - // update the $analyzed_sql - $analyzed_sql[0]['section_before_limit'] .= $sql_order_to_append; - $analyzed_sql[0]['order_by_clause'] = $_SESSION['tmp_user_values']['table_sorting'][$table]; - - } else if (! empty($analyzed_sql[0]['order_by_clause'])) { + // update the $analyzed_sql + $analyzed_sql[0]['section_before_limit'] .= $sql_order_to_append; + $analyzed_sql[0]['order_by_clause'] = $sorted_col; + } + } else { // store the remembered table into session - $_SESSION['tmp_user_values']['table_sorting'][$table] = $analyzed_sql[0]['order_by_clause']; + $pmatable->setUiProp(PMA_Table::PROP_SORTED_COLUMN, $analyzed_sql[0]['order_by_clause']); } } From 7d8be177ef55d867c567dec3c78b80af406fae65 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 28 May 2011 07:00:37 -0400 Subject: [PATCH 11/13] ChangeLog for three features from GSoC 2011 --- ChangeLog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7457914719..915e38c2d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,9 @@ + Patch #3256122 [search] Show/hide db search results + Patch #3302354 Add gettext wrappers around a message + Remove deprecated function PMA_DBI_get_fields ++ rfe #2098927 Remember recent tables ++ rfe #3078542 Remember the last sort order for each table ++ AJAX for Create table in navigation panel 3.4.2.0 (not yet released) - bug #3301249 [interface] Iconic table operations does not remove inline edit label From eeeca229de40bd4599ebc84aa0b219ca174537c5 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 28 May 2011 08:23:56 -0400 Subject: [PATCH 12/13] Undefined variable when query is too big --- libraries/common.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 538d8ac9a4..f0d174fe4f 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -1094,6 +1094,7 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', $is_view // but only explain a SELECT (that has not been explained) /* SQL-Parser-Analyzer */ $explain_link = ''; + $is_select = false; if (! empty($cfg['SQLQuery']['Explain']) && ! $query_too_big) { $explain_params = $url_params; // Detect if we are validating as well @@ -1101,7 +1102,6 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', $is_view if (! empty($GLOBALS['validatequery'])) { $explain_params['validatequery'] = 1; } - $is_select = false; if (preg_match('@^SELECT[[:space:]]+@i', $sql_query)) { $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query; $_message = __('Explain SQL'); From ae0af9e5c6855c0b5535bfa6d2e27974c2b9f3ae Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 28 May 2011 08:29:38 -0400 Subject: [PATCH 13/13] Remove author name --- db_datadict.php | 2 +- db_qbe.php | 1 - libraries/common.lib.php | 4 ++-- libraries/export/htmlword.php | 2 +- libraries/export/latex.php | 2 +- libraries/export/odt.php | 2 +- libraries/export/sql.php | 2 +- libraries/export/texytext.php | 2 +- libraries/schema/Pdf_Relation_Schema.class.php | 4 ++-- tbl_printview.php | 2 +- 10 files changed, 11 insertions(+), 12 deletions(-) diff --git a/db_datadict.php b/db_datadict.php index e9d18fdf1e..9941ef4440 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -135,7 +135,7 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) { $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); } - // Check if we can use Relations (Mike Beck) + // Check if we can use Relations if (!empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array diff --git a/db_qbe.php b/db_qbe.php index a076798741..a5bd7a7e4e 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -686,7 +686,6 @@ if (!empty($qry_select)) { // 2. FROM // Create LEFT JOINS out of Relations -// Code originally by Mike Beck // If we can use Relations we could make some left joins. // First find out if relations are available in this database. diff --git a/libraries/common.lib.php b/libraries/common.lib.php index f0d174fe4f..633acb2c3c 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -1090,7 +1090,7 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', $is_view $edit_link = 'server_sql.php'; } - // Want to have the query explained (Mike Beck 2002-05-22) + // Want to have the query explained // but only explain a SELECT (that has not been explained) /* SQL-Parser-Analyzer */ $explain_link = ''; @@ -1137,7 +1137,7 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', $is_view $url_qpart = PMA_generate_common_url($url_params); // Also we would like to get the SQL formed in some nice - // php-code (Mike Beck 2002-05-22) + // php-code if (! empty($cfg['SQLQuery']['ShowAsPHP']) && ! $query_too_big) { $php_params = $url_params; diff --git a/libraries/export/htmlword.php b/libraries/export/htmlword.php index f5425bc4e0..d23640a600 100644 --- a/libraries/export/htmlword.php +++ b/libraries/export/htmlword.php @@ -210,7 +210,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $result = PMA_DBI_query($local_query); $fields_cnt = PMA_DBI_num_rows($result); - // Check if we can use Relations (Mike Beck) + // Check if we can use Relations if ($do_relation && ! empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array diff --git a/libraries/export/latex.php b/libraries/export/latex.php index 5ff1868910..2a434aed9e 100644 --- a/libraries/export/latex.php +++ b/libraries/export/latex.php @@ -330,7 +330,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $result = PMA_DBI_query($local_query); $fields_cnt = PMA_DBI_num_rows($result); - // Check if we can use Relations (Mike Beck) + // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array diff --git a/libraries/export/odt.php b/libraries/export/odt.php index b70388dd3c..d1324f0ecb 100644 --- a/libraries/export/odt.php +++ b/libraries/export/odt.php @@ -265,7 +265,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $result = PMA_DBI_query($local_query); $fields_cnt = PMA_DBI_num_rows($result); - // Check if we can use Relations (Mike Beck) + // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array diff --git a/libraries/export/sql.php b/libraries/export/sql.php index acfdf11f83..19f987364b 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -777,7 +777,7 @@ function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_mim $schema_create = ''; - // Check if we can use Relations (Mike Beck) + // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array diff --git a/libraries/export/texytext.php b/libraries/export/texytext.php index 8ed6a742ac..1895bcf5ac 100644 --- a/libraries/export/texytext.php +++ b/libraries/export/texytext.php @@ -192,7 +192,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $result = PMA_DBI_query($local_query); $fields_cnt = PMA_DBI_num_rows($result); - // Check if we can use Relations (Mike Beck) + // Check if we can use Relations if ($do_relation && ! empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array diff --git a/libraries/schema/Pdf_Relation_Schema.class.php b/libraries/schema/Pdf_Relation_Schema.class.php index ef602641a6..39fa62bc1f 100644 --- a/libraries/schema/Pdf_Relation_Schema.class.php +++ b/libraries/schema/Pdf_Relation_Schema.class.php @@ -1064,7 +1064,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema $pdf->SetFontSize(14); $pdf->SetLineWidth(0.2); $pdf->SetDisplayMode('fullpage'); - // Get the name of this pdfpage to use as filename (Mike Beck) + // Get the name of this pdfpage to use as filename $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE page_nr = ' . $pageNumber; $_name_rs = PMA_query_as_controluser($_name_sql); @@ -1189,7 +1189,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema */ $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); $fields_cnt = PMA_DBI_num_rows($result); - // Check if we can use Relations (Mike Beck) + // Check if we can use Relations if (!empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array diff --git a/tbl_printview.php b/tbl_printview.php index f2b80abfc6..6bfe3be191 100644 --- a/tbl_printview.php +++ b/tbl_printview.php @@ -114,7 +114,7 @@ foreach ($the_tables as $key => $table) { 0, 1); $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); - // Check if we can use Relations (Mike Beck) + // Check if we can use Relations // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table);