From dc7a308e690ef0994b16014b636f45b584b56520 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Tue, 3 Jul 2012 23:31:07 +0530 Subject: [PATCH 1/9] Break _getTableHeaders function in PMA_DisplayResults class, to sub functions --- libraries/DisplayResults.class.php | 318 +++++++++++++++++------------ 1 file changed, 191 insertions(+), 127 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 3ecc853ef1..83fa65e523 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -788,36 +788,13 @@ 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); - - // 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->_table, $this->_db); - - // do we have any index? - if ($indexes) { - $table_headers_html .= $this->_getSortByKeyDropDown( - $indexes, $sort_expression, - $unsorted_sql_query - ); - } - } + list($unsorted_sql_query, $drop_down_html) + = $this->_getUnsortedSqlAndSortByKeyDropDown( + $analyzed_sql, $sort_expression + ); + + $table_headers_html .= $drop_down_html; + } // Output data needed for grid editing @@ -850,103 +827,13 @@ class PMA_DisplayResults $is_display['del_lnk'] ); - // 1. Displays the full/partial text button (part 1)... - if ($directionCondition) { - - $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 .= '' - . $full_or_partial_text_link . ''; - // end horizontal/horizontalflipped mode - - } else { - - $GLOBALS['vertical_display']['textbtn'] - = ' ' . "\n" - . ' ' . "\n" - . ' ' . "\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 .= ''; - } + list($colspan, $rowspan, $button_html) + = $this->_getFeildVisibilityParams( + $directionCondition, $is_display, $fields_cnt, + $full_or_partial_text_link + ); + + $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" @@ -1191,8 +1078,62 @@ class PMA_DisplayResults return $table_headers_html; } // 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->_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->_table, $this->_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 * @@ -1280,7 +1221,130 @@ class PMA_DisplayResults return $drop_down_html; } // end of the '_getSortByKeyDropDown()' function + + + /** + * Set column span, row span and prepare html with full/partial + * text button or link + * + * @param boolean $directionCondition display direction horizontal or + * horizontalflipped + * @param array &$is_display which elements to display + * @param integer $fields_cnt the total number of fields + * returned by the SQL query + * @param string $full_or_partial_text_link full/partial link or text button + * + * @return array 3 element array - $colspan, $rowspan, $button_html + */ + private function _getFeildVisibilityParams( + $directionCondition, &$is_display, $fields_cnt, $full_or_partial_text_link + ) { + + $button_html = ''; + $colspan = $rowspan = null; + + // 1. Displays the full/partial text button (part 1)... + if ($directionCondition) { + $button_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) { + + $button_html .= '' + . '' + . ''; + + // end horizontal/horizontalflipped mode + } else { + + $span = $GLOBALS['num_rows'] + 1 + floor( + $GLOBALS['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 + + $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) { + + $button_html .= '' + . $full_or_partial_text_link . ''; + // end horizontal/horizontalflipped mode + + } else { + + $GLOBALS['vertical_display']['textbtn'] + = ' ' . "\n" + . ' ' . "\n" + . ' ' . "\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) { + + $button_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 + $button_html .= ''; + } + + return array($colspan, $rowspan, $button_html); + + } // end of the '_getFeildVisibilityParams()' function + /** * Prepare data for column restoring and show/hide From 76409e259d061ba65458516ca16c8f99588f6630 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Wed, 4 Jul 2012 23:06:01 +0530 Subject: [PATCH 2/9] Break _getTableHeaders function in PMA_DisplayResults class, to more sub functions --- libraries/DisplayResults.class.php | 477 ++++++++++++++++++----------- 1 file changed, 306 insertions(+), 171 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 83fa65e523..82ddc64979 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -827,6 +827,8 @@ class PMA_DisplayResults $is_display['del_lnk'] ); + // 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, $fields_cnt, @@ -843,19 +845,8 @@ 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'] && $GLOBALS['cfg']['BrowseMIME'] @@ -867,23 +858,8 @@ class PMA_DisplayResults // 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']) - ) { - - $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'; - } - } - } - + $this->_setHighlightedColumnGlobalField($analyzed_sql); + list($col_order, $col_visib) = $this->_getColumnParams(); for ($j = 0; $j < $fields_cnt; $j++) { @@ -902,98 +878,17 @@ class PMA_DisplayResults $comments = $this->_getCommentForRow($comments_map, $fields_meta[$i]); 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` - - $sort_tbl = (isset($fields_meta[$i]->table) - && strlen($fields_meta[$i]->table)) - ? $this->getCommonFunctions()->backquote( - $fields_meta[$i]->table - ) . '.' - : ''; - - // 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 - ); - } + + 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 + ); + + $table_headers_html .= $sorted_headrer_html; $GLOBALS['vertical_display']['desc'][] = ' '; } // end else (2.2) } // end for - - // 3. 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') - ) { - - $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" - . '' . $full_or_partial_text_link - . ''; - - // end horizontal/horizontalflipped mode - } else { - $GLOBALS['vertical_display']['textbtn'] = ' ' . "\n" - . ' ' . "\n" - . ' ' . "\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 .= '' @@ -1235,6 +1087,10 @@ class PMA_DisplayResults * @param string $full_or_partial_text_link full/partial link or text button * * @return array 3 element array - $colspan, $rowspan, $button_html + * + * @access private + * + * @see _getTableHeaders() */ private function _getFeildVisibilityParams( $directionCondition, &$is_display, $fields_cnt, $full_or_partial_text_link @@ -1345,6 +1201,77 @@ class PMA_DisplayResults } // end of the '_getFeildVisibilityParams()' function + + /** + * Get table comments as array + * + * @param boolean $directionCondition 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->_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) + { + + $GLOBALS['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 + ) { + $GLOBALS['highlight_columns'][$wci] = 'true'; + } + } + } + + } // end of the '_setHighlightedColumnGlobalField()' function + /** * Prepare data for column restoring and show/hide @@ -1622,7 +1549,138 @@ class PMA_DisplayResults } return $comments; } // 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->_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); + + // 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 @@ -1934,6 +1992,83 @@ 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 = ''; + + // 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') + ) { + + $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) { + $right_column_html .= "\n" + . '' . $full_or_partial_text_link + . ''; + + // end horizontal/horizontalflipped mode + } else { + $GLOBALS['vertical_display']['textbtn'] = ' ' . "\n" + . ' ' . "\n" + . ' ' . "\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) { + $right_column_html .= "\n" + . ''; + + // end horizontal/horizontalflipped mode + } else { + $GLOBALS['vertical_display']['textbtn'] = ' ' . "\n"; + } // end vertical mode + } + + return $right_column_html; + + } // end of the '_getColumnAtRightSide()' function + /** * Prepares the display for a value From 0e818398dc91245051f9fc2266d368fc132a70e1 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Thu, 5 Jul 2012 01:35:30 +0530 Subject: [PATCH 3/9] Break _getTableBody function in PMA_DisplayResults class, to sub functions --- libraries/DisplayResults.class.php | 566 +++++++++++++++++------------ 1 file changed, 324 insertions(+), 242 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 82ddc64979..701aa75e64 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -2357,175 +2357,12 @@ 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 only if the display dir is not vertical - && ($_SESSION['tmp_user_values']['disp_direction'] - != self::DISP_DIR_VERTICAL)) - ? 'hide' - : ''; - - // handle datetime-related class, for grid editing - $field_type_class - = $this->_getClassForDateTimeRelatedFields($meta->type); - - $pointer = $i; - $is_field_truncated = false; - //If the previous column had blob data, we need to reset the class - // to $inline_edit_class - $class = $this->_getResettedClassForInlineEdit( - $grid_edit_class, $not_null_class, $relation_class, - $hide_class, $field_type_class, $row_no - ); - - // See if this column should get highlight because it's used in the - // where-query. - $condition_field = (isset($GLOBALS['highlight_columns']) - && (isset($GLOBALS['highlight_columns'][$meta->name]) - || isset($GLOBALS['highlight_columns'][$this->getCommonFunctions()->backquote($meta->name)]))) - ? true - : false; - - // Wrap MIME-transformations. [MIME] - $default_function = '_mimeDefaultFunction'; // default_function - $transformation_plugin = $default_function; - $transform_options = array(); - - if ($GLOBALS['cfgRelation']['mimework'] - && $GLOBALS['cfg']['BrowseMIME'] - ) { - - if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) - && isset($GLOBALS['mime_map'][$meta->name]['transformation']) - && !empty($GLOBALS['mime_map'][$meta->name]['transformation']) - ) { - - $file = $GLOBALS['mime_map'][$meta->name]['transformation']; - $include_file = 'libraries/plugins/transformations/' . $file; - - if (file_exists($include_file)) { - - include_once $include_file; - $class_name = str_replace('.class.php', '', $file); - // todo add $plugin_manager - $plugin_manager = null; - $transformation_plugin = new $class_name( - $plugin_manager - ); - - $transform_options = PMA_transformation_getOptions( - isset($GLOBALS['mime_map'][$meta->name] - ['transformation_options'] - ) - ? $GLOBALS['mime_map'][$meta->name] - ['transformation_options'] - : '' - ); - - $meta->mimetype = str_replace( - '_', '/', - $GLOBALS['mime_map'][$meta->name]['mimetype'] - ); - - } // end if file_exists - } // end if transformation is set - } // end if mime/transformation works. - - $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, - 'where_clause' => $where_clause, - 'transform_key' => $meta->name, - ); - - if (! empty($this->_sql_query)) { - $_url_params['sql_query'] = $url_sql_query; - } - - $transform_options['wrapper_link'] - = PMA_generate_common_url($_url_params); - - if ($meta->numeric == 1) { - // n u m e r i c - - // if two fields have the same name (this is possible - // with self-join queries, for example), using $meta->name - // will show both fields NULL even if only one is NULL, - // so use the $pointer - - $GLOBALS['vertical_display']['data'][$row_no][$i] - = $this->_getDataCellForNumericColumns( - $row[$i], $class, $condition_field, $meta, $map, - $is_field_truncated, $analyzed_sql, - $transformation_plugin, $default_function, - $transform_options - ); - - } elseif (stristr($meta->type, self::BLOB_FIELD)) { - // b l o b - - // PMA_mysql_fetch_fields returns BLOB in place of - // TEXT fields type so we have to ensure it's really a BLOB - $field_flags = PMA_DBI_field_flags($dt_result, $i); - - $GLOBALS['vertical_display']['data'][$row_no][$i] - = $this->_getDataCellForBlobColumns( - $row[$i], $class, $meta, $_url_params, $field_flags, - $transformation_plugin, $default_function, - $transform_options, $condition_field, $is_field_truncated - ); - - } elseif ($meta->type == self::GEOMETRY_FIELD) { - // g e o m e t r y - - // Remove 'grid_edit' from $class as we do not allow to - // inline-edit geometry data. - $class = str_replace('grid_edit', '', $class); - - $GLOBALS['vertical_display']['data'][$row_no][$i] - = $this->_getDataCellForGeometryColumns( - $row[$i], $class, $meta, $map, $_url_params, - $condition_field, $transformation_plugin, - $default_function, $transform_options, - $is_field_truncated, $analyzed_sql - ); - - } else { - // n o t n u m e r i c a n d n o t B L O B - - $GLOBALS['vertical_display']['data'][$row_no][$i] - = $this->_getDataCellForNonNumericAndNonBlobColumns( - $row[$i], $class, $meta, $map, $_url_params, - $condition_field, $transformation_plugin, - $default_function, $transform_options, - $is_field_truncated, $analyzed_sql, $dt_result, $i - ); - - } - - // output stored cell - if ($directionCondition) { - $table_body_html - .= $GLOBALS['vertical_display']['data'][$row_no][$i]; - } - - if (isset($GLOBALS['vertical_display']['rowdata'][$i][$row_no])) { - $GLOBALS['vertical_display']['rowdata'][$i][$row_no] - .= $GLOBALS['vertical_display']['data'][$row_no][$i]; - } else { - $GLOBALS['vertical_display']['rowdata'][$i][$row_no] - = $GLOBALS['vertical_display']['data'][$row_no][$i]; - } - } // end for (2) - + $table_body_html .= $this->_getRowValues( + $dt_result, $row, $row_no, $col_order, $map, + $grid_edit_class, $col_visib, $where_clause, + $url_sql_query, $analyzed_sql, $directionCondition + ); + // 3. Displays the modify/delete links on the right if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) @@ -2546,79 +2383,13 @@ class PMA_DisplayResults } // end if // 4. Gather links of del_urls and edit_urls in an array for later - // output - if (! isset($GLOBALS['vertical_display']['edit'][$row_no])) { - $GLOBALS['vertical_display']['edit'][$row_no] = ''; - $GLOBALS['vertical_display']['copy'][$row_no] = ''; - $GLOBALS['vertical_display']['delete'][$row_no] = ''; - $GLOBALS['vertical_display']['row_delete'][$row_no] = ''; - } - - $vertical_class = ' row_' . $row_no; - if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) { - $vertical_class .= ' vpointer'; - } - - if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) { - $vertical_class .= ' vmarker'; - } - - if (!empty($del_url) - && ($is_display['del_lnk'] != self::KILL_PROCESS) - ) { - - $GLOBALS['vertical_display']['row_delete'][$row_no] - .= $this->_getCheckboxForMultiRowSubmissions( - $del_url, $is_display, $row_no, $where_clause_html, - $condition_array, $del_query, '[%_PMA_CHECKBOX_DIR_%]', - $alternating_color_class . $vertical_class - ); - - } else { - unset($GLOBALS['vertical_display']['row_delete'][$row_no]); - } - - if (isset($edit_url)) { - - $GLOBALS['vertical_display']['edit'][$row_no] .= $this->_getEditLink( - $edit_url, - $alternating_color_class . ' ' . $edit_anchor_class - . $vertical_class, $edit_str, - $where_clause, - $where_clause_html - ); - - } else { - unset($GLOBALS['vertical_display']['edit'][$row_no]); - } - - if (isset($copy_url)) { - - $GLOBALS['vertical_display']['copy'][$row_no] .= $this->_getCopyLink( - $copy_url, $copy_str, $where_clause, $where_clause_html, - $alternating_color_class . $vertical_class - ); - - } else { - unset($GLOBALS['vertical_display']['copy'][$row_no]); - } - - if (isset($del_url)) { - - if (! isset($js_conf)) { - $js_conf = ''; - } - - $GLOBALS['vertical_display']['delete'][$row_no] - .= $this->_getDeleteLink( - $del_url, $del_str, $js_conf, - $alternating_color_class . $vertical_class - ); - - } else { - unset($GLOBALS['vertical_display']['delete'][$row_no]); - } - + // output + $this->_gatherLinksForLaterOutputs( + $row_no, $is_display, $where_clause, $where_clause_html, $js_conf, + $del_url, $del_query, $del_str, $edit_anchor_class, $edit_str, + $copy_url, $copy_str, $alternating_color_class, $condition_array + ); + $table_body_html .= $directionCondition ? "\n" : ''; $row_no++; @@ -2627,7 +2398,318 @@ class PMA_DisplayResults return $table_body_html; } // end of the '_getTableBody()' function + + + /** + * Prepare rows + * + * @param integer &$dt_result the link id associated to the query + * which results have to be displayed + * @param array $row current row data + * @param integer $row_no the index of current row + * @param array $col_order the column order + * false when a property not found + * @param array $map the list of relations + * @param string $grid_edit_class the class for all editable columns + * @param boolean $col_visib column is visible(false) + * array column isn't visible(string array) + * @param string $where_clause where clause + * @param string $url_sql_query the analyzed sql query + * @param array $analyzed_sql the analyzed query + * @param boolean $directionCondition the directional condition + * + * @return string $row_values_html html content + * + * @access private + * + * @see _getTableBody() + */ + private function _getRowValues( + &$dt_result, $row, $row_no, $col_order, $map, + $grid_edit_class, $col_visib, $where_clause, + $url_sql_query, $analyzed_sql, $directionCondition + ) { + + $row_values_html = ''; + + 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 only if the display dir is not vertical + && ($_SESSION['tmp_user_values']['disp_direction'] + != self::DISP_DIR_VERTICAL)) + ? 'hide' + : ''; + + // handle datetime-related class, for grid editing + $field_type_class + = $this->_getClassForDateTimeRelatedFields($meta->type); + + $pointer = $i; + $is_field_truncated = false; + //If the previous column had blob data, we need to reset the class + // to $inline_edit_class + $class = $this->_getResettedClassForInlineEdit( + $grid_edit_class, $not_null_class, $relation_class, + $hide_class, $field_type_class, $row_no + ); + + // See if this column should get highlight because it's used in the + // where-query. + $condition_field = (isset($GLOBALS['highlight_columns']) + && (isset($GLOBALS['highlight_columns'][$meta->name]) + || isset($GLOBALS['highlight_columns'][$this->getCommonFunctions()->backquote($meta->name)]))) + ? true + : false; + + // Wrap MIME-transformations. [MIME] + $default_function = '_mimeDefaultFunction'; // default_function + $transformation_plugin = $default_function; + $transform_options = array(); + + if ($GLOBALS['cfgRelation']['mimework'] + && $GLOBALS['cfg']['BrowseMIME'] + ) { + + if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) + && isset($GLOBALS['mime_map'][$meta->name]['transformation']) + && !empty($GLOBALS['mime_map'][$meta->name]['transformation']) + ) { + + $file = $GLOBALS['mime_map'][$meta->name]['transformation']; + $include_file = 'libraries/plugins/transformations/' . $file; + + if (file_exists($include_file)) { + + include_once $include_file; + $class_name = str_replace('.class.php', '', $file); + // todo add $plugin_manager + $plugin_manager = null; + $transformation_plugin = new $class_name( + $plugin_manager + ); + + $transform_options = PMA_transformation_getOptions( + isset($GLOBALS['mime_map'][$meta->name] + ['transformation_options'] + ) + ? $GLOBALS['mime_map'][$meta->name] + ['transformation_options'] + : '' + ); + + $meta->mimetype = str_replace( + '_', '/', + $GLOBALS['mime_map'][$meta->name]['mimetype'] + ); + + } // end if file_exists + } // end if transformation is set + } // end if mime/transformation works. + + $_url_params = array( + 'db' => $this->_db, + 'table' => $this->_table, + 'where_clause' => $where_clause, + 'transform_key' => $meta->name, + ); + + if (! empty($this->_sql_query)) { + $_url_params['sql_query'] = $url_sql_query; + } + + $transform_options['wrapper_link'] + = PMA_generate_common_url($_url_params); + + if ($meta->numeric == 1) { + // n u m e r i c + + // if two fields have the same name (this is possible + // with self-join queries, for example), using $meta->name + // will show both fields NULL even if only one is NULL, + // so use the $pointer + + $GLOBALS['vertical_display']['data'][$row_no][$i] + = $this->_getDataCellForNumericColumns( + $row[$i], $class, $condition_field, $meta, $map, + $is_field_truncated, $analyzed_sql, + $transformation_plugin, $default_function, + $transform_options + ); + + } elseif (stristr($meta->type, self::BLOB_FIELD)) { + // b l o b + + // PMA_mysql_fetch_fields returns BLOB in place of + // TEXT fields type so we have to ensure it's really a BLOB + $field_flags = PMA_DBI_field_flags($dt_result, $i); + + $GLOBALS['vertical_display']['data'][$row_no][$i] + = $this->_getDataCellForBlobColumns( + $row[$i], $class, $meta, $_url_params, $field_flags, + $transformation_plugin, $default_function, + $transform_options, $condition_field, $is_field_truncated + ); + + } elseif ($meta->type == self::GEOMETRY_FIELD) { + // g e o m e t r y + + // Remove 'grid_edit' from $class as we do not allow to + // inline-edit geometry data. + $class = str_replace('grid_edit', '', $class); + + $GLOBALS['vertical_display']['data'][$row_no][$i] + = $this->_getDataCellForGeometryColumns( + $row[$i], $class, $meta, $map, $_url_params, + $condition_field, $transformation_plugin, + $default_function, $transform_options, + $is_field_truncated, $analyzed_sql + ); + + } else { + // n o t n u m e r i c a n d n o t B L O B + + $GLOBALS['vertical_display']['data'][$row_no][$i] + = $this->_getDataCellForNonNumericAndNonBlobColumns( + $row[$i], $class, $meta, $map, $_url_params, + $condition_field, $transformation_plugin, + $default_function, $transform_options, + $is_field_truncated, $analyzed_sql, $dt_result, $i + ); + + } + + // output stored cell + if ($directionCondition) { + $row_values_html + .= $GLOBALS['vertical_display']['data'][$row_no][$i]; + } + + if (isset($GLOBALS['vertical_display']['rowdata'][$i][$row_no])) { + $GLOBALS['vertical_display']['rowdata'][$i][$row_no] + .= $GLOBALS['vertical_display']['data'][$row_no][$i]; + } else { + $GLOBALS['vertical_display']['rowdata'][$i][$row_no] + = $GLOBALS['vertical_display']['data'][$row_no][$i]; + } + } // end for + + return $row_values_html; + + } // end of the '_getRowValues()' function + + + /** + * Gather delete/edit url links for further outputs + * + * @param integer $row_no the index of current row + * @param array $is_display which elements to display + * @param string $where_clause where clause + * @param string $where_clause_html the html encoded where clause + * @param string $js_conf text for the JS confirmation + * @param string $del_url the url for delete row + * @param string $del_query the query for delete row + * @param string $del_str the label for delete row + * @param string $edit_anchor_class the class for html element for edit + * @param string $edit_str the label for edit row + * @param string $copy_url the url for copy row + * @param string $copy_str the label for copy row + * @param string $alternating_color_class class for display two colors in rows + * @param array $condition_array array of keys + * (primary,unique,condition) + * + * @return void + * + * @access private + * + * @see _getTableBody() + */ + private function _gatherLinksForLaterOutputs( + $row_no, $is_display, $where_clause, $where_clause_html, $js_conf, + $del_url, $del_query, $del_str, $edit_anchor_class, $edit_str, + $copy_url, $copy_str, $alternating_color_class, $condition_array + ) { + + if (! isset($GLOBALS['vertical_display']['edit'][$row_no])) { + $GLOBALS['vertical_display']['edit'][$row_no] = ''; + $GLOBALS['vertical_display']['copy'][$row_no] = ''; + $GLOBALS['vertical_display']['delete'][$row_no] = ''; + $GLOBALS['vertical_display']['row_delete'][$row_no] = ''; + } + + $vertical_class = ' row_' . $row_no; + if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) { + $vertical_class .= ' vpointer'; + } + + if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) { + $vertical_class .= ' vmarker'; + } + + if (!empty($del_url) + && ($is_display['del_lnk'] != self::KILL_PROCESS) + ) { + + $GLOBALS['vertical_display']['row_delete'][$row_no] + .= $this->_getCheckboxForMultiRowSubmissions( + $del_url, $is_display, $row_no, $where_clause_html, + $condition_array, $del_query, '[%_PMA_CHECKBOX_DIR_%]', + $alternating_color_class . $vertical_class + ); + + } else { + unset($GLOBALS['vertical_display']['row_delete'][$row_no]); + } + + if (isset($edit_url)) { + + $GLOBALS['vertical_display']['edit'][$row_no] .= $this->_getEditLink( + $edit_url, + $alternating_color_class . ' ' . $edit_anchor_class + . $vertical_class, $edit_str, + $where_clause, + $where_clause_html + ); + + } else { + unset($GLOBALS['vertical_display']['edit'][$row_no]); + } + + if (isset($copy_url)) { + + $GLOBALS['vertical_display']['copy'][$row_no] .= $this->_getCopyLink( + $copy_url, $copy_str, $where_clause, $where_clause_html, + $alternating_color_class . $vertical_class + ); + + } else { + unset($GLOBALS['vertical_display']['copy'][$row_no]); + } + + if (isset($del_url)) { + + if (! isset($js_conf)) { + $js_conf = ''; + } + + $GLOBALS['vertical_display']['delete'][$row_no] + .= $this->_getDeleteLink( + $del_url, $del_str, $js_conf, + $alternating_color_class . $vertical_class + ); + + } else { + unset($GLOBALS['vertical_display']['delete'][$row_no]); + } + + } // end of the '_gatherLinksForLaterOutputs()' function + /** * Get url sql query without conditions to shorten URLs From 9a83ad284e4925aab644823f739eed3890c15876 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Thu, 5 Jul 2012 07:41:39 +0530 Subject: [PATCH 4/9] Break _getTable function in PMA_DisplayResults class, to sub functions --- libraries/DisplayResults.class.php | 155 +++++++++++++++++++---------- 1 file changed, 104 insertions(+), 51 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 701aa75e64..e103753c69 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -28,6 +28,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'; @@ -4108,18 +4111,10 @@ class PMA_DisplayResults } - if (($is_display['nav_bar'] == '1') - && empty($analyzed_sql[0]['limit_clause']) - ) { - - $table_html .= $this->_getTableNavigation( - $pos_next, $pos_prev, 'top_direction_dropdown' - ) - . "\n"; - - } elseif (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) { - $table_html .= "\n" . '

