From be3102e2524db0f47eded1d486a622f3b08fcbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 20 Oct 2003 13:26:35 +0000 Subject: [PATCH] Make default functions configurable (RFE #821271). --- ChangeLog | 5 + Documentation.html | 25 ++++ Documentation.txt | 19 ++- config.inc.php3 | 9 ++ libraries/common.lib.php3 | 2 +- libraries/config_import.lib.php3 | 211 ++++++++++++++++--------------- tbl_change.php3 | 16 ++- 7 files changed, 177 insertions(+), 110 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b2a6cf54..7bc2a8399 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-10-20 Michal Cihar + * Documentation, config.inc.php3, tbl_change.php3, + libraries/common.lib.php3, libraries/config_import.lib.php3: Make + default functions configurable (RFE #821271). + 2003-10-18 Marc Delisle * libraries/common.lib.php3: bug 821512, Safari 1.0 v85.5 and fonts * libraries/functions.js: bug 825665, scratchboard and paper size diff --git a/Documentation.html b/Documentation.html index f951b3bd4..a128a8d6b 100755 --- a/Documentation.html +++ b/Documentation.html @@ -1912,6 +1912,31 @@ $cfg['PmaAbsoluteUri'] = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://'

+
$cfg['RestrictColumnTypes'] array
+
+ Mapping of column types to meta types used for prefering displayed + functions. In most cases you don't need to edit this. +

+
+ +
$cfg['RestrictFunctions'] array
+
+ Functions prefered for column meta types as defined in + $cfg['RestrictColumnTypes']. In most cases you don't need + to edit this. +

+
+ +
$cfg['DefaultFunctions'] array
+
+ Functions selected by default when insering/changing row, Functions + are defined for meta types from + $cfg['RestrictColumnTypes'] and for + first_timestamp, which is used for first timestamp column + in table. +

+
+ diff --git a/Documentation.txt b/Documentation.txt index 782d0c3b7..7399bb9e1 100644 --- a/Documentation.txt +++ b/Documentation.txt @@ -14,8 +14,8 @@ + Version history: ChangeLog + General notes: README + License: LICENSE - * Documentation version: $Id: Documentation.html,v 1.509 2003/10/13 - 00:53:11 lem9 Exp $ + * Documentation version: $Id: Documentation.html,v 1.510 2003/10/16 + 15:22:11 nijel Exp $ Requirements @@ -1300,6 +1300,21 @@ $cfg['PmaAbsoluteUri'] = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' A list of functions MySQL supports. In most cases you don't need to edit this. + $cfg['RestrictColumnTypes'] array + Mapping of column types to meta types used for prefering + displayed functions. In most cases you don't need to edit this. + + $cfg['RestrictFunctions'] array + Functions prefered for column meta types as defined in + $cfg['RestrictColumnTypes']. In most cases you don't need to + edit this. + + $cfg['DefaultFunctions'] array + Functions selected by default when insering/changing row, + Functions are defined for meta types from + $cfg['RestrictColumnTypes'] and for first_timestamp, which is + used for first timestamp column in table. + Transformations Introduction - Usage - File structure - diff --git a/config.inc.php3 b/config.inc.php3 index 0788b6d17..17f4bcca9 100755 --- a/config.inc.php3 +++ b/config.inc.php3 @@ -724,6 +724,15 @@ if ($cfg['ShowFunctionFields']) { ) ); + // Default functions for above defined groups + $cfg['DefaultFunctions'] = array( + 'FUNC_CHAR' => '', + 'FUNC_DATE' => '', + 'FUNC_NUMBER' => '', + 'first_timestamp' => 'NOW' + ); + + } // end if diff --git a/libraries/common.lib.php3 b/libraries/common.lib.php3 index 32402dc3c..5cd75940d 100644 --- a/libraries/common.lib.php3 +++ b/libraries/common.lib.php3 @@ -135,7 +135,7 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold} * Includes compatibility code for older config.inc.php3 revisions * if necessary */ - if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 203) { + if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 206) { include('./libraries/config_import.lib.php3'); } diff --git a/libraries/config_import.lib.php3 b/libraries/config_import.lib.php3 index 3632e2718..de0b65213 100644 --- a/libraries/config_import.lib.php3 +++ b/libraries/config_import.lib.php3 @@ -1012,109 +1012,120 @@ if (!defined('PMA_CONFIG_IMPORT_LIB_INCLUDED')) { } } - if (!isset($cfg['Functions']) && $cfg['ShowFunctionFields']) { - if (isset($cfgFunctions)) { - $cfg['Functions'] = $cfgFunctions; - } else { - $cfg['Functions'] = array( - 'ASCII', - 'CHAR', - 'SOUNDEX', - 'LCASE', - 'UCASE', - 'NOW', - 'PASSWORD', - 'MD5', - 'ENCRYPT', - 'RAND', - 'LAST_INSERT_ID', - 'COUNT', - 'AVG', - 'SUM', - 'CURDATE', - 'CURTIME', - 'FROM_DAYS', - 'FROM_UNIXTIME', - 'PERIOD_ADD', - 'PERIOD_DIFF', - 'TO_DAYS', - 'UNIX_TIMESTAMP', - 'USER', - 'WEEKDAY', - 'CONCAT' + if ($cfg['ShowFunctionFields']) { + if (!isset($cfg['Functions'])) { + if (isset($cfgFunctions)) { + $cfg['Functions'] = $cfgFunctions; + } else { + $cfg['Functions'] = array( + 'ASCII', + 'CHAR', + 'SOUNDEX', + 'LCASE', + 'UCASE', + 'NOW', + 'PASSWORD', + 'MD5', + 'ENCRYPT', + 'RAND', + 'LAST_INSERT_ID', + 'COUNT', + 'AVG', + 'SUM', + 'CURDATE', + 'CURTIME', + 'FROM_DAYS', + 'FROM_UNIXTIME', + 'PERIOD_ADD', + 'PERIOD_DIFF', + 'TO_DAYS', + 'UNIX_TIMESTAMP', + 'USER', + 'WEEKDAY', + 'CONCAT' + ); + } + + // Which column types will be mapped to which Group? + $cfg['RestrictColumnTypes'] = array( + 'VARCHAR' => 'FUNC_CHAR', + 'TINYINT' => 'FUNC_NUMBER', + 'TEXT' => 'FUNC_CHAR', + 'DATE' => 'FUNC_DATE', + 'SMALLINT' => 'FUNC_NUMBER', + 'MEDIUMINT' => 'FUNC_NUMBER', + 'INT' => 'FUNC_NUMBER', + 'BIGINT' => 'FUNC_NUMBER', + 'FLOAT' => 'FUNC_NUMBER', + 'DOUBLE' => 'FUNC_NUMBER', + 'DECIMAL' => 'FUNC_NUMBER', + 'DATETIME' => 'FUNC_DATE', + 'TIMESTAMP' => 'FUNC_DATE', + 'TIME' => 'FUNC_DATE', + 'YEAR' => 'FUNC_DATE', + 'CHAR' => 'FUNC_CHAR', + 'TINYBLOB' => 'FUNC_CHAR', + 'TINYTEXT' => 'FUNC_CHAR', + 'BLOB' => 'FUNC_CHAR', + 'MEDIUMBLOB' => 'FUNC_CHAR', + 'MEDIUMTEXT' => 'FUNC_CHAR', + 'LONGBLOB' => 'FUNC_CHAR', + 'LONGTEXT' => 'FUNC_CHAR', + 'ENUM' => '', + 'SET' => '' + ); + + // Map above defined groups to any function + $cfg['RestrictFunctions'] = array( + 'FUNC_CHAR' => array( + 'ASCII', + 'CHAR', + 'SOUNDEX', + 'LCASE', + 'UCASE', + 'PASSWORD', + 'MD5', + 'ENCRYPT', + 'LAST_INSERT_ID', + 'USER', + 'CONCAT' + ), + + 'FUNC_DATE' => array( + 'NOW', + 'CURDATE', + 'CURTIME', + 'FROM_DAYS', + 'FROM_UNIXTIME', + 'PERIOD_ADD', + 'PERIOD_DIFF', + 'TO_DAYS', + 'UNIX_TIMESTAMP', + 'WEEKDAY' + ), + + 'FUNC_NUMBER' => array( + 'ASCII', + 'CHAR', + 'MD5', + 'ENCRYPT', + 'RAND', + 'LAST_INSERT_ID', + 'COUNT', + 'AVG', + 'SUM' + ) ); } - // Which column types will be mapped to which Group? - $cfg['RestrictColumnTypes'] = array( - 'VARCHAR' => 'FUNC_CHAR', - 'TINYINT' => 'FUNC_NUMBER', - 'TEXT' => 'FUNC_CHAR', - 'DATE' => 'FUNC_DATE', - 'SMALLINT' => 'FUNC_NUMBER', - 'MEDIUMINT' => 'FUNC_NUMBER', - 'INT' => 'FUNC_NUMBER', - 'BIGINT' => 'FUNC_NUMBER', - 'FLOAT' => 'FUNC_NUMBER', - 'DOUBLE' => 'FUNC_NUMBER', - 'DECIMAL' => 'FUNC_NUMBER', - 'DATETIME' => 'FUNC_DATE', - 'TIMESTAMP' => 'FUNC_DATE', - 'TIME' => 'FUNC_DATE', - 'YEAR' => 'FUNC_DATE', - 'CHAR' => 'FUNC_CHAR', - 'TINYBLOB' => 'FUNC_CHAR', - 'TINYTEXT' => 'FUNC_CHAR', - 'BLOB' => 'FUNC_CHAR', - 'MEDIUMBLOB' => 'FUNC_CHAR', - 'MEDIUMTEXT' => 'FUNC_CHAR', - 'LONGBLOB' => 'FUNC_CHAR', - 'LONGTEXT' => 'FUNC_CHAR', - 'ENUM' => '', - 'SET' => '' - ); - - // Map above defined groups to any function - $cfg['RestrictFunctions'] = array( - 'FUNC_CHAR' => array( - 'ASCII', - 'CHAR', - 'SOUNDEX', - 'LCASE', - 'UCASE', - 'PASSWORD', - 'MD5', - 'ENCRYPT', - 'LAST_INSERT_ID', - 'USER', - 'CONCAT' - ), - - 'FUNC_DATE' => array( - 'NOW', - 'CURDATE', - 'CURTIME', - 'FROM_DAYS', - 'FROM_UNIXTIME', - 'PERIOD_ADD', - 'PERIOD_DIFF', - 'TO_DAYS', - 'UNIX_TIMESTAMP', - 'WEEKDAY' - ), - - 'FUNC_NUMBER' => array( - 'ASCII', - 'CHAR', - 'MD5', - 'ENCRYPT', - 'RAND', - 'LAST_INSERT_ID', - 'COUNT', - 'AVG', - 'SUM' - ) - ); + if (!isset($cfg['DefaultFunctions'])) { + $cfg['DefaultFunctions'] = array( + 'FUNC_CHAR' => '', + 'FUNC_DATE' => '', + 'FUNC_NUMBER' => '', + 'first_timestamp' => 'NOW' + ); + } } if (!isset($cfg['GD2Available'])) { diff --git a/tbl_change.php3 b/tbl_change.php3 index 17d0ecfd8..242a5e438 100755 --- a/tbl_change.php3 +++ b/tbl_change.php3 @@ -360,7 +360,9 @@ for ($i = 0; $i < $fields_cnt; $i++) { // or something similar. Then directly look up the entry in the RestrictFunctions array, // which will then reveal the available dropdown options if (isset($cfg['RestrictFunctions']) && isset($cfg['RestrictColumnTypes']) && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]) && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) { - $dropdown = $cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]]; + $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]; + $dropdown = $cfg['RestrictFunctions'][$current_func_type]; + $default_function = $cfg['DefaultFunctions'][$current_func_type]; } else { $dropdown = array(); } @@ -370,9 +372,9 @@ for ($i = 0; $i < $fields_cnt; $i++) { // garvin: loop on the dropdown array and print all available options for that field. for ($j = 0; $j < count($dropdown); $j++) { - // for default function = NOW() on first timestamp field - // -- swix/18jul01 - $selected = ($first_timestamp && $dropdown[$j] == 'NOW') + // Is current function defined as default? + $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp']) + || (!$first_timestamp && $dropdown[$j] == $default_function) ? ' selected="selected"' : ''; echo ' '; @@ -386,9 +388,9 @@ for ($i = 0; $i < $fields_cnt; $i++) { // yet. for ($j = 0; $j < count($cfg['Functions']); $j++) { if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') { - // for default function = NOW() on first timestamp field - // -- swix/18jul01 - $selected = ($first_timestamp && $cfg['Functions'][$j] == 'NOW') + // Is current function defined as default? + $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp']) + || (!$first_timestamp && $cfg['Functions'][$j] == $default_function) ? ' selected="selected"' : ''; if ($op_spacing_needed == TRUE) {