/pma/libraries/display_tbl.lib.php
PHP | 2316 lines | 1527 code | 238 blank | 551 comment | 622 complexity | b74bfdb4cbd90be77285bdfcee93f5db MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0, LGPL-2.1
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
- *
- * @version $Id: display_tbl.lib.php 12390 2009-05-04 16:05:24Z lem9 $
- * @package phpMyAdmin
- */
- /**
- *
- */
- require_once './libraries/Table.class.php';
- 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 synthetic value for display_mode (see a few
- * lines above for explanations)
- * @param integer 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') {
- // 2.0 Print view -> set all elements to false!
- if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
- $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';
- }
- // 2.1 Statement is a "SELECT COUNT", a
- // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
- // contains a "PROC ANALYSE" part
- elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
- $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';
- }
- // 2.2 Statement is a "SHOW..."
- elseif ($GLOBALS['is_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';
- }
- // 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)
- else {
- $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, true);
- }
- // 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)) {
- // garvin: 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
- /**
- * Displays a navigation bar to browse among the results of a SQL query
- *
- * @uses $_SESSION['userconf']['disp_direction']
- * @uses $_SESSION['userconf']['repeat_cells']
- * @uses $_SESSION['userconf']['max_rows']
- * @uses $_SESSION['userconf']['pos']
- * @param integer the offset for the "next" page
- * @param integer the offset for the "previous" page
- * @param string the URL-encoded query
- *
- * @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)
- {
- 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="2" cellspacing="0">
- <tr>
- <?php
- // Move to the beginning or to the previous page
- if ($_SESSION['userconf']['pos'] && $_SESSION['userconf']['max_rows'] != 'all') {
- // loic1: patch #474210 from Gosha Sakovich - part 1
- if ($GLOBALS['cfg']['NavigationBarIconic']) {
- $caption1 = '<<';
- $caption2 = ' < ';
- $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
- $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
- } else {
- $caption1 = $GLOBALS['strPos1'] . ' <<';
- $caption2 = $GLOBALS['strPrevious'] . ' <';
- $title1 = '';
- $title2 = '';
- } // end if... else...
- ?>
- <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="goto" value="<?php echo $goto; ?>" />
- <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
- </form>
- </td>
- <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="<?php echo $pos_prev; ?>" />
- <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
- <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
- </form>
- </td>
- <?php
- } // end move back
- ?>
- <td>
-
- </td>
- <td align="center">
- <?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 ?>
- <form action="sql.php" method="post"
- onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 1) && checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 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" value="<?php echo $GLOBALS['strShow']; ?> :" />
- <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['userconf']['max_rows'] != 'all') ? $_SESSION['userconf']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
- <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
- <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
- <br />
- <?php
- // Display mode (horizontal/vertical and repeat headers)
- $param1 = ' <select name="disp_direction">' . "\n"
- . ' <option value="horizontal"' . (($_SESSION['userconf']['disp_direction'] == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
- . ' <option value="horizontalflipped"' . (($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
- . ' <option value="vertical"' . (($_SESSION['userconf']['disp_direction'] == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
- . ' </select>' . "\n"
- . ' ';
- $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['userconf']['repeat_cells'] . '" class="textfield" />' . "\n"
- . ' ';
- echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
- ?>
- </form>
- </td>
- <td>
-
- </td>
- <?php
- // Move to the next page or to the last one
- if (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['userconf']['max_rows']
- && $_SESSION['userconf']['max_rows'] != 'all') {
- // loic1: patch #474210 from Gosha Sakovich - part 2
- if ($GLOBALS['cfg']['NavigationBarIconic']) {
- $caption3 = ' > ';
- $caption4 = '>>';
- $title3 = ' title="' . $GLOBALS['strNext'] . '"';
- $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
- } else {
- $caption3 = '> ' . $GLOBALS['strNext'];
- $caption4 = '>> ' . $GLOBALS['strEnd'];
- $title3 = '';
- $title4 = '';
- } // end if... else...
- 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="<?php echo $pos_next; ?>" />
- <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
- <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
- </form>
- </td>
- <td>
- <form action="sql.php" method="post"
- onsubmit="return <?php echo (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['userconf']['max_rows']) ? 'true' : 'false'); ?>">
- <?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 @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows'])- 1) * $_SESSION['userconf']['max_rows']); ?>" />
- <?php
- if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
- echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
- // no backquote around this message
- $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
- }
- ?>
- <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
- <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> <?php echo (empty($onclick) ? '' : $onclick); ?>/>
- </form>
- </td>
- <?php
- } // end move toward
- //page redirection
- // (unless we are showing all records)
- if ('all' != $_SESSION['userconf']['max_rows']) { //if1
- $pageNow = @floor($_SESSION['userconf']['pos'] / $_SESSION['userconf']['max_rows']) + 1;
- $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['userconf']['max_rows']);
- if ($nbTotalPage > 1){ //if2
- ?>
- <td>
-
- </td>
- <td>
- <?php //<form> for keep the form alignment of button < and << ?>
- <form action="none">
- <?php
- $_url_params = array(
- 'db' => $db,
- 'table' => $table,
- 'sql_query' => $sql_query,
- 'goto' => $goto,
- );
- echo PMA_pageselector(
- 'sql.php' . PMA_generate_common_url($_url_params) . PMA_get_arg_separator('js'),
- $_SESSION['userconf']['max_rows'],
- $pageNow,
- $nbTotalPage,
- 200,
- 5,
- 5,
- 20,
- 10,
- $GLOBALS['strPageNumber']
- );
- ?>
- </form>
- </td>
- <?php
- } //_if2
- } //_if1
- // Display the "Show all" button if allowed
- if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
- echo "\n";
- ?>
- <td>
-
- </td>
- <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 $GLOBALS['strShowAll']; ?>" />
- </form>
- </td>
- <?php
- } // end show all
- echo "\n";
- ?>
- </tr>
- </table>
- <?php
- } // end of the 'PMA_displayTableNavigation()' function
- /**
- * Displays the headers of the results table
- *
- * @uses $_SESSION['userconf']['disp_direction']
- * @uses $_SESSION['userconf']['repeat_cells']
- * @uses $_SESSION['userconf']['max_rows']
- * @uses $_SESSION['userconf']['display_text']
- * @uses $_SESSION['userconf']['display_binary']
- * @param array which elements to display
- * @param array the list of fields properties
- * @param integer the total number of fields returned by the SQL query
- * @param array the analyzed query
- *
- * @return boolean always true
- *
- * @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;
- 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['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['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['userconf']['repeat_cells']) + 1;
- }
- echo '<form action="sql.php" method="post">' . "\n";
- echo PMA_generate_common_hidden_inputs($db, $table);
- echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\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;
- echo '<option value="'
- . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
- . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
- . '>' . htmlspecialchars($index->getName()) . ' ('
- . $GLOBALS['strAscending'] . ')</option>';
- echo '<option value="'
- . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
- . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
- . '>' . htmlspecialchars($index->getName()) . ' ('
- . $GLOBALS['strDescending'] . ')</option>';
- }
- echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
- echo '</select>' . "\n";
- echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
- echo '</form>' . "\n";
- }
- }
- }
- $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">';
- $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',$GLOBALS['strOptions']);
- echo '<fieldset>';
- echo '<div class="formelement">';
- $choices = array(
- 'P' => $GLOBALS['strPartialText'],
- 'F' => $GLOBALS['strFullText']
- );
- PMA_generate_html_radio('display_text', $choices, $_SESSION['userconf']['display_text']);
- echo '</div>';
- if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
- echo '<div class="formelement">';
- $choices = array(
- 'K' => $GLOBALS['strRelationalKey'],
- 'D' => $GLOBALS['strRelationalDisplayField']
- );
- PMA_generate_html_radio('relational_display', $choices, $_SESSION['userconf']['relational_display']);
- echo '</div>';
- }
- echo '<div class="formelement">';
- PMA_generate_html_checkbox('display_binary', $GLOBALS['strShowBinaryContents'], ! empty($_SESSION['userconf']['display_binary']), false);
- echo '<br />';
- PMA_generate_html_checkbox('display_blob', $GLOBALS['strShowBLOBContents'], ! empty($_SESSION['userconf']['display_blob']), 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_generate_html_checkbox('hide_transformation', $GLOBALS['strHide'] . ' ' . $GLOBALS['strMIME_transformation'], ! empty($_SESSION['userconf']['hide_transformation']), false);
- echo '</div>';
- echo '<div class="clearfloat"></div>';
- echo '</fieldset>';
- echo '<fieldset class="tblFooters">';
- echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
- 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="rowsDeleteForm" id="rowsDeleteForm">' . "\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">' . "\n";
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- echo '<thead><tr>' . "\n";
- }
- // 1. Displays the full/partial text button (part 1)...
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
- ? ' colspan="3"'
- : '';
- } else {
- $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
- ? ' rowspan="3"'
- : '';
- }
- // ... 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') ? 3 : 0;
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['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['userconf']['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']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
- $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- ?>
- <th <?php echo $colspan; ?>></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']['ModifyDeleteAtLeft']
- && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
- $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- ?>
- <td<?php echo $colspan; ?>></td>
- <?php
- } // end horizontal/horizontalfipped mode
- else {
- $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
- } // end vertical mode
- }
- // 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['userconf']['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['userconf']['hide_transformation']) {
- require_once './libraries/transformations.lib.php';
- $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
- }
- if ($is_display['sort_lnk'] == '1') {
- $select_expr = $analyzed_sql[0]['select_expr_clause'];
- }
- // garvin: 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';
- }
- }
- }
- for ($i = 0; $i < $fields_cnt; $i++) {
- // garvin: 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;
- if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
- $name_to_use_in_sort = $fields_meta[$i]->orgname;
- }
- // $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 (avoids problems with queries
- // like "SELECT id, count(id)..." and clicking to sort
- // on id or on count(id))
- if (strpos($sort_expression_nodirection, $sort_tbl) === 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`)'
- if (strpos($name_to_use_in_sort, '(') !== false) {
- $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
- } else {
- $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
- }
- unset($name_to_use_in_sort);
- // 2.1.4 Do define the sorting URL
- if (! $is_in_sort) {
- // loic1: 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 = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
- } else {
- $sort_order .= ' DESC';
- $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
- }
- if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $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,
- );
- $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
- // 2.1.5 Displays the sorting URL
- // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
- // 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'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
- $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
- } elseif (strstr($order_img, 'desc')) {
- $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
- $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
- }
- }
- if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
- && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
- $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
- }
- $order_link_params['title'] = $GLOBALS['strSort'];
- $order_link_content = ($_SESSION['userconf']['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['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- echo '<th';
- if ($condition_field) {
- echo ' class="condition"';
- }
- if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- echo ' valign="bottom"';
- }
- echo '>' . $order_link . $comments . '</th>';
- }
- $vertical_display['desc'][] = ' <th '
- . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
- . $order_link . $comments . ' </th>' . "\n";
- } // end if (2.1)
- // 2.2 Results can't be sorted
- else {
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- echo '<th';
- if ($condition_field) {
- echo ' class="condition"';
- }
- if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- echo ' valign="bottom"';
- }
- if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
- && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
- echo ' style="direction: ltr; writing-mode: tb-rl;"';
- }
- echo '>';
- if ($_SESSION['userconf']['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 '
- . ($condition_field ? ' class="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']['ModifyDeleteAtRight']
- && ($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') ? 3 : 1;
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- echo "\n";
- ?>
- <th <?php echo $colspan; ?>>
- </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 columns if required
- // (unless coming from Browse mode print view)
- elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
- && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
- && (!$GLOBALS['is_header_sent'])) {
- $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- echo "\n";
- ?>
- <td<?php echo $colspan; ?>></td>
- <?php
- } // end horizontal/horizontalflipped mode
- else {
- $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
- } // end vertical mode
- }
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- ?>
- </tr>
- </thead>
- <?php
- }
- return true;
- } // end of the 'PMA_displayTableHeaders()' function
- /**
- * Displays the body of the results table
- *
- * @uses $_SESSION['userconf']['disp_direction']
- * @uses $_SESSION['userconf']['repeat_cells']
- * @uses $_SESSION['userconf']['max_rows']
- * @uses $_SESSION['userconf']['display_text']
- * @uses $_SESSION['userconf']['display_binary']
- * @uses $_SESSION['userconf']['display_blob']
- * @param integer the link id associated to the query which results have
- * to be displayed
- * @param array which elements to display
- * @param array the list of relations
- * @param array the analyzed query
- *
- * @return boolean always true
- *
- * @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 array $fields_meta the list of fields properties
- * @global integer $fields_cnt the total number of fields returned by
- * the SQL query
- * @global array $vertical_display informations used with vertical display
- * mode
- * @global array $highlight_columns column names to highlight
- * @global array $row current row data
- *
- * @access private
- *
- * @see PMA_displayTable()
- */
- function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
- global $db, $table, $goto;
- global $sql_query, $fields_meta, $fields_cnt;
- global $vertical_display, $highlight_columns;
- global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
- $url_sql_query = $sql_query;
- // query without conditions to shorten URLs when needed, 200 is just
- // guess, it should depend on remaining URL length
- if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
- isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
- strlen($sql_query) > 200) {
- $url_sql_query = 'SELECT ';
- if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
- $url_sql_query .= ' DISTINCT ';
- }
- $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
- if (!empty($analyzed_sql[0]['from_clause'])) {
- $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
- }
- }
- if (!is_array($map)) {
- $map = array();
- }
- $row_no = 0;
- $vertical_display['edit'] = array();
- $vertical_display['delete'] = array();
- $vertical_display['data'] = array();
- $vertical_display['row_delete'] = array();
- // Correction University of Virginia 19991216 in the while below
- // Previous code assumed that all tables have keys, specifically that
- // the phpMyAdmin GUI should support row delete/edit only for such
- // tables.
- // Although always using keys is arguably the prescribed way of
- // defining a relational table, it is not required. This will in
- // particular be violated by the novice.
- // We want to encourage phpMyAdmin usage by such novices. So the code
- // below has been changed to conditionally work as before when the
- // table being displayed has one or more keys; but to display
- // delete/edit options correctly for tables without keys.
- $odd_row = true;
- while ($row = PMA_DBI_fetch_row($dt_result)) {
- // lem9: "vertical display" mode stuff
- if ($row_no != 0 && $_SESSION['userconf']['repeat_cells'] != 0 && !($row_no % $_SESSION['userconf']['repeat_cells'])
- && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped'))
- {
- echo '<tr>' . "\n";
- if ($vertical_display['emptypre'] > 0) {
- echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
- .' </th>' . "\n";
- }
- foreach ($vertical_display['desc'] as $val) {
- echo $val;
- }
- if ($vertical_display['emptyafter'] > 0) {
- echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
- .' </th>' . "\n";
- }
- echo '</tr>' . "\n";
- } // end if
- $class = $odd_row ? 'odd' : 'even';
- $odd_row = ! $odd_row;
- if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
- || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
- // loic1: pointer code part
- echo ' <tr class="' . $class . '">' . "\n";
- $class = '';
- }
- // 1. Prepares the row (gets primary keys to use)
- // 1.1 Results from a "SELECT" statement -> builds the
- // "primary" key to use in links
- /**
- * @todo $unique_condition could be empty, for example a table
- * with only one field and it's a BLOB; in this case,
- * avoid to display the delete and edit links
- */
- $unique_condition = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
- $unique_condition_html = urlencode($unique_condition);
- // 1.2 Defines the URLs for the modify/delete link(s)
- if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
- // We need to copy the value or else the == 'both' check will always return true
- if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
- $iconic_spacer = '<div class="nowrap">';
- } else {
- $iconic_spacer = '';
- }
- // 1.2.1 Modify link(s)
- if ($is_display['edit_lnk'] == 'ur') { // update row case
- $_url_params = array(
- 'db' => $db,
- 'table' => $table,
- 'primary_key' => $unique_condition,
- 'sql_query' => $url_sql_query,
- 'goto' => 'sql.php',
- );
- $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
- $edit_str = PMA_getIcon('b_edit.png', …
Large files files are truncated, but you can click here to view the full file