home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / db_info.inc.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  8.0 KB  |  251 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * Gets the list of the table in the current db and informations about these
  5.  * tables if possible
  6.  *
  7.  * fills tooltip arrays and provides $tables, $num_tables, $is_show_stats
  8.  * and $db_is_information_schema
  9.  *
  10.  * staybyte: speedup view on locked tables - 11 June 2001
  11.  *
  12.  * @uses    PMA_MYSQL_INT_VERSION
  13.  * @uses    $cfg['ShowStats']
  14.  * @uses    $cfg['ShowTooltip']
  15.  * @uses    $cfg['ShowTooltipAliasTB']
  16.  * @uses    $cfg['SkipLockedTables']
  17.  * @uses    $GLOBALS['db']
  18.  * @uses    PMA_fillTooltip()
  19.  * @uses    PMA_checkParameters()
  20.  * @uses    PMA_escape_mysql_wildcards()
  21.  * @uses    PMA_DBI_query()
  22.  * @uses    PMA_backquote()
  23.  * @uses    PMA_DBI_num_rows()
  24.  * @uses    PMA_DBI_fetch_row()
  25.  * @uses    PMA_DBI_fetch_assoc()
  26.  * @uses    PMA_DBI_free_result()
  27.  * @uses    PMA_DBI_get_tables_full()
  28.  * @uses    PMA_isValid()
  29.  * @uses    preg_match()
  30.  * @uses    preg_quote()
  31.  * @uses    uksort()
  32.  * @uses    strnatcasecmp()
  33.  * @uses    count()
  34.  * @uses    addslashes()
  35.  * @version $Id: db_info.inc.php 11326 2008-06-17 21:32:48Z lem9 $
  36.  */
  37. if (! defined('PHPMYADMIN')) {
  38.     exit;
  39. }
  40.  
  41. /**
  42.  * requirements
  43.  */
  44. require_once './libraries/common.inc.php';
  45.  
  46. /**
  47.  * limits for table list
  48.  */
  49. if (! isset($_SESSION['userconf']['table_limit_offset'])) {
  50.     $_SESSION['userconf']['table_limit_offset'] = 0;
  51. }
  52. if (isset($_REQUEST['pos'])) {
  53.     $_SESSION['userconf']['table_limit_offset'] = (int) $_REQUEST['pos'];
  54. }
  55. $pos = $_SESSION['userconf']['table_limit_offset'];
  56.  
  57. /**
  58.  * fills given tooltip arrays
  59.  *
  60.  * @uses    $cfg['ShowTooltipAliasTB']
  61.  * @uses    $GLOBALS['strStatCreateTime']
  62.  * @uses    PMA_localisedDate()
  63.  * @uses    strtotime()
  64.  * @param   array   $tooltip_truename   tooltip data
  65.  * @param   array   $tooltip_aliasname  tooltip data
  66.  * @param   array   $table              tabledata
  67.  */
  68. function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
  69. {
  70.     if (empty($table['Comment'])) {
  71.         $table['Comment'] = $table['Name'];
  72.     } else {
  73.         // why?
  74.         $table['Comment'] .= ' ';
  75.     }
  76.  
  77.     if ($GLOBALS['cfg']['ShowTooltipAliasTB']
  78.      && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
  79.         $tooltip_truename[$table['Name']] = $table['Comment'];
  80.         $tooltip_aliasname[$table['Name']] = $table['Name'];
  81.     } else {
  82.         $tooltip_truename[$table['Name']] = $table['Name'];
  83.         $tooltip_aliasname[$table['Name']] = $table['Comment'];
  84.     }
  85.  
  86.     if (isset($table['Create_time']) && !empty($table['Create_time'])) {
  87.         $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCreateTime']
  88.              . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
  89.     }
  90.  
  91.     if (! empty($table['Update_time'])) {
  92.         $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatUpdateTime']
  93.              . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
  94.     }
  95.  
  96.     if (! empty($table['Check_time'])) {
  97.         $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCheckTime']
  98.              . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
  99.     }
  100. }
  101.  
  102. PMA_checkParameters(array('db'));
  103.  
  104. /**
  105.  * @global bool whether to display extended stats
  106.  */
  107. $is_show_stats = $cfg['ShowStats'];
  108.  
  109. /**
  110.  * @global bool whether selected db is information_schema
  111.  */
  112. $db_is_information_schema = false;
  113.  
  114. if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
  115.     $is_show_stats = false;
  116.     $db_is_information_schema = true;
  117. }
  118.  
  119. /**
  120.  * @global array information about tables in db
  121.  */
  122. $tables = array();
  123.  
  124. // When used in Nested table group mode, only show tables matching the given groupname
  125. if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
  126.     $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
  127. } else {
  128.     $tbl_group_sql = '';
  129. }
  130.  
  131. if ($cfg['ShowTooltip']) {
  132.     $tooltip_truename = array();
  133.     $tooltip_aliasname = array();
  134. }
  135.  
  136. // Special speedup for newer MySQL Versions (in 4.0 format changed)
  137. if (true === $cfg['SkipLockedTables']) {
  138.     $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
  139.  
  140.     // Blending out tables in use
  141.     if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
  142.         while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
  143.             // if in use memorize tablename
  144.             if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
  145.                 $sot_cache[$tmp[0]] = true;
  146.             }
  147.         }
  148.         PMA_DBI_free_result($db_info_result);
  149.  
  150.         if (isset($sot_cache)) {
  151.             $db_info_result = PMA_DBI_query(
  152.                 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
  153.                 null, PMA_DBI_QUERY_STORE);
  154.             if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
  155.                 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
  156.                     if (!isset($sot_cache[$tmp[0]])) {
  157.                         $sts_result  = PMA_DBI_query(
  158.                             'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
  159.                              . ' LIKE \'' . addslashes($tmp[0]) . '\';');
  160.                         $sts_tmp     = PMA_DBI_fetch_assoc($sts_result);
  161.                         PMA_DBI_free_result($sts_result);
  162.                         unset($sts_result);
  163.  
  164.                         if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
  165.                             $sts_tmp['Type'] =& $sts_tmp['Engine'];
  166.                         }
  167.  
  168.                         if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
  169.                          && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
  170.                             continue;
  171.                         }
  172.  
  173.                         if ($cfg['ShowTooltip']) {
  174.                             PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
  175.                         }
  176.  
  177.                         $tables[$sts_tmp['Name']]    = $sts_tmp;
  178.                     } else { // table in use
  179.                         $tables[$tmp[0]]    = array('Name' => $tmp[0]);
  180.                     }
  181.                 }
  182.                 if ($GLOBALS['cfg']['NaturalOrder']) {
  183.                     uksort($tables, 'strnatcasecmp');
  184.                 }
  185.  
  186.                 $sot_ready = true;
  187.             } elseif ($db_info_result) {
  188.                 PMA_DBI_free_result($db_info_result);
  189.             }
  190.             unset($sot_cache);
  191.         }
  192.         unset($tmp);
  193.     } elseif ($db_info_result) {
  194.         PMA_DBI_free_result($db_info_result);
  195.     }
  196. }
  197.  
  198. if (! isset($sot_ready)) {
  199.     if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
  200.         // only tables for selected group
  201.         $tables = PMA_DBI_get_tables_full($db, $tbl_group, true);
  202.     } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
  203.         // only tables for selected group,
  204.         // but grouping is done on comment ...
  205.         $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment');
  206.     } else {
  207.         // all tables in db
  208.         // - get the total number of tables
  209.         $tables = PMA_DBI_get_tables($db);
  210.         $total_num_tables = count($tables);
  211.         if (isset($sub_part) && $sub_part == '_export') {
  212.             // (don't fetch only a subset if we are coming from db_export.php,
  213.             // because I think it's too risky to display only a subset of the 
  214.             // table names when exporting a db)
  215.             /**
  216.              *
  217.              * @todo Page selector for table names?
  218.              */
  219.             $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false);
  220.         } else {
  221.             // fetch the details for a possible limited subset
  222.             $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true);
  223.         }
  224.     }
  225.  
  226.     if ($cfg['ShowTooltip']) {
  227.         foreach ($tables as $each_table) {
  228.             PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
  229.         }
  230.     }
  231. }
  232.  
  233. /**
  234.  * @global int count of tables in db
  235.  */
  236. $num_tables = count($tables);
  237. if (! isset($total_num_tables)) {
  238.     $total_num_tables = $num_tables;
  239. }
  240.  
  241. /**
  242.  * cleanup
  243.  */
  244. unset($each_table, $tbl_group_sql, $db_info_result);
  245.  
  246. /**
  247.  * Displays top menu links
  248.  */
  249. require './libraries/db_links.inc.php';
  250. ?>
  251.