home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phptriad / phptriad2-2-1.exe / htdocs / phpmyadmin / db_printview.php < prev    next >
PHP Script  |  2002-01-06  |  9KB  |  265 lines

  1. <?php
  2. /* $Id: db_printview.php,v 1.16 2001/11/23 19:13:07 loic1 Exp $ */
  3.  
  4.  
  5. /**
  6.  * Gets the variables sent or posted to this script, then displays headers
  7.  */
  8. require('./libraries/grab_globals.lib.php');
  9. require('./header.inc.php');
  10.  
  11.  
  12. /**
  13.  * Defines the url to return to in case of error in a sql statement
  14.  */
  15. $err_url = 'db_details.php'
  16.          . '?lang=' . $lang
  17.          . '&server=' . $server
  18.          . '&db=' . urlencode($db);
  19.  
  20.  
  21. /**
  22.  * Gets the list of the table in the current db and informations about these
  23.  * tables if possible
  24.  */
  25. // staybyte: speedup view on locked tables - 11 June 2001
  26. if (PMA_MYSQL_INT_VERSION >= 32303) {
  27.     // Special speedup for newer MySQL Versions (in 4.0 format changed)
  28.     if ($cfgSkipLockedTables == TRUE && PMA_MYSQL_INT_VERSION >= 32330) {
  29.         $local_query  = 'SHOW OPEN TABLES FROM ' . PMA_backquote($db);
  30.         $result        = mysql_query($query) or PMA_mysqlDie('', $local_query, '', $err_url);
  31.         // Blending out tables in use
  32.         if ($result != FALSE && mysql_num_rows($result) > 0) {
  33.             while ($tmp = mysql_fetch_array($result)) {
  34.                 // if in use memorize tablename
  35.                 if (eregi('in_use=[1-9]+', $tmp)) {
  36.                     $sot_cache[$tmp[0]] = TRUE;
  37.                 }
  38.             }
  39.             mysql_free_result($result);
  40.  
  41.             if (isset($sot_cache)) {
  42.                 $local_query = 'SHOW TABLES FROM ' . PMA_backquote($db);
  43.                 $result      = mysql_query($query) or PMA_mysqlDie('', $local_query, '', $err_url);
  44.                 if ($result != FALSE && mysql_num_rows($result) > 0) {
  45.                     while ($tmp = mysql_fetch_array($result)) {
  46.                         if (!isset($sot_cache[$tmp[0]])) {
  47.                             $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\'';
  48.                             $sts_result  = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  49.                             $sts_tmp     = mysql_fetch_array($sts_result);
  50.                             $tables[]    = $sts_tmp;
  51.                         } else { // table in use
  52.                             $tables[]    = array('Name' => $tmp[0]);
  53.                         }
  54.                     }
  55.                     mysql_free_result($result);
  56.                     $sot_ready = TRUE;
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     if (!isset($sot_ready)) {
  62.         $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db);
  63.         $result      = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  64.         if ($result != FALSE && mysql_num_rows($result) > 0) {
  65.             while ($sts_tmp = mysql_fetch_array($result)) {
  66.                 $tables[] = $sts_tmp;
  67.             }
  68.             mysql_free_result($result);
  69.         }
  70.     }
  71.     $num_tables = (isset($tables) ? count($tables) : 0);
  72. } // end if (PMA_MYSQL_INT_VERSION >= 32303)
  73. else {
  74.     $result     = mysql_list_tables($db);
  75.     $num_tables = @mysql_numrows($result);
  76.     for ($i = 0; $i < $num_tables; $i++) {
  77.         $tables[] = mysql_tablename($result, $i);
  78.     }
  79.     mysql_free_result($result);
  80. }
  81.  
  82.  
  83. /**
  84.  * If there is at least one table, displays the printer friendly view, else
  85.  * an error message
  86.  */
  87. // 1. No table
  88. if ($num_tables == 0) {
  89.     echo $strNoTablesFound;
  90. }
  91. // 2. Shows table informations on mysql >= 3.23 - staybyte - 11 June 2001
  92. else if (PMA_MYSQL_INT_VERSION >= 32300) {
  93.     ?>
  94.  
  95. <!-- The tables list -->
  96. <table border="<?php echo $cfgBorder; ?>">
  97. <tr>
  98.     <th> <?php echo ucfirst($strTable); ?> </th>
  99.     <th><?php echo ucfirst($strRecords); ?></th>
  100.     <th><?php echo ucfirst($strType); ?></th>
  101.     <?php
  102.     if ($cfgShowStats) {
  103.         echo '<th>' . ucfirst($strSize) . '</th>';
  104.     }
  105.     echo "\n";
  106.     ?>
  107. </tr>
  108.     <?php
  109.     $i = $sum_entries = $sum_size = 0;
  110.     while (list($keyname, $sts_data) = each($tables)) {
  111.         $table     = $sts_data['Name'];
  112.         $bgcolor   = ($i++ % 2) ? $cfgBgcolorOne : $cfgBgcolorTwo;
  113.         echo "\n";
  114.         ?>
  115. <tr>
  116.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  117.          <b><?php echo htmlspecialchars($table); ?> </b> 
  118.     </td>
  119.         <?php
  120.         echo "\n";
  121.         $mergetable         = FALSE;
  122.         $nonisam            = FALSE;
  123.         if (isset($sts_data['Type'])) {
  124.             if ($sts_data['Type'] == 'MRG_MyISAM') {
  125.                 $mergetable = TRUE;
  126.             } else if (!eregi('ISAM|HEAP', $sts_data['Type'])) {
  127.                 $nonisam    = TRUE;
  128.             }
  129.         }
  130.  
  131.         if (isset($sts_data['Rows'])) {
  132.             if ($mergetable == FALSE) {
  133.                 if ($cfgShowStats && $nonisam == FALSE) {
  134.                     $tblsize                        =  $sts_data['Data_length'] + $sts_data['Index_length'];
  135.                     $sum_size                       += $tblsize;
  136.                     if ($tblsize > 0) {
  137.                         list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, 1);
  138.                     } else {
  139.                         list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, 0);
  140.                     }
  141.                 } else if ($cfgShowStats) {
  142.                     $formated_size                  = ' - ';
  143.                     $unit                           = '';
  144.                 }
  145.                 $sum_entries                        += $sts_data['Rows'];
  146.             }
  147.             // MyISAM MERGE Table
  148.             else if ($cfgShowStats && $mergetable == TRUE) {
  149.                 $formated_size = ' - ';
  150.                 $unit          = '';
  151.             }
  152.             else if ($cfgShowStats) {
  153.                 $formated_size = 'unknown';
  154.                 $unit          = '';
  155.             }
  156.             ?>
  157.     <td align="right" bgcolor="<?php echo $bgcolor; ?>">
  158.             <?php
  159.             echo "\n" . '        ';
  160.             if ($mergetable == TRUE) {
  161.                 echo '<i>' . number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . '</i>' . "\n";
  162.             } else {
  163.                 echo number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n";
  164.             }
  165.             ?>
  166.     </td>
  167.     <td nowrap="nowrap" bgcolor="<?php echo $bgcolor; ?>">
  168.          <?php echo (isset($sts_data['Type']) ? $sts_data['Type'] : ' '); ?> 
  169.     </td>
  170.             <?php
  171.             if ($cfgShowStats) {
  172.                 echo "\n";
  173.                 ?>
  174.     <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  175.          <?php echo $formated_size . ' ' . $unit . "\n"; ?>
  176.     </td>
  177.                 <?php
  178.                 echo "\n";
  179.             } // end if
  180.         } else {
  181.             ?>
  182.     <td colspan="3" align="center" bgcolor="<?php echo $bgcolor; ?>">
  183.         <?php echo $strInUse . "\n"; ?>
  184.     </td>
  185.             <?php
  186.         }
  187.         echo "\n";
  188.         ?>
  189. </tr>
  190.         <?php
  191.     }
  192.     // Show Summary
  193.     if ($cfgShowStats) {
  194.         list($sum_formated, $unit) = PMA_formatByteDown($sum_size, 3, 1);
  195.     }
  196.     echo "\n";
  197.     ?>
  198. <tr>
  199.     <th align="center">
  200.          <b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b> 
  201.     </th>
  202.     <th align="right" nowrap="nowrap">
  203.         <b><?php echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?></b>
  204.     </th>
  205.     <th align="center">
  206.         <b>--</b>
  207.     </th>
  208.     <?php
  209.     if ($cfgShowStats) {
  210.         echo "\n";
  211.         ?>
  212.     <th align="right" nowrap="nowrap">
  213.         <b><?php echo $sum_formated . ' ' . $unit; ?></b>
  214.     </th>
  215.         <?php
  216.     }
  217.     echo "\n";
  218.     ?>
  219. </tr>
  220. </table>
  221.     <?php
  222. } // end case mysql >= 3.23
  223.  
  224. // 3. Shows tables list mysql < 3.23
  225. else {
  226.     $i = 0;
  227.     echo "\n";
  228.     ?>
  229.  
  230. <!-- The tables list -->
  231. <table border="<?php echo $cfgBorder; ?>">
  232. <tr>
  233.     <th> <?php echo ucfirst($strTable); ?> </th>
  234.     <th><?php echo ucfirst($strRecords); ?></th>
  235. </tr>
  236.     <?php
  237.     while ($i < $num_tables) {
  238.         $bgcolor = ($i % 2) ? $cfgBgcolorOne : $bgcolor = $cfgBgcolorTwo;
  239.         echo "\n";
  240.         ?>
  241. <tr>
  242.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  243.         <b><?php echo htmlspecialchars($tables[$i]); ?> </b>
  244.     </td>
  245.     <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  246.          <?php PMA_countRecords($db, $tables[$i]); ?> 
  247.     </td>
  248. </tr>
  249.         <?php
  250.         $i++;
  251.     } // end while
  252.     echo "\n";
  253.     ?>
  254. </table>
  255.     <?php
  256. } // end if
  257.  
  258.  
  259. /**
  260.  * Displays the footer
  261.  */
  262. echo "\n";
  263. require('./footer.inc.php');
  264. ?>
  265.