' . "\n"; - } + $table_html .= $this->_getPlacedTableNavigatoins( + $is_display, $analyzed_sql, $pos_next, $pos_prev, + self::PLACE_TOP_DIRECTION_DROPDOWN, "\n" + ); // 2b ----- Get field references from Database ----- // (see the 'relation' configuration variable) @@ -4146,33 +4141,8 @@ class PMA_DisplayResults if (! strlen($this->_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 @@ -4213,18 +4183,10 @@ class PMA_DisplayResults // 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' - ); - - } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { - $table_html .= "\n" . '

' . "\n"; - } + $table_html .= $this->_getPlacedTableNavigatoins( + $is_display, $analyzed_sql, $pos_next, $pos_prev, + self::PLACE_BOTTOM_DIRECTION_DROPDOWN, '
' . "\n" + ); // 6. ----- Prepare "Query results operations" if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { @@ -4548,6 +4510,50 @@ 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->_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 + + } // end of the '_setParamForLinkForiegnKeyRelatedTables()' function + /** * Prepare multi field edit/delete links @@ -4646,6 +4652,53 @@ class PMA_DisplayResults } // end of the '_getMultiRowOperationLinks()' function + + /** + * Prepare table navigation bar at the top or bottom + * + * @param array $is_display which elements to display + * @param array $analyzed_sql the analyzed query + * @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 + * + * @return string html content of navigation bar + * + * @access private + * + * @see _getTable() + */ + private function _getPlacedTableNavigatoins( + $is_display, $analyzed_sql, $pos_next, $pos_prev, $place, $empty_line + ) { + + $navigation_html = ''; + + if (($is_display['nav_bar'] == '1') + && empty($analyzed_sql[0]['limit_clause']) + ) { + + if ($place == self::PLACE_BOTTOM_DIRECTION_DROPDOWN) { + $navigation_html .= '
' . "\n"; + } + + $navigation_html .= $this->_getTableNavigation( + $pos_next, $pos_prev, 'top_direction_dropdown' + ); + + if ($place == self::PLACE_TOP_DIRECTION_DROPDOWN) { + $navigation_html .= "\n"; + } + + } elseif (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) { + $navigation_html .= "\n" . '

' . "\n"; + } + + return $navigation_html; + + } // end of the '_getPlacedTableNavigatoins()' function + /** * Get operations that are available on results. From e7794d65c9f08b81474663ccc84f6db609123e55 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Sat, 7 Jul 2012 09:13:31 +0530 Subject: [PATCH 5/9] Reduce the use of superglobal variables in PMA_DisplayResults class --- libraries/DisplayResults.class.php | 397 ++++++++++++++++------------- 1 file changed, 218 insertions(+), 179 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index e103753c69..f8425799f0 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -68,7 +68,12 @@ class PMA_DisplayResults private $_common_functions; - private $_db, $_table, $_goto, $_sql_query; + private $_db, $_table, $_goto, $_sql_query; + private $_unlim_num_rows, $_fields_meta, $_is_count, $_is_export, $_is_func, + $_is_analyse, $_num_rows, $_showtable, $_highlight_columns, + $_vertical_display, $_fields_cnt, $_printview, $_querytime, + $_pma_theme_image, $_text_dir, $_url_query, $_is_maint, $_is_explain, + $_is_show, $_mime_map; /** @@ -166,7 +171,7 @@ 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($this->_printview) && $this->_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 @@ -176,8 +181,8 @@ 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->_is_count || $this->_is_analyse + || $this->_is_maint || $this->_is_explain ) { // 2.1 Statement is a "SELECT COUNT", a // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or @@ -188,14 +193,14 @@ 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->_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->_is_show) { // 2.2 Statement is a "SHOW..." /** * 2.2.1 @@ -205,7 +210,7 @@ class PMA_DisplayResults '@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?' . 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS' . ')@i', - $GLOBALS['sql_query'], $which + $this->_sql_query, $which ); if (isset($which[1]) && (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) @@ -232,17 +237,17 @@ class PMA_DisplayResults // 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 = $this->_fields_meta[0]->table; $do_display['text_btn'] = (string) '1'; - for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) { + for ($i = 0; $i < $this->_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)) + && (($this->_fields_meta[$i]->table == '') + || ($this->_fields_meta[$i]->table != $prev_table)) ) { // don't display links $do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE; @@ -259,14 +264,14 @@ class PMA_DisplayResults } // 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 = $this->_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($this->_unlim_num_rows) && $this->_unlim_num_rows != '') { + $the_total = $this->_unlim_num_rows; } elseif ((($do_display['nav_bar'] == '1') || ($do_display['sort_lnk'] == '1')) && (strlen($this->_db) && !empty($this->_table)) @@ -283,8 +288,8 @@ 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 + if (isset($this->_unlim_num_rows) + && $this->_unlim_num_rows < 2 && ! PMA_Table::isView($this->_db, $this->_table) ) { // force display of navbar for vertical/horizontal display-choice. @@ -304,6 +309,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 * @@ -311,13 +318,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->_is_count || $this->_is_export + || $this->_is_func || $this->_is_analyse) + && (count($analyzed_sql[0]['select_expr']) == 0) + && isset($analyzed_sql[0]['queryflags']['select_from']) + && (count($analyzed_sql[0]['table_ref']) == 1); } @@ -381,6 +388,7 @@ class PMA_DisplayResults * @param integer $pos_next the offset for the "next" page * @param integer $pos_prev the offset for the "previous" page * @param string $id_for_direction_dropdown the id for the direction dropdown + * @param boolean $is_innodb whether its InnoDB or not * * @return string html content * @@ -389,7 +397,7 @@ class PMA_DisplayResults * @see _getTable() */ private function _getTableNavigation( - $pos_next, $pos_prev, $id_for_direction_dropdown + $pos_next, $pos_prev, $id_for_direction_dropdown, $is_innodb ) { $table_navigation_html = ''; @@ -402,8 +410,8 @@ class PMA_DisplayResults * @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($this->_showtable['Type']) + && $this->_showtable['Type'] == self::TABLE_TYPE_INNO_DB); // Navigation bar $table_navigation_html .= '' @@ -433,7 +441,7 @@ class PMA_DisplayResults ) + 1; $nbTotalPage = @ceil( - $GLOBALS['unlim_num_rows'] + $this->_unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'] ); @@ -464,9 +472,9 @@ class PMA_DisplayResults } //_if1 // Display the "Show all" button if allowed - if (($GLOBALS['num_rows'] < $GLOBALS['unlim_num_rows']) + if (($this->_num_rows < $this->_unlim_num_rows) && ($GLOBALS['cfg']['ShowAll'] - || ($GLOBALS['cfg']['MaxRows'] * 5 >= $GLOBALS['unlim_num_rows'])) + || ($GLOBALS['cfg']['MaxRows'] * 5 >= $this->_unlim_num_rows)) ) { $table_navigation_html .= $this->_getShowAllButtonForTableNavigation( @@ -479,15 +487,15 @@ class PMA_DisplayResults $endpos = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows']; - if (($endpos < $GLOBALS['unlim_num_rows']) - && ($GLOBALS['num_rows'] >= $_SESSION['tmp_user_values']['max_rows']) + if (($endpos < $this->_unlim_num_rows) + && ($this->_num_rows >= $_SESSION['tmp_user_values']['max_rows']) && ($_SESSION['tmp_user_values']['max_rows'] != self::ALL_ROWS) ) { $table_navigation_html .= $this->_getMoveForwardButtonsForTableNavigation( - $html_sql_query, $pos_next, $GLOBALS['is_innodb'], - $GLOBALS['unlim_num_rows'], $GLOBALS['num_rows'] + $html_sql_query, $pos_next, $is_innodb, + $this->_unlim_num_rows, $this->_num_rows ); } // end move toward @@ -534,8 +542,8 @@ class PMA_DisplayResults . str_replace('\'', '\\\'', __('%d is not valid row number.')) . '\', ' . '0' - . (($GLOBALS['unlim_num_rows'] > 0) - ? ', ' . ($GLOBALS['unlim_num_rows'] - 1) + . (($this->_unlim_num_rows > 0) + ? ', ' . ($this->_unlim_num_rows - 1) : '' ) . ')' @@ -548,7 +556,7 @@ class PMA_DisplayResults $table_navigation_html .= $this->_getAdditionalFieldsForTableNavigation( $html_sql_query, $pos_next, - $GLOBALS['unlim_num_rows'], $id_for_direction_dropdown + $this->_unlim_num_rows, $id_for_direction_dropdown ); $table_navigation_html .= '' @@ -773,7 +781,7 @@ class PMA_DisplayResults // required to generate sort links that will remember whether the // "Show all" button has been clicked - $sql_md5 = md5($GLOBALS['sql_query']); + $sql_md5 = md5($this->_sql_query); $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows']; @@ -808,16 +816,16 @@ class PMA_DisplayResults . ''; // 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'] = ''; + $this->_vertical_display['emptypre'] = 0; + $this->_vertical_display['emptyafter'] = 0; + $this->_vertical_display['textbtn'] = ''; // Display options (if we are not in print view) - if (! (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1'))) { + if (! (isset($this->_printview) && ($this->_printview == '1'))) { $table_headers_html .= $this->_getOptionsBlock(); @@ -856,14 +864,14 @@ 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->_mime_map = PMA_getMIME($this->_db, $this->_table); } // See if we have to highlight any header fields of a WHERE query. // Uses SQL-Parser results. $this->_setHighlightedColumnGlobalField($analyzed_sql); - list($col_order, $col_visib) = $this->_getColumnParams(); + list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); for ($j = 0; $j < $fields_cnt; $j++) { @@ -872,8 +880,8 @@ class PMA_DisplayResults // 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($this->_highlight_columns[$fields_meta[$i]->name]) + || isset($this->_highlight_columns[$this->getCommonFunctions()->backquote($fields_meta[$i]->name)])) ? true : false; @@ -893,7 +901,7 @@ class PMA_DisplayResults $table_headers_html .= $sorted_headrer_html; - $GLOBALS['vertical_display']['desc'][] = ' '; @@ -1153,7 +1161,7 @@ class PMA_DisplayResults // ... at the left column of the result table header if possible // and required - $GLOBALS['vertical_display']['emptypre'] + $this->_vertical_display['emptypre'] = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; @@ -1165,7 +1173,7 @@ class PMA_DisplayResults } else { - $GLOBALS['vertical_display']['textbtn'] + $this->_vertical_display['textbtn'] = ' ' . "\n"; @@ -1178,7 +1186,7 @@ class PMA_DisplayResults ) { // ... elseif no button, displays empty(ies) col(s) if required - $GLOBALS['vertical_display']['emptypre'] + $this->_vertical_display['emptypre'] = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; @@ -1188,7 +1196,7 @@ class PMA_DisplayResults // end horizontal/horizontalfipped mode } else { - $GLOBALS['vertical_display']['textbtn'] = ' _vertical_display['textbtn'] = ' ' . "\n"; } // end vertical mode @@ -1256,7 +1264,7 @@ class PMA_DisplayResults private function _setHighlightedColumnGlobalField($analyzed_sql) { - $GLOBALS['highlight_columns'] = array(); + $this->_highlight_columns = array(); if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['where_clause_identifiers']) ) { @@ -1268,7 +1276,7 @@ class PMA_DisplayResults foreach ($analyzed_sql[0]['where_clause_identifiers'] as $wci_nr => $wci ) { - $GLOBALS['highlight_columns'][$wci] = 'true'; + $this->_highlight_columns[$wci] = 'true'; } } } @@ -1291,7 +1299,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->_table, $this->_db); $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER); if ($col_order) { @@ -1307,10 +1315,10 @@ class PMA_DisplayResults } // generate table create time - if (! PMA_Table::isView($GLOBALS['table'], $GLOBALS['db'])) { + if (! PMA_Table::isView($this->_db, $this->_table)) { $data_html .= ''; } @@ -1464,11 +1472,11 @@ class PMA_DisplayResults 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->_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->_pma_theme_image . 's_fulltext.png'; $tmp_txt = __('Full texts'); $url_params_full_text['display_text'] = self::DISPLAY_FULL_TEXT; } @@ -2028,7 +2036,7 @@ class PMA_DisplayResults && ($is_display['text_btn'] == '1') ) { - $GLOBALS['vertical_display']['emptyafter'] + $this->_vertical_display['emptyafter'] = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 1; @@ -2039,7 +2047,7 @@ class PMA_DisplayResults // end horizontal/horizontalflipped mode } else { - $GLOBALS['vertical_display']['textbtn'] = ' ' . "\n"; @@ -2053,7 +2061,7 @@ class PMA_DisplayResults // ... elseif no button, displays empty columns if required // (unless coming from Browse mode print view) - $GLOBALS['vertical_display']['emptyafter'] + $this->_vertical_display['emptyafter'] = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 1; @@ -2063,7 +2071,7 @@ class PMA_DisplayResults // end horizontal/horizontalflipped mode } else { - $GLOBALS['vertical_display']['textbtn'] = ' _vertical_display['textbtn'] = ' ' . "\n"; } // end vertical mode } @@ -2234,16 +2242,16 @@ class PMA_DisplayResults } $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(); + $this->_vertical_display['edit'] = array(); + $this->_vertical_display['copy'] = array(); + $this->_vertical_display['delete'] = array(); + $this->_vertical_display['data'] = array(); + $this->_vertical_display['row_delete'] = array(); // 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 @@ -2268,7 +2276,7 @@ class PMA_DisplayResults // "vertical display" mode stuff $table_body_html .= $this->_getVerticalDisplaySupportSegments( - $GLOBALS['vertical_display'], $row_no, $directionCondition + $this->_vertical_display, $row_no, $directionCondition ); $alternating_color_class = ($odd_row ? 'odd' : 'even'); @@ -2289,7 +2297,7 @@ 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->_fields_cnt, $this->_fields_meta, $row ); $where_clause_html = urlencode($where_clause); @@ -2435,12 +2443,12 @@ class PMA_DisplayResults $row_values_html = ''; - for ($j = 0; $j < $GLOBALS['fields_cnt']; ++$j) { + for ($j = 0; $j < $this->_fields_cnt; ++$j) { // assign $i with appropriate column order $i = $col_order ? $col_order[$j] : $j; - $meta = $GLOBALS['fields_meta'][$i]; + $meta = $this->_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] @@ -2465,9 +2473,9 @@ class PMA_DisplayResults // See if this column should get highlight because it's used in the // where-query. - $condition_field = (isset($GLOBALS['highlight_columns']) - && (isset($GLOBALS['highlight_columns'][$meta->name]) - || isset($GLOBALS['highlight_columns'][$this->getCommonFunctions()->backquote($meta->name)]))) + $condition_field = (isset($this->_highlight_columns) + && (isset($this->_highlight_columns[$meta->name]) + || isset($this->_highlight_columns[$this->getCommonFunctions()->backquote($meta->name)]))) ? true : false; @@ -2480,12 +2488,12 @@ class PMA_DisplayResults && $GLOBALS['cfg']['BrowseMIME'] ) { - if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) - && isset($GLOBALS['mime_map'][$meta->name]['transformation']) - && !empty($GLOBALS['mime_map'][$meta->name]['transformation']) + if (isset($this->_mime_map[$meta->name]['mimetype']) + && isset($this->_mime_map[$meta->name]['transformation']) + && !empty($this->_mime_map[$meta->name]['transformation']) ) { - $file = $GLOBALS['mime_map'][$meta->name]['transformation']; + $file = $this->_mime_map[$meta->name]['transformation']; $include_file = 'libraries/plugins/transformations/' . $file; if (file_exists($include_file)) { @@ -2499,17 +2507,17 @@ class PMA_DisplayResults ); $transform_options = PMA_transformation_getOptions( - isset($GLOBALS['mime_map'][$meta->name] + isset($this->_mime_map[$meta->name] ['transformation_options'] ) - ? $GLOBALS['mime_map'][$meta->name] + ? $this->_mime_map[$meta->name] ['transformation_options'] : '' ); $meta->mimetype = str_replace( '_', '/', - $GLOBALS['mime_map'][$meta->name]['mimetype'] + $this->_mime_map[$meta->name]['mimetype'] ); } // end if file_exists @@ -2538,7 +2546,7 @@ class PMA_DisplayResults // will show both fields NULL even if only one is NULL, // so use the $pointer - $GLOBALS['vertical_display']['data'][$row_no][$i] + $this->_vertical_display['data'][$row_no][$i] = $this->_getDataCellForNumericColumns( $row[$i], $class, $condition_field, $meta, $map, $is_field_truncated, $analyzed_sql, @@ -2553,7 +2561,7 @@ class PMA_DisplayResults // TEXT fields type so we have to ensure it's really a BLOB $field_flags = PMA_DBI_field_flags($dt_result, $i); - $GLOBALS['vertical_display']['data'][$row_no][$i] + $this->_vertical_display['data'][$row_no][$i] = $this->_getDataCellForBlobColumns( $row[$i], $class, $meta, $_url_params, $field_flags, $transformation_plugin, $default_function, @@ -2567,7 +2575,7 @@ class PMA_DisplayResults // inline-edit geometry data. $class = str_replace('grid_edit', '', $class); - $GLOBALS['vertical_display']['data'][$row_no][$i] + $this->_vertical_display['data'][$row_no][$i] = $this->_getDataCellForGeometryColumns( $row[$i], $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, @@ -2578,7 +2586,7 @@ class PMA_DisplayResults } else { // n o t n u m e r i c a n d n o t B L O B - $GLOBALS['vertical_display']['data'][$row_no][$i] + $this->_vertical_display['data'][$row_no][$i] = $this->_getDataCellForNonNumericAndNonBlobColumns( $row[$i], $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, @@ -2591,15 +2599,15 @@ class PMA_DisplayResults // output stored cell if ($directionCondition) { $row_values_html - .= $GLOBALS['vertical_display']['data'][$row_no][$i]; + .= $this->_vertical_display['data'][$row_no][$i]; } - if (isset($GLOBALS['vertical_display']['rowdata'][$i][$row_no])) { - $GLOBALS['vertical_display']['rowdata'][$i][$row_no] - .= $GLOBALS['vertical_display']['data'][$row_no][$i]; + if (isset($this->_vertical_display['rowdata'][$i][$row_no])) { + $this->_vertical_display['rowdata'][$i][$row_no] + .= $this->_vertical_display['data'][$row_no][$i]; } else { - $GLOBALS['vertical_display']['rowdata'][$i][$row_no] - = $GLOBALS['vertical_display']['data'][$row_no][$i]; + $this->_vertical_display['rowdata'][$i][$row_no] + = $this->_vertical_display['data'][$row_no][$i]; } } // end for @@ -2639,11 +2647,11 @@ class PMA_DisplayResults $copy_url, $copy_str, $alternating_color_class, $condition_array ) { - if (! isset($GLOBALS['vertical_display']['edit'][$row_no])) { - $GLOBALS['vertical_display']['edit'][$row_no] = ''; - $GLOBALS['vertical_display']['copy'][$row_no] = ''; - $GLOBALS['vertical_display']['delete'][$row_no] = ''; - $GLOBALS['vertical_display']['row_delete'][$row_no] = ''; + if (! isset($this->_vertical_display['edit'][$row_no])) { + $this->_vertical_display['edit'][$row_no] = ''; + $this->_vertical_display['copy'][$row_no] = ''; + $this->_vertical_display['delete'][$row_no] = ''; + $this->_vertical_display['row_delete'][$row_no] = ''; } $vertical_class = ' row_' . $row_no; @@ -2659,7 +2667,7 @@ class PMA_DisplayResults && ($is_display['del_lnk'] != self::KILL_PROCESS) ) { - $GLOBALS['vertical_display']['row_delete'][$row_no] + $this->_vertical_display['row_delete'][$row_no] .= $this->_getCheckboxForMultiRowSubmissions( $del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, '[%_PMA_CHECKBOX_DIR_%]', @@ -2667,12 +2675,12 @@ class PMA_DisplayResults ); } else { - unset($GLOBALS['vertical_display']['row_delete'][$row_no]); + unset($this->_vertical_display['row_delete'][$row_no]); } if (isset($edit_url)) { - $GLOBALS['vertical_display']['edit'][$row_no] .= $this->_getEditLink( + $this->_vertical_display['edit'][$row_no] .= $this->_getEditLink( $edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, @@ -2681,18 +2689,18 @@ class PMA_DisplayResults ); } else { - unset($GLOBALS['vertical_display']['edit'][$row_no]); + unset($this->_vertical_display['edit'][$row_no]); } if (isset($copy_url)) { - $GLOBALS['vertical_display']['copy'][$row_no] .= $this->_getCopyLink( + $this->_vertical_display['copy'][$row_no] .= $this->_getCopyLink( $copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class ); } else { - unset($GLOBALS['vertical_display']['copy'][$row_no]); + unset($this->_vertical_display['copy'][$row_no]); } if (isset($del_url)) { @@ -2701,14 +2709,14 @@ class PMA_DisplayResults $js_conf = ''; } - $GLOBALS['vertical_display']['delete'][$row_no] + $this->_vertical_display['delete'][$row_no] .= $this->_getDeleteLink( $del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class ); } else { - unset($GLOBALS['vertical_display']['delete'][$row_no]); + unset($this->_vertical_display['delete'][$row_no]); } } // end of the '_gatherLinksForLaterOutputs()' function @@ -2755,6 +2763,8 @@ class PMA_DisplayResults /** * Get column order and column visibility + * + * @param array $analyzed_sql the analyzed query * * @return array 2 element array - $col_order, $col_visib * @@ -2762,10 +2772,10 @@ class PMA_DisplayResults * * @see _getTableBody() */ - private function _getColumnParams() + private function _getColumnParams($analyzed_sql) { - if ($this->_isSelect()) { - $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']); + if ($this->_isSelect($analyzed_sql)) { + $pmatable = new PMA_Table($this->_table, $this->_db); $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER); $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB); } else { @@ -3046,7 +3056,7 @@ class PMA_DisplayResults . $relation_class . ' ' . $hide_class . ' ' . $field_type_class; if (($_SESSION['tmp_user_values']['disp_direction'] == self::DISP_DIR_VERTICAL) - && (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) + && (! isset($this->_printview) || ($this->_printview != '1')) ) { // the row number corresponds to a data row, not HTML table row $class .= ' row_' . $row_no; @@ -3438,7 +3448,7 @@ class PMA_DisplayResults // so don't treat them as BINARY } elseif (stristr($field_flags, self::BINARY_FIELD) && ($meta->type == self::STRING_FIELD) - && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse']) + && !(isset($this->_is_analyse) && $this->_is_analyse) ) { if ($_SESSION['tmp_user_values']['display_binary']) { @@ -3513,6 +3523,8 @@ class PMA_DisplayResults /** * Get the resulted table with the vertical direction mode. + * + * @param array $analyzed_sql the analyzed query * * @return string html content * @@ -3520,16 +3532,16 @@ class PMA_DisplayResults * * @see _getTable() */ - private function _getVerticalTable() + private function _getVerticalTable($analyzed_sql) { $vertical_table_html = ''; // Prepares "multi row delete" link at top if required if (($GLOBALS['cfg']['RowActionLinks'] != self::POSITION_RIGHT) - && is_array($GLOBALS['vertical_display']['row_delete']) - && ((count($GLOBALS['vertical_display']['row_delete']) > 0) - || !empty($GLOBALS['vertical_display']['textbtn'])) + && is_array($this->_vertical_display['row_delete']) + && ((count($this->_vertical_display['row_delete']) > 0) + || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= '' . "\n"; @@ -3539,9 +3551,9 @@ class PMA_DisplayResults $vertical_table_html .= '' . "\n"; } - $vertical_table_html .= $GLOBALS['vertical_display']['textbtn'] + $vertical_table_html .= $this->_vertical_display['textbtn'] . $this->_getCheckBoxesForMultipleRowOperations( - $GLOBALS['vertical_display'], '_left' + $this->_vertical_display, '_left' ) . '' . "\n"; } // end if @@ -3549,43 +3561,43 @@ class PMA_DisplayResults // 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($this->_vertical_display['edit']) + && ((count($this->_vertical_display['edit']) > 0) + || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'edit' + $this->_vertical_display, '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($this->_vertical_display['copy']) + && ((count($this->_vertical_display['copy']) > 0) + || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'copy' + $this->_vertical_display, '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($this->_vertical_display['delete']) + && ((count($this->_vertical_display['delete']) > 0) + || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'delete' + $this->_vertical_display, '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 ($this->_vertical_display['desc'] AS $j => $val) { // assign appropriate key with current column order $key = $col_order ? $col_order[$j] : $j; @@ -3596,7 +3608,7 @@ class PMA_DisplayResults . $val; $cell_displayed = 0; - foreach ($GLOBALS['vertical_display']['rowdata'][$key] as $subval) { + foreach ($this->_vertical_display['rowdata'][$key] as $subval) { if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) @@ -3616,15 +3628,15 @@ 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($this->_vertical_display['row_delete']) + && ((count($this->_vertical_display['row_delete']) > 0) + || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= '' . "\n" - . $GLOBALS['vertical_display']['textbtn'] + . $this->_vertical_display['textbtn'] . $this->_getCheckBoxesForMultipleRowOperations( - $GLOBALS['vertical_display'], '_right' + $this->_vertical_display, '_right' ) . '' . "\n"; } // end if @@ -3632,36 +3644,36 @@ class PMA_DisplayResults // 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($this->_vertical_display['edit']) + && ((count($this->_vertical_display['edit']) > 0) + || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'edit' + $this->_vertical_display, '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($this->_vertical_display['copy']) + && ((count($this->_vertical_display['copy']) > 0) + || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'copy' + $this->_vertical_display, '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($this->_vertical_display['delete']) + && ((count($this->_vertical_display['delete']) > 0) + || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $GLOBALS['vertical_display'], 'delete' + $this->_vertical_display, 'delete' ); } @@ -3773,10 +3785,10 @@ class PMA_DisplayResults public function setConfigParamsForDisplayTable() { - $sql_md5 = md5($GLOBALS['sql_query']); + $sql_md5 = md5($this->_sql_query); $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] - = $GLOBALS['sql_query']; + = $this->_sql_query; $valid_disp_dir = PMA_isValid( $_REQUEST['disp_direction'], @@ -4012,6 +4024,31 @@ class PMA_DisplayResults public function getTable(&$dt_result, &$the_disp_mode, $analyzed_sql) { + // Initialize global variables which is not set in constructor + $this->_unlim_num_rows = $GLOBALS['unlim_num_rows']; + $this->_fields_meta = $GLOBALS['fields_meta']; + $this->_is_count = $GLOBALS['is_count']; + $this->_is_export = $GLOBALS['is_export']; + $this->_is_func = $GLOBALS['is_func']; + $this->_is_analyse = $GLOBALS['is_analyse']; + $this->_num_rows = $GLOBALS['num_rows']; + $this->_fields_cnt = $GLOBALS['fields_cnt']; + $this->_querytime = $GLOBALS['querytime']; + $this->_pma_theme_image = $GLOBALS['pmaThemeImage']; + $this->_text_dir = $GLOBALS['text_dir']; + $this->_is_maint = $GLOBALS['is_maint']; + $this->_is_explain = $GLOBALS['is_explain']; + $this->_is_show = $GLOBALS['is_show']; + if (isset ($GLOBALS['showtable'])) { + $this->_showtable = $GLOBALS['showtable']; + } + if (isset ($GLOBALS['printview'])) { + $this->_printview = $GLOBALS['printview']; + } + if (isset ($GLOBALS['url_query'])) { + $this->_url_query = $GLOBALS['url_query']; + } + $table_html = ''; // why was this called here? (already called from sql.php) @@ -4021,8 +4058,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($this->_showtable['Type']) + && $this->_showtable['Type'] == self::TABLE_TYPE_INNO_DB); if ($is_innodb && ! isset($analyzed_sql[0]['queryflags']['union']) @@ -4067,7 +4104,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'], + $dt_result, $this->_fields_meta, $this->_num_rows, $sort_expression_nodirection ); @@ -4079,7 +4116,7 @@ class PMA_DisplayResults $message = $this->_setMessageInformation( $sorted_column_message, - $analyzed_sql[0]['limit_clause'], $GLOBALS['unlim_num_rows'], + $analyzed_sql[0]['limit_clause'], $this->_unlim_num_rows, $total, $pos_next, $pre_count, $after_count ); @@ -4087,7 +4124,7 @@ class PMA_DisplayResults $message, $this->_sql_query, 'success' ); - } elseif (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) { + } elseif (! isset($this->_printview) || ($this->_printview != '1')) { $table_html .= $this->getCommonFunctions()->getMessage( __('Your SQL query has been executed successfully'), @@ -4104,7 +4141,7 @@ 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->_table = $this->_fields_meta[0]->table; } else { $this->_table = ''; } @@ -4113,7 +4150,7 @@ class PMA_DisplayResults $table_html .= $this->_getPlacedTableNavigatoins( $is_display, $analyzed_sql, $pos_next, $pos_prev, - self::PLACE_TOP_DIRECTION_DROPDOWN, "\n" + self::PLACE_TOP_DIRECTION_DROPDOWN, "\n", $is_innodb ); // 2b ----- Get field references from Database ----- @@ -4148,8 +4185,8 @@ class PMA_DisplayResults // 3. ----- Prepare the results table ----- $table_html .= $this->_getTableHeaders( - $is_display, $GLOBALS['fields_meta'], - $GLOBALS['fields_cnt'], $analyzed_sql, $sort_expression, + $is_display, $this->_fields_meta, + $this->_fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction ) . '' . "\n"; @@ -4161,10 +4198,10 @@ 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']); + unset($this->_vertical_display); $table_html .= '' . "\n" . ''; @@ -4175,8 +4212,8 @@ 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, $this->_fields_cnt, $this->_fields_meta, + $this->_num_rows, $analyzed_sql, $is_display['del_lnk'] ); } @@ -4185,11 +4222,11 @@ class PMA_DisplayResults $table_html .= $this->_getPlacedTableNavigatoins( $is_display, $analyzed_sql, $pos_next, $pos_prev, - self::PLACE_BOTTOM_DIRECTION_DROPDOWN, '
' . "\n" + self::PLACE_BOTTOM_DIRECTION_DROPDOWN, '
' . "\n", $is_innodb ); // 6. ----- Prepare "Query results operations" - if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { + if (! isset($this->_printview) || $this->_printview != '1') { $table_html .= $this->_getResultsOperations( $the_disp_mode, $analyzed_sql ); @@ -4499,7 +4536,7 @@ class PMA_DisplayResults } $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec') . ')'); - $messagge_qt->addParam($GLOBALS['querytime']); + $messagge_qt->addParam($this->_querytime); $message->addMessage($messagge_qt, ''); if (! is_null($sorted_column_message)) { @@ -4592,8 +4629,8 @@ class PMA_DisplayResults if ($_SESSION['tmp_user_values']['disp_direction'] != self::DISP_DIR_VERTICAL) { $links_html .= '' . __('With selected:') . ''; } @@ -4624,9 +4661,9 @@ class PMA_DisplayResults $links_html .= '' . "\n"; - if (! empty($GLOBALS['url_query'])) { + if (! empty($this->_url_query)) { $links_html .= '' . "\n"; + .' value="' . $this->_url_query . '" />' . "\n"; } // fetch last row of the result set @@ -4662,6 +4699,7 @@ class PMA_DisplayResults * @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 * @@ -4670,7 +4708,8 @@ class PMA_DisplayResults * @see _getTable() */ private function _getPlacedTableNavigatoins( - $is_display, $analyzed_sql, $pos_next, $pos_prev, $place, $empty_line + $is_display, $analyzed_sql, $pos_next, $pos_prev + , $place, $empty_line, $is_innodb ) { $navigation_html = ''; @@ -4684,14 +4723,14 @@ class PMA_DisplayResults } $navigation_html .= $this->_getTableNavigation( - $pos_next, $pos_prev, 'top_direction_dropdown' + $pos_next, $pos_prev, 'top_direction_dropdown', $is_innodb ); if ($place == self::PLACE_TOP_DIRECTION_DROPDOWN) { $navigation_html .= "\n"; } - } elseif (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) { + } elseif (! isset($this->_printview) || ($this->_printview != '1')) { $navigation_html .= "\n" . '

' . "\n"; } @@ -4790,7 +4829,7 @@ class PMA_DisplayResults $header_shown = true; } - $_url_params['unlim_num_rows'] = $GLOBALS['unlim_num_rows']; + $_url_params['unlim_num_rows'] = $this->_unlim_num_rows; /** * At this point we don't know the table name; this can happen @@ -4830,7 +4869,7 @@ class PMA_DisplayResults // prepare GIS chart $geometry_found = false; // If atleast one geometry field is found - foreach ($GLOBALS['fields_meta'] as $meta) { + foreach ($this->_fields_meta as $meta) { if ($meta->type == self::GEOMETRY_FIELD) { $geometry_found = true; break; @@ -5073,7 +5112,7 @@ class PMA_DisplayResults $dispval = ''; } // end if... else... - if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { + if (isset($this->_printview) && $this->_printview == '1') { $result .= ($transformation_plugin != $default_function ? $transformation_plugin->applyTransformation( From f37304b8e03ff19a44b31ea12349f689b9f1e88a Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Sat, 7 Jul 2012 11:06:20 +0530 Subject: [PATCH 6/9] Use class varables without passing them to functions in PMA_DisplayResults class --- libraries/DisplayResults.class.php | 228 ++++++++++++++++------------- 1 file changed, 130 insertions(+), 98 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index f8425799f0..c44d4bbad2 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -66,14 +66,83 @@ class PMA_DisplayResults const ALL_ROWS = 'all'; const QUERY_TYPE_SELECT = 'SELECT'; - + /** PMA_CommonFunctions object */ private $_common_functions; - private $_db, $_table, $_goto, $_sql_query; - private $_unlim_num_rows, $_fields_meta, $_is_count, $_is_export, $_is_func, - $_is_analyse, $_num_rows, $_showtable, $_highlight_columns, - $_vertical_display, $_fields_cnt, $_printview, $_querytime, - $_pma_theme_image, $_text_dir, $_url_query, $_is_maint, $_is_explain, - $_is_show, $_mime_map; + + /** 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; /** @@ -494,8 +563,7 @@ class PMA_DisplayResults $table_navigation_html .= $this->_getMoveForwardButtonsForTableNavigation( - $html_sql_query, $pos_next, $is_innodb, - $this->_unlim_num_rows, $this->_num_rows + $html_sql_query, $pos_next, $is_innodb ); } // end move toward @@ -555,8 +623,7 @@ class PMA_DisplayResults ); $table_navigation_html .= $this->_getAdditionalFieldsForTableNavigation( - $html_sql_query, $pos_next, - $this->_unlim_num_rows, $id_for_direction_dropdown + $html_sql_query, $pos_next, $id_for_direction_dropdown ); $table_navigation_html .= '' @@ -629,8 +696,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 * @@ -639,7 +704,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 @@ -651,7 +716,7 @@ class PMA_DisplayResults ); // prepare some options for the End button - if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) { + if ($is_innodb && $this->_unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) { $input_for_real_end = ''; // no backquote around this message @@ -662,8 +727,8 @@ 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->_unlim_num_rows + && $this->_num_rows >= $_SESSION['tmp_user_values']['max_rows']) ? 'true' : 'false' . '"'; @@ -671,7 +736,7 @@ class PMA_DisplayResults $buttons_html .= $this->_getTableNavigationButton( '>>', _pgettext('Last page', 'End'), - @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) + @((ceil($this->_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 ); @@ -688,10 +753,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 @@ -701,8 +762,7 @@ 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 = ''; @@ -715,7 +775,7 @@ class PMA_DisplayResults . ' value="' . __('Show') . ' :" />' . __('Start row') . ': ' . "\n" . '' . __('Number of rows') . ': ' . "\n" . '' . "\n" . $order_link . $comments . ' ' . "\n"; } else { // 2.2 Results can't be sorted @@ -913,16 +969,16 @@ class PMA_DisplayResults $table_headers_html .= $this->_getDraggableClassForNonSortableColumns( $col_visib, $col_visib[$j], $condition_field, - $direction, $fields_meta[$i], $comments + $direction, $this->_fields_meta[$i], $comments ); } $this->_vertical_display['desc'][] = ' ' . "\n" . ' ' - . htmlspecialchars($fields_meta[$i]->name) + . htmlspecialchars($this->_fields_meta[$i]->name) . "\n" . $comments . ' '; } // end else (2.2) } // end for @@ -1093,8 +1149,6 @@ class PMA_DisplayResults * @param boolean $directionCondition display direction horizontal or * horizontalflipped * @param array &$is_display which elements to display - * @param integer $fields_cnt the total number of fields - * returned by the SQL query * @param string $full_or_partial_text_link full/partial link or text button * * @return array 3 element array - $colspan, $rowspan, $button_html @@ -1104,7 +1158,7 @@ class PMA_DisplayResults * @see _getTableHeaders() */ private function _getFeildVisibilityParams( - $directionCondition, &$is_display, $fields_cnt, $full_or_partial_text_link + $directionCondition, &$is_display, $full_or_partial_text_link ) { $button_html = ''; @@ -1139,7 +1193,7 @@ class PMA_DisplayResults if ($directionCondition) { - $button_html .= '' + $button_html .= '' . '' . ''; @@ -3553,7 +3607,7 @@ class PMA_DisplayResults $vertical_table_html .= $this->_vertical_display['textbtn'] . $this->_getCheckBoxesForMultipleRowOperations( - $this->_vertical_display, '_left' + '_left' ) . '' . "\n"; } // end if @@ -3566,7 +3620,7 @@ class PMA_DisplayResults || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $this->_vertical_display, 'edit' + 'edit' ); } // end if @@ -3578,7 +3632,7 @@ class PMA_DisplayResults || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $this->_vertical_display, 'copy' + 'copy' ); } // end if @@ -3590,7 +3644,7 @@ class PMA_DisplayResults || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $this->_vertical_display, 'delete' + 'delete' ); } // end if @@ -3635,9 +3689,7 @@ class PMA_DisplayResults $vertical_table_html .= '' . "\n" . $this->_vertical_display['textbtn'] - . $this->_getCheckBoxesForMultipleRowOperations( - $this->_vertical_display, '_right' - ) + . $this->_getCheckBoxesForMultipleRowOperations('_right') . '' . "\n"; } // end if @@ -3649,7 +3701,7 @@ class PMA_DisplayResults || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $this->_vertical_display, 'edit' + 'edit' ); } // end if @@ -3661,7 +3713,7 @@ class PMA_DisplayResults || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $this->_vertical_display, 'copy' + 'copy' ); } // end if @@ -3673,7 +3725,7 @@ class PMA_DisplayResults || !empty($this->_vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( - $this->_vertical_display, 'delete' + 'delete' ); } @@ -3685,7 +3737,6 @@ 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 * * @return string $links_html html content @@ -3694,26 +3745,24 @@ class PMA_DisplayResults * * @see _getVerticalTable() */ - private function _getOperationLinksForVerticleTable( - $vertical_display, $operation - ) { + private function _getOperationLinksForVerticleTable($operation) { $link_html = '' . "\n"; - if (! is_array($vertical_display['row_delete'])) { + if (! is_array($this->_vertical_display['row_delete'])) { if (($operation == 'edit') || ($operation == 'copy')) { - $link_html .= $vertical_display['textbtn']; + $link_html .= $this->_vertical_display['textbtn']; } elseif ($operation == 'delete') { - if (! is_array($vertical_display['edit'])) { - $link_html .= $vertical_display['textbtn']; + if (! is_array($this->_vertical_display['edit'])) { + $link_html .= $this->_vertical_display['textbtn']; } } } - foreach ($vertical_display[$operation] as $val) { + foreach ($this->_vertical_display[$operation] as $val) { $link_html .= $val; } // end while @@ -3727,7 +3776,6 @@ class PMA_DisplayResults /** * Get checkboxes for multiple row data operations * - * @param array $vertical_display the information to display * @param string $dir _left / _right * * @return $checkBoxes_html html content @@ -3736,13 +3784,13 @@ class PMA_DisplayResults * * @see _getVerticalTable() */ - private function _getCheckBoxesForMultipleRowOperations($vertical_display, $dir) + private function _getCheckBoxesForMultipleRowOperations($dir) { $checkBoxes_html = ''; $cell_displayed = 0; - foreach ($vertical_display['row_delete'] as $val) { + foreach ($this->_vertical_display['row_delete'] as $val) { if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) @@ -4104,8 +4152,7 @@ class PMA_DisplayResults // 1.4 Prepares display of first and last value of the sorted column $sorted_column_message = $this->_getSortedColumnMessage( - $dt_result, $this->_fields_meta, $this->_num_rows, - $sort_expression_nodirection + $dt_result, $sort_expression_nodirection ); @@ -4115,8 +4162,7 @@ class PMA_DisplayResults if (($is_display['nav_bar'] == '1') && isset($pos_next)) { $message = $this->_setMessageInformation( - $sorted_column_message, - $analyzed_sql[0]['limit_clause'], $this->_unlim_num_rows, + $sorted_column_message, $analyzed_sql[0]['limit_clause'], $total, $pos_next, $pre_count, $after_count ); @@ -4185,8 +4231,7 @@ class PMA_DisplayResults // 3. ----- Prepare the results table ----- $table_html .= $this->_getTableHeaders( - $is_display, $this->_fields_meta, - $this->_fields_cnt, $analyzed_sql, $sort_expression, + $is_display, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction ) . '' . "\n"; @@ -4212,8 +4257,7 @@ class PMA_DisplayResults ) { $table_html .= $this->_getMultiRowOperationLinks( - $dt_result, $this->_fields_cnt, $this->_fields_meta, - $this->_num_rows, $analyzed_sql, $is_display['del_lnk'] + $dt_result, $analyzed_sql, $is_display['del_lnk'] ); } @@ -4321,9 +4365,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 @@ -4334,7 +4375,7 @@ class PMA_DisplayResults * @see getTable() */ private function _getSortedColumnMessage( - &$dt_result, $fields_meta, $num_rows, $sort_expression_nodirection + &$dt_result, $sort_expression_nodirection ) { if (! empty($sort_expression_nodirection)) { @@ -4354,7 +4395,7 @@ class PMA_DisplayResults // (this might be a multi-table query) $sorted_column_index = false; - foreach ($fields_meta as $key => $meta) { + foreach ($this->_fields_meta as $key => $meta) { if (($meta->table == $sort_table) && ($meta->name == $sort_column)) { $sorted_column_index = $key; break; @@ -4372,7 +4413,7 @@ class PMA_DisplayResults $transform_options = array(); // check for non printable sorted row data - $meta = $fields_meta[$sorted_column_index]; + $meta = $this->_fields_meta[$sorted_column_index]; if (stristr($meta->type, self::BLOB_FIELD) || ($meta->type == self::GEOMETRY_FIELD) @@ -4393,11 +4434,11 @@ 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->_num_rows - 1); $row = PMA_DBI_fetch_row($dt_result); // check for non printable sorted row data - $meta = $fields_meta[$sorted_column_index]; + $meta = $this->_fields_meta[$sorted_column_index]; if (stristr($meta->type, self::BLOB_FIELD) || ($meta->type == self::GEOMETRY_FIELD) ) { @@ -4436,9 +4477,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 @@ -4453,12 +4491,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 ) { - if (isset($unlim_num_rows) && ($unlim_num_rows != $total)) { - $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query'); + if (isset($this->_unlim_num_rows) && ($this->_unlim_num_rows != $total)) { + $selectstring = ', ' . $this->_unlim_num_rows . ' ' . __('in query'); } else { $selectstring = ''; } @@ -4597,11 +4635,6 @@ class PMA_DisplayResults * * @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' * @@ -4612,8 +4645,7 @@ 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 = ''; @@ -4667,14 +4699,14 @@ 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->_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->_fields_cnt, $this->_fields_meta, $row ); // reset to first row for the loop in _getTableBody() From 3a66d4862c497f6422ad52a239b25d338c4366ba Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Sun, 8 Jul 2012 15:16:00 +0530 Subject: [PATCH 7/9] Add get set magic methods for PMA_DisplayResults class --- libraries/DisplayResults.class.php | 641 +++++++++++++++++------------ 1 file changed, 380 insertions(+), 261 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index c44d4bbad2..4424c54472 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'; @@ -66,6 +67,8 @@ class PMA_DisplayResults const ALL_ROWS = 'all'; const QUERY_TYPE_SELECT = 'SELECT'; + + // Declare global fields /** PMA_CommonFunctions object */ private $_common_functions; @@ -145,6 +148,40 @@ class PMA_DisplayResults private $_mime_map; + /** + * 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 (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 + * + * @return PMA_DisplayResults + */ + public function __set($property, $value) { + + if (property_exists($this, $property)) { + $this->$property = $value; + } + + return $this; + + } + + /** * Set CommmonFunctions * @@ -170,8 +207,8 @@ class PMA_DisplayResults } return $this->_common_functions; } + - /** * Constructor for PMA_DisplayResults class * @@ -184,10 +221,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); } @@ -226,6 +263,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]; @@ -240,7 +285,8 @@ class PMA_DisplayResults // 2. Display mode is not "false for all elements" -> updates the // display mode if ($the_disp_mode != 'nnnn000000') { - if (isset($this->_printview) && $this->_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 @@ -250,8 +296,9 @@ class PMA_DisplayResults $do_display['bkm_form'] = (string) '0'; $do_display['text_btn'] = (string) '0'; $do_display['pview_lnk'] = (string) '0'; - } elseif ($this->_is_count || $this->_is_analyse - || $this->_is_maint || $this->_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 @@ -262,14 +309,15 @@ class PMA_DisplayResults $do_display['nav_bar'] = (string) '0'; $do_display['ins_row'] = (string) '0'; $do_display['bkm_form'] = (string) '1'; - if ($this->_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 ($this->_is_show) { + } elseif ($this->__get ('_is_show')) { // 2.2 Statement is a "SHOW..." /** * 2.2.1 @@ -279,7 +327,7 @@ class PMA_DisplayResults '@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?' . 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS' . ')@i', - $this->_sql_query, $which + $this->__get('_sql_query'), $which ); if (isset($which[1]) && (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) @@ -302,21 +350,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 = $this->_fields_meta[0]->table; + $prev_table = $fields_meta[0]->table; $do_display['text_btn'] = (string) '1'; - for ($i = 0; $i < $this->_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 - && (($this->_fields_meta[$i]->table == '') - || ($this->_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; @@ -331,21 +383,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 = $this->_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($this->_unlim_num_rows) && $this->_unlim_num_rows != '') { - $the_total = $this->_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 @@ -357,9 +411,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($this->_unlim_num_rows) - && $this->_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'; @@ -389,8 +443,8 @@ class PMA_DisplayResults */ private function _isSelect($analyzed_sql) { - return ! ($this->_is_count || $this->_is_export - || $this->_is_func || $this->_is_analyse) + 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); @@ -436,11 +490,11 @@ 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 */ - $is_innodb = (isset($this->_showtable['Type']) - && $this->_showtable['Type'] == self::TABLE_TYPE_INNO_DB); + $is_innodb = (isset($showtable['Type']) + && $showtable['Type'] == self::TABLE_TYPE_INNO_DB); // Navigation bar $table_navigation_html .= '' @@ -510,7 +565,7 @@ class PMA_DisplayResults ) + 1; $nbTotalPage = @ceil( - $this->_unlim_num_rows + $this->__get('_unlim_num_rows') / $_SESSION['tmp_user_values']['max_rows'] ); @@ -518,10 +573,10 @@ class PMA_DisplayResults $table_navigation_html .= ''; @@ -716,7 +771,7 @@ class PMA_DisplayResults ); // prepare some options for the End button - if ($is_innodb && $this->_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 @@ -727,8 +782,8 @@ class PMA_DisplayResults $onsubmit = 'onsubmit="return ' . ($_SESSION['tmp_user_values']['pos'] - + $_SESSION['tmp_user_values']['max_rows'] < $this->_unlim_num_rows - && $this->_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' . '"'; @@ -736,7 +791,7 @@ class PMA_DisplayResults $buttons_html .= $this->_getTableNavigationButton( '>>', _pgettext('Last page', 'End'), - @((ceil($this->_unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) + @((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 ); @@ -769,13 +824,13 @@ class PMA_DisplayResults $additional_fields_html .= '' - . '' + . '' . '' . __('Start row') . ': ' . "\n" . '' . __('Number of rows') . ': ' . "\n" . '_sql_query); + $sql_md5 = md5($this->__get('_sql_query')); $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows']; @@ -869,7 +930,7 @@ class PMA_DisplayResults $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 @@ -877,12 +938,14 @@ class PMA_DisplayResults $table_headers_html .= $this->_getDataForResettingColumnOrder(); } - $this->_vertical_display['emptypre'] = 0; - $this->_vertical_display['emptyafter'] = 0; - $this->_vertical_display['textbtn'] = ''; + $vertical_display['emptypre'] = 0; + $vertical_display['emptyafter'] = 0; + $vertical_display['textbtn'] = ''; + $this->__set('_vertical_display', $vertical_display); + // Display options (if we are not in print view) - if (! (isset($this->_printview) && ($this->_printview == '1'))) { + if (! (isset($printview) && ($printview == '1'))) { $table_headers_html .= $this->_getOptionsBlock(); @@ -920,7 +983,7 @@ class PMA_DisplayResults && ! $_SESSION['tmp_user_values']['hide_transformation'] ) { include_once './libraries/transformations.lib.php'; - $this->_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. @@ -929,26 +992,28 @@ class PMA_DisplayResults list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); - for ($j = 0; $j < $this->_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($this->_highlight_columns[$this->_fields_meta[$i]->name]) - || isset($this->_highlight_columns[$this->getCommonFunctions()->backquote($this->_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, $this->_fields_meta[$i]); + $comments = $this->_getCommentForRow($comments_map, $fields_meta[$i]); + + $vertical_display = $this->__get('_vertical_display'); if ($is_display['sort_lnk'] == '1') { list($order_link, $sorted_headrer_html) = $this->_getOrderLinkAndSortedHeaderHtml( - $this->_fields_meta[$i], $sort_expression, + $fields_meta[$i], $sort_expression, $sort_expression_nodirection, $i, $unsorted_sql_query, $session_max_rows, $direction, $comments, $sort_direction, $directionCondition, $col_visib, @@ -957,10 +1022,10 @@ class PMA_DisplayResults $table_headers_html .= $sorted_headrer_html; - $this->_vertical_display['desc'][] = ' ' . "\n"; } else { // 2.2 Results can't be sorted @@ -969,18 +1034,21 @@ class PMA_DisplayResults $table_headers_html .= $this->_getDraggableClassForNonSortableColumns( $col_visib, $col_visib[$j], $condition_field, - $direction, $this->_fields_meta[$i], $comments + $direction, $fields_meta[$i], $comments ); } - $this->_vertical_display['desc'][] = ' '; } // end else (2.2) + + $this->__set('_vertical_display', $vertical_display); + } // end for // Display column at rightside - checkboxes or empty column @@ -1018,7 +1086,7 @@ class PMA_DisplayResults $drop_down_html = ''; // Just as fallback - $unsorted_sql_query = $this->_sql_query; + $unsorted_sql_query = $this->__get('_sql_query'); if (isset($analyzed_sql[0]['unsorted_query'])) { $unsorted_sql_query = $analyzed_sql[0]['unsorted_query']; } @@ -1037,7 +1105,7 @@ class PMA_DisplayResults ) { // grab indexes data: - $indexes = PMA_Index::getFromTable($this->_table, $this->_db); + $indexes = PMA_Index::getFromTable($this->__get('_table'), $this->__get('_db')); // do we have any index? if ($indexes) { @@ -1073,7 +1141,7 @@ 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') . ': ' + $button_html .= '' . '' . ''; // end horizontal/horizontalflipped mode } else { - $span = $this->_num_rows + 1 + floor( - $this->_num_rows + $span = $this->__get('_num_rows') + 1 + floor( + $this->__get('_num_rows') / $_SESSION['tmp_user_values']['repeat_cells'] ); $button_html .= ''; @@ -1215,7 +1284,7 @@ class PMA_DisplayResults // ... at the left column of the result table header if possible // and required - $this->_vertical_display['emptypre'] + $vertical_display['emptypre'] = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; @@ -1227,7 +1296,7 @@ class PMA_DisplayResults } else { - $this->_vertical_display['textbtn'] + $vertical_display['textbtn'] = ' ' . "\n"; @@ -1240,7 +1309,7 @@ class PMA_DisplayResults ) { // ... elseif no button, displays empty(ies) col(s) if required - $this->_vertical_display['emptypre'] + $vertical_display['emptypre'] = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 0; @@ -1250,7 +1319,7 @@ class PMA_DisplayResults // end horizontal/horizontalfipped mode } else { - $this->_vertical_display['textbtn'] = ' ' . "\n"; } // end vertical mode @@ -1262,6 +1331,8 @@ class PMA_DisplayResults $button_html .= ''; } + $this->__set('_vertical_display', $vertical_display); + return array($colspan, $rowspan, $button_html); } // end of the '_getFeildVisibilityParams()' function @@ -1293,7 +1364,7 @@ class PMA_DisplayResults 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); + $comments_map[$tb] = PMA_getComments($this->__get('_db'), $tb); unset($tb); } } @@ -1318,7 +1389,7 @@ class PMA_DisplayResults private function _setHighlightedColumnGlobalField($analyzed_sql) { - $this->_highlight_columns = array(); + $highlight_columns = array(); if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['where_clause_identifiers']) ) { @@ -1330,11 +1401,13 @@ class PMA_DisplayResults foreach ($analyzed_sql[0]['where_clause_identifiers'] as $wci_nr => $wci ) { - $this->_highlight_columns[$wci] = 'true'; + $highlight_columns[$wci] = 'true'; } } } + $this->__set('_highlight_columns', $highlight_columns); + } // end of the '_setHighlightedColumnGlobalField()' function @@ -1353,7 +1426,7 @@ class PMA_DisplayResults $data_html = ''; // generate the column order, if it is set - $pmatable = new PMA_Table($this->_table, $this->_db); + $pmatable = new PMA_Table($this->__get('_table'), $this->__get('_db')); $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER); if ($col_order) { @@ -1369,10 +1442,10 @@ class PMA_DisplayResults } // generate table create time - if (! PMA_Table::isView($this->_db, $this->_table)) { + if (! PMA_Table::isView($this->__get('_db'), $this->__get('_table'))) { $data_html .= ''; } @@ -1405,10 +1478,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 ); @@ -1517,20 +1590,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 = $this->_pma_theme_image . '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 = $this->_pma_theme_image . '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; } @@ -1572,7 +1645,7 @@ 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"; } @@ -1721,8 +1794,8 @@ class PMA_DisplayResults } $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), 'sql_query' => $sorted_sql_query, 'session_max_rows' => $session_max_rows ); @@ -2080,6 +2153,7 @@ class PMA_DisplayResults ) { $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... @@ -2090,7 +2164,7 @@ class PMA_DisplayResults && ($is_display['text_btn'] == '1') ) { - $this->_vertical_display['emptyafter'] + $vertical_display['emptyafter'] = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 1; @@ -2101,7 +2175,7 @@ class PMA_DisplayResults // end horizontal/horizontalflipped mode } else { - $this->_vertical_display['textbtn'] = ' ' . "\n"; @@ -2115,7 +2189,7 @@ class PMA_DisplayResults // ... elseif no button, displays empty columns if required // (unless coming from Browse mode print view) - $this->_vertical_display['emptyafter'] + $vertical_display['emptyafter'] = (($is_display['edit_lnk'] != self::NO_EDIT_OR_DELETE) && ($is_display['del_lnk'] != self::NO_EDIT_OR_DELETE)) ? 4 : 1; @@ -2125,11 +2199,13 @@ class PMA_DisplayResults // end horizontal/horizontalflipped mode } else { - $this->_vertical_display['textbtn'] = ' ' . "\n"; } // end vertical mode } + $this->__set('_vertical_display', $vertical_display); + return $right_column_html; } // end of the '_getColumnAtRightSide()' function @@ -2290,17 +2366,20 @@ class PMA_DisplayResults // query without conditions to shorten URLs when needed, 200 is just // 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; - $this->_vertical_display['edit'] = array(); - $this->_vertical_display['copy'] = array(); - $this->_vertical_display['delete'] = array(); - $this->_vertical_display['data'] = array(); - $this->_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'; @@ -2330,7 +2409,7 @@ class PMA_DisplayResults // "vertical display" mode stuff $table_body_html .= $this->_getVerticalDisplaySupportSegments( - $this->_vertical_display, $row_no, $directionCondition + $vertical_display, $row_no, $directionCondition ); $alternating_color_class = ($odd_row ? 'odd' : 'even'); @@ -2351,7 +2430,7 @@ class PMA_DisplayResults */ list($where_clause, $clause_is_unique, $condition_array) = $this->getCommonFunctions()->getUniqueCondition( - $dt_result, $this->_fields_cnt, $this->_fields_meta, $row + $dt_result, $this->__get('_fields_cnt'), $this->__get('_fields_meta'), $row ); $where_clause_html = urlencode($where_clause); @@ -2497,12 +2576,19 @@ class PMA_DisplayResults $row_values_html = ''; - for ($j = 0; $j < $this->_fields_cnt; ++$j) { + // Following variable are needed for use in isset/empty or + // use with array indexes/safe use in foreach + $sql_query = $this->__get('_sql_query'); + $fields_meta = $this->__get('_fields_meta'); + $highlight_columns = $this->__get('_highlight_columns'); + $mime_map = $this->__get('_mime_map'); + + for ($j = 0; $j < $this->__get('_fields_cnt'); ++$j) { // assign $i with appropriate column order $i = $col_order ? $col_order[$j] : $j; - $meta = $this->_fields_meta[$i]; + $meta = $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] @@ -2527,9 +2613,9 @@ class PMA_DisplayResults // See if this column should get highlight because it's used in the // where-query. - $condition_field = (isset($this->_highlight_columns) - && (isset($this->_highlight_columns[$meta->name]) - || isset($this->_highlight_columns[$this->getCommonFunctions()->backquote($meta->name)]))) + $condition_field = (isset($highlight_columns) + && (isset($highlight_columns[$meta->name]) + || isset($highlight_columns[$this->getCommonFunctions()->backquote($meta->name)]))) ? true : false; @@ -2542,12 +2628,12 @@ class PMA_DisplayResults && $GLOBALS['cfg']['BrowseMIME'] ) { - if (isset($this->_mime_map[$meta->name]['mimetype']) - && isset($this->_mime_map[$meta->name]['transformation']) - && !empty($this->_mime_map[$meta->name]['transformation']) + if (isset($mime_map[$meta->name]['mimetype']) + && isset($mime_map[$meta->name]['transformation']) + && !empty($mime_map[$meta->name]['transformation']) ) { - $file = $this->_mime_map[$meta->name]['transformation']; + $file = $mime_map[$meta->name]['transformation']; $include_file = 'libraries/plugins/transformations/' . $file; if (file_exists($include_file)) { @@ -2561,17 +2647,17 @@ class PMA_DisplayResults ); $transform_options = PMA_transformation_getOptions( - isset($this->_mime_map[$meta->name] + isset($mime_map[$meta->name] ['transformation_options'] ) - ? $this->_mime_map[$meta->name] + ? $mime_map[$meta->name] ['transformation_options'] : '' ); $meta->mimetype = str_replace( '_', '/', - $this->_mime_map[$meta->name]['mimetype'] + $mime_map[$meta->name]['mimetype'] ); } // end if file_exists @@ -2579,19 +2665,21 @@ class PMA_DisplayResults } // end if mime/transformation works. $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), 'where_clause' => $where_clause, 'transform_key' => $meta->name, ); - if (! empty($this->_sql_query)) { + if (! empty($sql_query)) { $_url_params['sql_query'] = $url_sql_query; } $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params); + $vertical_display = $this->__get('_vertical_display'); + if ($meta->numeric == 1) { // n u m e r i c @@ -2600,7 +2688,7 @@ class PMA_DisplayResults // will show both fields NULL even if only one is NULL, // so use the $pointer - $this->_vertical_display['data'][$row_no][$i] + $vertical_display['data'][$row_no][$i] = $this->_getDataCellForNumericColumns( $row[$i], $class, $condition_field, $meta, $map, $is_field_truncated, $analyzed_sql, @@ -2615,7 +2703,7 @@ class PMA_DisplayResults // TEXT fields type so we have to ensure it's really a BLOB $field_flags = PMA_DBI_field_flags($dt_result, $i); - $this->_vertical_display['data'][$row_no][$i] + $vertical_display['data'][$row_no][$i] = $this->_getDataCellForBlobColumns( $row[$i], $class, $meta, $_url_params, $field_flags, $transformation_plugin, $default_function, @@ -2629,7 +2717,7 @@ class PMA_DisplayResults // inline-edit geometry data. $class = str_replace('grid_edit', '', $class); - $this->_vertical_display['data'][$row_no][$i] + $vertical_display['data'][$row_no][$i] = $this->_getDataCellForGeometryColumns( $row[$i], $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, @@ -2640,7 +2728,7 @@ class PMA_DisplayResults } else { // n o t n u m e r i c a n d n o t B L O B - $this->_vertical_display['data'][$row_no][$i] + $vertical_display['data'][$row_no][$i] = $this->_getDataCellForNonNumericAndNonBlobColumns( $row[$i], $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, @@ -2653,16 +2741,19 @@ class PMA_DisplayResults // output stored cell if ($directionCondition) { $row_values_html - .= $this->_vertical_display['data'][$row_no][$i]; + .= $vertical_display['data'][$row_no][$i]; } - if (isset($this->_vertical_display['rowdata'][$i][$row_no])) { - $this->_vertical_display['rowdata'][$i][$row_no] - .= $this->_vertical_display['data'][$row_no][$i]; + if (isset($vertical_display['rowdata'][$i][$row_no])) { + $vertical_display['rowdata'][$i][$row_no] + .= $vertical_display['data'][$row_no][$i]; } else { - $this->_vertical_display['rowdata'][$i][$row_no] - = $this->_vertical_display['data'][$row_no][$i]; + $vertical_display['rowdata'][$i][$row_no] + = $vertical_display['data'][$row_no][$i]; } + + $this->__set('_vertical_display', $vertical_display); + } // end for return $row_values_html; @@ -2701,11 +2792,13 @@ class PMA_DisplayResults $copy_url, $copy_str, $alternating_color_class, $condition_array ) { - if (! isset($this->_vertical_display['edit'][$row_no])) { - $this->_vertical_display['edit'][$row_no] = ''; - $this->_vertical_display['copy'][$row_no] = ''; - $this->_vertical_display['delete'][$row_no] = ''; - $this->_vertical_display['row_delete'][$row_no] = ''; + $vertical_display = $this->__get('_vertical_display'); + + if (! isset($vertical_display['edit'][$row_no])) { + $vertical_display['edit'][$row_no] = ''; + $vertical_display['copy'][$row_no] = ''; + $vertical_display['delete'][$row_no] = ''; + $vertical_display['row_delete'][$row_no] = ''; } $vertical_class = ' row_' . $row_no; @@ -2721,7 +2814,7 @@ class PMA_DisplayResults && ($is_display['del_lnk'] != self::KILL_PROCESS) ) { - $this->_vertical_display['row_delete'][$row_no] + $vertical_display['row_delete'][$row_no] .= $this->_getCheckboxForMultiRowSubmissions( $del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, '[%_PMA_CHECKBOX_DIR_%]', @@ -2729,12 +2822,12 @@ class PMA_DisplayResults ); } else { - unset($this->_vertical_display['row_delete'][$row_no]); + unset($vertical_display['row_delete'][$row_no]); } if (isset($edit_url)) { - $this->_vertical_display['edit'][$row_no] .= $this->_getEditLink( + $vertical_display['edit'][$row_no] .= $this->_getEditLink( $edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, @@ -2743,18 +2836,18 @@ class PMA_DisplayResults ); } else { - unset($this->_vertical_display['edit'][$row_no]); + unset($vertical_display['edit'][$row_no]); } if (isset($copy_url)) { - $this->_vertical_display['copy'][$row_no] .= $this->_getCopyLink( + $vertical_display['copy'][$row_no] .= $this->_getCopyLink( $copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class ); } else { - unset($this->_vertical_display['copy'][$row_no]); + unset($vertical_display['copy'][$row_no]); } if (isset($del_url)) { @@ -2763,16 +2856,18 @@ class PMA_DisplayResults $js_conf = ''; } - $this->_vertical_display['delete'][$row_no] + $vertical_display['delete'][$row_no] .= $this->_getDeleteLink( $del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class ); } else { - unset($this->_vertical_display['delete'][$row_no]); + unset($vertical_display['delete'][$row_no]); } + $this->__set('_vertical_display', $vertical_display); + } // end of the '_gatherLinksForLaterOutputs()' function @@ -2794,7 +2889,7 @@ class PMA_DisplayResults && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['querytype']) && ($analyzed_sql[0]['querytype'] == self::QUERY_TYPE_SELECT) - && (strlen($this->_sql_query) > 200) + && (strlen($this->__get('_sql_query')) > 200) ) { $url_sql_query = 'SELECT '; @@ -2810,7 +2905,7 @@ class PMA_DisplayResults return $url_sql_query; } - return $this->_sql_query; + return $this->__get('_sql_query'); } // end of the '_getUrlSqlQuery()' function @@ -2829,7 +2924,7 @@ class PMA_DisplayResults private function _getColumnParams($analyzed_sql) { if ($this->_isSelect($analyzed_sql)) { - $pmatable = new PMA_Table($this->_table, $this->_db); + $pmatable = new PMA_Table($this->__get('_table'), $this->__get('_db')); $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER); $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB); } else { @@ -2915,8 +3010,8 @@ class PMA_DisplayResults ) { $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), 'where_clause' => $where_clause, 'clause_is_unique' => $clause_is_unique, 'sql_query' => $url_sql_query, @@ -2970,35 +3065,37 @@ class PMA_DisplayResults $where_clause, $clause_is_unique, $url_sql_query, $del_lnk ) { + $goto = $this->__get('_goto'); + if ($del_lnk == self::DELETE_ROW) { // delete row case $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), 'sql_query' => $url_sql_query, 'message_to_show' => __('The row has been deleted'), - 'goto' => (empty($this->_goto) ? 'tbl_sql.php' : $this->_goto), + 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto), ); $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text'); $del_query = 'DELETE FROM ' - . $this->getCommonFunctions()->backquote($this->_db) . '.' - . $this->getCommonFunctions()->backquote($this->_table) + . $this->getCommonFunctions()->backquote($this->__get('_db')) . '.' + . $this->getCommonFunctions()->backquote($this->__get('_table')) . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1'); $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), 'sql_query' => $del_query, 'message_to_show' => __('The row has been deleted'), 'goto' => $lnk_goto, ); $del_url = 'sql.php' . PMA_generate_common_url($_url_params); - $js_conf = 'DELETE FROM ' . PMA_jsFormat($this->_db) . '.' - . PMA_jsFormat($this->_table) + $js_conf = 'DELETE FROM ' . PMA_jsFormat($this->__get('_db')) . '.' + . PMA_jsFormat($this->__get('_table')) . ' WHERE ' . PMA_jsFormat($where_clause, false) . ($clause_is_unique ? '' : ' LIMIT 1'); @@ -3009,8 +3106,8 @@ class PMA_DisplayResults } elseif ($del_lnk == self::KILL_PROCESS) { // kill process case $_url_params = array( - 'db' => $this->_db, - 'table' => $this->_table, + 'db' => $this->__get('_db'), + 'table' => $this->__get('_table'), 'sql_query' => $url_sql_query, 'goto' => 'main.php', ); @@ -3105,12 +3202,14 @@ class PMA_DisplayResults $grid_edit_class, $not_null_class, $relation_class, $hide_class, $field_type_class, $row_no ) { + + $printview = $this->__get('_printview'); $class = 'data ' . $grid_edit_class . ' ' . $not_null_class . ' ' . $relation_class . ' ' . $hide_class . ' ' . $field_type_class; if (($_SESSION['tmp_user_values']['disp_direction'] == self::DISP_DIR_VERTICAL) - && (! isset($this->_printview) || ($this->_printview != '1')) + && (! isset($printview) || ($printview != '1')) ) { // the row number corresponds to a data row, not HTML table row $class .= ' row_' . $row_no; @@ -3468,6 +3567,8 @@ class PMA_DisplayResults $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql, &$dt_result, $col_index ) { + + $is_analyse = $this->__get ('_is_analyse'); if (! isset($column) || is_null($column)) { @@ -3502,7 +3603,7 @@ class PMA_DisplayResults // so don't treat them as BINARY } elseif (stristr($field_flags, self::BINARY_FIELD) && ($meta->type == self::STRING_FIELD) - && !(isset($this->_is_analyse) && $this->_is_analyse) + && !(isset($is_analyse) && $is_analyse) ) { if ($_SESSION['tmp_user_values']['display_binary']) { @@ -3590,12 +3691,13 @@ class PMA_DisplayResults { $vertical_table_html = ''; + $vertical_display = $this->__get('_vertical_display'); // Prepares "multi row delete" link at top if required if (($GLOBALS['cfg']['RowActionLinks'] != self::POSITION_RIGHT) - && is_array($this->_vertical_display['row_delete']) - && ((count($this->_vertical_display['row_delete']) > 0) - || !empty($this->_vertical_display['textbtn'])) + && is_array($vertical_display['row_delete']) + && ((count($vertical_display['row_delete']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= '' . "\n"; @@ -3605,7 +3707,7 @@ class PMA_DisplayResults $vertical_table_html .= '' . "\n"; } - $vertical_table_html .= $this->_vertical_display['textbtn'] + $vertical_table_html .= $vertical_display['textbtn'] . $this->_getCheckBoxesForMultipleRowOperations( '_left' ) @@ -3615,9 +3717,9 @@ class PMA_DisplayResults // Prepares "edit" link at top if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($this->_vertical_display['edit']) - && ((count($this->_vertical_display['edit']) > 0) - || !empty($this->_vertical_display['textbtn'])) + && is_array($vertical_display['edit']) + && ((count($vertical_display['edit']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( 'edit' @@ -3627,9 +3729,9 @@ class PMA_DisplayResults // Prepares "copy" link at top if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($this->_vertical_display['copy']) - && ((count($this->_vertical_display['copy']) > 0) - || !empty($this->_vertical_display['textbtn'])) + && is_array($vertical_display['copy']) + && ((count($vertical_display['copy']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( 'copy' @@ -3639,9 +3741,9 @@ class PMA_DisplayResults // Prepares "delete" link at top if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($this->_vertical_display['delete']) - && ((count($this->_vertical_display['delete']) > 0) - || !empty($this->_vertical_display['textbtn'])) + && is_array($vertical_display['delete']) + && ((count($vertical_display['delete']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( 'delete' @@ -3651,7 +3753,7 @@ class PMA_DisplayResults list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); // Prepares data - foreach ($this->_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; @@ -3662,7 +3764,7 @@ class PMA_DisplayResults . $val; $cell_displayed = 0; - foreach ($this->_vertical_display['rowdata'][$key] as $subval) { + foreach ($vertical_display['rowdata'][$key] as $subval) { if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) @@ -3682,13 +3784,13 @@ 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($this->_vertical_display['row_delete']) - && ((count($this->_vertical_display['row_delete']) > 0) - || !empty($this->_vertical_display['textbtn'])) + && is_array($vertical_display['row_delete']) + && ((count($vertical_display['row_delete']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= '' . "\n" - . $this->_vertical_display['textbtn'] + . $vertical_display['textbtn'] . $this->_getCheckBoxesForMultipleRowOperations('_right') . '' . "\n"; } // end if @@ -3696,9 +3798,9 @@ class PMA_DisplayResults // Prepares "edit" link at bottom if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($this->_vertical_display['edit']) - && ((count($this->_vertical_display['edit']) > 0) - || !empty($this->_vertical_display['textbtn'])) + && is_array($vertical_display['edit']) + && ((count($vertical_display['edit']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( 'edit' @@ -3708,9 +3810,9 @@ class PMA_DisplayResults // Prepares "copy" link at bottom if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($this->_vertical_display['copy']) - && ((count($this->_vertical_display['copy']) > 0) - || !empty($this->_vertical_display['textbtn'])) + && is_array($vertical_display['copy']) + && ((count($vertical_display['copy']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( 'copy' @@ -3720,9 +3822,9 @@ class PMA_DisplayResults // Prepares "delete" link at bottom if required if ((($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT) || ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)) - && is_array($this->_vertical_display['delete']) - && ((count($this->_vertical_display['delete']) > 0) - || !empty($this->_vertical_display['textbtn'])) + && is_array($vertical_display['delete']) + && ((count($vertical_display['delete']) > 0) + || !empty($vertical_display['textbtn'])) ) { $vertical_table_html .= $this->_getOperationLinksForVerticleTable( 'delete' @@ -3748,21 +3850,22 @@ class PMA_DisplayResults private function _getOperationLinksForVerticleTable($operation) { $link_html = '' . "\n"; + $vertical_display = $this->__get('_vertical_display'); - if (! is_array($this->_vertical_display['row_delete'])) { + if (! is_array($vertical_display['row_delete'])) { if (($operation == 'edit') || ($operation == 'copy')) { - $link_html .= $this->_vertical_display['textbtn']; + $link_html .= $vertical_display['textbtn']; } elseif ($operation == 'delete') { - if (! is_array($this->_vertical_display['edit'])) { - $link_html .= $this->_vertical_display['textbtn']; + if (! is_array($vertical_display['edit'])) { + $link_html .= $vertical_display['textbtn']; } } } - foreach ($this->_vertical_display[$operation] as $val) { + foreach ($vertical_display[$operation] as $val) { $link_html .= $val; } // end while @@ -3789,8 +3892,9 @@ class PMA_DisplayResults $checkBoxes_html = ''; $cell_displayed = 0; + $vertical_display = $this->__get('_vertical_display'); - foreach ($this->_vertical_display['row_delete'] as $val) { + foreach ($vertical_display['row_delete'] as $val) { if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) @@ -3833,10 +3937,10 @@ class PMA_DisplayResults public function setConfigParamsForDisplayTable() { - $sql_md5 = md5($this->_sql_query); + $sql_md5 = md5($this->__get('_sql_query')); $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] - = $this->_sql_query; + = $this->__get('_sql_query'); $valid_disp_dir = PMA_isValid( $_REQUEST['disp_direction'], @@ -4073,31 +4177,37 @@ class PMA_DisplayResults { // Initialize global variables which is not set in constructor - $this->_unlim_num_rows = $GLOBALS['unlim_num_rows']; - $this->_fields_meta = $GLOBALS['fields_meta']; - $this->_is_count = $GLOBALS['is_count']; - $this->_is_export = $GLOBALS['is_export']; - $this->_is_func = $GLOBALS['is_func']; - $this->_is_analyse = $GLOBALS['is_analyse']; - $this->_num_rows = $GLOBALS['num_rows']; - $this->_fields_cnt = $GLOBALS['fields_cnt']; - $this->_querytime = $GLOBALS['querytime']; - $this->_pma_theme_image = $GLOBALS['pmaThemeImage']; - $this->_text_dir = $GLOBALS['text_dir']; - $this->_is_maint = $GLOBALS['is_maint']; - $this->_is_explain = $GLOBALS['is_explain']; - $this->_is_show = $GLOBALS['is_show']; + $this->__set('_unlim_num_rows', $GLOBALS['unlim_num_rows']); + $this->__set('_fields_meta', $GLOBALS['fields_meta']); + $this->__set('_is_count', $GLOBALS['is_count']); + $this->__set('_is_export', $GLOBALS['is_export']); + $this->__set('_is_func', $GLOBALS['is_func']); + $this->__set('_is_analyse', $GLOBALS['is_analyse']); + $this->__set('_num_rows', $GLOBALS['num_rows']); + $this->__set('_fields_cnt', $GLOBALS['fields_cnt']); + $this->__set('_querytime', $GLOBALS['querytime']); + $this->__set('_pma_theme_image', $GLOBALS['pmaThemeImage']); + $this->__set('_text_dir', $GLOBALS['text_dir']); + $this->__set('_is_maint', $GLOBALS['is_maint']); + $this->__set('_is_explain', $GLOBALS['is_explain']); + $this->__set('_is_show', $GLOBALS['is_show']); + if (isset ($GLOBALS['showtable'])) { - $this->_showtable = $GLOBALS['showtable']; + $this->__set('_showtable', $GLOBALS['showtable']); } if (isset ($GLOBALS['printview'])) { - $this->_printview = $GLOBALS['printview']; + $this->__set('_printview', $GLOBALS['printview']); } if (isset ($GLOBALS['url_query'])) { - $this->_url_query = $GLOBALS['url_query']; - } + $this->__set('_url_query', $GLOBALS['url_query']); + } $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(); @@ -4106,8 +4216,8 @@ class PMA_DisplayResults * @todo move this to a central place * @todo for other future table types */ - $is_innodb = (isset($this->_showtable['Type']) - && $this->_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']) @@ -4167,19 +4277,19 @@ class PMA_DisplayResults ); $table_html .= $this->getCommonFunctions()->getMessage( - $message, $this->_sql_query, 'success' + $message, $this->__get('_sql_query'), 'success' ); - } elseif (! isset($this->_printview) || ($this->_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) @@ -4187,9 +4297,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 = $this->_fields_meta[0]->table; + $this->__set('_table', $fields_meta[0]->table); } else { - $this->_table = ''; + $this->__set('_table', ''); } } @@ -4221,7 +4331,7 @@ class PMA_DisplayResults $tabs = '(\'' . join('\',\'', $target) . '\')'; - if (! strlen($this->_table)) { + if (! strlen($this->__get('_table'))) { $exist_rel = false; } else { // This method set the values for $map array @@ -4246,7 +4356,8 @@ class PMA_DisplayResults $table_html .= $this->_getVerticalTable($analyzed_sql); } // end if - unset($this->_vertical_display); + $this->__set('_vertical_display', null); + $table_html .= '' . "\n" . ''; @@ -4270,7 +4381,7 @@ class PMA_DisplayResults ); // 6. ----- Prepare "Query results operations" - if (! isset($this->_printview) || $this->_printview != '1') { + if (! isset($printview) || ($printview != '1')) { $table_html .= $this->_getResultsOperations( $the_disp_mode, $analyzed_sql ); @@ -4378,10 +4489,12 @@ class PMA_DisplayResults &$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) @@ -4395,7 +4508,7 @@ class PMA_DisplayResults // (this might be a multi-table query) $sorted_column_index = false; - foreach ($this->_fields_meta as $key => $meta) { + foreach ($fields_meta as $key => $meta) { if (($meta->table == $sort_table) && ($meta->name == $sort_column)) { $sorted_column_index = $key; break; @@ -4413,7 +4526,7 @@ class PMA_DisplayResults $transform_options = array(); // check for non printable sorted row data - $meta = $this->_fields_meta[$sorted_column_index]; + $meta = $fields_meta[$sorted_column_index]; if (stristr($meta->type, self::BLOB_FIELD) || ($meta->type == self::GEOMETRY_FIELD) @@ -4434,11 +4547,11 @@ class PMA_DisplayResults ); // fetch last row of the result set - PMA_DBI_data_seek($dt_result, $this->_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 - $meta = $this->_fields_meta[$sorted_column_index]; + $meta = $fields_meta[$sorted_column_index]; if (stristr($meta->type, self::BLOB_FIELD) || ($meta->type == self::GEOMETRY_FIELD) ) { @@ -4494,9 +4607,11 @@ class PMA_DisplayResults $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($this->_unlim_num_rows) && ($this->_unlim_num_rows != $total)) { - $selectstring = ', ' . $this->_unlim_num_rows . ' ' . __('in query'); + if (isset($unlim_num_rows) && ($unlim_num_rows != $total)) { + $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query'); } else { $selectstring = ''; } @@ -4527,7 +4642,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']) ) { @@ -4574,7 +4689,7 @@ class PMA_DisplayResults } $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec') . ')'); - $messagge_qt->addParam($this->_querytime); + $messagge_qt->addParam($this->__get('_querytime')); $message->addMessage($messagge_qt, ''); if (! is_null($sorted_column_message)) { @@ -4607,7 +4722,7 @@ class PMA_DisplayResults // 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 + $this->__get('_db'), $this->__get('_table'), '', self::POSITION_BOTH ); if ($exist_rel) { @@ -4649,20 +4764,21 @@ class PMA_DisplayResults ) { $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:') . ''; } @@ -4691,22 +4807,22 @@ class PMA_DisplayResults $links_html .= "\n"; $links_html .= '' . "\n"; + .' value="' . htmlspecialchars($this->__get('_sql_query')) . '" />' . "\n"; - if (! empty($this->_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, $this->_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, $this->_fields_cnt, $this->_fields_meta, $row + $dt_result, $this->__get('_fields_cnt'), $this->__get('_fields_meta'), $row ); // reset to first row for the loop in _getTableBody() @@ -4745,6 +4861,7 @@ class PMA_DisplayResults ) { $navigation_html = ''; + $printview = $this->__get('_printview'); if (($is_display['nav_bar'] == '1') && empty($analyzed_sql[0]['limit_clause']) @@ -4762,7 +4879,7 @@ class PMA_DisplayResults $navigation_html .= "\n"; } - } elseif (! isset($this->_printview) || ($this->_printview != '1')) { + } elseif (! isset($printview) || ($printview != '1')) { $navigation_html .= "\n" . '

' . "\n"; } @@ -4787,6 +4904,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') . ''; @@ -4801,10 +4919,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); @@ -4861,7 +4979,7 @@ class PMA_DisplayResults $header_shown = true; } - $_url_params['unlim_num_rows'] = $this->_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 @@ -4901,7 +5019,7 @@ class PMA_DisplayResults // prepare GIS chart $geometry_found = false; // If atleast one geometry field is found - foreach ($this->_fields_meta as $meta) { + foreach ($fields_meta as $meta) { if ($meta->type == self::GEOMETRY_FIELD) { $geometry_found = true; break; @@ -5082,7 +5200,8 @@ class PMA_DisplayResults $transformation_plugin, $default_function, $nowrap, $where_comparison, $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($this->__get('_db')) . '.' . $this->getCommonFunctions()->backquote($meta->orgtable) . ' WHERE ' . $this->getCommonFunctions()->backquote($meta->orgname) From 10224f7dad7389add80ed253a36b467323a63f5b Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Sun, 8 Jul 2012 23:39:45 +0530 Subject: [PATCH 8/9] Remove setCommonFunctions --- libraries/DisplayResults.class.php | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 4424c54472..cdad4c181d 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -168,33 +168,16 @@ class PMA_DisplayResults * * @param string $property name of the property * @param $value value to set - * - * @return PMA_DisplayResults */ public function __set($property, $value) { if (property_exists($this, $property)) { $this->$property = $value; } - - return $this; } - /** - * Set CommmonFunctions - * - * @param PMA_CommonFunctions $commonFunctions - * - * @return void - */ - public function setCommonFunctions(PMA_CommonFunctions $commonFunctions) - { - $this->_common_functions = $commonFunctions; - } - - /** * Get CommmonFunctions * @@ -270,7 +253,7 @@ class PMA_DisplayResults $unlim_num_rows = $this->__get('_unlim_num_rows'); $fields_meta = $this->__get('_fields_meta'); $printview = $this->__get('_printview'); - +//var_dump($the_disp_mode);echo "-----
"; var_dump($the_total);echo "-----
"; // 1. Initializes the $do_display array $do_display = array(); $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1]; @@ -423,7 +406,7 @@ class PMA_DisplayResults // 5. Updates the synthetic var $the_disp_mode = join('', $do_display); - +//echo "****
";var_dump($do_display);echo "
****"; return $do_display; } // end of the 'setDisplayMode()' function From f25472455baa4451ab8c3fe17e62642de7eaeb71 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Tue, 10 Jul 2012 01:03:16 +0530 Subject: [PATCH 9/9] Fix defect in print view when vertical mode is on --- libraries/DisplayResults.class.php | 81 ++++++++++++++++-------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index cdad4c181d..80a523bc0a 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -253,7 +253,7 @@ class PMA_DisplayResults $unlim_num_rows = $this->__get('_unlim_num_rows'); $fields_meta = $this->__get('_fields_meta'); $printview = $this->__get('_printview'); -//var_dump($the_disp_mode);echo "-----
"; var_dump($the_total);echo "-----
"; + // 1. Initializes the $do_display array $do_display = array(); $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1]; @@ -406,7 +406,7 @@ class PMA_DisplayResults // 5. Updates the synthetic var $the_disp_mode = join('', $do_display); -//echo "****
";var_dump($do_display);echo "
****"; + return $do_display; } // end of the 'setDisplayMode()' function @@ -924,6 +924,7 @@ class PMA_DisplayResults $vertical_display['emptypre'] = 0; $vertical_display['emptyafter'] = 0; $vertical_display['textbtn'] = ''; + $full_or_partial_text_link = null; $this->__set('_vertical_display', $vertical_display); @@ -1021,7 +1022,7 @@ class PMA_DisplayResults ); } - $vertical_display[] = ' __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) @@ -4186,7 +4191,7 @@ class PMA_DisplayResults } $table_html = ''; - // Following variable are needed for use in isset/empty or + // 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'); @@ -4286,11 +4291,19 @@ class PMA_DisplayResults } } + + if (($is_display['nav_bar'] == '1') + && empty($analyzed_sql[0]['limit_clause']) + ) { - $table_html .= $this->_getPlacedTableNavigatoins( - $is_display, $analyzed_sql, $pos_next, $pos_prev, - self::PLACE_TOP_DIRECTION_DROPDOWN, "\n", $is_innodb - ); + $table_html .= $this->_getPlacedTableNavigatoins( + $pos_next, $pos_prev, self::PLACE_TOP_DIRECTION_DROPDOWN, + "\n", $is_innodb + ); + + } elseif (! isset($printview) || ($printview != '1')) { + $table_html .= "\n" . '

