diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 3ecc853ef1..80a523bc0a 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'; @@ -28,6 +29,9 @@ class PMA_DisplayResults const POSITION_RIGHT = 'right'; 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'; @@ -64,20 +68,113 @@ class PMA_DisplayResults const QUERY_TYPE_SELECT = 'SELECT'; + // Declare global fields + /** PMA_CommonFunctions object */ private $_common_functions; - private $_db, $_table, $_goto, $_sql_query; + + /** string Database name */ + private $_db; + + /** string Table name */ + private $_table; + + /** string the URL to go back in case of errors */ + private $_goto; + + /** string the SQL query */ + private $_sql_query; + + /** + * integer the total number of rows returned by the SQL query without any + * appended "LIMIT" clause programmatically + */ + private $_unlim_num_rows; + + /** array meta information about fields */ + private $_fields_meta; + + /** boolean */ + private $_is_count; + + /** integer */ + private $_is_export; + + /** boolean */ + private $_is_func; + + /** integer */ + private $_is_analyse; + + /** integer the total number of rows returned by the SQL query */ + private $_num_rows; + + /** array table definitions */ + private $_showtable; + + /** array column names to highlight */ + private $_highlight_columns; + + /** array informations used with vertical display mode */ + private $_vertical_display; + + /** integer the total number of fields returned by the SQL query */ + private $_fields_cnt; + + /** string */ + private $_printview; + + /** double time taken for execute the SQL query */ + private $_querytime; + + /** string path for theme images directory */ + private $_pma_theme_image; + + /** string */ + private $_text_dir; + + /** string URL query */ + private $_url_query; + + /** boolean */ + private $_is_maint; + + /** boolean */ + private $_is_explain; + + /** boolean */ + private $_is_show; + + /** array mime types information of fields */ + private $_mime_map; /** - * Set CommmonFunctions + * Get any property of this class * - * @param PMA_CommonFunctions $commonFunctions - * - * @return void + * @param string $property name of the property + * @return if property exist, value of the relavant property */ - public function setCommonFunctions(PMA_CommonFunctions $commonFunctions) - { - $this->_common_functions = $commonFunctions; + public function __get($property) { + + if (property_exists($this, $property)) { + return $this->$property; + } + + } + + + /** + * Set values for any property of this class + * + * @param string $property name of the property + * @param $value value to set + */ + public function __set($property, $value) { + + if (property_exists($this, $property)) { + $this->$property = $value; + } + } @@ -93,8 +190,8 @@ class PMA_DisplayResults } return $this->_common_functions; } + - /** * Constructor for PMA_DisplayResults class * @@ -107,10 +204,10 @@ 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); } @@ -149,6 +246,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 +268,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 +279,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 +292,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 +310,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 +333,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 +366,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 +394,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'; @@ -301,6 +415,8 @@ 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 * @@ -308,13 +424,13 @@ class PMA_DisplayResults * * @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 +473,11 @@ class PMA_DisplayResults return '