diff --git a/ChangeLog b/ChangeLog index 7a14f69867..7f30c2356d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -49,6 +49,7 @@ VerboseMultiSubmit, ReplaceHelpImg - bug #3534979 [interface] Copy Database Ajax feedback vanishes long before copying is done - bug #3527531 [interface] GC-maxlifetime warning incorrectly displayed - bug #3526916 [interface] Search fails with JS error when tooltips disabled +- bug #3544366 [interface] Event comments not saved 3.5.2.0 (2012-07-07) - bug #3521416 [interface] JS error when editing index diff --git a/Documentation.html b/Documentation.html index 1a120427bd..d23017b1b0 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1561,7 +1561,7 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE
$cfg['ShowTooltipAliasDB'] boolean
If tool-tips are enabled and a DB comment is set, this will flip the - comment and the real name. That means that if you have a table called + comment and the real name. That means that if you have a database called 'user0001' and add the comment 'MyName' on it, you will see the name 'MyName' used consequently in the left frame and the tool-tip shows the real name of the DB.
diff --git a/libraries/Advisor.class.php b/libraries/Advisor.class.php index c12b749e0d..f4efd8622a 100644 --- a/libraries/Advisor.class.php +++ b/libraries/Advisor.class.php @@ -317,14 +317,14 @@ class Advisor // Actually evaluate the code ob_start(); - eval('$value = '.$expr.';'); + eval('$value = ' . $expr . ';'); $err = ob_get_contents(); ob_end_clean(); // Error handling if ($err) { throw new Exception( - strip_tags($err) . '
Executed code: $value = ' . $expr . ';' + strip_tags($err) . '
Executed code: $value = ' . htmlspecialchars($expr) . ';' ); } return $value; diff --git a/libraries/CommonFunctions.class.php b/libraries/CommonFunctions.class.php index 896f3429ee..6bbf8629a0 100644 --- a/libraries/CommonFunctions.class.php +++ b/libraries/CommonFunctions.class.php @@ -9,12 +9,12 @@ /** * Misc functions used all over the scripts. - * + * * @package PhpMyAdmin */ class PMA_CommonFunctions { - + /** * PMA_CommonFunctions instance * @@ -23,8 +23,8 @@ class PMA_CommonFunctions * @var object */ private static $_instance; - - + + /** * Creates a new class instance * @@ -33,8 +33,8 @@ class PMA_CommonFunctions private function __construct() { } - - + + /** * Returns the singleton PMA_CommonFunctions object * @@ -47,7 +47,7 @@ class PMA_CommonFunctions } return self::$_instance; } - + /** * Detects which function to use for pow. @@ -168,6 +168,10 @@ class PMA_CommonFunctions public function getImage($image, $alternate = '', $attributes = array()) { static $sprites; // cached list of available sprites (if any) + if (defined(TESTSUITE)) { + // prevent caching in testsuite + unset($sprites); + } $url = ''; $is_sprite = false; @@ -1306,10 +1310,10 @@ class PMA_CommonFunctions $php_link = ' [' . $this->linkOrButton($php_link, $_message) . ']'; if (isset($GLOBALS['show_as_php'])) { - + $runquery_link = 'import.php' . PMA_generate_common_url($url_params); - + $php_link .= ' [' . $this->linkOrButton($runquery_link, __('Submit Query')) . ']'; @@ -2172,7 +2176,7 @@ class PMA_CommonFunctions * would have to check if the error message file is always available * * @param array $params The names of the parameters needed by the calling script - * @param bool $request Whether to include this list in checking for + * @param bool $request Whether to include this list in checking for * special params * * @return void @@ -2348,19 +2352,19 @@ class PMA_CommonFunctions } else { $con_val = '= \'' . $this->sqlAddSlashes($row[$i], false, true) . '\''; - } + } } if ($con_val != null) { $condition .= $con_val . ' AND'; - if ($meta->primary_key > 0) { + if ($meta->primary_key > 0) { $primary_key .= $condition; - $primary_key_array[$con_key] = $con_val; - } elseif ($meta->unique_key > 0) { + $primary_key_array[$con_key] = $con_val; + } elseif ($meta->unique_key > 0) { $unique_key .= $condition; - $unique_key_array[$con_key] = $con_val; + $unique_key_array[$con_key] = $con_val; } $nonprimary_condition .= $condition; @@ -2373,18 +2377,18 @@ class PMA_CommonFunctions // but use conjunction of all values if no primary key $clause_is_unique = true; - if ($primary_key) { + if ($primary_key) { $preferred_condition = $primary_key; $condition_array = $primary_key_array; - } elseif ($unique_key) { + } elseif ($unique_key) { $preferred_condition = $unique_key; $condition_array = $unique_key_array; - } elseif (! $force_unique) { + } elseif (! $force_unique) { $preferred_condition = $nonprimary_condition; $condition_array = $nonprimary_condition_array; - $clause_is_unique = false; + $clause_is_unique = false; } $where_clause = trim(preg_replace('|\s?AND$|', '', $preferred_condition)); @@ -2636,7 +2640,7 @@ class PMA_CommonFunctions . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">' . $caption1 . ''; - $_url_params['pos'] = $pos - $max_count; + $_url_params['pos'] = $pos - $max_count; $list_navigator_html .= '' . $caption2 . ''; @@ -2758,8 +2762,8 @@ class PMA_CommonFunctions */ public function getExternalBug( $functionality, $component, $minimum_version, $bugref - ) { - $ext_but_html = ''; + ) { + $ext_but_html = ''; if (($component == 'mysql') && (PMA_MYSQL_INT_VERSION < $minimum_version)) { $ext_but_html .= $this->showHint( sprintf( @@ -2768,7 +2772,7 @@ class PMA_CommonFunctions PMA_linkURL('http://bugs.mysql.com/') . $bugref ) ); - } + } return $ext_but_html; } @@ -3447,7 +3451,7 @@ class PMA_CommonFunctions /* Optional escaping */ if (! is_null($escape)) { - foreach ($replace as $key => $val) { + foreach ($replace as $key => $val) { $replace[$key] = ($escape == 'backquote') ? $this->$escape($val) : $escape($val); @@ -4198,7 +4202,7 @@ class PMA_CommonFunctions return $values; } - + } ?> diff --git a/libraries/DbSearch.class.php b/libraries/DbSearch.class.php index 8e7f14cf0b..7c42982bbb 100644 --- a/libraries/DbSearch.class.php +++ b/libraries/DbSearch.class.php @@ -93,19 +93,6 @@ class PMA_DbSearch $this->_setSearchParams(); } - /** - * Set CommmonFunctions - * - * @param PMA_CommonFunctions $commonFunctions - * - * @return void - */ - public function setCommonFunctions(PMA_CommonFunctions $commonFunctions) - { - $this->_common_functions = $commonFunctions; - } - - /** * Get CommmonFunctions * diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 3ecc853ef1..9fbde32e25 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -19,6 +19,7 @@ if (! defined('PHPMYADMIN')) { class PMA_DisplayResults { + // Define constants const NO_EDIT_OR_DELETE = 'nn'; const UPDATE_ROW = 'ur'; const DELETE_ROW = 'dr'; @@ -29,6 +30,9 @@ class PMA_DisplayResults const POSITION_BOTH = 'both'; const POSITION_NONE = 'none'; + const PLACE_TOP_DIRECTION_DROPDOWN = 'top_direction_dropdown'; + const PLACE_BOTTOM_DIRECTION_DROPDOWN = 'bottom_direction_dropdown'; + const DISP_DIR_HORIZONTAL = 'horizontal'; const DISP_DIR_HORIZONTAL_FLIPPED = 'horizontalflipped'; const DISP_DIR_VERTICAL = 'vertical'; @@ -62,28 +66,126 @@ class PMA_DisplayResults const TABLE_TYPE_INNO_DB = 'InnoDB'; const ALL_ROWS = 'all'; const QUERY_TYPE_SELECT = 'SELECT'; - - + + + // Declare global fields + /** PMA_CommonFunctions object */ private $_common_functions; - private $_db, $_table, $_goto, $_sql_query; - + /** array with properties of the class */ + private $_property_array = array( + + /** string Database name */ + '_db' => null, + + /** string Table name */ + '_table' => null, + + /** string the URL to go back in case of errors */ + '_goto' => null, + + /** string the SQL query */ + '_sql_query' => null, + + /** + * integer the total number of rows returned by the SQL query without any + * appended "LIMIT" clause programmatically + */ + '_unlim_num_rows' => null, + + /** array meta information about fields */ + '_fields_meta' => null, + + /** boolean */ + '_is_count' => null, + + /** integer */ + '_is_export' => null, + + /** boolean */ + '_is_func' => null, + + /** integer */ + '_is_analyse' => null, + + /** integer the total number of rows returned by the SQL query */ + '_num_rows' => null, + + /** integer the total number of fields returned by the SQL query */ + '_fields_cnt' => null, + + /** double time taken for execute the SQL query */ + '_querytime' => null, + + /** string path for theme images directory */ + '_pma_theme_image' => null, + + /** string */ + '_text_dir' => null, + + /** boolean */ + '_is_maint' => null, + + /** boolean */ + '_is_explain' => null, + + /** boolean */ + '_is_show' => null, + + /** array table definitions */ + '_showtable' => null, + + /** string */ + '_printview' => null, + + /** string URL query */ + '_url_query' => null, + + /** array column names to highlight */ + '_highlight_columns' => null, + + /** array informations used with vertical display mode */ + '_vertical_display' => null, + + /** array mime types information of fields */ + '_mime_map' => null + ); + + /** - * Set CommmonFunctions - * - * @param PMA_CommonFunctions $commonFunctions - * + * Get any property of this class + * + * @param string $property name of the property + * + * @return if property exist, value of the relavant property + */ + public function __get($property) + { + if(array_key_exists($property, $this->_property_array)) { + return $this->_property_array[$property]; + } + } + + + /** + * Set values for any property of this class + * + * @param string $property name of the property + * @param $value value to set + * * @return void */ - public function setCommonFunctions(PMA_CommonFunctions $commonFunctions) - { - $this->_common_functions = $commonFunctions; + public function __set($property, $value) + { + if(array_key_exists($property, $this->_property_array)) { + $this->_property_array[$property] = $value; + } } - - + + /** * Get CommmonFunctions - * + * * @return CommonFunctions object */ public function getCommonFunctions() @@ -93,7 +195,7 @@ class PMA_DisplayResults } return $this->_common_functions; } - + /** * Constructor for PMA_DisplayResults class @@ -107,13 +209,67 @@ class PMA_DisplayResults */ public function __construct($db, $table, $goto, $sql_query) { - $this->_db = $db; - $this->_table = $table; - $this->_goto = $goto; - $this->_sql_query = $sql_query; + $this->__set('_db', $db); + $this->__set('_table', $table); + $this->__set('_goto', $goto); + $this->__set('_sql_query', $sql_query); } + /** + * Set properties which were not initialized at the constructor + * + * @param type $unlim_num_rows integer the total number of rows returned by + * the SQL query without any appended + * "LIMIT" clause programmatically + * @param type $fields_meta array meta information about fields + * @param type $is_count boolean + * @param type $is_export integer + * @param type $is_func boolean + * @param type $is_analyse integer + * @param type $num_rows integer total no. of rows returned by SQL query + * @param type $fields_cnt integer total no.of fields returned by SQL query + * @param type $querytime double time taken for execute the SQL query + * @param type $pmaThemeImage string path for theme images directory + * @param type $text_dir string + * @param type $is_maint boolean + * @param type $is_explain boolean + * @param type $is_show boolean + * @param type $showtable array table definitions + * @param type $printview string + * @param type $url_query string URL query + * + * @return void + * + * @see sql.php + */ + public function setProperties( + $unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func, + $is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $text_dir, + $is_maint, $is_explain, $is_show, $showtable, $printview, $url_query + ) { + + $this->__set('_unlim_num_rows', $unlim_num_rows); + $this->__set('_fields_meta', $fields_meta); + $this->__set('_is_count', $is_count); + $this->__set('_is_export', $is_export); + $this->__set('_is_func', $is_func); + $this->__set('_is_analyse', $is_analyse); + $this->__set('_num_rows', $num_rows); + $this->__set('_fields_cnt', $fields_cnt); + $this->__set('_querytime', $querytime); + $this->__set('_pma_theme_image', $pmaThemeImage); + $this->__set('_text_dir', $text_dir); + $this->__set('_is_maint', $is_maint); + $this->__set('_is_explain', $is_explain); + $this->__set('_is_show', $is_show); + $this->__set('_showtable', $showtable); + $this->__set('_printview', $printview); + $this->__set('_url_query', $url_query); + + } // end of the 'setProperties()' function + + /** * Defines the display mode to use for the results of a SQL query * @@ -149,6 +305,14 @@ class PMA_DisplayResults private function _setDisplayMode(&$the_disp_mode, &$the_total) { + // Following variables are needed for use in isset/empty or + // use with array indexes or safe use in foreach + $db = $this->__get('_db'); + $table = $this->__get('_table'); + $unlim_num_rows = $this->__get('_unlim_num_rows'); + $fields_meta = $this->__get('_fields_meta'); + $printview = $this->__get('_printview'); + // 1. Initializes the $do_display array $do_display = array(); $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1]; @@ -163,7 +327,8 @@ class PMA_DisplayResults // 2. Display mode is not "false for all elements" -> updates the // display mode if ($the_disp_mode != 'nnnn000000') { - if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { + + if (isset($printview) && ($printview == '1')) { // 2.0 Print view -> set all elements to false! $do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE; // no edit link $do_display['del_lnk'] = self::NO_EDIT_OR_DELETE; // no delete link @@ -173,8 +338,9 @@ class PMA_DisplayResults $do_display['bkm_form'] = (string) '0'; $do_display['text_btn'] = (string) '0'; $do_display['pview_lnk'] = (string) '0'; - } elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] - || $GLOBALS['is_maint'] || $GLOBALS['is_explain'] + + } elseif ($this->__get('_is_count') || $this->__get('_is_analyse') + || $this->__get('_is_maint') || $this->__get('_is_explain') ) { // 2.1 Statement is a "SELECT COUNT", a // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or @@ -185,14 +351,15 @@ class PMA_DisplayResults $do_display['nav_bar'] = (string) '0'; $do_display['ins_row'] = (string) '0'; $do_display['bkm_form'] = (string) '1'; - if ($GLOBALS['is_maint']) { + + if ($this->__get('_is_maint')) { $do_display['text_btn'] = (string) '1'; } else { $do_display['text_btn'] = (string) '0'; } $do_display['pview_lnk'] = (string) '1'; - } elseif ($GLOBALS['is_show']) { + } elseif ($this->__get('_is_show')) { // 2.2 Statement is a "SHOW..." /** * 2.2.1 @@ -202,7 +369,7 @@ class PMA_DisplayResults '@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?' . 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS' . ')@i', - $GLOBALS['sql_query'], $which + $this->__get('_sql_query'), $which ); if (isset($which[1]) && (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) @@ -225,21 +392,25 @@ class PMA_DisplayResults $do_display['bkm_form'] = (string) '1'; $do_display['text_btn'] = (string) '1'; $do_display['pview_lnk'] = (string) '1'; + } else { // 2.3 Other statements (ie "SELECT" ones) -> updates // $do_display['edit_lnk'], $do_display['del_lnk'] and // $do_display['text_btn'] (keeps other default values) - $prev_table = $GLOBALS['fields_meta'][0]->table; + $prev_table = $fields_meta[0]->table; $do_display['text_btn'] = (string) '1'; - for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) { + + for ($i = 0; $i < $this->__get('_fields_cnt'); $i++) { + $is_link = ($do_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) || ($do_display['del_lnk'] != self::NO_EDIT_OR_DELETE) || ($do_display['sort_lnk'] != '0') || ($do_display['ins_row'] != '0'); + // 2.3.2 Displays edit/delete/sort/insert links? if ($is_link - && (($GLOBALS['fields_meta'][$i]->table == '') - || ($GLOBALS['fields_meta'][$i]->table != $prev_table)) + && (($fields_meta[$i]->table == '') + || ($fields_meta[$i]->table != $prev_table)) ) { // don't display links $do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE; @@ -254,21 +425,23 @@ class PMA_DisplayResults break; } } // end if (2.3.2) + // 2.3.3 Always display print view link $do_display['pview_lnk'] = (string) '1'; - $prev_table = $GLOBALS['fields_meta'][$i]->table; + $prev_table = $fields_meta[$i]->table; + } // end for } // end if..elseif...else (2.1 -> 2.3) } // end if (2) // 3. Gets the total number of rows if it is unknown - if (isset($GLOBALS['unlim_num_rows']) && $GLOBALS['unlim_num_rows'] != '') { - $the_total = $GLOBALS['unlim_num_rows']; + if (isset($unlim_num_rows) && $unlim_num_rows != '') { + $the_total = $unlim_num_rows; } elseif ((($do_display['nav_bar'] == '1') || ($do_display['sort_lnk'] == '1')) - && (strlen($this->_db) && !empty($this->_table)) + && (strlen($db) && !empty($table)) ) { - $the_total = PMA_Table::countRecords($this->_db, $this->_table); + $the_total = PMA_Table::countRecords($db, $table); } // 4. If navigation bar or sorting fields names URLs should be @@ -280,9 +453,9 @@ class PMA_DisplayResults // - For a VIEW we (probably) did not count the number of rows // so don't test this number here, it would remove the possibility // of sorting VIEW results. - if (isset($GLOBALS['unlim_num_rows']) - && $GLOBALS['unlim_num_rows'] < 2 - && ! PMA_Table::isView($this->_db, $this->_table) + if (isset($unlim_num_rows) + && ($unlim_num_rows < 2) + && ! PMA_Table::isView($db, $table) ) { // force display of navbar for vertical/horizontal display-choice. // $do_display['nav_bar'] = (string) '0'; @@ -302,19 +475,21 @@ class PMA_DisplayResults * Return true if we are executing a query in the form of * "SELECT * FROM ..." * + * @param array $analyzed_sql the analyzed query + * * @return boolean * * @access private * * @see _getTableHeaders(), _getColumnParams() */ - private function _isSelect() + private function _isSelect($analyzed_sql) { - return ! ($GLOBALS['is_count'] || $GLOBALS['is_export'] - || $GLOBALS['is_func'] || $GLOBALS['is_analyse']) - && (count($GLOBALS['analyzed_sql'][0]['select_expr']) == 0) - && isset($GLOBALS['analyzed_sql'][0]['queryflags']['select_from']) - && (count($GLOBALS['analyzed_sql'][0]['table_ref']) == 1); + return ! ($this->__get('_is_count') || $this->__get('_is_export') + || $this->__get('_is_func') || $this->__get('_is_analyse')) + && (count($analyzed_sql[0]['select_expr']) == 0) + && isset($analyzed_sql[0]['queryflags']['select_from']) + && (count($analyzed_sql[0]['table_ref']) == 1); } @@ -357,11 +532,14 @@ class PMA_DisplayResults return '' . '
' - . PMA_generate_common_hidden_inputs($this->_db, $this->_table) + . PMA_generate_common_hidden_inputs( + $this->__get('_db'), $this->__get('_table') + ) . '' . '' - . '' + . '' . $input_for_real_end . '__get('_showtable'); // To use in isset // here, using htmlentities() would cause problems if the query // contains accented characters - $html_sql_query = htmlspecialchars($this->_sql_query); + $html_sql_query = htmlspecialchars($this->__get('_sql_query')); /** * @todo move this to a central place * @todo for other future table types */ - $GLOBALS['is_innodb'] = (isset($GLOBALS['showtable']['Type']) - && $GLOBALS['showtable']['Type'] == self::TABLE_TYPE_INNO_DB); + $is_innodb = (isset($showtable['Type']) + && $showtable['Type'] == self::TABLE_TYPE_INNO_DB); // Navigation bar $table_navigation_html .= '' @@ -430,7 +610,7 @@ class PMA_DisplayResults ) + 1; $nbTotalPage = @ceil( - $GLOBALS['unlim_num_rows'] + $this->__get('_unlim_num_rows') / $_SESSION['tmp_user_values']['max_rows'] ); @@ -438,10 +618,10 @@ class PMA_DisplayResults $table_navigation_html .= ''; @@ -618,8 +799,6 @@ class PMA_DisplayResults * @param string $html_sql_query the sql encoded by html special characters * @param integer $pos_next the offset for the "next" page * @param boolean $is_innodb whether its InnoDB or not - * @param integer $unlim_num_rows the total number of rows returned by the - * @param integer $num_rows the total number of rows returned by the * * @return string $buttons_html html content * @@ -628,7 +807,7 @@ class PMA_DisplayResults * @see _getTableNavigation() */ private function _getMoveForwardButtonsForTableNavigation( - $html_sql_query, $pos_next, $is_innodb, $unlim_num_rows, $num_rows + $html_sql_query, $pos_next, $is_innodb ) { // display the Next button @@ -640,7 +819,9 @@ class PMA_DisplayResults ); // prepare some options for the End button - if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) { + if ($is_innodb + && $this->__get('_unlim_num_rows') > $GLOBALS['cfg']['MaxExactCount'] + ) { $input_for_real_end = ''; // no backquote around this message @@ -651,8 +832,9 @@ class PMA_DisplayResults $onsubmit = 'onsubmit="return ' . ($_SESSION['tmp_user_values']['pos'] - + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows - && $num_rows >= $_SESSION['tmp_user_values']['max_rows']) + + $_SESSION['tmp_user_values']['max_rows'] + < $this->__get('_unlim_num_rows') + && $this->__get('_num_rows') >= $_SESSION['tmp_user_values']['max_rows']) ? 'true' : 'false' . '"'; @@ -660,8 +842,10 @@ class PMA_DisplayResults $buttons_html .= $this->_getTableNavigationButton( '>>', _pgettext('Last page', 'End'), - @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) - * $_SESSION['tmp_user_values']['max_rows']), + @((ceil( + $this->__get('_unlim_num_rows') + / $_SESSION['tmp_user_values']['max_rows'] + )- 1) * $_SESSION['tmp_user_values']['max_rows']), $html_sql_query, $onsubmit, $input_for_real_end, $onclick ); @@ -677,10 +861,6 @@ class PMA_DisplayResults * @param string $html_sql_query the sql encoded by html special * characters * @param integer $pos_next the offset for the "next" page - * @param integer $unlim_num_rows the total number of rows returned - * by the SQL query without any - * programmatically appended "LIMIT" - * clause * @param string $id_for_direction_dropdown the id for the direction dropdown * * @return string $additional_fields_html html content @@ -690,21 +870,21 @@ class PMA_DisplayResults * @see _getTableNavigation() */ private function _getAdditionalFieldsForTableNavigation( - $html_sql_query, $pos_next, - $unlim_num_rows, $id_for_direction_dropdown + $html_sql_query, $pos_next, $id_for_direction_dropdown ) { $additional_fields_html = ''; $additional_fields_html .= '' - . '' + . '' . '' . __('Start row') . ': ' . "\n" . '' . __('Number of rows') . ': ' . "\n" . '__get('_sql_query')); $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows']; @@ -788,56 +971,38 @@ class PMA_DisplayResults // can the result be sorted? if ($is_display['sort_lnk'] == '1') { - // Just as fallback - $unsorted_sql_query = $this->_sql_query; - if (isset($analyzed_sql[0]['unsorted_query'])) { - $unsorted_sql_query = $analyzed_sql[0]['unsorted_query']; - } - // Handles the case of multiple clicks on a column's header - // which would add many spaces before "ORDER BY" in the - // generated query. - $unsorted_sql_query = trim($unsorted_sql_query); + list($unsorted_sql_query, $drop_down_html) + = $this->_getUnsortedSqlAndSortByKeyDropDown( + $analyzed_sql, $sort_expression + ); - // sorting by indexes, only if it makes sense (only one table ref) - if (isset($analyzed_sql) - && isset($analyzed_sql[0]) - && isset($analyzed_sql[0]['querytype']) - && ($analyzed_sql[0]['querytype'] == self::QUERY_TYPE_SELECT) - && isset($analyzed_sql[0]['table_ref']) - && (count($analyzed_sql[0]['table_ref']) == 1) - ) { + $table_headers_html .= $drop_down_html; - // grab indexes data: - $indexes = PMA_Index::getFromTable($this->_table, $this->_db); - - // do we have any index? - if ($indexes) { - $table_headers_html .= $this->_getSortByKeyDropDown( - $indexes, $sort_expression, - $unsorted_sql_query - ); - } - } } // Output data needed for grid editing $table_headers_html .= '' . '
' - . PMA_generate_common_hidden_inputs($this->_db, $this->_table) + . PMA_generate_common_hidden_inputs( + $this->__get('_db'), $this->__get('_table') + ) . '
'; // Output data needed for column reordering and show/hide column - if ($this->_isSelect()) { + if ($this->_isSelect($analyzed_sql)) { $table_headers_html .= $this->_getDataForResettingColumnOrder(); } - $GLOBALS['vertical_display']['emptypre'] = 0; - $GLOBALS['vertical_display']['emptyafter'] = 0; - $GLOBALS['vertical_display']['textbtn'] = ''; + $vertical_display['emptypre'] = 0; + $vertical_display['emptyafter'] = 0; + $vertical_display['textbtn'] = ''; + $full_or_partial_text_link = null; + + $this->__set('_vertical_display', $vertical_display); // Display options (if we are not in print view) - if (! (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1'))) { + if (! (isset($printview) && ($printview == '1'))) { $table_headers_html .= $this->_getOptionsBlock(); @@ -850,103 +1015,14 @@ class PMA_DisplayResults $is_display['del_lnk'] ); - // 1. Displays the full/partial text button (part 1)... - if ($directionCondition) { + // 1. Set $colspan or $rowspan and generate html with full/partial + // text button or link + list($colspan, $rowspan, $button_html) + = $this->_getFeildVisibilityParams( + $directionCondition, $is_display, $full_or_partial_text_link + ); - $table_headers_html .= '' . "\n"; - - $colspan = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) - && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) - ? ' colspan="4"' - : ''; - - } else { - $rowspan = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) - && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) - ? ' rowspan="4"' - : ''; - } - - // ... before the result table - if ((($is_display['edit_lnk'] == self::NO_EDIT_OR_DELETE) - && ($is_display['del_lnk'] == self::NO_EDIT_OR_DELETE)) - && ($is_display['text_btn'] == '1') - ) { - - $GLOBALS['vertical_display']['emptypre'] - = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) - && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; - - if ($directionCondition) { - - $table_headers_html .= '' - . '' - . ''; - - // end horizontal/horizontalflipped mode - } else { - - $span = $GLOBALS['num_rows'] + 1 + floor( - $GLOBALS['num_rows'] - / $_SESSION['tmp_user_values']['repeat_cells'] - ); - $table_headers_html .= ''; - - } // end vertical mode - - } elseif ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) - || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && ($is_display['text_btn'] == '1') - ) { - // ... at the left column of the result table header if possible - // and required - - $GLOBALS['vertical_display']['emptypre'] - = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) - && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; - - if ($directionCondition) { - - $table_headers_html .= ''; - // end horizontal/horizontalflipped mode - - } else { - - $GLOBALS['vertical_display']['textbtn'] - = ' ' . "\n"; - } // end vertical mode - - } elseif ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) - || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) - || ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) - ) { - // ... elseif no button, displays empty(ies) col(s) if required - - $GLOBALS['vertical_display']['emptypre'] - = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) - && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; - - if ($directionCondition) { - - $table_headers_html .= ''; - - // end horizontal/horizontalfipped mode - } else { - $GLOBALS['vertical_display']['textbtn'] = ' ' . "\n"; - } // end vertical mode - - } elseif (($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_NONE) - && ($directionCondition) - ) { - // ... elseif display an empty column if the actions links are - // disabled to match the rest of the table - $table_headers_html .= ''; - } + $table_headers_html .= $button_html; // 2. Displays the fields' name // 2.0 If sorting links should be used, checks if the query is a "JOIN" @@ -956,18 +1032,7 @@ class PMA_DisplayResults // ($GLOBALS['cfg']['ShowBrowseComments']). // Do not show comments, if using horizontalflipped mode, // because of space usage - if ($GLOBALS['cfg']['ShowBrowseComments'] - && ($direction != self::DISP_DIR_HORIZONTAL_FLIPPED) - ) { - $comments_map = array(); - if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) { - foreach ($analyzed_sql[0]['table_ref'] as $tbl) { - $tb = $tbl['table_true_name']; - $comments_map[$tb] = PMA_getComments($this->_db, $tb); - unset($tb); - } - } - } + $comments_map = $this->_getTableCommentsArray($direction, $analyzed_sql); if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] @@ -975,140 +1040,49 @@ class PMA_DisplayResults && ! $_SESSION['tmp_user_values']['hide_transformation'] ) { include_once './libraries/transformations.lib.php'; - $GLOBALS['mime_map'] = PMA_getMIME($this->_db, $this->_table); + $this->__set( + '_mime_map', + PMA_getMIME($this->__get('_db'), $this->__get('_table')) + ); } // See if we have to highlight any header fields of a WHERE query. // Uses SQL-Parser results. - $GLOBALS['highlight_columns'] = array(); - if (isset($analyzed_sql) && isset($analyzed_sql[0]) - && isset($analyzed_sql[0]['where_clause_identifiers']) - ) { + $this->_setHighlightedColumnGlobalField($analyzed_sql); - $wi = 0; - if (isset($analyzed_sql[0]['where_clause_identifiers']) - && is_array($analyzed_sql[0]['where_clause_identifiers']) - ) { - foreach ($analyzed_sql[0]['where_clause_identifiers'] - as $wci_nr => $wci - ) { - $GLOBALS['highlight_columns'][$wci] = 'true'; - } - } - } + list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); - list($col_order, $col_visib) = $this->_getColumnParams(); - - for ($j = 0; $j < $fields_cnt; $j++) { + for ($j = 0; $j < $this->__get('_fields_cnt'); $j++) { // assign $i with appropriate column order $i = $col_order ? $col_order[$j] : $j; // See if this column should get highlight because it's used in the // where-query. - $condition_field = (isset($GLOBALS['highlight_columns'][$fields_meta[$i]->name]) - || isset($GLOBALS['highlight_columns'][$this->getCommonFunctions()->backquote($fields_meta[$i]->name)])) + $condition_field = (isset($highlight_columns[$fields_meta[$i]->name]) + || isset($highlight_columns[$this->getCommonFunctions()->backquote($fields_meta[$i]->name)])) ? true : false; // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled. $comments = $this->_getCommentForRow($comments_map, $fields_meta[$i]); + $vertical_display = $this->__get('_vertical_display'); + if ($is_display['sort_lnk'] == '1') { - // 2.1 Results can be sorted - // 2.1.1 Checks if the table name is required; it's the case - // for a query with a "JOIN" statement and if the column - // isn't aliased, or in queries like - // SELECT `1`.`master_field` , `2`.`master_field` - // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2` + list($order_link, $sorted_headrer_html) + = $this->_getOrderLinkAndSortedHeaderHtml( + $fields_meta[$i], $sort_expression, + $sort_expression_nodirection, $i, $unsorted_sql_query, + $session_max_rows, $direction, $comments, + $sort_direction, $directionCondition, $col_visib, + $col_visib[$j], $condition_field + ); - $sort_tbl = (isset($fields_meta[$i]->table) - && strlen($fields_meta[$i]->table)) - ? $this->getCommonFunctions()->backquote( - $fields_meta[$i]->table - ) . '.' - : ''; + $table_headers_html .= $sorted_headrer_html; - // 2.1.2 Checks if the current column is used to sort the - // results - // the orgname member does not exist for all MySQL versions - // but if found, it's the one on which to sort - $name_to_use_in_sort = $fields_meta[$i]->name; - $is_orgname = false; - if (isset($fields_meta[$i]->orgname) - && strlen($fields_meta[$i]->orgname) - ) { - $name_to_use_in_sort = $fields_meta[$i]->orgname; - $is_orgname = true; - } - - // $name_to_use_in_sort might contain a space due to - // formatting of function expressions like "COUNT(name )" - // so we remove the space in this situation - $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort); - - $is_in_sort = $this->_isInSorted( - $sort_expression, $sort_expression_nodirection, - $sort_tbl, $name_to_use_in_sort - ); - - // 2.1.3 Check the field name for a bracket. - // If it contains one, it's probably a function column - // like 'COUNT(`field`)' - // It still might be a column name of a view. See bug #3383711 - // Check is_orgname. - if ((strpos($name_to_use_in_sort, '(') !== false) && ! $is_orgname) { - $sort_order = "\n" . 'ORDER BY ' . $name_to_use_in_sort . ' '; - } else { - $sort_order = "\n" . 'ORDER BY ' . $sort_tbl - . $this->getCommonFunctions()->backquote( - $name_to_use_in_sort - ) . ' '; - } - unset($name_to_use_in_sort); - unset($is_orgname); - - // 2.1.4 Do define the sorting URL - - list($sort_order, $order_img) = $this->_getSortingUrlParams( - $is_in_sort, $sort_direction, $fields_meta[$i], - $sort_order, $i - ); - - if (preg_match( - '@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|' - . 'LOCK IN SHARE MODE))@is', - $unsorted_sql_query, $regs3 - )) { - $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2]; - } else { - $sorted_sql_query = $unsorted_sql_query . $sort_order; - } - - $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, - 'sql_query' => $sorted_sql_query, - 'session_max_rows' => $session_max_rows - ); - $order_url = 'sql.php' . PMA_generate_common_url($_url_params); - - // 2.1.5 Displays the sorting URL - // enable sort order swapping for image - $order_link = $this->_getSortOrderLink( - $order_img, $i, $direction, $fields_meta[$i], $order_url - ); - - if ($directionCondition) { - $table_headers_html - .= $this->_getDraggableClassForSortableColumns( - $col_visib, $col_visib[$j], $condition_field, - $direction, $fields_meta[$i], $order_link, $comments - ); - } - - $GLOBALS['vertical_display']['desc'][] = ' '; - - // end horizontal/horizontalflipped mode - } else { - $GLOBALS['vertical_display']['textbtn'] = ' ' . "\n"; - } // end vertical mode - } elseif ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) - || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && (($is_display['edit_lnk'] == self::NO_EDIT_OR_DELETE) - && ($is_display['del_lnk'] == self::NO_EDIT_OR_DELETE)) - && (! isset($GLOBALS['is_header_sent']) || ! $GLOBALS['is_header_sent']) - ) { - // ... elseif no button, displays empty columns if required - // (unless coming from Browse mode print view) - - $GLOBALS['vertical_display']['emptyafter'] - = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) - && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 1; - - if ($directionCondition) { - $table_headers_html .= "\n" - . ''; - - // end horizontal/horizontalflipped mode - } else { - $GLOBALS['vertical_display']['textbtn'] = ' ' . "\n"; - } // end vertical mode - } + // Display column at rightside - checkboxes or empty column + $table_headers_html .= $this->_getColumnAtRightSide( + $is_display, $directionCondition, $full_or_partial_text_link, + $colspan, $rowspan + ); if ($directionCondition) { $table_headers_html .= '' @@ -1193,6 +1127,62 @@ class PMA_DisplayResults } // end of the '_getTableHeaders()' function + /** + * Prepare unsorted sql query and sort by key drop down + * + * @param array $analyzed_sql the analyzed query + * @param string $sort_expression sort expression + * + * @return array two element array - $unsorted_sql_query, $drop_down_html + * + * @access private + * + * @see _getTableHeaders() + */ + private function _getUnsortedSqlAndSortByKeyDropDown( + $analyzed_sql, $sort_expression + ) { + + $drop_down_html = ''; + + // Just as fallback + $unsorted_sql_query = $this->__get('_sql_query'); + if (isset($analyzed_sql[0]['unsorted_query'])) { + $unsorted_sql_query = $analyzed_sql[0]['unsorted_query']; + } + // Handles the case of multiple clicks on a column's header + // which would add many spaces before "ORDER BY" in the + // generated query. + $unsorted_sql_query = trim($unsorted_sql_query); + + // sorting by indexes, only if it makes sense (only one table ref) + if (isset($analyzed_sql) + && isset($analyzed_sql[0]) + && isset($analyzed_sql[0]['querytype']) + && ($analyzed_sql[0]['querytype'] == self::QUERY_TYPE_SELECT) + && isset($analyzed_sql[0]['table_ref']) + && (count($analyzed_sql[0]['table_ref']) == 1) + ) { + // grab indexes data: + $indexes = PMA_Index::getFromTable( + $this->__get('_table'), + $this->__get('_db') + ); + + // do we have any index? + if ($indexes) { + $drop_down_html = $this->_getSortByKeyDropDown( + $indexes, $sort_expression, + $unsorted_sql_query + ); + } + } + + return array($unsorted_sql_query, $drop_down_html); + + } // end of the '_getUnsortedSqlAndSortByKeyDropDown()' function + + /** * Prepare sort by key dropdown - html code segment * @@ -1213,7 +1203,9 @@ class PMA_DisplayResults $drop_down_html = ''; $drop_down_html .= '' . "\n" - . PMA_generate_common_hidden_inputs($this->_db, $this->_table) + . PMA_generate_common_hidden_inputs( + $this->__get('_db'), $this->__get('_table') + ) . __('Sort by key') . ': ' . "\n"; + + $colspan = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) + ? ' colspan="4"' + : ''; + + } else { + $rowspan = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) + ? ' rowspan="4"' + : ''; + } + + // ... before the result table + if ((($is_display['edit_lnk'] == self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] == self::NO_EDIT_OR_DELETE)) + && ($is_display['text_btn'] == '1') + ) { + + $vertical_display['emptypre'] + = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; + + if ($directionCondition) { + + $button_html .= '' + . '' + . ''; + + // end horizontal/horizontalflipped mode + } else { + + $span = $this->__get('_num_rows') + 1 + floor( + $this->__get('_num_rows') + / $_SESSION['tmp_user_values']['repeat_cells'] + ); + $button_html .= ''; + + } // end vertical mode + + } elseif ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) + || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) + && ($is_display['text_btn'] == '1') + ) { + // ... at the left column of the result table header if possible + // and required + + $vertical_display['emptypre'] + = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; + + if ($directionCondition) { + + $button_html .= ''; + // end horizontal/horizontalflipped mode + + } else { + + $vertical_display['textbtn'] + = ' ' . "\n"; + } // end vertical mode + + } elseif ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) + || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) + && (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + || ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) + ) { + // ... elseif no button, displays empty(ies) col(s) if required + + $vertical_display['emptypre'] + = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; + + if ($directionCondition) { + + $button_html .= ''; + + // end horizontal/horizontalfipped mode + } else { + $vertical_display['textbtn'] = ' ' . "\n"; + } // end vertical mode + + } elseif (($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_NONE) + && ($directionCondition) + ) { + // ... elseif display an empty column if the actions links are + // disabled to match the rest of the table + $button_html .= ''; + } + + $this->__set('_vertical_display', $vertical_display); + + return array($colspan, $rowspan, $button_html); + + } // end of the '_getFeildVisibilityParams()' function + + + /** + * Get table comments as array + * + * @param boolean $direction display direction, horizontal + * or horizontalflipped + * @param array $analyzed_sql the analyzed query + * + * @return array $comments_map table comments when condition true + * null when condition falls + * + * @access private + * + * @see _getTableHeaders() + */ + private function _getTableCommentsArray($direction, $analyzed_sql) + { + + $comments_map = null; + + if ($GLOBALS['cfg']['ShowBrowseComments'] + && ($direction != self::DISP_DIR_HORIZONTAL_FLIPPED) + ) { + $comments_map = array(); + if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) { + foreach ($analyzed_sql[0]['table_ref'] as $tbl) { + $tb = $tbl['table_true_name']; + $comments_map[$tb] = PMA_getComments($this->__get('_db'), $tb); + unset($tb); + } + } + } + + return $comments_map; + + } // end of the '_getTableCommentsArray()' function + + + /** + * Set global array for store highlighted header fields + * + * @param array $analyzed_sql the analyzed query + * + * @return void + * + * @access private + * + * @see _getTableHeaders() + */ + private function _setHighlightedColumnGlobalField($analyzed_sql) + { + + $highlight_columns = array(); + if (isset($analyzed_sql) && isset($analyzed_sql[0]) + && isset($analyzed_sql[0]['where_clause_identifiers']) + ) { + + $wi = 0; + if (isset($analyzed_sql[0]['where_clause_identifiers']) + && is_array($analyzed_sql[0]['where_clause_identifiers']) + ) { + foreach ($analyzed_sql[0]['where_clause_identifiers'] + as $wci_nr => $wci + ) { + $highlight_columns[$wci] = 'true'; + } + } + } + + $this->__set('_highlight_columns', $highlight_columns); + + } // end of the '_setHighlightedColumnGlobalField()' function + + /** * Prepare data for column restoring and show/hide * @@ -1297,7 +1491,7 @@ class PMA_DisplayResults $data_html = ''; // generate the column order, if it is set - $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']); + $pmatable = new PMA_Table($this->__get('_table'), $this->__get('_db')); $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER); if ($col_order) { @@ -1313,10 +1507,10 @@ class PMA_DisplayResults } // generate table create time - if (! PMA_Table::isView($GLOBALS['table'], $GLOBALS['db'])) { + if (! PMA_Table::isView($this->__get('_db'), $this->__get('_table'))) { $data_html .= ''; } @@ -1349,10 +1543,10 @@ class PMA_DisplayResults $options_html .= '>'; $url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, - 'sql_query' => $this->_sql_query, - 'goto' => $this->_goto, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), + 'sql_query' => $this->__get('_sql_query'), + 'goto' => $this->__get('_goto'), 'display_options_form' => 1 ); @@ -1461,20 +1655,20 @@ class PMA_DisplayResults { $url_params_full_text = array( - 'db' => $this->_db, - 'table' => $this->_table, - 'sql_query' => $this->_sql_query, - 'goto' => $this->_goto, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), + 'sql_query' => $this->__get('_sql_query'), + 'goto' => $this->__get('_goto'), 'full_text_button' => 1 ); if ($_SESSION['tmp_user_values']['display_text'] == self::DISPLAY_FULL_TEXT) { // currently in fulltext mode so show the opposite link - $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png'; + $tmp_image_file = $this->__get('_pma_theme_image') . 's_partialtext.png'; $tmp_txt = __('Partial texts'); $url_params_full_text['display_text'] = self::DISPLAY_PARTIAL_TEXT; } else { - $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png'; + $tmp_image_file = $this->__get('_pma_theme_image') . 's_fulltext.png'; $tmp_txt = __('Full texts'); $url_params_full_text['display_text'] = self::DISPLAY_FULL_TEXT; } @@ -1516,7 +1710,9 @@ class PMA_DisplayResults } $form_html .= '>' . "\n" - . PMA_generate_common_hidden_inputs($this->_db, $this->_table, 1) + . PMA_generate_common_hidden_inputs( + $this->__get('_db'), $this->__get('_table'), 1 + ) . '' . "\n"; } @@ -1560,6 +1756,137 @@ class PMA_DisplayResults } // end of the '_getCommentForRow()' function + /** + * Prepare parameters and html for sorted table header fields + * + * @param array $fields_meta set of field properties + * @param string $sort_expression sort expression + * @param string $sort_expression_nodirection sort expression without direction + * @param integer $column_index the index of the column + * @param string $unsorted_sql_query the unsorted sql query + * @param integer $session_max_rows maximum rows resulted by sql + * @param string $direction the display direction + * @param string $comments comment for row + * @param string $sort_direction sort direction + * @param boolean $directionCondition display direction horizontal + * or horizontalflipped + * @param boolean $col_visib column is visible(false) + * array column isn't visible(string array) + * @param string $col_visib_j element of $col_visib array + * @param boolean $condition_field whether the column is a part of + * the where clause + * + * @return array 2 element array - $order_link, $sorted_header_html + * + * @access private + * + * @see _getTableHeaders() + */ + private function _getOrderLinkAndSortedHeaderHtml( + $fields_meta, $sort_expression, $sort_expression_nodirection, + $column_index, $unsorted_sql_query, $session_max_rows, $direction, + $comments, $sort_direction, $directionCondition, $col_visib, + $col_visib_j, $condition_field + ) { + + $sorted_header_html = ''; + + // Checks if the table name is required; it's the case + // for a query with a "JOIN" statement and if the column + // isn't aliased, or in queries like + // SELECT `1`.`master_field` , `2`.`master_field` + // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2` + + $sort_tbl = (isset($fields_meta->table) + && strlen($fields_meta->table)) + ? $this->getCommonFunctions()->backquote( + $fields_meta->table + ) . '.' + : ''; + + // Checks if the current column is used to sort the + // results + // the orgname member does not exist for all MySQL versions + // but if found, it's the one on which to sort + $name_to_use_in_sort = $fields_meta->name; + $is_orgname = false; + if (isset($fields_meta->orgname) + && strlen($fields_meta->orgname) + ) { + $name_to_use_in_sort = $fields_meta->orgname; + $is_orgname = true; + } + + // $name_to_use_in_sort might contain a space due to + // formatting of function expressions like "COUNT(name )" + // so we remove the space in this situation + $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort); + + $is_in_sort = $this->_isInSorted( + $sort_expression, $sort_expression_nodirection, + $sort_tbl, $name_to_use_in_sort + ); + + // Check the field name for a bracket. + // If it contains one, it's probably a function column + // like 'COUNT(`field`)' + // It still might be a column name of a view. See bug #3383711 + // Check is_orgname. + if ((strpos($name_to_use_in_sort, '(') !== false) && ! $is_orgname) { + $sort_order = "\n" . 'ORDER BY ' . $name_to_use_in_sort . ' '; + } else { + $sort_order = "\n" . 'ORDER BY ' . $sort_tbl + . $this->getCommonFunctions()->backquote( + $name_to_use_in_sort + ) . ' '; + } + unset($name_to_use_in_sort); + unset($is_orgname); + + // Do define the sorting URL + + list($sort_order, $order_img) = $this->_getSortingUrlParams( + $is_in_sort, $sort_direction, $fields_meta, + $sort_order, $column_index + ); + + if (preg_match( + '@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|' + . 'LOCK IN SHARE MODE))@is', + $unsorted_sql_query, $regs3 + )) { + $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2]; + } else { + $sorted_sql_query = $unsorted_sql_query . $sort_order; + } + + $_url_params = array( + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), + 'sql_query' => $sorted_sql_query, + 'session_max_rows' => $session_max_rows + ); + $order_url = 'sql.php' . PMA_generate_common_url($_url_params); + + // Displays the sorting URL + // enable sort order swapping for image + $order_link = $this->_getSortOrderLink( + $order_img, $column_index, $direction, + $fields_meta, $order_url + ); + + if ($directionCondition) { + $sorted_header_html .= $this->_getDraggableClassForSortableColumns( + $col_visib, $col_visib_j, $condition_field, $direction, + $fields_meta, $order_link, $comments + ); + } + + return array($order_link, $sorted_header_html); + + } // end of the '_getOrderLinkAndSortedHeaderHtml()' function + + /** * Check whether the column is sorted * @@ -1592,8 +1919,8 @@ class PMA_DisplayResults // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p // (and try clicking on each column's header twice) if (! empty($sort_tbl) - && (strpos($sort_expression_nodirection, $sort_tbl) === false) - && (strpos($sort_expression_nodirection, '(') === false) + && strpos($sort_expression_nodirection, $sort_tbl) === false + && strpos($sort_expression_nodirection, '(') === false ) { $new_sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection; @@ -1604,8 +1931,8 @@ class PMA_DisplayResults $is_in_sort = false; $sort_name = str_replace('`', '', $sort_tbl) . $name_to_use_in_sort; - if (($sort_name == str_replace('`', '', $new_sort_expression_nodirection)) - || ($sort_name == str_replace('`', '', $sort_expression_nodirection)) + if ($sort_name == str_replace('`', '', $new_sort_expression_nodirection) + || $sort_name == str_replace('`', '', $sort_expression_nodirection) ) { $is_in_sort = true; } @@ -1871,6 +2198,86 @@ class PMA_DisplayResults } // end of the '_getDraggableClassForNonSortableColumns()' function + /** + * Prepare column to show at right side - check boxes or empty column + * + * @param array &$is_display which elements to display + * @param boolean $directionCondition display direction horizontal + * or horizontalflipped + * @param string $full_or_partial_text_link full/partial link or text button + * @param string $colspan column span of table header + * @param string $rowspan row span of table header + * + * @return string html content + * + * @access private + * + * @see _getTableHeaders() + */ + private function _getColumnAtRightSide( + &$is_display, $directionCondition, $full_or_partial_text_link, + $colspan, $rowspan + ) { + + $right_column_html = ''; + $vertical_display = $this->__get('_vertical_display'); + + // Displays the needed checkboxes at the right + // column of the result table header if possible and required... + if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) + || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) + && (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + || ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) + && ($is_display['text_btn'] == '1') + ) { + + $vertical_display['emptyafter'] + = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 1; + + if ($directionCondition) { + $right_column_html .= "\n" + . ''; + + // end horizontal/horizontalflipped mode + } else { + $vertical_display['textbtn'] = ' ' . "\n"; + } // end vertical mode + } elseif ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) + || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) + && (($is_display['edit_lnk'] == self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] == self::NO_EDIT_OR_DELETE)) + && (! isset($GLOBALS['is_header_sent']) || ! $GLOBALS['is_header_sent']) + ) { + // ... elseif no button, displays empty columns if required + // (unless coming from Browse mode print view) + + $vertical_display['emptyafter'] + = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) + && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 1; + + if ($directionCondition) { + $right_column_html .= "\n" + . ''; + + // end horizontal/horizontalflipped mode + } else { + $vertical_display['textbtn'] = ' ' . "\n"; + } // end vertical mode + } + + $this->__set('_vertical_display', $vertical_display); + + return $right_column_html; + + } // end of the '_getColumnAtRightSide()' function + + /** * Prepares the display for a value * @@ -2027,21 +2434,24 @@ class PMA_DisplayResults // guess, it should depend on remaining URL length $url_sql_query = $this->_getUrlSqlQuery($analyzed_sql); + $vertical_display = $this->__get('_vertical_display'); + if (! is_array($map)) { $map = array(); } $row_no = 0; - $GLOBALS['vertical_display']['edit'] = array(); - $GLOBALS['vertical_display']['copy'] = array(); - $GLOBALS['vertical_display']['delete'] = array(); - $GLOBALS['vertical_display']['data'] = array(); - $GLOBALS['vertical_display']['row_delete'] = array(); + $vertical_display['edit'] = array(); + $vertical_display['copy'] = array(); + $vertical_display['delete'] = array(); + $vertical_display['data'] = array(); + $vertical_display['row_delete'] = array(); + $this->__set('_vertical_display', $vertical_display); // name of the class added to all grid editable elements $grid_edit_class = 'grid_edit'; // prepare to get the column order, if available - list($col_order, $col_visib) = $this->_getColumnParams(); + list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); // Correction University of Virginia 19991216 in the while below // Previous code assumed that all tables have keys, specifically that @@ -2066,7 +2476,7 @@ class PMA_DisplayResults // "vertical display" mode stuff $table_body_html .= $this->_getVerticalDisplaySupportSegments( - $GLOBALS['vertical_display'], $row_no, $directionCondition + $vertical_display, $row_no, $directionCondition ); $alternating_color_class = ($odd_row ? 'odd' : 'even'); @@ -2087,10 +2497,17 @@ class PMA_DisplayResults */ list($where_clause, $clause_is_unique, $condition_array) = $this->getCommonFunctions()->getUniqueCondition( - $dt_result, $GLOBALS['fields_cnt'], $GLOBALS['fields_meta'], $row + $dt_result, + $this->__get('_fields_cnt'), + $this->__get('_fields_meta'), + $row ); $where_clause_html = urlencode($where_clause); + // In print view these variable needs toinitialized + $del_url = $del_query = $del_str = $edit_anchor_class + = $edit_str = $js_conf = $copy_url = $copy_str = null; + // 1.2 Defines the URLs for the modify/delete link(s) if (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) @@ -2158,174 +2575,11 @@ class PMA_DisplayResults } // end if (1) // 2. Displays the rows' values - - for ($j = 0; $j < $GLOBALS['fields_cnt']; ++$j) { - - // assign $i with appropriate column order - $i = $col_order ? $col_order[$j] : $j; - - $meta = $GLOBALS['fields_meta'][$i]; - $not_null_class = $meta->not_null ? 'not_null' : ''; - $relation_class = isset($map[$meta->name]) ? 'relation' : ''; - $hide_class = ($col_visib && !$col_visib[$j] - // hide per ' . "\n"; @@ -3255,53 +3781,51 @@ class PMA_DisplayResults $vertical_table_html .= '' . "\n"; } - $vertical_table_html .= $GLOBALS['vertical_display']['textbtn'] - . $this->_getCheckBoxesForMultipleRowOperations( - $GLOBALS['vertical_display'], '_left' - ) - . '' . "\n"; + $vertical_table_html .= $vertical_display['textbtn'] + . $this->_getCheckBoxesForMultipleRowOperations('_left') + . '' . "\n"; } // end if // Prepares "edit" link at top if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($GLOBALS['vertical_display']['edit']) - && ((count($GLOBALS['vertical_display']['edit']) > 0) - || !empty($GLOBALS['vertical_display']['textbtn'])) + && is_array($vertical_display['edit']) + && ((count($vertical_display['edit']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'edit' + 'edit' ); } // end if // Prepares "copy" link at top if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($GLOBALS['vertical_display']['copy']) - && ((count($GLOBALS['vertical_display']['copy']) > 0) - || !empty($GLOBALS['vertical_display']['textbtn'])) + && is_array($vertical_display['copy']) + && ((count($vertical_display['copy']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'copy' + 'copy' ); } // end if // Prepares "delete" link at top if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($GLOBALS['vertical_display']['delete']) - && ((count($GLOBALS['vertical_display']['delete']) > 0) - || !empty($GLOBALS['vertical_display']['textbtn'])) + && is_array($vertical_display['delete']) + && ((count($vertical_display['delete']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'delete' + 'delete' ); } // end if - list($col_order, $col_visib) = $this->_getColumnParams(); + list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); // Prepares data - foreach ($GLOBALS['vertical_display']['desc'] AS $j => $val) { + foreach ($vertical_display['desc'] AS $j => $val) { // assign appropriate key with current column order $key = $col_order ? $col_order[$j] : $j; @@ -3312,11 +3836,11 @@ class PMA_DisplayResults . $val; $cell_displayed = 0; - foreach ($GLOBALS['vertical_display']['rowdata'][$key] as $subval) { + foreach ($vertical_display['rowdata'][$key] as $subval) { if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) - && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells']) + && ! ($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells']) ) { $vertical_table_html .= $val; } @@ -3332,52 +3856,50 @@ class PMA_DisplayResults // Prepares "multi row delete" link at bottom if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($GLOBALS['vertical_display']['row_delete']) - && ((count($GLOBALS['vertical_display']['row_delete']) > 0) - || !empty($GLOBALS['vertical_display']['textbtn'])) + && is_array($vertical_display['row_delete']) + && ((count($vertical_display['row_delete']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= '' . "\n" - . $GLOBALS['vertical_display']['textbtn'] - . $this->_getCheckBoxesForMultipleRowOperations( - $GLOBALS['vertical_display'], '_right' - ) + . $vertical_display['textbtn'] + . $this->_getCheckBoxesForMultipleRowOperations('_right') . '' . "\n"; } // end if // Prepares "edit" link at bottom if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($GLOBALS['vertical_display']['edit']) - && ((count($GLOBALS['vertical_display']['edit']) > 0) - || !empty($GLOBALS['vertical_display']['textbtn'])) + && is_array($vertical_display['edit']) + && ((count($vertical_display['edit']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'edit' + 'edit' ); } // end if // Prepares "copy" link at bottom if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($GLOBALS['vertical_display']['copy']) - && ((count($GLOBALS['vertical_display']['copy']) > 0) - || !empty($GLOBALS['vertical_display']['textbtn'])) + && is_array($vertical_display['copy']) + && ((count($vertical_display['copy']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'copy' + 'copy' ); } // end if // Prepares "delete" link at bottom if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($GLOBALS['vertical_display']['delete']) - && ((count($GLOBALS['vertical_display']['delete']) > 0) - || !empty($GLOBALS['vertical_display']['textbtn'])) + && is_array($vertical_display['delete']) + && ((count($vertical_display['delete']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'delete' + 'delete' ); } @@ -3389,20 +3911,19 @@ class PMA_DisplayResults /** * Prepare edit, copy and delete links for verticle table * - * @param array $vertical_display the information to display - * @param string $operation edit/copy/delete + * @param string $operation edit/copy/delete * - * @return string $links_html html content + * @return string $links_html html content * * @access private * * @see _getVerticalTable() */ - private function _getOperationLinksForVerticleTable( - $vertical_display, $operation - ) { + private function _getOperationLinksForVerticleTable($operation) + { $link_html = '' . "\n"; + $vertical_display = $this->__get('_vertical_display'); if (! is_array($vertical_display['row_delete'])) { @@ -3431,20 +3952,20 @@ class PMA_DisplayResults /** * Get checkboxes for multiple row data operations * - * @param array $vertical_display the information to display - * @param string $dir _left / _right + * @param string $dir _left / _right * - * @return $checkBoxes_html html content + * @return $checkBoxes_html html content * * @access private * * @see _getVerticalTable() */ - private function _getCheckBoxesForMultipleRowOperations($vertical_display, $dir) + private function _getCheckBoxesForMultipleRowOperations($dir) { $checkBoxes_html = ''; $cell_displayed = 0; + $vertical_display = $this->__get('_vertical_display'); foreach ($vertical_display['row_delete'] as $val) { @@ -3489,10 +4010,10 @@ class PMA_DisplayResults public function setConfigParamsForDisplayTable() { - $sql_md5 = md5($GLOBALS['sql_query']); + $sql_md5 = md5($this->__get('_sql_query')); $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] - = $GLOBALS['sql_query']; + = $this->__get('_sql_query'); $valid_disp_dir = PMA_isValid( $_REQUEST['disp_direction'], @@ -3729,6 +4250,11 @@ class PMA_DisplayResults { $table_html = ''; + // Following variable are needed for use in isset/empty or + // use with array indexes/safe use in foreach + $fields_meta = $this->__get('_fields_meta'); + $showtable = $this->__get('_showtable'); + $printview = $this->__get('_printview'); // why was this called here? (already called from sql.php) //$this->setConfigParamsForDisplayTable(); @@ -3737,8 +4263,8 @@ class PMA_DisplayResults * @todo move this to a central place * @todo for other future table types */ - $is_innodb = (isset($GLOBALS['showtable']['Type']) - && $GLOBALS['showtable']['Type'] == self::TABLE_TYPE_INNO_DB); + $is_innodb = (isset($showtable['Type']) + && $showtable['Type'] == self::TABLE_TYPE_INNO_DB); if ($is_innodb && ! isset($analyzed_sql[0]['queryflags']['union']) @@ -3750,10 +4276,7 @@ class PMA_DisplayResults $pre_count = '~'; $after_count = $this->getCommonFunctions()->showHint( PMA_sanitize( - __( - 'May be approximate. See [a@./Documentation.html' - . '#faq3_11@Documentation]FAQ 3.11[/a]' - ) + __('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]') ) ); } else { @@ -3783,8 +4306,7 @@ class PMA_DisplayResults // 1.4 Prepares display of first and last value of the sorted column $sorted_column_message = $this->_getSortedColumnMessage( - $dt_result, $GLOBALS['fields_meta'], $GLOBALS['num_rows'], - $sort_expression_nodirection + $dt_result, $sort_expression_nodirection ); @@ -3794,25 +4316,24 @@ class PMA_DisplayResults if (($is_display['nav_bar'] == '1') && isset($pos_next)) { $message = $this->_setMessageInformation( - $sorted_column_message, - $analyzed_sql[0]['limit_clause'], $GLOBALS['unlim_num_rows'], + $sorted_column_message, $analyzed_sql[0]['limit_clause'], $total, $pos_next, $pre_count, $after_count ); $table_html .= $this->getCommonFunctions()->getMessage( - $message, $this->_sql_query, 'success' + $message, $this->__get('_sql_query'), 'success' ); - } elseif (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) { + } elseif (! isset($printview) || ($printview != '1')) { $table_html .= $this->getCommonFunctions()->getMessage( __('Your SQL query has been executed successfully'), - $this->_sql_query, 'success' + $this->__get('_sql_query'), 'success' ); } // 2.3 Prepare the navigation bars - if (! strlen($this->_table)) { + if (! strlen($this->__get('_table'))) { if (isset($analyzed_sql[0]['query_type']) && ($analyzed_sql[0]['query_type'] == self::QUERY_TYPE_SELECT) @@ -3820,9 +4341,9 @@ class PMA_DisplayResults // table does not always contain a real table name, // for example in MySQL 5.0.x, the query SHOW STATUS // returns STATUS as a table name - $this->_table = $GLOBALS['fields_meta'][0]->table; + $this->__set('_table', $fields_meta[0]->table); } else { - $this->_table = ''; + $this->__set('_table', ''); } } @@ -3831,12 +4352,12 @@ class PMA_DisplayResults && empty($analyzed_sql[0]['limit_clause']) ) { - $table_html .= $this->_getTableNavigation( - $pos_next, $pos_prev, 'top_direction_dropdown' - ) - . "\n"; + $table_html .= $this->_getPlacedTableNavigatoins( + $pos_next, $pos_prev, self::PLACE_TOP_DIRECTION_DROPDOWN, + "\n", $is_innodb + ); - } elseif (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) { + } elseif (! isset($printview) || ($printview != '1')) { $table_html .= "\n" . '

' . "\n"; } @@ -3860,45 +4381,19 @@ class PMA_DisplayResults } - $tabs = '(\'' . join('\',\'', $target) . '\')'; + $tabs = '(\'' . join('\',\'', $target) . '\')'; - if (! strlen($this->_table)) { + if (! strlen($this->__get('_table'))) { $exist_rel = false; } else { - - // To be able to later display a link to the related table, - // we verify both types of relations: either those that are - // native foreign keys or those defined in the phpMyAdmin - // configuration storage. If no PMA storage, we won't be able - // to use the "column to display" notion (for example show - // the name related to a numeric id). - $exist_rel = PMA_getForeigners( - $this->_db, $this->_table, '', self::POSITION_BOTH - ); - - if ($exist_rel) { - - foreach ($exist_rel as $master_field => $rel) { - - $display_field = PMA_getDisplayField( - $rel['foreign_db'], $rel['foreign_table'] - ); - - $map[$master_field] = array( - $rel['foreign_table'], - $rel['foreign_field'], - $display_field, - $rel['foreign_db'] - ); - } // end while - } // end if + // This method set the values for $map array + $this->_setParamForLinkForiegnKeyRelatedTables($map); } // end if // end 2b // 3. ----- Prepare the results table ----- $table_html .= $this->_getTableHeaders( - $is_display, $GLOBALS['fields_meta'], - $GLOBALS['fields_cnt'], $analyzed_sql, $sort_expression, + $is_display, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction ) . '' . "\n"; @@ -3910,10 +4405,11 @@ class PMA_DisplayResults // vertical output case if ($_SESSION['tmp_user_values']['disp_direction'] == self::DISP_DIR_VERTICAL) { - $table_html .= $this->_getVerticalTable(); + $table_html .= $this->_getVerticalTable($analyzed_sql); } // end if - unset($GLOBALS['vertical_display']); + $this->__set('_vertical_display', null); + $table_html .= '' . "\n" . ''; @@ -3924,29 +4420,26 @@ class PMA_DisplayResults ) { $table_html .= $this->_getMultiRowOperationLinks( - $dt_result, $GLOBALS['fields_cnt'], $GLOBALS['fields_meta'], - $GLOBALS['num_rows'], $analyzed_sql, $is_display['del_lnk'] + $dt_result, $analyzed_sql, $is_display['del_lnk'] ); } // 5. ----- Get the navigation bar at the bottom if required ----- - if (($is_display['nav_bar'] == '1') && empty($analyzed_sql[0]['limit_clause']) ) { - - $table_html .= '
' . "\n"; - $table_html .= $this->_getTableNavigation( - $pos_next, $pos_prev, 'bottom_direction_dropdown' + $table_html .= $this->_getPlacedTableNavigatoins( + $pos_next, $pos_prev, self::PLACE_BOTTOM_DIRECTION_DROPDOWN, + '
' . "\n", $is_innodb ); - - } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { + } elseif (! isset($printview) || ($printview != '1')) { $table_html .= "\n" . '

' . "\n"; } + // 6. ----- Prepare "Query results operations" - if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { + if (! isset($printview) || ($printview != '1')) { $table_html .= $this->_getResultsOperations( $the_disp_mode, $analyzed_sql ); @@ -4041,9 +4534,6 @@ class PMA_DisplayResults * @param integer &$dt_result the link id associated to the * query which results have to * be displayed - * @param array $fields_meta the list of fields properties - * @param integer $num_rows the total number of rows returned - * by the SQL query * @param string $sort_expression_nodirection sort expression without direction * * @return string html content @@ -4054,13 +4544,15 @@ class PMA_DisplayResults * @see getTable() */ private function _getSortedColumnMessage( - &$dt_result, $fields_meta, $num_rows, $sort_expression_nodirection + &$dt_result, $sort_expression_nodirection ) { + $fields_meta = $this->__get('_fields_meta'); // To use array indexes + if (! empty($sort_expression_nodirection)) { if (strpos($sort_expression_nodirection, '.') === false) { - $sort_table = $this->_table; + $sort_table = $this->__get('_table'); $sort_column = $sort_expression_nodirection; } else { list($sort_table, $sort_column) @@ -4113,7 +4605,7 @@ class PMA_DisplayResults ); // fetch last row of the result set - PMA_DBI_data_seek($dt_result, $num_rows - 1); + PMA_DBI_data_seek($dt_result, $this->__get('_num_rows') - 1); $row = PMA_DBI_fetch_row($dt_result); // check for non printable sorted row data @@ -4156,9 +4648,6 @@ class PMA_DisplayResults * * @param string $sorted_column_message the message for sorted column * @param string $limit_clause the limit clause of analyzed query - * @param integer $unlim_num_rows the total number of rows returned by - * the SQL query without any appended - * "LIMIT" clause programmatically * @param integer $total the total number of rows returned by * the SQL query without any * programmatically appended LIMIT clause @@ -4173,10 +4662,12 @@ class PMA_DisplayResults * @see getTable() */ private function _setMessageInformation( - $sorted_column_message, $limit_clause, $unlim_num_rows, - $total, $pos_next, $pre_count, $after_count + $sorted_column_message, $limit_clause, $total, + $pos_next, $pre_count, $after_count ) { + $unlim_num_rows = $this->__get('_unlim_num_rows'); // To use in isset() + if (isset($unlim_num_rows) && ($unlim_num_rows != $total)) { $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query'); } else { @@ -4209,7 +4700,7 @@ class PMA_DisplayResults } - if (PMA_Table::isView($this->_db, $this->_table) + if (PMA_Table::isView($this->__get('_db'), $this->__get('_table')) && ($total == $GLOBALS['cfg']['MaxExactCountViews']) ) { @@ -4256,7 +4747,7 @@ class PMA_DisplayResults } $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec') . ')'); - $messagge_qt->addParam($GLOBALS['querytime']); + $messagge_qt->addParam($this->__get('_querytime')); $message->addMessage($messagge_qt, ''); if (! is_null($sorted_column_message)) { @@ -4268,16 +4759,55 @@ class PMA_DisplayResults } // end of the '_setMessageInformation()' function + /** + * Set the value of $map array for linking foreign key related tables + * + * @param array &$map the list of relations + * + * @return void + * + * @access private + * + * @see getTable() + */ + private function _setParamForLinkForiegnKeyRelatedTables(&$map) + { + + // To be able to later display a link to the related table, + // we verify both types of relations: either those that are + // native foreign keys or those defined in the phpMyAdmin + // configuration storage. If no PMA storage, we won't be able + // to use the "column to display" notion (for example show + // the name related to a numeric id). + $exist_rel = PMA_getForeigners( + $this->__get('_db'), $this->__get('_table'), '', self::POSITION_BOTH + ); + + if ($exist_rel) { + + foreach ($exist_rel as $master_field => $rel) { + + $display_field = PMA_getDisplayField( + $rel['foreign_db'], $rel['foreign_table'] + ); + + $map[$master_field] = array( + $rel['foreign_table'], + $rel['foreign_field'], + $display_field, + $rel['foreign_db'] + ); + } // end while + } // end if + + } // end of the '_setParamForLinkForiegnKeyRelatedTables()' function + + /** * Prepare multi field edit/delete links * * @param integer &$dt_result the link id associated to the query * which results have to be displayed - * @param integer $fields_cnt the total number of fields returned by - * the SQL query - * @param array $fields_meta the list of fields properties - * @param integer $num_rows the total number of rows returned - * by the SQL query * @param array $analyzed_sql the analyzed query * @param string $del_link the display element - 'del_link' * @@ -4288,25 +4818,25 @@ class PMA_DisplayResults * @see getTable() */ private function _getMultiRowOperationLinks( - &$dt_result, $fields_cnt, $fields_meta, $num_rows, $analyzed_sql, - $del_link + &$dt_result, $analyzed_sql, $del_link ) { $links_html = ''; + $url_query = $this->__get('_url_query'); $delete_text = ($del_link == self::DELETE_ROW) ? __('Delete') : __('Kill'); $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, - 'sql_query' => $this->_sql_query, - 'goto' => $this->_goto, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), + 'sql_query' => $this->__get('_sql_query'), + 'goto' => $this->__get('_goto'), ); if ($_SESSION['tmp_user_values']['disp_direction'] != self::DISP_DIR_VERTICAL) { $links_html .= '' . __('With selected:') . ''; } @@ -4325,7 +4855,9 @@ class PMA_DisplayResults $delete_text, 'b_drop.png', 'delete' ); - if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == self::QUERY_TYPE_SELECT) { + if (isset($analyzed_sql[0]) + && $analyzed_sql[0]['querytype'] == self::QUERY_TYPE_SELECT + ) { $links_html .= $this->getCommonFunctions()->getButtonOrImage( 'submit_mult', 'mult_submit', 'submit_mult_export', __('Export'), 'b_tblexport.png', 'export' @@ -4335,22 +4867,25 @@ class PMA_DisplayResults $links_html .= "\n"; $links_html .= '' . "\n"; + .' value="' . htmlspecialchars($this->__get('_sql_query')) . '" />' . "\n"; - if (! empty($GLOBALS['url_query'])) { + if (! empty($url_query)) { $links_html .= '' . "\n"; + .' value="' . $url_query . '" />' . "\n"; } // fetch last row of the result set - PMA_DBI_data_seek($dt_result, $num_rows - 1); + PMA_DBI_data_seek($dt_result, $this->__get('_num_rows') - 1); $row = PMA_DBI_fetch_row($dt_result); // $clause_is_unique is needed by getTable() to generate the proper param // in the multi-edit and multi-delete form list($where_clause, $clause_is_unique, $condition_array) = $this->getCommonFunctions()->getUniqueCondition( - $dt_result, $fields_cnt, $fields_meta, $row + $dt_result, + $this->__get('_fields_cnt'), + $this->__get('_fields_meta'), + $row ); // reset to first row for the loop in _getTableBody() @@ -4366,6 +4901,44 @@ class PMA_DisplayResults } // end of the '_getMultiRowOperationLinks()' function + /** + * Prepare table navigation bar at the top or bottom + * + * @param integer $pos_next the offset for the "next" page + * @param integer $pos_prev the offset for the "previous" page + * @param string $place the place to show navigation + * @param string $empty_line empty line depend on the $place + * @param boolean $is_innodb whether its InnoDB or not + * + * @return string html content of navigation bar + * + * @access private + * + * @see _getTable() + */ + private function _getPlacedTableNavigatoins( + $pos_next, $pos_prev, $place, $empty_line, $is_innodb + ) { + + $navigation_html = ''; + + if ($place == self::PLACE_BOTTOM_DIRECTION_DROPDOWN) { + $navigation_html .= '
' . "\n"; + } + + $navigation_html .= $this->_getTableNavigation( + $pos_next, $pos_prev, 'top_direction_dropdown', $is_innodb + ); + + if ($place == self::PLACE_TOP_DIRECTION_DROPDOWN) { + $navigation_html .= "\n"; + } + + return $navigation_html; + + } // end of the '_getPlacedTableNavigatoins()' function + + /** * Get operations that are available on results. * @@ -4382,6 +4955,7 @@ class PMA_DisplayResults { $results_operations_html = ''; + $fields_meta = $this->__get('_fields_meta'); // To safe use in foreach $header_shown = false; $header = '
' . __('Query results operations') . ''; @@ -4396,10 +4970,10 @@ class PMA_DisplayResults } $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), 'printview' => '1', - 'sql_query' => $this->_sql_query, + 'sql_query' => $this->__get('_sql_query'), ); $url_query = PMA_generate_common_url($_url_params); @@ -4409,7 +4983,10 @@ class PMA_DisplayResults $this->getCommonFunctions()->getIcon( 'b_print.png', __('Print view'), true ), - '', true, true, 'print_view' + '', + true, + true, + 'print_view' ) . "\n"; @@ -4424,7 +5001,10 @@ class PMA_DisplayResults 'b_print.png', __('Print view (with full texts)'), true ), - '', true, true, 'print_view' + '', + true, + true, + 'print_view' ) . "\n"; unset($_url_params['display_text']); @@ -4451,12 +5031,12 @@ class PMA_DisplayResults $_url_params['single_table'] = 'true'; } - if (!$header_shown) { + if (! $header_shown) { $results_operations_html .= $header; $header_shown = true; } - $_url_params['unlim_num_rows'] = $GLOBALS['unlim_num_rows']; + $_url_params['unlim_num_rows'] = $this->__get('_unlim_num_rows'); /** * At this point we don't know the table name; this can happen @@ -4466,7 +5046,7 @@ class PMA_DisplayResults * first table of this database, so that tbl_export.php and * the script it calls do not fail */ - if (empty($_url_params['table']) && !empty($_url_params['db'])) { + if (empty($_url_params['table']) && ! empty($_url_params['db'])) { $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES"); /* No result (probably no database selected) */ if ($_url_params['table'] === false) { @@ -4479,7 +5059,10 @@ class PMA_DisplayResults $this->getCommonFunctions()->getIcon( 'b_tblexport.png', __('Export'), true ), - '', true, true, '' + '', + true, + true, + '' ) . "\n"; @@ -4489,14 +5072,17 @@ class PMA_DisplayResults $this->getCommonFunctions()->getIcon( 'b_chart.png', __('Display chart'), true ), - '', true, true, '' + '', + true, + true, + '' ) . "\n"; // prepare GIS chart $geometry_found = false; // If atleast one geometry field is found - foreach ($GLOBALS['fields_meta'] as $meta) { + foreach ($fields_meta as $meta) { if ($meta->type == self::GEOMETRY_FIELD) { $geometry_found = true; break; @@ -4511,7 +5097,10 @@ class PMA_DisplayResults $this->getCommonFunctions()->getIcon( 'b_globe.gif', __('Visualize GIS data'), true ), - '', true, true, '' + '', + true, + true, + '' ) . "\n"; } @@ -4574,7 +5163,8 @@ class PMA_DisplayResults * * @access private * - * @see _getDataCellForBlobColumns(), _getDataCellForGeometryColumns(), + * @see _getDataCellForBlobColumns(), + * _getDataCellForGeometryColumns(), * _getDataCellForNonNumericAndNonBlobColumns(), * _getSortedColumnMessage() */ @@ -4582,7 +5172,7 @@ class PMA_DisplayResults $category, $content, $transformation_plugin, $transform_options, $default_function, $meta, $url_params = array() ) { - + $result = '[' . $category; if (is_null($content)) { @@ -4678,6 +5268,7 @@ class PMA_DisplayResults $transform_options, $is_field_truncated ) { + $printview = $this->__get('_printview'); $result = ' $this->_db, + 'db' => $this->__get('_db'), 'table' => $meta->orgtable, 'pos' => '0', 'sql_query' => 'SELECT * FROM ' - . $this->getCommonFunctions()->backquote($this->_db) . '.' - . $this->getCommonFunctions()->backquote($meta->orgtable) + . $this->getCommonFunctions()->backquote($this->__get('_db')) + . '.' . $this->getCommonFunctions()->backquote($meta->orgtable) . ' WHERE ' . $this->getCommonFunctions()->backquote($meta->orgname) . $where_comparison, @@ -5110,7 +5701,7 @@ class PMA_DisplayResults return $ret; } // end of the '_getCheckboxAndLinks()' function - + /** * Replace some html-unfriendly stuff @@ -5118,9 +5709,9 @@ class PMA_DisplayResults * @param string $buffer String to process * * @return Escaped and cleaned up text suitable for html. - * + * * @access private - * + * * @see _getDataCellForBlobField(), _getRowData(), * _handleNonPrintableContents() */ @@ -5135,7 +5726,7 @@ class PMA_DisplayResults $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '
', $buffer); return $buffer; - } + } } ?> diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index dc264560d5..d6de4af77e 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -40,20 +40,6 @@ class PMA_Menu private $_common_functions; - - /** - * Set CommmonFunctions - * - * @param PMA_CommonFunctions $commonFunctions - * - * @return void - */ - public function setCommonFunctions(PMA_CommonFunctions $commonFunctions) - { - $this->_common_functions = $commonFunctions; - } - - /** * Get CommmonFunctions * diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 570a1519cb..891240a1bf 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -68,20 +68,6 @@ class PMA_Table private $_common_functions; - - /** - * Set CommmonFunctions - * - * @param PMA_CommonFunctions $commonFunctions - * - * @return void - */ - public function setCommonFunctions(PMA_CommonFunctions $commonFunctions) - { - $this->_common_functions = $commonFunctions; - } - - /** * Get CommmonFunctions * diff --git a/libraries/TableSearch.class.php b/libraries/TableSearch.class.php index 5c96dd6c0f..457e8d16af 100644 --- a/libraries/TableSearch.class.php +++ b/libraries/TableSearch.class.php @@ -83,20 +83,6 @@ class PMA_TableSearch private $_common_functions; - - /** - * Set CommmonFunctions - * - * @param PMA_CommonFunctions $commonFunctions - * - * @return void - */ - public function setCommonFunctions(PMA_CommonFunctions $commonFunctions) - { - $this->_common_functions = $commonFunctions; - } - - /** * Get CommmonFunctions * diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 2f17f20db0..0fbc152099 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -54,21 +54,20 @@ function PMA_getFormParametersForInsertForm($db, $table, $where_clauses, */ function PMA_getStuffForEditMode($where_clause, $table, $db) { - $found_unique_key = false; if (isset($where_clause)) { $where_clause_array = PMA_getWhereClauseArray($where_clause); list($whereClauses, $resultArray, $rowsArray, $found_unique_key) = PMA_analyzeWhereClauses( - $where_clause_array, $table, $db, $found_unique_key + $where_clause_array, $table, $db ); return array( false, $whereClauses, $resultArray, $rowsArray, $where_clause_array, $found_unique_key - ); + ); } else { list($results, $row) = PMA_loadFirstRowInEditMode($table, $db); - return array(true, null, $results, $row, null, $found_unique_key); + return array(true, null, $results, $row, null, false); } } @@ -93,34 +92,35 @@ function PMA_getWhereClauseArray($where_clause) /** * Analysing where clauses array * - * @param array $where_clause_array array of where clauses - * @param string $table name of the table - * @param string $db name of the database - * @param boolean $found_unique_key boolean variable for unique key + * @param array $where_clause_array array of where clauses + * @param string $table name of the table + * @param string $db name of the database * * @return array $where_clauses, $result, $rows */ function PMA_analyzeWhereClauses( - $where_clause_array, $table, $db, $found_unique_key + $where_clause_array, $table, $db ) { $rows = array(); $result = array(); $where_clauses = array(); + $found_unique_key = false; foreach ($where_clause_array as $key_id => $where_clause) { - $local_query = 'SELECT * FROM ' + $local_query = 'SELECT * FROM ' . PMA_CommonFunctions::getInstance()->backquote($db) . '.' . PMA_CommonFunctions::getInstance()->backquote($table) . ' WHERE ' . $where_clause . ';'; - $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); - $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); + $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); + $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); - $found_unique_key = PMA_showEmptyResultMessageOrSetUniqueCondition( - $rows, $key_id, - $where_clause_array, $local_query, - $result, $found_unique_key + $has_unique_condition = PMA_showEmptyResultMessageOrSetUniqueCondition( + $rows, $key_id, $where_clause_array, $local_query, $result ); + if ($has_unique_condition) { + $found_unique_key = true; + } } return array($where_clauses, $result, $rows, $found_unique_key); } @@ -128,18 +128,19 @@ function PMA_analyzeWhereClauses( /** * Show message for empty reult or set the unique_condition * - * @param array $rows MySQL returned rows - * @param string $key_id ID in current key - * @param array $where_clause_array array of where clauses - * @param string $local_query query performed - * @param array $result MySQL result handle - * @param boolean $found_unique_key boolean variable for unique key + * @param array $rows MySQL returned rows + * @param string $key_id ID in current key + * @param array $where_clause_array array of where clauses + * @param string $local_query query performed + * @param array $result MySQL result handle * - * @return boolean $found_unique_key + * @return boolean $has_unique_condition */ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, - $where_clause_array, $local_query, $result, $found_unique_key + $where_clause_array, $local_query, $result ) { + $has_unique_condition = false; + // No row returned if (! $rows[$key_id]) { unset($rows[$key_id], $where_clause_array[$key_id]); @@ -157,11 +158,11 @@ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, ); if (! empty($unique_condition)) { - $found_unique_key = true; + $has_unique_condition = true; } unset($unique_condition, $tmp_clause_is_unique); } - return $found_unique_key; + return $has_unique_condition; } /** @@ -481,14 +482,14 @@ function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, || strstr($column['True_Type'], 'set') || in_array($column['pma_type'], $no_support_types) ) { - $html_output .= ' --' . "\n"; + $html_output .= '--' . "\n"; } else { $html_output .= '' . "\n"; - $html_output .= ''; $html_output .= PMA_CommonFunctions::getInstance() ->getFunctionsForField($column, $insert_mode) . "\n"; @@ -737,14 +738,18 @@ function PMA_getForeignLink($column, $backup_field, $column_name_appendix, list($db, $table) = $paramTableDbArray; $html_output = ''; $html_output .= $backup_field . "\n"; + $html_output .= ''; - $html_output .= '' - . '
'; + + $html_output .= '' - . ''; + + $html_output .= ''; return $html_output; } @@ -820,18 +828,18 @@ function PMA_getTextarea($column, $backup_field, $column_name_appendix, } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea'] && strstr($column['pma_type'], 'longtext') ) { - $textAreaRows = $GLOBALS['cfg']['TextareaRows']*2; - $textareaCols = $GLOBALS['cfg']['TextareaCols']*2; + $textAreaRows = $GLOBALS['cfg']['TextareaRows'] * 2; + $textareaCols = $GLOBALS['cfg']['TextareaCols'] * 2; } $html_output = $backup_field . "\n" . ''; @@ -903,9 +911,9 @@ function PMA_getColumnEnumValues($column, $extracted_columnspec) // Removes automatic MySQL escape format $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val)); $column['values'][] = array( - 'plain' => $val, - 'html' => htmlspecialchars($val), - ); + 'plain' => $val, + 'html' => htmlspecialchars($val), + ); } return $column['values']; } @@ -929,14 +937,13 @@ function PMA_getDropDownDependingOnLength( $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values ) { $html_output = ''; + . ' class="textfield"' + . ' size="' . $select_size . '"' + . ' multiple="multiple"' + . ' ' . $unnullify_trigger + . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"' + . ' id="field_' . ($idindex) . '_3">'; foreach ($column_set_values as $column_set_value) { - $html_output .= ' '; $html_output .= 'Copy Copy\n array('\n array( - array('1\n'), - array('cv x c c\n') - ), - 'row_delete' => array(' '), - 'rowdata' => array( - array('1\n'), - array('edit not_null row_0 vpointer vmarker ">cv x c c\n') - ) - ), 'edit', ' -\nEdit Edit\n + ' ) ); @@ -500,58 +533,53 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase /** * Test for _getOperationLinksForVerticleTable - case 1 - * - * @param array $vertical_display the information to display + * * @param string $operation edit/copy/delete * @param string $output output of _getOperationLinksForVerticleTable - * + * * @dataProvider dataProviderForTestGetOperationLinksForVerticleTableCase1 */ public function testGetOperationLinksForVerticleTableCase1( - $vertical_display, $operation, $output + $operation, $output ) { + + $vertical_display = array( + 'row_delete' => array(), + 'textbtn' => '\n \n \n', + 'edit' => array(), + 'copy' => array( + '\nCopy Copy\n\nCopy Copy\n array( + '\n\n array(" \n\nid\n \n", " \n\nname\n \n"), - 'edit' => array('\nEdit Edit\n array('\nCopy Copy\n array('\n array( - array('1\n'), - array('cv x c c\n') - ), - 'row_delete' => '', - 'rowdata' => array( - array('1\n'), - array('edit not_null row_0 vpointer vmarker ">cv x c c\n') - ) - ), - 'edit', + array( + 'copy', ' - - - -\nEdit Edit\n +\nCopy Copy\n\nCopy Copy\n ' ) ); @@ -559,59 +587,54 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase /** * Test for _getOperationLinksForVerticleTable - case 2 - * - * @param array $vertical_display the information to display + * * @param string $operation edit/copy/delete * @param string $output output of _getOperationLinksForVerticleTable - * + * * @dataProvider dataProviderForTestGetOperationLinksForVerticleTableCase2 */ public function testGetOperationLinksForVerticleTableCase2( - $vertical_display, $operation, $output + $operation, $output ) { + + $vertical_display = array( + 'row_delete' => array(), + 'textbtn' => '\n \n \n', + 'edit' => array(), + 'copy' => array( + '\nCopy Copy\n\nCopy Copy\n array( + '\n\n array(" \n\nid\n \n", " \n\nname\n \n"), - 'edit' => '', - 'copy' => array('\nCopy Copy\n array('\n array( - array('1\n'), - array('cv x c c\n') - ), - 'row_delete' => '', - 'rowdata' => array( - array('1\n'), - array('edit not_null row_0 vpointer vmarker ">cv x c c\n') - ) - ), 'delete', ' - - - -\n +\n\n\n \n \n', + 'edit' => array(), + 'copy' => array( + '\nCopy Copy\n\nCopy Copy\n array( + '\n\n\n \n \n', - 'desc' => array( - '\n\nid\n \n', - '\n\ncars_id\n \n', - '\n\ncustomer_id Ascending Descending array( - '\nEdit Edit\n\nEdit Edit\n\nEdit Edit\n\nEdit Edit\n array( - '\nCopy Copy\n\nCopy Copy\n\nCopy Copy\n\nCopy Copy\n array( - '\n\n\n\n array( - array( - '2\n', - '6\n', - '1\n' - ), - array( - '3\n', - '7\n', - '2\n' - ), - array( - '1\n', - '9\n', - '3\n' - ), - array( - '4\n', - '8\n', - '5\n' - ) - ), - 'row_delete' => array( - ' ', - ' ', - ' ', - ' ' - ), - 'rowdata' => array( - array( - '2\n', - '3\n', - '1\n', - '4\n' - ), - array( - '6\n', - '7\n', - '9\n', - '8\n' - ), - array( - '1\n', - '2\n', - '3\n', - '5\n' - ) - ) - ), '_left', - ' ' + ' ' ) ); } - + /** * Test for _getCheckBoxesForMultipleRowOperations - * + * * @param array $vertical_display the information to display * @param string $dir _left / _right * @param string $output output of _getCheckBoxesForMultipleRowOperations - * + * * @dataProvider dataProviderForGetCheckBoxesForMultipleRowOperations */ public function testGetCheckBoxesForMultipleRowOperations( - $vertical_display, $dir, $output + $dir, $output ) { + + $vertical_display = array( + 'row_delete' => array( + ' ', + ' ' + ) + ); + + $this->object->__set('_vertical_display', $vertical_display); + $_SESSION['tmp_user_values']['repeat_cells'] = 0; $this->assertEquals( $this->_callPrivateFunction( '_getCheckBoxesForMultipleRowOperations', - array($vertical_display, $dir) + array($dir) ), $output ); } - + /** * Test for _getOffsets - case 1 */ @@ -762,7 +735,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase array(0, 0) ); } - + /** * Test for _getOffsets - case 2 */ @@ -775,10 +748,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase array(9, 0) ); } - + /** * Data provider for testGetSortParamsCase1 - * + * * @return array parameters and output */ public function dataProviderForGetSortParamsCase1() @@ -787,13 +760,13 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase array('', array('', '', '')) ); } - + /** * Test for _getSortParams - case 1 - * + * * @param string $order_by_clause the order by clause of the sql query * @param string $output output of _getSortParams - * + * * @dataProvider dataProviderForGetSortParamsCase1 */ public function testGetSortParamsCase1($order_by_clause, $output) @@ -805,10 +778,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $output ); } - + /** * Data provider for testGetSortParamsCase2 - * + * * @return array parameters and output */ public function dataProviderForGetSortParamsCase2() @@ -824,13 +797,13 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase ) ); } - + /** * Test for _getSortParams - case 2 - * + * * @param string $order_by_clause the order by clause of the sql query * @param string $output output of _getSortParams - * + * * @dataProvider dataProviderForGetSortParamsCase2 */ public function testGetSortParamsCase2($order_by_clause, $output) @@ -842,10 +815,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $output ); } - + /** * Data provider for testGetCheckboxForMultiRowSubmissions - * + * * @return array parameters and output */ public function dataProviderForGetCheckboxForMultiRowSubmissions() @@ -876,7 +849,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase /** * Test for _getCheckboxForMultiRowSubmissions - * + * * @param string $del_url delete url * @param array $is_display array with explicit indexes for all * the display elements @@ -888,7 +861,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase * @param string $class css classes for the td element * @param string $output output of _getSortParams * @param string $output output of _getCheckboxForMultiRowSubmissions - * + * * @dataProvider dataProviderForGetCheckboxForMultiRowSubmissions */ public function testGetCheckboxForMultiRowSubmissions( @@ -901,15 +874,15 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase array( $del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix, $class - ) + ) ), $output ); } - + /** * Data provider for testGetEditLink - * + * * @return array parametres and output */ public function dataProviderForGetEditLink() @@ -927,26 +900,26 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase ) ); } - + /** * Test for _getEditLink - * + * * @param string $edit_url edit url * @param string $class css classes for td element * @param string $edit_str text for the edit link * @param string $where_clause where clause * @param string $where_clause_html url encoded where clause * @param string $output output of _getEditLink - * + * * @dataProvider dataProviderForGetEditLink */ public function testGetEditLink( $edit_url, $class, $edit_str, $where_clause, $where_clause_html, $output ) { - + $GLOBALS['cfg']['PropertiesIconic'] = 'both'; $GLOBALS['cfg']['LinkLengthLimit'] = 1000; - + $this->assertEquals( $this->_callPrivateFunction( '_getEditLink', @@ -956,12 +929,12 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase ), $output ); - + } - + /** * Data provider for testGetCopyLink - * + * * @return array parameters and output */ public function dataProviderForGetCopyLink() @@ -979,26 +952,26 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase ) ); } - + /** * Test for _getCopyLink - * + * * @param string $copy_url copy url * @param string $copy_str text for the copy link * @param string $where_clause where clause * @param string $where_clause_html url encoded where clause * @param string $class css classes for the td element * @param string $output output of _getCopyLink - * + * * @dataProvider dataProviderForGetCopyLink */ public function testGetCopyLink( $copy_url, $copy_str, $where_clause, $where_clause_html, $class, $output ) { - + $GLOBALS['cfg']['PropertiesIconic'] = 'both'; $GLOBALS['cfg']['LinkLengthLimit'] = 1000; - + $this->assertEquals( $this->_callPrivateFunction( '_getCopyLink', @@ -1009,10 +982,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $output ); } - + /** * Data provider for testGetDeleteLink - * + * * @return array parameters and output */ public function dataProviderForGetDeleteLink() @@ -1029,25 +1002,25 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase ) ); } - + /** * Test for _getDeleteLink - * + * * @param string $del_url delete url * @param string $del_str text for the delete link * @param string $js_conf text for the JS confirmation * @param string $class css classes for the td element * @param string $output output of _getDeleteLink - * + * * @dataProvider dataProviderForGetDeleteLink */ public function testGetDeleteLink( $del_url, $del_str, $js_conf, $class, $output ) { - + $GLOBALS['cfg']['PropertiesIconic'] = 'both'; $GLOBALS['cfg']['LinkLengthLimit'] = 1000; - + $this->assertEquals( $this->_callPrivateFunction( '_getDeleteLink', @@ -1058,10 +1031,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $output ); } - + /** * Data provider for testGetCheckboxAndLinksCase1 - * + * * @return array parameters and output */ public function dataProviderForGetCheckboxAndLinksCase1() @@ -1105,10 +1078,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase ) ); } - + /** * Test for _getCheckboxAndLinks - case 1 - * + * * @param string $position the position of the checkbox and links * @param string $del_url delete url * @param array $is_display array with explicit indexes for all the @@ -1127,7 +1100,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase * @param string $del_str text for the delete link * @param string $js_conf text for the JS confirmation * @param string $output output of _getCheckboxAndLinks - * + * * @dataProvider dataProviderForGetCheckboxAndLinksCase1 */ public function testGetCheckboxAndLinksCase1( @@ -1135,7 +1108,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $where_clause_html, $condition_array, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf, $output ) { - + $this->assertEquals( $this->_callPrivateFunction( '_getCheckboxAndLinks', @@ -1149,10 +1122,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $output ); } - + /** * Data provider for testGetCheckboxAndLinksCase2 - * + * * @return array parameters and output */ public function dataProviderForGetCheckboxAndLinksCase2() @@ -1196,10 +1169,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase ) ); } - + /** * Test for _getCheckboxAndLinks - case 2 - * + * * @param string $position the position of the checkbox and links * @param string $del_url delete url * @param array $is_display array with explicit indexes for all the @@ -1218,7 +1191,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase * @param string $del_str text for the delete link * @param string $js_conf text for the JS confirmation * @param string $output output of _getCheckboxAndLinks - * + * * @dataProvider dataProviderForGetCheckboxAndLinksCase2 */ public function testGetCheckboxAndLinksCase2( @@ -1226,7 +1199,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $where_clause_html, $condition_array, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf, $output ) { - + $this->assertEquals( $this->_callPrivateFunction( '_getCheckboxAndLinks', @@ -1240,10 +1213,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $output ); } - + /** * Data provider for testGetCheckboxAndLinksCase3 - * + * * @return array parameters and output */ public function dataProviderForGetCheckboxAndLinksCase3() @@ -1281,10 +1254,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase ) ); } - + /** * Test for _getCheckboxAndLinks - case 3 - * + * * @param string $position the position of the checkbox and links * @param string $del_url delete url * @param array $is_display array with explicit indexes for all the @@ -1303,7 +1276,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase * @param string $del_str text for the delete link * @param string $js_conf text for the JS confirmation * @param string $output output of _getCheckboxAndLinks - * + * * @dataProvider dataProviderForGetCheckboxAndLinksCase3 */ public function testGetCheckboxAndLinksCase3( @@ -1311,7 +1284,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $where_clause_html, $condition_array, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf, $output ) { - + $this->assertEquals( $this->_callPrivateFunction( '_getCheckboxAndLinks', @@ -1325,7 +1298,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $output ); } - + /** * Test for _mimeDefaultFunction */ @@ -1339,10 +1312,10 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase "A 'quote' is <b>bold</b>" ); } - + /** * Data provider for testGetPlacedLinks - * + * * @return array parameters and output */ public function dataProviderForGetPlacedLinks() @@ -1383,7 +1356,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase /** * Test for _getPlacedLinks - * + * * @param string $dir the direction of links should place * @param string $del_url the url for delete row * @param array $is_display which elements to display @@ -1400,15 +1373,15 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase * @param string $copy_str the label for copy row * @param string $del_str the label for delete row * @param string $js_conf text for the JS confirmation - * @param string $output output of _getPlacedLinks - * + * @param string $output output of _getPlacedLinks + * * @dataProvider dataProviderForGetPlacedLinks */ public function testGetPlacedLinks( $dir, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, $dir_letter, $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf, $output - ) { + ) { $this->assertEquals( $this->_callPrivateFunction( '_getPlacedLinks', @@ -1422,6 +1395,6 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase $output ); } - + } diff --git a/test/classes/PMA_Error_test.php b/test/classes/PMA_Error_test.php index 0965b90546..e1c0569253 100644 --- a/test/classes/PMA_Error_test.php +++ b/test/classes/PMA_Error_test.php @@ -49,7 +49,7 @@ class PMA_Error_test extends PHPUnit_Framework_TestCase */ public function testSetBacktrace(){ $this->object->setBacktrace(array('bt1','bt2')); - $this->assertEquals($this->object->getBacktrace(),array('bt1','bt2')); + $this->assertEquals(array('bt1','bt2'), $this->object->getBacktrace()); } /** @@ -57,15 +57,15 @@ class PMA_Error_test extends PHPUnit_Framework_TestCase */ public function testSetLine(){ $this->object->setLine(15); - $this->assertEquals($this->object->getLine(),15); + $this->assertEquals(15, $this->object->getLine()); } /** * Test for setFile */ public function testSetFile(){ - $this->object->setFile('/var/www/pma.txt'); - $this->assertEquals($this->object->getFile(),'./../../..'); + $this->object->setFile('./pma.txt'); + $this->assertEquals('./../../../../..', $this->object->getFile()); } /** @@ -93,13 +93,13 @@ class PMA_Error_test extends PHPUnit_Framework_TestCase * Test for getHtmlTitle */ public function testGetHtmlTitle(){ - $this->assertEquals($this->object->getHtmlTitle(),'Warning: Compile Error'); + $this->assertEquals('Warning: Compile Error', $this->object->getHtmlTitle()); } /** * Test for getTitle */ public function testGetTitle(){ - $this->assertEquals($this->object->getTitle(),'Warning: Compile Error'); + $this->assertEquals('Warning: Compile Error', $this->object->getTitle()); } } diff --git a/test/classes/PMA_Message_test.php b/test/classes/PMA_Message_test.php index 19db79edfd..444b45f574 100644 --- a/test/classes/PMA_Message_test.php +++ b/test/classes/PMA_Message_test.php @@ -329,6 +329,7 @@ class PMA_Message_test extends PHPUnit_Framework_TestCase $GLOBALS['lang'] = 'en'; $_SESSION[' PMA_token '] = 'token'; unset($GLOBALS['server']); + unset($GLOBALS['collation_connection']); $this->assertEquals($expected, PMA_Message::decodeBB($actual)); } diff --git a/test/classes/PMA_Scripts_test.php b/test/classes/PMA_Scripts_test.php index ef26ed54e3..8ab2adf77b 100644 --- a/test/classes/PMA_Scripts_test.php +++ b/test/classes/PMA_Scripts_test.php @@ -111,12 +111,12 @@ class PMA_Scripts_test extends PHPUnit_Framework_TestCase $this->object->addFile('common.js'); $this->object->addEvent('onClick', 'doSomething'); - $this->assertEquals( - $this->object->getDisplay(), - ' -' + $this->assertRegExp( + '@ +@', + $this->object->getDisplay() ); } diff --git a/test/classes/PMA_Theme_Manager_test.php b/test/classes/PMA_Theme_Manager_test.php index d9c7bfbec1..f76d49e9aa 100644 --- a/test/classes/PMA_Theme_Manager_test.php +++ b/test/classes/PMA_Theme_Manager_test.php @@ -26,8 +26,10 @@ class PMA_Theme_Manager_test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['ThemeDefault'] = 'pmahomme'; $GLOBALS['cfg']['ServerDefault'] = 0; $GLOBALS['server'] = 99; + $GLOBALS['lang'] = 'en'; $_SESSION[' PMA_token '] = 'token'; $GLOBALS['PMA_Config'] = new PMA_Config(); + $GLOBALS['collation_connection'] = 'utf8_general_ci'; } public function testCookieName() @@ -89,8 +91,8 @@ class PMA_Theme_Manager_test extends PHPUnit_Framework_TestCase public function testGetPrintPreviews(){ $tm = new PMA_Theme_Manager(); $this->assertEquals( - $tm->getPrintPreviews(), - '

pmahomme (1.1)

pmahomme
[ take it ]

' + '

Original (2.9)

Original
[ take it ]

pmahomme (1.1)

pmahomme
[ take it ]

', + $tm->getPrintPreviews() ); } diff --git a/test/classes/PMA_Theme_test.php b/test/classes/PMA_Theme_test.php index d65f2a0e6c..6a7c548778 100644 --- a/test/classes/PMA_Theme_test.php +++ b/test/classes/PMA_Theme_test.php @@ -33,6 +33,9 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['SQP']['fmtColor'] = array('fake' => 'red'); $GLOBALS['text_dir'] = 'ltr'; require 'themes/pmahomme/layout.inc.php'; + $_SESSION[' PMA_token '] = 'token'; + $GLOBALS['lang'] = 'en'; + $GLOBALS['server'] = '99'; } /** @@ -222,7 +225,7 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase { $this->assertEquals( $this->object->getPrintPreview(), - '' + '' ); } diff --git a/test/classes/PMA_Types_MySQL_test.php b/test/classes/PMA_Types_MySQL_test.php index 281598e53a..f322b87cdd 100644 --- a/test/classes/PMA_Types_MySQL_test.php +++ b/test/classes/PMA_Types_MySQL_test.php @@ -267,8 +267,8 @@ class PMA_Types_MySQL_test extends PHPUnit_Framework_TestCase } $this->assertEquals( - $this->object->getFunctionsClass($class), - $output + $output, + $this->object->getFunctionsClass($class) ); } diff --git a/test/libraries/PMA_SQL_parser_test.php b/test/libraries/PMA_SQL_parser_test.php index 845701760b..d2f49959e3 100644 --- a/test/libraries/PMA_SQL_parser_test.php +++ b/test/libraries/PMA_SQL_parser_test.php @@ -15,9 +15,10 @@ class PMA_SQL_parser_test extends PHPUnit_Framework_TestCase { private function assertParser($sql, $expected, $error = '') { + PMA_SQP_resetError(); $parsed_sql = PMA_SQP_parse($sql); - $this->assertEquals(PMA_SQP_getErrorString(), $error); - $this->assertEquals($parsed_sql, $expected); + $this->assertEquals($error, PMA_SQP_getErrorString()); + $this->assertEquals($expected, $parsed_sql); } public function testParse_1() diff --git a/test/libraries/PMA_STR_sub_test.php b/test/libraries/PMA_STR_sub_test.php index 73639d0250..3bf3a8c807 100644 --- a/test/libraries/PMA_STR_sub_test.php +++ b/test/libraries/PMA_STR_sub_test.php @@ -6,33 +6,6 @@ * @package PhpMyAdmin-test */ -$match = array(); -preg_match( - '@^([0-9]{1,2})(?:.([0-9]{1,2})(?:.([0-9]{1,2}))?)?@', - phpversion(), - $match -); -if (isset($match) && ! empty($match[1])) { - if (! isset($match[2])) { - $match[2] = 0; - } - if (! isset($match[3])) { - $match[3] = 0; - } - /** - * @ignore - */ - define( - 'PMA_PHP_INT_VERSION', - (int)sprintf('%d%02d%02d', $match[1], $match[2], $match[3]) - ); -} else { - /** - * @ignore - */ - define('PMA_PHP_INT_VERSION', 0); -} - require_once 'libraries/string.lib.php'; class PMA_STR_sub_test extends PHPUnit_Framework_TestCase diff --git a/test/libraries/PMA_bookmark_test.php b/test/libraries/PMA_bookmark_test.php index 7454299905..0054815743 100644 --- a/test/libraries/PMA_bookmark_test.php +++ b/test/libraries/PMA_bookmark_test.php @@ -102,7 +102,12 @@ class PMA_bookmark_test extends PHPUnit_Framework_TestCase } } $this->assertEquals( - PMA_Bookmark_save('phpmyadmin'), + PMA_Bookmark_save(array( + 'dbase' => 'phpmyadmin', + 'user' => 'phpmyadmin', + 'query' => 'SELECT "phpmyadmin"', + 'label' => 'phpmyadmin', + )), true ); } diff --git a/test/libraries/PMA_mime_test.php b/test/libraries/PMA_mime_test.php new file mode 100644 index 0000000000..57ef205ec6 --- /dev/null +++ b/test/libraries/PMA_mime_test.php @@ -0,0 +1,55 @@ +assertEquals( + PMA_detectMIME($test), + $output + ); + } + + /** + * Provider for testPMA_detectMIME + */ + public function providerForTestPMA_detectMIME(){ + return array( + array( + 'pma', + 'application/octet-stream' + ), + array( + 'GIF', + 'image/gif' + ), + array( + "\x89PNG", + 'image/png' + ), + array( + chr(0xff).chr(0xd8), + 'image/jpeg' + ), + ); + } +}