' . "\n"; + } // 2b ----- Get field references from Database ----- // (see the 'relation' configuration variable) @@ -4357,11 +4370,17 @@ class PMA_DisplayResults } // 5. ----- Get the navigation bar at the bottom if required ----- - - $table_html .= $this->_getPlacedTableNavigatoins( - $is_display, $analyzed_sql, $pos_next, $pos_prev, - self::PLACE_BOTTOM_DIRECTION_DROPDOWN, '
' . "\n", $is_innodb - ); + if (($is_display['nav_bar'] == '1') + && empty($analyzed_sql[0]['limit_clause']) + ) { + $table_html .= $this->_getPlacedTableNavigatoins( + $pos_next, $pos_prev, self::PLACE_BOTTOM_DIRECTION_DROPDOWN, + '
' . "\n", $is_innodb + ); + } elseif (! isset($printview) || ($printview != '1')) { + $table_html .= "\n" . '

' . "\n"; + } + // 6. ----- Prepare "Query results operations" if (! isset($printview) || ($printview != '1')) { @@ -4824,8 +4843,6 @@ class PMA_DisplayResults /** * Prepare table navigation bar at the top or bottom * - * @param array $is_display which elements to display - * @param array $analyzed_sql the analyzed query * @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 @@ -4839,31 +4856,21 @@ class PMA_DisplayResults * @see _getTable() */ private function _getPlacedTableNavigatoins( - $is_display, $analyzed_sql, $pos_next, $pos_prev - , $place, $empty_line, $is_innodb + $pos_next, $pos_prev, $place, $empty_line, $is_innodb ) { $navigation_html = ''; - $printview = $this->__get('_printview'); - if (($is_display['nav_bar'] == '1') - && empty($analyzed_sql[0]['limit_clause']) - ) { - - 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"; - } - - } elseif (! isset($printview) || ($printview != '1')) { - $navigation_html .= "\n" . '

' . "\n"; + 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;