From b13dee72f389bfda1eb3769e8d0abb54239fc057 Mon Sep 17 00:00:00 2001 From: Crack Date: Thu, 1 Jul 2010 22:24:18 +0200 Subject: [PATCH] Import settings --- js/config.js | 24 +++++++++++++ libraries/config.default.php | 23 ++++++++++++- libraries/config.values.php | 6 ++++ libraries/config/messages.inc.php | 32 ++++++++++++++++- libraries/config/setup.forms.php | 25 ++++++++++++++ libraries/config/user_preferences.forms.php | 38 +++++++++++++++++++-- setup/lib/validate.lib.php | 30 ++++++++++++++-- 7 files changed, 172 insertions(+), 6 deletions(-) diff --git a/js/config.js b/js/config.js index 85dc4c51f..aa2e41bd0 100644 --- a/js/config.js +++ b/js/config.js @@ -221,6 +221,30 @@ var validators = { var valid = this.value.match(/^(?:horizontal|vertical|[0-9]+)$/) != null; return valid ? true : PMA_messages['error_invalid_value'] }, + /** + * Validates string length - must be 1 character long + * + * @param {boolean} isKeyUp + */ + validate_str1: function (isKeyUp) { + if (isKeyUp && this.value == '') { + return true; + } + var result = this.value.length == 1; + return result ? true : PMA_messages['error_invalid_value']; + }, + /** + * Validates string length - must be 0 or 1 character long + * + * @param {boolean} isKeyUp + */ + validate_str01: function (isKeyUp) { + if (isKeyUp && this.value == '') { + return true; + } + var result = this.value.length <= 1; + return result ? true : PMA_messages['error_invalid_value']; + }, // field validators _field: { }, diff --git a/libraries/config.default.php b/libraries/config.default.php index 8db79c39b..810d25ff8 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -1726,7 +1726,7 @@ $cfg['Import']['allow_interrupt'] = true; * * @global integer $cfg['Import']['skip_queries'] */ -$cfg['Import']['skip_queries'] = '0'; +$cfg['Import']['skip_queries'] = 0; /** * @@ -1749,6 +1749,13 @@ $cfg['Import']['sql_no_auto_value_on_zero'] = true; */ $cfg['Import']['csv_replace'] = false; +/** + * + * + * @global boolean $cfg['Import']['csv_ignore'] + */ +$cfg['Import']['csv_ignore'] = false; + /** * * @@ -1798,6 +1805,13 @@ $cfg['Import']['csv_col_names'] = false; */ $cfg['Import']['ldi_replace'] = false; +/** + * + * + * @global boolean $cfg['Import']['ldi_ignore'] + */ +$cfg['Import']['ldi_ignore'] = false; + /** * * @@ -1882,6 +1896,13 @@ $cfg['Import']['xls_col_names'] = false; */ $cfg['Import']['xls_empty_rows'] = true; +/** + * + * + * @global string $cfg['Import']['xlsx_col_names'] + */ +$cfg['Import']['xlsx_col_names'] = false; + /** * Link to the official MySQL documentation. * Be sure to include no trailing slash on the path. diff --git a/libraries/config.values.php b/libraries/config.values.php index 522d2362f..f7978210e 100644 --- a/libraries/config.values.php +++ b/libraries/config.values.php @@ -102,6 +102,12 @@ $cfg_db['_validators'] = array( 'CharTextareaRows' => 'validate_positive_number', 'DefaultPropDisplay' => 'validate_DefaultPropDisplay', 'ForeignKeyMaxLimit' => 'validate_positive_number', + 'Import/csv_enclosed' => 'validate_str01', + 'Import/csv_escaped' => 'validate_str1', + 'Import/csv_terminated' => 'validate_str1', + 'Import/ldi_enclosed' => 'validate_str01', + 'Import/ldi_escaped' => 'validate_str1', + 'Import/ldi_terminated' => 'validate_str1', 'Import/skip_queries' => 'validate_non_negative_number', 'InsertRows' => 'validate_positive_number', 'LeftFrameTableLevel' => 'validate_positive_number', diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 490f32ec2..575a82b05 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -85,8 +85,12 @@ $strSetupForeignKeyMaxLimit_desc = __('A dropdown will be used if fewer items ar $strSetupForeignKeyMaxLimit_name = __('Foreign key limit'); $strSetupForm_Browse = __('Browse mode'); $strSetupForm_Browse_desc = __('Customize browse mode'); +$strSetupForm_Csv = __('CSV'); +$strSetupForm_Csv_desc = __('Customize default options'); $strSetupForm_Edit_desc = __('Customize edit mode'); $strSetupForm_Edit = __('Edit mode'); +$strSetupForm_Excel = __('Excel Workbook'); +$strSetupForm_Excel_desc = __('Customize default options'); $strSetupForm_Export_defaults_desc = __('Customize default export options'); $strSetupForm_Export_defaults = __('Export defaults'); $strSetupForm_General = __('General settings'); @@ -94,6 +98,8 @@ $strSetupForm_Import_defaults_desc = __('Customize default common import options $strSetupForm_Import_defaults = __('Import defaults'); $strSetupForm_Import_export_desc = __('Set import and export directories and compression options'); $strSetupForm_Import_export = __('Import / export'); +$strSetupForm_Ldi = __('CSV using LOAD DATA'); +$strSetupForm_Ldi_desc = __('Customize default options'); $strSetupForm_Left_databases = __('Databases'); $strSetupForm_Left_databases_desc = __('Databases display options'); $strSetupForm_Left_frame_desc = __('Customize appearance of the navigation frame'); @@ -103,12 +109,16 @@ $strSetupForm_Left_servers = __('Servers'); $strSetupForm_Left_tables_desc = __('Tables display options'); $strSetupForm_Left_tables = __('Tables'); $strSetupForm_Main_frame = __('Main frame'); +$strSetupForm_Ods = __('Open Document Spreadsheet'); +$strSetupForm_Ods_desc = __('Customize default options'); $strSetupForm_Other_core_settings_desc = __('Settings that didn\'t fit enywhere else'); $strSetupForm_Other_core_settings = __('Other core settings'); $strSetupForm_Query_window_desc = __('Customize query window options'); $strSetupForm_Query_window = __('Query window'); $strSetupForm_Page_titles = __('Page titles'); $strSetupForm_Page_titles_desc = __('Specify browser\'s title bar text. Refer to [a@Documentation.html#cfg_TitleTable]documentation[/a] for magic strings that can be used to get special values.'); +$strSetupForm_Sql = __('SQL'); +$strSetupForm_Sql_desc = __('Customize default options'); $strSetupForm_Security_desc = __('Please note that phpMyAdmin is just a user interface and its features do not limit MySQL'); $strSetupForm_Security = __('Security'); $strSetupForm_Server = __('Basic settings'); @@ -128,7 +138,7 @@ $strSetupFormset_Left_frame = __('Customize navigation frame'); $strSetupFormset_Main_frame = __('Customize main frame'); $strSetupForm_Sql_box_desc = __('Customize links shown in SQL Query boxes'); $strSetupForm_Sql_box = __('SQL Query box'); -$strSetupForm_Sql_queries_desc = __('SQL queries settings, for SQL Query box options see [a@?page=form&formset=main_frame#tab_Sql_box]Navigation frame[/a] settings'); +$strSetupForm_Sql_queries_desc = __('SQL queries settings, for SQL Query box options see [a@?page=form&formset=Main_frame#tab_Sql_box]Navigation frame[/a] settings'); $strSetupForm_Sql_queries = __('SQL queries'); $strSetupForm_Startup_desc = __('Customize startup page'); $strSetupForm_Startup = __('Startup'); @@ -142,10 +152,30 @@ $strSetupIgnoreMultiSubmitErrors_desc = __('If enabled, phpMyAdmin continues com $strSetupIgnoreMultiSubmitErrors_name = __('Ignore multiple statement errors'); $strSetupImport_allow_interrupt_desc = __('Allow interrupt of import in case script detects it is close to time limit. This might be good way to import large files, however it can break transactions.'); $strSetupImport_allow_interrupt_name = __('Partial import: allow interrupt'); +$strSetupImport_csv_replace_name = __('Replace table data with file'); +$strSetupImport_csv_ignore_name = __('Ignore duplicate rows'); +$strSetupImport_csv_terminated_name = __('Columns terminated by'); +$strSetupImport_csv_enclosed_name = __('Columns enclosed by'); +$strSetupImport_csv_escaped_name = __('Columns escaped by'); +$strSetupImport_csv_col_names_name = __('Lines terminated by'); $strSetupImport_format_desc = __('Default format; be aware that this list depends on location (database, table) and only SQL is always available'); $strSetupImport_format_name = __('Format of imported file'); +$strSetupImport_ldi_replace_name = __('Replace table data with file'); +$strSetupImport_ldi_ignore_name = __('Ignore duplicate rows'); +$strSetupImport_ldi_terminated_name = __('Columns terminated by'); +$strSetupImport_ldi_enclosed_name = __('Columns enclosed by'); +$strSetupImport_ldi_escaped_name = __('Columns escaped by'); +$strSetupImport_ldi_local_option_name = __('Use LOCAL keyword'); +$strSetupImport_ods_col_names_name = __('Column names in first row'); +$strSetupImport_ods_empty_rows_name = __('Do not import empty rows'); +$strSetupImport_ods_recognize_percentages_name = __('Import percentages as proper decimals (12.00% to .12)'); +$strSetupImport_ods_recognize_currency_name = __('Import currencies ($5.00 to 5.00)'); +$strSetupImport_sql_compatibility_name = __('SQL compatibility mode'); +$strSetupImport_sql_no_auto_value_on_zero_name = __('Do not use AUTO_INCREMENT for zero values'); $strSetupImport_skip_queries_desc = __('Number of queries to skip from start'); $strSetupImport_skip_queries_name = __('Partial import: skip queries'); +$strSetupImport_xls_col_names_name = __('Column names in first row') . ' (Excel 97-2003)'; +$strSetupImport_xlsx_col_names_name = __('Column names in first row') . ' (Excel 2007+)'; $strSetupInitialSlidersState_name = __('Initial state for sliders'); $strSetupInsertRows_desc = __('How many rows can be inserted at one time'); $strSetupInsertRows_name = __('Number of inserted rows'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index 2ddc0e97a..b44d4e085 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -196,6 +196,31 @@ $forms['Import']['Import_defaults'] = array('Import' => array( 'format', 'allow_interrupt', 'skip_queries')); +$forms['Import']['Sql'] = array('Import' => array( + 'sql_compatibility', + 'sql_no_auto_value_on_zero')); +$forms['Import']['Csv'] = array('Import' => array( + 'csv_replace', + 'csv_ignore', + 'csv_terminated', + 'csv_enclosed', + 'csv_escaped', + 'csv_col_names')); +$forms['Import']['Ldi'] = array('Import' => array( + 'ldi_replace', + 'ldi_ignore', + 'ldi_terminated', + 'ldi_enclosed', + 'ldi_escaped', + 'ldi_local_option')); +$forms['Import']['Excel'] = array('Import' => array( + 'xls_col_names', + 'xlsx_col_names')); +$forms['Import']['Ods'] = array('Import' => array( + 'ods_col_names', + 'ods_empty_rows', + 'ods_recognize_percentages', + 'ods_recognize_currency')); $forms['Export']['Export_defaults'] = array('Export' => array( 'format', 'compression', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index 98c9275d8..290bb1003 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -97,6 +97,40 @@ $forms['Main_frame']['Tabs'] = array( 'DefaultTabServer', 'DefaultTabDatabase', 'DefaultTabTable'); -$forms['Import']['Import_defaults'] = array(); -$forms['Export']['Export_defaults'] = array(); +$forms['Import']['Import_defaults'] = array( + 'Import/format', + 'Import/allow_interrupt', + 'Import/skip_queries'); +$forms['Import']['Sql'] = array( + 'Import/sql_compatibility', + 'Import/sql_no_auto_value_on_zero'); +$forms['Import']['Csv'] = array( + 'Import/csv_replace', + 'Import/csv_ignore', + 'Import/csv_terminated', + 'Import/csv_enclosed', + 'Import/csv_escaped', + 'Import/csv_col_names'); +$forms['Import']['Ldi'] = array( + 'Import/ldi_replace', + 'Import/ldi_ignore', + 'Import/ldi_terminated', + 'Import/ldi_enclosed', + 'Import/ldi_escaped', + 'Import/ldi_local_option'); +$forms['Import']['Excel'] = array( + 'Import/xls_col_names', + 'Import/xlsx_col_names'); +$forms['Import']['Ods'] = array( + 'Import/ods_col_names', + 'Import/ods_empty_rows', + 'Import/ods_recognize_percentages', + 'Import/ods_recognize_currency'); +$forms['Export']['Export_defaults'] = array( + 'Export/format', + 'Export/compression', + 'Export/remember_file_template', + 'Export/file_template_table', + 'Export/file_template_database', + 'Export/file_template_server'); ?> \ No newline at end of file diff --git a/setup/lib/validate.lib.php b/setup/lib/validate.lib.php index 34c5d98bb..47e81d10c 100644 --- a/setup/lib/validate.lib.php +++ b/setup/lib/validate.lib.php @@ -364,8 +364,8 @@ function validate_non_negative_number($path, $values) /** * Validates DefaultPropDisplay field * - * @param $path - * @param $values + * @param string $path + * @param array $values * @return array */ function validate_DefaultPropDisplay($path, $values) @@ -373,4 +373,30 @@ function validate_DefaultPropDisplay($path, $values) $result = preg_match('/^(?:horizontal|vertical|\d+)$/', $values[$path]); return array($path => ($result ? '' : __('Incorrect value'))); } + +/** + * Validates string length - must be 1 character long + * + * @param string $path + * @param array $values + * @return array + */ +function validate_str1($path, $values) +{ + $result = strlen($values[$path]) == 1; + return array($path => ($result ? '' : __('Incorrect value'))); +} + +/** + * Validates string length - must be 0 or 1 character long + * + * @param string $path + * @param array $values + * @return array + */ +function validate_str01($path, $values) +{ + $result = strlen($values[$path]) <= 1; + return array($path => ($result ? '' : __('Incorrect value'))); +} ?> \ No newline at end of file