diff --git a/ChangeLog b/ChangeLog index 0c547ae2d881..19ba60846846 100644 --- a/ChangeLog +++ b/ChangeLog @@ -54,6 +54,10 @@ VerboseMultiSubmit, ReplaceHelpImg - bug #3548491 [interface] Inline query editor doesn't work from search results - bug #3547825 [edit] BLOB download no longer works - bug #3541966 [config] Error in generated configuration arrray +- bug #3553551 [GUI] Invalid HTML code in multi submits confirmation form + +3.5.2.1 (2012-08-03) +- [security] Fixed local path disclosure vulnerability, see PMASA-2012-3 3.5.2.0 (2012-07-07) - bug #3521416 [interface] JS error when editing index @@ -163,11 +167,11 @@ VerboseMultiSubmit, ReplaceHelpImg + patch #3303195 [interface] Checkbox to have SQL input remain - patch #3472899 [export] Fixed CSV escape for the export - patch #3475424 [import] Fixed CSV escape for the import -- bug #3482734 [interface] No warning on syntax error in search form +- bug #3482734 [interface] No warning on syntax error in search form - bug #3423717 [core] Improved detection of SSL connection + FULLTEXT support for InnoDB, starting with MySQL 5.6.4 - bug #3497151 [interface] Duplicate inline query edit box -- bug #3504567 [mime] Description of the transformation missing in the tooltip +- bug #3504567 [mime] Description of the transformation missing in the tooltip 3.4.11.0 (2012-04-14) - bug #3486970 [import] Exception on XML import diff --git a/changelog.php b/changelog.php index 1467ee05768a..2a44ea640fe6 100644 --- a/changelog.php +++ b/changelog.php @@ -11,6 +11,8 @@ */ require 'libraries/common.inc.php'; +$response = PMA_Response::getInstance()->disable(); + $filename = CHANGELOG_FILE; /** diff --git a/db_operations.php b/db_operations.php index 4b54c2c364d2..97561b1601d3 100644 --- a/db_operations.php +++ b/db_operations.php @@ -73,7 +73,6 @@ "sql", 'libraries/plugins/export/', array( - 'export_type' => $export_type, 'single_table' => isset($single_table) ) ); diff --git a/js/functions.js b/js/functions.js index b6195c13bf92..e7877e0db2fd 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2598,33 +2598,37 @@ $(function() { $(this).dialog('close'); }; $.get($(this).attr('href'), {'ajax_request': true}, function(data) { - $('
') - .dialog({ - title: PMA_messages['strChangePassword'], - width: 600, - close: function(ev, ui) { - $(this).remove(); - }, - buttons : button_options, - modal: true - }) - .append(data.message); - // for this dialog, we remove the fieldset wrapping due to double headings - $("fieldset#fieldset_change_password") - .find("legend").remove().end() - .find("table.noclick").unwrap().addClass("some-margin") - .find("input#text_pma_pw").focus(); - displayPasswordGenerateButton(); - $('#fieldset_change_password_footer').hide(); - PMA_ajaxRemoveMessage($msgbox); - $('#change_password_form').bind('submit', function (e) { - e.preventDefault(); - $(this) - .closest('.ui-dialog') - .find('.ui-dialog-buttonpane .ui-button') - .first() - .click(); - }); + if (data.success) { + $('
') + .dialog({ + title: PMA_messages['strChangePassword'], + width: 600, + close: function(ev, ui) { + $(this).remove(); + }, + buttons : button_options, + modal: true + }) + .append(data.message); + // for this dialog, we remove the fieldset wrapping due to double headings + $("fieldset#fieldset_change_password") + .find("legend").remove().end() + .find("table.noclick").unwrap().addClass("some-margin") + .find("input#text_pma_pw").focus(); + displayPasswordGenerateButton(); + $('#fieldset_change_password_footer').hide(); + PMA_ajaxRemoveMessage($msgbox); + $('#change_password_form').bind('submit', function (e) { + e.preventDefault(); + $(this) + .closest('.ui-dialog') + .find('.ui-dialog-buttonpane .ui-button') + .first() + .click(); + }); + } else { + PMA_ajaxShowMessage(data.error, false); + } }); // end $.get() }); // end handler for change password anchor }); // end $() for Change Password diff --git a/js/tbl_change.js b/js/tbl_change.js index 2b017154e16e..2ebead15ea42 100644 --- a/js/tbl_change.js +++ b/js/tbl_change.js @@ -286,10 +286,9 @@ $(function() { $('select[name="submit_type"]').bind('change', function (e) { var $table = $('table.insertRowTable'); var auto_increment_column = $table.find('input[name^="auto_increment"]').attr('name'); - var prev_value_field = $table.find('input[name="' + auto_increment_column.replace('auto_increment', 'fields_prev') + '"]'); - var value_field = $table.find('input[name="' + auto_increment_column.replace('auto_increment', 'fields') + '"]'); - if (auto_increment_column) { + var prev_value_field = $table.find('input[name="' + auto_increment_column.replace('auto_increment', 'fields_prev') + '"]'); + var value_field = $table.find('input[name="' + auto_increment_column.replace('auto_increment', 'fields') + '"]'); var previous_value = $(prev_value_field).val(); if (previous_value !== undefined) { if ($(this).val() == 'insert' || $(this).val() == 'insertignore' || $(this).val() == 'showinsert' ) { @@ -299,7 +298,6 @@ $(function() { } } } - }); diff --git a/libraries/CommonFunctions.class.php b/libraries/CommonFunctions.class.php index de5a172d4281..6ffa5095907b 100644 --- a/libraries/CommonFunctions.class.php +++ b/libraries/CommonFunctions.class.php @@ -2302,7 +2302,9 @@ public function getUniqueCondition( $con_key = $this->backquote($meta->table) . '.' . $this->backquote($meta->orgname); } // end if... else... - $condition = ' ' . $con_key . ' '; + $condition = ($fields_cnt == 1) + ? ' CHAR_LENGTH(' . $con_key . ') ' + : ' ' . $con_key . ' '; if (! isset($row[$i]) || is_null($row[$i])) { $con_val = 'IS NULL'; @@ -2330,7 +2332,9 @@ public function getUniqueCondition( $con_val = '= CAST(0x' . bin2hex($row[$i]) . ' AS BINARY)'; } else { // this blob won't be part of the final condition - $con_val = null; + $con_val = ($fields_cnt == 1) + ? ' = '. strlen($row[$i]) + : null; } } elseif (in_array($meta->type, $this->getGISDatatypes()) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 3a528efbcb96..d67237f1a563 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -66,6 +66,9 @@ class PMA_DisplayResults const TABLE_TYPE_INNO_DB = 'InnoDB'; const ALL_ROWS = 'all'; const QUERY_TYPE_SELECT = 'SELECT'; + + const ROUTINE_PROCEDURE = 'procedure'; + const ROUTINE_FUNCTION = 'function'; // Declare global fields @@ -2685,7 +2688,9 @@ private function _getRowValues( $fields_meta = $this->__get('_fields_meta'); $highlight_columns = $this->__get('_highlight_columns'); $mime_map = $this->__get('_mime_map'); - + + $row_info = $this->_getRowInfoForSpecialLinks($row, $col_order); + for ($j = 0; $j < $this->__get('_fields_cnt'); ++$j) { // assign $i with appropriate column order @@ -2784,7 +2789,8 @@ private function _getRowValues( $vertical_display = $this->__get('_vertical_display'); // Check whether the field needs to display with syntax highlighting - if ($this->_isNeedToSytaxHighliight($meta->name) + + if ($this->_isNeedToSytaxHighlight($meta->name) && (trim($row[$i]) != '') ) { @@ -2806,9 +2812,32 @@ private function _getRowValues( '_', '/', $this->sytax_highlighting_column_info[strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][strtolower($meta->name)][2] ); + + } + + // Check for the predefined fields need to show as link in schemas + include_once 'libraries/special_schema_links.lib.php'; + + if (isset($GLOBALS['special_schema_links']) + && ($this->_isFieldNeedToLink(strtolower($meta->name))) + ) { + + $linking_url = $this->_getSpecialLinkUrl($row[$i], $row_info, strtolower($meta->name)); + include_once "libraries/plugins/transformations/Text_Plain_Link.class.php"; + $transformation_plugin = new Text_Plain_Link(null); - } + $transform_options = array( + 0 => $linking_url, + 2 => true + ); + $meta->mimetype = str_replace( + '_', '/', + 'Text/Plain' + ); + + } + if ($meta->numeric == 1) { // n u m e r i c @@ -3007,14 +3036,108 @@ private function _gatherLinksForLaterOutputs( * * @return boolean */ - private function _isNeedToSytaxHighliight($field) { + private function _isNeedToSytaxHighlight($field) { if (! empty($this->sytax_highlighting_column_info[strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][strtolower($field)])) { return true; } return false; } - + + /** + * Check whether the field needs to be link + * + * @param string $field field to check + * + * @return boolean + */ + private function _isFieldNeedToLink($field) { + if (! empty($GLOBALS['special_schema_links'][strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][$field])) { + return true; + } + return false; + } + + + /** + * Get link for display special schema links + * + * @param string $column_value column value + * @param array $row_info information about row + * @param string $field_name column name + * + * @return string generated link + */ + private function _getSpecialLinkUrl($column_value, $row_info, $field_name) + { + + $linking_url_params = array(); + $link_relations = $GLOBALS['special_schema_links'][strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][$field_name]; + + if (! is_array($link_relations['link_param'])) { + $linking_url_params[$link_relations['link_param']] = $column_value; + } else { + // Consider only the case of creating link for column field + // sql query need to be pass as url param + $sql = 'SELECT `'.$column_value.'` FROM `'. $row_info[$link_relations['link_param'][1]] .'`.`'. $row_info[$link_relations['link_param'][2]] .'`'; + $linking_url_params[$link_relations['link_param'][0]] = $sql; + } + + + if (! empty($link_relations['link_dependancy_params'])) { + + foreach ($link_relations['link_dependancy_params'] as $new_param) { + + // If param_info is an array, set the key and value + // from that array + if (is_array($new_param['param_info'])) { + $linking_url_params[$new_param['param_info'][0]] = $new_param['param_info'][1]; + } else { + $linking_url_params[$new_param['param_info']] = $row_info[strtolower($new_param['column_name'])]; + + // Special case 1 - when executing routines, according + // to the type of the routine, url param changes + if (!empty($row_info['routine_type'])){ + if (strtolower($row_info['routine_type']) == self::ROUTINE_PROCEDURE) { + $linking_url_params['execute_routine'] = 1; + } else if (strtolower($row_info['routine_type']) == self::ROUTINE_FUNCTION) { + $linking_url_params['execute_dialog'] = 1; + } + } + } + + } + } + + return $link_relations['default_page'] . PMA_generate_common_url($linking_url_params); + + } + + + /** + * Prepare row information for display special links + * + * @param array $row current row data + * @param array $col_order the column order + * + * @return array $row_info associative array with column nama -> value + */ + private function _getRowInfoForSpecialLinks($row, $col_order) + { + + $row_info = array(); + $fields_meta = $this->__get('_fields_meta'); + + for ($n = 0; $n < $this->__get('_fields_cnt'); ++$n) { + $m = $col_order ? $col_order[$n] : $n; + $row_info[strtolower($fields_meta[$m]->name)] = $row[$m]; + } + + return $row_info; + + } + + /** * Get url sql query without conditions to shorten URLs * @@ -3520,7 +3643,8 @@ private function _getDataCellForBlobColumns( // replacements will be made if ((PMA_strlen($column) > $GLOBALS['cfg']['LimitChars']) && ($_SESSION['tmp_user_values']['display_text'] == self::DISPLAY_PARTIAL_TEXT) - && ! $this->_isNeedToSytaxHighliight(strtolower($meta->name)) + && ! $this->_isNeedToSytaxHighlight(strtolower($meta->name)) + ) { $column = PMA_substr($column, 0, $GLOBALS['cfg']['LimitChars']) . '...'; diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index 143c903db9c2..2cb309053f02 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -326,7 +326,8 @@ public function getDisplay() $retval .= ob_get_contents(); ob_end_clean(); } - } else if (! $this->_isAjax) { + } + if (! $this->_isAjax) { $retval .= ""; } } diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index d6de4af77e96..1a1160cee934 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -36,22 +36,11 @@ class PMA_Menu * @access private * @var string */ - private $_table; - - private $_common_functions; - + private $_table; /** - * Get CommmonFunctions - * - * @return CommonFunctions object + * @var object A reference to the common functions object */ - public function getCommonFunctions() - { - if (is_null($this->_common_functions)) { - $this->_common_functions = PMA_CommonFunctions::getInstance(); - } - return $this->_common_functions; - } + private $_commonFunctions; /** * Creates a new instance of PMA_Menu @@ -67,6 +56,7 @@ public function __construct($server, $db, $table) $this->_server = $server; $this->_db = $db; $this->_table = $table; + $this->_commonFunctions = PMA_commonFunctions::getInstance(); } /** @@ -92,7 +82,7 @@ public function getDisplay() if (isset($GLOBALS['buffer_message'])) { $buffer_message = $GLOBALS['buffer_message']; } - $retval .= $this->getCommonFunctions()->getMessage($GLOBALS['message']); + $retval .= $this->_commonFunctions->getMessage($GLOBALS['message']); unset($GLOBALS['message']); if (isset($buffer_message)) { $GLOBALS['buffer_message'] = $buffer_message; @@ -118,7 +108,7 @@ private function _getMenu() } else { $tabs = $this->_getServerTabs(); } - return $this->getCommonFunctions()->getHtmlTabs($tabs, $url_params); + return $this->_commonFunctions->getHtmlTabs($tabs, $url_params); } /** @@ -147,7 +137,7 @@ private function _getBreadcrumbs() $retval .= "
"; $retval .= "
"; if ($GLOBALS['cfg']['NavigationBarIconic']) { - $retval .= $this->getCommonFunctions()->getImage( + $retval .= $this->_commonFunctions->getImage( 's_host.png', '', array('class' => 'item') @@ -164,7 +154,7 @@ private function _getBreadcrumbs() if (strlen($this->_db)) { $retval .= $separator; if ($GLOBALS['cfg']['NavigationBarIconic']) { - $retval .= $this->getCommonFunctions()->getImage( + $retval .= $this->_commonFunctions->getImage( 's_db.png', '', array('class' => 'item') @@ -187,7 +177,7 @@ private function _getBreadcrumbs() $retval .= $separator; if ($GLOBALS['cfg']['NavigationBarIconic']) { $icon = $tbl_is_view ? 'b_views.png' : 's_tbl.png'; - $retval .= $this->getCommonFunctions()->getImage( + $retval .= $this->_commonFunctions->getImage( $icon, '', array('class' => 'item') @@ -273,6 +263,10 @@ private function _getTableTabs() $tabs['search']['icon'] = 'b_search.png'; $tabs['search']['text'] = __('Search'); $tabs['search']['link'] = 'tbl_select.php'; + $tabs['search']['active'] = in_array( + basename($GLOBALS['PMA_PHP_SELF']), + array('tbl_select.php', 'tbl_zoom_select.php') + ); if (! $db_is_information_schema) { $tabs['insert']['icon'] = 'b_insrow.png'; @@ -305,7 +299,7 @@ private function _getTableTabs() } if (! $db_is_information_schema && ! PMA_DRIZZLE - && $this->getCommonFunctions()->currentUserHasPrivilege('TRIGGER', $this->_db, $this->_table) + && $this->_commonFunctions->currentUserHasPrivilege('TRIGGER', $this->_db, $this->_table) && ! $tbl_is_view ) { $tabs['triggers']['link'] = 'tbl_triggers.php'; @@ -347,15 +341,6 @@ private function _getDbTabs() $tabs = array(); - /** - * export, search and qbe links if there is at least one table - */ - if ($num_tables == 0) { - $tabs['qbe']['warning'] = __('Database seems to be empty!'); - $tabs['search']['warning'] = __('Database seems to be empty!'); - $tabs['export']['warning'] = __('Database seems to be empty!'); - } - $tabs['structure']['link'] = 'db_structure.php'; $tabs['structure']['text'] = __('Structure'); $tabs['structure']['icon'] = 'b_props.png'; @@ -368,14 +353,23 @@ private function _getDbTabs() $tabs['search']['text'] = __('Search'); $tabs['search']['icon'] = 'b_search.png'; $tabs['search']['link'] = 'db_search.php'; + if ($num_tables == 0) { + $tabs['search']['warning'] = __('Database seems to be empty!'); + } $tabs['qbe']['text'] = __('Query'); $tabs['qbe']['icon'] = 's_db.png'; $tabs['qbe']['link'] = 'db_qbe.php'; + if ($num_tables == 0) { + $tabs['qbe']['warning'] = __('Database seems to be empty!'); + } $tabs['export']['text'] = __('Export'); $tabs['export']['icon'] = 'b_export.png'; $tabs['export']['link'] = 'db_export.php'; + if ($num_tables == 0) { + $tabs['export']['warning'] = __('Database seems to be empty!'); + } if (! $db_is_information_schema) { $tabs['import']['link'] = 'db_import.php'; @@ -401,14 +395,14 @@ private function _getDbTabs() } if (PMA_MYSQL_INT_VERSION >= 50106 && ! PMA_DRIZZLE - && $this->getCommonFunctions()->currentUserHasPrivilege('EVENT', $this->_db) + && $this->_commonFunctions->currentUserHasPrivilege('EVENT', $this->_db) ) { $tabs['events']['link'] = 'db_events.php'; $tabs['events']['text'] = __('Events'); $tabs['events']['icon'] = 'b_events.png'; } if (! PMA_DRIZZLE - && $this->getCommonFunctions()->currentUserHasPrivilege('TRIGGER', $this->_db) + && $this->_commonFunctions->currentUserHasPrivilege('TRIGGER', $this->_db) ) { $tabs['triggers']['link'] = 'db_triggers.php'; $tabs['triggers']['text'] = __('Triggers'); diff --git a/libraries/Table.class.php b/libraries/Table.class.php index c646f28eca1b..c6138e55a946 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -65,12 +65,12 @@ class PMA_Table * @var array messages */ var $messages = array(); - + private $_common_functions; - + /** * Get CommmonFunctions - * + * * @return CommonFunctions object */ public function getCommonFunctions() @@ -201,9 +201,9 @@ function getFullName($backquoted = false) */ static public function isView($db = null, $table = null) { - + $common_functions = PMA_CommonFunctions::getInstance(); - + if (empty($db) || empty($table)) { return false; } @@ -319,11 +319,10 @@ static public function sGetToolTip($db, $table) static public function sGetStatusInfo($db, $table, $info = null, $force_read = false, $disable_error = false ) { - - if ($_SESSION['is_multi_query']) { + if (! empty($_SESSION['is_multi_query'])) { $disable_error = true; } - + if (! isset(PMA_Table::$cache[$db][$table]) || $force_read) { PMA_DBI_get_tables_full($db, $table); } @@ -383,7 +382,7 @@ static function generateFieldSpec($name, $type, $index, $length = '', $default_type = 'USER_DEFINED', $default_value = '', $extra = '', $comment = '', &$field_primary = null, $move_to = '' ) { - + $common_functions = PMA_CommonFunctions::getInstance(); $is_timestamp = strpos(strtoupper($type), 'TIMESTAMP') !== false; @@ -519,9 +518,9 @@ static function generateFieldSpec($name, $type, $index, $length = '', static public function countRecords($db, $table, $force_exact = false, $is_view = null ) { - + $common_functions = PMA_CommonFunctions::getInstance(); - + if (isset(PMA_Table::$cache[$db][$table]['ExactRows'])) { $row_count = PMA_Table::$cache[$db][$table]['ExactRows']; } else { @@ -649,7 +648,7 @@ static public function generateAlter($oldcol, $newcol, $type, $length, static public function duplicateInfo($work, $pma_table, $get_fields, $where_fields, $new_fields ) { - + $common_functions = PMA_CommonFunctions::getInstance(); $last_id = -1; @@ -732,7 +731,7 @@ static public function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode ) { global $err_url; - + $common_functions = PMA_CommonFunctions::getInstance(); /* Try moving table directly */ @@ -787,7 +786,7 @@ static public function moveCopy($source_db, $source_table, $target_db, // get Export SQL instance $export_sql_plugin = PMA_getPlugin( "export", - "sql", + "sql", 'libraries/plugins/export/', array( 'export_type' => $export_type, diff --git a/libraries/TableSearch.class.php b/libraries/TableSearch.class.php index 457e8d16af69..13351c6cb1e3 100644 --- a/libraries/TableSearch.class.php +++ b/libraries/TableSearch.class.php @@ -80,12 +80,12 @@ class PMA_TableSearch * @var array */ private $_foreigners; - + private $_common_functions; - + /** * Get CommmonFunctions - * + * * @return CommonFunctions object */ public function getCommonFunctions() @@ -95,7 +95,7 @@ public function getCommonFunctions() } return $this->_common_functions; } - + /** * Public Constructor @@ -103,7 +103,6 @@ public function getCommonFunctions() * @param string $db Database name * @param string $table Table name * @param string $searchType Whether normal or zoom search - * */ public function __construct($db, $table, $searchType) { @@ -134,6 +133,7 @@ public function getColumnNames() * Gets all the columns of a table along with their types, collations * and whether null or not. * + * @return void */ private function _loadTableInfo() { @@ -445,38 +445,34 @@ private function _getInputbox($foreignData, $column_name, $column_type, */ private function _getEnumWhereClause($criteriaValues, $func_type) { - $where = ''; $common_functions = PMA_CommonFunctions::getInstance(); - if (! empty($criteriaValues)) { - if (! is_array($criteriaValues)) { - $criteriaValues = explode(',', $criteriaValues); - } - $enum_selected_count = count($criteriaValues); - if ($func_type == '=' && $enum_selected_count > 1) { - $func_type = 'IN'; - $parens_open = '('; - $parens_close = ')'; + if (! is_array($criteriaValues)) { + $criteriaValues = explode(',', $criteriaValues); + } + $enum_selected_count = count($criteriaValues); + if ($func_type == '=' && $enum_selected_count > 1) { + $func_type = 'IN'; + $parens_open = '('; + $parens_close = ')'; - } elseif ($func_type == '!=' && $enum_selected_count > 1) { - $func_type = 'NOT IN'; - $parens_open = '('; - $parens_close = ')'; + } elseif ($func_type == '!=' && $enum_selected_count > 1) { + $func_type = 'NOT IN'; + $parens_open = '('; + $parens_close = ')'; - } else { - $parens_open = ''; - $parens_close = ''; - } - $enum_where = '\'' - . $common_functions->sqlAddSlashes($criteriaValues[0]) . '\''; - for ($e = 1; $e < $enum_selected_count; $e++) { - $enum_where .= ', \'' - . $common_functions->sqlAddSlashes($criteriaValues[$e]) . '\''; - } - - $where = ' ' . $func_type . ' ' . $parens_open - . $enum_where . $parens_close; + } else { + $parens_open = ''; + $parens_close = ''; } - return $where; + $enum_where = '\'' + . $common_functions->sqlAddSlashes($criteriaValues[0]) . '\''; + for ($e = 1; $e < $enum_selected_count; $e++) { + $enum_where .= ', \'' + . $common_functions->sqlAddSlashes($criteriaValues[$e]) . '\''; + } + + return ' ' . $func_type . ' ' . $parens_open + . $enum_where . $parens_close; } /** @@ -548,9 +544,9 @@ private function _getGeomWhereClause($criteriaValues, $names, private function _getWhereClause($criteriaValues, $names, $types, $collations, $func_type, $unaryFlag, $geom_func = null ) { - + $common_functions = PMA_CommonFunctions::getInstance(); - + // If geometry function is set if ($geom_func != null && trim($geom_func) != '') { return $this->_getGeomWhereClause( @@ -564,7 +560,7 @@ private function _getWhereClause($criteriaValues, $names, $types, $collations, $criteriaValues = ''; $where = $backquoted_name . ' ' . $func_type; - } elseif (strncasecmp($types, 'enum', 4) == 0) { + } elseif (strncasecmp($types, 'enum', 4) == 0 && ! empty($criteriaValues)) { $where = $backquoted_name; $where .= $this->_getEnumWhereClause($criteriaValues, $func_type); @@ -770,7 +766,7 @@ private function _getOptions() $html_output .= $this->getCommonFunctions()->getDivForSliderEffect( 'searchoptions', __('Options') ); - + /** * Displays columns select list for selecting distinct columns in the search */ @@ -834,7 +830,7 @@ private function _getOptions() ); unset($choices); - $html_output .= '
'; + $html_output .= '
'; return $html_output; } @@ -1112,48 +1108,41 @@ private function _getFormTag($goto) */ public function getSelectionForm($goto, $dataLabel = null) { - $html_output = ''; - $html_output .= '
'; $url_params = array(); $url_params['db'] = $this->_db; $url_params['table'] = $this->_table; - $html_output .= $this->getCommonFunctions()->getHtmlTabs( - $this->_getSubTabs(), $url_params, 'topmenu2' - ); - $html_output .= $this->_getFormTag($goto); + $html_output = ''; + $html_output .= '
'; - $html_output .= '
'; - $html_output .= ($this->_searchType == 'zoom' - ? '' : '
'); + $html_output .= $this->_getFormTag($goto); - // Set caption for fieldset if ($this->_searchType == 'zoom') { + $html_output .= ''; } else { + $html_output .= ''; $html_output .= $this->_getOptions(); + $html_output .= '
'; } /** @@ -1165,12 +1154,7 @@ public function getSelectionForm($goto, $dataLabel = null) . ($this->_searchType == 'zoom' ? '" id="inputFormSubmitId"' : '" ') . 'value="' . __('Go') . '" />'; $html_output .= '
'; - if ($this->_searchType == 'zoom') { - $html_output = '
' - . $html_output . '
'; - } else { - $html_output .= '
'; - } + $html_output .= '
'; return $html_output; } diff --git a/libraries/Tracker.class.php b/libraries/Tracker.class.php index 0276d1e68446..9d8c430dc5fd 100644 --- a/libraries/Tracker.class.php +++ b/libraries/Tracker.class.php @@ -371,7 +371,7 @@ static public function deleteTracking($dbname, $tablename) . $common_functions->sqlAddSlashes($dbname) . "'" . " AND `table_name` = '" . $common_functions->sqlAddSlashes($tablename) . "'"; - $result = PMA_query_as_controluser($sql_query); + $result = PMA_queryAsControlUser($sql_query); return $result; } diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 2554563f75eb..680db4d2acde 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -317,7 +317,7 @@ /> + echo ($default_fk_check_value) ? ' checked="checked"' : '' ?>/> @@ -326,6 +326,7 @@ '; exit; } elseif ($mult_btn == __('Yes')) { @@ -457,21 +458,21 @@ break; case 'add_prefix_tbl': - $newtablename = $add_prefix . $selected[$i]; + $newtablename = $_POST['add_prefix'] . $selected[$i]; $a_query = 'ALTER TABLE ' . $common_functions->backquote($selected[$i]) . ' RENAME ' . $common_functions->backquote($newtablename); // ADD PREFIX TO TABLE NAME $run_parts = true; break; case 'replace_prefix_tbl': $current = $selected[$i]; - $newtablename = preg_replace("/^" . $from_prefix . "/", $to_prefix, $current); + $newtablename = preg_replace("/^" . $_POST['from_prefix'] . "/", $_POST['to_prefix'], $current); $a_query = 'ALTER TABLE ' . $common_functions->backquote($selected[$i]) . ' RENAME ' . $common_functions->backquote($newtablename); // CHANGE PREFIX PATTERN $run_parts = true; break; case 'copy_tbl_change_prefix': $current = $selected[$i]; - $newtablename = preg_replace("/^" . $from_prefix . "/", $to_prefix, $current); + $newtablename = preg_replace("/^" . $_POST['from_prefix'] . "/", $_POST['to_prefix'], $current); $a_query = 'CREATE TABLE ' . $common_functions->backquote($newtablename) . ' SELECT * FROM ' . $common_functions->backquote($selected[$i]); // COPY TABLE AND CHANGE PREFIX PATTERN $run_parts = true; break; diff --git a/libraries/plugin_interface.lib.php b/libraries/plugin_interface.lib.php index f4b9888f3272..2a83cf0a670e 100644 --- a/libraries/plugin_interface.lib.php +++ b/libraries/plugin_interface.lib.php @@ -199,13 +199,16 @@ function PMA_pluginGetChoice($section, $name, &$list, $cfgname = null) $plugin_name = strtolower(substr(get_class($plugin), strlen($section))); $ret .= ''. "\n"; } + return $ret; } @@ -439,6 +442,7 @@ function PMA_pluginGetOptions($section, &$list) $ret .= '

' . PMA_getString($plugin->getProperties()->getText()) . '

'; + $no_options = true; if ($plugin->getProperties()->getOptions() != null && count($plugin->getProperties()->getOptions()) > 0 ) { diff --git a/libraries/plugins/auth/AuthenticationCookie.class.php b/libraries/plugins/auth/AuthenticationCookie.class.php index a4bd88982fb6..01ca6da1db61 100644 --- a/libraries/plugins/auth/AuthenticationCookie.class.php +++ b/libraries/plugins/auth/AuthenticationCookie.class.php @@ -73,7 +73,12 @@ public function auth() if ($response->isAjax()) { $response->isSuccess(false); if (! empty($conn_error)) { - $response->addJSON('message', $conn_error); + $response->addJSON( + 'message', + PMA_Message::error( + $conn_error + ) + ); } else { $response->addJSON( 'message', @@ -688,4 +693,4 @@ public function blowfishDecrypt($encdata, $secret) public function update (SplSubject $subject) { } -} \ No newline at end of file +} diff --git a/libraries/plugins/export/README b/libraries/plugins/export/README index 3d69bc1bd7e6..47d0c4fd4fa6 100644 --- a/libraries/plugins/export/README +++ b/libraries/plugins/export/README @@ -70,32 +70,56 @@ class Export[Name] extends ExportPlugin */ protected function setProperties() { - // optional - get globals - // set properties - $this->properties = array( // set name of your plugin - 'text' => __('[Name]'), // text to be displayed as choice - 'extension' => '[ext]', // extension this plugin can handle - 'options' => array(), // array of options - 'options_text' => __('Options') - ); + $props = 'libraries/properties/'; + // include the main class for properties for the export plug-ins + include_once "$props/plugins/ExportPluginProperties.class.php"; + // include the group properties classes + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + // include the needed single property items + include_once "$props/options/items/RadioPropertyItem.class.php"; + + $exportPluginProperties = new ExportPluginProperties(); + $exportPluginProperties->setText('[name]'); // the name of your plug-in + $exportPluginProperties->setExtension('[ext]'); // extension this plug-in can handle + $exportPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $exportPluginProperties + // this will be shown as "Format specific options" + $exportSpecificOptions = new OptionsPropertyRootGroup(); + $exportSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); // optional : - // type - bool or text, or begin/end group_subgroup + // create primary items and add them to the group + // type - one of the classes listed in libraries/properties/options/items/ // name - form element name // text - description in GUI - // size - size of text element (optional) - // len - maximal size of input (optional) - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - [..], + // size - size of text element + // len - maximal size of input + // values - possible values of the item + $leaf = new RadioPropertyItem(); + $leaf->setName("structure_or_data"); + $leaf->setValues( array( - 'type' => 'end_group' + 'structure' => __('structure'), + 'data' => __('data'), + 'structure_and_data' => __('structure and data') ) ); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $exportSpecificOptions->addProperty($generalOptions); + + // set the options for the export plugin property item + $exportPluginProperties->setOptions($exportSpecificOptions); + $this->properties = $exportPluginProperties; } /** diff --git a/libraries/plugins/export/todo_change_properties/ExportMediawiki.class.php b/libraries/plugins/export/todo_change_properties/ExportMediawiki.class.php deleted file mode 100644 index eed2ad2c92e4..000000000000 --- a/libraries/plugins/export/todo_change_properties/ExportMediawiki.class.php +++ /dev/null @@ -1,357 +0,0 @@ -setProperties(); - } - - /** - * Sets the export MediaWiki properties - * - * @return void - */ - protected function setProperties() - { - $this->properties = array( - 'text' => __('MediaWiki Table'), - 'extension' => 'mediawiki', - 'mime_type' => 'text/plain', - 'options' => array(), - 'options_text' => __('Options') - ); - - // general options - $this->properties['options'][] = array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ); - - // what to dump (structure/data/both) - $this->properties['options'][] = array( - 'type' => 'begin_subgroup', - 'subgroup_header' => array( - 'type' => 'message_only', - 'text' => __('Dump table') - ) - ); - $this->properties['options'][] = array( - 'type' => 'radio', - 'name' => 'structure_or_data', - 'values' => array( - 'structure' => __('structure'), - 'data' => __('data'), - 'structure_and_data' => __('structure and data') - ) - ); - $this->properties['options'][] = array( - 'type' => 'end_subgroup' - ); - - // export table name - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'caption', - 'text' => __('Export table names') - ); - - // export table headers - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'headers', - 'text' => __('Export table headers') - ); - - // end general options - $this->properties['options'][] = array( - 'type' => 'end_group' - ); - } - - /** - * This method is called when any PluginManager to which the observer - * is attached calls PluginManager::notify() - * - * @param SplSubject $subject The PluginManager notifying the observer - * of an update. - * - * @return void - */ - public function update (SplSubject $subject) - { - } - - /** - * Outputs export header - * - * @return bool Whether it succeeded - */ - public function exportHeader () - { - return true; - } - - /** - * Outputs export footer - * - * @return bool Whether it succeeded - */ - public function exportFooter () - { - return true; - } - - /** - * Outputs database header - * - * @param string $db Database name - * - * @return bool Whether it succeeded - */ - public function exportDBHeader ($db) - { - return true; - } - - /** - * Outputs database footer - * - * @param string $db Database name - * - * @return bool Whether it succeeded - */ - public function exportDBFooter ($db) - { - return true; - } - - /** - * Outputs CREATE DATABASE statement - * - * @param string $db Database name - * - * @return bool Whether it succeeded - */ - public function exportDBCreate($db) - { - return true; - } - - /** - * Outputs table's structure - * - * @param string $db database name - * @param string $table table name - * @param string $crlf the end of line sequence - * @param string $error_url the url to go back in case of error - * @param string $export_mode 'create_table','triggers','create_view', - * 'stand_in' - * @param string $export_type 'server', 'database', 'table' - * @param bool $do_relation whether to include relation comments - * @param bool $do_comments whether to include the pmadb-style column - * comments as comments in the structure; this is - * deprecated but the parameter is left here - * because export.php calls exportStructure() - * also for other export types which use this - * parameter - * @param bool $do_mime whether to include mime comments - * @param bool $dates whether to include creation/update/check dates - * - * @return bool Whether it succeeded - */ - public function exportStructure( - $db, - $table, - $crlf, - $error_url, - $export_mode, - $export_type, - $do_relation = false, - $do_comments = false, - $do_mime = false, - $dates = false - ) { - switch($export_mode) { - case 'create_table': - $columns = PMA_DBI_get_columns($db, $table); - $columns = array_values($columns); - $row_cnt = count($columns); - - // Print structure comment - $output = $this->_exportComment( - "Table structure for " - . PMA_CommonFunctions::getInstance()->backquote($table) - ); - - // Begin the table construction - $output .= "{| class=\"wikitable\" style=\"text-align:center;\"" - . $this->_exportCRLF(); - - // Add the table name - if ($GLOBALS['mediawiki_caption']) { - $output .= "|+'''" . $table . "'''" . $this->_exportCRLF(); - } - - // Add the table headers - if ($GLOBALS['mediawiki_headers']) { - $output .= "|- style=\"background:#ffdead;\"" . $this->_exportCRLF(); - $output .= "! style=\"background:#ffffff\" | " - . $this->_exportCRLF(); - for ($i = 0; $i < $row_cnt; ++$i) { - $output .= " | " . $columns[$i]['Field']. $this->_exportCRLF(); - } - } - - // Add the table structure - $output .= "|-" . $this->_exportCRLF(); - $output .= "! Type" . $this->_exportCRLF(); - for ($i = 0; $i < $row_cnt; ++$i) { - $output .= " | " . $columns[$i]['Type'] . $this->_exportCRLF(); - } - - $output .= "|-" . $this->_exportCRLF(); - $output .= "! Null" . $this->_exportCRLF(); - for ($i = 0; $i < $row_cnt; ++$i) { - $output .= " | " . $columns[$i]['Null'] . $this->_exportCRLF(); - } - - $output .= "|-" . $this->_exportCRLF(); - $output .= "! Default" . $this->_exportCRLF(); - for ($i = 0; $i < $row_cnt; ++$i) { - $output .= " | " . $columns[$i]['Default'] . $this->_exportCRLF(); - } - - $output .= "|-" . $this->_exportCRLF(); - $output .= "! Extra" . $this->_exportCRLF(); - for ($i = 0; $i < $row_cnt; ++$i) { - $output .= " | " . $columns[$i]['Extra'] . $this->_exportCRLF(); - } - - $output .= "|}" . str_repeat($this->_exportCRLF(), 2); - break; - } // end switch - - return PMA_exportOutputHandler($output); - } - - /** - * Outputs the content of a table in MediaWiki format - * - * @param string $db database name - * @param string $table table name - * @param string $crlf the end of line sequence - * @param string $error_url the url to go back in case of error - * @param string $sql_query SQL query for obtaining data - * - * @return bool Whether it succeeded - */ - public function exportData( - $db, - $table, - $crlf, - $error_url, - $sql_query - ) { - // Print data comment - $output = $this->_exportComment( - "Table data for ". PMA_CommonFunctions::getInstance()->backquote($table) - ); - - // Begin the table construction - // Use the "wikitable" class for style - // Use the "sortable" class for allowing tables to be sorted by column - $output .= "{| class=\"wikitable sortable\" style=\"text-align:center;\"" - . $this->_exportCRLF(); - - // Add the table name - if ($GLOBALS['mediawiki_caption']) { - $output .= "|+'''" . $table . "'''" . $this->_exportCRLF(); - } - - // Add the table headers - if ($GLOBALS['mediawiki_headers']) { - // Get column names - $column_names = PMA_DBI_get_column_names($db, $table); - - // Add column names as table headers - if ( ! is_null($column_names) ) { - // Use '|-' for separating rows - $output .= "|-" . $this->_exportCRLF(); - - // Use '!' for separating table headers - foreach ($column_names as $column) { - $output .= " ! " . $column . "" . $this->_exportCRLF(); - } - } - } - - // Get the table data from the database - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $fields_cnt = PMA_DBI_num_fields($result); - - while ($row = PMA_DBI_fetch_row($result)) { - $output .= "|-" . $this->_exportCRLF(); - - // Use '|' for separating table columns - for ($i = 0; $i < $fields_cnt; ++ $i) { - $output .= " | " . $row[$i] . "" . $this->_exportCRLF(); - } - } - - // End table construction - $output .= "|}" . str_repeat($this->_exportCRLF(), 2); - return PMA_exportOutputHandler($output); - } - - /** - * Outputs comments containing info about the exported tables - * - * @param string $text Text of comment - * - * @return string The formatted comment - */ - private function _exportComment($text = '') - { - // see http://www.mediawiki.org/wiki/Help:Formatting - $comment = $this->_exportCRLF(); - $comment .= '' . str_repeat($this->_exportCRLF(), 2); - - return $comment; - } - - /** - * Outputs CRLF - * - * @return string CRLF - */ - private function _exportCRLF() - { - // The CRLF expected by the mediawiki format is "\n" - return "\n"; - } -} -?> \ No newline at end of file diff --git a/libraries/plugins/export/todo_change_properties/ExportSql.class.php b/libraries/plugins/export/todo_change_properties/ExportSql.class.php deleted file mode 100644 index 46e1d949431e..000000000000 --- a/libraries/plugins/export/todo_change_properties/ExportSql.class.php +++ /dev/null @@ -1,1952 +0,0 @@ -setProperties(); - - // Avoids undefined variables, use NULL so isset() returns false - if (! isset($GLOBALS['sql_backquotes'])) { - $GLOBALS['sql_backquotes'] = null; - } - } - - /** - * Initialize the local variables that are used specific for export SQL - * - * @global array $mysql_charset_map - * @global string $sql_drop_table - * @global bool $sql_backquotes - * @global string $sql_constraints - * @global string $sql_constraints_query - * @global string $sql_drop_foreign_keys - * @global int $current_row - * - * @return void - */ - protected function initSpecificVariables() - { - global $sql_drop_table; - global $sql_backquotes; - global $sql_constraints; - global $sql_constraints_query; - global $sql_drop_foreign_keys; - $this->_setSqlDropTable($sql_drop_table); - $this->_setSqlBackquotes($sql_backquotes); - $this->_setSqlConstraints($sql_constraints); - $this->_setSqlConstraintsQuery($sql_constraints_query); - $this->_setSqlDropForeignKeys($sql_drop_foreign_keys); - } - - /** - * Sets the export SQL properties - * - * @return void - */ - protected function setProperties() - { - global $plugin_param; - $this->setPluginParam($plugin_param); - - $hide_sql = false; - $hide_structure = false; - if ($plugin_param['export_type'] == 'table' - && ! $plugin_param['single_table'] - ) { - $hide_structure = true; - $hide_sql = true; - } - if (! $hide_sql) { - $this->properties = array( - 'text' => __('SQL'), - 'extension' => 'sql', - 'mime_type' => 'text/x-sql', - 'options' => array(), - 'options_text' => __('Options') - ); - - $this->properties['options'][] = array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ); - - /* comments */ - $this->properties['options'][] = array( - 'type' => 'begin_subgroup', - 'subgroup_header' => array( - 'type' => 'bool', - 'name' => 'include_comments', - 'text' => __( - 'Display comments (includes info such as export' - . ' timestamp, PHP version, and server version)' - ) - ) - ); - $this->properties['options'][] = array( - 'type' => 'text', - 'name' => 'header_comment', - 'text' => __('Additional custom header comment (\n splits lines):') - ); - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'dates', - 'text' => __( - 'Include a timestamp of when databases were created, last' - . ' updated, and last checked' - ) - ); - if (! empty($GLOBALS['cfgRelation']['relation'])) { - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'relation', - 'text' => __('Display foreign key relationships') - ); - } - if (! empty($GLOBALS['cfgRelation']['mimework'])) { - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'mime', - 'text' => __('Display MIME types') - ); - } - $this->properties['options'][] = array( - 'type' => 'end_subgroup' - ); - /* end comments */ - - /* enclose in a transaction */ - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'use_transaction', - 'text' => __('Enclose export in a transaction'), - 'doc' => array( - 'programs', - 'mysqldump', - 'option_mysqldump_single-transaction' - ) - ); - - /* disable foreign key checks */ - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'disable_fk', - 'text' => __('Disable foreign key checks'), - 'doc' => array( - 'manual_MySQL_Database_Administration', - 'server-system-variables', - 'sysvar_foreign_key_checks' - ) - ); - - /* compatibility maximization */ - $compats = PMA_DBI_getCompatibilities(); - if (count($compats) > 0) { - $values = array(); - foreach ($compats as $val) { - $values[$val] = $val; - } - $this->properties['options'][] = array( - 'type' => 'select', - 'name' => 'compatibility', - 'text' => __( - 'Database system or older MySQL server to maximize output' - . ' compatibility with:' - ), - 'values' => $values, - 'doc' => array( - 'manual_MySQL_Database_Administration', - 'Server_SQL_mode' - ) - ); - unset($values); - } - - /* server export options */ - if ($plugin_param['export_type'] == 'server') { - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'drop_database', - 'text' => sprintf( - __('Add %s statement'), 'DROP DATABASE' - ) - ); - } - - /* what to dump (structure/data/both) */ - $this->properties['options'][] = array( - 'type' => 'begin_subgroup', - 'subgroup_header' => array( - 'type' => 'message_only', - 'text' => __('Dump table') - ) - ); - $this->properties['options'][] = array( - 'type' => 'radio', - 'name' => 'structure_or_data', - 'values' => array( - 'structure' => __('structure'), - 'data' => __('data'), - 'structure_and_data' => __('structure and data') - ) - ); - $this->properties['options'][] = array( - 'type' => 'end_subgroup' - ); - - $this->properties['options'][] = array( - 'type' => 'end_group' - ); - - /* begin Structure options */ - if (! $hide_structure) { - $this->properties['options'][] = array( - 'type' => 'begin_group', - 'name' => 'structure', - 'text' => __('Object creation options'), - 'force' => 'data' - ); - - /* begin SQL Statements */ - $this->properties['options'][] = array( - 'type' => 'begin_subgroup', - 'subgroup_header' => array( - 'type' => 'message_only', - 'name' => 'add_statements', - 'text' => __('Add statements:') - ) - ); - if ($plugin_param['export_type'] == 'table') { - if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) { - $drop_clause = 'DROP VIEW'; - } else { - $drop_clause = 'DROP TABLE'; - } - } else { - if (PMA_DRIZZLE) { - $drop_clause = 'DROP TABLE'; - } else { - $drop_clause = 'DROP TABLE / VIEW / PROCEDURE' - . ' / FUNCTION'; - if (PMA_MYSQL_INT_VERSION > 50100) { - $drop_clause .= ' / EVENT'; - } - } - } - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'drop_table', - 'text' => sprintf(__('Add %s statement'), $drop_clause) - ); - // Drizzle doesn't support procedures and functions - if (! PMA_DRIZZLE) { - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'procedure_function', - 'text' => sprintf( - __('Add %s statement'), - 'CREATE PROCEDURE / FUNCTION' - . (PMA_MYSQL_INT_VERSION > 50100 - ? ' / EVENT' : '') - ) - ); - } - - /* begin CREATE TABLE statements*/ - $this->properties['options'][] = array( - 'type' => 'begin_subgroup', - 'subgroup_header' => array( - 'type' => 'bool', - 'name' => 'create_table_statements', - 'text' => __('CREATE TABLE options:') - ) - ); - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'if_not_exists', - 'text' => 'IF NOT EXISTS' - ); - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'auto_increment', - 'text' => 'AUTO_INCREMENT' - ); - $this->properties['options'][] = array( - 'type' => 'end_subgroup' - ); - /* end CREATE TABLE statements */ - - $this->properties['options'][] = array( - 'type' => 'end_subgroup' - ); - /* end SQL statements */ - - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'backquotes', - 'text' => __( - 'Enclose table and column names with backquotes ' - . '(Protects column and table names formed with' - . ' special characters or keywords)' - ) - ); - - $this->properties['options'][] = array( - 'type' => 'end_group' - ); - } - /* end Structure options */ - - /* begin Data options */ - $this->properties['options'][] = array( - 'type' => 'begin_group', - 'name' => 'data', - 'text' => __('Data dump options'), - 'force' => 'structure' - ); - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'truncate', - 'text' => __('Truncate table before insert') - ); - /* begin SQL statements */ - $this->properties['options'][] = array( - 'type' => 'begin_subgroup', - 'subgroup_header' => array( - 'type' => 'message_only', - 'text' => __('Instead of INSERT statements, use:') - ) - ); - // Not supported in Drizzle - if (! PMA_DRIZZLE) { - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'delayed', - 'text' => __('INSERT DELAYED statements'), - 'doc' => array( - 'manual_MySQL_Database_Administration', - 'insert_delayed' - ) - ); - } - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'ignore', - 'text' => __('INSERT IGNORE statements'), - 'doc' => array( - 'manual_MySQL_Database_Administration', - 'insert' - ) - ); - $this->properties['options'][] = array( - 'type' => 'end_subgroup' - ); - /* end SQL statements */ - - /* Function to use when dumping data */ - $this->properties['options'][] = array( - 'type' => 'select', - 'name' => 'type', - 'text' => __('Function to use when dumping data:'), - 'values' => array( - 'INSERT' => 'INSERT', - 'UPDATE' => 'UPDATE', - 'REPLACE' => 'REPLACE' - ) - ); - - /* Syntax to use when inserting data */ - $this->properties['options'][] = array( - 'type' => 'begin_subgroup', - 'subgroup_header' => array( - 'type' => 'message_only', - 'text' => __('Syntax to use when inserting data:') - ) - ); - $this->properties['options'][] = array( - 'type' => 'radio', - 'name' => 'insert_syntax', - 'values' => array( - 'complete' => __( - 'include column names in every INSERT statement' - . '
      Example: INSERT INTO' - . ' tbl_name (col_A,col_B,col_C) VALUES (1,2,3)' - ), - 'extended' => __( - 'insert multiple rows in every INSERT statement' - . '
      Example: INSERT INTO' - . ' tbl_name VALUES (1,2,3), (4,5,6), (7,8,9)' - ), - 'both' => __( - 'both of the above
      Example:' - . ' INSERT INTO tbl_name (col_A,col_B) VALUES (1,2,3),' - . ' (4,5,6), (7,8,9)' - ), - 'none' => __( - 'neither of the above
      Example:' - . ' INSERT INTO tbl_name VALUES (1,2,3)' - ) - ) - ); - $this->properties['options'][] = array( - 'type' => 'end_subgroup' - ); - - /* Max length of query */ - $this->properties['options'][] = array( - 'type' => 'text', - 'name' => 'max_query_size', - 'text' => __('Maximal length of created query') - ); - - /* Dump binary columns in hexadecimal */ - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'hex_for_blob', - 'text' => __( - 'Dump binary columns in hexadecimal notation' - . ' (for example, "abc" becomes 0x616263)' - ) - ); - - // Drizzle works only with UTC timezone - if (! PMA_DRIZZLE) { - /* Dump time in UTC */ - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'utc_time', - 'text' => __( - 'Dump TIMESTAMP columns in UTC (enables TIMESTAMP columns' - . ' to be dumped and reloaded between servers in different' - . ' time zones)' - ) - ); - } - - $this->properties['options'][] = array( - 'type' => 'end_group' - ); - /* end Data options */ - } - } - - /** - * This method is called when any PluginManager to which the observer - * is attached calls PluginManager::notify() - * - * @param SplSubject $subject The PluginManager notifying the observer - * of an update. - * - * @return void - */ - public function update (SplSubject $subject) - { - } - - /** - * Exports routines (procedures and functions) - * - * @param string $db Database - * - * @return bool Whether it succeeded - */ - public function exportRoutines($db) - { - global $crlf; - $this->setCrlf($crlf); - - $common_functions = PMA_CommonFunctions::getInstance(); - $text = ''; - $delimiter = '$$'; - - $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); - $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); - - if ($procedure_names || $function_names) { - $text .= $crlf - . 'DELIMITER ' . $delimiter . $crlf; - } - - if ($procedure_names) { - $text .= - $this->_exportComment() - . $this->_exportComment(__('Procedures')) - . $this->_exportComment(); - - foreach ($procedure_names as $procedure_name) { - if (! empty($GLOBALS['sql_drop_table'])) { - $text .= 'DROP PROCEDURE IF EXISTS ' - . $common_functions->backquote($procedure_name) - . $delimiter . $crlf; - } - $text .= PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name) - . $delimiter . $crlf . $crlf; - } - } - - if ($function_names) { - $text .= - $this->_exportComment() - . $this->_exportComment(__('Functions')) - . $this->_exportComment(); - - foreach ($function_names as $function_name) { - if (! empty($GLOBALS['sql_drop_table'])) { - $text .= 'DROP FUNCTION IF EXISTS ' - . $common_functions->backquote($function_name) - . $delimiter . $crlf; - } - $text .= PMA_DBI_get_definition($db, 'FUNCTION', $function_name) - . $delimiter . $crlf . $crlf; - } - } - - if ($procedure_names || $function_names) { - $text .= 'DELIMITER ;' . $crlf; - } - - if (! empty($text)) { - return PMA_exportOutputHandler($text); - } else { - return false; - } - } - - /** - * Possibly outputs comment - * - * @param string $text Text of comment - * - * @return string The formatted comment - */ - private function _exportComment($text = '') - { - if (isset($GLOBALS['sql_include_comments']) - && $GLOBALS['sql_include_comments'] - ) { - // see http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-comments.html - return '--' . (empty($text) ? '' : ' ') . $text . $GLOBALS['crlf']; - } else { - return ''; - } - } - - /** - * Possibly outputs CRLF - * - * @return string $crlf or nothing - */ - private function _possibleCRLF() - { - if (isset($GLOBALS['sql_include_comments']) - && $GLOBALS['sql_include_comments'] - ) { - return $GLOBALS['crlf']; - } else { - return ''; - } - } - - /** - * Outputs export footer - * - * @return bool Whether it succeeded - */ - public function exportFooter() - { - global $crlf; - $this->setCrlf($crlf); - $mysql_charset_map = $this->_getMysqlCharsetMap(); - - $foot = ''; - - if (isset($GLOBALS['sql_disable_fk'])) { - $foot .= 'SET FOREIGN_KEY_CHECKS=1;' . $crlf; - } - - if (isset($GLOBALS['sql_use_transaction'])) { - $foot .= 'COMMIT;' . $crlf; - } - - // restore connection settings - $charset_of_file = isset($GLOBALS['charset_of_file']) - ? $GLOBALS['charset_of_file'] : ''; - if (! empty($GLOBALS['asfile']) - && isset($mysql_charset_map[$charset_of_file]) - && ! PMA_DRIZZLE - ) { - $foot .= $crlf - . '/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;' - . $crlf - . '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;' - . $crlf - . '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;' - . $crlf; - } - - /* Restore timezone */ - if (isset($GLOBALS['sql_utc_time']) && $GLOBALS['sql_utc_time']) { - PMA_DBI_query('SET time_zone = "' . $GLOBALS['old_tz'] . '"'); - } - - return PMA_exportOutputHandler($foot); - } - - /** - * Outputs export header. It is the first method to be called, so all - * the required variables are initialized here. - * - * @return bool Whether it succeeded - */ - public function exportHeader() - { - global $crlf, $cfg; - global $mysql_charset_map; - $this->setCrlf($crlf); - $this->setCfg($cfg); - $this->_setMysqlCharsetMap($mysql_charset_map); - - if (isset($GLOBALS['sql_compatibility'])) { - $tmp_compat = $GLOBALS['sql_compatibility']; - if ($tmp_compat == 'NONE') { - $tmp_compat = ''; - } - PMA_DBI_try_query('SET SQL_MODE="' . $tmp_compat . '"'); - unset($tmp_compat); - } - $head = $this->_exportComment('phpMyAdmin SQL Dump') - . $this->_exportComment('version ' . PMA_VERSION) - . $this->_exportComment('http://www.phpmyadmin.net') - . $this->_exportComment(); - $host_string = __('Host') . ': ' . $cfg['Server']['host']; - if (! empty($cfg['Server']['port'])) { - $host_string .= ':' . $cfg['Server']['port']; - } - $head .= $this->_exportComment($host_string); - $head .= - $this->_exportComment( - __('Generation Time') . ': ' - . PMA_CommonFunctions::getInstance()->localisedDate() - ) - . $this->_exportComment( - __('Server version') . ': ' . PMA_MYSQL_STR_VERSION - ) - . $this->_exportComment(__('PHP Version') . ': ' . phpversion()) - . $this->_possibleCRLF(); - - if (isset($GLOBALS['sql_header_comment']) - && ! empty($GLOBALS['sql_header_comment']) - ) { - // '\n' is not a newline (like "\n" would be), it's the characters - // backslash and n, as explained on the export interface - $lines = explode('\n', $GLOBALS['sql_header_comment']); - $head .= $this->_exportComment(); - foreach ($lines as $one_line) { - $head .= $this->_exportComment($one_line); - } - $head .= $this->_exportComment(); - } - - if (isset($GLOBALS['sql_disable_fk'])) { - $head .= 'SET FOREIGN_KEY_CHECKS=0;' . $crlf; - } - - // We want exported AUTO_INCREMENT columns to have still same value, - // do this only for recent MySQL exports - if ((! isset($GLOBALS['sql_compatibility']) - || $GLOBALS['sql_compatibility'] == 'NONE') - && ! PMA_DRIZZLE - ) { - $head .= 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' . $crlf; - } - - if (isset($GLOBALS['sql_use_transaction'])) { - $head .= 'SET AUTOCOMMIT = 0;' . $crlf - . 'START TRANSACTION;' . $crlf; - } - - /* Change timezone if we should export timestamps in UTC */ - if (isset($GLOBALS['sql_utc_time']) && $GLOBALS['sql_utc_time']) { - $head .= 'SET time_zone = "+00:00";' . $crlf; - $GLOBALS['old_tz'] = PMA_DBI_fetch_value('SELECT @@session.time_zone'); - PMA_DBI_query('SET time_zone = "+00:00"'); - } - - $head .= $this->_possibleCRLF(); - - if (! empty($GLOBALS['asfile']) && ! PMA_DRIZZLE) { - // we are saving as file, therefore we provide charset information - // so that a utility like the mysql client can interpret - // the file correctly - if (isset($GLOBALS['charset_of_file']) - && isset($mysql_charset_map[$GLOBALS['charset_of_file']]) - ) { - // we got a charset from the export dialog - $set_names = $mysql_charset_map[$GLOBALS['charset_of_file']]; - } else { - // by default we use the connection charset - $set_names = $mysql_charset_map['utf-8']; - } - $head .= $crlf - . '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=' - . '@@CHARACTER_SET_CLIENT */;' . $crlf - . '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=' - . '@@CHARACTER_SET_RESULTS */;' . $crlf - . '/*!40101 SET @OLD_COLLATION_CONNECTION=' - . '@@COLLATION_CONNECTION */;'. $crlf - . '/*!40101 SET NAMES ' . $set_names . ' */;' . $crlf . $crlf; - } - - return PMA_exportOutputHandler($head); - } - - /** - * Outputs CREATE DATABASE statement - * - * @param string $db Database name - * - * @return bool Whether it succeeded - */ - public function exportDBCreate($db) - { - global $crlf; - - $common_functions = PMA_CommonFunctions::getInstance(); - $this->setCrlf($crlf); - - if (isset($GLOBALS['sql_drop_database'])) { - if (! PMA_exportOutputHandler( - 'DROP DATABASE ' - . (isset($GLOBALS['sql_backquotes']) - ? $common_functions->backquote($db) : $db) - . ';' . $crlf - )) { - return false; - } - } - $create_query = 'CREATE DATABASE ' - . (isset($GLOBALS['sql_backquotes']) ? $common_functions->backquote($db) : $db); - $collation = PMA_getDbCollation($db); - if (PMA_DRIZZLE) { - $create_query .= ' COLLATE ' . $collation; - } else { - if (strpos($collation, '_')) { - $create_query .= ' DEFAULT CHARACTER SET ' - . substr($collation, 0, strpos($collation, '_')) - . ' COLLATE ' . $collation; - } else { - $create_query .= ' DEFAULT CHARACTER SET ' . $collation; - } - } - $create_query .= ';' . $crlf; - if (! PMA_exportOutputHandler($create_query)) { - return false; - } - if (isset($GLOBALS['sql_backquotes']) - && ((isset($GLOBALS['sql_compatibility']) - && $GLOBALS['sql_compatibility'] == 'NONE') - || PMA_DRIZZLE) - ) { - $result = PMA_exportOutputHandler( - 'USE ' . $common_functions->backquote($db) . ';' . $crlf - ); - } else { - $result = PMA_exportOutputHandler('USE ' . $db . ';' . $crlf); - } - - return $result; - } - - /** - * Outputs database header - * - * @param string $db Database name - * - * @return bool Whether it succeeded - */ - public function exportDBHeader($db) - { - $head = $this->_exportComment() - . $this->_exportComment( - __('Database') . ': ' - . (isset($GLOBALS['sql_backquotes']) - ? PMA_CommonFunctions::getInstance()->backquote($db) : '\'' . $db . '\'') - ) - . $this->_exportComment(); - return PMA_exportOutputHandler($head); - } - - /** - * Outputs database footer - * - * @param string $db Database name - * - * @return bool Whether it succeeded - */ - public function exportDBFooter($db) - { - global $crlf; - $this->setCrlf($crlf); - - $common_functions = PMA_CommonFunctions::getInstance(); - $result = true; - if (isset($GLOBALS['sql_constraints'])) { - $result = PMA_exportOutputHandler($GLOBALS['sql_constraints']); - unset($GLOBALS['sql_constraints']); - } - - if (($GLOBALS['sql_structure_or_data'] == 'structure' - || $GLOBALS['sql_structure_or_data'] == 'structure_and_data') - && isset($GLOBALS['sql_procedure_function']) - ) { - $text = ''; - $delimiter = '$$'; - - if (PMA_MYSQL_INT_VERSION > 50100) { - $event_names = PMA_DBI_fetch_result( - 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE' - . ' EVENT_SCHEMA= \'' - . $common_functions->sqlAddSlashes($db, true) - . '\';' - ); - } else { - $event_names = array(); - } - - if ($event_names) { - $text .= $crlf - . 'DELIMITER ' . $delimiter . $crlf; - - $text .= - $this->_exportComment() - . $this->_exportComment(__('Events')) - . $this->_exportComment(); - - foreach ($event_names as $event_name) { - if (! empty($GLOBALS['sql_drop_table'])) { - $text .= 'DROP EVENT ' . $common_functions->backquote($event_name) - . $delimiter . $crlf; - } - $text .= PMA_DBI_get_definition($db, 'EVENT', $event_name) - . $delimiter . $crlf . $crlf; - } - - $text .= 'DELIMITER ;' . $crlf; - } - - if (! empty($text)) { - $result = PMA_exportOutputHandler($text); - } - } - return $result; - } - - /** - * Returns a stand-in CREATE definition to resolve view dependencies - * - * @param string $db the database name - * @param string $view the view name - * @param string $crlf the end of line sequence - * - * @return string resulting definition - */ - public function getTableDefStandIn($db, $view, $crlf) - { - - $common_functions = PMA_CommonFunctions::getInstance(); - $create_query = ''; - if (! empty($GLOBALS['sql_drop_table'])) { - $create_query .= 'DROP VIEW IF EXISTS ' . $common_functions->backquote($view) - . ';' . $crlf; - } - - $create_query .= 'CREATE TABLE '; - - if (isset($GLOBALS['sql_if_not_exists']) - && $GLOBALS['sql_if_not_exists'] - ) { - $create_query .= 'IF NOT EXISTS '; - } - $create_query .= $common_functions->backquote($view) . ' (' . $crlf; - $tmp = array(); - $columns = PMA_DBI_get_columns_full($db, $view); - foreach ($columns as $column_name => $definition) { - $tmp[] = $common_functions->backquote($column_name) . ' ' . $definition['Type'] . $crlf; - } - $create_query .= implode(',', $tmp) . ');'; - return($create_query); - } - - /** - * Returns $table's CREATE definition - * - * @param string $db the database name - * @param string $table the table name - * @param string $crlf the end of line sequence - * @param string $error_url the url to go back in case of error - * @param bool $show_dates whether to include creation/update/check dates - * @param bool $add_semicolon whether to add semicolon and end-of-line at - * the end - * @param bool $view whether we're handling a view - * - * @return string resulting schema - */ - public function getTableDef( - $db, - $table, - $crlf, - $error_url, - $show_dates = false, - $add_semicolon = true, - $view = false - ) { - $this->initSpecificVariables(); - - $sql_drop_table = $this->_getSqlDropTable(); - $sql_backquotes = $this->_getSqlBackquotes(); - $sql_constraints = $this->_getSqlConstraints(); - $sql_constraints_query = $this->_getSqlConstraintsQuery(); - $sql_drop_foreign_keys = $this->_getSqlDropForeignKeys(); - - $common_functions = PMA_CommonFunctions::getInstance(); - $schema_create = ''; - $auto_increment = ''; - $new_crlf = $crlf; - - // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli - $result = PMA_DBI_query( - 'SHOW TABLE STATUS FROM ' . $common_functions->backquote($db) . ' LIKE \'' - . $common_functions->sqlAddSlashes($table, true) . '\'', - null, - PMA_DBI_QUERY_STORE - ); - if ($result != false) { - if (PMA_DBI_num_rows($result) > 0) { - $tmpres = PMA_DBI_fetch_assoc($result); - if (PMA_DRIZZLE && $show_dates) { - // Drizzle doesn't give Create_time and Update_time in - // SHOW TABLE STATUS, add it - $sql ="SELECT - TABLE_CREATION_TIME AS Create_time, - TABLE_UPDATE_TIME AS Update_time - FROM data_dictionary.TABLES - WHERE TABLE_SCHEMA = '" . $common_functions->sqlAddSlashes($db) . "' - AND TABLE_NAME = '" . $common_functions->sqlAddSlashes($table) . "'"; - $tmpres = array_merge(PMA_DBI_fetch_single_row($sql), $tmpres); - } - // Here we optionally add the AUTO_INCREMENT next value, - // but starting with MySQL 5.0.24, the clause is already included - // in SHOW CREATE TABLE so we'll remove it below - // It's required for Drizzle because SHOW CREATE TABLE uses - // the value from table's creation time - if (isset($GLOBALS['sql_auto_increment']) - && ! empty($tmpres['Auto_increment']) - ) { - $auto_increment .= ' AUTO_INCREMENT=' - . $tmpres['Auto_increment'] . ' '; - } - - if ($show_dates - && isset($tmpres['Create_time']) - && ! empty($tmpres['Create_time']) - ) { - $schema_create .= $this->_exportComment( - __('Creation') . ': ' - . $common_functions->localisedDate( - strtotime($tmpres['Create_time']) - ) - ); - $new_crlf = $this->_exportComment() . $crlf; - } - - if ($show_dates - && isset($tmpres['Update_time']) - && ! empty($tmpres['Update_time']) - ) { - $schema_create .= $this->_exportComment( - __('Last update') . ': ' - . $common_functions->localisedDate( - strtotime($tmpres['Update_time']) - ) - ); - $new_crlf = $this->_exportComment() . $crlf; - } - - if ($show_dates - && isset($tmpres['Check_time']) - && ! empty($tmpres['Check_time']) - ) { - $schema_create .= $this->_exportComment( - __('Last check') . ': ' - . $common_functions->localisedDate( - strtotime($tmpres['Check_time']) - ) - ); - $new_crlf = $this->_exportComment() . $crlf; - } - } - PMA_DBI_free_result($result); - } - - $schema_create .= $new_crlf; - - // no need to generate a DROP VIEW here, it was done earlier - if (! empty($sql_drop_table) && ! PMA_Table::isView($db, $table)) { - $schema_create .= 'DROP TABLE IF EXISTS ' - . $common_functions->backquote($table, $sql_backquotes) . ';' . $crlf; - } - - // Complete table dump, - // Whether to quote table and column names or not - // Drizzle always quotes names - if (! PMA_DRIZZLE) { - if ($sql_backquotes) { - PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1'); - } else { - PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0'); - } - } - - // I don't see the reason why this unbuffered query could cause problems, - // because SHOW CREATE TABLE returns only one row, and we free the - // results below. Nonetheless, we got 2 user reports about this - // (see bug 1562533) so I removed the unbuffered mode. - // $result = PMA_DBI_query('SHOW CREATE TABLE ' . backquote($db) - // . '.' . backquote($table), null, PMA_DBI_QUERY_UNBUFFERED); - // - // Note: SHOW CREATE TABLE, at least in MySQL 5.1.23, does not - // produce a displayable result for the default value of a BIT - // column, nor does the mysqldump command. See MySQL bug 35796 - $result = PMA_DBI_try_query( - 'SHOW CREATE TABLE ' . $common_functions->backquote($db) . '.' . $common_functions->backquote($table) - ); - // an error can happen, for example the table is crashed - $tmp_error = PMA_DBI_getError(); - if ($tmp_error) { - return $this->_exportComment(__('in use') . '(' . $tmp_error . ')'); - } - - if ($result != false && ($row = PMA_DBI_fetch_row($result))) { - $create_query = $row[1]; - unset($row); - - // Convert end of line chars to one that we want (note that MySQL - // doesn't return query it will accept in all cases) - if (strpos($create_query, "(\r\n ")) { - $create_query = str_replace("\r\n", $crlf, $create_query); - } elseif (strpos($create_query, "(\n ")) { - $create_query = str_replace("\n", $crlf, $create_query); - } elseif (strpos($create_query, "(\r ")) { - $create_query = str_replace("\r", $crlf, $create_query); - } - - /* - * Drop database name from VIEW creation. - * - * This is a bit tricky, but we need to issue SHOW CREATE TABLE with - * database name, but we don't want name to show up in CREATE VIEW - * statement. - */ - if ($view) { - $create_query = preg_replace( - '/' . $common_functions->backquote($db) . '\./', - '', - $create_query - ); - } - - // Should we use IF NOT EXISTS? - if (isset($GLOBALS['sql_if_not_exists'])) { - $create_query = preg_replace( - '/^CREATE TABLE/', - 'CREATE TABLE IF NOT EXISTS', - $create_query - ); - } - - // Drizzle (checked on 2011.03.13) returns ROW_FORMAT surrounded - // with quotes, which is not accepted by parser - if (PMA_DRIZZLE) { - $create_query = preg_replace( - '/ROW_FORMAT=\'(\S+)\'/', - 'ROW_FORMAT=$1', - $create_query - ); - } - - // are there any constraints to cut out? - if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $create_query)) { - - // Split the query into lines, so we can easily handle it. - // We know lines are separated by $crlf (done few lines above). - $sql_lines = explode($crlf, $create_query); - $sql_count = count($sql_lines); - - // lets find first line with constraints - for ($i = 0; $i < $sql_count; $i++) { - if (preg_match( - '@^[\s]*(CONSTRAINT|FOREIGN[\s]+KEY)@', - $sql_lines[$i] - )) { - break; - } - } - - // If we really found a constraint - if ($i != $sql_count) { - - // remove, from the end of create statement - $sql_lines[$i - 1] = preg_replace( - '@,$@', - '', - $sql_lines[$i - 1] - ); - - // prepare variable for constraints - if (! isset($sql_constraints)) { - if (isset($GLOBALS['no_constraints_comments'])) { - $sql_constraints = ''; - } else { - $sql_constraints = $crlf - . $this->_exportComment() - . $this->_exportComment( - __('Constraints for dumped tables') - ) - . $this->_exportComment(); - } - } - - // comments for current table - if (! isset($GLOBALS['no_constraints_comments'])) { - $sql_constraints .= $crlf - . $this->_exportComment() - . $this->_exportComment( - __('Constraints for table') - . ' ' - . $common_functions->backquote($table) - ) - . $this->_exportComment(); - } - - // let's do the work - $sql_constraints_query .= 'ALTER TABLE ' - . $common_functions->backquote($table) . $crlf; - $sql_constraints .= 'ALTER TABLE ' - . $common_functions->backquote($table) . $crlf; - $sql_drop_foreign_keys .= 'ALTER TABLE ' - . $common_functions->backquote($db) . '.' - . $common_functions->backquote($table) . $crlf; - - $first = true; - for ($j = $i; $j < $sql_count; $j++) { - if (preg_match( - '@CONSTRAINT|FOREIGN[\s]+KEY@', - $sql_lines[$j] - )) { - if (! $first) { - $sql_constraints .= $crlf; - } - if (strpos($sql_lines[$j], 'CONSTRAINT') === false) { - $tmp_str = preg_replace( - '/(FOREIGN[\s]+KEY)/', - 'ADD \1', - $sql_lines[$j] - ); - $sql_constraints_query .= $tmp_str; - $sql_constraints .= $tmp_str; - } else { - $tmp_str = preg_replace( - '/(CONSTRAINT)/', - 'ADD \1', - $sql_lines[$j] - ); - $sql_constraints_query .= $tmp_str; - $sql_constraints .= $tmp_str; - preg_match( - '/(CONSTRAINT)([\s])([\S]*)([\s])/', - $sql_lines[$j], - $matches - ); - if (! $first) { - $sql_drop_foreign_keys .= ', '; - } - $sql_drop_foreign_keys .= 'DROP FOREIGN KEY ' - . $matches[3]; - } - $first = false; - } else { - break; - } - } - $sql_constraints .= ';' . $crlf; - $sql_constraints_query .= ';'; - - $create_query = implode( - $crlf, - array_slice($sql_lines, 0, $i) - ) - . $crlf - . implode( - $crlf, - array_slice($sql_lines, $j, $sql_count - 1) - ); - unset($sql_lines); - } - } - $schema_create .= $create_query; - } - - // remove a possible "AUTO_INCREMENT = value" clause - // that could be there starting with MySQL 5.0.24 - // in Drizzle it's useless as it contains the value given at table - // creation time - $schema_create = preg_replace( - '/AUTO_INCREMENT\s*=\s*([0-9])+/', - '', - $schema_create - ); - - $schema_create .= $auto_increment; - - PMA_DBI_free_result($result); - return $schema_create . ($add_semicolon ? ';' . $crlf : ''); - } // end of the 'getTableDef()' function - - /** - * Returns $table's comments, relations etc. - * - * @param string $db database name - * @param string $table table name - * @param string $crlf end of line sequence - * @param bool $do_relation whether to include relation comments - * @param bool $do_mime whether to include mime comments - * - * @return string resulting comments - */ - private function _getTableComments( - $db, - $table, - $crlf, - $do_relation = false, - $do_mime = false - ) { - global $cfgRelation; - - $common_functions = PMA_CommonFunctions::getInstance(); - $this->setCfgRelation($cfgRelation); - $sql_backquotes = $this->_getSqlBackquotes(); - - $schema_create = ''; - - // 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 - $res_rel = PMA_getForeigners($db, $table); - - if ($res_rel && count($res_rel) > 0) { - $have_rel = true; - } else { - $have_rel = false; - } - } else { - $have_rel = false; - } // end if - - if ($do_mime && $cfgRelation['mimework']) { - if (! ($mime_map = PMA_getMIME($db, $table, true))) { - unset($mime_map); - } - } - - if (isset($mime_map) && count($mime_map) > 0) { - $schema_create .= $this->_possibleCRLF() - . $this->_exportComment() - . $this->_exportComment( - __('MIME TYPES FOR TABLE'). ' ' - . $common_functions->backquote($table, $sql_backquotes) . ':' - ); - @reset($mime_map); - foreach ($mime_map AS $mime_field => $mime) { - $schema_create .= - $this->_exportComment( - ' ' - . $common_functions->backquote($mime_field, $sql_backquotes) - ) - . $this->_exportComment( - ' ' - . $common_functions->backquote($mime['mimetype'], $sql_backquotes) - ); - } - $schema_create .= $this->_exportComment(); - } - - if ($have_rel) { - $schema_create .= $this->_possibleCRLF() - . $this->_exportComment() - . $this->_exportComment( - __('RELATIONS FOR TABLE') . ' ' - . $common_functions->backquote($table, $sql_backquotes) - . ':' - ); - foreach ($res_rel AS $rel_field => $rel) { - $schema_create .= - $this->_exportComment( - ' ' - . $common_functions->backquote($rel_field, $sql_backquotes) - ) - . $this->_exportComment( - ' ' - . $common_functions->backquote($rel['foreign_table'], $sql_backquotes) - . ' -> ' - . $common_functions->backquote($rel['foreign_field'], $sql_backquotes) - ); - } - $schema_create .= $this->_exportComment(); - } - - return $schema_create; - - } // end of the '_getTableComments()' function - - /** - * Outputs table's structure - * - * @param string $db database name - * @param string $table table name - * @param string $crlf the end of line sequence - * @param string $error_url the url to go back in case of error - * @param string $export_mode 'create_table','triggers','create_view', - * 'stand_in' - * @param string $export_type 'server', 'database', 'table' - * @param bool $relation whether to include relation comments - * @param bool $comments whether to include the pmadb-style column comments - * as comments in the structure; this is deprecated - * but the parameter is left here because export.php - * calls exportStructure() also for other export - * types which use this parameter - * @param bool $mime whether to include mime comments - * @param bool $dates whether to include creation/update/check dates - * - * @return bool Whether it succeeded - */ - public function exportStructure( - $db, - $table, - $crlf, - $error_url, - $export_mode, - $export_type, - $relation = false, - $comments = false, - $mime = false, - $dates = false - ) { - - $common_functions = PMA_CommonFunctions::getInstance(); - - $formatted_table_name = (isset($GLOBALS['sql_backquotes'])) - ? $common_functions->backquote($table) : '\'' . $table . '\''; - $dump = $this->_possibleCRLF() - . $this->_exportComment(str_repeat('-', 56)) - . $this->_possibleCRLF() - . $this->_exportComment(); - - switch($export_mode) { - case 'create_table': - $dump .= $this->_exportComment( - __('Table structure for table') . ' '. $formatted_table_name - ); - $dump .= $this->_exportComment(); - $dump .= $this->getTableDef($db, $table, $crlf, $error_url, $dates); - $dump .= $this->_getTableComments($db, $table, $crlf, $relation, $mime); - break; - case 'triggers': - $dump = ''; - $triggers = PMA_DBI_get_triggers($db, $table); - if ($triggers) { - $dump .= $this->_possibleCRLF() - . $this->_exportComment() - . $this->_exportComment( - __('Triggers') . ' ' . $formatted_table_name - ) - . $this->_exportComment(); - $delimiter = '//'; - foreach ($triggers as $trigger) { - $dump .= $trigger['drop'] . ';' . $crlf; - $dump .= 'DELIMITER ' . $delimiter . $crlf; - $dump .= $trigger['create']; - $dump .= 'DELIMITER ;' . $crlf; - } - } - break; - case 'create_view': - $dump .= - $this->_exportComment( - __('Structure for view') - . ' ' - . $formatted_table_name - ) - . $this->_exportComment(); - // delete the stand-in table previously created (if any) - if ($export_type != 'table') { - $dump .= 'DROP TABLE IF EXISTS ' - . $common_functions->backquote($table) . ';' . $crlf; - } - $dump .= $this->getTableDef( - $db, $table, $crlf, $error_url, $dates, true, true - ); - break; - case 'stand_in': - $dump .= - $this->_exportComment( - __('Stand-in structure for view') . ' ' . $formatted_table_name - ) - . $this->_exportComment(); - // export a stand-in definition to resolve view dependencies - $dump .= getTableDefStandIn($db, $table, $crlf); - } // end switch - - // this one is built by getTableDef() to use in table copy/move - // but not in the case of export - unset($GLOBALS['sql_constraints_query']); - - return PMA_exportOutputHandler($dump); - } - - /** - * Outputs the content of a table in SQL format - * - * @param string $db database name - * @param string $table table name - * @param string $crlf the end of line sequence - * @param string $error_url the url to go back in case of error - * @param string $sql_query SQL query for obtaining data - * - * @return bool Whether it succeeded - */ - public function exportData($db, $table, $crlf, $error_url, $sql_query) - { - global $current_row; - $this->_setCurrentRow($current_row); - $sql_backquotes = $this->_getSqlBackquotes(); - - $common_functions = PMA_CommonFunctions::getInstance(); - $formatted_table_name = (isset($GLOBALS['sql_backquotes'])) - ? $common_functions->backquote($table) - : '\'' . $table . '\''; - - // Do not export data for a VIEW - // (For a VIEW, this is called only when exporting a single VIEW) - if (PMA_Table::isView($db, $table)) { - $head = $this->_possibleCRLF() - . $this->_exportComment() - . $this->_exportComment('VIEW ' . ' ' . $formatted_table_name) - . $this->_exportComment(__('Data') . ': ' . __('None')) - . $this->_exportComment() - . $this->_possibleCRLF(); - - if (! PMA_exportOutputHandler($head)) { - return false; - } - return true; - } - - // analyze the query to get the true column names, not the aliases - // (this fixes an undefined index, also if Complete inserts - // are used, we did not get the true column name in case of aliases) - $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query)); - - $result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - // a possible error: the table has crashed - $tmp_error = PMA_DBI_getError(); - if ($tmp_error) { - return PMA_exportOutputHandler( - $this->_exportComment( - __('Error reading data:') . ' (' . $tmp_error . ')' - ) - ); - } - - if ($result != false) { - $fields_cnt = PMA_DBI_num_fields($result); - - // Get field information - $fields_meta = PMA_DBI_get_fields_meta($result); - $field_flags = array(); - for ($j = 0; $j < $fields_cnt; $j++) { - $field_flags[$j] = PMA_DBI_field_flags($result, $j); - } - - for ($j = 0; $j < $fields_cnt; $j++) { - if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) { - $field_set[$j] = $common_functions->backquote( - $analyzed_sql[0]['select_expr'][$j]['column'], - $sql_backquotes - ); - } else { - $field_set[$j] = $common_functions->backquote( - $fields_meta[$j]->name, - $sql_backquotes - ); - } - } - - if (isset($GLOBALS['sql_type']) - && $GLOBALS['sql_type'] == 'UPDATE' - ) { - // update - $schema_insert = 'UPDATE '; - if (isset($GLOBALS['sql_ignore'])) { - $schema_insert .= 'IGNORE '; - } - // avoid EOL blank - $schema_insert .= $common_functions->backquote($table, $sql_backquotes) . ' SET'; - } else { - // insert or replace - if (isset($GLOBALS['sql_type']) - && $GLOBALS['sql_type'] == 'REPLACE' - ) { - $sql_command = 'REPLACE'; - } else { - $sql_command = 'INSERT'; - } - - // delayed inserts? - if (isset($GLOBALS['sql_delayed'])) { - $insert_delayed = ' DELAYED'; - } else { - $insert_delayed = ''; - } - - // insert ignore? - if (isset($GLOBALS['sql_type']) - && $GLOBALS['sql_type'] == 'INSERT' - && isset($GLOBALS['sql_ignore']) - ) { - $insert_delayed .= ' IGNORE'; - } - //truncate table before insert - if (isset($GLOBALS['sql_truncate']) - && $GLOBALS['sql_truncate'] - && $sql_command == 'INSERT' - ) { - $truncate = 'TRUNCATE TABLE ' - . $common_functions->backquote($table, $sql_backquotes) . ";"; - $truncatehead = $this->_possibleCRLF() - . $this->_exportComment() - . $this->_exportComment( - __('Truncate table before insert') . ' ' - . $formatted_table_name - ) - . $this->_exportComment() - . $crlf; - PMA_exportOutputHandler($truncatehead); - PMA_exportOutputHandler($truncate); - } else { - $truncate = ''; - } - // scheme for inserting fields - if ($GLOBALS['sql_insert_syntax'] == 'complete' - || $GLOBALS['sql_insert_syntax'] == 'both' - ) { - $fields = implode(', ', $field_set); - $schema_insert = $sql_command . $insert_delayed .' INTO ' - . $common_functions->backquote($table, $sql_backquotes) - // avoid EOL blank - . ' (' . $fields . ') VALUES'; - } else { - $schema_insert = $sql_command . $insert_delayed .' INTO ' - . $common_functions->backquote($table, $sql_backquotes) - . ' VALUES'; - } - } - - //\x08\\x09, not required - $search = array("\x00", "\x0a", "\x0d", "\x1a"); - $replace = array('\0', '\n', '\r', '\Z'); - $current_row = 0; - $query_size = 0; - if (($GLOBALS['sql_insert_syntax'] == 'extended' - || $GLOBALS['sql_insert_syntax'] == 'both') - && (! isset($GLOBALS['sql_type']) - || $GLOBALS['sql_type'] != 'UPDATE') - ) { - $separator = ','; - $schema_insert .= $crlf; - } else { - $separator = ';'; - } - - while ($row = PMA_DBI_fetch_row($result)) { - if ($current_row == 0) { - $head = $this->_possibleCRLF() - . $this->_exportComment() - . $this->_exportComment( - __('Dumping data for table') . ' ' - . $formatted_table_name - ) - . $this->_exportComment() - . $crlf; - if (! PMA_exportOutputHandler($head)) { - return false; - } - } - $current_row++; - for ($j = 0; $j < $fields_cnt; $j++) { - // NULL - if (! isset($row[$j]) || is_null($row[$j])) { - $values[] = 'NULL'; - } elseif ($fields_meta[$j]->numeric - && $fields_meta[$j]->type != 'timestamp' - && ! $fields_meta[$j]->blob - ) { - // a number - // timestamp is numeric on some MySQL 4.1, BLOBs are - // sometimes numeric - $values[] = $row[$j]; - } elseif (stristr($field_flags[$j], 'BINARY') - && $fields_meta[$j]->blob - && isset($GLOBALS['sql_hex_for_blob']) - ) { - // a true BLOB - // - mysqldump only generates hex data when the --hex-blob - // option is used, for fields having the binary attribute - // no hex is generated - // - a TEXT field returns type blob but a real blob - // returns also the 'binary' flag - - // empty blobs need to be different, but '0' is also empty - // :-( - if (empty($row[$j]) && $row[$j] != '0') { - $values[] = '\'\''; - } else { - $values[] = '0x' . bin2hex($row[$j]); - } - } elseif ($fields_meta[$j]->type == 'bit') { - // detection of 'bit' works only on mysqli extension - $values[] = "b'" . $common_functions->sqlAddSlashes( - $common_functions->printableBitValue( - $row[$j], $fields_meta[$j]->length - ) - ) - . "'"; - } else { - // something else -> treat as a string - $values[] = '\'' - . str_replace( - $search, $replace, $common_functions->sqlAddSlashes($row[$j]) - ) - . '\''; - } // end if - } // end for - - // should we make update? - if (isset($GLOBALS['sql_type']) - && $GLOBALS['sql_type'] == 'UPDATE' - ) { - - $insert_line = $schema_insert; - for ($i = 0; $i < $fields_cnt; $i++) { - if (0 == $i) { - $insert_line .= ' '; - } - if ($i > 0) { - // avoid EOL blank - $insert_line .= ','; - } - $insert_line .= $field_set[$i] . ' = ' . $values[$i]; - } - - list($tmp_unique_condition, $tmp_clause_is_unique) - = $common_functions->getUniqueCondition( - $result, - $fields_cnt, - $fields_meta, - $row - ); - $insert_line .= ' WHERE ' . $tmp_unique_condition; - unset($tmp_unique_condition, $tmp_clause_is_unique); - - } else { - - // Extended inserts case - if ($GLOBALS['sql_insert_syntax'] == 'extended' - || $GLOBALS['sql_insert_syntax'] == 'both' - ) { - if ($current_row == 1) { - $insert_line = $schema_insert . '(' - . implode(', ', $values) . ')'; - } else { - $insert_line = '(' . implode(', ', $values) . ')'; - $sql_max_size = $GLOBALS['sql_max_query_size']; - if (isset($sql_max_size) - && $sql_max_size > 0 - && $query_size + strlen($insert_line) > $sql_max_size - ) { - if (! PMA_exportOutputHandler(';' . $crlf)) { - return false; - } - $query_size = 0; - $current_row = 1; - $insert_line = $schema_insert . $insert_line; - } - } - $query_size += strlen($insert_line); - // Other inserts case - } else { - $insert_line = $schema_insert - . '(' - . implode(', ', $values) - . ')'; - } - } - unset($values); - - if (! PMA_exportOutputHandler( - ($current_row == 1 ? '' : $separator . $crlf) - . $insert_line - )) { - return false; - } - - } // end while - if ($current_row > 0) { - if (! PMA_exportOutputHandler(';' . $crlf)) { - return false; - } - } - } // end if ($result != false) - PMA_DBI_free_result($result); - - return true; - } // end of the 'exportData()' function - - - /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ - - /** - * Gets the MySQL charset map - * - * @return array - */ - private function _getMysqlCharsetMap() - { - return $this->_mysqlCharsetMap; - } - - /** - * Sets the MySQL charset map - * - * @param string $mysqlCharsetMap file charset - * - * @return void - */ - private function _setMysqlCharsetMap($mysqlCharsetMap) - { - $this->_mysqlCharsetMap = $mysqlCharsetMap; - } - - /** - * Gets the SQL for dropping a table - * - * @return string - */ - private function _getSqlDropTable() - { - return $this->_sqlDropTable; - } - - /** - * Sets the SQL for dropping a table - * - * @param string $sqlDropTable SQL for dropping a table - * - * @return void - */ - private function _setSqlDropTable($sqlDropTable) - { - $this->_sqlDropTable = $sqlDropTable; - } - - /** - * Gets the SQL Backquotes - * - * @return bool - */ - private function _getSqlBackquotes() - { - return $this->_sqlBackquotes; - } - - /** - * Sets the SQL Backquotes - * - * @param string $sqlBackquotes SQL Backquotes - * - * @return void - */ - private function _setSqlBackquotes($sqlBackquotes) - { - $this->_sqlBackquotes = $sqlBackquotes; - } - - /** - * Gets the SQL Constraints - * - * @return void - */ - private function _getSqlConstraints() - { - return $this->_sqlConstraints; - } - - /** - * Sets the SQL Constraints - * - * @param string $sqlConstraints SQL Constraints - * - * @return void - */ - private function _setSqlConstraints($sqlConstraints) - { - $this->_sqlConstraints = $sqlConstraints; - } - - /** - * Gets the text of the SQL constraints query - * - * @return void - */ - private function _getSqlConstraintsQuery() - { - return $this->_sqlConstraintsQuery; - } - - /** - * Sets the text of the SQL constraints query - * - * @param string $sqlConstraintsQuery text of the SQL constraints query - * - * @return void - */ - private function _setSqlConstraintsQuery($sqlConstraintsQuery) - { - $this->_sqlConstraintsQuery = $sqlConstraintsQuery; - } - - /** - * Gets the SQL for dropping foreign keys - * - * @return void - */ - private function _getSqlDropForeignKeys() - { - return $this->_sqlDropForeignKeys; - } - - /** - * Sets the SQL SQL for dropping foreign keys - * - * @param string $sqlDropForeignKeys SQL for dropping foreign keys - * - * @return void - */ - private function _setSqlDropForeignKeys($sqlDropForeignKeys) - { - $this->_sqlDropForeignKeys = $sqlDropForeignKeys; - } - - /** - * The number of the current row - * - * @return int - */ - private function _getCurrentRow() - { - return $this->_currentRow; - } - - /** - * Sets the number of the current row - * - * @param string $currentRow number of the current row - * - * @return void - */ - private function _setCurrentRow($currentRow) - { - $this->_currentRow = $currentRow; - } -} \ No newline at end of file diff --git a/libraries/plugins/import/ImportCsv.class.php b/libraries/plugins/import/ImportCsv.class.php index b0cf2e8f67a5..281740950845 100644 --- a/libraries/plugins/import/ImportCsv.class.php +++ b/libraries/plugins/import/ImportCsv.class.php @@ -27,7 +27,7 @@ class ImportCsv extends ImportPlugin * @var bool */ private $_analyze; - + /** * Constructor */ @@ -50,67 +50,67 @@ protected function setProperties() $this->_setAnalyze(true); } - $this->properties = array( - 'text' => __('CSV'), - 'extension' => 'csv', - 'options' => array(), - 'options_text' => __('Options') - ); - - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - array( - 'type' => 'bool', - 'name' => 'replace', - 'text' => __('Replace table data with file') - ), - array( - 'type' => 'bool', - 'name' => 'ignore', - 'text' => __('Do not abort on INSERT error') - ), - array( - 'type' => 'text', - 'name' => 'terminated', - 'text' => __('Columns separated with:'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'enclosed', - 'text' => __('Columns enclosed with:'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'escaped', - 'text' => __('Columns escaped with:'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'new_line', - 'text' => __('Lines terminated with:'), - 'size' => 2 - ) - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; + include_once "$props/options/items/TextPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('CSV'); + $importPluginProperties->setExtension('csv'); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new BoolPropertyItem(); + $leaf->setName("replace"); + $leaf->setText(__('Replace table data with file')); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("terminated"); + $leaf->setText(__('Columns separated with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("enclosed"); + $leaf->setText(__('Columns enclosed with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("escaped"); + $leaf->setText(__('Columns escaped with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("new_line"); + $leaf->setText(__('Lines terminated with:')); + $leaf->setSize(2); + $generalOptions->addProperty($leaf); if ($GLOBALS['plugin_param'] !== 'table') { - $this->properties['options'][] = array( - 'type' => 'bool', - 'name' => 'col_names', - 'text' => __( - 'The first line of the file contains the table column names ' - . '(if this is unchecked, the first line will become part of the' - . ' data)' + $leaf = new BoolPropertyItem(); + $leaf->setName("col_names"); + $leaf->setText( + __( + 'The first line of the file contains the table column names' + . ' (if this is unchecked, the first line will become part' + . ' of the data)' ) ); + $generalOptions->addProperty($leaf); } else { $hint = new PMA_Message( __( @@ -120,15 +120,21 @@ protected function setProperties() . ' and not enclosed in quotations.' ) ); - $this->properties['options'][] = array( - 'type' => 'text', - 'name' => 'columns', - 'text' => __('Column names: ') - . PMA_CommonFunctions::getInstance()->showHint($hint) + $leaf = new TextPropertyItem(); + $leaf->setName("columns"); + $leaf->setText( + __('Column names: ') + . PMA_CommonFunctions::getInstance()->showHint($hint) ); + $generalOptions->addProperty($leaf); } - $this->properties['options'][] = array('type' => 'end_group'); + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** @@ -146,7 +152,7 @@ public function update (SplSubject $subject) /** * Handles the whole import logic - * + * * @return void */ public function doImport() @@ -499,7 +505,7 @@ public function doImport() $sql .= ')'; /** - * @todo maybe we could add original line to verbose + * @todo maybe we could add original line to verbose * SQL in comment */ PMA_importRunQuery($sql, $sql); @@ -597,11 +603,11 @@ public function doImport() $error = true; } } - + /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ - + /** * Returns true if the table should be analyzed, false otherwise * diff --git a/libraries/plugins/import/ImportDocsql.class.php b/libraries/plugins/import/ImportDocsql.class.php index 17d828884209..e0f440653bb4 100644 --- a/libraries/plugins/import/ImportDocsql.class.php +++ b/libraries/plugins/import/ImportDocsql.class.php @@ -18,7 +18,7 @@ $GLOBALS['skip_import'] = true; return; } - + /** * Handles the import for the DocSQL format * @@ -58,27 +58,38 @@ protected function setProperties() return; } - $this->properties = array( - 'text' => __('DocSQL'), - 'extension' => '', - 'options' => array(), - 'options_text' => __('Options'), - ); - - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - array( - 'type' => 'text', - 'name' => 'table', - 'text' => __('Table name') - ), - array( - 'type' => 'end_group' - ) - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/TextPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('DocSQL'); + $importPluginProperties->setExtension(''); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new TextPropertyItem(); + $leaf->setName("table"); + $leaf->setText(__('Table name')); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** @@ -104,7 +115,7 @@ public function doImport() global $error, $timeout_passed, $finished; $cfgRelation = $this->_getCfgRelation(); $common_functions = PMA_CommonFunctions::getInstance(); - + $tab = $_POST['docsql_table']; $buffer = ''; diff --git a/libraries/plugins/import/ImportLdi.class.php b/libraries/plugins/import/ImportLdi.class.php index 09eab78a1258..3780a21e8df1 100644 --- a/libraries/plugins/import/ImportLdi.class.php +++ b/libraries/plugins/import/ImportLdi.class.php @@ -56,71 +56,39 @@ protected function setProperties() unset($result); } - $this->properties = array( - 'text' => __('CSV using LOAD DATA'), - // Following is nonsense, however we want to default to our - // parser for csv - 'extension' => 'ldi', - 'options' => array(), - 'options_text' => __('Options'), - ); - - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - array( - 'type' => 'bool', - 'name' => 'replace', - 'text' => __('Replace table data with file') - ), - array( - 'type' => 'bool', - 'name' => 'ignore', - 'text' => __('Do not abort on INSERT error') - ), - array( - 'type' => 'text', - 'name' => 'terminated', - 'text' => __('Columns terminated by'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'enclosed', - 'text' => __('Columns enclosed by'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'escaped', - 'text' => __('Columns escaped by'), - 'size' => 2, - 'len' => 2 - ), - array( - 'type' => 'text', - 'name' => 'new_line', - 'text' => __('Lines terminated by'), - 'size' => 2 - ), - array( - 'type' => 'text', - 'name' => 'columns', - 'text' => __('Column names') - ), - array( - 'type' => 'bool', - 'name' => 'local_option', - 'text' => __('Use LOCAL keyword') - ), - array( - 'type' => 'end_group' - ) - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; + include_once "$props/options/items/TextPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('CSV using LOAD DATA'); + $importPluginProperties->setExtension('ldi'); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new BoolPropertyItem(); + $leaf->setName("replace"); + $leaf->setText(__('Replace table data with file')); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** @@ -146,9 +114,9 @@ public function doImport() global $finished, $error, $import_file, $compression, $charset_conversion; global $ldi_local_option, $ldi_replace, $ldi_terminated, $ldi_enclosed, $ldi_escaped, $ldi_new_line, $skip_queries, $ldi_columns; - + $common_functions = PMA_CommonFunctions::getInstance(); - + if ($import_file == 'none' || $compression != 'none' || $charset_conversion diff --git a/libraries/plugins/import/ImportMediawiki.class.php b/libraries/plugins/import/ImportMediawiki.class.php index 8ed5e52be752..e6ce2e0e96a7 100644 --- a/libraries/plugins/import/ImportMediawiki.class.php +++ b/libraries/plugins/import/ImportMediawiki.class.php @@ -48,13 +48,17 @@ protected function setProperties() $this->_setAnalyze(true); } - $this->properties = array( - 'text' => __('MediaWiki Table'), - 'extension' => 'txt', - 'mime_type' => 'text/plain', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText(__('MediaWiki Table')); + $importPluginProperties->setExtension('txt'); + $importPluginProperties->setMimeType('text/plain'); + $importPluginProperties->setOptions(array()); + $importPluginProperties->setOptionsText(__('Options')); + + $this->properties = $importPluginProperties; } /** diff --git a/libraries/plugins/import/ImportOds.class.php b/libraries/plugins/import/ImportOds.class.php index c275de649180..d1879ef0b691 100644 --- a/libraries/plugins/import/ImportOds.class.php +++ b/libraries/plugins/import/ImportOds.class.php @@ -45,40 +45,59 @@ public function __construct() */ protected function setProperties() { - $this->properties = array( - 'text' => __('Open Document Spreadsheet'), - 'extension' => 'ods', - 'options' => array(), - 'options_text' => __('Options'), + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('Open Document Spreadsheet'); + $importPluginProperties->setExtension('ods'); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new BoolPropertyItem(); + $leaf->setName("col_names"); + $leaf->setText( + __('The first line of the file contains the table column names' + . ' (if this is unchecked, the first line will become part' + . ' of the data)' + ) ); - - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - array( - 'type' => 'bool', - 'name' => 'col_names', - 'text' => __('The first line of the file contains the table column names (if this is unchecked, the first line will become part of the data)') - ), - array( - 'type' => 'bool', - 'name' => 'empty_rows', - 'text' => __('Do not import empty rows') - ), - array( - 'type' => 'bool', - 'name' => 'recognize_percentages', - 'text' => __('Import percentages as proper decimals (ex. 12.00% to .12)') - ), - array( - 'type' => 'bool', - 'name' => 'recognize_currency', - 'text' => __('Import currencies (ex. $5.00 to 5.00)') - ), - array('type' => 'end_group') + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("empty_rows"); + $leaf->setText(__('Do not import empty rows')); + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("recognize_percentages"); + $leaf->setText( + __( + 'Import percentages as proper decimals (ex. 12.00% to .12)' + ) ); + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("recognize_currency"); + $leaf->setText(__('Import currencies (ex. $5.00 to 5.00)')); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** diff --git a/libraries/plugins/import/ImportShp.class.php b/libraries/plugins/import/ImportShp.class.php index 7f35135e030b..e05d368464fe 100644 --- a/libraries/plugins/import/ImportShp.class.php +++ b/libraries/plugins/import/ImportShp.class.php @@ -45,12 +45,16 @@ public function __construct() */ protected function setProperties() { - $this->properties = array( - 'text' => __('ESRI Shape File'), - 'extension' => 'shp', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText(__('ESRI Shape File')); + $importPluginProperties->setExtension('shp'); + $importPluginProperties->setOptions(array()); + $importPluginProperties->setOptionsText(__('Options')); + + $this->properties = $importPluginProperties; } /** @@ -312,7 +316,7 @@ public function doImport() * Sets $eof when $GLOBALS['finished'] is set and the buffer falls short. * * @param int $length number of bytes - * + * * @return string */ public static function readFromBuffer($length) diff --git a/libraries/plugins/import/ImportSql.class.php b/libraries/plugins/import/ImportSql.class.php index d25c71139ab9..5f0f1e0b48d8 100644 --- a/libraries/plugins/import/ImportSql.class.php +++ b/libraries/plugins/import/ImportSql.class.php @@ -36,12 +36,17 @@ public function __construct() */ protected function setProperties() { - $this->properties = array( - 'text' => __('SQL'), - 'extension' => 'sql', - 'options' => array(), - 'options_text' => __('Options'), - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/SelectPropertyItem.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('SQL'); + $importPluginProperties->setExtension('sql'); + $importPluginProperties->setOptionsText(__('Options')); $compats = PMA_DBI_getCompatibilities(); if (count($compats) > 0) { @@ -49,33 +54,49 @@ protected function setProperties() foreach ($compats as $val) { $values[$val] = $val; } - $this->properties['options'] = array( - array('type' => 'begin_group', 'name' => 'general_opts'), + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create primary items and add them to the group + $leaf = new SelectPropertyItem(); + $leaf->setName("compatibility"); + $leaf->setText(__('SQL compatibility mode:')); + $leaf->setValues($values); + $leaf->setDoc( array( - 'type' => 'select', - 'name' => 'compatibility', - 'text' => __('SQL compatibility mode:'), - 'values' => $values, - 'doc' => array( - 'manual_MySQL_Database_Administration', - 'Server_SQL_mode', - ), - ), + 'manual_MySQL_Database_Administration', + 'Server_SQL_mode', + ) + ); + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("no_auto_value_on_zero"); + $leaf->setText( + __('Do not use AUTO_INCREMENT for zero values') + ); + $leaf->setDoc( array( - 'type' => 'bool', - 'name' => 'no_auto_value_on_zero', - 'text' => __( - 'Do not use AUTO_INCREMENT for zero values' - ), - 'doc' => array( - 'manual_MySQL_Database_Administration', - 'Server_SQL_mode', - 'sqlmode_no_auto_value_on_zero' - ), - ), - array('type' => 'end_group'), + 'manual_MySQL_Database_Administration', + 'Server_SQL_mode', + 'sqlmode_no_auto_value_on_zero' + ) ); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); } + + $this->properties = $importPluginProperties; } /** @@ -93,7 +114,7 @@ public function update (SplSubject $subject) /** * Handles the whole import logic - * + * * @param &$sql_data array 2-element array with sql data * * @return void diff --git a/libraries/plugins/import/ImportXml.class.php b/libraries/plugins/import/ImportXml.class.php index 496a4ddc4f63..7d84dd2bc4a6 100644 --- a/libraries/plugins/import/ImportXml.class.php +++ b/libraries/plugins/import/ImportXml.class.php @@ -45,13 +45,17 @@ public function __construct() */ protected function setProperties() { - $this->properties = array( - 'text' => __('XML'), - 'extension' => 'xml', - 'mime_type' => 'text/xml', - 'options' => array(), - 'options_text' => __('Options') - ); + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText(__('XML')); + $importPluginProperties->setExtension('xml'); + $importPluginProperties->setMimeType('text/xml'); + $importPluginProperties->setOptions(array()); + $importPluginProperties->setOptionsText(__('Options')); + + $this->properties = $importPluginProperties; } /** diff --git a/libraries/plugins/import/README b/libraries/plugins/import/README index 8e840658a1bc..fae847f0643d 100644 --- a/libraries/plugins/import/README +++ b/libraries/plugins/import/README @@ -48,32 +48,56 @@ class Import[Name] extends ImportPlugin */ protected function setProperties() { - // optional - get globals - // set properties - $this->properties = array( // set name of your plugin - 'text' => __('[Name]'), // text to be displayed as choice - 'extension' => '[ext]', // extension this plugin can handle - 'options' => array(), // array of options - 'options_text' => __('Options') - ); + $props = 'libraries/properties/'; + // include the main class for properties for the import plug-ins + include_once "$props/plugins/ImportPluginProperties.class.php"; + // include the group properties classes + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + // include the needed single property items + include_once "$props/options/items/RadioPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setText('[name]'); // the name of your plug-in + $importPluginProperties->setExtension('[ext]'); // extension this plug-in can handle + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); // optional : - // type - bool or text, or begin/end group_subgroup + // create primary items and add them to the group + // type - one of the classes listed in libraries/properties/options/items/ // name - form element name // text - description in GUI - // size - size of text element (optional) - // len - maximal size of input (optional) - $this->properties['options'] = array( - array( - 'type' => 'begin_group', - 'name' => 'general_opts' - ), - [..], + // size - size of text element + // len - maximal size of input + // values - possible values of the item + $leaf = new RadioPropertyItem(); + $leaf->setName("structure_or_data"); + $leaf->setValues( array( - 'type' => 'end_group' + 'structure' => __('structure'), + 'data' => __('data'), + 'structure_and_data' => __('structure and data') ) ); + $generalOptions->addProperty($leaf); + + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; } /** diff --git a/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php index 43bc65792d02..947ad310f0e8 100644 --- a/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php @@ -45,11 +45,14 @@ public static function getInfo() */ public function applyTransformation($buffer, $options = array(), $meta = '') { + + $append_part = (isset($options[2]) && $options[2]) ? '' : $buffer; + $transform_options = array ( 'string' => '' . (isset($options[1]) ? $options[1] : $buffer) . '' + . '" target="_new">' . (isset($options[1]) ? $options[1] : $buffer) . '' ); $buffer = PMA_transformation_global_html_replace( diff --git a/libraries/properties/plugins/ExportPluginProperties.class.php b/libraries/properties/plugins/ExportPluginProperties.class.php index b8f8465da8ca..51f9d7da796a 100644 --- a/libraries/properties/plugins/ExportPluginProperties.class.php +++ b/libraries/properties/plugins/ExportPluginProperties.class.php @@ -55,7 +55,6 @@ class ExportPluginProperties extends PluginPropertyItem */ private $_mimeType; - /** * Whether to force or not * diff --git a/libraries/properties/plugins/ImportPluginProperties.class.php b/libraries/properties/plugins/ImportPluginProperties.class.php index 24ff567d616d..e377fc7b0d43 100644 --- a/libraries/properties/plugins/ImportPluginProperties.class.php +++ b/libraries/properties/plugins/ImportPluginProperties.class.php @@ -48,6 +48,13 @@ class ImportPluginProperties extends PluginPropertyItem */ private $_optionsText; + /** + * MIME Type + * + * @var string + */ + private $_mimeType; + /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ @@ -152,5 +159,27 @@ public function setOptionsText($optionsText) { $this->_optionsText = $optionsText; } + + /** + * Gets the MIME type + * + * @return string + */ + public function getMimeType() + { + return $this->_mimeType; + } + + /** + * Sets the MIME type + * + * @param string $mimeType MIME type + * + * @return void + */ + public function setMimeType($mimeType) + { + $this->_mimeType = $mimeType; + } } ?> \ No newline at end of file diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index d7ccb5fc15dd..278883b2d790 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -95,7 +95,7 @@ function PMA_extractPrivInfo($row = '', $enableHTML = false) } unset($current_grant); } - + $privs = array(); $allPrivileges = true; foreach ($grants as $current_grant) { @@ -156,8 +156,8 @@ function PMA_extractPrivInfo($row = '', $enableHTML = false) /** * Get the grants array which contains all the privilege types * and relevent grant messages - * - * @return array + * + * @return array */ function PMA_getGrantsArray() { @@ -331,12 +331,12 @@ function PMA_getHtmlForDisplayColumnPrivileges($columns, $row, $name_for_select, /** * Get sql query for display privileges table - * + * * @param string $db the database * @param string $table the table * @param string $username username for database connection * @param string $hostname hostname for database connection - * + * * @return string sql query */ function PMA_getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname) @@ -376,7 +376,7 @@ function PMA_getHtmlToDisplayPrivilegesTable($random_n, $db = '*', $table = '*', $submit = true ) { $html_output = ''; - + if ($db == '*') { $table = '*'; } @@ -478,10 +478,10 @@ function PMA_getHtmlToDisplayPrivilegesTable($random_n, $db = '*', /** * Get HTML for "Resource limits" - * + * * @param array $row first row from result or boolean false - * - * @return string html snippet + * + * @return string html snippet */ function PMA_getHtmlForDisplayResourceLimits($row) { @@ -490,10 +490,10 @@ function PMA_getHtmlForDisplayResourceLimits($row) . '

' . '' . __('Note: Setting these options to 0 (zero) removes the limit.') . '

' . "\n"; - + $html_output .= '
' . "\n" . '' . "\n" @@ -503,7 +503,7 @@ function PMA_getHtmlForDisplayResourceLimits($row) . 'title="' . __('Limits the number of queries the user may send to the server per hour.') . '" />' . "\n" . '
' . "\n"; - + $html_output .= '
' . "\n" . '
' . "\n"; - + $html_output .= '
' . "\n" . '
' . "\n"; - + $html_output .= '
' . "\n" . '
' . "\n"; - + $html_output .= '' . "\n"; - + return $html_output; } /** * Get the HTML snippet for table specific privileges - * + * * @param string $username username for database connection * @param string $hostname hostname for database connection * @param string $db the database * @param string $table the table * @param boolean $columns columns array - * + * * @return string $html_output */ function PMA_getHtmlForTableSpecificPrivileges($username, $hostname, $db @@ -594,24 +594,24 @@ function PMA_getHtmlForTableSpecificPrivileges($username, $hostname, $db // privs that are attached to a specific column $html_output .= PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn($columns, $row); - - // privs that are not attached to a specific column + + // privs that are not attached to a specific column $html_output .= '
' . "\n" . PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn($row) . '
' . "\n"; - + // for Safari 2.0.2 $html_output .= '
' . "\n"; - + return $html_output; } /** * Get HTML snippet for privileges that are attached to a specific column - * + * * @param string $columns columns array * @param array $row first row from result or boolean false - * + * * @return string $html_output */ function PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn($columns, $row) @@ -638,11 +638,11 @@ function PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn($columns, $row) return $html_output; } -/** +/** * Get HTML for privileges that are not attached to a specific column - * + * * @param array $row first row from result or boolean false - * + * * @return string $html_output */ function PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn($row) @@ -708,13 +708,13 @@ function PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn($row) /** * Get HTML for global or database specific privileges - * + * * @param string $db the database * @param string $table the table * @param string $row first row from result or boolean false * @param string $random_n a random number that will be appended * to the id of the user forms - * + * * @return string $html_output */ function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n) @@ -732,7 +732,7 @@ function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n) // a d m i n i s t r a t i o n $privTable[2] = PMA_getAdministrationPrivilegeTable($db); - + $html_output = '' . __('Uncheck All') . ')' . "\n" . '' . "\n" - . '

' - . __('Note: MySQL privilege names are expressed in English') + . '

' + . __('Note: MySQL privilege names are expressed in English') . '

' . "\n"; // Output the Global privilege tables with checkboxes @@ -772,15 +772,15 @@ function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n) } // for Safari 2.0.2 $html_output .= '
' . "\n"; - + return $html_output; } /** * Get data privilege table as an array - * + * * @param string $db the database - * + * * @return string data privilege table */ function PMA_getDataPrivilegeTable($db) @@ -803,10 +803,10 @@ function PMA_getDataPrivilegeTable($db) /** * Get structure privilege table as an array - * + * * @param string $table the table * @param array $row first row from result or boolean false - * + * * @return string structure privilege table */ function PMA_getStructurePrivilegeTable($table, $row) @@ -826,7 +826,7 @@ function PMA_getStructurePrivilegeTable($table, $row) array('Index', 'INDEX', __('Allows creating and dropping indexes.')), array('Drop', 'DROP', - ($table == '*' + ($table == '*' ? __('Allows dropping databases and tables.') : __('Allows dropping tables.') ) @@ -879,9 +879,9 @@ function PMA_getStructurePrivilegeTable($table, $row) /** * Get administration privilege table as an array - * + * * @param string $db the table - * + * * @return string administration privilege table */ function PMA_getAdministrationPrivilegeTable($db) @@ -941,11 +941,11 @@ function PMA_getAdministrationPrivilegeTable($db) /** * Get HTML snippet for global privileges table with check boxes - * + * * @param array $privTable privileges table array * @param array $privTable_names names of the privilege tables (Data, Structure, Administration) * @param array $row first row from result or boolean false - * + * * @return string $html_output */ function PMA_getHtmlForGlobalPrivTableWithCheckboxes($privTable, $privTable_names, $row) @@ -999,35 +999,35 @@ function PMA_getHtmlForDisplayLoginInformationFields($mode = 'new') . ' ' . __('User name') . ':' . "\n" . '' . "\n" . '' . "\n"; - + $html_output .= '' . "\n" . '' . "\n"; - + $html_output .= '' . "\n" . '' . "\n"; - + $html_output .= '
' . "\n" . '' . "\n"; - + $html_output .= '' . "\n" . ' ' . "\n" . '' . "\n"; - + $html_output .= '' . "\n" . ' ' . __('Password') . ':' . "\n" @@ -1147,7 +1147,7 @@ function PMA_getHtmlForDisplayLoginInformationFields($mode = 'new') . '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n"; - + return $html_output; } /** * Get the list of privileges and list of compared privileges as strings * and return a array that contains both strings - * + * * @return array $list_of_privileges, $list_of_compared_privileges */ function PMA_getListOfPrivilegesAndComparedPrivileges() @@ -1480,10 +1480,10 @@ function PMA_getListOfPrivilegesAndComparedPrivileges() /** * Get the HTML for user form and check the privileges for a particular database. - * + * * @param string $link_edit standard link for edit * @param string $conditional_class if ajaxable 'Ajax' otherwise '' - * + * * @return string $html_output */ function PMA_getHtmlForSpecificDbPrivileges($link_edit, $conditional_class) @@ -1496,14 +1496,14 @@ function PMA_getHtmlForSpecificDbPrivileges($link_edit, $conditional_class) . ' ' . sprintf( __('Users having access to "%s"'), - '' . htmlspecialchars($_REQUEST['checkprivs']) . '' ) . "\n" . '' . "\n"; - + $html_output .= '' . "\n" . '' . "\n" . '' . "\n" @@ -1553,7 +1553,7 @@ function PMA_getHtmlForSpecificDbPrivileges($link_edit, $conditional_class) // Offer to create a new user for the current database $html_output .= '
' . "\n" . '' . __('New') . '' . "\n"; - + $html_output .= '' . "\n" . $common_functions->getIcon('b_usradd.png') . ' ' . __('Add user') . '' . "\n"; - + $html_output .= '
' . "\n"; } return $html_output; @@ -1571,13 +1571,13 @@ function PMA_getHtmlForSpecificDbPrivileges($link_edit, $conditional_class) /** * Get HTML snippet for table body of specific database privileges - * + * * @param boolean $found whether user found or not - * @param array $row array of rows from mysql , db table with list of privileges + * @param array $row array of rows from mysql , db table with list of privileges * @param boolean $odd_row whether odd or not * @param string $link_edit standard link for edit * @param string $res ran sql query - * + * * @return string $html_output */ function PMA_getHtmlTableBodyForSpecificDbPrivs($found, $row, $odd_row, @@ -1602,12 +1602,12 @@ function PMA_getHtmlTableBodyForSpecificDbPrivs($found, $row, $odd_row, if (count($current_privileges) > 1) { $html_output .= ' rowspan="' . count($current_privileges) . '"'; } - $html_output .= '>' + $html_output .= '>' . (empty($current_user) ? '' . __('Any') . '' : htmlspecialchars($current_user)) . "\n" . '' . "\n"; - + $html_output .= ' 1) { $html_output .= ' rowspan="' . count($current_privileges) . '"'; @@ -1632,14 +1632,14 @@ function PMA_getHtmlTableBodyForSpecificDbPrivs($found, $row, $odd_row, } $html_output .= "\n" . '' . "\n"; - + $html_output .='' . "\n"; - + $html_output .= '' . "\n" @@ -1672,22 +1672,22 @@ function PMA_getHtmlTableBodyForSpecificDbPrivs($found, $row, $odd_row, . '' . "\n"; } $html_output .= '' . "\n"; - + return $html_output; } /** * Define some standard links - * $link_edit, $link_revoke, $link_export, $link_export_all - * + * $link_edit, $link_revoke, $link_export + * * @param string $conditional_class if ajaxable 'Ajax' otherwise '' - * - * @return array with some standard links + * + * @return array with some standard links */ function PMA_getStandardLinks($conditional_class) { $common_functions = PMA_CommonFunctions::getInstance(); - + $link_edit = '' - . $common_functions->getIcon('b_tblexport.png', __('Export all')) - . ''; - - return array($link_edit, $link_revoke, $link_export, $link_export_all); + return array($link_edit, $link_revoke, $link_export); } /** * This function return the extra data array for the ajax behavior - * + * * @param string $sql_query sql query * @param string $link_edit standard link for edit * @param boolean $dbname_is_wildcard whether database name is wildcard or not - * + * * @return array $extra_data */ function PMA_getExtraDataForAjaxBehavior($password, $link_export, $sql_query, $link_edit, $dbname_is_wildcard, $hostname, $username ) { if (strlen($sql_query)) { - $extra_data['sql_query'] + $extra_data['sql_query'] = PMA_CommonFunctions::getInstance()->getMessage(null, $sql_query); } @@ -1759,8 +1749,8 @@ function PMA_getExtraDataForAjaxBehavior($password, $link_export, $sql_query, . htmlspecialchars($username) . '&#27;' . htmlspecialchars($hostname) . '" />' . '' . "\n" - . '' . "\n" . '' . "\n"; @@ -1833,11 +1823,11 @@ function PMA_getExtraDataForAjaxBehavior($password, $link_export, $sql_query, } /** - * Get the HTML snippet for change user login information - * + * Get the HTML snippet for change user login information + * * @param string $username username * @param string $hostname host name - * + * * @return string HTML snippet */ function PMA_getChangeLoginInformationHtmlForm($username, $hostname) @@ -1859,7 +1849,7 @@ function PMA_getChangeLoginInformationHtmlForm($username, $hostname) . '' . __('Change Login Information / Copy User') . '' . "\n" . PMA_getHtmlForDisplayLoginInformationFields('change'); - + $html_output .= '
' . "\n" . ' ' . __('Create a new user with the same privileges and ...') @@ -1869,22 +1859,22 @@ function PMA_getChangeLoginInformationHtmlForm($username, $hostname) ); $html_output .= '
' . "\n" . '' . "\n"; - + $html_output .= '' . "\n" . '' . "\n"; - + return $html_output; } /** * Provide a line with links to the relevant database and table - * - * @param string $url_dbname url database name that urlencode() string + * + * @param string $url_dbname url database name that urlencode() string * @param string $dbname database name * @param string $tablename table name - * + * * @return string HTML snippet */ function PMA_getLinkToDbAndTable($url_dbname, $dbname, $tablename) @@ -1916,11 +1906,11 @@ function PMA_getLinkToDbAndTable($url_dbname, $dbname, $tablename) * no db name given, so we want all privs for the given user * db name was given, so we want all user specific rights for this db * So this function returns user rights as an array - * + * * @param string $dbname database name * @param array $tables tables * @param string $user_host_condition a where clause that containd user's host condition - * + * * @return array $db_rights database rights */ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) @@ -1940,7 +1930,7 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) $tables_to_search_for_users = array('columns_priv',); $dbOrTableName = 'Table_name'; } - + $db_rights_sqls = array(); foreach ($tables_to_search_for_users as $table_search_in) { if (in_array($table_search_in, $tables)) { @@ -2016,13 +2006,13 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) /** * Display user rights in table rows(Table specific or database specific privs) - * + * * @param array $db_rights user's database rights array * @param string $link_edit standard link to edit privileges * @param string $link_revoke standard link to revoke * @param string $hostname host name * @param string $username username - * + * * @return array $found_rows, $html_output */ function PMA_getHtmlForDisplayUserRightsInRows($db_rights, $link_edit, $dbname, @@ -2042,7 +2032,7 @@ function PMA_getHtmlForDisplayUserRightsInRows($db_rights, $link_edit, $dbname, $found_rows[] = (! strlen($dbname)) ? $row['Db'] : $row['Table_name']; $html_output .= '' . "\n" - . '' . "\n" - . '' . "\n" . '' . "\n" - . '' . "\n"; // display rows list ($found_rows, $html_out) = PMA_getHtmlForDisplayUserRightsInRows( @@ -2166,15 +2156,15 @@ function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname $html_output .= $html_out; $html_output .= '' . "\n"; $html_output .='
' . __('User') . '' . "\n" . '' . "\n" - . '' + . '' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, true)) . "\n" . '' . "\n" . '' . "\n" . '' . ($current['Grant_priv'] == 'Y' ? __('Yes') : __('No')) . "\n" . '
' . htmlspecialchars($hostname) . '
' + . '' . htmlspecialchars((! strlen($dbname)) ? $row['Db'] : $row['Table_name']) @@ -2051,7 +2041,7 @@ function PMA_getHtmlForDisplayUserRightsInRows($db_rights, $link_edit, $dbname, . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, true)) . "\n" . '' + . '' . ((((! strlen($dbname)) && $row['Grant_priv'] == 'Y') || (strlen($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ? __('Yes') @@ -2096,13 +2086,13 @@ function PMA_getHtmlForDisplayUserRightsInRows($db_rights, $link_edit, $dbname, /** * Get a HTML table for display user's tabel specific or database specific rights - * + * * @param string $username username * @param string $hostname host name * @param string $dbname database name * @param string $link_edit standard link to edit privileges * @param string $link_revoke standard link to revoke - * + * * @return array $html_output, $found_rows */ function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname @@ -2128,7 +2118,7 @@ function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname . '' . "\n" . '' . __('Privileges') . '' . __('Grant') . '' + . '' . (! strlen($dbname) ? __('Table-specific privileges') : __('Column-specific privileges') @@ -2156,7 +2146,7 @@ function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname $db_rights = PMA_getUserSpecificRights($tables, $user_host_condition, $dbname); ksort($db_rights); - + $html_output .= '
' . "\n"; - + return array($html_output, $found_rows); } /** * Get HTML for display select db - * + * * @param array $found_rows isset($dbname)) ? $row['Db'] : $row['Table_name'] - * + * * @return string HTML snippet */ function PMA_getHTmlForDisplaySelectDbInEditPrivs($found_rows) @@ -2208,28 +2198,28 @@ function PMA_getHTmlForDisplaySelectDbInEditPrivs($found_rows) /** * Get HTML for display table in edit privilege - * + * * @param string $dbname database naame * @param array $found_rows isset($dbname)) ? $row['Db'] : $row['Table_name'] - * + * * @return string HTML snippet */ function PMA_displayTablesInEditPrivs($dbname, $found_rows) { $common_functions = PMA_CommonFunctions::getInstance(); - + $html_output = '' . "\n"; - $html_output .= '