home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / display_tbl.lib.php < prev    next >
Encoding:
PHP Script  |  2004-02-11  |  96.1 KB  |  1,911 lines

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