diff --git a/ChangeLog b/ChangeLog index c249cd17e7..256001a8cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -56,6 +56,7 @@ VerboseMultiSubmit, ReplaceHelpImg - bug #3531586 [unterface] Add user form prints JSON when user presses enter - bug #3534121 [config] duplicate line in config.sample.inc.php - bug #3534311 [interface] Grid editing incorrectly parses ENUM/SET values +- bug #3510196 [core] More clever URL rewriting with ForceSSL 3.5.1.0 (2012-05-03) - bug #3510784 [edit] Limit clause ignored when sort order is remembered diff --git a/db_datadict.php b/db_datadict.php index 506a1ba09a..aeb62041bb 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -281,6 +281,6 @@ foreach ($tables as $table) { /** * Displays the footer */ -PMA_printButton(); +echo PMA_getButton(); ?> diff --git a/db_printview.php b/db_printview.php index 3160089361..6dcfd6f06a 100644 --- a/db_printview.php +++ b/db_printview.php @@ -244,7 +244,7 @@ if ($num_tables == 0) { /** * Displays the footer */ -PMA_printButton(); +echo PMA_getButton(); echo "
\n"; ?> diff --git a/db_structure.php b/db_structure.php index d711e0e75a..9424391ee0 100644 --- a/db_structure.php +++ b/db_structure.php @@ -112,7 +112,7 @@ if (isset($_REQUEST['sort_order'])) { $_url_params['sort_order'] = $_REQUEST['sort_order']; } -PMA_listNavigator( +echo PMA_getListNavigator( $total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList'] ); @@ -727,7 +727,7 @@ if (!$db_is_information_schema && !$cfg['DisableMultiTableMaintenance']) { _db = $db; + $this->_table = $table; + $this->_goto = $goto; + $this->_sql_query = $sql_query; + } + + + /** + * Defines the display mode to use for the results of a SQL query + * + * It uses a synthetic string that contains all the required informations. + * In this string: + * - the first two characters stand for the action to do while + * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no + * edit link...); + * - the next two characters stand for the action to do while + * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for + * no delete link...); + * - the next characters are boolean values (1/0) and respectively stand + * for sorting links, navigation bar, "insert a new row" link, the + * bookmark feature, the expand/collapse text/blob fields button and + * the "display printable view" option. + * Of course '0'/'1' means the feature won't/will be enabled. + * + * @param string &$the_disp_mode the synthetic value for display_mode (see a few + * lines above for explanations) + * @param integer &$the_total the total number of rows returned by the SQL + * query without any programmatically appended + * LIMIT clause + * (just a copy of $unlim_num_rows if it exists, + * elsecomputed inside this function) + * + * @return array an array with explicit indexes for all the display + * elements + * + * @access private + * + * @see getTable() + */ + private function _setDisplayMode(&$the_disp_mode, &$the_total) + { + + // 1. Initializes the $do_display array + $do_display = array(); + $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1]; + $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3]; + $do_display['sort_lnk'] = (string) $the_disp_mode[4]; + $do_display['nav_bar'] = (string) $the_disp_mode[5]; + $do_display['ins_row'] = (string) $the_disp_mode[6]; + $do_display['bkm_form'] = (string) $the_disp_mode[7]; + $do_display['text_btn'] = (string) $the_disp_mode[8]; + $do_display['pview_lnk'] = (string) $the_disp_mode[9]; + + // 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') { + // 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 + $do_display['sort_lnk'] = (string) '0'; + $do_display['nav_bar'] = (string) '0'; + $do_display['ins_row'] = (string) '0'; + $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'] + ) { + // 2.1 Statement is a "SELECT COUNT", a + // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or + // contains a "PROC ANALYSE" part + $do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE; // no edit link + $do_display['del_lnk'] = self::NO_EDIT_OR_DELETE; // no delete link + $do_display['sort_lnk'] = (string) '0'; + $do_display['nav_bar'] = (string) '0'; + $do_display['ins_row'] = (string) '0'; + $do_display['bkm_form'] = (string) '1'; + if ($GLOBALS['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']) { + // 2.2 Statement is a "SHOW..." + /** + * 2.2.1 + * @todo defines edit/delete links depending on show statement + */ + $tmp = preg_match( + '@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?' + . 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS' + . ')@i', + $GLOBALS['sql_query'], $which + ); + if (isset($which[1]) + && (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) + ) { + // no edit link + $do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE; + // "kill process" type edit link + $do_display['del_lnk'] = self::KILL_PROCESS; + } else { + // Default case -> no links + // no edit link + $do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE; + // no delete link + $do_display['del_lnk'] = self::NO_EDIT_OR_DELETE; + } + // 2.2.2 Other settings + $do_display['sort_lnk'] = (string) '0'; + $do_display['nav_bar'] = (string) '0'; + $do_display['ins_row'] = (string) '0'; + $do_display['bkm_form'] = (string) '1'; + $do_display['text_btn'] = (string) '1'; + $do_display['pview_lnk'] = (string) '1'; + } else { + // 2.3 Other statements (ie "SELECT" ones) -> updates + // $do_display['edit_lnk'], $do_display['del_lnk'] and + // $do_display['text_btn'] (keeps other default values) + $prev_table = $GLOBALS['fields_meta'][0]->table; + $do_display['text_btn'] = (string) '1'; + for ($i = 0; $i < $GLOBALS['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)) + ) { + // don't display links + $do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE; + $do_display['del_lnk'] = self::NO_EDIT_OR_DELETE; + /** + * @todo May be problematic with same field names + * in two joined table. + */ + // $do_display['sort_lnk'] = (string) '0'; + $do_display['ins_row'] = (string) '0'; + if ($do_display['text_btn'] == '1') { + break; + } + } // end if (2.3.2) + // 2.3.3 Always display print view link + $do_display['pview_lnk'] = (string) '1'; + $prev_table = $GLOBALS['fields_meta'][$i]->table; + } // 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']; + } elseif ((($do_display['nav_bar'] == '1') + || ($do_display['sort_lnk'] == '1')) + && (strlen($this->_db) && !empty($this->_table)) + ) { + $the_total = PMA_Table::countRecords($this->_db, $this->_table); + } + + // 4. If navigation bar or sorting fields names URLs should be + // displayed but there is only one row, change these settings to + // false + if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') { + + // - Do not display sort links if less than 2 rows. + // - For a VIEW we (probably) did not count the number of rows + // so don't test this number here, it would remove the possibility + // of sorting VIEW results. + if (isset($GLOBALS['unlim_num_rows']) + && $GLOBALS['unlim_num_rows'] < 2 + && ! PMA_Table::isView($this->_db, $this->_table) + ) { + // force display of navbar for vertical/horizontal display-choice. + // $do_display['nav_bar'] = (string) '0'; + $do_display['sort_lnk'] = (string) '0'; + } + } // end if (3) + + // 5. Updates the synthetic var + $the_disp_mode = join('', $do_display); + + return $do_display; + + } // end of the 'setDisplayMode()' function + + + /** + * Return true if we are executing a query in the form of + * "SELECT * FROM ..." + * + * @return boolean + * + * @access private + * + * @see _getTableHeaders(), _getColumnParams() + */ + private function _isSelect() + { + 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); + } + + + /** + * Get a navigation button + * + * @param string $caption iconic caption for button + * @param string $title text for button + * @param integer $pos position for next query + * @param string $html_sql_query query ready for display + * @param string $onsubmit optional onsubmit clause + * @param string $input_for_real_end optional hidden field for special treatment + * @param string $onclick optional onclick clause + * + * @return string html content + * + * @access private + * + * @see _getMoveBackwardButtonsForTableNavigation(), + * _getMoveForwardButtonsForTableNavigation() + */ + private function _getTableNavigationButton( + $caption, $title, $pos, $html_sql_query, $onsubmit = '', + $input_for_real_end = '', $onclick = '' + ) { + + $caption_output = ''; + // for true or 'both' + if ($GLOBALS['cfg']['NavigationBarIconic']) { + $caption_output .= $caption; + } + + // for false or 'both' + if (($GLOBALS['cfg']['NavigationBarIconic'] === false) + || ($GLOBALS['cfg']['NavigationBarIconic'] === self::POSITION_BOTH) + ) { + $caption_output .= ' ' . $title; + } + $title_output = ' title="' . $title . '"'; + + return '| '; + + // Move to the beginning or to the previous page + if ($_SESSION['tmp_user_values']['pos'] + && ($_SESSION['tmp_user_values']['max_rows'] != self::ALL_ROWS) + ) { + + $table_navigation_html + .= $this->_getMoveBackwardButtonsForTableNavigation( + $html_sql_query, $pos_prev + ); + + } // end move back + + $nbTotalPage = 1; + //page redirection + // (unless we are showing all records) + if ($_SESSION['tmp_user_values']['max_rows'] != self::ALL_ROWS) { //if1 + + $pageNow = @floor( + $_SESSION['tmp_user_values']['pos'] + / $_SESSION['tmp_user_values']['max_rows'] + ) + 1; + + $nbTotalPage = @ceil( + $GLOBALS['unlim_num_rows'] + / $_SESSION['tmp_user_values']['max_rows'] + ); + + if ($nbTotalPage > 1) { //if2 + + $table_navigation_html .= ' | '; + $_url_params = array( + 'db' => $this->_db, + 'table' => $this->_table, + 'sql_query' => $this->_sql_query, + 'goto' => $this->_goto, + ); + + //' + . ' | '; + } //_if2 + } //_if1 + + // Display the "Show all" button if allowed + if (($GLOBALS['num_rows'] < $GLOBALS['unlim_num_rows']) + && ($GLOBALS['cfg']['ShowAll'] + || ($GLOBALS['cfg']['MaxRows'] * 5 >= $GLOBALS['unlim_num_rows'])) + ) { + + $table_navigation_html .= $this->_getShowAllButtonForTableNavigation( + $html_sql_query + ); + + } // end show all + + // Move to the next page or to the last one + $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']) + && ($_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'] + ); + + } // end move toward + + // show separator if pagination happen + if ($nbTotalPage > 1) { + $table_navigation_html + .= ''; + } + + $table_navigation_html .= ' | ' + . '' + . ' | ' + . '' + . '' + . ' | '; + + // if displaying a VIEW, $unlim_num_rows could be zero because + // of $cfg['MaxExactCountViews']; in this case, avoid passing + // the 5th parameter to checkFormElementInRange() + // (this means we can't validate the upper limit + $table_navigation_html .= ''; + + $table_navigation_html .= '' + . ' | ' + . '' + . ' |
[->' . $dispval . ']';
+
+ } else {
+
+ if ($_SESSION['tmp_user_values']['relational_display'] == self::RELATIONAL_KEY) {
+
+ // user chose "relational key" in the display options, so
+ // the title contains the display field
+ $title = (! empty($dispval))
+ ? ' title="' . htmlspecialchars($dispval) . '"'
+ : '';
+
+ } else {
+ $title = ' title="' . htmlspecialchars($data) . '"';
+ }
+
+ $_url_params = array(
+ 'db' => $map[$meta->name][3],
+ 'table' => $map[$meta->name][0],
+ 'pos' => '0',
+ 'sql_query' => 'SELECT * FROM '
+ . PMA_backquote($map[$meta->name][3]) . '.'
+ . PMA_backquote($map[$meta->name][0])
+ . ' WHERE ' . PMA_backquote($map[$meta->name][1])
+ . $where_comparison,
+ );
+
+ $result .= '';
+
+ if ($transform_function != $default_function) {
+ // always apply a transformation on the real data,
+ // not on the display field
+ $result .= $transform_function($data, $transform_options, $meta);
+ } else {
+
+ if ($_SESSION['tmp_user_values']['relational_display'] == self::RELATIONAL_DISPLAY_COLUMN) {
+ // user chose "relational display field" in the
+ // display options, so show display field in the cell
+ $result .= $transform_function($dispval, array(), $meta);
+ } else {
+ // otherwise display data in the cell
+ $result .= $transform_function($data, array(), $meta);
+ }
+
+ }
+ $result .= '';
+ }
+
+ } else {
+ $result .= ($transform_function != $default_function)
+ ? $transform_function($data, $transform_options, $meta)
+ : $transform_function($data, array(), $meta);
+ }
+
+ // create hidden field if results from structure table
+ if (isset($_GET['browse_distinct']) && ($_GET['browse_distinct'] == 1)) {
+
+ $where_comparison = " = '" . $data . "'";
+
+ $_url_params_for_show_data_row = array(
+ 'db' => $this->_db,
+ 'table' => $meta->orgtable,
+ 'pos' => '0',
+ 'sql_query' => 'SELECT * FROM '
+ . PMA_backquote($this->_db) . '.'
+ . PMA_backquote($meta->orgtable)
+ . ' WHERE '
+ . PMA_backquote($meta->orgname)
+ . $where_comparison,
+ );
+
+ $result .= '';
+
+ }
+
+ $result .= '