[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libraries/ -> display_tbl.lib.php (source)

   1  <?php
   2  /* $Id: display_tbl.lib.php 10479 2007-07-10 15:01:45Z lem9 $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  require_once  './libraries/Table.class.php';
   6  
   7  /**
   8   * Set of functions used to display the records returned by a sql query
   9   */
  10  
  11  /**
  12   * Avoids undefined variables
  13   */
  14  if (!isset($pos)) {
  15      $pos = 0;
  16  } else {
  17      /* We need this to be a integer */
  18      $pos = (int)$pos;
  19  }
  20  
  21  /**
  22   * Defines the display mode to use for the results of a sql query
  23   *
  24   * It uses a synthetic string that contains all the required informations.
  25   * In this string:
  26   *   - the first two characters stand for the action to do while
  27   *     clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
  28   *     edit link...);
  29   *   - the next two characters stand for the action to do while
  30   *     clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
  31   *     no delete link...);
  32   *   - the next characters are boolean values (1/0) and respectively stand
  33   *     for sorting links, navigation bar, "insert a new row" link, the
  34   *     bookmark feature, the expand/collapse text/blob fields button and
  35   *     the "display printable view" option.
  36   *     Of course '0'/'1' means the feature won't/will be enabled.
  37   *
  38   * @param   string   the synthetic value for display_mode (see �1 a few
  39   *                   lines above for explanations)
  40   * @param   integer  the total number of rows returned by the sql query
  41   *                   without any programmatically appended "LIMIT" clause
  42   *                   (just a copy of $unlim_num_rows if it exists, else
  43   *                   computed inside this function)
  44   *
  45   * @return  array    an array with explicit indexes for all the display
  46   *                   elements
  47   *
  48   * @global  string   the database name
  49   * @global  string   the table name
  50   * @global  integer  the total number of rows returned by the sql query
  51   *                   without any programmatically appended "LIMIT" clause
  52   * @global  array    the properties of the fields returned by the query
  53   * @global  string   the url to return to in case of error in a sql
  54   *                   statement
  55   *
  56   * @access  private
  57   *
  58   * @see     PMA_displayTable()
  59   */
  60  function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
  61  {
  62      global $db, $table;
  63      global $unlim_num_rows, $fields_meta;
  64      global $err_url;
  65  
  66      // 1. Initializes the $do_display array
  67      $do_display              = array();
  68      $do_display['edit_lnk']  = $the_disp_mode[0] . $the_disp_mode[1];
  69      $do_display['del_lnk']   = $the_disp_mode[2] . $the_disp_mode[3];
  70      $do_display['sort_lnk']  = (string) $the_disp_mode[4];
  71      $do_display['nav_bar']   = (string) $the_disp_mode[5];
  72      $do_display['ins_row']   = (string) $the_disp_mode[6];
  73      $do_display['bkm_form']  = (string) $the_disp_mode[7];
  74      $do_display['text_btn']  = (string) $the_disp_mode[8];
  75      $do_display['pview_lnk'] = (string) $the_disp_mode[9];
  76  
  77      // 2. Display mode is not "false for all elements" -> updates the
  78      // display mode
  79      if ($the_disp_mode != 'nnnn000000') {
  80          // 2.0 Print view -> set all elements to false!
  81          if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  82              $do_display['edit_lnk']  = 'nn'; // no edit link
  83              $do_display['del_lnk']   = 'nn'; // no delete link
  84              $do_display['sort_lnk']  = (string) '0';
  85              $do_display['nav_bar']   = (string) '0';
  86              $do_display['ins_row']   = (string) '0';
  87              $do_display['bkm_form']  = (string) '0';
  88              $do_display['text_btn']  = (string) '0';
  89              $do_display['pview_lnk'] = (string) '0';
  90          }
  91          // 2.1 Statement is a "SELECT COUNT", a
  92          //     "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
  93          //     contains a "PROC ANALYSE" part
  94          elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
  95              $do_display['edit_lnk']  = 'nn'; // no edit link
  96              $do_display['del_lnk']   = 'nn'; // no delete link
  97              $do_display['sort_lnk']  = (string) '0';
  98              $do_display['nav_bar']   = (string) '0';
  99              $do_display['ins_row']   = (string) '0';
 100              $do_display['bkm_form']  = (string) '1';
 101              if ($GLOBALS['is_maint']) {
 102                  $do_display['text_btn']  = (string) '1';
 103              } else {
 104                  $do_display['text_btn']  = (string) '0';
 105              }
 106              $do_display['pview_lnk'] = (string) '1';
 107          }
 108          // 2.2 Statement is a "SHOW..."
 109          elseif ($GLOBALS['is_show']) {
 110              /**
 111               * 2.2.1
 112               * @todo defines edit/delete links depending on show statement
 113               */
 114              $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
 115              if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
 116                  $do_display['edit_lnk'] = 'nn'; // no edit link
 117                  $do_display['del_lnk']  = 'kp'; // "kill process" type edit link
 118              } else {
 119                  // Default case -> no links
 120                  $do_display['edit_lnk'] = 'nn'; // no edit link
 121                  $do_display['del_lnk']  = 'nn'; // no delete link
 122              }
 123              // 2.2.2 Other settings
 124              $do_display['sort_lnk']  = (string) '0';
 125              $do_display['nav_bar']   = (string) '0';
 126              $do_display['ins_row']   = (string) '0';
 127              $do_display['bkm_form']  = (string) '1';
 128              $do_display['text_btn']  = (string) '1';
 129              $do_display['pview_lnk'] = (string) '1';
 130          }
 131          // 2.3 Other statements (ie "SELECT" ones) -> updates
 132          //     $do_display['edit_lnk'], $do_display['del_lnk'] and
 133          //     $do_display['text_btn'] (keeps other default values)
 134          else {
 135              $prev_table = $fields_meta[0]->table;
 136              $do_display['text_btn']  = (string) '1';
 137              for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
 138                  $is_link = ($do_display['edit_lnk'] != 'nn'
 139                              || $do_display['del_lnk'] != 'nn'
 140                              || $do_display['sort_lnk'] != '0'
 141                              || $do_display['ins_row'] != '0');
 142                  // 2.3.2 Displays edit/delete/sort/insert links?
 143                  if ($is_link
 144                      && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
 145                      $do_display['edit_lnk'] = 'nn'; // don't display links
 146                      $do_display['del_lnk']  = 'nn';
 147                      /**
 148                       * @todo May be problematic with same fields names in two joined table.
 149                       */
 150                      // $do_display['sort_lnk'] = (string) '0';
 151                      $do_display['ins_row']  = (string) '0';
 152                      if ($do_display['text_btn'] == '1') {
 153                          break;
 154                      }
 155                  } // end if (2.3.2)
 156                  // 2.3.3 Always display print view link
 157                  $do_display['pview_lnk']    = (string) '1';
 158                  $prev_table = $fields_meta[$i]->table;
 159              } // end for
 160          } // end if..elseif...else (2.1 -> 2.3)
 161      } // end if (2)
 162  
 163      // 3. Gets the total number of rows if it is unknown
 164      if (isset($unlim_num_rows) && $unlim_num_rows != '') {
 165          $the_total = $unlim_num_rows;
 166      } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
 167               && (isset($db) && strlen($db) && !empty($table))) {
 168          $the_total   = PMA_Table::countRecords($db, $table, true);
 169      }
 170  
 171      // 4. If navigation bar or sorting fields names urls should be
 172      //    displayed but there is only one row, change these settings to
 173      //    false
 174      if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
 175  
 176          // - Do not display sort links if less than 2 rows.
 177          // - For a VIEW we (probably) did not count the number of rows
 178          //   so don't test this number here, it would remove the possibility
 179          //   of sorting VIEW results.
 180          if (isset($unlim_num_rows) && $unlim_num_rows < 2  && ! PMA_Table::isView($db, $table)) {
 181              // garvin: force display of navbar for vertical/horizontal display-choice.
 182              // $do_display['nav_bar']  = (string) '0';
 183              $do_display['sort_lnk'] = (string) '0';
 184          }
 185  
 186      } // end if (3)
 187  
 188      // 5. Updates the synthetic var
 189      $the_disp_mode = join('', $do_display);
 190  
 191      return $do_display;
 192  } // end of the 'PMA_setDisplayMode()' function
 193  
 194  
 195  /**
 196   * Displays a navigation bar to browse among the results of a sql query
 197   *
 198   * @param   integer  the offset for the "next" page
 199   * @param   integer  the offset for the "previous" page
 200   * @param   string   the url-encoded query
 201   *
 202   * @global  string   $db             the database name
 203   * @global  string   $table          the table name
 204   * @global  string   $goto           the url to go back in case of errors
 205   * @global  boolean  $dontlimitchars whether to limit the number of displayed
 206   *                                   characters  of text type fields or not
 207   * @global  integer  $num_rows       the total number of rows returned by the
 208   *                                   sql query
 209   * @global  integer  $unlim_num_rows the total number of rows returned by the
 210   *                                   sql any programmatically appended "LIMIT" clause
 211   * @global  integer  $pos            the current position in results
 212   * @global  mixed    $session_max_rows the maximum number of rows per page
 213   *                                   ('all'  = no limit)
 214   * @global  string   $disp_direction the display mode
 215   *                                   (horizontal / vertical / horizontalflipped)
 216   * @global  integer  $repeat_cells   the number of row to display between two
 217   *                                   table headers
 218   * @global  boolean  $is_innodb      whether its InnoDB or not
 219   * @global  array    $showtable      table definitions
 220   *
 221   * @access  private
 222   *
 223   * @see     PMA_displayTable()
 224   */
 225  function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
 226  {
 227      global $db, $table, $goto, $dontlimitchars;
 228      global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
 229      global $disp_direction, $repeat_cells;
 230      global $is_innodb;
 231      global $showtable;
 232  
 233      /**
 234       * @todo move this to a central place
 235       * @todo for other future table types
 236       */
 237      $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
 238  
 239      ?>
 240  
 241  <!-- Navigation bar -->
 242  <table border="0" cellpadding="2" cellspacing="0">
 243  <tr>
 244      <?php
 245      // Move to the beginning or to the previous page
 246      if ($pos > 0 && $session_max_rows != 'all') {
 247          // loic1: patch #474210 from Gosha Sakovich - part 1
 248          if ($GLOBALS['cfg']['NavigationBarIconic']) {
 249              $caption1 = '&lt;&lt;';
 250              $caption2 = ' &lt; ';
 251              $title1   = ' title="' . $GLOBALS['strPos1'] . '"';
 252              $title2   = ' title="' . $GLOBALS['strPrevious'] . '"';
 253          } else {
 254              $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
 255              $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
 256              $title1   = '';
 257              $title2   = '';
 258          } // end if... else...
 259          ?>
 260  <td>
 261      <form action="sql.php" method="post">
 262          <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 263          <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 264          <input type="hidden" name="pos" value="0" />
 265          <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
 266          <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 267          <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 268          <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 269          <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 270          <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
 271      </form>
 272  </td>
 273  <td>
 274      <form action="sql.php" method="post">
 275          <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 276          <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 277          <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
 278          <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
 279          <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 280          <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 281          <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 282          <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 283          <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
 284      </form>
 285  </td>
 286          <?php
 287      } // end move back
 288      ?>
 289  <td>
 290      &nbsp;&nbsp;&nbsp;
 291  </td>
 292  <td align="center">
 293  <?php // if displaying a VIEW, $unlim_num_rows could be zero because
 294        // of $cfg['MaxExactCountViews']; in this case, avoid passing
 295        // the 5th parameter to checkFormElementInRange() 
 296        // (this means we can't validate the upper limit ?>
 297      <form action="sql.php" method="post"
 298  onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 1) &amp;&amp; checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
 299          <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 300          <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 301          <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 302          <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 303          <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
 304          <input type="text" name="session_max_rows" size="3" value="<?php echo (($session_max_rows != 'all') ? $session_max_rows : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
 305          <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
 306          <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
 307          <br />
 308      <?php
 309      // Display mode (horizontal/vertical and repeat headers)
 310      $param1 = '            <select name="disp_direction">' . "\n"
 311              . '                <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
 312              . '                <option value="horizontalflipped"' . (($disp_direction == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
 313              . '                <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
 314              . '            </select>' . "\n"
 315              . '           ';
 316      $param2 = '            <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" class="textfield" />' . "\n"
 317              . '           ';
 318      echo '    ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
 319      ?>
 320      </form>
 321  </td>
 322  <td>
 323      &nbsp;&nbsp;&nbsp;
 324  </td>
 325      <?php
 326      // Move to the next page or to the last one
 327      if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
 328          && $session_max_rows != 'all') {
 329          // loic1: patch #474210 from Gosha Sakovich - part 2
 330          if ($GLOBALS['cfg']['NavigationBarIconic']) {
 331              $caption3 = ' &gt; ';
 332              $caption4 = '&gt;&gt;';
 333              $title3   = ' title="' . $GLOBALS['strNext'] . '"';
 334              $title4   = ' title="' . $GLOBALS['strEnd'] . '"';
 335          } else {
 336              $caption3 = '&gt; ' . $GLOBALS['strNext'];
 337              $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
 338              $title3   = '';
 339              $title4   = '';
 340          } // end if... else...
 341          echo "\n";
 342          ?>
 343  <td>
 344      <form action="sql.php" method="post">
 345          <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 346          <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 347          <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
 348          <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
 349          <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 350          <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 351          <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 352          <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 353          <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
 354      </form>
 355  </td>
 356  <td>
 357      <form action="sql.php" method="post"
 358          onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
 359          <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 360          <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 361          <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $session_max_rows)- 1) * $session_max_rows); ?>" />
 362          <?php
 363          if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
 364              echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
 365              // no backquote around this message
 366              $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
 367          }
 368          ?>
 369          <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
 370          <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 371          <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 372          <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 373          <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 374          <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> <?php echo (empty($onclick) ? '' : $onclick); ?>/>
 375      </form>
 376  </td>
 377          <?php
 378      } // end move toward
 379  
 380  
 381      //page redirection
 382      $pageNow = @floor($pos / $session_max_rows) + 1;
 383      $nbTotalPage = @ceil($unlim_num_rows / $session_max_rows);
 384  
 385      if ($nbTotalPage > 1){ //if1
 386         ?>
 387     <td>
 388         &nbsp;&nbsp;&nbsp;
 389     </td>
 390     <td>
 391          <?php //<form> for keep the form alignment of button < and << ?>
 392          <form action="none">
 393          <?php echo PMA_pageselector(
 394                       'sql.php?sql_query='        . $encoded_query .
 395                          '&amp;session_max_rows=' . $session_max_rows .
 396                          '&amp;disp_direction='   . $disp_direction .
 397                          '&amp;repeat_cells='     . $repeat_cells .
 398                          '&amp;goto='             . $goto .
 399                          '&amp;dontlimitchars='   . $dontlimitchars .
 400                          '&amp;'                  . PMA_generate_common_url($db, $table) .
 401                          '&amp;',
 402                       $session_max_rows,
 403                       $pageNow,
 404                       $nbTotalPage
 405                );
 406          ?>
 407          </form>
 408      </td>
 409          <?php
 410      } //_if1
 411  
 412  
 413      // Show all the records if allowed
 414      if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
 415          echo "\n";
 416          ?>
 417  <td>
 418      &nbsp;&nbsp;&nbsp;
 419  </td>
 420  <td>
 421      <form action="sql.php" method="post">
 422          <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 423          <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 424          <input type="hidden" name="pos" value="0" />
 425          <input type="hidden" name="session_max_rows" value="all" />
 426          <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 427          <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 428          <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 429          <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 430          <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
 431      </form>
 432  </td>
 433          <?php
 434      } // end show all
 435      echo "\n";
 436      ?>
 437  </tr>
 438  </table>
 439  
 440      <?php
 441  } // end of the 'PMA_displayTableNavigation()' function
 442  
 443  
 444  /**
 445   * Displays the headers of the results table
 446   *
 447   * @param   array    which elements to display
 448   * @param   array    the list of fields properties
 449   * @param   integer  the total number of fields returned by the sql query
 450   * @param   array    the analyzed query
 451   *
 452   * @return  boolean  always true
 453   *
 454   * @global  string   $db               the database name
 455   * @global  string   $table            the table name
 456   * @global  string   $goto             the url to go back in case of errors
 457   * @global  boolean  $dontlimitchars   whether to limit the number of displayed
 458   *                                     characters of text type fields or not
 459   * @global  string   $sql_query        the sql query
 460   * @global  integer  $num_rows         the total number of rows returned by the
 461   *                                     sql query
 462   * @global  integer  $pos              the current position in results
 463   * @global  integer  $session_max_rows the maximum number of rows per page
 464   * @global  array    $vertical_display informations used with vertical display
 465   *                                     mode
 466   * @global  string   $disp_direction   the display mode
 467   *                                     (horizontal/vertical/horizontalflipped)
 468   * @global  integer  $repeat_cellsthe  number of row to display between two
 469   *                                     table headers
 470   *
 471   * @access  private
 472   *
 473   * @see     PMA_displayTable()
 474   */
 475  function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
 476  {
 477      global $db, $table, $goto, $dontlimitchars;
 478      global $sql_query, $num_rows, $pos, $session_max_rows;
 479      global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
 480  
 481      if ($analyzed_sql == '') {
 482          $analyzed_sql = array();
 483      }
 484  
 485      // can the result be sorted?
 486      if ($is_display['sort_lnk'] == '1') {
 487  
 488          // Just as fallback
 489          $unsorted_sql_query     = $sql_query;
 490          if (isset($analyzed_sql[0]['unsorted_query'])) {
 491              $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
 492          }
 493  
 494          // we need $sort_expression and $sort_expression_nodir
 495          // even if there are many table references
 496  
 497          $sort_expression = trim(str_replace('  ', ' ', $analyzed_sql[0]['order_by_clause']));
 498  
 499          /**
 500           * Get rid of ASC|DESC
 501           * @todo analyzer
 502           */
 503          preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
 504          $sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
 505  
 506          // sorting by indexes, only if it makes sense (only one table ref)
 507          if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
 508              isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
 509              isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
 510  
 511              // grab indexes data:
 512              PMA_DBI_select_db($db);
 513              if (!defined('PMA_IDX_INCLUDED')) {
 514                  $ret_keys = PMA_get_indexes($table);
 515              }
 516  
 517              $prev_index = '';
 518              foreach ($ret_keys as $row) {
 519  
 520                  if ($row['Key_name'] != $prev_index){
 521                      $indexes[]  = $row['Key_name'];
 522                      $prev_index = $row['Key_name'];
 523                  }
 524                  $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
 525                  $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
 526                  if (isset($row['Cardinality'])) {
 527                      $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
 528                  }
 529              //    I don't know what does the following column mean....
 530              //    $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
 531                  $indexes_info[$row['Key_name']]['Comment']         = (isset($row['Comment']))
 532                                                                     ? $row['Comment']
 533                                                                     : '';
 534                  $indexes_info[$row['Key_name']]['Index_type']      = (isset($row['Index_type']))
 535                                                                     ? $row['Index_type']
 536                                                                     : '';
 537  
 538                  $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
 539                  if (isset($row['Sub_part'])) {
 540                      $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
 541                  }
 542              } // end while
 543  
 544              // do we have any index?
 545              if (isset($indexes_data)) {
 546  
 547                  if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 548                      $span = $fields_cnt;
 549                      if ($is_display['edit_lnk'] != 'nn') {
 550                          $span++;
 551                      }
 552                      if ($is_display['del_lnk'] != 'nn') {
 553                          $span++;
 554                      }
 555                      if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
 556                          $span++;
 557                      }
 558                  } else {
 559                      $span = $num_rows + floor($num_rows/$repeat_cells) + 1;
 560                  }
 561  
 562                  echo '<form action="sql.php" method="post">' . "\n";
 563                  echo PMA_generate_common_hidden_inputs($db, $table, 5);
 564                  echo '<input type="hidden" name="pos" value="' . $pos .  '" />' . "\n";
 565                  echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
 566                  echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
 567                  echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
 568                  echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
 569                  echo $GLOBALS['strSortByKey'] . ': <select name="sql_query">' . "\n";
 570                  $used_index = false;
 571                  $local_order = (isset($sort_expression) ? $sort_expression : '');
 572                  foreach ($indexes_data AS $key => $val) {
 573                      $asc_sort = '';
 574                      $desc_sort = '';
 575                      foreach ($val AS $key2 => $val2) {
 576                          $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
 577                          $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
 578                      }
 579                      $asc_sort = substr($asc_sort, 0, -3);
 580                      $desc_sort = substr($desc_sort, 0, -3);
 581                      $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
 582                      echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
 583                      echo "\n";
 584                      echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
 585                      echo "\n";
 586                  }
 587                  echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
 588                  echo "\n";
 589                  echo '</select>' . "\n";
 590                  echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
 591                  echo "\n";
 592                  echo '</form>' . "\n";
 593              }
 594          }
 595      }
 596  
 597  
 598      $vertical_display['emptypre']   = 0;
 599      $vertical_display['emptyafter'] = 0;
 600      $vertical_display['textbtn']    = '';
 601  
 602  
 603      // Start of form for multi-rows delete
 604  
 605      if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
 606          echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
 607          echo PMA_generate_common_hidden_inputs($db, $table, 1);
 608          echo '<input type="hidden" name="disp_direction"   value="' . $disp_direction . '" />' . "\n";
 609          echo '<input type="hidden" name="repeat_cells"     value="' . $repeat_cells   . '" />' . "\n";
 610          echo '<input type="hidden" name="dontlimitchars"   value="' . $dontlimitchars . '" />' . "\n";
 611          echo '<input type="hidden" name="pos"              value="' . $pos . '" />' . "\n";
 612          echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
 613          echo '<input type="hidden" name="goto"             value="sql.php" />' . "\n";
 614      }
 615  
 616      echo '<table id="table_results" class="data">' . "\n";
 617      if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 618          echo '<thead><tr>' . "\n";
 619      }
 620  
 621      // 1. Displays the full/partial text button (part 1)...
 622      if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 623          $colspan  = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
 624                    ? ' colspan="3"'
 625                    : '';
 626      } else {
 627          $rowspan  = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
 628                    ? ' rowspan="3"'
 629                    : '';
 630      }
 631      $text_url = 'sql.php?'
 632                . PMA_generate_common_url($db, $table)
 633                . '&amp;sql_query=' . urlencode($sql_query)
 634                . '&amp;session_max_rows=' . $session_max_rows
 635                . '&amp;pos=' . $pos
 636                . '&amp;disp_direction=' . $disp_direction
 637                . '&amp;repeat_cells=' . $repeat_cells
 638                . '&amp;goto=' . $goto
 639                . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
 640      $text_message = '<img class="fulltext" src="' . $GLOBALS['pmaThemeImage'] . 's_'.($dontlimitchars ? 'partialtext' : 'fulltext') . '.png" width="50" height="20" alt="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" />';
 641      $text_link = PMA_linkOrButton($text_url, $text_message, array(), false);
 642  
 643      //     ... before the result table
 644      if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
 645          && $is_display['text_btn'] == '1') {
 646          $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
 647          if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 648              ?>
 649      <th colspan="<?php echo $fields_cnt; ?>"><?php echo $text_link; ?></th>
 650  </tr>
 651  <tr>
 652              <?php
 653          } // end horizontal/horizontalflipped mode
 654          else {
 655              ?>
 656  <tr>
 657      <th colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>">
 658          <?php echo $text_link; ?></th>
 659  </tr>
 660              <?php
 661          } // end vertical mode
 662      }
 663  
 664      //     ... at the left column of the result table header if possible
 665      //     and required
 666      elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
 667          $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
 668          if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 669              ?>
 670      <th <?php echo $colspan; ?>><?php echo $text_link; ?></th>
 671              <?php
 672          } // end horizontal/horizontalflipped mode
 673          else {
 674              $vertical_display['textbtn'] = '    <th ' . $rowspan . ' valign="middle">' . "\n"
 675                                           . '        ' . $text_link . "\n"
 676                                           . '    </th>' . "\n";
 677          } // end vertical mode
 678      }
 679  
 680      //     ... elseif no button, displays empty(ies) col(s) if required
 681      elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
 682               && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
 683          $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
 684          if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 685              ?>
 686      <td<?php echo $colspan; ?>></td>
 687              <?php
 688          } // end horizontal/horizontalfipped mode
 689          else {
 690              $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
 691          } // end vertical mode
 692      }
 693  
 694      // 2. Displays the fields' name
 695      // 2.0 If sorting links should be used, checks if the query is a "JOIN"
 696      //     statement (see 2.1.3)
 697  
 698      // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
 699      //       Do not show comments, if using horizontalflipped mode, because of space usage
 700      if ($GLOBALS['cfg']['ShowBrowseComments'] && ($GLOBALS['cfgRelation']['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) && $disp_direction != 'horizontalflipped') {
 701          $comments_map = array();
 702          if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
 703              foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
 704                  $tb = $tbl['table_true_name'];
 705                  $comments_map[$tb] = PMA_getComments($db, $tb);
 706                  unset($tb);
 707              }
 708          }
 709      }
 710  
 711      if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
 712          require_once  './libraries/transformations.lib.php';
 713          $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
 714      }
 715  
 716      if ($is_display['sort_lnk'] == '1') {
 717          //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt);
 718          $is_join = (isset($analyzed_sql[0]['queryflags']['join']) ? true : false);
 719          $select_expr = $analyzed_sql[0]['select_expr_clause'];
 720      } else {
 721          $is_join = false;
 722      }
 723  
 724      // garvin: See if we have to highlight any header fields of a WHERE query.
 725      //  Uses SQL-Parser results.
 726      $highlight_columns = array();
 727      if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
 728          isset($analyzed_sql[0]['where_clause_identifiers'])) {
 729  
 730          $wi = 0;
 731          if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
 732              foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
 733                  $highlight_columns[$wci] = 'true';
 734              }
 735          }
 736      }
 737  
 738      for ($i = 0; $i < $fields_cnt; $i++) {
 739          // garvin: See if this column should get highlight because it's used in the
 740          //  where-query.
 741          if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
 742              $condition_field = true;
 743          } else {
 744              $condition_field = false;
 745          }
 746  
 747          // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
 748          if (isset($comments_map) &&
 749                  isset($comments_map[$fields_meta[$i]->table]) &&
 750                  isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
 751              $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
 752          } else {
 753              $comments = '';
 754          }
 755  
 756          // 2.1 Results can be sorted
 757          if ($is_display['sort_lnk'] == '1') {
 758  
 759              // 2.1.1 Checks if the table name is required; it's the case
 760              //       for a query with a "JOIN" statement and if the column
 761              //       isn't aliased, or in queries like
 762              //       SELECT `1`.`master_field` , `2`.`master_field`
 763              //       FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
 764              /**
 765               * we prefer always using table if existing
 766               * and second this code does not correctly check $fields_meta[$i]->table
 767              if (($is_join
 768                  && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . strtr($fields_meta[$i]->name, array('[' => '\\[', '~' => '\\~', '\\' => '\\\\')) . '~i', $select_expr, $parts))
 769                 || (isset($analyzed_sql[0]['select_expr'][$i]['expr'])
 770                     && isset($analyzed_sql[0]['select_expr'][$i]['column'])
 771                     && $analyzed_sql[0]['select_expr'][$i]['expr'] !=
 772                     $analyzed_sql[0]['select_expr'][$i]['column']
 773                    && isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table))) {
 774              */
 775              if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
 776                  $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
 777              } else {
 778                  $sort_tbl = '';
 779              }
 780  
 781              // 2.1.2 Checks if the current column is used to sort the
 782              //       results
 783              if (empty($sort_expression)) {
 784                  $is_in_sort = false;
 785              } else {
 786                  // field name may be preceded by a space, or any number
 787                  // of characters followed by a dot (tablename.fieldname)
 788                  // so do a direct comparison
 789                  // for the sort expression (avoids problems with queries
 790                  // like "SELECT id, count(id)..." and clicking to sort
 791                  // on id or on count(id))
 792                  $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? true : false);
 793              }
 794              // 2.1.3 Check the field name for backquotes.
 795              //       If it contains some, it's probably a function column
 796              //       like 'COUNT(`field`)'
 797              if (strpos($fields_meta[$i]->name, '`') !== false) {
 798                  $sort_order = ' ORDER BY ' . PMA_backquote($fields_meta[$i]->name) . ' ';
 799              } else {
 800                  $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
 801              }
 802  
 803              // 2.1.4 Do define the sorting url
 804              if (! $is_in_sort) {
 805                  // loic1: patch #455484 ("Smart" order)
 806                  $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
 807                  if ($GLOBALS['cfg']['Order'] === 'SMART') {
 808                      $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
 809                  } else {
 810                      $sort_order .= $GLOBALS['cfg']['Order'];
 811                  }
 812                  $order_img   = '';
 813              } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
 814                  $sort_order .= ' ASC';
 815                  $order_img   = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
 816              } else {
 817                  $sort_order .= ' DESC';
 818                  $order_img   = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
 819              }
 820  
 821              if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
 822                  $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
 823              } else {
 824                  $sorted_sql_query = $unsorted_sql_query . $sort_order;
 825              }
 826              $url_query = PMA_generate_common_url($db, $table)
 827                         . '&amp;pos=' . $pos
 828                         . '&amp;session_max_rows=' . $session_max_rows
 829                         . '&amp;disp_direction=' . $disp_direction
 830                         . '&amp;repeat_cells=' . $repeat_cells
 831                         . '&amp;dontlimitchars=' . $dontlimitchars
 832                         . '&amp;sql_query=' . urlencode($sorted_sql_query);
 833              $order_url  = 'sql.php?' . $url_query;
 834  
 835              // 2.1.5 Displays the sorting url
 836              // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
 837              //                    enable sord order swapping for image
 838              $order_link_params = array();
 839              if (isset($order_img) && $order_img!='') {
 840                  if (strstr($order_img, 'asc')) {
 841                      $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
 842                      $order_link_params['onmouseout']  = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
 843                  } elseif (strstr($order_img, 'desc')) {
 844                      $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
 845                      $order_link_params['onmouseout']  = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
 846                  }
 847              }
 848              if ($disp_direction == 'horizontalflipped'
 849                && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
 850                  $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
 851              }
 852              $order_link_params['title'] = $GLOBALS['strSort'];
 853              $order_link_content = ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
 854              $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
 855  
 856              if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 857                  echo '<th';
 858                  if ($condition_field) {
 859                      echo ' class="condition"';
 860                  }
 861                  if ($disp_direction == 'horizontalflipped') {
 862                      echo ' valign="bottom"';
 863                  }
 864                  echo '>' . $order_link . $comments . '</th>';
 865              }
 866              $vertical_display['desc'][] = '    <th '
 867                  . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
 868                  . $order_link . $comments . '    </th>' . "\n";
 869          } // end if (2.1)
 870  
 871          // 2.2 Results can't be sorted
 872          else {
 873              if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 874                  echo '<th';
 875                  if ($condition_field) {
 876                      echo ' class="condition"';
 877                  }
 878                  if ($disp_direction == 'horizontalflipped') {
 879                      echo ' valign="bottom"';
 880                  }
 881                  if ($disp_direction == 'horizontalflipped'
 882                   && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
 883                      echo ' style="direction: ltr; writing-mode: tb-rl;"';
 884                  }
 885                  echo '>';
 886                  if ($disp_direction == 'horizontalflipped'
 887                   && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
 888                      echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
 889                  } else {
 890                      echo htmlspecialchars($fields_meta[$i]->name);
 891                  }
 892                  echo "\n" . $comments . '</th>';
 893              }
 894              $vertical_display['desc'][] = '    <th '
 895                  . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
 896                  . '        ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
 897                  . $comments . '    </th>';
 898          } // end else (2.2)
 899      } // end for
 900  
 901      // 3. Displays the full/partial text button (part 2) at the right
 902      //    column of the result table header if possible and required...
 903      if ($GLOBALS['cfg']['ModifyDeleteAtRight']
 904          && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
 905          && $is_display['text_btn'] == '1') {
 906          $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
 907          if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 908              echo "\n";
 909              ?>
 910  <th <?php echo $colspan; ?>>
 911      <?php echo $text_link; ?>
 912  </th>
 913              <?php
 914          } // end horizontal/horizontalflipped mode
 915          else {
 916              $vertical_display['textbtn'] = '    <th ' . $rowspan . ' valign="middle">' . "\n"
 917                                           . '        ' . $text_link . "\n"
 918                                           . '    </th>' . "\n";
 919          } // end vertical mode
 920      }
 921  
 922      //     ... elseif no button, displays empty cols if required
 923      // (unless coming from Browse mode print view)
 924      elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
 925               && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
 926               && (!$GLOBALS['is_header_sent'])) {
 927          $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
 928          if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 929              echo "\n";
 930              ?>
 931  <td<?php echo $colspan; ?>></td>
 932              <?php
 933          } // end horizontal/horizontalflipped mode
 934          else {
 935              $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
 936          } // end vertical mode
 937      }
 938  
 939      if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 940          ?>
 941  </tr>
 942  </thead>
 943          <?php
 944      }
 945  
 946      return true;
 947  } // end of the 'PMA_displayTableHeaders()' function
 948  
 949  
 950  
 951  /**
 952   * Displays the body of the results table
 953   *
 954   * @param   integer  the link id associated to the query which results have
 955   *                   to be displayed
 956   * @param   array    which elements to display
 957   * @param   array    the list of relations
 958   * @param   array    the analyzed query
 959   *
 960   * @return  boolean  always true
 961   *
 962   * @global  string   $db                the database name
 963   * @global  string   $table             the table name
 964   * @global  string   $goto              the url to go back in case of errors
 965   * @global  boolean  $dontlimitchars    whether to limit the number of displayed
 966   *                                      characters of text type fields or not
 967   * @global  string   $sql_query         the sql query
 968   * @global  integer  $pos               the current position in results
 969   * @global  integer  $session_max_rows  the maximum number of rows per page
 970   * @global  array    $fields_meta       the list of fields properties
 971   * @global  integer  $fields_cnt        the total number of fields returned by
 972   *                                      the sql query
 973   * @global  array    $vertical_display  informations used with vertical display
 974   *                                      mode
 975   * @global  string   $disp_direction    the display mode
 976   *                                      (horizontal/vertical/horizontalflipped)
 977   * @global  integer  $repeat_cells      the number of row to display between two
 978   *                                      table headers
 979   * @global  array    $highlight_columns collumn names to highlight
 980   * @gloabl  array    $row               current row data
 981   *
 982   * @access  private
 983   *
 984   * @see     PMA_displayTable()
 985   */
 986  function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
 987      global $db, $table, $goto, $dontlimitchars;
 988      global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
 989      global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
 990      global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
 991  
 992      $url_sql_query          = $sql_query;
 993  
 994      // query without conditions to shorten urls when needed, 200 is just
 995      // guess, it should depend on remaining url length
 996  
 997      if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
 998          isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
 999          strlen($sql_query) > 200) {
1000  
1001          $url_sql_query = 'SELECT ';
1002          if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1003              $url_sql_query .= ' DISTINCT ';
1004          }
1005          $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1006          if (!empty($analyzed_sql[0]['from_clause'])) {
1007              $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1008          }
1009      }
1010  
1011      if (!is_array($map)) {
1012          $map = array();
1013      }
1014      $row_no                         = 0;
1015      $vertical_display['edit']       = array();
1016      $vertical_display['delete']     = array();
1017      $vertical_display['data']       = array();
1018      $vertical_display['row_delete'] = array();
1019  
1020      // Correction University of Virginia 19991216 in the while below
1021      // Previous code assumed that all tables have keys, specifically that
1022      // the phpMyAdmin GUI should support row delete/edit only for such
1023      // tables.
1024      // Although always using keys is arguably the prescribed way of
1025      // defining a relational table, it is not required. This will in
1026      // particular be violated by the novice.
1027      // We want to encourage phpMyAdmin usage by such novices. So the code
1028      // below has been changed to conditionally work as before when the
1029      // table being displayed has one or more keys; but to display
1030      // delete/edit options correctly for tables without keys.
1031  
1032      // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
1033      //        to get the NULL values
1034  
1035      // rabus: This function needs a little rework.
1036      //        Using MYSQL_BOTH just pollutes the memory!
1037  
1038      // ne0x:  Use function PMA_DBI_fetch_array() due to mysqli
1039      //        compatibility. Now this function is wrapped.
1040  
1041      $odd_row = true;
1042      while ($row = PMA_DBI_fetch_row($dt_result)) {
1043          // lem9: "vertical display" mode stuff
1044          if ($row_no != 0 && $repeat_cells != 0 && !($row_no % $repeat_cells)
1045            && ($disp_direction == 'horizontal'
1046              || $disp_direction == 'horizontalflipped'))
1047          {
1048              echo '<tr>' . "\n";
1049              if ($vertical_display['emptypre'] > 0) {
1050                  echo '    <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1051                      .'        &nbsp;</th>' . "\n";
1052              }
1053  
1054              foreach ($vertical_display['desc'] as $val) {
1055                  echo $val;
1056              }
1057  
1058              if ($vertical_display['emptyafter'] > 0) {
1059                  echo '    <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1060                      .'        &nbsp;</th>' . "\n";
1061              }
1062              echo '</tr>' . "\n";
1063          } // end if
1064  
1065          $class = $odd_row ? 'odd' : 'even';
1066          $odd_row = ! $odd_row;
1067          if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1068              // loic1: pointer code part
1069              echo '    <tr class="' . $class . '">' . "\n";
1070              $class = '';
1071          }
1072  
1073  
1074          // 1. Prepares the row (gets primary keys to use)
1075          // 1.1 Results from a "SELECT" statement -> builds the
1076          //     "primary" key to use in links
1077          /**
1078           * @todo $unique_condition could be empty, for example a table
1079           *       with only one field and it's a BLOB; in this case,
1080           *       avoid to display the delete and edit links
1081           */
1082  
1083          $unique_condition     = urlencode(PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row));
1084  
1085          // 1.2 Defines the urls for the modify/delete link(s)
1086          $url_query  = PMA_generate_common_url($db, $table)
1087                      . '&amp;pos=' . $pos
1088                      . '&amp;session_max_rows=' . $session_max_rows
1089                      . '&amp;disp_direction=' . $disp_direction
1090                      . '&amp;repeat_cells=' . $repeat_cells
1091                      . '&amp;dontlimitchars=' . $dontlimitchars;
1092  
1093          if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1094              // We need to copy the value or else the == 'both' check will always return true
1095  
1096              if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1097                  $iconic_spacer = '<div class="nowrap">';
1098              } else {
1099                  $iconic_spacer = '';
1100              }
1101  
1102              // 1.2.1 Modify link(s)
1103              if ($is_display['edit_lnk'] == 'ur') { // update row case
1104                  $lnk_goto = 'sql.php';
1105  
1106                  $edit_url = 'tbl_change.php'
1107                            . '?' . $url_query
1108                            . '&amp;primary_key=' . $unique_condition
1109                            . '&amp;sql_query=' . urlencode($url_sql_query)
1110                            . '&amp;goto=' . urlencode($lnk_goto);
1111                  if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1112                      $edit_str = $GLOBALS['strEdit'];
1113                  } else {
1114                      $edit_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" />';
1115                      if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1116                          $edit_str .= ' ' . $GLOBALS['strEdit'] . '</div>';
1117                      }
1118                  }
1119              } // end if (1.2.1)
1120  
1121              if (isset($GLOBALS['cfg']['Bookmark']['table']) && isset($GLOBALS['cfg']['Bookmark']['db']) && $table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) {
1122                  $bookmark_go = '<a href="import.php?'
1123                                  . PMA_generate_common_url($row[1], '')
1124                                  . '&amp;id_bookmark=' . $row[0]
1125                                  . '&amp;action_bookmark=0'
1126                                  . '&amp;action_bookmark_all=1'
1127                                  . '&amp;SQL=' . $GLOBALS['strExecuteBookmarked']
1128                                  .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1129  
1130                  if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1131                      $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
1132                  } else {
1133                      $bookmark_go .= $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" />';
1134                      if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1135                          $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</div>';
1136                      }
1137                  }
1138  
1139                  $bookmark_go .= '</a>';
1140              } else {
1141                  $bookmark_go = '';
1142              }
1143  
1144              // 1.2.2 Delete/Kill link(s)
1145              if ($is_display['del_lnk'] == 'dr') { // delete row case
1146                  $lnk_goto = 'sql.php'
1147                            . '?' . str_replace('&amp;', '&', $url_query)
1148                            . '&sql_query=' . urlencode($url_sql_query)
1149                            . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1150                            . '&goto=' . (empty($goto) ? 'tbl_sql.php' : $goto);
1151                  $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $unique_condition . '+LIMIT+1';
1152                  $del_url  = 'sql.php'
1153                            . '?' . $url_query
1154                            . '&amp;sql_query=' . $del_query
1155                            . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1156                            . '&amp;goto=' . urlencode($lnk_goto);
1157                  $js_conf  = 'DELETE FROM ' . PMA_jsFormat($table)
1158                            . ' WHERE ' . trim(PMA_jsFormat(urldecode($unique_condition), false))
1159                            . ' LIMIT 1';
1160                  if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1161                      $del_str = $GLOBALS['strDelete'];
1162                  } else {
1163                      $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" />';
1164                      if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1165                          $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>';
1166                      }
1167                  }
1168              } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1169                  $lnk_goto = 'sql.php'
1170                            . '?' . str_replace('&amp;', '&', $url_query)
1171                            . '&sql_query=' . urlencode($url_sql_query)
1172                            . '&goto=main.php';
1173                  $del_url  = 'sql.php?'
1174                            . PMA_generate_common_url('mysql')
1175                            . '&amp;sql_query=' . urlencode('KILL ' . $row[0])
1176                            . '&amp;goto=' . urlencode($lnk_goto);
1177                  $del_query = urlencode('KILL ' . $row[0]);
1178                  $js_conf  = 'KILL ' . $row[0];
1179                  if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1180                      $del_str = $GLOBALS['strKill'];
1181                  } else {
1182                      $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" />';
1183                      if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1184                          $del_str .= ' ' . $GLOBALS['strKill'] . '</div>';
1185                      }
1186                  }
1187              } // end if (1.2.2)
1188  
1189              // 1.3 Displays the links at left if required
1190              if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1191                  && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1192                  $doWriteModifyAt = 'left';
1193                  require './libraries/display_tbl_links.lib.php';
1194              } // end if (1.3)
1195          } // end if (1)
1196  
1197          // 2. Displays the rows' values
1198          for ($i = 0; $i < $fields_cnt; ++$i) {
1199              $meta    = $fields_meta[$i];
1200              // loic1: To fix bug #474943 under php4, the row pointer will
1201              //        depend on whether the "is_null" php4 function is
1202              //        available or not
1203              $pointer = (function_exists('is_null') ? $i : $meta->name);
1204              // garvin: See if this column should get highlight because it's used in the
1205              //  where-query.
1206              if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1207                  $condition_field = true;
1208              } else {
1209                  $condition_field = false;
1210              }
1211  
1212              $mouse_events = '';
1213              if ($disp_direction == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1214                  if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1215                      $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1216                                . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1217                  }
1218                  if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1219                      $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1220                  } else {
1221                      $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1222                  }
1223              }// end if
1224  
1225              // garvin: Wrap MIME-transformations. [MIME]
1226              $default_function = 'default_function'; // default_function
1227              $transform_function = $default_function;
1228              $transform_options = array();
1229  
1230              if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1231  
1232                  if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1233                      $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
1234  
1235                      if (file_exists('./libraries/transformations/' . $include_file)) {
1236                          $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1237  
1238                          require_once './libraries/transformations/' . $include_file;
1239  
1240                          if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1241                              $transform_function = 'PMA_transformation_' . $transformfunction_name;
1242                              $transform_options  = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1243                              $meta->mimetype     = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1244                          }
1245                      } // end if file_exists
1246                  } // end if transformation is set
1247              } // end if mime/transformation works.
1248  
1249              $transform_options['wrapper_link'] = '?'
1250                                                  . (isset($url_query) ? $url_query : '')
1251                                                  . '&amp;primary_key=' . (isset($unique_condition) ? $unique_condition : '')
1252                                                  . '&amp;sql_query=' . (isset($sql_query) ? urlencode($url_sql_query) : '')
1253                                                  . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
1254                                                  . '&amp;transform_key=' . urlencode($meta->name);
1255  
1256  
1257              // n u m e r i c
1258              if ($meta->numeric == 1) {
1259  
1260  
1261              // lem9: if two fields have the same name (this is possible
1262              //       with self-join queries, for example), using $meta->name
1263              //       will show both fields NULL even if only one is NULL,
1264              //       so use the $pointer
1265              //      (works only if function_exists('is_null')
1266              // PS:   why not always work with the number ($i), since
1267              //       the default second parameter of
1268              //       mysql_fetch_array() is MYSQL_BOTH, so we always get
1269              //       associative and numeric indices?
1270  
1271                  //if (!isset($row[$meta->name])
1272                  if (!isset($row[$i]) || is_null($row[$i])) {
1273                      $vertical_display['data'][$row_no][$i]     = '    <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1274                  } elseif ($row[$i] != '') {
1275                      $vertical_display['data'][$row_no][$i]     = '    <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . ' nowrap">';
1276  
1277                      if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1278                          foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1279                              $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1280                              if (isset($alias) && strlen($alias)) {
1281                                  $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1282                                  if ($alias == $meta->name) {
1283                                      $meta->name = $true_column;
1284                                  } // end if
1285                              } // end if
1286                          } // end while
1287                      }
1288  
1289                      if (isset($map[$meta->name])) {
1290                          // Field to display from the foreign table?
1291                          if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
1292                              $dispsql     = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1293                                           . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1294                                           . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1295                                           . ' = ' . $row[$i];
1296                              $dispresult  = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
1297                              if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1298                                  list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
1299                              } else {
1300                                  $dispval = $GLOBALS['strLinkNotFound'];
1301                              }
1302                              @PMA_DBI_free_result($dispresult);
1303                          } else {
1304                              $dispval     = '';
1305                          } // end if... else...
1306  
1307                          if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1308                              $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
1309                          } else {
1310                              $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1311  
1312                              $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1313                                                                     .  PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1314                                                                     .  '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1315                                                                     .  '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]) . '"' . $title . '>'
1316                                                                     .  ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . '</a>';
1317                          }
1318                      } else {
1319                          $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta));
1320                      }
1321                      $vertical_display['data'][$row_no][$i]     .= '</td>' . "\n";
1322                  } else {
1323                      $vertical_display['data'][$row_no][$i]     = '    <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1324                  }
1325  
1326              //  b l o b
1327  
1328              } elseif ($GLOBALS['cfg']['ShowBlob'] == false && stristr($meta->type, 'BLOB')) {
1329                  // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1330                  // TEXT fields type, however TEXT fields must be displayed
1331                  // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type
1332                  // of the fields.
1333                  $field_flags = PMA_DBI_field_flags($dt_result, $i);
1334                  if (stristr($field_flags, 'BINARY')) {
1335                      $blobtext = '[BLOB';
1336                      if (!isset($row[$i]) || is_null($row[$i])) {
1337                          $blobtext .= ' - NULL';
1338                          $blob_size = 0;
1339                      } elseif (isset($row[$i])) {
1340                          $blob_size = strlen($row[$i]);
1341                          $display_blob_size = PMA_formatByteDown($blob_size, 3, 1);
1342                          $blobtext .= ' - '. $display_blob_size[0] . ' ' . $display_blob_size[1];
1343                          unset($display_blob_size);
1344                      }
1345  
1346                      $blobtext .= ']';
1347                      if (strpos($transform_function, 'octetstream')) {
1348                          $blobtext = $row[$i];
1349                      }
1350                      if ($blob_size > 0) {
1351                          $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
1352                      }
1353                      unset($blob_size);
1354  
1355                      $vertical_display['data'][$row_no][$i]      = '    <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
1356                  } else {
1357                      if (!isset($row[$i]) || is_null($row[$i])) {
1358                          $vertical_display['data'][$row_no][$i] = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1359                      } elseif ($row[$i] != '') {
1360                          // garvin: if a transform function for blob is set, none of these replacements will be made
1361                          if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1362                              $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1363                          }
1364                          // loic1: displays all space characters, 4 space
1365                          // characters for tabulations and <cr>/<lf>
1366                          $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1367  
1368                          $vertical_display['data'][$row_no][$i] = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1369                      } else {
1370                          $vertical_display['data'][$row_no][$i] = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1371                      }
1372                  }
1373              } else {
1374                  if (!isset($row[$i]) || is_null($row[$i])) {
1375                      $vertical_display['data'][$row_no][$i]     = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1376                  } elseif ($row[$i] != '') {
1377                      // loic1: support blanks in the key
1378                      $relation_id = $row[$i];
1379  
1380                      // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1381                      // lem9: (unless it's a link-type transformation)
1382                      if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1) && !strpos($transform_function, 'link') === true) {
1383                          $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1384                      }
1385  
1386                      // loic1: displays special characters from binaries
1387                      $field_flags = PMA_DBI_field_flags($dt_result, $i);
1388                      if (stristr($field_flags, 'BINARY')) {
1389                          $row[$i]     = str_replace("\x00", '\0', $row[$i]);
1390                          $row[$i]     = str_replace("\x08", '\b', $row[$i]);
1391                          $row[$i]     = str_replace("\x0a", '\n', $row[$i]);
1392                          $row[$i]     = str_replace("\x0d", '\r', $row[$i]);
1393                          $row[$i]     = str_replace("\x1a", '\Z', $row[$i]);
1394                          $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1395                      }
1396                      // loic1: displays all space characters, 4 space
1397                      // characters for tabulations and <cr>/<lf>
1398                      else {
1399                          $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1400                      }
1401  
1402                      // garvin: transform functions may enable nowrapping:
1403                      $function_nowrap = $transform_function . '_nowrap';
1404                      $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1405  
1406                      // loic1: do not wrap if date field type
1407                      $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1408                      $vertical_display['data'][$row_no][$i]     = '    <td' . $mouse_events . ' class="' . $class . $nowrap . ($condition_field ? ' condition' : '') . '">';
1409  
1410                      if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1411                          foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1412                              $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1413                              if (isset($alias) && strlen($alias)) {
1414                                  $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1415                                  if ($alias == $meta->name) {
1416                                      $meta->name = $true_column;
1417                                  } // end if
1418                              } // end if
1419                          } // end while
1420                      }
1421  
1422                      if (isset($map[$meta->name])) {
1423                          // Field to display from the foreign table?
1424                          if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
1425                              $dispsql     = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1426                                           . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1427                                           . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1428                                           . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1429                              $dispresult  = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
1430                              if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1431                                  list($dispval) = PMA_DBI_fetch_row($dispresult);
1432                                  @PMA_DBI_free_result($dispresult);
1433                              } else {
1434                                  $dispval = $GLOBALS['strLinkNotFound'];
1435                              }
1436                          } else {
1437                              $dispval = '';
1438                          }
1439                          $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1440  
1441                          $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1442                                                                 .  PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1443                                                                 .  '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1444                                                                 .  '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1445                                                                 .  $row[$i] . '</a>';
1446                      } else {
1447                          $vertical_display['data'][$row_no][$i] .= $row[$i];
1448                      }
1449                      $vertical_display['data'][$row_no][$i]     .= '</td>' . "\n";
1450                  } else {
1451                      $vertical_display['data'][$row_no][$i]     = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1452                  }
1453              }
1454  
1455              // lem9: output stored cell
1456              if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1457                  echo $vertical_display['data'][$row_no][$i];
1458              }
1459  
1460              if (isset($vertical_display['rowdata'][$i][$row_no])) {
1461                  $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1462              } else {
1463                  $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1464              }
1465          } // end for (2)
1466  
1467          // 3. Displays the modify/delete links on the right if required
1468          if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1469              && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1470                  $doWriteModifyAt = 'right';
1471                  require './libraries/display_tbl_links.lib.php';
1472          } // end if (3)
1473  
1474          if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1475              ?>
1476  </tr>
1477              <?php
1478          } // end if
1479  
1480          // 4. Gather links of del_urls and edit_urls in an array for later
1481          //    output
1482          if (!isset($vertical_display['edit'][$row_no])) {
1483              $vertical_display['edit'][$row_no]       = '';
1484              $vertical_display['delete'][$row_no]     = '';
1485              $vertical_display['row_delete'][$row_no] = '';
1486          }
1487  
1488          $column_style_vertical = '';
1489          if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1490              $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1491                           . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1492          }
1493          $column_marker_vertical = '';
1494          if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1495              $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1496          }
1497  
1498          if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1499              $vertical_display['row_delete'][$row_no] .= '    <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1500                                                       .  '        <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $unique_condition . ']"'
1501                                                       .  ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1502                                                       .  ' value="' . $del_query . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1503                                                       .  '    </td>' . "\n";
1504          } else {
1505              unset($vertical_display['row_delete'][$row_no]);
1506          }
1507  
1508          if (isset($edit_url)) {
1509              $vertical_display['edit'][$row_no]   .= '    <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1510                                                   . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1511                                                   . $bookmark_go
1512                                                   .  '    </td>' . "\n";
1513          } else {
1514              unset($vertical_display['edit'][$row_no]);
1515          }
1516  
1517          if (isset($del_url)) {
1518              $vertical_display['delete'][$row_no] .= '    <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1519                                                   . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
1520                                                   .  '    </td>' . "\n";
1521          } else {
1522              unset($vertical_display['delete'][$row_no]);
1523          }
1524  
1525          echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1526          $row_no++;
1527      } // end while
1528  
1529      if (isset($url_query)) {
1530          $GLOBALS['url_query'] = $url_query;
1531      }
1532  
1533      return true;
1534  } // end of the 'PMA_displayTableBody()' function
1535  
1536  
1537  /**
1538   * Do display the result table with the vertical direction mode.
1539   * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1540   *
1541   * @return  boolean  always true
1542   *
1543   * @global  array    $vertical_display the information to display
1544   * @global  integer  $repeat_cells     the number of row to display between two
1545   *                                     table headers
1546   *
1547   * @access  private
1548   *
1549   * @see     PMA_displayTable()
1550   */
1551  function PMA_displayVerticalTable()
1552  {
1553      global $vertical_display, $repeat_cells;
1554  
1555      // Displays "multi row delete" link at top if required
1556      if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1557          echo '<tr>' . "\n";
1558          echo $vertical_display['textbtn'];
1559          $foo_counter = 0;
1560          foreach ($vertical_display['row_delete'] as $val) {
1561              if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1562                  echo '<th>&nbsp;</th>' . "\n";
1563              }
1564  
1565              echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1566              $foo_counter++;
1567          } // end while
1568          echo '</tr>' . "\n";
1569      } // end if
1570  
1571      // Displays "edit" link at top if required
1572      if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1573          echo '<tr>' . "\n";
1574          if (!is_array($vertical_display['row_delete'])) {
1575              echo $vertical_display['textbtn'];
1576          }
1577          $foo_counter = 0;
1578          foreach ($vertical_display['edit'] as $val) {
1579              if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1580                  echo '    <th>&nbsp;</th>' . "\n";
1581              }
1582  
1583              echo $val;
1584              $foo_counter++;
1585          } // end while
1586          echo '</tr>' . "\n";
1587      } // end if
1588  
1589      // Displays "delete" link at top if required
1590      if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1591          echo '<tr>' . "\n";
1592          if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1593              echo $vertical_display['textbtn'];
1594          }
1595          $foo_counter = 0;
1596          foreach ($vertical_display['delete'] as $val) {
1597              if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1598                  echo '<th>&nbsp;</th>' . "\n";
1599              }
1600  
1601              echo $val;
1602              $foo_counter++;
1603          } // end while
1604          echo '</tr>' . "\n";
1605      } // end if
1606  
1607      // Displays data
1608      foreach ($vertical_display['desc'] AS $key => $val) {
1609  
1610          echo '<tr>' . "\n";
1611          echo $val;
1612  
1613          $foo_counter = 0;
1614          foreach ($vertical_display['rowdata'][$key] as $subval) {
1615              if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1616                  echo $val;
1617              }
1618  
1619              echo $subval;
1620              $foo_counter++;
1621          } // end while
1622  
1623          echo '</tr>' . "\n";
1624      } // end while
1625  
1626      // Displays "multi row delete" link at bottom if required
1627      if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1628          echo '<tr>' . "\n";
1629          echo $vertical_display['textbtn'];
1630          $foo_counter = 0;
1631          foreach ($vertical_display['row_delete'] as $val) {
1632              if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1633                  echo '<th>&nbsp;</th>' . "\n";
1634              }
1635  
1636              echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1637              $foo_counter++;
1638          } // end while
1639          echo '</tr>' . "\n";
1640      } // end if
1641  
1642      // Displays "edit" link at bottom if required
1643      if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1644          echo '<tr>' . "\n";
1645          if (!is_array($vertical_display['row_delete'])) {
1646              echo $vertical_display['textbtn'];
1647          }
1648          $foo_counter = 0;
1649          foreach ($vertical_display['edit'] as $val) {
1650              if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1651                  echo '<th>&nbsp;</th>' . "\n";
1652              }
1653  
1654              echo $val;
1655              $foo_counter++;
1656          } // end while
1657          echo '</tr>' . "\n";
1658      } // end if
1659  
1660      // Displays "delete" link at bottom if required
1661      if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1662          echo '<tr>' . "\n";
1663          if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1664              echo $vertical_display['textbtn'];
1665          }
1666          $foo_counter = 0;
1667          foreach ($vertical_display['delete'] as $val) {
1668              if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1669                  echo '<th>&nbsp;</th>' . "\n";
1670              }
1671  
1672              echo $val;
1673              $foo_counter++;
1674          } // end while
1675          echo '</tr>' . "\n";
1676      }
1677  
1678      return true;
1679  } // end of the 'PMA_displayVerticalTable' function
1680  
1681  
1682  /**
1683   * Displays a table of results returned by a sql query.
1684   * This function is called by the "sql.php" script.
1685   *
1686   * @param   integer the link id associated to the query which results have
1687   *                  to be displayed
1688   * @param   array   the display mode
1689   * @param   array   the analyzed query
1690   *
1691   * @global  string   $db                the database name
1692   * @global  string   $table             the table name
1693   * @global  string   $goto              the url to go back in case of errors
1694   * @global  boolean  $dontlimitchars    whether to limit the number of displayed
1695   *                                      characters of text type fields or not
1696   * @global  string   $sql_query         the current sql query
1697   * @global  integer  $num_rows          the total number of rows returned by the
1698   *                                      sql query
1699   * @global  integer  $unlim_num_rows    the total number of rows returned by the
1700   *                                      sql query without any programmatically
1701   *                                      appended "LIMIT" clause
1702   * @global  integer  $pos               the current postion of the first record
1703   *                                      to be displayed
1704   * @global  array    $fields_meta       the list of fields properties
1705   * @global  integer  $fields_cnt        the total number of fields returned by
1706   *                                      the sql query
1707   * @global  array    $vertical_display  informations used with vertical display
1708   *                                      mode
1709   * @global  string   $disp_direction    the display mode
1710   *                                      (horizontal/vertical/horizontalflipped)
1711   * @global  integer  $repeat_cells      the number of row to display between two
1712   *                                      table headers
1713   * @global  array    $highlight_columns collumn names to highlight
1714   * @global  array    $cfgRelation       the relation settings
1715   *
1716   * @access  private
1717   *
1718   * @see     PMA_showMessage(), PMA_setDisplayMode(),
1719   *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1720   *          PMA_displayTableBody(), PMA_displayResultsOperations()
1721   */
1722  function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1723  {
1724      global $db, $table, $goto, $dontlimitchars;
1725      global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1726      global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
1727      global $cfgRelation;
1728  
1729      // 1. ----- Prepares the work -----
1730  
1731      // 1.1 Gets the informations about which functionnalities should be
1732      //     displayed
1733      $total      = '';
1734      $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1735  
1736      // 1.2 Defines offsets for the next and previous pages
1737      if ($is_display['nav_bar'] == '1') {
1738          if (!isset($pos)) {
1739              $pos          = 0;
1740          }
1741          if ($GLOBALS['session_max_rows'] == 'all') {
1742              $pos_next     = 0;
1743              $pos_prev     = 0;
1744          } else {
1745              $pos_next     = $pos + $GLOBALS['cfg']['MaxRows'];
1746              $pos_prev     = $pos - $GLOBALS['cfg']['MaxRows'];
1747              if ($pos_prev < 0) {
1748                  $pos_prev = 0;
1749              }
1750          }
1751      } // end if
1752  
1753      // 1.3 Urlencodes the query to use in input form fields
1754      $encoded_sql_query = urlencode($sql_query);
1755  
1756      // 2. ----- Displays the top of the page -----
1757  
1758      // 2.1 Displays a messages with position informations
1759      if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1760          if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1761              $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1762          } else {
1763              $selectstring = '';
1764          }
1765          $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1766                          ? $total - 1
1767                          : $pos_next - 1;
1768          PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec (" . PMA_formatNumber($total, 0) . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1769          if (isset($table) && PMA_Table::isView($db, $table) && $total ==  $GLOBALS['cfg']['MaxExactCount']) {
1770              echo '<div class="notice">' . "\n";
1771              echo PMA_sanitize(sprintf($GLOBALS['strViewMaxExactCount'], PMA_formatNumber($GLOBALS['cfg']['MaxExactCount'], 0), '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]')) . "\n";
1772              echo '</div>' . "\n";
1773          }
1774  
1775      } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1776          PMA_showMessage($GLOBALS['strSQLQuery']);
1777      }
1778  
1779      // 2.3 Displays the navigation bars
1780      if (!isset($table) || strlen(trim($table)) == 0) {
1781          if (isset($analyzed_sql[0]['query_type'])
1782             && $analyzed_sql[0]['query_type'] == 'SELECT') {
1783              // table does not always contain a real table name,
1784              // for example in MySQL 5.0.x, the query SHOW STATUS
1785              // returns STATUS as a table name
1786              $table = $fields_meta[0]->table;
1787          } else {
1788              $table = '';
1789          }
1790      }
1791      if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1792          PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
1793      }
1794      if ($is_display['nav_bar'] == '1') {
1795          PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1796          echo "\n";
1797      } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1798          echo "\n" . '<br /><br />' . "\n";
1799      }
1800  
1801      // 2b ----- Get field references from Database -----
1802      // (see the 'relation' config variable)
1803      // loic1, 2002-03-02: extended to php3
1804  
1805      // init map
1806      $map = array();
1807  
1808      // find tables
1809      $target=array();
1810      if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1811          foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1812             $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1813          }
1814      }
1815      $tabs    = '(\'' . join('\',\'', $target) . '\')';
1816  
1817      if ($cfgRelation['displaywork']) {
1818          if (! isset($table) || ! strlen($table)) {
1819              $exist_rel = false;
1820          } else {
1821              $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1822              if ($exist_rel) {
1823                  foreach ($exist_rel AS $master_field => $rel) {
1824                      $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
1825                      $map[$master_field] = array($rel['foreign_table'],
1826                                            $rel['foreign_field'],
1827                                            $display_field,
1828                                            $rel['foreign_db']);
1829                  } // end while
1830              } // end if
1831          } // end if
1832      } // end if
1833      // end 2b
1834  
1835      // 3. ----- Displays the results table -----
1836      PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1837      $url_query='';
1838      echo '<tbody>' . "\n";
1839      PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1840      // vertical output case
1841      if ($disp_direction == 'vertical') {
1842          PMA_displayVerticalTable();
1843      } // end if
1844      unset($vertical_display);
1845      echo '</tbody>' . "\n";
1846      ?>
1847  </table>
1848  
1849      <?php
1850      // 4. ----- Displays the link for multi-fields delete
1851  
1852      if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
1853  
1854          $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
1855  
1856          $uncheckall_url = 'sql.php?'
1857                    . PMA_generate_common_url($db, $table)
1858                    . '&amp;sql_query=' . urlencode($sql_query)
1859                    . '&amp;pos=' . $pos
1860                    . '&amp;session_max_rows=' . $GLOBALS['session_max_rows']
1861                    . '&amp;pos=' . $pos
1862                    . '&amp;disp_direction=' . $disp_direction
1863                    . '&amp;repeat_cells=' . $repeat_cells
1864                    . '&amp;goto=' . $goto
1865                    . '&amp;dontlimitchars=' . $dontlimitchars;
1866          $checkall_url = $uncheckall_url . '&amp;checkall=1';
1867  
1868          if ($disp_direction == 'vertical') {
1869              $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
1870              $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
1871          } else {
1872              $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
1873              $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
1874          }
1875          $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
1876          $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
1877          if ($disp_direction != 'vertical') {
1878              echo '<img class="selectallarrow" width="38" height="22"'
1879                  .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
1880                  .' alt="' . $GLOBALS['strWithChecked'] . '" />';
1881          }
1882          echo $checkall_link . "\n"
1883              .' / ' . "\n"
1884              .$uncheckall_link . "\n"
1885              .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
1886  
1887          if ($GLOBALS['cfg']['PropertiesIconic']) {
1888              PMA_buttonOrImage('submit_mult', 'mult_submit',
1889                  'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
1890              PMA_buttonOrImage('submit_mult', 'mult_submit',
1891                  'submit_mult_delete', $delete_text, 'b_drop.png');
1892              if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1893                  PMA_buttonOrImage('submit_mult', 'mult_submit',
1894                      'submit_mult_export', $GLOBALS['strExport'],
1895                      'b_tblexport.png');
1896              }
1897              echo "\n";
1898          } else {
1899              echo ' <input type="submit" name="submit_mult"'
1900                  .' value="' . htmlspecialchars($GLOBALS['strEdit']) . '"'
1901                  .' title="' . $GLOBALS['strEdit'] . '" />' . "\n";
1902              echo ' <input type="submit" name="submit_mult"'
1903                  .' value="' . htmlspecialchars($delete_text) . '"'
1904                  .' title="' . $delete_text . '" />' . "\n";
1905              if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1906                  echo ' <input type="submit" name="submit_mult"'
1907                      .' value="' . htmlspecialchars($GLOBALS['strExport']) . '"'
1908                      .' title="' . $GLOBALS['strExport'] . '" />' . "\n";
1909              }
1910          }
1911          echo '<input type="hidden" name="sql_query"'
1912              .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
1913          echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
1914          echo '<input type="hidden" name="url_query"'
1915              .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
1916          echo '</form>' . "\n";
1917      }
1918  
1919      // 5. ----- Displays the navigation bar at the bottom if required -----
1920  
1921      if ($is_display['nav_bar'] == '1') {
1922          echo '<br />' . "\n";
1923          PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1924      } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1925          echo "\n" . '<br /><br />' . "\n";
1926      }
1927  } // end of the 'PMA_displayTable()' function
1928  
1929  function default_function($buffer) {
1930      $buffer = htmlspecialchars($buffer);
1931      $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
1932          str_replace('  ', ' &nbsp;', $buffer));
1933      $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
1934  
1935      return $buffer;
1936  }
1937  
1938  /**
1939   * Displays operations that are available on results.
1940   *
1941   * @param   array   the display mode
1942   * @param   array   the analyzed query
1943   *
1944   * @global  string   $db                the database name
1945   * @global  string   $table             the table name
1946   * @global  boolean  $dontlimitchars    whether to limit the number of displayed
1947   *                                      characters of text type fields or not
1948   * @global  integer  $pos               the current postion of the first record
1949   *                                      to be displayed
1950   * @global  string   $sql_query         the current sql query
1951   * @global  integer  $unlim_num_rows    the total number of rows returned by the
1952   *                                      sql query without any programmatically
1953   *                                      appended "LIMIT" clause
1954   * @global  string   $disp_direction    the display mode
1955   *                                      (horizontal/vertical/horizontalflipped)
1956   * @global  integer  $repeat_cells      the number of row to display between two
1957   *                                      table headers
1958   *
1959   * @access  private
1960   *
1961   * @see     PMA_showMessage(), PMA_setDisplayMode(),
1962   *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1963   *          PMA_displayTableBody(), PMA_displayResultsOperations()
1964   */
1965  function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
1966      global $db, $table, $dontlimitchars, $pos, $sql_query, $unlim_num_rows, $disp_direction, $repeat_cells;
1967  
1968      $header_shown = FALSE;
1969      $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
1970  
1971      if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
1972          // Displays "printable view" link if required
1973          if ($the_disp_mode[9] == '1') {
1974  
1975              if (!$header_shown) {
1976                  echo $header;
1977                  $header_shown = TRUE;
1978              }
1979  
1980              $url_query = '?'
1981                         . PMA_generate_common_url($db, $table)
1982                         . '&amp;pos=' . $pos
1983                         . '&amp;session_max_rows=' . $GLOBALS['session_max_rows']
1984                         . '&amp;disp_direction=' . $disp_direction
1985                         . '&amp;repeat_cells=' . $repeat_cells
1986                         . '&amp;printview=1'
1987                         . '&amp;sql_query=' . urlencode($sql_query);
1988              echo '    <!-- Print view -->' . "\n";
1989              echo PMA_linkOrButton(
1990                  'sql.php' . $url_query . ((isset($dontlimitchars) && $dontlimitchars == '1') ? '&amp;dontlimitchars=1' : ''),
1991                  ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_print.png" height="16" width="16" alt="' . $GLOBALS['strPrintView'] . '"/>' : '') . $GLOBALS['strPrintView'],
1992                  '', true, true, 'print_view') . "\n";
1993  
1994              if (!$dontlimitchars) {
1995                  echo   '    &nbsp;&nbsp;' . "\n";
1996                  echo PMA_linkOrButton(
1997                      'sql.php' . $url_query . '&amp;dontlimitchars=1',
1998                      ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_print.png" height="16" width="16" alt="' . $GLOBALS['strPrintViewFull'] . '"/>' : '') . $GLOBALS['strPrintViewFull'],
1999                      '', true, true, 'print_view') . "\n";
2000              }
2001          } // end displays "printable view"
2002  
2003          echo "\n";
2004      }
2005  
2006      // Export link
2007      // (the url_query has extra parameters that won't be used to export)
2008      // (the single_table parameter is used in display_export.lib.php
2009      //  to hide the SQL and the structure export dialogs)
2010      if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview)) {
2011          if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2012              $single_table   = '&amp;single_table=true';
2013          } else {
2014              $single_table   = '';
2015          }
2016          if (!$header_shown) {
2017              echo $header;
2018              $header_shown = TRUE;
2019          }
2020          echo '    <!-- Export -->' . "\n";
2021          echo   '    &nbsp;&nbsp;' . "\n";
2022          echo PMA_linkOrButton(
2023              'tbl_export.php' . $url_query . '&amp;unlim_num_rows=' . $unlim_num_rows . $single_table,
2024              ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_tblexport.png" height="16" width="16" alt="' . $GLOBALS['strExport'] . '" />' : '') . $GLOBALS['strExport'],
2025              '', true, true, '') . "\n";
2026      }
2027      if ($header_shown) {
2028          echo '</fieldset><br />';
2029      }
2030  }
2031  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics