/phpMyAdmin/libraries/display_tbl.lib.php
PHP | 3032 lines | 2005 code | 296 blank | 731 comment | 805 complexity | b1192d9b97f18248da9ad85cef982a2c MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
Large files files are truncated, but you can click here to view the full file
- <?php
- /* vim: set expandtab sw=4 ts=4 sts=4: */
- /**
- * library for displaying table with results from all sort of select queries
- *
- * @package PhpMyAdmin
- */
- /**
- *
- */
- require_once './libraries/Index.class.php';
- /**
- * 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, else
- * computed inside this function)
- *
- * @return array an array with explicit indexes for all the display
- * elements
- *
- * @global string the database name
- * @global string the table name
- * @global integer the total number of rows returned by the SQL query
- * without any programmatically appended "LIMIT" clause
- * @global array the properties of the fields returned by the query
- * @global string the URL to return to in case of error in a SQL
- * statement
- *
- * @access private
- *
- * @see PMA_displayTable()
- */
- function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
- {
- global $db, $table;
- global $unlim_num_rows, $fields_meta;
- global $err_url;
- // 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'] = 'nn'; // no edit link
- $do_display['del_lnk'] = 'nn'; // 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'] = 'nn'; // no edit link
- $do_display['del_lnk'] = 'nn'; // 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) {
- $do_display['edit_lnk'] = 'nn'; // no edit link
- $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
- } else {
- // Default case -> no links
- $do_display['edit_lnk'] = 'nn'; // no edit link
- $do_display['del_lnk'] = 'nn'; // no delete link
- }
- // 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 = $fields_meta[0]->table;
- $do_display['text_btn'] = (string) '1';
- for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
- $is_link = ($do_display['edit_lnk'] != 'nn'
- || $do_display['del_lnk'] != 'nn'
- || $do_display['sort_lnk'] != '0'
- || $do_display['ins_row'] != '0');
- // 2.3.2 Displays edit/delete/sort/insert links?
- if ($is_link
- && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)
- ) {
- $do_display['edit_lnk'] = 'nn'; // don't display links
- $do_display['del_lnk'] = 'nn';
- /**
- * @todo May be problematic with same fields 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 = $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($unlim_num_rows) && $unlim_num_rows != '') {
- $the_total = $unlim_num_rows;
- } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
- && (strlen($db) && !empty($table))) {
- $the_total = PMA_Table::countRecords($db, $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($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';
- $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 'PMA_setDisplayMode()' function
- /**
- * Return true if we are executing a query in the form of
- * "SELECT * FROM <a table> ..."
- *
- * @return boolean
- */
- function PMA_isSelect()
- {
- // global variables set from sql.php
- global $is_count, $is_export, $is_func, $is_analyse;
- global $analyzed_sql;
- return ! ($is_count || $is_export || $is_func || $is_analyse)
- && count($analyzed_sql[0]['select_expr']) == 0
- && isset($analyzed_sql[0]['queryflags']['select_from'])
- && count($analyzed_sql[0]['table_ref']) == 1;
- }
- /**
- * Displays 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 nothing
- *
- * @global string $db the database name
- * @global string $table the table name
- * @global string $goto the URL to go back in case of errors
- *
- * @access private
- *
- * @see PMA_displayTableNavigation()
- */
- function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '')
- {
- global $db, $table, $goto;
- $caption_output = '';
- // for true or 'both'
- if ($GLOBALS['cfg']['NavigationBarIconic']) {
- $caption_output .= $caption;
- }
- // for false or 'both'
- if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
- $caption_output .= ' ' . $title;
- }
- $title_output = ' title="' . $title . '"';
- ?>
- <td>
- <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
- <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
- <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
- <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
- <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
- <?php echo $input_for_real_end; ?>
- <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax" ' : '' ); ?> value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
- </form>
- </td>
- <?php
- } // end function PMA_displayTableNavigationOneButton()
- /**
- * Displays a navigation bar to browse among the results of a SQL query
- *
- * @param integer $pos_next the offset for the "next" page
- * @param integer $pos_prev the offset for the "previous" page
- * @param string $sql_query the URL-encoded query
- * @param string $id_for_direction_dropdown the id for the direction dropdown
- *
- * @return nothing
- *
- * @global string $db the database name
- * @global string $table the table name
- * @global string $goto the URL to go back in case of errors
- * @global integer $num_rows the total number of rows returned by the
- * SQL query
- * @global integer $unlim_num_rows the total number of rows returned by the
- * SQL any programmatically appended "LIMIT" clause
- * @global boolean $is_innodb whether its InnoDB or not
- * @global array $showtable table definitions
- *
- * @access private
- *
- * @see PMA_displayTable()
- */
- function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
- {
- global $db, $table, $goto;
- global $num_rows, $unlim_num_rows;
- global $is_innodb;
- global $showtable;
- // here, using htmlentities() would cause problems if the query
- // contains accented characters
- $html_sql_query = htmlspecialchars($sql_query);
- /**
- * @todo move this to a central place
- * @todo for other future table types
- */
- $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
- ?>
- <!-- Navigation bar -->
- <table border="0" cellpadding="0" cellspacing="0" class="navigation">
- <tr>
- <td class="navigation_separator"></td>
- <?php
- // Move to the beginning or to the previous page
- if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
- PMA_displayTableNavigationOneButton('<<', _pgettext('First page', 'Begin'), 0, $html_sql_query);
- PMA_displayTableNavigationOneButton('<', _pgettext('Previous page', 'Previous'), $pos_prev, $html_sql_query);
- } // end move back
- $nbTotalPage = 1;
- //page redirection
- // (unless we are showing all records)
- if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
- $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
- $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
- if ($nbTotalPage > 1) { //if2
- ?>
- <td>
- <?php
- $_url_params = array(
- 'db' => $db,
- 'table' => $table,
- 'sql_query' => $sql_query,
- 'goto' => $goto,
- );
- //<form> to keep the form alignment of button < and <<
- // and also to know what to execute when the selector changes
- echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
- echo PMA_pageselector(
- $_SESSION['tmp_user_values']['max_rows'],
- $pageNow,
- $nbTotalPage,
- 200,
- 5,
- 5,
- 20,
- 10
- );
- ?>
- </form>
- </td>
- <?php
- } //_if2
- } //_if1
- // Display the "Show all" button if allowed
- if (($num_rows < $unlim_num_rows) && ($GLOBALS['cfg']['ShowAll'] || ($GLOBALS['cfg']['MaxRows'] * 5 >= $unlim_num_rows))) {
- echo "\n";
- ?>
- <td>
- <form action="sql.php" method="post">
- <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
- <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
- <input type="hidden" name="pos" value="0" />
- <input type="hidden" name="session_max_rows" value="all" />
- <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
- <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
- </form>
- </td>
- <?php
- } // end show all
- // Move to the next page or to the last one
- if (($_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'] != 'all'
- ) {
- // display the Next button
- PMA_displayTableNavigationOneButton(
- '>',
- _pgettext('Next page', 'Next'),
- $pos_next,
- $html_sql_query
- );
- // prepare some options for the End button
- if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
- $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
- // no backquote around this message
- $onclick = '';
- } else {
- $input_for_real_end = $onclick = '';
- }
- // display the End button
- PMA_displayTableNavigationOneButton(
- '>>',
- _pgettext('Last page', 'End'),
- @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
- $html_sql_query,
- 'onsubmit="return ' . (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['tmp_user_values']['max_rows']) ? 'true' : 'false') . '"',
- $input_for_real_end,
- $onclick
- );
- } // end move toward
- // show separator if pagination happen
- if ($nbTotalPage > 1) {
- echo '<td><div class="navigation_separator">|</div></td>';
- }
- ?>
- <td>
- <div class="save_edited hide">
- <input type="submit" value="<?php echo __('Save edited data'); ?>" />
- <div class="navigation_separator">|</div>
- </div>
- </td>
- <td>
- <div class="restore_column hide">
- <input type="submit" value="<?php echo __('Restore column order'); ?>" />
- <div class="navigation_separator">|</div>
- </div>
- </td>
- <?php // 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 ?>
- <td class="navigation_goto">
- <form action="sql.php" method="post"
- onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 1) && checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
- <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
- <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
- <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
- <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
- <?php echo __('Start row') . ': ' . "\n"; ?>
- <input type="text" name="pos" size="3" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
- <?php echo __('Number of rows') . ': ' . "\n"; ?>
- <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['tmp_user_values']['max_rows'] != 'all') ? $_SESSION['tmp_user_values']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
- <?php
- if ($GLOBALS['cfg']['ShowDisplayDirection']) {
- // Display mode (horizontal/vertical and repeat headers)
- echo __('Mode') . ': ' . "\n";
- $choices = array(
- 'horizontal' => __('horizontal'),
- 'horizontalflipped' => __('horizontal (rotated headers)'),
- 'vertical' => __('vertical'));
- echo PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
- unset($choices);
- }
- printf(
- __('Headers every %s rows'),
- '<input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />'
- );
- echo "\n";
- ?>
- </form>
- </td>
- <td class="navigation_separator"></td>
- </tr>
- </table>
- <?php
- } // end of the 'PMA_displayTableNavigation()' function
- /**
- * Displays the headers of the results table
- *
- * @param array &$is_display which elements to display
- * @param array &$fields_meta the list of fields properties
- * @param integer $fields_cnt the total number of fields returned by the SQL query
- * @param array $analyzed_sql the analyzed query
- * @param string $sort_expression sort expression
- * @param string $sort_expression_nodirection sort expression without direction
- * @param string $sort_direction sort direction
- *
- * @return boolean $clause_is_unique
- *
- * @global string $db the database name
- * @global string $table the table name
- * @global string $goto the URL to go back in case of errors
- * @global string $sql_query the SQL query
- * @global integer $num_rows the total number of rows returned by the
- * SQL query
- * @global array $vertical_display informations used with vertical display
- * mode
- *
- * @access private
- *
- * @see PMA_displayTable()
- */
- function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
- {
- global $db, $table, $goto;
- global $sql_query, $num_rows;
- global $vertical_display, $highlight_columns;
- // required to generate sort links that will remember whether the
- // "Show all" button has been clicked
- $sql_md5 = md5($GLOBALS['sql_query']);
- $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
- if ($analyzed_sql == '') {
- $analyzed_sql = array();
- }
- // can the result be sorted?
- if ($is_display['sort_lnk'] == '1') {
- // Just as fallback
- $unsorted_sql_query = $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'] == 'SELECT'
- && isset($analyzed_sql[0]['table_ref'])
- && count($analyzed_sql[0]['table_ref']) == 1
- ) {
- // grab indexes data:
- $indexes = PMA_Index::getFromTable($table, $db);
- // do we have any index?
- if ($indexes) {
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- $span = $fields_cnt;
- if ($is_display['edit_lnk'] != 'nn') {
- $span++;
- }
- if ($is_display['del_lnk'] != 'nn') {
- $span++;
- }
- if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
- $span++;
- }
- } else {
- $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
- }
- echo '<form action="sql.php" method="post">' . "\n";
- echo PMA_generate_common_hidden_inputs($db, $table);
- echo __('Sort by key') . ': <select name="sql_query" class="autosubmit">' . "\n";
- $used_index = false;
- $local_order = (isset($sort_expression) ? $sort_expression : '');
- foreach ($indexes as $index) {
- $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
- $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
- $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
- if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $my_reg)) {
- $unsorted_sql_query_first_part = $my_reg[1];
- $unsorted_sql_query_second_part = $my_reg[2];
- } else {
- $unsorted_sql_query_first_part = $unsorted_sql_query;
- $unsorted_sql_query_second_part = '';
- }
- echo '<option value="'
- . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $asc_sort . $unsorted_sql_query_second_part)
- . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
- . '>' . htmlspecialchars($index->getName()) . ' ('
- . __('Ascending') . ')</option>';
- echo '<option value="'
- . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $desc_sort . $unsorted_sql_query_second_part)
- . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
- . '>' . htmlspecialchars($index->getName()) . ' ('
- . __('Descending') . ')</option>';
- }
- echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
- echo '</select>' . "\n";
- echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
- echo '</form>' . "\n";
- }
- }
- }
- // Output data needed for grid editing
- echo '<input id="save_cells_at_once" type="hidden" value="' . $GLOBALS['cfg']['SaveCellsAtOnce'] . '" />';
- echo '<div class="common_hidden_inputs">';
- echo PMA_generate_common_hidden_inputs($db, $table);
- echo '</div>';
- // Output data needed for column reordering and show/hide column
- if (PMA_isSelect()) {
- // generate the column order, if it is set
- $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
- $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
- if ($col_order) {
- echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
- }
- $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
- if ($col_visib) {
- echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
- }
- // generate table create time
- if (! PMA_Table::isView($GLOBALS['table'], $GLOBALS['db'])) {
- echo '<input id="table_create_time" type="hidden" value="' .
- PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
- }
- }
- $vertical_display['emptypre'] = 0;
- $vertical_display['emptyafter'] = 0;
- $vertical_display['textbtn'] = '';
- // Display options (if we are not in print view)
- if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
- echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
- if ($GLOBALS['cfg']['AjaxEnable']) {
- echo ' class="ajax" ';
- }
- echo '>';
- $url_params = array(
- 'db' => $db,
- 'table' => $table,
- 'sql_query' => $sql_query,
- 'goto' => $goto,
- 'display_options_form' => 1
- );
- echo PMA_generate_common_hidden_inputs($url_params);
- echo '<br />';
- PMA_generate_slider_effect('displayoptions', __('Options'));
- echo '<fieldset>';
- echo '<div class="formelement">';
- $choices = array(
- 'P' => __('Partial texts'),
- 'F' => __('Full texts')
- );
- PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
- echo '</div>';
- // prepare full/partial text button or link
- $url_params_full_text = array(
- 'db' => $db,
- 'table' => $table,
- 'sql_query' => $sql_query,
- 'goto' => $goto,
- 'full_text_button' => 1
- );
- if ($_SESSION['tmp_user_values']['display_text']=='F') {
- // currently in fulltext mode so show the opposite link
- $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
- $tmp_txt = __('Partial texts');
- $url_params_full_text['display_text'] = 'P';
- } else {
- $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
- $tmp_txt = __('Full texts');
- $url_params_full_text['display_text'] = 'F';
- }
- $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
- $tmp_url = 'sql.php' . PMA_generate_common_url($url_params_full_text);
- $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
- unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
- if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
- echo '<div class="formelement">';
- $choices = array(
- 'K' => __('Relational key'),
- 'D' => __('Relational display column')
- );
- PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
- echo '</div>';
- }
- echo '<div class="formelement">';
- PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
- echo '<br />';
- PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
- echo '<br />';
- PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
- echo '</div>';
- // I would have preferred to name this "display_transformation".
- // This is the only way I found to be able to keep this setting sticky
- // per SQL query, and at the same time have a default that displays
- // the transformations.
- echo '<div class="formelement">';
- PMA_display_html_checkbox('hide_transformation', __('Hide browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
- echo '</div>';
- if (! PMA_DRIZZLE) {
- echo '<div class="formelement">';
- $choices = array(
- 'GEOM' => __('Geometry'),
- 'WKT' => __('Well Known Text'),
- 'WKB' => __('Well Known Binary')
- );
- PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
- echo '</div>';
- }
- echo '<div class="clearfloat"></div>';
- echo '</fieldset>';
- echo '<fieldset class="tblFooters">';
- echo '<input type="submit" value="' . __('Go') . '" />';
- echo '</fieldset>';
- echo '</div>';
- echo '</form>';
- }
- // Start of form for multi-rows edit/delete/export
- if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
- echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
- if ($GLOBALS['cfg']['AjaxEnable']) {
- echo ' class="ajax" ';
- }
- echo '>' . "\n";
- echo PMA_generate_common_hidden_inputs($db, $table, 1);
- echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
- }
- echo '<table id="table_results" class="data';
- if ($GLOBALS['cfg']['AjaxEnable']) {
- echo ' ajax';
- }
- echo '">' . "\n";
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- echo '<thead><tr>' . "\n";
- }
- // 1. Displays the full/partial text button (part 1)...
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
- ? ' colspan="4"'
- : '';
- } else {
- $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
- ? ' rowspan="4"'
- : '';
- }
- // ... before the result table
- if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
- && $is_display['text_btn'] == '1'
- ) {
- $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- ?>
- <th colspan="<?php echo $fields_cnt; ?>"></th>
- </tr>
- <tr>
- <?php
- // end horizontal/horizontalflipped mode
- } else {
- ?>
- <tr>
- <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
- </tr>
- <?php
- } // end vertical mode
- }
- // ... at the left column of the result table header if possible
- // and required
- elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
- && $is_display['text_btn'] == '1'
- ) {
- $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- ?>
- <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
- <?php
- // end horizontal/horizontalflipped mode
- } else {
- $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
- . ' ' . "\n"
- . ' </th>' . "\n";
- } // end vertical mode
- }
- // ... elseif no button, displays empty(ies) col(s) if required
- elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
- && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
- $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- ?>
- <td<?php echo $colspan; ?>></td>
- <?php
- // end horizontal/horizontalfipped mode
- } else {
- $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
- } // end vertical mode
- }
- // ... elseif display an empty column if the actions links are disabled to match the rest of the table
- elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none'
- && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
- ) {
- echo '<th></th>';
- }
- // 2. Displays the fields' name
- // 2.0 If sorting links should be used, checks if the query is a "JOIN"
- // statement (see 2.1.3)
- // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
- // Do not show comments, if using horizontalflipped mode, because of space usage
- if ($GLOBALS['cfg']['ShowBrowseComments']
- && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped'
- ) {
- $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($db, $tb);
- unset($tb);
- }
- }
- }
- if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
- include_once './libraries/transformations.lib.php';
- $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
- }
- // See if we have to highlight any header fields of a WHERE query.
- // Uses SQL-Parser results.
- $highlight_columns = array();
- if (isset($analyzed_sql) && isset($analyzed_sql[0])
- && isset($analyzed_sql[0]['where_clause_identifiers'])
- ) {
- $wi = 0;
- if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
- foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
- $highlight_columns[$wci] = 'true';
- }
- }
- }
- if (PMA_isSelect()) {
- // prepare to get the column order, if available
- $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
- $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
- $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
- } else {
- $col_order = false;
- $col_visib = false;
- }
- for ($j = 0; $j < $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.
- if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
- $condition_field = true;
- } else {
- $condition_field = false;
- }
- // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
- if (isset($comments_map)
- && isset($comments_map[$fields_meta[$i]->table])
- && isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])
- ) {
- $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
- } else {
- $comments = '';
- }
- // 2.1 Results can be sorted
- if ($is_display['sort_lnk'] == '1') {
- // 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`
- if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
- $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
- } else {
- $sort_tbl = '';
- }
- // 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);
- if (empty($sort_expression)) {
- $is_in_sort = false;
- } else {
- // Field name may be preceded by a space, or any number
- // of characters followed by a dot (tablename.fieldname)
- // so do a direct comparison for the sort expression;
- // this avoids problems with queries like
- // "SELECT id, count(id)..." and clicking to sort
- // on id or on count(id).
- // Another query to test this:
- // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
- // (and try clicking on each column's header twice)
- if (! empty($sort_tbl)
- && strpos($sort_expression_nodirection, $sort_tbl) === false
- && strpos($sort_expression_nodirection, '(') === false
- ) {
- $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
- }
- $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
- }
- // 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 . PMA_backquote($name_to_use_in_sort) . ' ';
- }
- unset($name_to_use_in_sort);
- unset($is_orgname);
- // 2.1.4 Do define the sorting URL
- if (! $is_in_sort) {
- // patch #455484 ("Smart" order)
- $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
- if ($GLOBALS['cfg']['Order'] === 'SMART') {
- $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
- } else {
- $sort_order .= $GLOBALS['cfg']['Order'];
- }
- $order_img = '';
- } elseif ('DESC' == $sort_direction) {
- $sort_order .= ' ASC';
- $order_img = ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg$i", 'title' => ''));
- $order_img .= ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg$i hide", 'title' => ''));
- } else {
- $sort_order .= ' DESC';
- $order_img = ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg$i", 'title' => ''));
- $order_img .= ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg$i hide", 'title' => ''));
- }
- 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' => $db,
- 'table' => $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_params = array();
- if (isset($order_img) && $order_img!='') {
- if (strstr($order_img, 'asc')) {
- $order_link_params['onmouseover'] = "$('.soimg$i').toggle()";
- $order_link_params['onmouseout'] = "$('.soimg$i').toggle()";
- } elseif (strstr($order_img, 'desc')) {
- $order_link_params['onmouseover'] = "$('.soimg$i').toggle()";
- $order_link_params['onmouseout'] = "$('.soimg$i').toggle()";
- }
- }
- if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
- if (PMA_USR_BROWSER_AGENT == 'IE') {
- $GLOBALS['cfg']['HeaderFlipType'] = 'css';
- } else {
- $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
- }
- }
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- && $GLOBALS['cfg']['HeaderFlipType'] == 'css'
- ) {
- $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
- }
- $order_link_params['title'] = __('Sort');
- $order_link_content = ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
- $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- echo '<th';
- $th_class = array();
- $th_class[] = 'draggable';
- if ($col_visib && !$col_visib[$j]) {
- $th_class[] = 'hide';
- }
- if ($condition_field) {
- $th_class[] = 'condition';
- }
- $th_class[] = 'column_heading';
- if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
- $th_class[] = 'pointer';
- }
- if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
- $th_class[] = 'marker';
- }
- echo ' class="' . implode(' ', $th_class) . '"';
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
- echo ' valign="bottom"';
- }
- echo '>' . $order_link . $comments . '</th>';
- }
- $vertical_display['desc'][] = ' <th '
- . 'class="draggable'
- . ($condition_field ? ' condition' : '')
- . '">' . "\n"
- . $order_link . $comments . ' </th>' . "\n";
- } // end if (2.1)
- // 2.2 Results can't be sorted
- else {
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- echo '<th';
- $th_class = array();
- $th_class[] = 'draggable';
- if ($col_visib && !$col_visib[$j]) {
- $th_class[] = 'hide';
- }
- if ($condition_field) {
- $th_class[] = 'condition';
- }
- echo ' class="' . implode(' ', $th_class) . '"';
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
- echo ' valign="bottom"';
- }
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- && $GLOBALS['cfg']['HeaderFlipType'] == 'css'
- ) {
- echo ' style="direction: ltr; writing-mode: tb-rl;"';
- }
- echo '>';
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'
- ) {
- echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
- } else {
- echo htmlspecialchars($fields_meta[$i]->name);
- }
- echo "\n" . $comments . '</th>';
- }
- $vertical_display['desc'][] = ' <th '
- . 'class="draggable'
- . ($condition_field ? ' condition"' : '')
- . '">' . "\n"
- . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
- . $comments . ' </th>';
- } // 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'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
- && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
- && $is_display['text_btn'] == '1'
- ) {
- $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
- if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
- || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
- ) {
- echo "\n";
- ?>
- <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
- </th>
- <?php
- // end horizontal/horizontalflipped mode
- } else {
- $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
- …
Large files files are truncated, but you can click here to view the full file